Beispiel #1
0
        protected override void OnStart(string[] args)
        {
            DataBaseWorker reader            = new DataBaseWorker(dataOptions.ConnectionString);
            FileTransfer   fileTransfer      = new FileTransfer(dataOptions.OutputFolder, dataOptions.SourcePath);
            string         customersFileName = "customers";
            await reader.GetCustomersAsync(dataOptions.OutputFolder, appInsights, customersFileName);

            await fileTransfer.SendFileToFtpAsync($"{customersFileName}.xml");

            await fileTransfer.SendFileToFtpAsync($"{customersFileName}.xsd");

            await appInsights.InsertInsightAsync("Files uploaded");
        }
Beispiel #2
0
        static async Task Main()
        {
            ConfigManager  configManager;
            DataOptions    dataOptions;
            DataBaseWorker appInsights;

            try
            {
                if (File.Exists(xmlPath) && File.Exists(xsdPath))
                {
                    XmlSchemaSet schema = new XmlSchemaSet();
                    schema.Add(string.Empty, xsdPath);
                    XDocument xdoc = XDocument.Load(xmlPath);
                    xdoc.Validate(schema, ValidationEventHandler);
                    configManager = new ConfigManager(xmlPath, typeof(DataOptions));
                }
                else if (File.Exists(jsonPath))
                {
                    configManager = new ConfigManager(jsonPath, typeof(DataOptions));
                }
                else
                {
                    throw new Exception("No options");
                }
                dataOptions = configManager.GetOptions <DataOptions>();
                appInsights = new DataBaseWorker(dataOptions.LoggerConnectionString);
                await appInsights.ClearInsightsAsync();

                await appInsights.InsertInsightAsync("Connection established");
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = new StreamWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Exceptions.txt"), true))
                {
                    await sw.WriteLineAsync($"{DateTime.Now:dd/MM/yyyy HH:mm:ss} Exception: {ex.Message}");
                }
                return;
            }
            try
            {
                DataManager service = new DataManager(dataOptions, appInsights);
                ServiceBase.Run(service);
            }
            catch (Exception ex)
            {
                await appInsights.InsertInsightAsync("Exception: " + ex.Message);

                await appInsights.WriteInsightsToXmlAsync(dataOptions.OutputFolder);
            }
        }