コード例 #1
0
        /// <summary>
        /// Constructs a new <see cref="CmdExecutor"/> object, initializes its command queue and sets the <see cref="TargetEnvironment"/> property.
        /// </summary>
        /// <param name="targetEnvironmentViewModel">The target environment which will participate in the <see cref="EnvironmentChanged"/> event.</param>
        /// <seealso cref="CmdExecutorBase"/>
        public CmdExecutor(EnvironmentViewModel targetEnvironmentViewModel)
        {
            var converter            = new EnvironmentConverter();
            var convertedEnvironment = converter.From(targetEnvironmentViewModel);

            TargetEnvironment = convertedEnvironment;
        }
コード例 #2
0
        public async Task TestLoad()
        {
            //arrange
            var serverID         = Guid.NewGuid();
            var explorerItemMock = new Mock <IExplorerItem>();

            _serverMock.SetupGet(it => it.IsConnected).Returns(true);
            _serverMock.SetupGet(it => it.EnvironmentID).Returns(serverID);
            _serverMock.Setup(it => it.LoadExplorer(false)).Returns(Task.FromResult(explorerItemMock.Object));

            var localhost = new Mock <IServer>();

            localhost.Setup(a => a.DisplayName).Returns("Localhost");
            localhost.SetupGet(server => server.CanDeployTo).Returns(true);

            var shellViewModel = new Mock <IShellViewModel>();

            var env        = new Mock <IEnvironmentViewModel>();
            var exploreItm = new Mock <IExplorerItemViewModel>();

            exploreItm.SetupGet(model => model.ResourceName).Returns("a");
            exploreItm.SetupGet(model => model.ResourceType).Returns("Dev2Server");
            exploreItm.SetupGet(model => model.ResourceId).Returns(serverID);
            exploreItm.SetupGet(model => model.Children).Returns(new BindableCollection <IExplorerItemViewModel>());

            var exploreItm1 = new Mock <IExplorerItemViewModel>();

            exploreItm1.SetupGet(model => model.ResourceName).Returns("a");
            exploreItm1.SetupGet(model => model.ResourceType).Returns("Dev2Server");
            exploreItm1.SetupGet(model => model.ResourceId).Returns(serverID);
            exploreItm1.SetupGet(model => model.Children).Returns(new BindableCollection <IExplorerItemViewModel>());
            env.SetupGet(model => model.Children).Returns(new BindableCollection <IExplorerItemViewModel>()
            {
                exploreItm.Object, exploreItm1.Object
            });

            shellViewModel.SetupGet(model => model.ExplorerViewModel).Returns(new Mock <IExplorerViewModel>().Object);
            shellViewModel.SetupGet(model => model.ExplorerViewModel.Environments).Returns(new BindableCollection <IEnvironmentViewModel>()
            {
                env.Object
            });
            var mockConnectControl = new Mock <IConnectControlViewModel>();

            mockConnectControl.SetupGet(a => a.Servers).Returns(new BindableCollection <IServer>()
            {
                _serverMock.Object
            });

            shellViewModel.Setup(model => model.ExplorerViewModel.ConnectControlViewModel).Returns(mockConnectControl.Object);
            shellViewModel.Setup(x => x.LocalhostServer).Returns(localhost.Object);
            shellViewModel.Setup(x => x.ActiveServer).Returns(new Mock <IServer>().Object);
            CustomContainer.Register(shellViewModel.Object);
            _target = new EnvironmentViewModel(_serverMock.Object, shellViewModel.Object);

            //act
            var result = await _target.LoadAsync();

            //assert
            Assert.IsFalse(_target.Children.Any());
        }
