Ejemplo n.º 1
0
        private void AddRole(RoleSettings roleToAdd, string cscfgFileLoc)
        {
            ServiceConfigurationSchema.ServiceConfiguration config = SerializationUtils.DeserializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(cscfgFileLoc);

            string roleNameToAdd = roleToAdd.name.ToUpperInvariant();

            if (config.Role != null)
            {
                //Check if role to be added is already present inside the cscfg. If so just update instance count.
                RoleSettings matchingRoleInConfig = config.Role.Where(eachRole => eachRole.name.ToUpperInvariant() == roleNameToAdd).FirstOrDefault();
                if (matchingRoleInConfig != null)
                {
                    ConfigureInstCount(matchingRoleInConfig);
                    SerializationUtils.SerializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(config, cscfgFileLoc);
                    WriteObject(string.Format(CultureInfo.InvariantCulture, Resources.RoleAlreadyPresentInCSCFG, roleNameToAdd, matchingRoleInConfig.Instances.count.ToString(CultureInfo.InvariantCulture)));
                    return;
                }
            }

            List <ServiceConfigurationSchema.RoleSettings> roles = new List <ServiceConfigurationSchema.RoleSettings>();

            //Retain existing roles inside the cscfg.
            if (config.Role != null)
            {
                roles.AddRange(config.Role);
            }
            roles.Add(roleToAdd);
            config.Role = roles.ToArray();
            SerializationUtils.SerializeXmlFile <ServiceConfigurationSchema.ServiceConfiguration>(config, cscfgFileLoc);
        }
        private static void AddCacheConfiguration(RoleSettings cacheRoleSettings, string connectionString = "")
        {
            List <ConfigConfigurationSetting> cachingConfigSettings = new List <ConfigConfigurationSetting>();

            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.NamedCacheSettingName,
                value = Resources.NamedCacheSettingValue
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.DiagnosticLevelName,
                value = Resources.DiagnosticLevelValue
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.CachingCacheSizePercentageSettingName,
                value = string.Empty
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.CachingConfigStoreConnectionStringSettingName,
                value = connectionString
            });

            cacheRoleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray <ConfigConfigurationSetting>(
                cacheRoleSettings.ConfigurationSettings,
                cachingConfigSettings);
        }
Ejemplo n.º 3
0
        public void Builder_01ThreadNextNode_Test()
        {
            PowerThreadDescription    description = new PowerThreadDescription();
            PowerThreadBuilderForTest builder     = new PowerThreadBuilderForTest(Guid.NewGuid(), "test thread", description);
            var thread = builder.Build();

            PrintThreadCurrentNode(thread);


            RoleSettings roleSettings             = new RoleSettings();
            Dictionary <string, string> varialbes = new Dictionary <string, string>();

            thread.StartWith(roleSettings, varialbes);

            PrintThreadCurrentNode(thread);


            thread.GoNextNode(thread.CurrentNode);
            PrintThreadCurrentNode(thread);


            thread.GoNextNode(thread.CurrentNode);
            PrintThreadCurrentNode(thread);

            thread.GoNextNode(thread.CurrentNode);
            PrintThreadCurrentNode(thread);

            thread.GoNextNode(thread.CurrentNode);
            PrintThreadCurrentNode(thread);
            //  thread.TerminateThreadAtNode(thread.CurrentNode);
        }
