public TemplateSelectorStepViewModel()
        {
            Title                 = new UiLocalizableString("Template.Title");
            Description           = new UiLocalizableString("Template.Description");
            SetTemplateCommand    = new DelegateCommand(SetTemplateExecute, CanSetTemplateExecute);
            MailTemplateService   = IoC.Resolve <MailTemplateService>();
            WebViewService        = IoC.Resolve <WebViewService>();
            StructureCacheService = IoC.Resolve <StructureCacheService>();

            GeneratePreviewCommand   = new DelegateCommand(GeneratePreviewExecute, CanGeneratePreviewExecute);
            MorestachioErrors        = new ThreadSaveObservableCollection <IMorestachioError>();
            ShowPreviewWindowCommand = new DelegateCommand(ShowPreviewWindowExecute, CanShowPreviewWindowExecute);
            PropertyChanged         += TemplateSelectorStepViewModel_PropertyChanged;
            Commands.Add(new MenuBarCommand(ShowPreviewWindowCommand)
            {
                Content = new UiLocalizableString("Template.Preview.Title")
            });

            if (File.Exists("preview_error_template.mdoc.html"))
            {
                var errorTemplateOptions = new ParserOptions(File.ReadAllText("preview_error_template.mdoc.html"));
                ErrorDisplayTemplate = Parser.ParseWithOptions(errorTemplateOptions).Compile();
            }

            SetSyntax();
            ThemeManager.Current.ThemeChanged += Current_ThemeChanged;
        }
        public CsvMailDataStrategyViewModel() : base(CsvImportStrategy.IdKey,
                                                     "comma seperated file|*.csv",
                                                     nameof(FilePath),
                                                     nameof(SelectedRegionData),
                                                     nameof(QuoteCharacter),
                                                     nameof(IgnoreQuotes),
                                                     nameof(IgnoreEmptyLines),
                                                     nameof(EscapeCharacter),
                                                     nameof(Delimiter),
                                                     nameof(CommentDelimiter),
                                                     nameof(AllowComments)
                                                     )
        {
            Title       = new UiLocalizableString("DataImport.Strategy.CSV.Title");
            Description = new UiLocalizableString("DataImport.Strategy.CSV.Description");
            Name        = new UiLocalizableString("DataImport.Strategy.CSV.Name");
            var config = new Configuration(CultureInfo.CurrentUICulture);

            SelectedRegionData = new RegionInfo(config.CultureInfo.LCID);
            QuoteCharacter     = config.Quote.ToString();
            IgnoreQuotes       = config.IgnoreQuotes;
            IgnoreEmptyLines   = config.IgnoreBlankLines;
            EscapeCharacter    = config.Escape.ToString();
            Delimiter          = config.Delimiter;
            CommentDelimiter   = config.Comment.ToString();
            AllowComments      = config.AllowComments;
        }
 public CloseStepViewModel()
 {
     Title          = new UiLocalizableString("Close.Title");
     Description    = new UiLocalizableString("Close.Description");
     Description    = new UiLocalizableString("");
     GroupKey       = "MainGroup";
     NextButtonText = new UiLocalizableString("Application.Header.Close");
 }
 public ImportDataSelectorStepViewModel()
 {
     Title             = new UiLocalizableString("DataImport.Selector.Title");
     Description       = new UiLocalizableString("DataImport.Selector.Description");
     GroupKey          = "MainGroup";
     DataImportService = IoC.Resolve <DataImportService>();
     MailComposer      = IoC.Resolve <MailComposer>();
 }
Exemplo n.º 5
0
 private void ResetExecute(object sender)
 {
     Progress    = new SendMailProgress("", 0, 100, true, 0, 0, 0, 0);
     Result      = null;
     IsProcessed = false;
     Commands.RemoveWhere(e => ((string)e.Tag).StartsWith("AfterButton."));
     SendPropertyChanged(() => Progress);
     NextButtonText = new UiLocalizableString("Application.Header.StartSend");
 }
