Example #1
0
        public ValidationResults Validate(CRMSolution solution)
        {
            ValidationResults allValidatorsResult = new ValidationResults();

            if (Validators == null || Validators.Count == 0)
            {
                throw new InvalidOperationException("No Validators exist, please change the validation settings first");
            }

            //publish all customizations first if the settings allow it
            if (MySettings.AlwaysPublish)
            {
                OnProgressChanged?.Invoke(this, new ProgressEventArgs("Publishing customizations"));
                PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
                CRMService.Execute(publishRequest);
            }

            // start the validators
            foreach (IValidator validator in Validators)
            {
                validator.OnValidatorError += (s, e) =>
                {
                    OnError?.Invoke(s, e);
                };
                validator.OnValidatorProgress += (s, e) =>
                {
                    OnProgressChanged?.Invoke(s, new ProgressEventArgs(e.Message));
                };

                ValidationResults validatorResult = validator.Validate();
                allValidatorsResult.AddResultSet(validatorResult);
            }

            return(allValidatorsResult);
        }
Example #2
0
        private ValidationResults ValidateManagedSolutionComponents()
        {
            ValidationResults results = new ValidationResults();

            // export the solution as managed and extract it to get the customizations xml
            ExportSolutionRequest exportRequest = new ExportSolutionRequest();

            exportRequest.Managed      = true;
            exportRequest.SolutionName = Solution.UniqueName;
            OnValidatorProgress?.Invoke(this, new ProgressEventArgs("Exporting solution as managed"));
            ExportSolutionResponse managedResponse = CRMService.Execute(exportRequest) as ExportSolutionResponse;

            if (managedResponse != null)
            {
                try
                {
                    string zipFileName         = Solution.UniqueName + ".zip";
                    string customiationXmlPath = Constants.APP_DATA_TEMP_DIRECTOY_PATH + "\\customizations.xml";
                    string zipPath             = Constants.APP_DATA_TEMP_DIRECTOY_PATH + zipFileName;

                    // cleanup an existing directory files
                    if (Directory.Exists(Constants.APP_DATA_TEMP_DIRECTOY_PATH))
                    {
                        Directory.Delete(Constants.APP_DATA_TEMP_DIRECTOY_PATH, true);
                    }

                    // recreate the directory
                    if (!Directory.Exists(Constants.APP_DATA_TEMP_DIRECTOY_PATH))
                    {
                        Directory.CreateDirectory(Constants.APP_DATA_TEMP_DIRECTOY_PATH);
                    }

                    // write the managed solution as a zip file in the directory
                    OnValidatorProgress?.Invoke(this, new ProgressEventArgs("Saving Managed Solution"));
                    File.WriteAllBytes(zipPath, managedResponse.ExportSolutionFile);

                    // extract the zip file to get the customizations.xml file content
                    OnValidatorProgress?.Invoke(this, new ProgressEventArgs("Extracting Managed Solution"));
                    ZipFile.ExtractToDirectory(zipPath, Constants.APP_DATA_TEMP_DIRECTOY_PATH);


                    //at this point customization.xml file should be ready, load it into an xdocument object
                    if (File.Exists(customiationXmlPath))
                    {
                        OnValidatorProgress?.Invoke(this, new ProgressEventArgs("Checking the Customization File"));

                        XDocument customizationsXml = XDocument.Load(customiationXmlPath);
                        results.AddResultSet(CheckAttributes(customizationsXml));
                        results.AddResultSet(CheckViews(customizationsXml));
                        results.AddResultSet(CheckForms(customizationsXml));
                    }
                }

                catch (IOException ioEx)
                {
                    // fire an error to be catched by whoever is listening to the OnValidationError Event
                    OnValidatorError?.Invoke(this, new ErrorEventArgs(ioEx));
                    throw ioEx;
                }
                catch (Exception ex)
                {
                    OnValidatorError?.Invoke(this, new ErrorEventArgs(ex));
                    throw ex;
                }
            }
            return(results);
        }