Ejemplo n.º 4
0
        private void OverrideSettings(RoleSettings roleToAdd)
        {
            if (string.IsNullOrEmpty(this.Settings) == true)
            {
                return;
            }
            if (roleToAdd.ConfigurationSettings == null)
            {
                WriteWarning(Resources.SettingsAbsentInCSCFG);
                return;
            }
            string[] separatedSetting = Settings.Split(SettingSplitter, StringSplitOptions.RemoveEmptyEntries);
            foreach (string eachSetting in separatedSetting)
            {
                string[] settingsPart = eachSetting.Split(SettingPartSplitter, StringSplitOptions.RemoveEmptyEntries);

                //Find setting in the role to add.
                ServiceConfigurationSchema.ConfigurationSetting settingToOverride =
                    roleToAdd.ConfigurationSettings.Where(e => e.name.ToLowerInvariant() == settingsPart[0].ToLowerInvariant()).FirstOrDefault();
                //OOPS not found.
                if (settingToOverride == null)
                {
                    WriteWarning(string.Format(CultureInfo.InvariantCulture, Resources.SettingsAbsentInCSCFG, settingsPart[0]));
                    continue;
                }
                //Update.
                settingToOverride.value = settingsPart[1];
            }
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            m_RoleID = _Request.Get <Guid>("roleid", Method.Get, Guid.Empty);

            if (m_RoleID == Guid.Empty)
            {
                m_Role   = AllSettings.Current.RoleSettings.GetManagerRoles()[0];
                m_RoleID = m_Role.RoleID;
            }
            else
            {
                m_Role = RoleSettings.GetRole(m_RoleID);
            }

            if (m_Role == null)
            {
                ShowError(new InvalidParamError("roleid"));
                return;
            }

            if (_Request.IsClick("savepermission"))
            {
                SavePermission();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks for equality between provided object and this object
        /// </summary>
        /// <param name="obj">This object can be type of RoleInfo, WebRoleInfo, WorkerRoleInfo, WebRole or WorkerRole</param>
        /// <returns>True if they are equals, false if not</returns>
        public override bool Equals(object obj)
        {
            Validate.ValidateNullArgument(obj, string.Empty);
            bool         equals;
            RoleInfo     roleInfo   = obj as RoleInfo;
            WebRole      webRole    = obj as WebRole;
            WorkerRole   workerRole = obj as WorkerRole;
            RoleSettings role       = obj as RoleSettings;

            if (roleInfo != null)
            {
                equals = this.InstanceCount.Equals(roleInfo.InstanceCount) &&
                         this.Name.Equals(roleInfo.Name);
            }
            else if (webRole != null)
            {
                equals = this.Name.Equals(webRole.name);
            }
            else if (workerRole != null)
            {
                equals = this.Name.Equals(workerRole.name);
            }
            else if (role != null)
            {
                equals = this.Name.Equals(role.name) &&
                         this.InstanceCount.Equals(role.Instances.count);
            }
            else
            {
                equals = false;
            }

            return(equals);
        }
 private static void AssertConfigExists(RoleSettings role, string connectionString = "")
 {
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting { name = Resources.NamedCacheSettingName, value = Resources.NamedCacheSettingValue }, role.ConfigurationSettings);
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting { name = Resources.DiagnosticLevelName, value = Resources.DiagnosticLevelValue }, role.ConfigurationSettings);
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting { name = Resources.CachingCacheSizePercentageSettingName, value = string.Empty }, role.ConfigurationSettings);
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = connectionString }, role.ConfigurationSettings);
 }
