Example #1
0
        private void Initialize(string url)
        {
            _serializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = new JsonConverter[]
                {
                    new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter(),
                    new MaintenanceJsonConverter()
                }
            };

            Check.IsNotNullOrWhiteSpace(url, "ZabbixApi.url");

            _url        = url;
            _webClient  = new WebClient();
            _httpClient = new HttpClient();

            Actions            = new ActionService(this);
            Alerts             = new AlertService(this);
            ApiInfo            = new ApiInfoService(this);
            Applications       = new ApplicationService(this);
            Correlations       = new CorrelationService(this);
            DiscoveredHosts    = new DiscoveredHostService(this);
            DiscoveredServices = new DiscoveredServiceService(this);
            DiscoveryChecks    = new DiscoveryCheckService(this);
            DiscoveryRules     = new DiscoveryRuleService(this);
            Events             = new EventService(this);
            GraphItems         = new GraphItemService(this);
            GraphPrototypes    = new GraphPrototypeService(this);
            Graphs             = new GraphService(this);
            History            = new HistoryService(this);
            HostGroups         = new HostGroupService(this);
            HostInterfaces     = new HostInterfaceService(this);
            HostPrototypes     = new HostPrototypeService(this);
            Hosts               = new HostService(this);
            IconMaps            = new IconMapService(this);
            ServiceService      = new ServiceService(this);
            Images              = new ImageService(this);
            ItemPrototypes      = new ItemPrototypeService(this);
            Items               = new ItemService(this);
            LLDRules            = new LLDRuleService(this);
            Maintenance         = new MaintenanceService(this);
            Maps                = new MapService(this);
            MediaTypes          = new MediaTypeService(this);
            Proxies             = new ProxyService(this);
            ScreenItems         = new ScreenItemService(this);
            Screens             = new ScreenService(this);
            Scripts             = new ScriptService(this);
            TemplateScreenItems = new TemplateScreenItemService(this);
            TemplateScreens     = new TemplateScreenService(this);
            Templates           = new TemplateService(this);
            TriggerPrototypes   = new TriggerPrototypeService(this);
            Triggers            = new TriggerService(this);
            UserGroups          = new UserGroupService(this);
            GlobalMacros        = new GlobalMacroService(this);
            HostMacros          = new HostMacroService(this);
            Users               = new UserService(this);
            ValueMaps           = new ValueMapService(this);
        }
        public ModifyLecturerViewModel(Lecturer lecturer)
        {
            if (lecturer != null)
            {
                LecturerId   = lecturer.Id;
                Name         = lecturer.FirstName;
                Skill        = lecturer.Skill;
                Surname      = lecturer.LastName;
                Patronymic   = lecturer.MiddleName;
                UserName     = lecturer.User.UserName;
                Avatar       = lecturer.User.Avatar;
                SkypeContact = lecturer.User.SkypeContact;
                Phone        = lecturer.User.Phone;
                About        = lecturer.User.About;
                Email        = lecturer.User.Email;

                IsSecretary = lecturer.IsSecretary;
                IsLecturerHasGraduateStudents = lecturer.IsLecturerHasGraduateStudents;

                var groups = CorrelationService.GetCorrelation("Group", lecturer.Id);
                if (lecturer.SecretaryGroups != null)
                {
                    Groups = new MultiSelectList(groups, "Id", "Name", lecturer.SecretaryGroups.Select(x => x.Id).ToList());
                }
            }
        }
        public void WhenHeaderIsPresentExistingCorrelationContextIsAvailable()
        {
            var httpContext = new DefaultHttpContext
            {
                RequestServices = new Moq.Mock <IServiceProvider>().Object
            };
            var header = "eyJpZCI6ImNvcnJlbGF0aW9uaWQiLAoic291cmNlSWQiOiIxIiwKInNvdXJjZU5hbWUiOiJ0ZXN0bmFtZSIsCiJpbnN0YW5jZUlkIjoiMiIsCiJpbnN0YW5jZU5hbWUiOiJ0ZXN0aW5zdGFuY2UiLAp1c2VySWQiOiJ1bmtvd251c2VyIiwKImlwQWRkcmVzcyI6IjEyMy4xMjMuMTIzLjEyMyJ9";

            httpContext.Request.Headers.Add(CorrelationHeader.Key, header);

            var httpContextAccessor = new Moq.Mock <IHttpContextAccessor>();

            httpContextAccessor.SetupProperty <HttpContext>(x => x.HttpContext, httpContext);
            var applicationContext          = new Moq.Mock <IApplicationContext>().Object;
            var logger                      = new Moq.Mock <ILogger <CorrelationService> >().Object;
            var correlationContextFormatter = new Moq.Mock <ICorrelationContextFormatter>();

            correlationContextFormatter.Setup(x => x.ValidateAndSetPropertiesFromDgpHeader(header)).Returns(new CorrelationContext {
                DgpHeader = header
            });
            var correlationContext = new Moq.Mock <IScopedCorrelationContext>().Object;

            var service = new CorrelationService(httpContextAccessor.Object, applicationContext, logger, correlationContextFormatter.Object, correlationContext);
            var context = service.GetContext();


            Assert.Equal(header, context.DgpHeader);
        }
        public async Task InvokeAsync(
            HttpContext context,
            ILogger <UnknownErrorCatchMiddleware> logger,
            CorrelationService correlationService)
        {
            try
            {
                await next.Invoke(context);
            }
            catch (Exception ex)
            {
                logger.LogError(ex,
                                $"{correlationService.CorrelationId} - Unknown error occured while processing your request");

                context.Response.StatusCode  = StatusCodes.Status500InternalServerError;
                context.Response.ContentType = "application/json";
                if (env.IsDevelopment())
                {
                    context.Response.Body.Write(JsonConvert.SerializeObject(ex, new JsonSerializerSettings
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    }).Select(x => (byte)x).ToArray());
                }
                else
                {
                    throw;
                }
            }
        }
 public TreeRecognitionDbProvider(
     TreeRecognitionDbContext databaseContext,
     CorrelationService correlationService,
     ILogger <BaseDatabaseProvider <TreeRecognitionDbContext> > logger) : base(databaseContext, logger,
                                                                               correlationService.CorrelationId)
 {
     this.logger   = logger;
     correlationId = correlationService.CorrelationId;
 }
        public ImageManager(
            ITreeRecognitionDbProvider dbProvider,
            IHttpProvider httpProvider,
            ILogger <ImageManager> logger,
            CorrelationService correlationService)
        {
            this.logger       = logger;
            this.dbProvider   = dbProvider;
            this.httpProvider = httpProvider;

            correlationId = correlationService.CorrelationId;
        }
