2 using System.Collections.Generic;
5 using System.Runtime.InteropServices;
6 using System.Management;
7 using System.Threading;
9 namespace AppLimit.NetSparkle
11 internal class NetSparkleDeviceInventory
13 public Boolean x64System { get; set; }
14 public uint ProcessorSpeed { get; set; }
15 public Int64 MemorySize { get; set; }
16 public string OsVersion { get; set; }
17 public int CPUCount { get; set; }
19 private NetSparkleConfiguration _config;
21 public NetSparkleDeviceInventory(NetSparkleConfiguration config)
26 public void CollectInventory()
29 CollectProcessorBitnes();
41 CollectWindowsVersion();
44 public String BuildRequestUrl(String baseRequestUrl)
46 String retValue = baseRequestUrl;
49 retValue += "cpu64bit=" + (x64System ? "1" : "0") + "&";
52 retValue += "cpuFreqMHz=" + ProcessorSpeed + "&";
55 retValue += "ramMB=" + MemorySize + "&";
57 // Application name (as indicated by CFBundleName)
58 retValue += "appName=" + _config.ApplicationName + "&";
60 // Application version (as indicated by CFBundleVersion)
61 retValue += "appVersion=" + _config.InstalledVersion + "&";
63 // User’s preferred language
64 retValue += "lang=" + Thread.CurrentThread.CurrentUICulture.ToString() + "&";
67 retValue += "osVersion=" + OsVersion + "&";
69 // CPU type/subtype (see mach/machine.h for decoder information on this data)
70 // ### TODO: cputype, cpusubtype ###
73 // ### TODO: model ###
75 // Number of CPUs (or CPU cores, in the case of something like a Core Duo)
77 retValue += "ncpu=" + CPUCount + "&";
80 retValue = retValue.TrimEnd('&');
86 private void CollectWindowsVersion()
88 OperatingSystem osInfo = Environment.OSVersion;
89 OsVersion = string.Format("{0}.{1}.{2}.{3}", osInfo.Version.Major, osInfo.Version.Minor, osInfo.Version.Build, osInfo.Version.Revision);
92 private void CollectProcessorBitnes()
94 if (Marshal.SizeOf(typeof(IntPtr)) == 8)
100 private void CollectCPUCount()
102 CPUCount = Environment.ProcessorCount;
105 private void CollectCPUSpeed()
107 ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
108 ProcessorSpeed = (uint)(Mo["CurrentClockSpeed"]);
112 private void CollectRamSize()
117 ManagementScope oMs = new ManagementScope();
118 ObjectQuery oQuery = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
119 ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
120 ManagementObjectCollection oCollection = oSearcher.Get();
124 // In case more than one Memory sticks are installed
125 foreach (ManagementObject mobj in oCollection)
127 mCap = Convert.ToInt64(mobj["Capacity"]);
131 MemorySize = (MemorySize / 1024) / 1024;