Ejemplo n.º 1
0
        public async Task GetServicesTask()
        {
            var serviceInstances = await ServiceProcessor.GetServices(Assembly.GetExecutingAssembly());

            Assert.True(serviceInstances.Any());
            Assert.True(serviceInstances.All(item => item is IPromDapterService));
        }
Ejemplo n.º 2
0
        private async Task initServiceCache()
        {
            string       prefix;
            var          configuredPrefix = Configuration?["PrometheusMetricPrefix"];
            const string defaultPrefix    = "hwi_";

            if (String.IsNullOrEmpty(configuredPrefix))
            {
                _logger.LogWarning($"No prefix defined in configuration; defaulting to {defaultPrefix}");
                prefix = defaultPrefix;
            }
            else
            {
                prefix = configuredPrefix;
            }

            var serviceProcessor = new ServiceProcessor();

            serviceProcessor.InitializeProcessors(prefix);
            Prefix = prefix;

            ServiceProcessor = serviceProcessor;
            var services = await ServiceProcessor.GetServices(Assembly.GetExecutingAssembly());

            Services = services;
            _logger?.Log(LogLevel.Information, "Cache Initialized");
        }
Ejemplo n.º 3
0
        static int Main(string[] args)
        {
            if (args.Length > 0)
            {
                ServiceProcessor objServiceProcessor = new ServiceProcessor(objSettigns, log);
                IEnumerator      ServiceEnum         = objServiceProcessor.GetEnumerator();
                while (ServiceEnum.MoveNext())
                {
                    ServiceProcessor.NTService service = ((ServiceProcessor.NTService)ServiceEnum.Current);

                    bool blnFound = false;
                    foreach (string strServiceName in args)
                    {
                        if (strServiceName == service.strServiceName)
                        {
                            blnFound = true;
                            break;
                        }
                    }

                    if (blnFound)
                    {
                        service.StatusBefore = ServiceControllerStatus.Running;
                    }
                }
                return(objServiceProcessor.Restore()?0:1);
            }
            else
            {
                System.Console.WriteLine("Usage: Utilities.Hotfix.StartService <list> ");
                System.Console.WriteLine("	     <list>  - list of space separeted service names from hotfix.xml");
                System.Console.WriteLine("	               Service name is case sensitive.");
            }
            return(1);
        }
 public async Task <IActionResult> HandleServiceRequest([FromRoute] string address, ServiceType type)
 {
     _logger.LogInformation($"Processing {type} for {address}");
     try
     {
         // not a fan of the controller having to know the specific
         // types for search service
         return(type switch
         {
             ServiceType.GeoIP => new OkObjectResult(await ServiceProcessor.Process <GeoIpModel>(address, type)),
             ServiceType.RDAP => new OkObjectResult(await ServiceProcessor.Process <RdapModel>(address, type)),
             ServiceType.ReverseDNS =>
             new OkObjectResult(await ServiceProcessor.Process <IPHostEntry>(address, type)),
             ServiceType.SslLabs => new OkObjectResult(
                 await ServiceProcessor.Process <SslLabsModel>(address, type)),
             ServiceType.Ping => new OkObjectResult(await ServiceProcessor.Process <PingModel>(address, type)),
             _ => new BadRequestObjectResult(new ServiceResult <string>
             {
                 Status = ServiceStatus.Bad,
                 Type = type,
                 ErrorMessage = $"Invalid type passed in. Expected a {nameof(ServiceType)} but got {type}",
                 WorkerId = Environment.MachineName,
             })
         });
     }
Ejemplo n.º 5
0
        public async Task should_catch_on_unknown_service()
        {
            var actual = await ServiceProcessor.Process <object>("calebukle.com", (ServiceType)50);

            Assert.IsNotNull(actual.ErrorMessage);
            Assert.AreEqual(ServiceStatus.Error, actual.Status);
        }
Ejemplo n.º 6
0
        public void should_normalize_ip()
        {
            var expected = "1.1.1.1";
            var actual   = ServiceProcessor.NormalizeAddress("    1.1.1.1  ", out var actualType);

            Assert.AreEqual(AddressType.Ip, actualType);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void should_normalize_domain_name()
        {
            var expected = "calebukle.com";
            var actual   = ServiceProcessor.NormalizeAddress("https://calebukle.com", out var actualType);

            Assert.AreEqual(AddressType.DomainName, actualType);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        private async void FillServiceListBox()
        {
            lstService.Items.Clear();
            services = await ServiceProcessor.ShowAllServices(currentUser.Token);

            foreach (ServiceModel m in services)
            {
                lstService.Items.Add(m);
            }
        }
Ejemplo n.º 9
0
 public void ConfigureOutputGateway_True()
 {
     _subject = new ServiceProcessor(_mockIdentification.Object,
                                     _mockInputGateway.Object,
                                     _mockHandlerRepository.Object,
                                     _messageBuilder.Object,
                                     ReinjectionEngineFactory.CreateDefaultEngine(_mockInputGateway.Object));
     _subject.ConfigureOutputGateway(_mockOutputGateway.Object);
     Assert.AreEqual(_subject.Status, ProcessorStatus.Configured);
 }
Ejemplo n.º 10
0
 public void ConfigureOutputGateway_True()
 {
     _subject = new ServiceProcessor(_mockIdentification.Object,
                                     _mockInputGateway.Object,
                                     _mockHandlerRepository.Object,
                                     _messageBuilder.Object,
                                     ReinjectionEngineFactory.CreateDefaultEngine(_mockInputGateway.Object));
     _subject.ConfigureOutputGateway(_mockOutputGateway.Object);
     Assert.AreEqual(_subject.Status, ProcessorStatus.Configured);
 }
Ejemplo n.º 11
0
        public async Task <ContentResult> Get(string filter = null, string option = null)
        {
            bool allowedAccess = await Semaphore.WaitAsync(3000);

            if (!allowedAccess)
            {
                return(Content("Semaphore failed"));
            }
            try
            {
                var  prefix        = Prefix;
                bool isResetFilter = filter == ResetFilterName;
                bool isJsonFilter  = filter == JsonFilterName;
                if (isResetFilter)
                {
                    Prefix           = null;
                    ServiceProcessor = null;
                    _logger?.Log(LogLevel.Information, "Cache Reset");
                    return(Content("Resetted"));
                }

                if (ServiceProcessor == null)
                {
                    await initServiceCache();
                }

                ContentResult content = null;
                if (isJsonFilter)
                {
                    content = await getJsonContent(option);
                }
                else
                {
                    content = await getPrometheusContent(filter);
                }

                return(content);
            }
            catch (Exception ex)
            {
                ServiceProcessor = null;
                Prefix           = null;
                _logger.LogCritical(ex, "Unhandled error");
                if (filter == DebugFilterName)
                {
                    var content = Content(ex.ToString());
                    return(content);
                }
                throw;
            }
            finally
            {
                Semaphore.Release();
            }
        }
        public WebsocketClientObject(IWebSocketConnection connection)//TcpClient tcpClient)//Socket tcpClient)
        {
            //client = tcpClient;
            _applicationProcessor = new ServiceProcessor(UserLoggedIn);
            // _accumulator = new List<byte>();
            _connection = connection;

            _connection.OnMessage = message => { DeconstructPacketAndProcess(message); };
            _connection.OnClose   = () => { Close(); };

            ServiceProcessor.UserLoggedIn userLoggedInAction = UserLoggedIn;
        }
Ejemplo n.º 13
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            services = await ServiceProcessor.ShowAllServices(currentUser.Token);

            foreach (ServiceModel m in services)
            {
                if (m.ServiceName == selectedOrder.ServiceName)
                {
                    txtPrice.Text = m.Price;
                }
            }
        }
Ejemplo n.º 14
0
        public bool TestStartServices()
        {
            ServiceProcessor objServiceProcessor = new ServiceProcessor(objSettigns, log);
            IEnumerator      ServiceEnum         = objServiceProcessor.GetEnumerator();

            while (ServiceEnum.MoveNext())
            {
                ServiceProcessor.NTService service = ((ServiceProcessor.NTService)ServiceEnum.Current);
                service.StatusBefore = ServiceControllerStatus.Running;
            }
            objServiceProcessor.Restore();
            return(true);
        }
Ejemplo n.º 15
0
 public async Task DataItemRegexPrometheusProcessorTest()
 {
     (string mimeType, object data)result = (null, null);
     for (int i = 0; i < 1000; i++)
     {
         var serviceProcessor = new ServiceProcessor();
         serviceProcessor.InitializeProcessors();
         var processor = serviceProcessor.DataItemRegexPrometheusProcessor;
         var service   = new HWiNFOProvider();
         result = await processor(service, null);
     }
     var metricDump = String.Join(Environment.NewLine, result);
 }
Ejemplo n.º 16
0
        public void Setup()
        {
            _mockIdentification    = new Mock <Identification>();
            _mockInputGateway      = new Mock <IInputGateway <IMessage, MessageHeader> >();
            _mockHandlerRepository = new Mock <IHandlerRepository>();
            _messageBuilder        = new Mock <IMessageBuilder>();

            _subject = ProcessorsFactory.CreateServiceProcessor(_mockIdentification.Object,
                                                                _mockInputGateway.Object,
                                                                _mockHandlerRepository.Object,
                                                                _messageBuilder.Object) as ServiceProcessor;

            _mockOutputGateway = new Mock <IOutputGateway <IMessage> >();
        }
Ejemplo n.º 17
0
        public void Setup()
        {
            _mockIdentification = new Mock<Identification>();
            _mockInputGateway = new Mock<IInputGateway<IMessage, MessageHeader>>();
            _mockHandlerRepository = new Mock<IHandlerRepository>();
            _messageBuilder = new Mock<IMessageBuilder>();

            _subject = ProcessorsFactory.CreateServiceProcessor(_mockIdentification.Object,
                                _mockInputGateway.Object,
                                _mockHandlerRepository.Object,
                                _messageBuilder.Object) as ServiceProcessor;

            _mockOutputGateway = new Mock<IOutputGateway<IMessage>>();
        }
        internal async Task <bool> TryProcessRoute(HttpContext httpContext)
        {
            var httpRequest = httpContext.Request;

            var path = httpRequest.Path.Value;

            if (!IsScenarioRoute(path, out var processorName, out var actionName))
            {
                return(false);
            }

            var serviceProcessor = ServiceProcessor.CreateProcessor(_serviceProvider, processorName);

            return(await serviceProcessor.Process(httpContext, actionName));
        }
Ejemplo n.º 19
0
        public bool TestServiceProcessor()
        {
            ServiceProcessor objServiceProcessor = new ServiceProcessor(objSettigns, log);

            objServiceProcessor.Stop();
            objServiceProcessor.Restore();
            objServiceProcessor.Stop();
            objServiceProcessor.Restore();
            objServiceProcessor.Stop();
            objServiceProcessor.Restore();
            objServiceProcessor.Stop();
            objServiceProcessor.Restore();
            objServiceProcessor.Stop();
            objServiceProcessor.Restore();
            return(true);
        }
Ejemplo n.º 20
0
        public async Task ServiceProcessorMemoryLeakTestHWInfo()
        {
            (string mimeType, object data)result = (null, null);
            for (int i = 0; i < 10000; i++)
            {
                var serviceProcessor = new ServiceProcessor();
                serviceProcessor.InitializeProcessors();
                var processor = serviceProcessor.DataItemRegexPrometheusProcessor;
                var service   = new HWiNFOProvider();
                result = await processor(service, null);

                Debug.WriteLine($"Current loop: {i}");
            }
            var textDump   = result.data?.ToString();
            var metricDump = String.Join(Environment.NewLine, textDump);
        }
Ejemplo n.º 21
0
        // This function will get triggered/executed when a new message is written
        // on an Azure Queue called queue.

        // Test throwing exception and make sure item does not get dequeued.
        // TODO: Add conversion library of odin to servicengineimporter objects

        public async Task ProcessQueueMessage([QueueTrigger("odintose")] string message, int dequeueCount, TextWriter log)
        {
            log.WriteLine(message);
            if (dequeueCount >= MaxQueueCount)
            {
                log.WriteLine("Hit Max dequeue count");
                return;
            }
            var queueEntry = JsonConvert.DeserializeObject <OdinToSeQueueEntry>(message);

            if (queueEntry.QueueTypeId == (int)QueueType.Service)
            {
                var serviceProcessor = new ServiceProcessor(_unitOfWork);
                var result           = await serviceProcessor.ProcessService(queueEntry.ObjectId, log);

                log.WriteLine($"Service Process Result: {result}");
            }
        }
Ejemplo n.º 22
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            DateTime serviceDate;

            try
            {
                serviceDate = (DateTime)apptDate.SelectedDate;
            }
            catch
            {
                MessageBox.Show("Please enter valid date");
                return;
            }
            string hour        = "0";
            string hours       = cmbHour.SelectedItem.ToString();
            String hoursResult = hours.Substring(hours.Length - 2);
            int    hoursTest   = int.Parse(hoursResult);

            if (cmbAMPM.SelectedIndex == 1)
            {
                if (cmbHour.SelectedIndex <= 2)
                {
                    MessageBox.Show("Please select an appropriate time.");
                    return;
                }
                if (cmbHour.SelectedIndex == 3)
                {
                    hoursTest = 12;
                }
                else
                {
                    hoursTest += 12;
                }

                hour = hoursTest.ToString();
            }
            else
            {
                if (cmbHour.SelectedIndex >= 3)
                {
                    MessageBox.Show("Please select a valid time");
                    return;
                }
                if (cmbHour.SelectedIndex == 0)
                {
                    hour = "09";
                }
                else if (cmbHour.SelectedIndex == 1)
                {
                    hour = "10";
                }
                else if (cmbHour.SelectedIndex == 2)
                {
                    hour = "11";
                }
            }
            string minutes       = cmbMinutes.SelectedItem.ToString();
            String minutesResult = minutes.Substring(minutes.Length - 2);
            string totalTime     = hour + ":" + minutesResult + ":00";
            string totalDate     = serviceDate.ToString("yyyy-MM-dd") + " " + totalTime;

            try
            {
                ServiceProcessor.SubmitOrder(selectedUser.UserID, selectedService.ServiceID, totalDate, currentUser.Token);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.Close();
        }
Ejemplo n.º 23
0
 public void should_throw_on_unknown_address()
 {
     Assert.Throws <ArgumentException>(() => ServiceProcessor.NormalizeAddress(string.Empty, out var type));
 }