示例#1
0
        public SourceControlResultModel QueryLocalRepository()
        {
            SourceControlResultModel result = new SourceControlResultModel();

            try
            {
                using (var gitRepo = new Repository(m_repoPath))
                {
                    m_progress?.Invoke("------------------- START -----------------------");
                    m_progress?.Invoke($"[AZOPS] => Detecting changes in the workspace.");

                    var repoStatus   = gitRepo.RetrieveStatus();
                    var totalChanges = repoStatus.Count();
                    var pendings     = new List <RawChanges>();

                    m_progress?.Invoke($"[AZOPS] => Found {repoStatus.Added.Count()} added items.");
                    m_progress?.Invoke($"[AZOPS] => Found {repoStatus.Modified.Count()} modified items.");
                    m_progress?.Invoke($"[AZOPS] => Found {repoStatus.Removed.Count()} removed items.");

                    for (int i = 0; i < totalChanges; i++)
                    {
                        var item = repoStatus.ElementAt(i);

                        if (item.State != FileStatus.DeletedFromWorkdir && item.State != FileStatus.ModifiedInWorkdir && item.State != FileStatus.NewInWorkdir)
                        {
                            continue;
                        }

                        // Path normalization
                        var fixedPath       = item.FilePath.Replace('/', '\\');
                        var firstSlashIndex = fixedPath.IndexOf('\\');
                        fixedPath = fixedPath.Substring(firstSlashIndex);

                        pendings.Add(new RawChanges
                        {
                            ChangeTypeName = item.State.ToString(),
                            LocalItem      = string.Concat(m_basePath, fixedPath),
                            FileName       = new FileInfo(item.FilePath).Name
                        });
                    }

                    result.Changes = pendings.ToArray();
                }
            }
            catch (Exception ex)
            {
                m_progress?.Invoke($"[ERROR] => {ex.Message}");
                m_telemetry.TrackExceptionWithCustomMetrics(ex);
                result.Continue = false;
            }

            return(result);
        }
        private void Save(DialogWindow window)
        {
            var panelGuid = new Guid("A8E3D03E-28C9-4900-BD48-CEEDEC35E7E6");

            try
            {
                string customError = string.Empty;
                List <ValidationResult> results = new List <ValidationResult>();
                var validation = Validator.TryValidateObject(Configuration, new ValidationContext(Configuration), results);

                if (!validation)
                {
                    results.ForEach((error) => m_service.LogMessage($"[ERROR] => {error.ErrorMessage}", panelGuid));
                    m_service.LogMessage($"[ERROR] => {customError}", panelGuid);
                    return;
                }

                var xmlDump  = XmlObjectsHelper.Serialize(Configuration);
                var fullPath = $"{m_service.PropertiesDirectory}\\AvanadeToolkit.publishSettings";
                File.WriteAllText(fullPath, xmlDump);
                FilePath = fullPath;

                window.Close();
            }
            catch (Exception ex)
            {
                m_service.LogMessage($"[ERROR] => {ex.Message}", panelGuid);
                m_telemetry.TrackExceptionWithCustomMetrics(ex);
            }
        }
示例#3
0
        public void Publish(DeployConfigurationModel deployConfiguration, TelemetryWrapper telemetry, string singleResourceName, string project, string projectPath, string basePath)
        {
            try
            {
                Action <string> reportAction        = (m) => { ReportProgress?.Invoke(this, m); };
                var             context             = new XrmService(deployConfiguration.DynamicsSettings, deployConfiguration.Solution, telemetry, reportAction);
                var             sourceControl       = new VersioningService(projectPath, basePath, deployConfiguration.Branch, reportAction, telemetry);
                var             sourceControlResult = sourceControl.QueryLocalRepository();

                // Must resolve conflicts or something went wrong with TFS interaction
                if (!sourceControlResult.Continue && sourceControlResult.Changes == null)
                {
                    return;
                }

                var changeList = sourceControlResult.Changes;
                if (!string.IsNullOrEmpty(singleResourceName))
                {
                    var filteredChangeList = sourceControlResult.Changes.Where(x => x.FileName.Equals(singleResourceName)).ToArray();
                    changeList = filteredChangeList;
                }

                PublishImpl(context, sourceControl, deployConfiguration, telemetry, changeList, project);
            }
            catch (Exception exception)
            {
                ReportProgress?.Invoke(this, $"[ERROR] => {exception.Message}\n");
                if (!(exception is ToolkitException))
                {
                    telemetry.TrackExceptionWithCustomMetrics(exception);
                }
            }
        }
