示例#1
0
        public UIService(ConfigurationItems configurationItems, CommandService commandService,
                         ExecutionService executionService, TelnetService telnetService)
        {
            _telnetService = telnetService;
            var entryAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly();

            _systemId = entryAssembly.GetName().Name;
            Thread.CurrentThread.Name = _systemId;
            _trayContainer            = new Container();
            _notifyIcon = new NotifyIcon(_trayContainer)
            {
                ContextMenuStrip = new ContextMenuStrip(),
                Icon             = GetIcon(entryAssembly, configurationItems.IconName),
                Text             = _systemId,
                Visible          = true
            };
            _notifyIcon.ContextMenuStrip.Opening += Context_OnMenuOpen;
            _notifyIcon.DoubleClick += Context_TrayIcon_OnDoubleClick;
            _notifyIcon.ContextMenuStrip.Items.Clear();
            _connectionCountTimer = new Timer {
                Enabled = _telnetService != null, Interval = 1000
            };
            _connectionCountTimer.Tick += Timer_ConnectionCount;
            _exitTimer = new Timer {
                Enabled = false, Interval = 500
            };
            _exitTimer.Tick += Timer_Exit;
            commandService.Init();
            executionService.Init();
        }
示例#2
0
        public async Task OnProjectChanged_ReadsProperties_InitializesProject()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            DocumentItems.Item("File.cshtml");
            DocumentItems.Property("File.cshtml", Rules.RazorGenerateWithTargetPath.TargetPathProperty, "File.cshtml");

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                DocumentItems.ToChange(),
            };

            var services = new TestProjectSystemServices("c:\\MyProject\\Test.csproj");

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("c:\\MyProject\\Test.csproj", snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions,
                e => Assert.Equal("MVC-2.1", e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName));

            Assert.Collection(
                snapshot.DocumentFilePaths.OrderBy(d => d),
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal("c:\\MyProject\\File.cshtml", document.FilePath);
                Assert.Equal("File.cshtml", document.TargetPath);
            });

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
示例#3
0
        public ElasticConnection(ConfigurationItems configurationItems)
        {
            var pool    = new StaticConnectionPool(BuildServerList(configurationItems.ElasticHostsAndPorts).ToArray());
            var setting = new ConnectionSettings(pool);

            _logger        = Log.Logger.ForContext <ElasticConnection>();
            _elasticClient = new ElasticClient(setting);
        }
 public CustomSchedulerFactory(string jobName, string groupName, string triggerName, ConfigurationItems configurationItems)
 {
     _jobName            = jobName;
     _groupName          = groupName;
     _triggerName        = triggerName;
     _configurationItems = configurationItems;
     _factory            = new StdSchedulerFactory();
 }
        public async Task OnProjectRenamed_RemovesHostProject_CopiesConfiguration()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            RazorComponentWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath));
            RazorComponentWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectComponentFile1.TargetPath);

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));
            RazorGenerateWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectFile1.TargetPath);

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal(TestProjectData.SomeProject.FilePath, snapshot.FilePath);
            Assert.Same("MVC-2.1", snapshot.Configuration.ConfigurationName);

            // Act - 2
            services.UnconfiguredProject.FullPath = TestProjectData.AnotherProject.FilePath;
            await Task.Run(async() => await host.OnProjectRenamingAsync());

            // Assert - 1
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal(TestProjectData.AnotherProject.FilePath, snapshot.FilePath);
            Assert.Same("MVC-2.1", snapshot.Configuration.ConfigurationName);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
        public static ConfigurationItems GetSettings(IConfigurationRoot configurationRoot)
        {
            var configurationItems = new ConfigurationItems
            {
                IconName   = configurationRoot.GetSection("Application")["IconName"] ?? string.Empty,
                UseLogging = bool.Parse(configurationRoot.GetSection("Application")["Logging"] ?? "false"),
                Messaging  =
                    new MessagingSettings
                {
                    UseLocalPipeline =
                        bool.Parse(configurationRoot.GetSection("Messaging")["UseLocalPipeline"] ?? "true")
                }
            };
            var uniqueEndPoints = new List <string>();
            var apiEndPoints    = configurationRoot.GetSection("RestApi").Get <string[]>();

            if (apiEndPoints != null)
            {
                foreach (var apiEndPoint in apiEndPoints)
                {
                    var ipEndPoint     = AddressParser.ParseEndPointConfiguration(apiEndPoint, 5000);
                    var uniqueEndPoint = ipEndPoint.ToString();
                    if (uniqueEndPoints.Contains(uniqueEndPoint))
                    {
                        continue;
                    }
                    uniqueEndPoints.Add(uniqueEndPoint);
                    configurationItems.ApiEndPoints.Add(ipEndPoint);
                }
            }
            var telnetEndPoints = configurationRoot.GetSection("Telnet").Get <string[]>();

            if (telnetEndPoints != null)
            {
                foreach (var telnetEndPoint in telnetEndPoints)
                {
                    var ipEndPoint     = AddressParser.ParseEndPointConfiguration(telnetEndPoint, 4000);
                    var uniqueEndPoint = ipEndPoint.ToString();
                    if (uniqueEndPoints.Contains(uniqueEndPoint))
                    {
                        continue;
                    }
                    uniqueEndPoints.Add(uniqueEndPoint);
                    configurationItems.TelnetEndPoints.Add(ipEndPoint);
                }
            }
            configurationRoot.GetSection("Messaging:EndPoints")
            .GetChildren()
            .ToList()
            .ForEach(item => { _ = configurationItems.Messaging.EndPoints.TryAdd(item.Key, item.Value); });
            return(configurationItems);
        }
 public TelnetService(ILogger <TelnetService> logger, MessageService messageService,
                      ConfigurationItems configurationItems, CancellationTokenSource cancellationTokenSource)
 {
     _logger = logger;
     _cancellationTokenSource = cancellationTokenSource;
     _initialCommunication    = new byte[]
     { 255, 251, 1, 255, 253, 3, 255, 252, 34, 255, 251, 201, 255, 249 };
     if (!configurationItems.TelnetEndPoints.Any())
     {
         _shuttingDown = true;
         return;
     }
     _messageService = messageService;
     _messageService.RegisterReceiveToClients("TelnetService", ReceiveToClientsMessage);
 }
