コード例 #1
0
        public ValidationResults Validate()
        {
            try
            {
                ValidationResults results = new ValidationResults();

                //get all solution compontents of type workflow that belong to the specified solution
                QueryExpression processQuery = new QueryExpression("solutioncomponent");
                processQuery.ColumnSet = new ColumnSet(true);
                processQuery.Criteria.AddCondition("componenttype", ConditionOperator.Equal, (int)SolutionComponentType.Process);
                processQuery.Criteria.AddCondition("solutionid", ConditionOperator.Equal, Solution.Id);

                var allProcesses = CRMService.RetrieveMultiple(processQuery);
                if (allProcesses != null && allProcesses.Entities.Count > 0)
                {
                    results = ValidateProcesses(allProcesses.Entities);
                }
                return(results);
            }
            catch (Exception ex)
            {
                OnValidatorError?.Invoke(this, new ErrorEventArgs(ex));
                return(null);
            }
        }
コード例 #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);
        }