Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var cultureInfo = new CultureInfo("en-GB");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            EnvironmentModel EnvronmentSetting = new EnvironmentModel()
            {
                GoogleMapApi = Configuration.GetSection("GoogleMapApi").Get <GoogleMapApi>(),
            };
            string _baseUrl = Encoding.UTF8.GetString(Convert.FromBase64String(EnvronmentSetting.GoogleMapApi.BaseUrl));

            EnvronmentSetting.GoogleMapApi.BaseUrl = string.Format(_baseUrl, EnvronmentSetting.GoogleMapApi.Type, EnvronmentSetting.GoogleMapApi.ApiKey, "{0}");

            services.AddHttpClient();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Core API", Version = "v1"
                });
            });

            services.AddControllers();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Register Service
            services.AddScoped <IEnvironmentConfigs>(r => new EnvironmentConfigs(EnvronmentSetting));
            services.AddScoped <IGoogleMapApiService, GoogleMapApiService>();

            // Register Repository
            services.AddScoped <IGoogleMapApiRepository, GoogleMapApiRepository>();
        }
Example #2
0
        // ReSharper disable InconsistentNaming - Unit Tests
        public void Save_WithValidConnection_Expected_InvokesSaveEnvironmentWithCategory()
        // ReSharper restore InconsistentNaming - Unit Tests
        {
            // BUG: 8786 - TWR - 2013.02.20
            var mockConnection = new Mock <IEnvironmentConnection>();

            mockConnection.Setup(connection => connection.ServerEvents).Returns(new Mock <IEventPublisher>().Object);
            var mockResourceRepo = new Mock <IResourceRepository>();
            var enviro           = new EnvironmentModel(Guid.NewGuid(), mockConnection.Object, mockResourceRepo.Object, new Mock <IStudioResourceRepository>().Object);

            var currentRepository = new Mock <IEnvironmentRepository>();

            currentRepository.Setup(e => e.Save(It.IsAny <IEnvironmentModel>())).Verifiable();
            currentRepository.Setup(c => c.ActiveEnvironment).Returns(enviro);

            var env = new Mock <IEnvironmentModel>();

            env.SetupProperty(e => e.Category); // start tracking sets/gets to this property

            currentRepository.Setup(e => e.Fetch(It.IsAny <IEnvironmentModel>())).Returns(env.Object);

            var handler = new ConnectCallbackHandler(new Mock <IEventAggregator>().Object, currentRepository.Object);

            handler.Save(ConnectionJson, null);

            // ReSharper disable PossibleUnintendedReferenceComparison - expected to be the same instance
            currentRepository.Verify(r => r.Save(It.IsAny <IEnvironmentModel>()));
            // ReSharper restore PossibleUnintendedReferenceComparison
        }
    private void EndTransition(object value)
    {
        EnvironmentModel newSprites = value as EnvironmentModel;

        newBackground = newSprites.backGround as Sprite;
        sprites       = newSprites.wallSprites as Sprite[];
    }
        private EnvironmentModel GetTestEnvironmentConfig()
        {
            EnvironmentModel env = new EnvironmentModel();

            env.Name     = "test";
            env.Commands = new List <CommandModel>();

            CommandModel cmd = new CommandModel();

            cmd.PluginType = "CreateTestFile";
            cmd.Settings   = new List <CommandSettingModel>();

            CommandSettingModel filename = new CommandSettingModel();

            filename.Name  = "FileName";
            filename.Value = "test_file.txt";
            cmd.Settings.Add(filename);

            CommandSettingModel message = new CommandSettingModel();

            message.Name  = "TestData";
            message.Value = "TEST_MESSAGE";
            cmd.Settings.Add(message);

            env.Commands.Add(cmd);

            return(env);
        }
