예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var model            = this.GetViewProfileModel();
            var validationResult = this.validationService.Validate(model);

            if (validationResult.Any())
            {
                var form = new ValidationForm(validationResult);
                form.ShowDialog();
                return;
            }

            var progressCallback = new ProgressWindowForm("New txt")
            {
                StartPosition = FormStartPosition.CenterParent
            };

            ;

            Task.Factory.StartNew(() => this.context.Send(state => progressCallback.ShowDialog(this), null));
            Task.Factory.StartNew(() => this.telnetService.Submit(model, progressCallback as IProgressCallback))
            .ContinueWith(this.ShowError, TaskContinuationOptions.OnlyOnFaulted)
            .ContinueWith(task => progressCallback.End());
        }
        /// <summary>
        /// This method validates the sourceObject passed in.
        /// </summary>
        /// <returns></returns>
        public new bool Validate()
        {
            // initial value
            bool valid = false;

            // If the SelectedProject exists
            if (this.HasSelectedProject)
            {
                // Create a ClientValidationManager
                ClientValidationManager clientValidationManager = new ClientValidationManager();

                // Create required fields

                // Create Project Required Fields
                RequiredField projectNameField   = new RequiredField("ProjectName", RequiredField.CreateMissingRequiredFieldMessage("Project Name", this.SelectedProject.ProjectName, false), this.SelectedProject, false);
                RequiredField projectFolderField = new RequiredField("ProjectFolder", RequiredField.CreateMissingRequiredFieldMessage("Project Folder", this.SelectedProject.ProjectFolder, true), this.SelectedProject, true);

                // Create Object Required Fields
                RequiredField objectFolderField    = new RequiredField("ObjectFolder", RequiredField.CreateMissingRequiredFieldMessage("Object Folder", this.SelectedProject.ObjectFolder, true), this.SelectedProject, true);
                RequiredField objectNamespaceField = new RequiredField("ObjectNamespace", RequiredField.CreateMissingRequiredFieldMessage("Object Namespace", this.SelectedProject.ObjectNamespace, false), this.SelectedProject, false);

                // Create DataManager Required Fields
                RequiredField dataManagerFolderField    = new RequiredField("DataManagerFolder", RequiredField.CreateMissingRequiredFieldMessage("Data Manager Folder", this.SelectedProject.DataManagerFolder, true), this.SelectedProject, true);
                RequiredField dataManagerNamespaceField = new RequiredField("DataManagerNamespace", RequiredField.CreateMissingRequiredFieldMessage("Data Manager Namespace", this.SelectedProject.DataManagerNamespace, false), this.SelectedProject, false);

                // Create DataOperations Required Fields
                RequiredField dataOperationsFolderField    = new RequiredField("DataOperationsFolder", RequiredField.CreateMissingRequiredFieldMessage("Data Operations Folder", this.SelectedProject.DataOperationsFolder, true), this.SelectedProject, true);
                RequiredField dataOperationsNamespaceField = new RequiredField("DataOperationsNamespace", RequiredField.CreateMissingRequiredFieldMessage("Data Operations Namespace", this.SelectedProject.DataOperationsNamespace, false), this.SelectedProject, false);

                // Create Controller Required Fields
                RequiredField controllerFolderField    = new RequiredField("ControllerFolder", RequiredField.CreateMissingRequiredFieldMessage("Controller Folder", this.SelectedProject.ControllerFolder, true), this.SelectedProject, true);
                RequiredField controllerNamespaceField = new RequiredField("ControllerNamespace", RequiredField.CreateMissingRequiredFieldMessage("Controller Namespace", this.SelectedProject.ControllerNamespace, false), this.SelectedProject, false);

                // Create Reader Required Fields
                RequiredField readerFolderField    = new RequiredField("ReaderFolder", RequiredField.CreateMissingRequiredFieldMessage("Reader Folder", this.SelectedProject.ReaderFolder, true), this.SelectedProject, true);
                RequiredField readerNamespaceField = new RequiredField("ReaderNamespace", RequiredField.CreateMissingRequiredFieldMessage("Reader Namespace", this.SelectedProject.ReaderNamespace, false), this.SelectedProject, false);

                // Create Writer Required Fields
                RequiredField writerFolderField    = new RequiredField("DataWriterFolder", RequiredField.CreateMissingRequiredFieldMessage("Writer Folder", this.SelectedProject.DataWriterFolder, true), this.SelectedProject, true);
                RequiredField writerNamespaceField = new RequiredField("DataWriterNamespace", RequiredField.CreateMissingRequiredFieldMessage("Writer Namespace", this.SelectedProject.DataWriterNamespace, false), this.SelectedProject, false);

                // Create StoredProcedure Required Fields
                RequiredField storedProcFolderField    = new RequiredField("StoredProcedureObjectFolder", RequiredField.CreateMissingRequiredFieldMessage("Stored Procedure Object Folder", this.SelectedProject.StoredProcedureObjectFolder, true), this.SelectedProject, true);
                RequiredField storedProcNamespaceField = new RequiredField("StoredProcedureObjectNamespace", RequiredField.CreateMissingRequiredFieldMessage("Stored Procedure Object Namespace", this.SelectedProject.StoredProcedureObjectNamespace, false), this.SelectedProject, false);

                // Add Required Fields

                // Add Project Fields
                clientValidationManager.RequiredFields.Add(projectNameField);
                clientValidationManager.RequiredFields.Add(projectFolderField);

                // Add Object Required Fields
                clientValidationManager.RequiredFields.Add(objectFolderField);
                clientValidationManager.RequiredFields.Add(objectNamespaceField);

                // Add DataManager Required Fields
                clientValidationManager.RequiredFields.Add(dataManagerFolderField);
                clientValidationManager.RequiredFields.Add(dataManagerNamespaceField);

                // Add DataOperations Required Fields
                clientValidationManager.RequiredFields.Add(dataOperationsFolderField);
                clientValidationManager.RequiredFields.Add(dataOperationsNamespaceField);

                // Add Controller Required Fields
                clientValidationManager.RequiredFields.Add(controllerFolderField);
                clientValidationManager.RequiredFields.Add(controllerNamespaceField);

                // Add Reader Required Fields
                clientValidationManager.RequiredFields.Add(readerFolderField);
                clientValidationManager.RequiredFields.Add(readerNamespaceField);

                // Add Writer Required Fields
                clientValidationManager.RequiredFields.Add(writerFolderField);
                clientValidationManager.RequiredFields.Add(writerNamespaceField);

                // Add Stored Procedure Writer Fields
                clientValidationManager.RequiredFields.Add(storedProcFolderField);
                clientValidationManager.RequiredFields.Add(storedProcNamespaceField);

                // Valildate this object.
                valid = clientValidationManager.Validate(this.SelectedProject);

                // if this object is not valid
                if (!valid)
                {
                    // Create a new instance of a 'ValidationForm' object.
                    ValidationForm validationForm = new ValidationForm();

                    // Setup the ClientValidationManager
                    validationForm.Setup(clientValidationManager);

                    // Show the form
                    validationForm.ShowDialog();
                }
            }

            // return value
            return(valid);
        }