Exemplo n.º 6
0
 public MailDistributorSelectorViewModel()
 {
     Title                  = new UiLocalizableString("MailDistributor.Selector.Title");
     Description            = new UiLocalizableString("MailDistributor.Selector.Description");
     Description            = new UiLocalizableString("");
     MailComposer           = IoC.Resolve <MailComposer>();
     DataDistributorService = IoC.Resolve <DataDistributorService>();
     MailDistributors       = new ObservableCollection <IMailDistributorBaseViewModel>(DataDistributorService.MailDistributors);
 }
 public SqlMailDataStrategyViewModel() : base(SqlImportStrategy.IdKey,
                                              nameof(Query),
                                              nameof(ConnectionString))
 {
     Title       = new UiLocalizableString("DataImport.Strategy.Sql.Title");
     Description = new UiLocalizableString("DataImport.Strategy.Sql.Description");
     Name        = new UiLocalizableString("DataImport.Strategy.Sql.Name");
     //Query = "SELECT * FROM Address WHERE EMailAddress IS NOT NULL";
     //ConnectionString = @"Server=.\V17;Database=JPB.MyWorksheet.Database;Trusted_Connection=True;";
 }
        public WelcomeStepViewModel()
        {
            Title                     = new UiLocalizableString("WelcomeStep.Title");
            Description               = new UiLocalizableString("WelcomeStep.Description");
            GroupKey                  = "MainGroup";
            WebViewService            = IoC.Resolve <WebViewService>();
            PersistantSettingsService = IoC.Resolve <PersistantSettingsService>();

            LoadSettingCommand       = new DelegateCommand <SettingsMetaEntry>(LoadSettingExecute, CanLoadSettingExecute);
            InstallWebRuntimeCommand = new DelegateCommand(InstallWebRuntimeExecute, CanInstallWebRuntimeExecute);
        }
 public PrepareMailDataStepViewModel()
 {
     Title                 = new UiLocalizableString("MailDistributor.Prepare.Title");
     Description           = new UiLocalizableString("MailDistributor.Prepare.Description");
     GroupKey              = "MainGroup";
     MailComposer          = IoC.Resolve <MailComposer>();
     StructureCacheService = IoC.Resolve <StructureCacheService>();
     ExampleMailData       = new MailData();
     //MExpressionFromName = "\"Mr Company\"";
     //MExpressionFromAddress = "\"[email protected]\"";
     //MExpressionSubject = "\"Hot new Newsletter\"";
 }
 public SmtpMailDistributorViewModel() : base(
         nameof(AuthPassword),
         nameof(AuthUserName),
         nameof(Host),
         nameof(HostPort))
 {
     Title       = new UiLocalizableString("MailDistributor.Strategy.Smtp.Title");
     Description = new UiLocalizableString("MailDistributor.Strategy.Smtp.Description");
     IdKey       = SmtpMailDistributor.IdKey;
     Name        = new UiLocalizableString("MailDistributor.Strategy.Smtp.Name");
     HostPort    = 587;
 }
Exemplo n.º 11
0
        public WriteToDirectoryMailDistributorViewModel() : base(nameof(Directory))
        {
            Title       = new UiLocalizableString("MailDistributor.Strategy.ToDirectory.Title");
            Description = new UiLocalizableString("MailDistributor.Strategy.ToDirectory.Description");
            IdKey       = WriteToDirectoryMailDistributor.IdKey;
            Name        = new UiLocalizableString("MailDistributor.Strategy.ToDirectory.Name");

            Directory = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Output");
            if (!System.IO.Directory.Exists(Directory))
            {
                System.IO.Directory.CreateDirectory(Directory);
            }

            PickDirectoryCommand = new DelegateCommand(PickDirectoryExecute, CanPickDirectoryExecute);
        }
        public SendReportStepViewModel()
        {
            GroupKey             = "Report";
            SaveReportCommand    = new DelegateCommand(SaveReportExecute, CanSaveReportExecute);
            RefreshReportCommand = new DelegateCommand(RefreshReportExecute, CanRefreshReportExecute);

            Commands.Add(new MenuBarCommand(SaveReportCommand)
            {
                Content = new UiLocalizableString("SendReport.Save.Title")
            });

            Commands.Add(new MenuBarCommand(RefreshReportCommand)
            {
                Content = new UiLocalizableString("SendReport.Refresh.Title")
            });
            Title       = new UiLocalizableString("SaveReport.Title");
            Description = new UiLocalizableString("SaveReport.Description");
        }
Exemplo n.º 13
0
        public SummeryStepViewModel()
        {
            Title                 = new UiLocalizableString("Summery.Title");
            Description           = new UiLocalizableString("Summery.Description");
            Progress              = new SendMailProgress("", 0, 0, true, 0, 0, 0, 0);
            NextButtonText        = new UiLocalizableString("Application.Header.StartSend");
            ResetCommand          = new DelegateCommand(ResetExecute, CanResetExecute);
            SaveSendReportCommand = new DelegateCommand(SaveSendReportExecute, CanSaveSendReportExecute);
            AbortSendingCommand   = new DelegateCommand(AbortSendingExecute, CanAbortSendingExecute);

            MailComposer  = IoC.Resolve <MailComposer>();
            StopRequested = new CancellationTokenSource();

            Commands.Add(new MenuBarCommand(AbortSendingCommand)
            {
                Content = new UiLocalizableString("Application.Cancel"),
                Tag     = ""
            });
        }
 public JsonMailDataStrategyViewModel() : base(JsonFileImportStrategy.IdKey, "json file|*.json")
 {
     Title       = new UiLocalizableString("DataImport.Strategy.Json.Title");
     Description = new UiLocalizableString("DataImport.Strategy.Json.Description");
     Name        = new UiLocalizableString("DataImport.Strategy.Json.Name");
 }