Example #5
0
        public void LoadTestConfigFile()
        {
            try {
                MakeTestConfigFile();

                ConfigManager configManager = new ConfigManager();
                ConfigModel   config        = configManager.Load();

                Assert.AreEqual(1, config.Applications.Count);
                ApplicationModel app = config.Applications.First();
                Assert.AreEqual("DbDelivery", app.Name);
                Assert.AreEqual(1, app.Environments.Count);
                EnvironmentModel env = app.Environments.First();
                Assert.AreEqual("test", env.Name);
                Assert.AreEqual(1, env.Commands.Count);
                CommandModel cmd = env.Commands.First();
                Assert.AreEqual("InitDatabase", cmd.PluginType);
                Assert.AreEqual(2, cmd.Settings.Count);
                CommandSettingModel providerName = cmd.Settings.FirstOrDefault(c => c.Name == "ProviderName");
                Assert.IsNotNull(providerName);
                Assert.IsFalse(String.IsNullOrEmpty(providerName.Value));
                CommandSettingModel connString = cmd.Settings.FirstOrDefault(c => c.Name == "ConnectionString");
                Assert.IsNotNull(connString);
                Assert.IsFalse(String.IsNullOrEmpty(connString.Value));
            } finally {
                if (File.Exists("config.xml"))
                {
                    File.Delete("config.xml");
                }
            }
        }
        /// <inheritdoc />
        public async Task UpdateApplicationMetadata(
            string org,
            string app,
            Application applicationMetadata,
            EnvironmentModel environmentModel)
        {
            Uri uri = new Uri($"{CreateUri(environmentModel)}{org}/{app}");

            if (uri.Host.Contains("tt02", StringComparison.InvariantCultureIgnoreCase))
            {
                _httpClient.DefaultRequestHeaders.Add(_platformSettings.SubscriptionKeyHeaderName, _platformSettings.SubscriptionKeyTT02);
            }

            string stringContent = JsonSerializer.Serialize(applicationMetadata);

            /*
             * Have to create a HttpRequestMessage instead of using helper extension methods like _httpClient.PostAsync(...)
             * because the base address can change on each request and after HttpClient gets initial base address,
             * it is not advised (and not allowed) to change base address.
             */
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, uri)
            {
                Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
            };
            await _httpClient.SendAsync(request);
        }
Example #7
0
        /// <summary>
        /// Make migration for the application in the environment
        /// </summary>
        /// <param name="applicationName"></param>
        /// <param name="environmentName"></param>
        public void Migrate(string applicationName, string environmentName)
        {
            ConfigModel      config   = this.ConfigManager.Load();
            EnvironmentModel envModel = this.ConfigManager.GetEnvironmentConfig(config, applicationName, environmentName);

            this.CommandInvoker.Invoke(envModel);
        }
        static void TestAuxilliaryConnections(string appServerUri)
        {
            var repo        = new Mock <IResourceRepository>();
            var sRepo       = new Mock <IStudioResourceRepository>();
            var connection  = CreateConnection(appServerUri);
            var environment = new EnvironmentModel(Guid.NewGuid(), connection, repo.Object, sRepo.Object)
            {
                Name = "conn"
            };

            var auxRepo        = new Mock <IResourceRepository>();
            var auxConnection  = CreateConnection(appServerUri);
            var auxEnvironment = new EnvironmentModel(Guid.NewGuid(), auxConnection, auxRepo.Object, sRepo.Object)
            {
                Name = "auxconn"
            };

            environment.Connect();
            Assert.IsTrue(environment.IsConnected);

            auxEnvironment.Connect(environment);
            Assert.IsTrue(auxEnvironment.IsConnected);

            auxEnvironment.Disconnect();
            environment.Disconnect();
        }
Example #9
0
        public void Lookup()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_Url.Replace("ssdp", "environment"));
                request.Accept = "application/json";

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    var serializer = new JsonSerializer();
                    using (var sr = new StreamReader(response.GetResponseStream()))
                        using (var jsonTextReader = new JsonTextReader(sr))
                        {
                            EnvironmentModel Model = (EnvironmentModel)serializer.Deserialize(jsonTextReader, typeof(EnvironmentModel));

                            string IPWithPort = m_IpAddress.Address + ((m_IpAddress.Port != 80) ? ":" + m_IpAddress.Port : "");

                            Resolved?.Invoke(this, new DataGridRow()
                            {
                                Name = Model.machineName, Url = "http://" + IPWithPort + "/", IpAddress = IPWithPort, Location = Model.location
                            });
                        }
                }
            }
            catch (WebException)
            {
                LookupLegacy();
            }
            catch (Exception)
            {
                Errored?.Invoke(this, m_Url);
            }
        }
        public JsonResult Update(EnvironmentModel data)
        {
            string    message         = "";
            string    jsonResult      = "";
            string    procedureValues = "";
            DataTable payload         = null;

            procedureValues = dbObject.checkDataType(data);

            if (ModelState.IsValid)
            {
                var result = dbObject.SQLConnection("Update_Environment", procedureValues);
                message = result.Item1;
                payload = result.Item2;
            }
            else
            {
                var err = string.Join(" | ", ModelState.Values
                                      .SelectMany(v => v.Errors)
                                      .Select(e => e.ErrorMessage));

                message = "Please provide required fields: " + err;
            }

            jsonResult = dbObject.BuildDataTableToJson(payload);

            var jsonResponse = new { message = message, results = jsonResult };

            return(Json(jsonResponse, JsonRequestBehavior.AllowGet));
        }
        public void WhenConnectedAsUserPartOf(string userGroup)
        {
            if (AccountExists("SpecsUser"))
            {
                if (!IsUserInGroup("SpecsUser", userGroup))
                {
                    try
                    {
                        SecurityIdentifier id            = GetUserSecurityIdentifier("SpecsUser");
                        PrincipalContext   context       = new PrincipalContext(ContextType.Machine);
                        UserPrincipal      userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.Sid, id.Value);
                        AddUserToGroup(userGroup, context, userPrincipal);
                    }
                    catch (Exception)
                    {
                        Assert.Fail("User not found");
                    }
                }
            }
            else
            {
                CreateLocalWindowsAccount("SpecsUser", "T35t3r!@#", userGroup);
            }
            var reconnectModel = new EnvironmentModel(Guid.NewGuid(), new ServerProxy(AppSettings.LocalHost, "SpecsUser", "T35t3r!@#"))
            {
                Name = "Other Connection"
            };

            ScenarioContext.Current.Add("currentEnvironment", reconnectModel);
        }
