static void WriteSecuritySettings(IWorkspace theWorkspace, Settings settings, ExecuteMessage result)
 {
     try
     {
         if(settings.Security != null)
         {
             var executionResult = ExecuteService(theWorkspace, new SecurityWrite(), "SecuritySettings", settings.Security);
             result.Message.AppendLine(executionResult);
         }
     }
     catch(Exception ex)
     {
         Dev2Logger.Log.Error("Error writing settings configuration.", ex);
         result.HasError = true;
         result.Message.AppendLine("Error writing settings configuration.");
     }
 }
예제 #2
0
        public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var settings = new Settings();
            try
            {
                var securityRead = CreateSecurityReadEndPoint();
                var loggingSettingsRead = CreateLoggingSettingsReadEndPoint();
                var jsonPermissions = securityRead.Execute(values, theWorkspace);
                var jsonLoggingSettings = loggingSettingsRead.Execute(values, theWorkspace);
                settings.Security = JsonConvert.DeserializeObject<SecuritySettingsTO>(jsonPermissions.ToString());
                settings.Logging = JsonConvert.DeserializeObject<LoggingSettingsTo>(jsonLoggingSettings.ToString());
            }
            catch(Exception ex)
            {
                Dev2Logger.Log.Error(ex);
                settings.HasError = true;
                settings.Error = "Error reading settings configuration : " + ex.Message;
                settings.Security = new SecuritySettingsTO(SecurityRead.DefaultPermissions);
            }

            var serializer = new Dev2JsonSerializer();
            return serializer.SerializeToBuilder(settings);
        }
        public void SettingsWrite_Execute_SettingsWriteValuePassedValidJSON_ShouldDoSecurityWrite()
        {
            //------------Setup for test--------------------------
            var permission = new WindowsGroupPermission { Administrator = true, IsServer = true, WindowsGroup = Environment.UserName };
            var windowsGroupPermissions = new List<WindowsGroupPermission> { permission };
            var settings = new Settings { Security = new SecuritySettingsTO(windowsGroupPermissions) };
            var serializeObject = JsonConvert.SerializeObject(settings);
            var settingsWrite = new SettingsWrite();
            //------------Execute Test---------------------------
            StringBuilder execute = settingsWrite.Execute(new Dictionary<string, StringBuilder> { { "Settings", new StringBuilder(serializeObject) } }, null);
            //------------Assert Results-------------------------
            Assert.IsTrue(File.Exists("secure.config"));
            File.Delete("secure.config");

            var msg = ToMsg(execute);

            StringAssert.Contains(msg.Message.ToString(), "Success");
        }