コード例 #3
0
        public void TestCreateFolderIsDialog()
        {
            //arrange
            _target = new EnvironmentViewModel(_serverMock.Object, _shellViewModelMock.Object, true);
            var explorerRepositoryMock = new Mock <IExplorerRepository>();

            _serverMock.SetupGet(it => it.ExplorerRepository).Returns(explorerRepositoryMock.Object);
            var isChildrenChanged = false;

            _target.CanCreateWorkflowService = false;
            _target.Children         = new ObservableCollection <IExplorerItemViewModel>();
            _target.PropertyChanged += (s, e) =>
            {
                isChildrenChanged = isChildrenChanged || e.PropertyName == "Children";
            };

            //act
            _target.CreateFolder();

            //assert
            var folder = _target.Children[0];

            Assert.IsTrue(isChildrenChanged);
            Assert.IsTrue(_target.IsExpanded);
            Assert.IsFalse(folder.AllowResourceCheck);
            Assert.IsFalse(folder.IsResourceChecked.HasValue && folder.IsResourceChecked.Value);
            Assert.IsFalse(folder.CanCreateSource);
            Assert.IsFalse(folder.CanCreateWorkflowService);
            Assert.IsFalse(folder.ShowContextMenu);
            Assert.IsFalse(folder.CanDeploy);
            Assert.IsFalse(folder.CanShowDependencies);
        }
コード例 #4
0
        private static List <ExpandoObject> GetFileList(string url, EnvironmentViewModel environment, FolderViewModel folder)
        {
            try
            {
                var html = GetDocumentFromUrl(url);
                var list = GetListOfNameAndDates(html);

                var returnList  = new List <ExpandoObject>();
                var listOfNames = list.Where(l => l.Value >= Filter.InitialDate && l.Value <= Filter.EndDate).ToList();

                foreach (var name in listOfNames)
                {
                    dynamic newExpando = new ExpandoObject();
                    newExpando.Name        = name.Key;
                    newExpando.Url         = url;
                    newExpando.Environment = environment;
                    newExpando.Folder      = folder;

                    returnList.Add(newExpando);
                }

                return(returnList);
            }
            catch (Exception ex)
            {
                ConsoleLog.WriteLog(url + " " + ex.Message, false);
                return(new List <ExpandoObject>());
            }
        }
コード例 #5
0
        /// <summary>
        /// Custom logic for reading a JSON object and converting it to an <see cref="EnvironmentViewModel"/>.
        /// </summary>
        /// <param name="reader">A <see cref="JsonReader"/>.</param>
        /// <param name="objectType">The <see cref="Type"/> to convert from.</param>
        /// <param name="existingValue">Unused.</param>
        /// <param name="serializer">The <see cref="JsonSerializer"/> to use.</param>
        /// <returns>A converter <see cref="EnvironmentViewModel"/> object.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            if (!CanConvert(objectType))
            {
                throw new NotSupportedException($"The converter cannot handle type {objectType}!");
            }

            JObject jObject   = JObject.Load(reader);
            var     viewModel = new EnvironmentViewModel
            {
                Name = jObject.GetValue("name", StringComparison.InvariantCultureIgnoreCase).ToString()
            };

            if (jObject.GetValue("environmentvariables", StringComparison.InvariantCultureIgnoreCase) is JObject
                environmentVariablesJObject)
            {
                foreach (var environmentVariable in environmentVariablesJObject)
                {
                    var environmentVariableViewModel = new EnvironmentVariableViewModel
                    {
                        Environment = viewModel,
                        Name        = environmentVariable.Key,
                        Value       = environmentVariable.Value.ToString()
                    };
                    viewModel.EnvironmentVariables.Add(environmentVariableViewModel);
                }
            }

            return(viewModel);
        }
コード例 #6
0
        public ActionResult Update(int id, [FromBody] EnvironmentViewModel Env)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
            }

            if (Env.Id != id)
            {
                return(BadRequest());
            }

            var EnvFind = _repo.FindById(id);

            EnvFind.Description = Env.Description;

            if (EnvFind is null)
            {
                return(NoContent());
            }

            _repo.Update(EnvFind);

            return(Ok());
        }
コード例 #7
0
        static IEnvironmentViewModel GetEnvironment()
        {
            var shellViewModel = CustomContainer.Get <IShellViewModel>();
            var env            = new EnvironmentViewModel(shellViewModel.ActiveServer, shellViewModel, true);

            return(env);
        }
コード例 #8
0
        /// <summary>
        /// Converts an <see cref="EnvironmentViewModel"/> to an <see cref="Environment"/> entity and inserts it if it's not been persisted yet. If it has, updates it.
        /// </summary>
        /// <param name="environment">The <see cref="EnvironmentViewModel"/> to save or update.</param>
        /// <returns>The newly-inserted or updated <see cref="Environment"/>, converted to an <see cref="EnvironmentViewModel"/></returns>
        public EnvironmentViewModel SaveEnvironment(EnvironmentViewModel environment)
        {
            var converter = new EnvironmentConverter();
            var entity    = converter.From(environment);
            var inserted  = _repository.UpsertEnvironment(entity);

            return(converter.To(inserted));
        }
