Пример #1
0
        bool SaveTasks()
        {
            if (CurrentEnvironment.IsConnected)
            {
                var authService = CurrentEnvironment.AuthorizationService;

                if (authService != null && authService.IsAuthorized(AuthorizationContext.Administrator, null))
                {
                    if (SelectedTask != null && SelectedTask.OldName != null && SelectedTask.IsDirty)
                    {
                        if (HasErrors && !Error.StartsWith(SaveErrorPrefix))
                        {
                            ShowSaveErrorDialog(Error);
                            return(false);
                        }

                        if (SelectedTask.OldName != SelectedTask.Name && !SelectedTask.OldName.Contains(NewTaskName) && !SelectedTask.IsNew)
                        {
                            var showNameChangedConflict = _popupController.ShowNameChangedConflict(SelectedTask.OldName,
                                                                                                   SelectedTask.Name);
                            if (showNameChangedConflict == MessageBoxResult.Cancel || showNameChangedConflict == MessageBoxResult.None)
                            {
                                return(false);
                            }
                            if (showNameChangedConflict == MessageBoxResult.No)
                            {
                                SelectedTask.Name = SelectedTask.OldName;
                                NotifyOfPropertyChange(() => Name);
                            }
                        }
                        if (SelectedTask.OldName != SelectedTask.Name && SelectedTask.OldName.Contains(NewTaskName))
                        {
                            SelectedTask.OldName = SelectedTask.Name;
                        }
                    }

                    GetCredentials(SelectedTask);
                    string errorMessage;
                    if (!ScheduledResourceModel.Save(SelectedTask, out errorMessage))
                    {
                        ShowSaveErrorDialog(errorMessage);
                        ShowError(errorMessage);
                        return(false);
                    }
                    Dev2Logger.Log.Info(String.Format("Save Schedule. Environment: {0} Name:{1} ", CurrentEnvironment.Name, SelectedTask != null ?SelectedTask.Name:""));
                    if (SelectedTask != null)
                    {
                        SelectedTask.Errors.ClearErrors();
                        NotifyOfPropertyChange(() => Error);
                        NotifyOfPropertyChange(() => Errors);
                        SelectedTask.OldName = SelectedTask.Name;
                        SelectedTask.IsNew   = false;
                    }
                    NotifyOfPropertyChange(() => TaskList);
                }
                else
                {
                    ShowError(@"Error while saving: You don't have permission to schedule on this server.
You need Administrator permission.");
                    return(false);
                }
                return(true);
            }
            ShowError(NotConnectedErrorMessage);
            return(false);
        }