Example #7
0
        public RootController(
            ILogger <RootController> logger,
            IImageManager manager,
            CorrelationService correlationService,
            IOptions <Urls> urlsOptions,
            IOptions <Paths> pathsOptions)
        {
            this.urlsOptions  = urlsOptions;
            this.pathsOptions = pathsOptions;
            this.manager      = manager;
            this.logger       = logger;

            correlationId = correlationService.CorrelationId;
        }
        public void WhenDuplicateHeaderCorrelationContextIsCreated()
        {
            var httpContext = new DefaultHttpContext
            {
                RequestServices = new Moq.Mock <IServiceProvider>().Object
            };

            var httpContextAccessor = new Moq.Mock <IHttpContextAccessor>();

            httpContextAccessor.SetupProperty <HttpContext>(x => x.HttpContext, httpContext);
            var applicationContext          = new Moq.Mock <IApplicationContext>().Object;
            var logger                      = new TestLogger <CorrelationService>(new List <string>());
            var correlationContextFormatter = new Moq.Mock <ICorrelationContextFormatter>();

            var service = new CorrelationService(httpContextAccessor.Object, applicationContext, logger, correlationContextFormatter.Object);
            var context = service.GetContext();

            Assert.NotNull(context.DgpHeader);
            Assert.NotNull(context.Id);
        }
 public ModifyLecturerViewModel()
 {
     Groups = new MultiSelectList(new List <Correlation>(CorrelationService.GetCorrelation("Group", null)), "Id", "Name");
 }
Example #10
0
 public HttpProvider(ILogger <HttpProvider> logger, CorrelationService correlationService)
 {
     this.logger   = logger;
     correlationId = correlationService.CorrelationId;
 }
Example #11
0
        public async Task InvokeAsync(HttpContext context, ILogger <CommonSqlErrorCatchMiddleware> logger, CorrelationService correlationService)
        {
            try
            {
                await next.Invoke(context);
            }
            catch (FlurlHttpException ex)
            {
                logger.LogError(ex, $"{correlationService.CorrelationId} - Error while communicating with DeepLearning API");

                context.Response.StatusCode = StatusCodes.Status500InternalServerError;
            }
        }