Ejemplo n.º 8
0
        public override bool BeforeSaveSettings(RoleSettings roleSettings)
        {
            if (My.IsOwner)
            {
                PermissionSettings settings = SettingManager.CloneSetttings <PermissionSettings>(AllSettings.Current.PermissionSettings);

                settings.ContentPermissionLimit.LimitType = _Request.Get <PermissionLimitType>("ContentPermissionLimit", Method.Post, PermissionLimitType.RoleLevelLowerMe);
                settings.UserPermissionLimit.LimitType    = _Request.Get <PermissionLimitType>("UserPermissionLimit", Method.Post, PermissionLimitType.RoleLevelLowerMe);

                if (settings.ContentPermissionLimit.LimitType == PermissionLimitType.ExcludeCustomRoles)
                {
                    string key = "content.{0}.{1}";
                    GetLimitRoleList(key, settings.ContentPermissionLimit);
                }

                if (settings.UserPermissionLimit.LimitType == PermissionLimitType.ExcludeCustomRoles)
                {
                    string key = "user.{0}.{1}";
                    GetLimitRoleList(key, settings.UserPermissionLimit);
                }

                SettingManager.SaveSettings(settings);
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Configure the worker role for caching by:
        /// * Add caching module to the role imports.
        /// * Enable caching Diagnostic store.
        /// * Remove input endpoints.
        /// * Add caching configuration settings.
        /// </summary>
        /// <param name="rootPath"></param>
        /// <param name="cacheRoleInfo"></param>
        /// <returns></returns>
        private AzureService Version180Configuration(string rootPath, RoleInfo cacheRoleInfo)
        {
            // Fetch cache role information from service definition and service configuration files.
            AzureService azureService      = new AzureService(rootPath, null);
            WorkerRole   cacheWorkerRole   = azureService.Components.GetWorkerRole(cacheRoleInfo.Name);
            RoleSettings cacheRoleSettings = azureService.Components.GetCloudConfigRole(cacheRoleInfo.Name);

            // Add caching module to the role imports
            cacheWorkerRole.Imports = General.ExtendArray <Import>(cacheWorkerRole.Imports, new Import {
                moduleName = Resources.CachingModuleName
            });

            // Enable caching Diagnostic store.
            LocalStore diagnosticStore = new LocalStore {
                name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false
            };

            cacheWorkerRole.LocalResources = General.InitializeIfNull <LocalResources>(cacheWorkerRole.LocalResources);
            cacheWorkerRole.LocalResources.LocalStorage = General.ExtendArray <LocalStore>(cacheWorkerRole.LocalResources.LocalStorage, diagnosticStore);

            // Remove input endpoints.
            cacheWorkerRole.Endpoints.InputEndpoint = null;

            // Add caching configuration settings
            AddCacheConfiguration(azureService.Components.GetCloudConfigRole(cacheRoleInfo.Name));
            AddCacheConfiguration(azureService.Components.GetLocalConfigRole(cacheRoleInfo.Name), Resources.EmulatorConnectionString);
            return(azureService);
        }
Ejemplo n.º 10
0
 private void ConfigureInstCount(RoleSettings roleToAdd)
 {
     if (roleToAdd.Instances == null)
     {
         roleToAdd.Instances = new TargetSetting();
     }
     roleToAdd.Instances.count = this.InstanceCount == 0 ? 1 : this.InstanceCount;
 }
Ejemplo n.º 11
0
        private static void AddClientDiagnosticLevelToConfig(RoleSettings roleSettings)
        {
            ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting {
                name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue
            };

            roleSettings.ConfigurationSettings = General.ExtendArray <ConfigConfigurationSetting>(roleSettings.ConfigurationSettings, clientDiagnosticLevel);
        }
Ejemplo n.º 12
0
        private void AssertCachingEnabled(
            FileSystemHelper files,
            string serviceName,
            string rootPath,
            string webRoleName,
            string expectedMessage)
        {
            WebRole      webRole      = Testing.GetWebRole(rootPath, webRoleName);
            RoleSettings roleSettings = Testing.GetCloudRole(rootPath, webRoleName);

            AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue);

            Assert.AreEqual <string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name);
            Assert.AreEqual <string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value);

            Assert.AreEqual <string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name);
            Assert.AreEqual <string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath);

            Assert.AreEqual <string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name);
            Assert.AreEqual <string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value);
            Assert.AreEqual(1, webRole.Startup.Task.Count(t => t.commandLine.Equals(Resources.CacheStartupCommand)));


            AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole));
            AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand);

            AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint,
                                               new InternalEndpoint {
                name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort
            });

            LocalStore localStore = new LocalStore
            {
                name = Resources.CacheDiagnosticStoreName,
                cleanOnRoleRecycle = false
            };

            AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources);

            DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting {
                name = Resources.CacheClientDiagnosticLevelAssemblyName
            };

            AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings);

            ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting {
                name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue
            };

            AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings);

            AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig));
            AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName));

            Assert.AreEqual <string>(expectedMessage, mockCommandRuntime.VerboseStream[0]);
            Assert.AreEqual <string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue <string>(Parameters.RoleName));
        }
Ejemplo n.º 13
0
        public static void AddRoleToConfig(string path, Dictionary <string, object> parameters)
        {
            RoleInfo                  role       = parameters["Role"] as RoleInfo;
            ServiceComponents         components = parameters["Components"] as ServiceComponents;
            PowerShellProjectPathInfo paths      = parameters["Paths"] as PowerShellProjectPathInfo;
            RoleSettings              settings   = General.DeserializeXmlFile <ServiceConfiguration>(path).Role[0];

            components.AddRoleToConfiguration(settings, DevEnv.Cloud);
            components.AddRoleToConfiguration(settings, DevEnv.Local);
            components.Save(paths);
        }