示例#4
0
        public XrmService(DynamicsConnectionSettings connectionSettings, string solution, TelemetryWrapper telemetry, Action <string> report)
        {
            try
            {
                m_progress  = report;
                m_telemetry = telemetry;
                m_solution  = solution;

                m_service = new Lazy <IOrganizationService>(() =>
                {
                    var crmServiceClient         = new CrmServiceClient(connectionSettings.ToString());
                    IOrganizationService service = crmServiceClient as IOrganizationService;

                    if (service == null)
                    {
                        throw new NullReferenceException("Unable to instantiate IOrganizationService");
                    }

                    return(service);
                });
            }
            catch (Exception exception)
            {
                m_progress?.Invoke($"[ERROR] => {exception.Message}");
                m_telemetry.TrackExceptionWithCustomMetrics(exception);
            }
        }
        private void DeployMenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var singleResourceName = e is SingleResourceEventArgs ? (e as SingleResourceEventArgs).File : null;
                var publishSettigsPath = m_service.GetPublishSettingsFilePathIfExist();
                var solutionPath       = m_service.GetSolutionRootPath();
                var basePath           = m_service.GetProjectBasePath();

                // Delete settings after breaking update
                if (!m_service.ReadOnlySettings.GetBoolean(SETTINGS_STORE, SETTINGS_KEY, false) && !string.IsNullOrEmpty(publishSettigsPath))
                {
                    File.Delete(publishSettigsPath);
                    publishSettigsPath = string.Empty;
                    m_service.WritableSettings.SetBoolean(SETTINGS_STORE, SETTINGS_KEY, true);
                }

                if (string.IsNullOrEmpty(publishSettigsPath))
                {
                    var dialog = new NewPublishSettingsPage(m_service, m_telemetry);
                    dialog.ShowDialog();
                    publishSettigsPath = (dialog.DataContext as NewPublishSettingsPageViewModel)?.FilePath;
                }

                // No valid configuration found or provided
                if (string.IsNullOrEmpty(publishSettigsPath))
                {
                    return;
                }

                var deployConfiguration = XmlObjectsHelper.Deserialize <DeployConfigurationModelFacade>(publishSettigsPath);
                var orchestrator        = new PublishOrchestrator();
                orchestrator.ReportProgress += LogProgress;

                var task = Async.Task.Factory.StartNew(() =>
                {
                    var projectName = m_service.GetSelectedProjectNameForAnalytics();
                    orchestrator.Publish(deployConfiguration.InnerObject, m_telemetry, singleResourceName, projectName, solutionPath, basePath);
                    orchestrator.ReportProgress -= LogProgress;
                }, m_token, Async.TaskCreationOptions.None, Async.TaskScheduler.Current);
            }
            catch (Exception ex)
            {
                m_service.LogMessage($"[ERROR] => {ex.Message}", m_pane);
                m_telemetry.TrackExceptionWithCustomMetrics(ex);
            }
        }
示例#6
0
        public SolutionDetailModel GetSolutionByName(string name)
        {
            SolutionDetailModel solution = null;

            try
            {
                var query = new QueryExpression("solution");
                query.Criteria.AddCondition("uniquename", ConditionOperator.Equal, name);
                var result = m_service.Value.RetrieveMultiple(query).Entities.FirstOrDefault();
                if (result != null)
                {
                    solution = new SolutionDetailModel(result.Id);
                }
            }
            catch (Exception exception)
            {
                m_progress?.Invoke($"[ERROR] => {exception.Message}");
                m_telemetry.TrackExceptionWithCustomMetrics(exception);
            }

            return(solution);
        }
示例#7
0
        private void PublishImpl(XrmService context, VersioningService gitvc, DeployConfigurationModel deployConfiguration, TelemetryWrapper telemetry, RawChanges[] changes, string project)
        {
            try
            {
                ChangeManagerService container = new ChangeManagerService(changes, deployConfiguration.Prefix, context);
                telemetry.TrackCustomEventWithCustomMetrics("Deploy Started", new MetricData("Project Name", project));

                if (container.WebResources.Count > 0)
                {
                    ReportProgress?.Invoke(this, $"[DYNAMICS] => Found {container.WebResources.Count} Web Resource.");
                    ReportProgress?.Invoke(this, $"[DYNAMICS] => '{deployConfiguration.Prefix}' used as base path.");
                    ReportProgress?.Invoke(this, $"[DYNAMICS] => Fetching '{deployConfiguration.Solution}' solution from CRM.");
                    container.EnsureContinue(deployConfiguration.Solution, deployConfiguration.Prefix);

                    ReportProgress?.Invoke(this, $"[DYNAMICS] => Publishing changes to the CRM.");
                    var faultedFlushResult = context.Flush(container.BuildRequestList(deployConfiguration.Solution));

                    if (!faultedFlushResult && deployConfiguration.CheckInEnabled)
                    {
                        ReportProgress?.Invoke(this, $"[AZOPS] => Commit & Push in progress.");
                        gitvc.CommitAndPush(deployConfiguration.Password);
                    }

                    ReportProgress?.Invoke(this, $"[AZOPS] => Publish completed.");
                }

                telemetry.TrackCustomEventWithCustomMetrics("Deploy Finished", new MetricData("Project Name", project));
            }
            catch (Exception exception)
            {
                ReportProgress?.Invoke(this, $"[ERROR] => {exception.Message}\n");
                if (!(exception is ToolkitException))
                {
                    telemetry.TrackExceptionWithCustomMetrics(exception);
                }
            }
        }