Exemplo n.º 15
0
        private async Task SendMails()
        {
            CreatedAt     = DateTime.Now;
            IsProcessing  = true;
            StopRequested = new CancellationTokenSource();

            var done = new CancellationTokenSource();
            var task = Task.Run(async() =>
            {
                while (!done.IsCancellationRequested)
                {
                    await Task.Delay(250, done.Token);
                    SendPropertyChanged(() => Progress);
                }
            }, done.Token);

            try
            {
                Result = await MailComposer.ComposeAndSend(this, StopRequested.Token);
            }
            catch (Exception e)
            {
                if (StopRequested.IsCancellationRequested)
                {
                    return;
                }

                var uiWorkflow  = IoC.Resolve <IUiWorkflow>();
                var textService = IoC.Resolve <ITextService>();

                await DialogCoordinator.Instance.ShowMessageAsync(uiWorkflow,
                                                                  textService.Compile("Application.Error.Title", CultureInfo.CurrentUICulture, out _).ToString(),
                                                                  textService.Compile("Summery.Error.Message", CultureInfo.CurrentUICulture, out _,
                                                                                      new FormattableArgument(e.Message, false)).ToString()
                                                                  );

                return;
            }
            finally
            {
                IsProcessing = false;
                done.Cancel();
            }

            FinishedAt = DateTime.Now;
            ViewModelAction(() =>
            {
                SendPropertyChanged(() => Progress);
                IsProcessed    = true;
                NextButtonText = new UiLocalizableString("Application.Navigation.Forward");
                Commands.Add(new MenuBarCommand(ResetCommand)
                {
                    Content = new UiLocalizableString("Summery.Commands.Reset"),
                    Tag     = "AfterButton.ResetCommand",
                    Dock    = Dock.Left
                });
                Commands.Add(new MenuBarCommand(SaveSendReportCommand)
                {
                    Content = new UiLocalizableString("Summery.Commands.Report"),
                    Tag     = "AfterButton.ReportCommand",
                });
            });
        }
            public PrepareMailDataStepViewModelErrors()
            {
                var invalidExpression = new UiLocalizableString("DataImport.PrepareStep.Errors.InvalidExpression");
                var invalidAddress    = new UiLocalizableString("DataImport.PrepareStep.Errors.InvalidAddress");

                //https://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/
                var mailRegEx = new Regex(@"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
                                          + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
                                          + @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$",
                                          RegexOptions.IgnoreCase);
                var defaultOptions = new ParserOptions()
                {
                    Timeout = TimeSpan.FromSeconds(3)
                };

                async ValueTask <string> ExportValue(string expressionValue, object value)
                {
                    if (string.IsNullOrWhiteSpace(expressionValue) || value == null)
                    {
                        return(null);
                    }

                    var context    = TokenzierContext.FromText(expressionValue);
                    var expression = ExpressionParser.ParseExpression(expressionValue, context);

                    if (expression == null)
                    {
                        return(null);
                    }

                    return((await expression.GetValue(new ContextObject(defaultOptions, "", null, value),
                                                      new ScopeData()))
                           .Value?.ToString());
                }

                Add(new AsyncError <PrepareMailDataStepViewModel>(invalidExpression, async e =>
                {
                    return((e.ExampleAddress = await ExportValue(e.MExpressionAddress, e.ExampleMailData)) == null);
                }, nameof(MExpressionAddress), nameof(ExampleMailData)));

                Add(new Error <PrepareMailDataStepViewModel>(invalidAddress, e =>
                {
                    if (string.IsNullOrWhiteSpace(e.ExampleAddress))
                    {
                        return(true);
                    }

                    return(!mailRegEx.IsMatch(e.ExampleAddress));
                }, nameof(ExampleAddress), nameof(MExpressionAddress), nameof(ExampleMailData)));

                Add(new AsyncError <PrepareMailDataStepViewModel>(invalidExpression, async e =>
                {
                    return((e.ExampleName = await ExportValue(e.MExpressionName, e.ExampleMailData)) == null);;
                }, nameof(MExpressionName), nameof(ExampleMailData)));

                Add(new AsyncError <PrepareMailDataStepViewModel>(invalidExpression, async e =>
                {
                    return((e.ExampleSubject = await ExportValue(e.MExpressionSubject, e.ExampleMailData)) == null);
                }, nameof(MExpressionSubject), nameof(ExampleMailData)));


                Add(new AsyncError <PrepareMailDataStepViewModel>(invalidExpression, async e =>
                {
                    return((e.ExampleFromName = await ExportValue(e.MExpressionFromName, e.ExampleMailData)) == null);
                }, nameof(MExpressionFromName), nameof(ExampleMailData)));

                Add(new AsyncError <PrepareMailDataStepViewModel>(invalidExpression, async e =>
                {
                    return((e.ExampleFromAddress = await ExportValue(e.MExpressionFromAddress, e.ExampleMailData)) == null);
                }, nameof(MExpressionFromAddress), nameof(ExampleMailData)));

                Add(new Error <PrepareMailDataStepViewModel>(invalidAddress, e =>
                {
                    if (string.IsNullOrWhiteSpace(e.ExampleFromAddress))
                    {
                        return(true);
                    }
                    return(!mailRegEx.IsMatch(e.ExampleFromAddress));
                }, nameof(ExampleFromAddress), nameof(MExpressionFromAddress), nameof(ExampleMailData)));
            }