Ejemplo n.º 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            m_RoleID = _Request.Get <Guid>("roleID", Method.Get, Guid.Empty);

            if (m_RoleID == Guid.Empty)
            {
                ShowError(new InvalidParamError("roleID"));
                return;
            }

            m_Role = AllSettings.Current.RoleSettings.GetRole(m_RoleID);

            if (m_Role == null)
            {
                ShowError("指定的用户组并不存在");
                return;
            }

            //根据不同类型的用户组检查不同的权限
            if (m_Role.IsLevel && AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.Action.Setting_Roles_Level) == false)
            {
                ShowError("您没有管理等级组的权限");
            }

            else if (m_Role.IsNormal && AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.Action.Setting_Roles_Other) == false)
            {
                ShowError("您没有管理自定义组的权限");
            }

            else if (m_Role.IsManager && AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.ActionWithTarget.Setting_Roles_Manager, m_Role) == false)
            {
                ShowError("您没有管理这个管理员组的权限");
            }

            //if (false == AllSettings.Current.BackendManageUserPermissionSet.Can(My, BackendManageUserPermissionSet.Action.ManageUserGroup))
            //{
            //    ShowError(Lang.PermissionItem_ManageUserPermissionSet_ChangeGroup);
            //}

            if (_Request.IsClick("delete"))
            {
                RoleSettings setting = AllSettings.Current.RoleSettings;

                setting.RemoveRole(Role.RoleID);

                SettingManager.SaveSettings(setting);

                Return(_Request.Get <Guid>("roleid", Method.All, Guid.Empty), true);
            }
        }
Ejemplo n.º 15
0
        public void AddRoleToConfiguration(RoleSettings role, DevEnv env)
        {
            Validate.ValidateNullArgument(role, string.Format(Resources.NullRoleSettingsMessage, "ServiceConfiguration"));

            ServiceConfiguration config = (env == DevEnv.Cloud) ? CloudConfig : LocalConfig;

            if (config.Role == null)
            {
                config.Role = new RoleSettings[] { role };
            }
            else
            {
                config.Role = config.Role.Concat(new RoleSettings[] { role }).ToArray();
            }
        }
Ejemplo n.º 16
0
 private static void AssertConfigExists(RoleSettings role, string connectionString = "")
 {
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting {
         name = Resources.NamedCacheSettingName, value = Resources.NamedCacheSettingValue
     }, role.ConfigurationSettings);
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting {
         name = Resources.DiagnosticLevelName, value = Resources.DiagnosticLevelValue
     }, role.ConfigurationSettings);
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting {
         name = Resources.CachingCacheSizePercentageSettingName, value = string.Empty
     }, role.ConfigurationSettings);
     AzureAssert.ConfigurationSettingExist(new ConfigConfigurationSetting {
         name = Resources.CachingConfigStoreConnectionStringSettingName, value = connectionString
     }, role.ConfigurationSettings);
 }
Ejemplo n.º 17
0
 private static void UpdateSetting(ref RoleSettings rs, ServiceConfigurationSchema.ConfigurationSetting cs)
 {
     if (rs.ConfigurationSettings == null)
     {
         return;
     }
     for (int i = 0; i < rs.ConfigurationSettings.Length; i++)
     {
         ServiceConfigurationSchema.ConfigurationSetting setting = rs.ConfigurationSettings[i];
         if (setting.name == cs.name)
         {
             setting.value = cs.value;
             break;
         }
     }
 }
Ejemplo n.º 18
0
        public void Builder_05SinkAndEmerge_Test()
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting = Newtonsoft.Json.Formatting.Indented,

                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            };


            Guid ThreadObjectId = Guid.Parse("a44dacf8-ffc4-485d-9eb9-d9693304e276");

            PowerThreadDescription    description = new PowerThreadDescription();
            PowerThreadBuilderForTest builder     =
                new PowerThreadBuilderForTest(ThreadObjectId, "test thread", description);
            var thread = builder.Build();


            PrintThreadCurrentNode(thread);



            RoleSettings roleSettings             = new RoleSettings();
            Dictionary <string, string> varialbes = new Dictionary <string, string>();

            thread.StartWith(roleSettings, varialbes);

            var t  = JsonConvert.SerializeObject(thread.CurrentNode.DefaultForm.BindingViewModel);
            var tt = JsonConvert.DeserializeObject <PowerThreadEntity>(t);

            var s = thread.Sink();



            var threadRevived = builder.BuildFromSink(thread.Id, s);

            PrintThreadCurrentNodePage(threadRevived);

            threadRevived.CurrentNode.DefaultForm.Go();
            PrintThreadCurrentNodePage(threadRevived);

            thread.CurrentNode.DefaultForm.Go();
            PrintThreadCurrentNodePage(thread);

            thread.CurrentNode.DefaultForm.Go();
            PrintThreadCurrentNodePage(thread);
        }