示例#8
0
        /// <summary>
        /// Get a configuration record from the respository by folder and id
        /// </summary>
        /// <param name="folderPath">Folder of the configuration record</param>
        /// <param name="id">Id of the configuration record</param>
        public virtual async Task <TModel> Get(string folderPath, TKey id)
        {
            if (id.Equals(default(TKey)))
            {
                throw new ArgumentNullException(nameof(id));
            }
            //Ensure the repository is initialised before retreiving item
            await _readyTask.ConfigureAwait(false);

            if (ConfigurationItems.TryGetValue(CreateEtcdKey(folderPath, id), out TModel configurationItem))
            {
                return(configurationItem);
            }
            return(null);
        }
示例#9
0
        internal static ImmutableArray <KeyValueConfigurationItem> ReadConfiguration(
            [NotNull] this ConfigurationItems configurationItems)
        {
            if (configurationItems is null)
            {
                throw new ArgumentNullException(nameof(configurationItems));
            }

            var keyValueConfigurationItems = configurationItems.Keys
                                             .Select(
                keyValue => new KeyValueConfigurationItem(keyValue.Key,
                                                          keyValue.Value,
                                                          keyValue.ConfigurationMetadata))
                                             .ToImmutableArray();

            return(keyValueConfigurationItems);
        }
        public CustomSchedulerFactory(string jobName, string groupName, string triggerName, int delay, int runsEvery,
                                      ConfigurationItems configurationItems)
        {
            _logger = Log.Logger.ForContext <CustomSchedulerFactory <T> >();

            _logger.Information("Generate Scheduler with Values: ");
            _logger.Information($"JobName: {jobName}");
            _logger.Information($"GroupName: {groupName}");
            _logger.Information($"TriggerName: {triggerName}");
            _logger.Information($"RepeatInterval: {runsEvery} s");
            _logger.Information($"Start delay: {delay} s");
            _jobName            = jobName;
            _groupName          = groupName;
            _triggerName        = triggerName;
            _configurationItems = configurationItems;
            _runsEvery          = runsEvery;
            _delay   = delay;
            _factory = new StdSchedulerFactory();
        }
        public async Task OnProjectChanged_NoVersionFound_DoesNotIniatializeProject()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "");

            ConfigurationItems.Item("TestConfiguration");

            ExtensionItems.Item("TestExtension");

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
示例#12
0
        public async Task OnProjectChanged_NoVersionFound_DoesNotIniatializeProject()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "");

            ConfigurationItems.Item("TestConfiguration");

            ExtensionItems.Item("TestExtension");

            DocumentItems.Item("File.cshtml");

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                DocumentItems.ToChange(),
            };

            var services = new TestProjectSystemServices("c:\\MyProject\\Test.csproj");

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
示例#13
0
 public MessageService(ILogger <MessageService> logger, ConfigurationItems configurationItems,
                       CancellationTokenSource cancellationTokenSource)
 {
     _logger = logger;
     _cancellationTokenSource = cancellationTokenSource;
     _messagingSettings       = configurationItems.Messaging;
     _fromClientSerializer    = new Serializer <FromClient>();
     _toClientsSerializer     = new Serializer <ToClients>();
     _receiveFromClients      = new ConcurrentDictionary <string, Action <FromClient> >(StringComparer.Ordinal);
     _receiveToClients        = new ConcurrentDictionary <string, Action <ToClients> >(StringComparer.Ordinal);
     _commandClient           = new HttpClient();
     _commandClient.DefaultRequestHeaders.Accept.Clear();
     _commandClient.DefaultRequestHeaders.Accept.Add(
         new MediaTypeWithQualityHeaderValue("application/octet-stream"));
     if (configurationItems.Messaging.EndPoints.ContainsKey("FromClient"))
     {
         _fromClientEndPoint = configurationItems.Messaging.EndPoints["FromClient"];
     }
     if (configurationItems.Messaging.EndPoints.ContainsKey("ToClients"))
     {
         _toClientsEndPoint = configurationItems.Messaging.EndPoints["ToClients"];
     }
 }