コード例 #9
0
 public void TestInitialize()
 {
     _serverMock          = new Mock <IServer>();
     _shellViewModelMock  = new Mock <IShellViewModel>();
     _popupControllerMock = new Mock <IPopupController>();
     CustomContainer.Register(_popupControllerMock.Object);
     _target = new EnvironmentViewModel(_serverMock.Object, _shellViewModelMock.Object);
 }
コード例 #10
0
        public void then_environment_section_delta_file_property_had_logical_parent_element()
        {
            var environmentDeltaFileProperty = (ILogicalPropertyContainerElement)EnvironmentViewModel.Property("EnvironmentDeltaFile");

            Assert.IsNotNull(environmentDeltaFileProperty);
            Assert.IsNotNull(environmentDeltaFileProperty.ContainingElement);
            Assert.IsNotNull(environmentDeltaFileProperty.ContainingElementDisplayName);
        }
コード例 #11
0
 public EnvironmentChangedEventArgs(EnvironmentViewModel newActiveEnvironment)
 {
     NewActiveEnvironment = newActiveEnvironment;
     if (NewActiveEnvironment != null)
     {
         NewActiveEnvironment.IsActive = true;
     }
 }
コード例 #12
0
 public ActionResult <EnvironmentViewModel> PostEnvironment([FromBody] EnvironmentViewModel value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(Ok(_mapper.Map <EnvironmentViewModel>(_service.RegisterEnvironment(_mapper.Map <Environment>(value)))));
 }
コード例 #13
0
        public PartialViewResult Environment()
        {
            var viewModel = new EnvironmentViewModel {
                EnvironmentName = _configurationValues.EnvironmentName
            };

            return(PartialView("~/Views/Shared/_Environment.cshtml", viewModel));
        }
コード例 #14
0
        public ActionResult Create()
        {
            var viewModel = new EnvironmentViewModel();

            viewModel.Products = ProductService.GetAll().ToList();

            return(View(viewModel));
        }
コード例 #15
0
 public ActionResult Create(EnvironmentViewModel viewModel)
 {
     Logger.DebugFormat ("Creating Environment: {0}", viewModel);
     try {
         return RedirectToAction ("Index");
     } catch {
         return View ();
     }
 }
