1) Download The Library

The first step is to download our library from http://getlittleapps.com/little-software-stats/libraries/csharp-latest.zip

2) Include The Library

Using a .NET Framework (C#, VB.NET, J#, etc) Project that was created, add the “Library” folder to your solution. Next, you’ll want to open up Config.cs and modify it so it works with your Little Software Stats:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LittleSoftwareStats
{
    public static class Config
    {
        public static bool Enabled { get; set; }

        internal static string ApiUrl
        {
            get
            {
                UriBuilder uri = new UriBuilder((Config.ApiSecure) ? ("https") : ("http"), Config.ApiHost, Config.ApiPort, Config.ApiPath);

                return uri.ToString();
            }
        }
        internal static string AppId { get; set; }
        internal static string AppVer { get; set; }

        // Nothing above this line should be changed!
        internal const string ApiHost = "stats.yourwebsitehere.com"; // Set this to your Little Software Stats URL
        internal const int ApiPort = 80; // The port for Little Software Stats (usually port 80 or port 443 for HTTPS)
        internal const bool ApiSecure = false; // Set to true if using HTTPS
        internal const string ApiPath = "api."+ApiFormat; // You should only have to change this if your web server doesn't support URL rewriting

        internal const string ApiFormat = "json"; // The API Format (JSON or XML)
        internal const string ApiUserAgent = "LittleSoftwareStatsNET"; // The user agent to send to the API
        internal const int ApiTimeout = 25000; // Time to wait for the API to respond 
    }
}

3) Integrate with your software

Now you’ll want to integerate Little Software Stats by calling it using your software code. This example is from the Little Software Stats C# library which shows how to use the library

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LittleSoftwareStatsNET
{
    public partial class Form1 : Form
    {
        LittleSoftwareStats.Watcher _watcher = new LittleSoftwareStats.Watcher();

        public Form1()
        {
            InitializeComponent();
            // Must be set to true in order for data to be sent
            LittleSoftwareStats.Config.Enabled = true;
            // Tells library to start collecting data
            this.m_watcher.Start("YOURAPPID", "YOURAPPVERSION");
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            // Make sure libary is still started
            if (this._watcher.Started)
                // If it is then stop it and send data before application exits
                this._watcher.Stop();
        }
    }

There is also an example Windows Forms C# project already made which is included with the library. You can use that to test and make sure that your Little Software Stats is receiving data properly.

LittleSoftwareStats.Watcher Functions

There are other functions that can be utilized to collect data using LittleSoftwareStats.Watcher which are described below:

// Starts tracking software
// Example: this._watcher.Start("26ad4eb8f804200f1e23b27c1873d703", "1.0");
void Start(string ApplicationID, string ApplicationVersion);

// Stops tracking software and sends data to API
// Example: this._watcher.Stop();
void Stop();

// Track an event
// Example: this._watcher.Event("Events", "Scan");
void Event(string EventCategory, string EventName);

// Track an event value
// Example: this._watcher.EventValue("Settings", "Theme", "Blue");
void EventValue(string EventCategory, string EventName, string EventValue);

// Track an event period
// Example: this._watcher.EventPeriod("Scans", "Clean", 360, true);
void EventPeriod(string EventCategory, string EventName, int EventDurationInSeconds, bool EventCompleted);

// Track a log message
// Example: this._watcher.Log("Hello World!");
void Log(string LogMessage);

// Track software license
// License parameter ("l") can be either (Free, Trial, Registered, Demo, or Cracked
// Example: this._watcher.License(LittleSoftwareStats.Watcher.Licenses.Free);
void License(Licenses l);

// Track custom data
// Example: this._watcher.CustomData("GFX Card Brand", "NVIDIA");
void CustomData(string Name, string Value);

// Track an exception
// Example: this._watcher.Exception(new DivideByZeroException());
void Exception(Exception ex);
void Exception(string ExceptionMsg, string StackTrace, string ExceptionSrc, string TargetSite);

// Track an installation
// Example: this._watcher.Install();
void Install();
// Track an uninstallation
// Example: this._watcher.Uninstall();
void Uninstall();

Notes

Please see the notes for this project on GitHub for more information.

Development Version

You can get the latest developer version of this library from GitHub. This version is not recommended, but it does contain new features. You will need the Git VCS to download the developer version.

You can get a copy of the branch using the command:

$ git clone git@github.com:little-apps/LittleSoftwareStatsNET.git

You can also browse the source code here:
https://github.com/little-apps/LittleSoftwareStatsNET

Comments