Inheritance: IScheduledResourceModel
        void SetupServer(IServer tmpEnv)
        {
            CurrentEnvironment = ToEnvironmentModel(tmpEnv);

            if (CurrentEnvironment?.AuthorizationService != null && CurrentEnvironment.IsConnected && tmpEnv.Permissions.Any(a => a.Administrator))
            {
                ClearConnectionError();
                var server = CurrentEnvironment ?? ServerRepository.Instance.ActiveServer;

                if (server.Permissions == null)
                {
                    server.Permissions = new List <IWindowsGroupPermission>();
                    server.Permissions.AddRange(server.AuthorizationService.SecurityService.Permissions);
                }
                SchedulerTaskManager.Source = new EnvironmentViewModel(server, CustomContainer.Get <IShellViewModel>(), true);

                ScheduledResourceModel = new ClientScheduledResourceModel(CurrentEnvironment, CreateNewTask);
                IsLoading = true;
                try
                {
                    var cmd = AddWorkflowCommand as Microsoft.Practices.Prism.Commands.DelegateCommand;
                    cmd?.RaiseCanExecuteChanged();

                    foreach (var scheduledResource in ScheduledResourceModel.ScheduledResources.Where(a => !a.IsNewItem))
                    {
                        scheduledResource.NextRunDate = scheduledResource.Trigger.Trigger.StartBoundary;
                        scheduledResource.OldName     = scheduledResource.Name;
                    }
                    NotifyOfPropertyChange(() => TaskList);
                    if (TaskList.Count > 0)
                    {
                        SelectedTask = TaskList[0];
                    }
                    IsLoading = false;
                }
                catch (Exception ex)
                {
                    if (!_errorShown)
                    {
                        Dev2Logger.Error(ex);
                        _errorShown = true;
                    }
                }
            }
            else
            {
                ClearConnectionError();
                ClearViewModel();
            }
        }
Example #2
0
        void OnServerChanged(object obj)
        {
            var tmpEnv = obj as IEnvironmentModel;

            if (!DoDeactivate())
            {
                return;
            }
            CurrentEnvironment = tmpEnv;

            if (CurrentEnvironment != null && CurrentEnvironment.AuthorizationService != null && CurrentEnvironment.IsConnected)
            {
                if (CurrentEnvironment.AuthorizationService.IsAuthorized(AuthorizationContext.Administrator, null))
                {
                    ClearConnectionError();
                    _resourcePicker        = new ResourcePickerDialog(enDsfActivityType.Workflow, CurrentEnvironment);
                    ScheduledResourceModel = new ClientScheduledResourceModel(CurrentEnvironment);
                    IsLoading = true;
                    _asyncWorker.Start(
                        () =>
                        ScheduledResourceModel.ScheduledResources = ScheduledResourceModel.GetScheduledResources(), () =>
                    {
                        foreach (var scheduledResource in ScheduledResourceModel.ScheduledResources)
                        {
                            scheduledResource.NextRunDate = scheduledResource.Trigger.Trigger.StartBoundary;
                            scheduledResource.OldName     = scheduledResource.Name;
                        }

                        NotifyOfPropertyChange(() => TaskList);
                        if (TaskList.Count > 0)
                        {
                            SelectedTask = TaskList[0];
                        }
                        IsLoading = false;
                    });
                }
                else
                {
                    SetConnectionError();
                    ClearViewModel();
                }
            }
            else
            {
                ClearConnectionError();
                ClearViewModel();
            }
        }
 public void ClientScheduledResourceModel_DeleteScheduledResource_CallsCommunicationsController()
 {
     //------------Setup for test--------------------------
     var scheduledResourceForTest = new ScheduledResourceForTest();
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(scheduledResourceForTest);
     var esbPayLoad = new EsbExecuteRequest { ServiceName = "DeleteScheduledResourceService" };
     esbPayLoad.AddArgument("Resource", serializeObject);
     var mockEnvironmentModel = new Mock<IEnvironmentModel>();
     var mockConnection = new Mock<IEnvironmentConnection>();
     mockConnection.Setup(connection => connection.IsConnected).Returns(true);
     mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>(), It.IsAny<Guid>())).Verifiable();
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     clientScheduledResourceModel.DeleteSchedule(scheduledResourceForTest);
     //------------Assert Results-------------------------
     mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>(), It.IsAny<Guid>()), Times.Once());
 }
 public void ClientScheduledResourceModel_GetScheduledResources_ReturnsCollectionOfIScheduledResource()
 {
     //------------Setup for test--------------------------
     var resources = new ObservableCollection<IScheduledResource>();
     var scheduledResourceForTest = new ScheduledResourceForTest();
     resources.Add(scheduledResourceForTest);
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(resources);
     var mockEnvironmentModel = new Mock<IEnvironmentModel>();
     var mockConnection = new Mock<IEnvironmentConnection>();
     mockConnection.Setup(connection => connection.IsConnected).Returns(true);
     mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>(), It.IsAny<Guid>())).Returns(serializeObject);
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     var scheduledResources = clientScheduledResourceModel.GetScheduledResources();
     //------------Assert Results-------------------------
     Assert.AreEqual(1, scheduledResources.Count);
 }
 public void ClientScheduledResourceModel_CreateHistory_ReturnsListOfIResourceHistory()
 {
     //------------Setup for test--------------------------
     var scheduledResourceForTest = new ScheduledResourceForTest();
     var resourceHistory = new ResourceHistoryForTest();
     var listOfHistoryResources = new List<IResourceHistory> { resourceHistory };
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(listOfHistoryResources);
     var mockEnvironmentModel = new Mock<IEnvironmentModel>();
     var mockConnection = new Mock<IEnvironmentConnection>();
     mockConnection.Setup(connection => connection.IsConnected).Returns(true);
     mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializeObject);
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     var resourceHistories = clientScheduledResourceModel.CreateHistory(scheduledResourceForTest);
     //------------Assert Results-------------------------
     mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>()), Times.Once());
     Assert.AreEqual(1, resourceHistories.Count);
 }