Ejemplo n.º 19
0
        public UserCollection GetRoleMembers(int operatorUserID, int roleID, int pageSize, int pageNumber, out int totalCount)
        {
            RoleSettings roleSetting = AllSettings.Current.RoleSettings;

            //if( ManagePermissionSet.Can(operatorUserID, ManageUserPermissionSet.ActionWithTarget.  )

            if (pageNumber <= 0)
            {
                pageNumber = 1;
            }
            if (pageSize <= 0)
            {
                pageSize = Consts.DefaultPageSize;
            }

            //        Role role = roleSetting.GetRole(roleID);
            Role role = RoleDao.Instance.GetRoleByID(roleID);

            totalCount = 0;
            if (role == null)
            {
                return(new UserCollection());
            }

            /*
             *  if (role.IsLevel)
             *  {
             *      int levelValue1, levelValue2 = int.MaxValue;
             *      levelValue1 = role.RequiredPoint;
             *      foreach (Role r in roleSetting.GetLevelRoles())
             *      {
             *          if (r.RequiredPoint > role.RequiredPoint)
             *          {
             *              levelValue2 = r.RequiredPoint;
             *              break;
             *          }
             *      }
             *
             *      return UserDao.Instance.GetRoleMembers(roleSetting.LevelLieOn
             *          , new Int32Scope(levelValue1, levelValue2)
             *          , pageSize, pageNumber, out totalCount);
             *  }
             *
             */
            return(RoleDao.Instance.GetRoleMembers(roleID, pageSize, pageNumber, out totalCount));
        }
Ejemplo n.º 20
0
        public void Builder_03RenderForm_Test()
        {
            PowerThreadDescription    description = new PowerThreadDescription();
            PowerThreadBuilderForTest builder     = new PowerThreadBuilderForTest(Guid.NewGuid(), "test thread", description);
            var thread = builder.Build();

            PrintThreadCurrentNode(thread);


            RoleSettings roleSettings             = new RoleSettings();
            Dictionary <string, string> varialbes = new Dictionary <string, string>();

            thread.StartWith(roleSettings, varialbes);
            PrintThreadCurrentNode(thread);

            var html = thread.CurrentNode.DefaultForm.RenderHtml();
            //  var html2 = thread.CurrentNode.RenderPage();
        }
Ejemplo n.º 21
0
        public void SetAzureVMSizeProcessTestsNode()
        {
            string newRoleVMSize = "Large";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                string roleName             = "WebRole1";
                service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath);
                service = new CloudServiceProject(service.Paths.RootPath, null);

                Assert.Equal <string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString());
                Assert.Equal <int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.Equal <string>(roleName, roleSettings.name);
            }
        }
Ejemplo n.º 22
0
        public void TestSetAzureRuntimeValidRuntimeVersions()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
                string roleName = "WebRole1";
                cmdlet.PassThru = false;

                RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(roleName, "node", "0.8.2", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files));
                RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(roleName, "iisnode", "0.1.21", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files));
                VerifyPackageJsonVersion(service.Paths.RootPath, roleName, "node", "0.8.2");
                VerifyPackageJsonVersion(service.Paths.RootPath, roleName, "iisnode", "0.1.21");
                Assert.AreEqual <int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.AreEqual <string>(roleName, roleSettings1.name);
                Assert.AreEqual <string>(roleName, roleSettings2.name);
            }
        }
Ejemplo n.º 23
0
 public void TestSetAzureRuntimeInvalidRuntimeVersion()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
         service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
         string       roleName      = "WebRole1";
         RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(roleName, "node", "0.8.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files));
         RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(roleName, "iisnode", "0.9.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files));
         VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "node", "*");
         VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "iisnode", "*");
         Assert.AreEqual <string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString());
         Assert.AreEqual <string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[1]).Members[Parameters.RoleName].Value.ToString());
         Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName));
         Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[1]).TypeNames.Contains(typeof(RoleSettings).FullName));
         Assert.AreEqual <string>(roleName, roleSettings1.name);
         Assert.AreEqual <string>(roleName, roleSettings2.name);
     }
 }
Ejemplo n.º 24
0
        public void SetAzureVMSizeProcessTestsCaseInsensitiveVMSizeSize()
        {
            string newRoleVMSize = "ExTraLaRge";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                AzureService service  = new AzureService(files.RootPath, serviceName, null);
                string       roleName = "WebRole1";
                service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath);
                service = new AzureService(service.Paths.RootPath, null);


                Assert.AreEqual <string>(newRoleVMSize.ToLower(), service.Components.Definition.WebRole[0].vmsize.ToString().ToLower());
                Assert.AreEqual <int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.AreEqual <string>(roleName, roleSettings.name);
            }
        }
