public void ReadInstancesFromServer() { List<WmiService> services; if(this.UseImpersonation == true) services = WmiService.GetAllServices(this.ServerName, this.UserName, Encryption.Decrypt(this.Password), "PathName LIKE '%memcached%'"); else services = WmiService.GetAllServices(this.ServerName, null, null, "PathName LIKE '%memcached%'"); Instances.Clear(); foreach (WmiService service in services) { Instance instance = new Instance(); instance.DisplayName = service.DisplayName; instance.ServiceName = service.Name; instance.ParseImagePath(service.PathName); Instances.Add(instance); } //ImpersonateUser impersonateUser = null; //try //{ // if (this.UseImpersonation == true) // { // impersonateUser = new ImpersonateUser(UserName, Encryption.Decrypt(Password)); // } // RegistryKey serviceBranchKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, this.ServerName).OpenSubKey(@"SYSTEM\CurrentControlSet\Services"); // Instances.Clear(); // foreach (string serviceName in serviceBranchKey.GetSubKeyNames()) // { // RegistryKey serviceKey = serviceBranchKey.OpenSubKey(serviceName); // string imagePath; // if ((imagePath = (string)serviceKey.GetValue("ImagePath", String.Empty)) != String.Empty) // { // if (imagePath.ToLower().Contains("memcached.exe") == true) // { // Instance instance = new Instance(); // instance.DisplayName = (string)serviceKey.GetValue("DisplayName", String.Empty); // Instances.Add(instance); // } // } // } //} //finally //{ // if(impersonateUser != null && impersonateUser.IsImpersonating == true) // impersonateUser.Undo(); //} }
public InstanceStatistics(System.Net.IPEndPoint serverEndPoint, Server server, Instance instance, ServerStats serverStats, State serviceState) { string memcachedFileVersion = null; if (File.Exists(Configuration.Default.MemcachedBinarySource) == true) memcachedFileVersion = FileVersionInfo.GetVersionInfo(Configuration.Default.MemcachedBinarySource).FileVersion; _serverName = server.ServerName; _instanceName = instance.DisplayName; _serviceState = serviceState; Instance = instance; _statusIconIndex = StatusIconIndex.CommunicationError; _statusTooltip = Constants.TooltipCommunicationError; if (serverStats != null && serverStats.GetRaw(serverEndPoint, StatItem.Version) != null) { foreach (StatItem statItem in Enum.GetValues(typeof(Enyim.Caching.Memcached.StatItem))) { switch (statItem) { case StatItem.BytesRead: _bytesRead = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.BytesWritten: _bytesWritten = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ConnectionCount: _connectionCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ConnectionStructures: _connectionStructures = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.GetCount: _getCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.GetHits: _getHits = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.GetMisses: _getMisses = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ItemCount: _itemCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.MaxBytes: _maxBytes = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ServerTime: string serverTimeRaw = serverStats.GetRaw(serverEndPoint, statItem); int serverTimeSeconds; if (serverTimeRaw != null && Int32.TryParse(serverTimeRaw, out serverTimeSeconds) == true) _serverTime = new DateTime(1970, 1, 1).AddSeconds(serverTimeSeconds).ToLocalTime().ToString(); else _serverTime = "<unknown>"; break; case StatItem.SetCount: _setCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.TotalConnections: _totalConnections = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.TotalItems: _totalItems = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.Uptime: string uptimeRaw = serverStats.GetRaw(serverEndPoint, statItem); int uptimeSeconds; if (uptimeRaw != null && Int32.TryParse(uptimeRaw, out uptimeSeconds) == true) _uptime = TimeSpan.FromSeconds(uptimeSeconds).ToString(); else _uptime = "<unknown>"; break; case StatItem.UsedBytes: _usedBytes = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.Version: _version = serverStats.GetRaw(serverEndPoint, statItem); break; } } } if (_serviceState != State.Running && _serviceState != State.Unknown) { _statusIconIndex = StatusIconIndex.ServiceDown; _statusTooltip = Constants.TooltipServiceDown; } else if (_serviceState == State.Unknown) { _statusIconIndex = StatusIconIndex.ServiceNonControllable; _statusTooltip = Constants.TooltipServiceNonControllable; } else if (_version == null || _version == String.Empty) { _statusIconIndex = StatusIconIndex.CommunicationError; _statusTooltip = Constants.TooltipCommunicationError; } else if (memcachedFileVersion != null && memcachedFileVersion != _version) { _statusIconIndex = StatusIconIndex.NeedsUpdate; _statusTooltip = Constants.TooltipNeedsUpdate; } else { _statusIconIndex = StatusIconIndex.Up; _statusTooltip = Constants.TooltipUp; } }