示例#14
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var cancellationTokenSource           = new CancellationTokenSource();
            ConfigurationItems configurationItems = null;
            var webHost = WebHost.CreateDefaultBuilder()
                          .UseKestrel()
                          .ConfigureServices((context, services) =>
            {
                var configurationBuilder = new ConfigurationBuilder()
                                           .SetBasePath(context.HostingEnvironment.ContentRootPath)
                                           .AddJsonFile("appSettings.json", true, true)
                                           .AddEnvironmentVariables();
                var configuration  = configurationBuilder.Build();
                configurationItems = ConfigurationService.GetSettings(configuration);
                services.Configure <KestrelServerOptions>(options =>
                {
                    options.ConfigureEndpointDefaults(opt => { opt.NoDelay = true; });
                    foreach (var apiEndPoint in configurationItems.ApiEndPoints)
                    {
                        options.Listen(apiEndPoint);
                    }
                    foreach (var telnetEndPoint in configurationItems.TelnetEndPoints)
                    {
                        options.Listen(telnetEndPoint,
                                       builder => { builder.UseConnectionHandler <TelnetConnectionHandler>(); });
                    }
                });
                services.AddSingleton(cancellationTokenSource);
                services.AddSingleton(configurationItems);
                services.AddSingleton(typeof(MessageService));
                services.AddSingleton(typeof(CommandService));
                services.AddSingleton(typeof(ExecutionService));
                services.AddSingleton(typeof(TelnetService));
                services.AddSingleton(typeof(UIService));
            })
                          .ConfigureLogging((context, logging) =>
            {
                logging.ClearProviders();
                if (configurationItems != null && configurationItems.UseLogging)
                {
                    logging.AddDebug();
                }
            })
                          .Configure(app =>
            {
                var messageService = app.ApplicationServices.GetService <MessageService>();
                app.Run(async context =>
                {
                    context.Response.ContentType = "text/plain";
                    if (!context.Request.Path.HasValue || string.IsNullOrWhiteSpace(context.Request.Path.Value))
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                    else if (!context.Request.ContentLength.HasValue || context.Request.ContentLength == 0)
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    }
                    else
                    {
                        var clientMessageBytes = new byte[context.Request.ContentLength ?? 0];
                        await context.Request.Body.ReadAsync(clientMessageBytes, 0,
                                                             (int)context.Request.ContentLength, cancellationTokenSource.Token);
                        context.Response.StatusCode =
                            messageService.ReceiveMessage(context.Request.Path.Value, clientMessageBytes);
                    }
                });
            })
                          .Build();

            webHost.RunAsync(cancellationTokenSource.Token).ConfigureAwait(false);
            Application.Run(webHost.Services.GetService <UIService>());
            cancellationTokenSource.Cancel();
            webHost.WaitForShutdown();
            Environment.Exit(0);
        }