コード例 #16
0
        public async Task <IActionResult> Create(EnvironmentViewModel environmentViewModel)
        {
            if (ModelState.IsValid)
            {
                _environmentAppService.Add(environmentViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(environmentViewModel));
        }
コード例 #17
0
        public MainWindow(TankViewModel tankvm, EnvironmentViewModel envirovm)
        {
            _tankViewModel   = tankvm;
            _enviroViewModel = envirovm;

            InitializeComponent();
            Tank1StackPanel.DataContext  = _tankViewModel.Tank1;
            Tank2StackPanel.DataContext  = _tankViewModel.Tank2;
            EnviroStackPanel.DataContext = _enviroViewModel;
        }
コード例 #18
0
        private EnvironmentViewModel GetEnvironmentModel(ApplicationUser user)
        {
            var environments = this.AppEnvironmentService.GetAppEnvironments(user.Id);

            var environmentViewModel = new EnvironmentViewModel(user);

            environmentViewModel.AddAllowedEnvironments(environments);

            return(environmentViewModel);
        }
コード例 #19
0
        private MainViewModel BuildMainDataContext()
        {
            var width = Properties.Settings.Default.EcosystemWidth;
            var height = Properties.Settings.Default.EcosystemHeight;

            // the event aggregator might be used by view models to inform of changes
            var eventaggregator = new EventAggregator();

            var habitats = new Habitat[width, height];
            var habitatViewModels = new List<List<HabitatViewModel>>();

            for (var x = 0; x < width; x++)
            {
                habitatViewModels.Add(new List<HabitatViewModel>());

                for (var y = 0; y < height; y++)
                {
                    // initially set each habitat to have an unknown environment and no organism
                    var environment = new Environment(Terrain.Unknown, false);
                    var environmentViewModel = new EnvironmentViewModel(environment, eventaggregator);

                    var organismViewModel = new OrganismViewModel(null, eventaggregator);

                    var habitat = new Habitat(environment, null);
                    var habitatViewModel = new HabitatViewModel(habitat, environmentViewModel, organismViewModel, eventaggregator);

                    habitats[x, y] = habitat;
                    habitatViewModels[x].Add(habitatViewModel);
                }
            }

            var ecosystem = new Ecosystem(habitats, new Dictionary<Organism, Habitat>());
            var ecosystemViewModel = new EcosystemViewModel(ecosystem, habitatViewModels, eventaggregator);

            this.InitialiseTerrain(ecosystem);
            var initialOrganismCoordinates = this.InitialiseOrganisms(ecosystem);

            // TODO: do this in InitialiseOrganisms
            // boshed together so the organisms are visible before ecosystem is switched on the first time
            foreach (var organismCoordinate in initialOrganismCoordinates)
            {
                habitatViewModels[organismCoordinate.X][organismCoordinate.Y].RefreshOrganismViewModel();
            }

            // TODO: setting up the summary view after organisms initialised... how to handle this nicely
            var organismViewModels = habitatViewModels.SelectMany(habitatViewModel => habitatViewModel)
                                                      .Select(habitatViewModel => habitatViewModel.OrganismViewModel)
                                                      .Where(organismViewModel => organismViewModel.HasOrganism).ToList();
            var organismSummaryViewModel = new OrganismSummaryViewModel(ecosystem, organismViewModels, eventaggregator);

            var main = new Main(ecosystem);
            var mainViewModel = new MainViewModel(main, ecosystemViewModel, organismSummaryViewModel, eventaggregator);

            return mainViewModel;
        }
コード例 #20
0
        public ActionResult Index(EnvironmentViewModel model)
        {
            udcEntities db = new udcEntities();

            model.Charts = db.EnvironmentDataNames.Select(n => new EnvironmentViewChart {
                Id = n.EnvironmentDataNameId, Title = n.EnvironmentDataName1
            }).ToList();
            model.Charts.RemoveAll(c => c.Title == "platform" || c.Title == "appVersion" || c.Title == "commit");
            ViewData.Model = model;
            return(View());
        }
コード例 #21
0
        public bool Update(EnvironmentViewModel entity)
        {
            var environment = _repo.Find(x => x.Id == entity.Id && x.Deleted == false);

            if (environment != null)
            {
                return(_repo.Update(_mapper.Map <Environment>(entity)));
            }

            return(false);
        }
コード例 #22
0
 private void SetEnvironmentModel(EnvironmentViewModel environmentViewModel, ApplicationUser user)
 {
     if (user.PreferredEnvironment == null)
     {
         this.AddEnvironmentToSession(environmentViewModel.SelectedEnvironment);
     }
     else
     {
         this.AddEnvironmentToSession(user.PreferredEnvironment);
     }
 }
コード例 #23
0
        public ActionResult Create([FromBody] EnvironmentViewModel Env)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(e => e.Errors)));
            }

            _repo.Add(_mapper.Map <Domain.Models.Environment>(Env));

            return(CreatedAtAction(nameof(GetById), new { id = Env.Id }, Env));
        }
コード例 #24
0
        public static EnvironmentViewModel ToViewModel(this Entities.Environment environment)
        {
            var vm = new EnvironmentViewModel()
            {
                EnvironmentId   = environment.EnvironmentId,
                EnvironmentUuid = environment.EnvironmentUuid,
                Name            = environment.Name,
                HostName        = environment.HostName
            };

            return(vm);
        }
コード例 #25
0
 public ActionResult Edit(EnvironmentViewModel viewModel, int?page)
 {
     if (ModelState.IsValid)
     {
         var environment = AutoMapper.Mapper.Map <EnvironmentViewModel, IEnvironment>(viewModel);
         if (viewModel != null && viewModel.SelectedProductId > 0)
         {
             environment.Product = ProductService.GetById(viewModel.SelectedProductId);
         }
         EnvironmentService.CreateOrUpdate(environment);
         return(RedirectToAction("Index", new { page }));
     }
     return(View(viewModel));
 }