Example #12
0
 private static void CreateModel()
 {
     model              = new EnvironmentModel();
     model.Offset       = new Vector3(0, 0, 0);
     model.bricks       = new List <Brick> ();
     model.CurrentLevel = 0;
 }
Example #13
0
    public void OnButtonSaveEnvironmentClicked()
    {
        var nameEnvironment = txtUser.text;

        if (nameEnvironment.Length == 0)
        {
            nameEnvironment = "Sem nome";
        }

        var environmentModel = new EnvironmentModel
        {
            id              = EnviromentController.Instance.allEnvironments.Count + 1,
            idIcon          = indexEnvironment,
            nameEnvironment = nameEnvironment
        };

        if (newEnvironmentSave != null)
        {
            newEnvironmentSave(environmentModel.id, nameEnvironment);
        }

        EnviromentController.Instance.allEnvironments.Add(environmentModel);
        AppManager.Instance.CheckEnvironments();

        Destroy(gameObject);
    }
Example #14
0
    public void OnButtonSelectEnvironmentClicked(EnvironmentModel environment)
    {
        print("Open Environment:: " + environment.nameEnvironment);
        OutputEnvironmentScreen outputEnvironmentScreen = Instantiate(screenOutputsEnvironment, canvasMain);

        outputEnvironmentScreen.SetNameEnvironment(environment.nameEnvironment);
        outputEnvironmentScreen.idEnvironment = environment.id;
    }
        // GET: Server
        public ActionResult EnvironmentDetails(EnvironmentModel data)
        {
            var model = new EnvironmentModel();

            ViewBag.environmentDetails = model.EnvironmentDetails(data.Environment_ID);
            ViewBag.ID = data.Environment_ID;

            return(PartialView("~/Views/Forms/SoftwareCatalogue/Environment/Environment_Details.cshtml", model));
        }
Example #16
0
 public void GivenIHaveAServer(string serverName)
 {
     if (serverName != "localhost")
     {
         var environmentModel = new EnvironmentModel(Guid.NewGuid(), new ServerProxy(new Uri(string.Format("http://{0}:3142", serverName))));
         EnvironmentRepository.Instance.Save(environmentModel);
         environmentModel.Connect();
     }
 }
    private void StartTransition(object value)
    {
        sprites = null;
        EnvironmentModel newSprites = value as EnvironmentModel;

        newBackground = woodBackground;
        sprites       = woodsSprites;
        isTransition  = true;
    }
Example #18
0
        /// <summary>
        /// Build commands and execute it
        /// </summary>
        /// <param name="config"></param>
        public void Invoke(EnvironmentModel config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            IEnumerable <IPluginCommand> commandChain = BuildChain(config);

            ExecuteChain(commandChain);
        }
Example #19
0
        public void EnvironmentModel_Constructor_ConnectionAndWizardEngine_InitializesConnectionAndResourceRepository()
        {
            var connection = CreateConnection();
            //, wizard.Object
            var env = new EnvironmentModel(Guid.NewGuid(), connection.Object);

            Assert.IsNotNull(env.Connection);
            Assert.IsNotNull(env.ResourceRepository);
            Assert.AreSame(connection.Object, env.Connection);
        }
Example #20
0
        /// <inheritdoc />
        public async Task UpdateApplicationAuthorizationPolicyAsync(
            string org,
            string app,
            string fullCommitId,
            EnvironmentModel deploymentEnvironment)
        {
            string policyFile = await GetAuthorizationPolicyFileFromGitea(org, app, fullCommitId);

            await _authorizationPolicyClient.SavePolicy(org, app, policyFile, deploymentEnvironment);
        }
