Ejemplo n.º 1
0
        public StorageManager(IStorageContext storage, IWebHostConfiguration configuration, IWebScheduler scheduler)
        {
            this.scheduler = scheduler;
            this.interval  = AdvConvert.ConvertToTimeSpan(configuration.Storage.Interval);
            foreach (StorageAreaElement areaConfig in configuration.Storage.Items)
            {
                IStorageAreaConfigurator areaConfigurator = storage.Configure.Area(areaConfig.Name);
                if (!areaConfig.History)
                {
                    continue;
                }

                areaConfigurator.EnableHistory();
                if (string.IsNullOrEmpty(areaConfig.HistoryAge))
                {
                    continue;
                }

                TimeSpan historyAge = AdvConvert.ConvertToTimeSpan(areaConfig.HistoryAge);
                if (historyAge <= TimeSpan.Zero)
                {
                    continue;
                }

                cleaners.Add(areaConfig.Name, new StorageHistoryCleaner(
                                 new Lazy <IStorageAreaHistory>(() => storage.Area(areaConfig.Name).History),
                                 historyAge));
            }
        }
Ejemplo n.º 2
0
        private DateTime?ParseOptionalDateTime(string value, DateTime now)
        {
            if (value == null || value == "*")
            {
                return(null);
            }

            if (value.Equals("NULL", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }

            if (value.Equals("NOW", StringComparison.InvariantCultureIgnoreCase))
            {
                return(now);
            }

            if (value.Equals("TODAY", StringComparison.InvariantCultureIgnoreCase))
            {
                return(now.Date);
            }

            if (value.StartsWith("+"))
            {
                return(now.Add(AdvConvert.ConvertToTimeSpan(value.Substring(1))));
            }

            if (value.StartsWith("-"))
            {
                return(now.Subtract(AdvConvert.ConvertToTimeSpan(value.Substring(1))));
            }

            if (value.StartsWith("NOW+", StringComparison.InvariantCultureIgnoreCase))
            {
                return(now.Add(AdvConvert.ConvertToTimeSpan(value.Substring(4))));
            }

            if (value.StartsWith("NOW-", StringComparison.InvariantCultureIgnoreCase))
            {
                return(now.Subtract(AdvConvert.ConvertToTimeSpan(value.Substring(4))));
            }

            if (value.StartsWith("TODAY+", StringComparison.InvariantCultureIgnoreCase))
            {
                return(now.Date.Add(AdvConvert.ConvertToTimeSpan(value.Substring(6))));
            }

            if (value.StartsWith("TODAY-", StringComparison.InvariantCultureIgnoreCase))
            {
                return(now.Date.Subtract(AdvConvert.ConvertToTimeSpan(value.Substring(6))));
            }

            return(DateTime.Parse(value, CultureInfo.InvariantCulture));
        }
Ejemplo n.º 3
0
        public ILogger Create()
        {
            if (configuration.Diagnostics?.Performance == null)
            {
                return(new NullLogger());
            }

            PerformanceConfiguration config = configuration.Diagnostics.Performance;
            var writer = new QueuingTraceWriter(resolver.MapPath(config.Path), AdvConvert.ConvertToByteCount(config.MaxSize), config.MaxFiles, config.Zip);

            return(new HighPrecisionLogger(new TraceEventCollector(writer), customDataProviderManager.Providers));
        }
Ejemplo n.º 4
0
        //TODO: To many dependencies, refactor!
        public StorageIndexManager(IStorageIndex index, IStorageContext storage, IWebHostConfiguration configuration, IWebScheduler scheduler, IInitializationTracker tracker, IDiagnosticsLogger logger)
        {
            this.index     = index;
            this.debugging = configuration.Index.Debugging;
            if (this.debugging)
            {
                this.index.Writer.InfoEvent += (sender, args) => logger.Log("indexdebug", Severity.Critical, args.Message, new { args });
            }
            this.scheduler = scheduler;
            this.tracker   = tracker;
            this.logger    = logger;
            interval       = TimeSpan.FromSeconds(configuration.Index.Watch.Interval);

            if (!string.IsNullOrEmpty(configuration.Index.Watch.RamBuffer))
            {
                buffer = (int)AdvConvert.ConvertToByteCount(configuration.Index.Watch.RamBuffer) / (1024 * 1024);
            }

            watchers = configuration.Index.Watch.Items
                       .ToDictionary(we => we.Area, we => (IStorageIndexChangeLogWatcher)
                                     new StorageChangeLogWatcher(we.Area, storage.Area(we.Area).Log, we.BatchSize < 1 ? configuration.Index.Watch.BatchSize : we.BatchSize, logger, InfoStream));
        }