Ejemplo n.º 25
0
        public void SetAzureVMSizeProcessTestsPHP()
        {
            string newRoleVMSize = "Medium";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                string roleName             = "WebRole1";
                service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath);
                RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath);
                service = new CloudServiceProject(service.Paths.RootPath, null);


                Assert.Equal <string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString());
                Assert.Equal <string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString());
                Assert.True(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName));
                Assert.Equal <string>(roleName, roleSettings.name);
            }
        }
        public void SetAzureInstancesProcessTestsNode()
        {
            int newRoleInstances = 10;

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                string roleName             = "WebRole1";
                service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath);
                service = new CloudServiceProject(service.Paths.RootPath, null);

                Assert.Equal <int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count);
                Assert.Equal <int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count);
                Assert.Equal <int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.Equal <int>(newRoleInstances, roleSettings.Instances.count);
                Assert.Equal <string>(roleName, roleSettings.name);
            }
        }
Ejemplo n.º 27
0
        public void SetAzureInstancesProcessTestsPHP()
        {
            int newRoleInstances = 10;

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                AzureService service  = new AzureService(files.RootPath, serviceName, null);
                string       roleName = "WebRole1";
                service.AddWebRole(Data.PHPWebRoleScaffoldingPath);
                RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath);
                service = new AzureService(service.Paths.RootPath, null);

                Assert.AreEqual <int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count);
                Assert.AreEqual <int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count);
                Assert.AreEqual <string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString());
                Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName));
                Assert.AreEqual <int>(newRoleInstances, roleSettings.Instances.count);
                Assert.AreEqual <string>(roleName, roleSettings.name);
            }
        }
