コード例 #1
0
        /// <summary>
        /// Show the folder browse dialog for a specified textbox
        /// </summary>
        /// <param name="textBox"> The text box that should be updated with the path (or extended data). </param>
        /// <param name="connectorInfo"> Information about the connector path. </param>
        /// <param name="useSave"> Indicates whether the dialog should ask the user to save instead of to load data. </param>
        private void ShowFolderDialog(Control textBox, ConnectorInformation connectorInfo, bool useSave)
        {
            var configurationClassType = connectorInfo.ConnectorPathDescription.WinformsConfigurationClass;

            if (configurationClassType != null)
            {
                var configurationClass = configurationClassType.GetConstructor(new Type[] { }).Invoke(null) as IConfigurable;
                if (configurationClass != null)
                {
                    textBox.Text = configurationClass.ShowConfigurationDialog(textBox.Text);
                }

                return;
            }

            if (connectorInfo.PathType == ClientPathType.FileSystemPath)
            {
                this.folderBrowser.SelectedPath = SyncWizardContext.ResolvePath(textBox.Text);
                if (this.folderBrowser.ShowDialog() == DialogResult.OK)
                {
                    textBox.Text = this.folderBrowser.SelectedPath;
                }

                return;
            }

            if (useSave)
            {
                this.saveFileDialog1.DefaultExt   = string.Empty;
                this.saveFileDialog1.Filter       = Resources.AllFilesFileFilter;
                this.saveFileDialog1.AddExtension = true;
                this.saveFileDialog1.FileName     = textBox.Text;
                try
                {
                    if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        textBox.Text = this.saveFileDialog1.FileName;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    this.ProcessingEventHandler(null, new ProcessingEventArgs {
                        Message = ex.Message
                    });
                }

                return;
            }

            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox.Text = this.openFileDialog1.FileName;
            }
        }
コード例 #2
0
        /// <summary>
        /// Setup of the event handler routing and "databinding"
        /// </summary>
        /// <param name="sender">the sender of the event - in this case the form instance </param>
        /// <param name="e">empty event arguments </param>
        private void SyncWizardLoad(object sender, EventArgs e)
        {
            this.versionLabel.Text = Resources.LabelVersion + new VersionCheck().ToString(false);

            // setup the data binding for combo boxes
            this.SetupBind(this.contextDataSource, "ClientsSource", this.cboSource, "Source.Name");
            this.SetupBind(this.contextDataTarget, "ClientsTarget", this.cboTarget, "Target.Name");
            this.SetupBind(this.contextDataWorkflows, "SyncWorkflowsTemplates", this.cboWorkFlowTemplates, "CurrentSyncWorkflowTemplate");
            this.SetupBind(this.contextDataWorkflowData, "SyncWorkflowData", this.cboWorkFlowData, "CurrentSyncWorkflowData");

            // setup data propagation from control to business object
            // todo: this needs to be changed to be included into databinding setup
            this.txtPathSource.TextChanged     += (s, ev) => { this.DataContext.Source.Path = ((Control)s).Text; };
            this.txtPathTarget.TextChanged     += (s, ev) => { this.DataContext.Target.Path = ((Control)s).Text; };
            this.txtUidSource.TextChanged      += (s, ev) => { this.DataContext.Source.LogonCredentials.LogOnUserId = ((Control)s).Text; };
            this.txtUidTarget.TextChanged      += (s, ev) => { this.DataContext.Target.LogonCredentials.LogOnUserId = ((Control)s).Text; };
            this.txtPasswordSource.TextChanged += (s, ev) => { this.DataContext.Source.LogonCredentials.LogOnPassword = ((Control)s).Text; };
            this.txtPasswordTarget.TextChanged += (s, ev) => { this.DataContext.Target.LogonCredentials.LogOnPassword = ((Control)s).Text; };
            this.txtDomainSource.TextChanged   += (s, ev) => { this.DataContext.Source.LogonCredentials.LogOnDomain = ((Control)s).Text; };
            this.txtDomainTarget.TextChanged   += (s, ev) => { this.DataContext.Target.LogonCredentials.LogOnDomain = ((Control)s).Text; };

            // setup the click handling
            this.btnClose.Click      += (s, ev) => this.Close();
            this.btnRun.Click        += (s, ev) => this.RunCommands();
            this.btnCancel.Click     += (s, ev) => this.DataContext.Cancel = true;
            this.btnSave.Click       += (s, ev) => this.DataContext.SaveTo(this.AskForDestinationFile(Path.GetFileNameWithoutExtension(this.DataContext.CurrentSyncWorkflowData)));
            this.btnPathSource.Click += (s, ev) => this.ShowFolderDialog(this.txtPathSource, this.DataContext.Source, false);
            this.btnPathTarget.Click += (s, ev) => this.ShowFolderDialog(this.txtPathTarget, this.DataContext.Target, true);
            this.button1.Click       += (s, ev) => this.DataContext.SwapSourceAndTarget();

            // we don't need to detach from these events, so we don't need to save the lambda into a variable for the detaching.
            this.openWorkingFolderToolStripMenuItem.Click   += (s, ev) => this.DataContext.OpenWorkingFolder();
            this.openExceptionFolderToolStripMenuItem.Click += (s, ev) => SyncWizardContext.OpenExceptionFolder();
            this.exitToolStripMenuItem.Click                   += (s, ev) => this.Close();
            this.removeDuplettesToolStripMenuItem.Click        += (s, ev) => this.DataContext.Run("SyncLists\\RemoveDuplicatesFromOutlook.SyncList");
            this.generateSampleProfilesToolStripMenuItem.Click += (s, ev) => this.DataContext.GenerateSamples();
            this.deleteCurrentProfileToolStripMenuItem.Click   += (s, ev) => this.DataContext.DeleteWorkflowData(this.DataContext.CurrentSyncWorkflowData);
            this.openCommandsViewToolStripMenuItem.Click       += (s, ev) => new Commands {
                DataContext = new ClientViewModel()
            }.Show();
            this.starteSynchronisationToolStripMenuItem.Click += (s, ev) => this.RunCommands();

            // setup event handling
            this.DataContext.ProcessingEvent = this.ProcessingEventHandler;
            this.DataContext.ProgressEvent   = (object s, ProgressEventArgs eventArgs) =>
            {
                this.Invoke(
                    new MethodInvoker(
                        () =>
                {
                    this.SyncProgress.Value = eventArgs.PercentageDone;
                    this.SyncProgress.Refresh();
                    return;
                }));
            };

            this.DataContext.FinishedEvent += s => this.Invoke(
                new MethodInvoker(
                    () =>
            {
                this.DataContext.Cancel   = false;
                this.pnlProgress.Visible  = false;
                this.lblDialogStatus.Text = Resources.ProcessFinishedMessage;
                this.DataContext.Locked   = false;
            }));

            // initialize the gui
            this.cboSource.SelectedIndex            = -1;
            this.cboTarget.SelectedIndex            = -1;
            this.cboWorkFlowTemplates.SelectedIndex = -1;

            this.DataContext.PropertyChanged  += this.ReadFromContext;
            this.cboWorkFlowData.SelectedValue = Config.LastUsedSyncTemplateData ?? this.cboWorkFlowData.SelectedValue;
        }