public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args)
                       .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
                // logging.AddEventSourceLogger();
            }).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <ApplicationDbContext>();
                try
                {
                    CreateSettings.GenerateSettings(context);
                    CreateContacts.GenerateContacts(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
Exemplo n.º 2
0
        public void ProcessAttributes()
        {
            if (cbbSolutions.SelectedItem == null)
            {
                MessageBox.Show(this, @"Please select a solution", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtFilePath.Text.Length == 0)
            {
                MessageBox.Show(this, @"Please define a file", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!File.Exists(txtFilePath.Text))
            {
                MessageBox.Show(this, @"The file specified does not exist", @"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var settings = new CreateSettings
            {
                FilePath           = txtFilePath.Text,
                LanguageCode       = languageCode,
                Solution           = (AppCode.SolutionInfo)cbbSolutions.SelectedItem,
                AddLookupSuffix    = chkAddLookupSuffix.Checked,
                AddOptionSetSuffix = chkAddOptionSetSuffix.Checked
            };

            lvLogs.Items.Clear();
            SetWorkingState(true);

            WorkAsync(new WorkAsyncInfo
            {
                Message       = string.Empty,
                AsyncArgument = settings,
                Work          = (w, e) =>
                {
                    var manager = new MetadataUpsertManager((CreateSettings)e.Argument, Service, ConnectionDetail.OrganizationMajorVersion);
                    manager.Process(w, ConnectionDetail);
                },
                ProgressChanged = e =>
                {
                    var info = (ProcessResult)e.UserState;
                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(e.ProgressPercentage, "Processing..."));

                    var item = lvLogs.Items.Cast <ListViewItem>().FirstOrDefault(i => i.Tag == info);
                    if (item != null)
                    {
                        if (info.Success)
                        {
                            item.ImageIndex       = 1;
                            item.SubItems[3].Text = info.Attribute;
                            item.SubItems[5].Text = info.IsCreate ? @"Created" : @"Updated";
                        }
                        else
                        {
                            item.ImageIndex       = 2;
                            item.SubItems[3].Text = info.Attribute;
                            item.SubItems[5].Text = $@"{(info.IsCreate ? "Create" : "Update")} Error";
                            item.SubItems[6].Text = info.Message;
                        }
                    }
                    else
                    {
                        item = new ListViewItem
                        {
                            Tag        = info,
                            ImageIndex = info.Processing ? 0 : info.Success ? 1 : 2,
                            Text       = string.Empty
                        };
                        item.SubItems.Add(info.DisplayName);
                        item.SubItems.Add(info.Type);
                        item.SubItems.Add(info.Attribute);
                        item.SubItems.Add(info.Entity);
                        item.SubItems.Add(info.Processing ? "Processing..." : info.Success ? info.IsCreate ? "Created" : "Updated" : info.IsCreate ? "Create Error" : "Update Error");
                        item.SubItems.Add(string.Empty);

                        lvLogs.Items.Add(item);
                    }
                },
                PostWorkCallBack = e =>
                {
                    SetWorkingState(false);

                    SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(null, null));
                    if (e.Error != null)
                    {
                        MessageBox.Show(this, e.Error.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                },
                IsCancelable = true
            });
        }