示例#15
0
        public async Task OnProjectChanged_AfterDispose_IgnoresUpdate()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            DocumentItems.Item("File.cshtml");
            DocumentItems.Property("File.cshtml", Rules.RazorGenerateWithTargetPath.TargetPathProperty, "File.cshtml");

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                DocumentItems.ToChange(),
            };

            var services = new TestProjectSystemServices("c:\\MyProject\\Test.csproj");

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("c:\\MyProject\\Test.csproj", snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions,
                e => Assert.Equal("MVC-2.1", e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName));

            // Act - 2
            await Task.Run(async() => await host.DisposeAsync());

            // Assert - 2
            Assert.Empty(ProjectManager.Projects);

            // Act - 3
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.0");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.0");
            ConfigurationItems.Item("MVC-2.0", new Dictionary <string, string>()
            {
                { "Extensions", "MVC-2.0;Another-Thing" },
            });

            changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(changes[0].After),
                ConfigurationItems.ToChange(changes[1].After),
                ExtensionItems.ToChange(changes[2].After),
                DocumentItems.ToChange(changes[3].After),
            };

            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 3
            Assert.Empty(ProjectManager.Projects);
        }
示例#16
0
        public async Task Process(ConfigurationItems configuration)
        {
            var sw = Stopwatch.StartNew();

            try
            {
                _logger.Information("try to read weatherinformations");
                var locationList =
                    (await _locationFileReader.ReadLocationsAsync(configuration.PathToLocationsMap)).ValueOr(
                        new List <string>());
                _logger.Information($"read the list of locations with {locationList.Count} entries");
                var rootTasksOption = _processingBaseImplementations
                                      .ConvertToParallelQuery(locationList, configuration.Parallelism)
                                      .Select(async location =>
                {
                    _logger.Information($"get weather information for configured {location}");
                    var url =
                        $"https://api.openweathermap.org/data/2.5/weather?{location}&APPID={configuration.OwmApiKey}&units=metric";
                    return(await _owmApiReader.ReadDataFromLocationAsync(url, location));
                });

                var rootOptions = (await Task.WhenAll(rootTasksOption)).Values();

                var rootStrings = _processingBaseImplementations
                                  .ConvertToParallelQuery(rootOptions, configuration.Parallelism)
                                  .Select(async rootString =>
                                          await _processingBaseImplementations.DeserializeObjectAsync <CurrentWeatherBase>(rootString));


                var readTime = DateTime.Now;
                _logger.Information($"define document timestamp for elastic is {readTime}");
                var toElastic = (await Task.WhenAll(rootStrings))
                                .Values()
                                .Select(item =>
                {
                    item.ReadTime = readTime;
                    item.Guid     = Guid.NewGuid();
                    return(item);
                });

                var concurrentBag = new ConcurrentBag <CurrentWeatherBase>(toElastic);

                await _processingUtils.WriteFilesToDirectory(configuration.FileStorageTemplate, concurrentBag);

                var elasticDocsTasks = _processingBaseImplementations
                                       .ConvertToParallelQuery(concurrentBag, configuration.Parallelism)
                                       .Select(async rootDoc => await _owmToElasticDocumentConverter.ConvertAsync(rootDoc));

                var elasticDocs = (await Task.WhenAll(elasticDocsTasks))
                                  .Values();

                var indexName = _elasticConnection.BuildIndexName(configuration.ElasticIndexName, readTime);
                _logger.Information($"write weather data to index {indexName}");

                if (!await _elasticConnection.IndexExistsAsync(indexName))
                {
                    await _elasticConnection.CreateIndexAsync <WeatherLocationDocument>(indexName);

                    await _elasticConnection.RefreshIndexAsync(indexName);

                    await _elasticConnection.FlushIndexAsync(indexName);
                }

                await _elasticConnection.BulkWriteDocumentsAsync(elasticDocs, indexName);
            }
            finally
            {
                sw.Stop();
                _logger.Information("Processed {MethodName} in {ElapsedMs:000} ms", "ProcessingBaseCurrentWeatherImpl.Execute",
                                    sw.ElapsedMilliseconds);
            }
        }
