Exemplo n.º 1
0
    public static string get_ram()
    {
        MemoryStatus stat = new MemoryStatus();
        GlobalMemoryStatus(out stat);
        long ram = (long)stat.TotalPhysical;

        return Size_Helper.GetFileSize(ram).ToString();
    }
Exemplo n.º 2
0
 public static long GetFreeMemory()
 {
     if (IsWindows)
     {
         var mStatus = new MemoryStatus();
         GlobalMemoryStatus(ref mStatus);
         return(Convert.ToInt64(mStatus.DwAvailPhys) / 1024 / 1024);
     }
     else
     {
         var lines        = File.ReadAllLines("/proc/meminfo");
         var infoDic      = lines.Select(line => line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Take(2).ToList()).ToDictionary(items => items[0], items => long.Parse(items[1]));
         var free         = infoDic["MemFree:"];
         var sReclaimable = infoDic["SReclaimable:"];
         return((free + sReclaimable) / 1024);
     }
 }
        public static int GetMemoryLoad(this IMemoryInfo i)
        {
            MemoryStatusEx mse = new MemoryStatusEx();

            mse.dwLength = (uint)Marshal.SizeOf(mse);

            if (GlobalMemoryStatusEx(ref mse))
            {
                return((int)mse.dwMemoryLoad);
            }
            MemoryStatus ms = new MemoryStatus();

            if (GlobalMemoryStatus(ref ms))
            {
                return((int)ms.dwMemoryLoad);
            }
            return(-1);
        }
 public ulong?GetTotalPhysicalMemoryBytes()
 {
     try
     {
         MemoryStatus status = new MemoryStatus();
         status.length = Marshal.SizeOf(status);
         if (!GlobalMemoryStatusEx(ref status))
         {
             int err = Marshal.GetLastWin32Error();
             throw new Win32Exception(err);
         }
         return(status.totalPhys);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 5
0
        public void GenerateStatusTypesProperly()
        {
            MemoryStatus mem_status = new MemoryStatus(80.0, 90.0);

            EStatusType status = mem_status.GetStatus(70, 100);

            Assert.Equal(EStatusType.AdequateFreeMemory, status);

            status = mem_status.GetStatus(80, 100);
            Assert.Equal(EStatusType.LowFreeMemory, status);

            status = mem_status.GetStatus(90, 100);
            Assert.Equal(EStatusType.CriticallyLowFreeMemory, status);

            status = mem_status.GetStatus(99, 100);
            Assert.Equal(EStatusType.CriticallyLowFreeMemory, status);

            status = mem_status.GetStatus(0, 100);
            Assert.Equal(EStatusType.AdequateFreeMemory, status);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get system's total memory
        /// </summary>
        /// <returns>System's total memory</returns>
        private ulong GetSystemMemory()
        {
            ///Retrieve system memory information
            MemoryStatus.MemoryStatusEx status;
            try
            {
                ///This call is quiet effiecient. Also, it is called only once if we
                /// successfully retrieve system memory information (otherwise we will retry
                /// every time the task is invoked until we reach the failure count)
                ///Benchmark @Quad core, 8GB RAM, 1,000,000 iterations
                ///Best(ms): 0.003821, Avg(ms): 0.004136, Worst(ms): 0.5701
                status = MemoryStatus.GetMemoryStatus();

                ///Unable to retrieve system memory status
                if (status.TotalMemory <= 0)
                {
                    //    "Failed to retrieve memory status. Garbage collection task will not start");
                    this._failureCount++;

                    return(0);
                }

                return(status.TotalMemory);
            }
            catch (Exception exc)
            {
                this._failureCount++;

                return(0);
            }
            finally
            {
                if (this._failureCount >= _maxFilureCount)
                {
                    AppUtil.LogEvent("NCache", "Failed to retrieve memory status. Garbage collection task will now exit",
                                     EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);

                    this._cancel = true;
                }
            }
        }
        // NOTE:
        // We could've used the DispatchTimer for this one (https://social.msdn.microsoft.com/Forums/vstudio/en-US/e7b66990-89c3-4958-b4e7-1d2ad1d4dd74/wpf-multitasking-along-with-a-timer-and-background-worker)
        // as the results as largely important only for the UI, but I've decided to
        // run this bugger in
        public static void BackgroundTask()
        {
            // We FIRST exec the UI update routine, because the UI timing parts of the CURRENT history record
            // will only now have been updated by the additional measurement background tasks.
            // If we would to this OnTick UI update work LAST, we would always lag one 'tick' (~ 2 seconds)
            // behind on timings, which would then show a flat leading part in any chart.
            OnTick?.Invoke(null, null);

            // history record based graphs, etc. *too*!
            // GC memory pressure?
            MemoryStatus mstat = ComputerStatistics.GetMemoryStatus();
            bool         are_timing_tests_running = false;

            // SHIFT the cursor one record forward and fill the new record as best as possible.
            // This means we have a 'fixed sample frequency' in the history, as set up in the
            // BackgroundWorkerDaemon.
            collected_data.ProcessCurrentRecord(shift: true, (rec, old) =>
            {
                rec.memory               = mstat;
                rec.UIResponsiveness     = old.UIResponsiveness;
                are_timing_tests_running = (resp_housekeeping.running > 0);

                // the easiest way to ensure the timing values stay until updated, is to copy
                // the now-old values:
            });

            // measure UI responsiveness? Only when we won't collide with still running tests!
            if (!are_timing_tests_running)
            {
                lock (collected_data.data_lock)
                {
                    resp_housekeeping.running = 2;

                    resp_housekeeping.clk2Test = Stopwatch.StartNew();
                }
                SafeThreadPool.QueueUserWorkItem(o => MeasureUIResponsivenessNormal());
                SafeThreadPool.QueueUserWorkItem(o => MeasureUIResponsivenessBackground());
            }
        }
Exemplo n.º 8
0
        static Framework()
        {
            var systemVersion = Environment.OSVersion.Version.ToString();

            IsServer2008 = systemVersion.StartsWith("6.0") || systemVersion.StartsWith("6.1");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var mStatus = new MemoryStatus();
                GlobalMemoryStatus(ref mStatus);
                TotalMemory = (int)(Convert.ToInt64(mStatus.DwTotalPhys) / 1024 / 1024);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                var lines   = File.ReadAllLines("/proc/meminfo");
                var infoDic = lines
                              .Select(line => line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Take(2).ToList())
                              .ToDictionary(items => items[0], items => long.Parse(items[1]));
                TotalMemory = (int)(infoDic["MemTotal:"] / 1024);
            }
            else
            {
                // TODO:
            }

            var networkInterface = NetworkInterface.GetAllNetworkInterfaces()
                                   .First(i => i.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
                                          i.NetworkInterfaceType == NetworkInterfaceType.Wireless80211);
            var unicastAddresses = networkInterface.GetIPProperties().UnicastAddresses;

            IpAddress = unicastAddresses.First(a =>
                                               a.IPv4Mask.ToString() != "255.255.255.255" && a.Address.AddressFamily == AddressFamily.InterNetwork)
                        .Address.ToString();

            OsDescription = $"{Environment.OSVersion.Platform} {Environment.OSVersion.Version}";

            LimitedConcurrencyThreadPool = new LimitedConcurrencyThreadPool(LimitedConcurrencyThread);
        }
 internal static MemoryStatus GetMemoryStatus()
 {
     MemoryStatus lpBuffer = new MemoryStatus();
     if (!GlobalMemoryStatusEx(lpBuffer))
     {
         return null;
     }
     return lpBuffer;
 }
Exemplo n.º 10
0
		/// <summary>
		/// Initializes a new instance of the class with the specified parameters.
		/// </summary>
		/// <param name="readStorage">Status of the current read storage</param>
		/// <param name="writeStorage">Status of the current write storage</param>
		/// <param name="receiveStorage">Status of the current receive storage</param>
		public MessageMemoryStatus(MemoryStatus readStorage, MemoryStatus writeStorage, MemoryStatus receiveStorage)
		{
			this.readStorage = readStorage;
			this.writeStorage = writeStorage;
			this.receiveStorage = receiveStorage;
		}
Exemplo n.º 11
0
 public static extern bool GlobalMemoryStatusEx([In, Out] MemoryStatus lpBuffer);
Exemplo n.º 12
0
 extern public static void GlobalMemoryStatus(ref MemoryStatus ms);
Exemplo n.º 13
0
 private static void TestMemoryUsage()
 {
     var result       = SystemInfo.MemoryUsageForCurrentProcess;
     var memoryStatus = MemoryStatus.Create();
 }
Exemplo n.º 14
0
 private extern static void GlobalMemoryStatus(ref MemoryStatus buffer);
Exemplo n.º 15
0
 public static bool GetMemoryStatus(this IMemoryInfo m, ref MemoryStatus ms)
 {
     return(GlobalMemoryStatus(ref ms));
 }
Exemplo n.º 16
0
		/// <summary>
		/// Retrieves the memory status of the device
		/// </summary>
		public static MemoryStatus GlobalMemoryStatus()
		{
			MemoryStatus ms = new MemoryStatus();
			
			GlobalMemoryStatusCE( out ms );
			
			return ms;
		}
Exemplo n.º 17
0
		internal static extern void GlobalMemoryStatusCE(out MemoryStatus msce);
Exemplo n.º 18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MemoryStatus stat = new MemoryStatus();
            GlobalMemoryStatus(out stat);

            long ram = (long)stat.TotalPhysical;

            StringBuilder builder = new StringBuilder();
            builder.Append("<pre>");

            builder.AppendLine(" ===== MEMORY STATUS ==== ");
            builder.AppendLine("Physical");
            builder.AppendLine(string.Format("{0,-30} {1,15}", "  Total:", MakeHumanReadable((long)stat.TotalPhysical)));
            builder.AppendLine(string.Format("{0,-30} {1,15}", "  Available:", MakeHumanReadable((long)stat.AvailablePhysical)));
            builder.AppendLine("Page File");
            builder.AppendLine(string.Format("{0,-30} {1,15}", "  Total:", MakeHumanReadable((long)stat.TotalPageFile)));
            builder.AppendLine(string.Format("{0,-30} {1,15}", "  Available:", MakeHumanReadable((long)stat.AvailablePageFile)));
            builder.AppendLine(string.Empty);
            builder.AppendLine("Virtual");
            builder.AppendLine(string.Format("{0,-30} {1,15}", "  Total:", MakeHumanReadable((long)stat.TotalVirtual)));
            builder.AppendLine(string.Format("{0,-30} {1,15}", "  Available:", MakeHumanReadable((long)stat.AvailableVirtual)));

            builder.AppendLine(string.Empty);
            builder.AppendLine(string.Empty);
            builder.AppendLine(" ===== HARD DRIVES STATUS ==== ");

            DriveInfo[] allDrives = DriveInfo.GetDrives();

            foreach (DriveInfo d in allDrives)
            {
                builder.AppendLine(string.Format("Drive {0}", d.Name));
                builder.AppendLine(string.Format("  Drive type: {0}", d.DriveType));

                if (d.IsReady == true)
                {
                    builder.AppendLine(string.Format("  Volume label: {0}", d.VolumeLabel));
                    builder.AppendLine(string.Format("  File system: {0}", d.DriveFormat));
                    builder.AppendLine(string.Format("{0,-30} {1,11}",
                        "  Available space to current user:"******"{0,-30} {1,15}",
                        "  Total available space:",
                        MakeHumanReadable(d.TotalFreeSpace)));

                    builder.AppendLine(string.Format("{0,-30} {1,15}",
                        "  Total size of drive:",
                        MakeHumanReadable(d.TotalSize)));
                }

                builder.AppendLine(string.Empty);
            }

            builder.AppendLine(string.Empty);
            builder.AppendLine(string.Empty);
            builder.AppendLine(" ===== MISC SYSTEM INFORMATION ===== ");

            builder.AppendLine(string.Format("{0,-22} {1}", "Machine Name:", System.Environment.MachineName));
            builder.AppendLine(string.Format("{0,-22} {1}", "User Domain:", System.Environment.UserDomainName));
            builder.AppendLine(string.Format("{0,-22} {1}", "UserName:"******"{0,-22} {1}", "OS Version:", System.Environment.OSVersion));
            builder.AppendLine(string.Format("{0,-22} {1}", "64 Bit OS:", System.Environment.Is64BitOperatingSystem));
            builder.AppendLine(string.Format("{0,-22} {1}", "64 Bit Process:", System.Environment.Is64BitProcess));
            builder.AppendLine(string.Format("{0,-22} {1}", "Processor Count:", System.Environment.ProcessorCount));
            builder.AppendLine(string.Format("{0,-22} {1}", "System Directory:", System.Environment.SystemDirectory));
            builder.AppendLine(string.Format("{0,-22} {1}", "System Page Size:", System.Environment.SystemPageSize));
            builder.AppendLine(string.Format("{0,-22} {1}", "Working Set:", System.Environment.WorkingSet));
            builder.AppendLine(string.Format("{0,-22} {1}", "Interactive Process:", System.Environment.UserInteractive));
            builder.AppendLine(string.Format("{0,-22} {1}", "CLR Version:", System.Environment.Version));

            // environment variables?
            builder.AppendLine(string.Empty);
            builder.AppendLine(string.Empty);
            builder.AppendLine(" ===== ENVIRONMENT VARIABLES ===== ");
            IDictionary environmentVariables = Environment.GetEnvironmentVariables();

            foreach (DictionaryEntry de in environmentVariables)
            {
                builder.AppendLine(string.Format("{0,-24} {1}", de.Key, de.Value));
            }

            builder.AppendLine("</pre>");

            this.machineblob.Text = builder.ToString();
        }
Exemplo n.º 19
0
 private static extern void GlobalMemoryStatus(ref MemoryStatus ms);
Exemplo n.º 20
0
 internal static extern void GlobalMemoryStatusEx(ref MemoryStatus lpbuffer);
Exemplo n.º 21
0
 static extern void GlobalMemoryStatus(ref MemoryStatus buf);
Exemplo n.º 22
0
        public bool Initialize()
        {
            XmlNodeList xnl;
            CultureInfo CI = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            CurrentFolder = Environment.CurrentDirectory + "\\";
            ProgramFolder = Application.StartupPath + "\\";

            MemoryStatus ms = new MemoryStatus();

            GlobalMemoryStatus(ref ms);
            TotalRAM = (int)(ms.dwTotalPhys / 1024 / 1024) + 1;

            XmlDocument xd             = new XmlDocument();
            var         readerSettings = new XmlReaderSettings {
                ProhibitDtd = false, ValidationType = ValidationType.DTD
            };
            var xvr = XmlReader.Create(Path.Combine(Application.StartupPath, "Settings.xml"), readerSettings);

            try { xd.Load(xvr); }
            catch (Exception e) {
                MessageBox.Show(e.Message.Replace(" An error occurred at file:///", "\nFile: ").Replace(", (", "\nLine, Column: ("), "GoodMerge - XML Loading Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally { xvr.Close(); }

            Biases = new StringCollection();
            foreach (XmlNode xn in xd.SelectNodes("/settings/biaspriority/zone/@name"))
            {
                Biases.Add(xn.Value);
            }

            SetName = xd.SelectSingleNode("/settings/romset/@name").Value;
            Version = xd.SelectSingleNode("/settings/romset/@version").Value;

            SourceCompression = xd.SelectSingleNode("/settings/compression/@source").Value;
            OutputCompression = xd.SelectSingleNode("/settings/compression/@output").Value;

            Arguments   = xd.SelectSingleNode("/settings/misc/@arguments").Value.Equals("true");
            Background  = xd.SelectSingleNode("/settings/misc/@background").Value.Equals("true");
            Minimal     = xd.SelectSingleNode("/settings/misc/@minimal").Value.Equals("true");
            Language    = xd.SelectSingleNode("/settings/misc/@language").Value;
            DeleteFiles = false;

            int x = 0, y = 0;

            try { x = Int32.Parse(xd.SelectSingleNode("/settings/windows/main/@x").Value); }
            catch { x = 0; }
            try { y = Int32.Parse(xd.SelectSingleNode("/settings/windows/main/@y").Value); }
            catch { y = 0; }
            MainWindowLocation = new Point(x, y);

            try { x = Int32.Parse(xd.SelectSingleNode("/settings/windows/log/@x").Value); }
            catch { x = 0; }
            try { y = Int32.Parse(xd.SelectSingleNode("/settings/windows/log/@y").Value); }
            catch { y = 0; }
            LogWindowLocation = new Point(x, y);

            try { x = Int32.Parse(xd.SelectSingleNode("/settings/windows/log/@width").Value); }
            catch { x = 0; }
            try { y = Int32.Parse(xd.SelectSingleNode("/settings/windows/log/@height").Value); }
            catch { y = 0; }
            LogWindowSize = new Size(x, y);

            int ram = 0;

            try { ram = Int32.Parse(xd.SelectSingleNode("/settings/ram/@mb").Value); }
            catch {
                ram = TotalRAM - 114;
                if (ram < 57)
                {
                    ram = 57;
                }
            }
            SetDesiredRAM(ram);

            SevenZip      = xd.SelectSingleNode("/settings/program/@sevenzip").Value;
            Rar           = xd.SelectSingleNode("/settings/program/@rar").Value;
            Ace           = xd.SelectSingleNode("/settings/program/@ace").Value;
            WorkingFolder = xd.SelectSingleNode("/settings/program/@working").Value;
            if (WorkingFolder.Equals(""))
            {
                WorkingFolder = CurrentFolder;
            }

            if (SevenZip.Equals(""))
            {
                Default7Zip();
            }
            if (Rar.Equals(""))
            {
                DefaultRar();
            }
            if (Ace.Equals(""))
            {
                DefaultAce();
            }

            SourceFolders = new Hashtable();
            OutputFolders = new Hashtable();
            HaveFiles     = new Hashtable();
            SetNames      = new StringCollection();
            xnl           = xd.SelectNodes("/settings/paths/setpath");
            foreach (XmlNode xn in xnl)
            {
                SetNames.Add(xn.Attributes["name"].Value);
                HaveFiles.Add(xn.Attributes["name"].Value, xn.Attributes["have"].Value);
                SourceFolders.Add(xn.Attributes["name"].Value, xn.Attributes["source"].Value);
                OutputFolders.Add(xn.Attributes["name"].Value, xn.Attributes["output"].Value);
            }
            if (HaveFiles.Contains(SetName))
            {
                HaveFile = HaveFiles[SetName].ToString();
            }
            if (SourceFolders.Contains(SetName))
            {
                SourceFolder = SourceFolders[SetName].ToString();
            }
            if (OutputFolders.Contains(SetName))
            {
                OutputFolder = OutputFolders[SetName].ToString();
            }

            xd  = new XmlDocument();
            xvr = XmlReader.Create(Path.Combine(Application.StartupPath, "Languages.xml"), readerSettings);
            try { xd.Load(xvr); }
            catch (Exception e) {
                MessageBox.Show(e.Message.Replace(" An error occurred at file:///", "\nFile: ").Replace(", (", "\nLine, Column: ("), "GoodMerge - XML Loading Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            finally { xvr.Close(); }

            xnl        = xd.SelectNodes("/languages/language[@name=\"" + Language + "\"]/text");
            Strings    = new string[xnl.Count + 1];
            Strings[0] = "GoodMerge";
            if (xnl.Count == 0)
            {
                XmlNodeList    xnll = xd.SelectNodes("/languages/language/@name");
                LanguagePicker lp   = new LanguagePicker(xnll);
                lp.ShowDialog();
                if (lp.Tree.Nodes.Count == 0)
                {
                    return(false);
                }
                Language   = lp.Tree.SelectedNode.Text;
                xnl        = xd.SelectNodes("/languages/language[@name=\"" + Language + "\"]/text");
                Strings    = new string[xnl.Count + 1];
                Strings[0] = "GoodMerge";
            }
            FontName = xd.SelectSingleNode("/languages/language[@name=\"" + Language + "\"]/font/@face").Value;
            FontSize = Single.Parse(xd.SelectSingleNode("/languages/language[@name=\"" + Language + "\"]/font/@size").Value);
            ScaleX   = Int32.Parse(xd.SelectSingleNode("/languages/language[@name=\"" + Language + "\"]/size/@scale-x").Value);
            ScaleY   = Int32.Parse(xd.SelectSingleNode("/languages/language[@name=\"" + Language + "\"]/size/@scale-y").Value);
            foreach (XmlNode xn in xnl)
            {
                Strings[Int32.Parse(xn.Attributes["n"].Value)] = xn.Attributes["t"].Value.Replace("$PRG", Strings[0]);
            }
            BiasesDisplay = new Hashtable();
            foreach (XmlNode xn in xd.SelectNodes("/languages/language[@name=\"" + Language + "\"]/zonetext"))
            {
                BiasesDisplay.Add(xn.Attributes["n"].Value, xn.Attributes["t"].Value);
            }

            Thread.CurrentThread.CurrentCulture = CI;
            return(true);
        }
Exemplo n.º 23
0
 internal static extern void GlobalMemoryStatus(out MemoryStatus msce);
Exemplo n.º 24
0
 private static extern bool GlobalMemoryStatus(ref MemoryStatus lpBuffer);
Exemplo n.º 25
0
		extern public static void GlobalMemoryStatus(ref MemoryStatus ms);
Exemplo n.º 26
0
 private static extern bool GlobalMemoryStatusEx(MemoryStatus buffer);
Exemplo n.º 27
0
        /// <summary>
        /// Retrieves the current global memory status.
        /// </summary>
        internal static MemoryStatus GetMemoryStatus()
        {
            MemoryStatus status = new MemoryStatus();
            bool returnValue = NativeMethodsShared.GlobalMemoryStatusEx(status);
            if (!returnValue)
            {
                return null;
            }

            return status;
        }
Exemplo n.º 28
0
        public PackageCacheStatusInfo(CacheStatusType cacheStatusType, string currentActionVerb, InstallStatusType installStatusType, int sweepIndex, int sweepCount, DateTime lastSweepStart, DateTime lastCacheStatusRequest, Dictionary <string, List <PathCacheStatus> > pathsProcessed, MemoryStatus memoryStatus)
        {
            this.CacheStatus    = cacheStatusType.ToString();
            this.InstallStatus  = installStatusType.ToString();
            this.SweepIndex     = sweepIndex;
            this.SweepCount     = sweepCount;
            this.LastSweepStart = lastSweepStart;

            Debug.Assert(currentActionVerb != null);

            this.CurrentActionVerb = currentActionVerb;

            this.pathsProcessed      = pathsProcessed.ToDictionary();
            this.pathsProcessedDelta = pathsProcessed.Where(p => p.Value.Last().Timestamp >= lastCacheStatusRequest).ToDictionary();

            if (memoryStatus != null)
            {
                memoryStatus.Update();

                this.MemoryStatus = memoryStatus;
            }
        }
Exemplo n.º 29
0
 public static extern void GlobalMemoryStatus(out MemoryStatus stat);
Exemplo n.º 30
0
 public static extern void GlobalMemoryStatus(out MemoryStatus stat);
Exemplo n.º 31
0
 public static extern bool GlobalMemoryStatus(ref MemoryStatus lpBuffer);
Exemplo n.º 32
0
        internal static MemoryStatus GetMemoryStatus()
        {
            MemoryStatus lpBuffer = new MemoryStatus();

            return(GlobalMemoryStatusEx(lpBuffer) ? lpBuffer : null);
        }
Exemplo n.º 33
0
 public GlobalMemoryInfo()
 {
     msinfo          = new MemoryStatus();
     msinfo.dwLength = Marshal.SizeOf(msinfo);
     GlobalMemoryStatus(ref msinfo);
 }
Exemplo n.º 34
0
        public static void report(string step, string game, string version, string guid, string strMore)
        {
            string requestUriString = "http://www.pcprime.it/installer/";

            try
            {
                ulong num2;
                ulong num3;
                ulong num4;
                requestUriString = (requestUriString + step + "?game=" + game) + "&version=" + version;
                OperatingSystem oSVersion = Environment.OSVersion;
                requestUriString = requestUriString + "&windowsVersion=" + oSVersion.Version.ToString();
                string servicePack = oSVersion.ServicePack;
                if ((servicePack != null) && (servicePack != ""))
                {
                    string str3 = servicePack.Replace(' ', '-');
                    requestUriString = requestUriString + "&servicePack=" + str3;
                }
                else
                {
                    requestUriString = requestUriString + "&servicePack=0";
                }
                MemoryStatus stat = new MemoryStatus();
                GlobalMemoryStatus(out stat);
                long totalPhysical = stat.TotalPhysical;
                requestUriString = requestUriString + "&physhicalMemory=" + (totalPhysical / 0x400L);
                GetDiskFreeSpaceEx("C:", out num2, out num3, out num4);
                requestUriString = requestUriString + "&freeCDriveSpace=" + (num4 / ((ulong)0x400L));
                string str4 = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727", "Version", "-1");
                if (str4 == null)
                {
                    str4 = "-1";
                }
                requestUriString = requestUriString + "&DOTNET20VERSION=" + str4;
                str4             = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0", "Version", "-1");
                if (str4 == null)
                {
                    str4 = "-1";
                }
                requestUriString = requestUriString + "&DOTNET30VERSION=" + str4;
                str4             = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5", "Version", "-1");
                if (str4 == null)
                {
                    str4 = "-1";
                }
                requestUriString = requestUriString + "&DOTNET35VERSION=" + str4;
                string[] subKeyNames = Registry.LocalMachine.OpenSubKey(@"Software\pcprime.it\").GetSubKeyNames();
                int      num5        = 0;
                for (int i = 0; i < subKeyNames.Length; i++)
                {
                    string      name = @"Software\pcprime.it\" + subKeyNames[i];
                    RegistryKey key2 = Registry.LocalMachine.OpenSubKey(name);
                    object      obj2 = key2.GetValue("Version", -1);
                    if ((obj2 != null) && (obj2.GetType() == typeof(int)))
                    {
                        int num7 = (int)key2.GetValue("Version", -1);
                        if (num7 != -1)
                        {
                            if (num5 == 0)
                            {
                                requestUriString = requestUriString + "&installed=";
                            }
                            else
                            {
                                requestUriString = requestUriString + "|";
                            }
                            requestUriString = requestUriString + subKeyNames[i] + "," + num7.ToString();
                            num5++;
                        }
                    }
                }
                requestUriString = requestUriString + "&guid=" + guid;
                if (strMore != null)
                {
                    requestUriString = requestUriString + strMore;
                }
                HttpWebRequest request = WebRequest.Create(requestUriString) as HttpWebRequest;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    HttpStatusCode statusCode = response.StatusCode;
                    new StreamReader(response.GetResponseStream()).ReadToEnd();
                }
            }
            catch (Exception exception)
            {
                Launcher.Logging.LogInfo(exception.Message);
            }
        }
Exemplo n.º 35
0
        public void CallProperties()
        {
            MemoryStatus status = new MemoryStatus();

            TypeHelper.ShowPropertyValues(status);
        }
Exemplo n.º 36
0
 public static void GlobalMemoryStatus(ref MemoryStatus ms)
 {
     Console.WriteLine("Warning--using unimplemented method GlobalMemoryStatus");             // FIXME Linux
     return;
 }
Exemplo n.º 37
0
 extern static void GlobalMemoryStatus(ref MemoryStatus lpbuffer);
Exemplo n.º 38
0
        //-------------------------------------------//

        //-------------------------------------------//

        public SystemInformation()
        {
            // get environment information
            PageSize       = Environment.SystemPageSize;
            ProcessorCount = Environment.ProcessorCount;
            Processor64Bit = Environment.Is64BitProcess;
            NameUser       = Environment.UserName;
            NameMachine    = Environment.MachineName;
            NameInstance   = Process.GetCurrentProcess().Id.ToString();

            // validate processor count
            if (ProcessorCount < 1)
            {
                ProcessorCount = 1;
            }

            // get current process
            Process = Process.GetCurrentProcess();
            // get process id
            ProcessId = Process.Id;

            // determine the platform
            int platformId = (int)Environment.OSVersion.Platform;

            if (platformId == 4 || platformId == 6 || platformId == 128)
            {
                Platform = Platform.Linux;
            }
            else
            {
                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.MacOSX:
                    Platform = Platform.Mac;
                    break;

                case PlatformID.Unix:
                    Platform = Platform.Linux;
                    break;

                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    Platform = Platform.Windows;
                    break;

                default:
                    Platform = Platform.Unknown;
                    break;
                }
            }

            switch (Platform)
            {
            case Platform.Windows:
                NewLine = "\r\n";
                break;

            default:
                NewLine = "\n";
                break;
            }

            // memory flag
            bool memorySet = false;

            // attempt to get memory state using kernal32.dll method
            try {
                _memoryStatus = new MemoryStatus();
                if (MemoryStatus.GlobalMemoryStatusEx(_memoryStatus))
                {
                    MemoryTotal     = _memoryStatus.ullTotalPhys;
                    MemoryAvailable = _memoryStatus.ullAvailPhys;
                    memorySet       = MemoryAvailable > 0;
                }
                // disable once EmptyGeneralCatchClause
            } catch {
                // ignore
            }

            // attempt to get available memory through null allocation
            if (!memorySet)
            {
                // Approximate the available memory by subtracting the current processes resource use.
                MemoryAvailable = MemoryTotal = (ulong)Process.PeakWorkingSet64 - (ulong)Process.WorkingSet64;
                memorySet       = MemoryAvailable > 0;
            }
        }
Exemplo n.º 39
0
 /// <summary>
 /// コンストラクターです。
 /// </summary>
 public PerformanceMetrics()
 {
     this.memoryStatus = new MemoryStatus();
 }