Пример #1
0
        public async Task <Service> GetServiceAsync(Uri applicationName, Uri serviceName)
        {
            try
            {
                string      key      = "Services-" + applicationName.ToString();
                ServiceList services = this.cache[key] as ServiceList;

                if (services == null)
                {
                    services = await this.GetServicesAsync(applicationName);

                    this.cache.Set(new CacheItem(key, services), new CacheItemPolicy()
                    {
                        AbsoluteExpiration = DateTimeOffset.UtcNow + this.cacheDuration
                    });
                }

                return(services.FirstOrDefault(x => x.ServiceName == serviceName));
            }
            catch (FabricObjectClosedException)
            {
                return(null);
            }
        }
Пример #2
0
        private void OnServiceUpdate(object sender, EventArgs e)
        {
            Console.WriteLine("Atualizando lista de serviços WMI");

            try
            {
                string query;
                if (ServiceFilter != null)
                {
                    query = $"{_serviceQuery} WHERE DisplayName LIKE '%{ServiceFilter}%'";
                }
                else
                {
                    query = _serviceQuery;
                }

                AllServices = Session.QueryInstances(@"root\cimv2", "WQL", query);


                if (ServiceList.Count() > 0)
                {
                    //Loop through all services
                    foreach (CimInstance oneService in AllServices)
                    {
                        Services s       = CimInstanceConvert(oneService);
                        Services service = ServiceList.FirstOrDefault(i => i.Name == s.Name);

                        if (service.State != s.State)
                        {
                            service.Update(s);
                            string       subtitle;
                            PackIconKind icon;

                            switch (s.State)
                            {
                            case "Running":
                                subtitle = "Serviço foi inicializado";
                                icon     = PackIconKind.Notifications;
                                break;

                            case "Start Pending":
                                subtitle = "Serviço esta sendo inicializado";
                                icon     = PackIconKind.InfoCircle;
                                break;

                            case "Stopped":
                                subtitle = "Serviço foi parado";
                                icon     = PackIconKind.Dangerous;
                                break;

                            case "Stop Pending":
                                subtitle = "Serviço esta sendo parado";
                                icon     = PackIconKind.Warning;
                                break;

                            default:
                                subtitle = "Estado não encontrado";
                                icon     = PackIconKind.SackPercent;
                                break;
                            }

                            if (_enableNotification)
                            {
                                _notifier.ShowNotification(s.DisplayName, subtitle, icon, s.State, null, declineAction: n => CloseNotification(n));
                            }
                        }
                    }
                }
                else
                {
                    //Loop through all services
                    foreach (CimInstance oneService in AllServices)
                    {
                        Services s = CimInstanceConvert(oneService);
                        ServiceList.Add(s);
                    }
                }

                IsLoading   = false;
                IsConnected = true;
            }
            catch (Exception ex)
            {
                IsConnected = false;
                IsLoading   = false;
                snackMessageQueue.Enqueue(ex.Message);
                SnackbarNotify.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D20101"));
                _task.Stop();
                //ServiceList.Clear();
                log.Error(ex.Message);
            }
        }
        private static async Task <Service> FindExistingServiceAsync(FabricClient client, Uri serviceUri)
        {
            ServiceList services = await client.QueryManager.GetServiceListAsync(GetApplicationUri());

            return(services.FirstOrDefault(s => s.ServiceName.AbsolutePath.Contains(serviceUri.LocalPath)));
        }