示例#17
0
 public ElasticConnection Build(ConfigurationItems configurationItems)
 {
     return(new ElasticConnection(configurationItems));
 }
示例#18
0
        public static string SetVersionFile(
            [NotNull] InstalledPackage installedPackage,
            [NotNull] DirectoryInfo targetDirectoryInfo,
            [NotNull] DeploymentExecutionDefinition deploymentExecutionDefinition,
            [NotNull] IEnumerable <string> xmlTransformedFiles,
            [NotNull] IEnumerable <string> replacedFiles,
            [NotNull] EnvironmentPackageResult environmentPackageResult,
            ILogger logger)
        {
            if (installedPackage == null)
            {
                throw new ArgumentNullException(nameof(installedPackage));
            }

            if (targetDirectoryInfo == null)
            {
                throw new ArgumentNullException(nameof(targetDirectoryInfo));
            }

            if (deploymentExecutionDefinition == null)
            {
                throw new ArgumentNullException(nameof(deploymentExecutionDefinition));
            }

            if (xmlTransformedFiles == null)
            {
                throw new ArgumentNullException(nameof(xmlTransformedFiles));
            }

            if (replacedFiles == null)
            {
                throw new ArgumentNullException(nameof(replacedFiles));
            }

            if (environmentPackageResult == null)
            {
                throw new ArgumentNullException(nameof(environmentPackageResult));
            }

            string applicationMetadataJsonFilePath = Path.Combine(targetDirectoryInfo.FullName,
                                                                  ConfigurationKeys.ApplicationMetadataFileName);

            var existingKeys = new List <KeyValue>();

            if (File.Exists(applicationMetadataJsonFilePath))
            {
                logger?.Debug("Appending existing metadata file {Path}", applicationMetadataJsonFilePath);

                string json = File.ReadAllText(applicationMetadataJsonFilePath, Encoding.UTF8);

                ConfigurationItems configurationItems = JsonConfigurationSerializer.Deserialize(json);

                if (!configurationItems.Keys.IsDefaultOrEmpty)
                {
                    existingKeys.AddRange(configurationItems.Keys);
                }
            }

            var version = new KeyValue(ConfigurationKeys.SemVer2Normalized,
                                       installedPackage.Version.ToNormalizedString(),
                                       null);

            var packageId = new KeyValue(ConfigurationKeys.PackageId,
                                         installedPackage.PackageId,
                                         null);

            var deployStartTimeUtc = new KeyValue(
                ConfigurationKeys.DeployStartTimeUtc,
                DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture),
                null);

            var deployedFromMachine = new KeyValue(
                ConfigurationKeys.DeployerDeployedFromMachine,
                Environment.MachineName,
                null);

            var deployerAssemblyVersion = new KeyValue(
                ConfigurationKeys.DeployerAssemblyVersion,
                GetAssemblyVersion(),
                null);

            var deployerAssemblyFileVersion = new KeyValue(
                ConfigurationKeys.DeployerAssemblyFileVersion,
                GetAssemblyFileVersion(),
                null);

            var environmentConfiguration = new KeyValue(
                ConfigurationKeys.DeployerEnvironmentConfiguration,
                deploymentExecutionDefinition.EnvironmentConfig,
                null);

            var keys = new List <KeyValue>(existingKeys)
            {
                version,
                deployStartTimeUtc,
                deployerAssemblyVersion,
                deployerAssemblyFileVersion,
                packageId
            }.ToImmutableArray();

            if (environmentPackageResult.Version != null)
            {
                keys.Add(environmentConfiguration);
            }

            string serialized = JsonConfigurationSerializer.Serialize(new ConfigurationItems("1.0", keys));

            File.WriteAllText(applicationMetadataJsonFilePath, serialized, Encoding.UTF8);

            logger?.Debug("Metadata file update {Path}", applicationMetadataJsonFilePath);

            return(applicationMetadataJsonFilePath);
        }
        public async Task Process(ConfigurationItems configuration)
        {
            var sw = Stopwatch.StartNew();

            try
            {
                var locationsList =
                    (await _locationFileReader.ReadLocationsAsync(configuration.AirPollutionLocationsFile)).ValueOr(
                        new List <string>());
                _logger.Information($"read the list of locations with {locationsList.Count} entries");
                var splitLocationList = locationsList.Select(element =>
                {
                    var splt = element.Split(";");
                    return(splt[0], splt[1]);
                });

                var rootTasks = _processingBaseImplementations
                                .ConvertToParallelQuery(splitLocationList, configuration.Parallelism)
                                .Select(async location =>
                {
                    _logger.Information($"get airpollution information for configured {location}");
                    var uri =
                        $"https://api.openweathermap.org/data/2.5/air_pollution?{location.Item1}&appid={configuration.OwmApiKey}";
                    var resultOpt = await _owmApiReader.ReadDataFromLocationAsync(uri, location.Item1);
                    return(resultOpt.Map(result => (location.Item2, result)));
                });

                var rootOptions = (await Task.WhenAll(rootTasks)).Values();

                var readTime = DateTime.Now;
                _logger.Information($"define document timestamp for elastic is {readTime}");
                var rootStrings = _processingBaseImplementations
                                  .ConvertToParallelQuery(rootOptions, configuration.Parallelism)
                                  .Select(async rootElement =>
                {
                    var elementOpt =
                        await _processingBaseImplementations
                        .DeserializeObjectAsync <AirPollutionBase>(rootElement.Item2);

                    return(elementOpt.Map(element =>
                    {
                        element.LocationName = rootElement.Item1;
                        element.ReadTime = readTime;
                        element.Guid = Guid.NewGuid();
                        return element;
                    }));
                });

                var toElastic = (await Task.WhenAll(rootStrings)).Values();

                var concurrentBag = new ConcurrentBag <AirPollutionBase>(toElastic);

                await _processingUtils.WriteFilesToDirectory(configuration.AirPollutionFileStoragePath, concurrentBag);

                var elasticDocTasks = _processingBaseImplementations
                                      .ConvertToParallelQuery(concurrentBag, configuration.Parallelism)
                                      .Select(async apDoc => await _owmToElasticDocumentConverter.ConvertAsync(apDoc));

                var elasticDocs = (await Task.WhenAll(elasticDocTasks)).Values();


                var indexName = _elasticConnection.BuildIndexName(configuration.AirPollutionIndexName, readTime);
                _logger.Information($"write airpollution data to index {indexName}");
                if (!await _elasticConnection.IndexExistsAsync(indexName))
                {
                    await _elasticConnection.CreateIndexAsync <AirPollutionDocument>(indexName);

                    await _elasticConnection.RefreshIndexAsync(indexName);

                    await _elasticConnection.FlushIndexAsync(indexName);
                }

                await _elasticConnection.BulkWriteDocumentsAsync(elasticDocs, indexName);
            }
            finally
            {
                sw.Stop();
                _logger.Information("Processed {MethodName} in {ElapsedMs:000} ms", "ProcessingBaseAirPollutionImpl.Execute",
                                    sw.ElapsedMilliseconds);
            }
        }
        public async Task OnProjectChanged_VersionRemoved_DeinitializesProject()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            RazorComponentWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath));
            RazorComponentWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectComponentFile1.TargetPath);

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));
            RazorGenerateWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectFile1.TargetPath);

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal(TestProjectData.SomeProject.FilePath, snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName),
                e => Assert.Equal("MVC-2.1", e.ExtensionName));

            // Act - 2
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "");

            changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(changes[0].After),
                ConfigurationItems.ToChange(changes[1].After),
                ExtensionItems.ToChange(changes[2].After),
                RazorComponentWithTargetPathItems.ToChange(changes[3].After),
                RazorGenerateWithTargetPathItems.ToChange(changes[4].After),
            };

            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 2
            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
        public async Task OnProjectChanged_UpdateProject_Succeeds()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            RazorComponentWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath));
            RazorComponentWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectComponentFile1.TargetPath);

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));
            RazorGenerateWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectFile1.TargetPath);

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal(TestProjectData.SomeProject.FilePath, snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName),
                e => Assert.Equal("MVC-2.1", e.ExtensionName));

            Assert.Collection(
                snapshot.DocumentFilePaths.OrderBy(d => d),
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectFile1.TargetPath, document.TargetPath);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            });

            // Act - 2
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.0");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.0");
            ConfigurationItems.RemoveItem("MVC-2.1");
            ConfigurationItems.Item("MVC-2.0", new Dictionary <string, string>()
            {
                { "Extensions", "MVC-2.0;Another-Thing" },
            });
            ExtensionItems.Item("MVC-2.0");
            RazorComponentWithTargetPathItems.Item(TestProjectData.AnotherProjectNestedComponentFile3.FilePath, new Dictionary <string, string>()
            {
                { Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.AnotherProjectNestedComponentFile3.TargetPath },
            });
            RazorGenerateWithTargetPathItems.Item(TestProjectData.AnotherProjectNestedFile3.FilePath, new Dictionary <string, string>()
            {
                { Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.AnotherProjectNestedFile3.TargetPath },
            });

            changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(changes[0].After),
                ConfigurationItems.ToChange(changes[1].After),
                ExtensionItems.ToChange(changes[2].After),
                RazorComponentWithTargetPathItems.ToChange(changes[3].After),
                RazorGenerateWithTargetPathItems.ToChange(changes[4].After),
            };

            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 2
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal(TestProjectData.SomeProject.FilePath, snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_0, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.0", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName),
                e => Assert.Equal("MVC-2.0", e.ExtensionName));

            Assert.Collection(
                snapshot.DocumentFilePaths.OrderBy(d => d),
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.AnotherProjectNestedFile3.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.AnotherProjectNestedFile3.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Legacy, document.FileKind);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.AnotherProjectNestedComponentFile3.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.AnotherProjectNestedComponentFile3.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectFile1.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Legacy, document.FileKind);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            });

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
示例#22
0
 public ConfigurationSection()
 {
     Items = new ConfigurationItems();
 }