Example #21
0
 public static Environment ToNewDbObject(this EnvironmentModel environment)
 {
     return(new Environment
     {
         EnvironmentName = environment.EnvironmentName,
         EnvironmentTypeId = (int)environment.EnvironmentType,
         IsActive = environment.IsActive,
         SuiteId = environment.SuiteId
     });
 }
Example #22
0
    private void StartTransition(object value)
    {
        //Change Sprites
        sprites = null; //reset just incase
        EnvironmentModel newSprites = value as EnvironmentModel;

        sprites         = woodsSprites;
        isTransition    = true;
        isTransitionOut = true;
    }
Example #23
0
    private void ChoosedEnvironment(EnvironmentModel environmentModel)
    {
        if (environmentModel == null)
        {
            return;
        }

        print(string.Format("Choosed id environment {1} and name environment {2}", environmentModel.id, environmentModel.nameEnvironment));
        txtNameEnvironmentOutput.text = environmentModel.nameEnvironment;
    }
Example #24
0
    private void ChoosedEnvironment(EnvironmentModel environmentModel)
    {
        if (environmentModel == null)
        {
            return;
        }

        print(string.Format("Button of output {0}, choosed id environment {1} and name environment {2}", outputEnvironmentClicked, environmentModel.id, environmentModel.nameEnvironment));
        txtNameEnvironmentOutput1.text = environmentModel.nameEnvironment;
    }
Example #25
0
        public LogRepository(ILogs ILogs, IEnvironmentConfigs IEnvironmentConfigs)
        {
            var cultureInfo = new CultureInfo("en-GB");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            _ILogs = ILogs;
            _IEnvironmentConfigs = IEnvironmentConfigs;
            _EnvironmentModel    = _IEnvironmentConfigs.GetEnvironmentSetting();
        }
Example #26
0
        public void EnvironmentModel_Constructor_ConnectionAndResourceRepository_InitializesConnectionAndResourceRepository()
        {
            var connection = CreateConnection();
            var repo       = new Mock <IResourceRepository>();
            var env        = new EnvironmentModel(Guid.NewGuid(), connection.Object, repo.Object, new Mock <IStudioResourceRepository>().Object);

            Assert.IsNotNull(env.Connection);
            Assert.IsNotNull(env.ResourceRepository);
            Assert.AreSame(connection.Object, env.Connection);
            Assert.AreSame(repo.Object, env.ResourceRepository);
        }
Example #27
0
    private void EndTransition(object value)
    {
        sprites = null; //reset just incase
        EnvironmentModel newSprites = value as EnvironmentModel;

        sprites = newSprites.backgroundTiles as Sprite[];
        transitionOut.GetComponent <SpriteRenderer>().sprite = newSprites.transitionOut;
        transitionIn.GetComponent <SpriteRenderer>().sprite  = newSprites.transitionIn;

        isTransitionIn = true;
    }
Example #28
0
        public void EnvironmentModel_AuthorizationService_Constructor_PropertyInitialized()
        {
            //------------Setup for test--------------------------
            var connection = CreateConnection();

            //------------Execute Test---------------------------
            var env = new EnvironmentModel(Guid.NewGuid(), connection.Object, new Mock <IResourceRepository>().Object, new Mock <IStudioResourceRepository>().Object);

            connection.Raise(environmentConnection => environmentConnection.NetworkStateChanged += null, new NetworkStateEventArgs(NetworkState.Offline, NetworkState.Online));
            //------------Assert Results-------------------------
            Assert.IsNotNull(env.AuthorizationService);
        }
        /// <inheritdoc />
        public async Task UpdateApplicationAuthorizationPolicyAsync(
            string org,
            string app,
            string shortCommitId,
            EnvironmentModel deploymentEnvironment)
        {
            GiteaFileContent policyFile = await GetAuthorizationPolicyFileFromGitea(org, app, shortCommitId);

            byte[] data = Convert.FromBase64String(policyFile.Content);
            string policyFileContent = Encoding.UTF8.GetString(data);
            await _authorizationPolicyClient.SavePolicy(org, app, policyFileContent, deploymentEnvironment);
        }
        /// <inheritdoc/>
        public async Task Update(string org, string app, TextResource textResource, EnvironmentModel environmentModel)
        {
            Uri uri = CreateGetAndPutUri(environmentModel, org, app, textResource.Language);

            HttpClientHelper.AddSubscriptionKeys(_httpClient, uri, _platformSettings);
            string             stringContent = JsonSerializer.Serialize(textResource);
            HttpRequestMessage request       = new HttpRequestMessage(HttpMethod.Put, uri)
            {
                Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
            };
            await _httpClient.SendAsync(request);
        }