Ejemplo n.º 28
0
 /// <summary>
 /// role1是否可以管理role2的用户
 /// </summary>
 /// <param name="role1"></param>
 /// <param name="role2"></param>
 /// <returns></returns>
 public bool CanManageUser(Guid role1, Guid role2)
 {
     return(RoleSettings.CanManageUser(role1, role2));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// role1是否可以管理role2的内容
 /// </summary>
 /// <param name="role1"></param>
 /// <param name="role2"></param>
 /// <returns></returns>
 public bool CanManageContent(Guid role1, Guid role2)
 {
     return(RoleSettings.CanManageContent(role1, role2));
 }
Ejemplo n.º 30
0
 public override bool BeforeSaveSettings(RoleSettings roleSettings)
 {
     roleSettings.LevelLieOn = _Request.Get <LevelLieOn>("levellieon", Method.Post, LevelLieOn.Point);
     return(true);
 }
Ejemplo n.º 31
0
        public bool SaveSettings()
        {
            MessageDisplay msdDisplay = CreateMessageDisplay("name", "title", "requiredPoint", "level");
            RoleCollection tempRoles  = new RoleCollection();

            RoleSettings settings = SettingManager.CloneSetttings <RoleSettings>(AllSettings.Current.RoleSettings);

            Role temp;

            Guid[] oldRoleids = _Request.GetList <Guid>("roleid", Method.Post, new Guid[00]);

            foreach (Guid r in oldRoleids)
            {
                temp = settings.GetRole(r);

                if (AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.ActionWithTarget.Setting_Roles_Manager, temp))
                {
                    temp = temp == null?CreateRole() : temp.Clone();   //不采用克隆的话可能会有些属性丢失掉

                    temp.Name            = _Request.Get("Name." + r, Method.Post);
                    temp.Title           = _Request.Get("title." + r, Method.Post);
                    temp.RequiredPoint   = _Request.Get <int>("RequiredPoint." + r, Method.Post, 0);
                    temp.Color           = _Request.Get("Color." + r, Method.Post);
                    temp.IconUrlSrc      = _Request.Get("IconUrl." + r, Method.Post);
                    temp.StarLevel       = _Request.Get <int>("StarLevel." + r, Method.Post, 0);
                    temp.Level           = _Request.Get <int>("Level." + r, Method.Post, 0);
                    temp.IsNew           = _Request.Get <bool>("isnew." + r, Method.Post, false);
                    temp.CanLoginConsole = _Request.Get <bool>("CanLoginConsole." + r, Method.Post, false) && temp.IsManager;
                    temp.RoleID          = r;
                    if (temp.IsLevel)
                    {
                        temp.Name = temp.Title;
                    }
                }
                else
                {
                    if (temp == null)
                    {
                        continue;
                    }
                }

                tempRoles.Add(temp);
            }

            //Nonsupport Javascript
            if (_Request.Get("newroleid", Method.Post, "").Contains("{0}"))
            {
                Role r = CreateRole();
                r.Name            = _Request.Get("name.new.{0}", Method.Post);
                r.Title           = _Request.Get("title.new.{0}", Method.Post);
                r.StarLevel       = _Request.Get <int>("starlevel.new.{0}", Method.Post, 0);
                r.RequiredPoint   = _Request.Get <int>("RequiredPoint.new.{0}", Method.Post, 0);
                r.Color           = _Request.Get("color.new.{0}", Method.Post);
                r.IconUrlSrc      = _Request.Get("IconUrl.new.{0}", Method.Post);
                r.Level           = _Request.Get <int>("Level.new.{0}", Method.Post, 0);
                r.CanLoginConsole = _Request.Get <bool>("CanLoginConsole.new.{0}", Method.Post, false) && r.IsManager;
                if (r.IsLevel)
                {
                    r.Name = r.Title;
                }
                if (!string.IsNullOrEmpty(r.Name))
                {
                    tempRoles.Add(r);
                }
            }
            else
            {
                int[] newroleid = _Request.GetList <int>("newroleid", Method.Post, new int[0]);

                foreach (int i in newroleid)
                {
                    Role r = CreateRole();
                    r.Name            = _Request.Get("name.new." + i, Method.Post);
                    r.Title           = _Request.Get("title.new." + i, Method.Post);
                    r.StarLevel       = _Request.Get <int>("starlevel.new." + i, Method.Post, 0);
                    r.RequiredPoint   = _Request.Get <int>("RequiredPoint.new." + i, Method.Post, 0);
                    r.Color           = _Request.Get("color.new." + i, Method.Post);
                    r.IconUrlSrc      = _Request.Get("IconUrl.new." + i, Method.Post);
                    r.Level           = _Request.Get <int>("Level.new." + i, Method.Post, 0);
                    r.CanLoginConsole = _Request.Get <bool>("CanLoginConsole.new." + i, Method.Post, false) && r.IsManager;
                    if (r.IsLevel)
                    {
                        r.Name = r.Title;
                    }
                    tempRoles.Add(r);
                }
            }

            if (ValidateRoleDate(tempRoles, msdDisplay))
            {
                foreach (Role r in tempRoles)
                {
                    settings.SetRole(r);
                }

                if (BeforeSaveSettings(settings))
                {
                    SettingManager.SaveSettings(settings);
                    m_RoleList = null;
                    return(true);
                }
            }

            m_RoleList = tempRoles;
            msdDisplay.AddError(new DataNoSaveError());
            return(false);
        }
Ejemplo n.º 32
0
        public void AddRoleToConfiguration(RoleSettings role, DevEnv env)
        {
            Validate.ValidateNullArgument(role, string.Format(Resources.NullRoleSettingsMessage, "ServiceConfiguration"));

            ServiceConfiguration config = (env == DevEnv.Cloud) ? CloudConfig : LocalConfig;

            if (config.Role == null)
            {
                config.Role = new RoleSettings[] { role };
            }
            else
            {
                config.Role = config.Role.Concat(new RoleSettings[] { role }).ToArray();
            }
        }
 private static void AddClientDiagnosticLevelToConfig(RoleSettings roleSettings)
 {
     ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue };
     roleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray<ConfigConfigurationSetting>(roleSettings.ConfigurationSettings, clientDiagnosticLevel);
 }
        private static void AddCacheConfiguration(RoleSettings cacheRoleSettings, string connectionString = "")
        {
            List<ConfigConfigurationSetting> cachingConfigSettings = new List<ConfigConfigurationSetting>();
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name = Resources.NamedCacheSettingName,
                value = Resources.NamedCacheSettingValue
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name = Resources.DiagnosticLevelName,
                value = Resources.DiagnosticLevelValue
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name = Resources.CachingCacheSizePercentageSettingName,
                value = string.Empty
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name = Resources.CachingConfigStoreConnectionStringSettingName,
                value = connectionString
            });

            cacheRoleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray<ConfigConfigurationSetting>(
                cacheRoleSettings.ConfigurationSettings,
                cachingConfigSettings);
        }