Пример #1
0
        public Task WriteInsightsToXmlAsync(string outputFolder)
        {
            return(Task.Run(async() =>
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlTransaction transaction = connection.BeginTransaction();

                    SqlCommand command = new SqlCommand("sp_GetInsights", connection);

                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transaction;

                    try
                    {
                        SqlDataAdapter adapter = new SqlDataAdapter(command);

                        DataSet dataSet = new DataSet("Insights");

                        DataTable dataTable = new DataTable("Insight");

                        dataSet.Tables.Add(dataTable);

                        adapter.Fill(dataSet.Tables["Insight"]);

                        XmlGenerator xmlGenerator = new XmlGenerator(outputFolder);

                        await xmlGenerator.WriteToXmlAsync(dataSet, "appInsights");

                        transaction.Commit();
                    }
                    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}");
                        }

                        transaction.Rollback();
                    }
                }
            }));
        }
Пример #2
0
        public Task GetCustomersAsync(string outputFolder, DataIO appInsights, string customersFileName)
        {
            return(Task.Run(async() =>
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlTransaction transaction = connection.BeginTransaction();

                    SqlCommand command = new SqlCommand("sp_GetCustomers", connection);

                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transaction;

                    try
                    {
                        SqlDataAdapter adapter = new SqlDataAdapter(command);

                        DataSet dataSet = new DataSet("Customers");

                        DataTable dataTable = new DataTable("Customer");

                        dataSet.Tables.Add(dataTable);

                        adapter.Fill(dataSet.Tables["Customer"]);

                        XmlGenerator xmlGenerator = new XmlGenerator(outputFolder);

                        await xmlGenerator.WriteToXmlAsync(dataSet, customersFileName);

                        await appInsights.InsertInsightAsync("Customers were received successfully");

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        await appInsights.InsertInsightAsync("EXCEPTION: " + ex.Message);

                        transaction.Rollback();
                    }
                }
            }));
        }