コード例 #26
0
        public Common.Entities.Environment Update(EnvironmentViewModel toUpdate)
        {
            var env = Get(toUpdate.EnvironmentId);

            if (string.IsNullOrEmpty(toUpdate.Name))
            {
                throw new EntityValidationException("Environmemnt Name cannot be blank!");
            }

            env.Name     = toUpdate.Name;
            env.HostName = toUpdate.HostName;

            return(env);
        }
コード例 #27
0
        public async Task <IActionResult> Edit(Guid id, EnvironmentViewModel environmentViewModel)
        {
            if (id != environmentViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _environmentAppService.Update(environmentViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(environmentViewModel));
        }
コード例 #28
0
 private static void EnvironmentShortcuts(KeyEventArgs e, EnvironmentViewModel environmentViewModel)
 {
     if (e.Key == Key.W && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
     {
         environmentViewModel.NewServiceCommand.Execute(null);
     }
     if (e.Key == Key.D && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
     {
         environmentViewModel.DeployCommand.Execute(null);
     }
     if (e.Key == Key.F && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
     {
         environmentViewModel.CreateFolder();
     }
 }
コード例 #29
0
        /// <summary>
        /// Validates the supplied <see cref="EnvironmentViewModel"/>. If the validation is successful, converts to an <see cref="Environment"/> entity and inserts it in the datastore.
        /// </summary>
        /// <param name="environmentViewModel">The <see cref="EnvironmentViewModel"/> to insert.</param>
        /// <returns>If the validation is successful, return a new instance of the <see cref="EnvironmentViewModel"/> with its id updated. Otherwise, returns null.</returns>
        public EnvironmentViewModel InsertEnvironment(EnvironmentViewModel environmentViewModel)
        {
            var validator        = new EnvironmentViewModelValidator();
            var validationResult = validator.Validate(environmentViewModel);

            if (validationResult.IsValid)
            {
                var converter = new EnvironmentConverter();
                var converted = converter.From(environmentViewModel);
                var inserted  = _repository.InsertEnvironment(converted);
                return(converter.To(inserted));
            }

            return(null);
        }
コード例 #30
0
        public void TestSetPropertiesForDialogIsDialogTrue()
        {
            //arrange
            _target = new EnvironmentViewModel(_serverMock.Object, _shellViewModelMock.Object, true);

            //act
            _target.SetPropertiesForDialog();

            //assert
            Assert.IsFalse(_target.AllowResourceCheck);
            Assert.IsFalse(_target.CanCreateSource);
            Assert.IsFalse(_target.CanCreateWorkflowService);
            Assert.IsFalse(_target.ShowContextMenu);
            Assert.IsFalse(_target.CanDeploy);
        }
コード例 #31
0
        public async Task TestLoadDialog()
        {
            //arrange
            var selPath          = Guid.NewGuid();
            var explorerItemMock = new Mock <IExplorerItem>();

            _serverMock.SetupGet(it => it.IsConnected).Returns(true);
            _serverMock.Setup(it => it.LoadExplorer(false)).Returns(Task.FromResult(explorerItemMock.Object));
            _target = new EnvironmentViewModel(_serverMock.Object, _shellViewModelMock.Object);

            //act
            var result = await _target.LoadDialog(selPath);

            //assert
            Assert.IsFalse(_target.Children.Any());
        }
コード例 #32
0
        public void TestInitialize()
        {
            _serverMock          = new Mock <IServer>();
            _shellViewModelMock  = new Mock <IShellViewModel>();
            _popupControllerMock = new Mock <IPopupController>();
            CustomContainer.Register(_popupControllerMock.Object);
            var serverRepo = new Mock <IServerRepository>();

            CustomContainer.Register(serverRepo.Object);
            var connectControlSingleton = new Mock <IConnectControlSingleton>();

            CustomContainer.Register(connectControlSingleton.Object);
            _explorerTooltips = new Mock <IExplorerTooltips>();
            CustomContainer.Register(_explorerTooltips.Object);
            _target = new EnvironmentViewModel(_serverMock.Object, _shellViewModelMock.Object);
        }