Example #6
0
        void OnServerChanged(object obj)
        {
            var tmpEnv = obj as IEnvironmentModel;

            if(!DoDeactivate())
            {
                return;
            }
            CurrentEnvironment = tmpEnv;

            if(CurrentEnvironment != null && CurrentEnvironment.AuthorizationService != null && CurrentEnvironment.IsConnected)
            {
                if(CurrentEnvironment.AuthorizationService.IsAuthorized(AuthorizationContext.Administrator, null))
                {
                    ClearConnectionError();
                    _resourcePicker = new ResourcePickerDialog(enDsfActivityType.Workflow, CurrentEnvironment);
                    ScheduledResourceModel = new ClientScheduledResourceModel(CurrentEnvironment);
                    IsLoading = true;
                    _asyncWorker.Start(
                        () =>
                        ScheduledResourceModel.ScheduledResources = ScheduledResourceModel.GetScheduledResources(), () =>
                    {
                        foreach(var scheduledResource in ScheduledResourceModel.ScheduledResources)
                        {
                            scheduledResource.NextRunDate = scheduledResource.Trigger.Trigger.StartBoundary;
                            scheduledResource.OldName = scheduledResource.Name;
                        }

                        NotifyOfPropertyChange(() => TaskList);
                        if(TaskList.Count > 0)
                        {
                            SelectedTask = TaskList[0];
                        }
                        IsLoading = false;
                    });
                }
                else
                {
                    SetConnectionError();
                    ClearViewModel();
                }
            }
            else
            {
                ClearConnectionError();
                ClearViewModel();
            }
        }
 public void ClientScheduledResourceModel_SaveScheduledResource_HasError_CallsCommunicationsController()
 {
     //------------Setup for test--------------------------
     var scheduledResourceForTest = new ScheduledResourceForTest();
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(scheduledResourceForTest);
     var esbPayLoad = new EsbExecuteRequest { ServiceName = "AddScheduledResourceService" };
     esbPayLoad.AddArgument("Resource", serializeObject);
     var returnMessage = new ExecuteMessage { HasError = true, Message = new StringBuilder("Error occurred") };
     var serializedReturnMessage = serializer.SerializeToBuilder(returnMessage);
     var mockEnvironmentModel = new Mock<IEnvironmentModel>();
     var mockConnection = new Mock<IEnvironmentConnection>();
     mockConnection.Setup(connection => connection.IsConnected).Returns(true);
     mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Verifiable();
     mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializedReturnMessage);
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     string errorMessage;
     var saved = clientScheduledResourceModel.Save(scheduledResourceForTest, out errorMessage);
     //------------Assert Results-------------------------
     mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>()), Times.Once());
     Assert.IsFalse(saved);
     Assert.AreEqual("Error occurred", errorMessage);
 }