示例#1
0
        async Task <IEnvironmentViewModel> ServerConnectedAsync(object sender, IServer server)
        {
            var environmentViewModel = await CreateEnvironmentViewModelAsync(sender, server.EnvironmentID, true).ConfigureAwait(true);

            environmentViewModel?.Server?.GetServerVersion();
            environmentViewModel?.Server?.GetMinSupportedVersion();
            SelectedEnvironment = environmentViewModel;
            StatsArea?.ReCalculate();
            if (environmentViewModel != null)
            {
                AfterLoad(environmentViewModel.ResourceId);
            }
            return(environmentViewModel);
        }
        async void Deploy()
        {
            IsDeploying = true;

            try
            {
                ErrorMessage = "";

                var serverInformation          = Source.SelectedServer.GetServerInformation();
                var supportsDirectServerDeploy = false;
                if (serverInformation != null)
                {
                    supportsDirectServerDeploy = serverInformation.ContainsKey("SupportsDirectServerDeploy") && bool.Parse(serverInformation["SupportsDirectServerDeploy"]);
                }
                CheckVersionConflict();
                if (!IsDeploying)
                {
                    return;
                }
                CheckResourceNameConflict();
                if (!IsDeploying)
                {
                    return;
                }

                var canDeploy = false;
                if (ConflictItems != null && ConflictItems.Count >= 1)
                {
                    var msgResult = PopupController.ShowDeployConflict(ConflictItems.Count);
                    if (msgResult == MessageBoxResult.Yes || msgResult == MessageBoxResult.OK)
                    {
                        canDeploy = true;
                    }
                }
                else
                {
                    canDeploy = true;
                }

                if (!canDeploy)
                {
                    ViewOverrides();
                }
                else
                {
                    var selectedItems     = Source.SelectedItems.Where(a => a.ResourceType != "Folder");
                    var explorerTreeItems = selectedItems as IExplorerTreeItem[] ?? selectedItems.ToArray();

                    var destinationEnvironmentId = Destination.ConnectControlViewModel.SelectedConnection.EnvironmentID;
                    var sourceEnv       = Source.Environments.First();
                    var sourceEnvServer = sourceEnv.Server;
                    var notfolders      = explorerTreeItems.Select(a => a.ResourceId).ToList();
                    var destEnv         = Destination.ConnectControlViewModel.SelectedConnection;
                    if (ConflictItems != null)
                    {
                        foreach (var conflictItem in ConflictItems)
                        {
                            if (destEnv?.ProxyLayer?.UpdateManagerProxy != null)
                            {
                                var task = Task.Run(async() => await destEnv.ProxyLayer.UpdateManagerProxy.MoveItem(
                                                        conflictItem.DestinationId, conflictItem.DestinationName,
                                                        conflictItem.SourceName));
                                task.Wait();
                            }
                        }
                    }
                    var deployResponse = new List <IDeployResult>();
                    if (supportsDirectServerDeploy)
                    {
                        if (destEnv != null)
                        {
                            var destConnection = new Connection
                            {
                                Address            = destEnv.Connection.AppServerUri.ToString(),
                                AuthenticationType = destEnv.Connection.AuthenticationType,
                                UserName           = destEnv.Connection.UserName,
                                Password           = destEnv.Connection.Password
                            };
                            deployResponse = sourceEnvServer.UpdateRepository.Deploy(notfolders, Destination.DeployTests, destConnection);
                        }
                    }

                    if (!supportsDirectServerDeploy || deployResponse.Where(r => r.HasError).Any())
                    {
                        _shell.DeployResources(sourceEnvServer.EnvironmentID, destinationEnvironmentId, notfolders, Destination.DeployTests);
                    }

                    DeploySuccessfull    = true;
                    DeploySuccessMessage = $"{notfolders.Count} Resource{(notfolders.Count == 1 ? "" : "s")} Deployed Successfully.";
                    var showDeploySuccessful = PopupController.ShowDeploySuccessful(DeploySuccessMessage);
                    if (showDeploySuccessful == MessageBoxResult.OK)
                    {
                        DeploySuccessfull = false;
                    }

                    await Destination.RefreshSelectedEnvironment();

                    UpdateServerCompareChanged(this, Guid.Empty);
                    _stats.ReCalculate();
                    Source.SelectedEnvironment.AsList().Apply(o => o.IsResourceChecked = false);
                }
            }
            catch (Exception e)
            {
                ErrorMessage = "Deploy error. " + e.Message;
            }
            IsDeploying = false;
        }