Beispiel #1
0
        public Worker(string name,
                      ICoordinator coordinator,
                      WorkerRole role,
                      int maxConcurrentItems,
                      Action<TcpTypedConnection<byte[]>, TcpPackage> onPackageArrived,
                      Func<Guid, VerificationEvent, TcpPackage> packager)
        {
            Ensure.NotNullOrEmpty(name, "name");
            Ensure.NotNull(coordinator, "coordinator");
            Ensure.NotNull(onPackageArrived, "onPackageArrived");
            Ensure.NotNull(packager, "packager");

            _name = name;
            _coordinator = coordinator;
            _role = role;
            _maxConcurrentItems = maxConcurrentItems;
            _onPackageArrived = onPackageArrived;
            _packager = packager;

            _thread = new Thread(MainLoop)
            {
                IsBackground = true,
                Name = string.Format("Worker - {0}", name)
            };
        }
        public static void SetRole(GameEntity company, int humanId, WorkerRole workerRole, GameContext gameContext)
        {
            var managers = company.team.Managers;

            managers[humanId] = workerRole;

            company.ReplaceTeam(company.team.Morale, company.team.Organisation, managers, company.team.Workers, company.team.Teams, company.team.Salaries);

            Humans.SetRole(gameContext, humanId, workerRole);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var worker = new WorkerRole();

            worker.OnStart();

            worker.Run();

            worker.OnStop();
        }
Beispiel #4
0
        // actions
        public static GameEntity SetSkill(GameEntity worker, WorkerRole workerRole, int level)
        {
            var roles = worker.humanSkills.Roles;

            roles[workerRole] = level;

            worker.ReplaceHumanSkills(roles, worker.humanSkills.Traits, worker.humanSkills.Expertise);

            return(worker);
        }
Beispiel #5
0
    public void SetEntity(GameEntity company, WorkerRole role, Transform Center)
    {
        CEOTransform = Center;
        //LookAtCenter();

        var c = GetComponent <TeamsAttachedToManagerView>();

        c.TeamType = GetTeamTypeByManagerRole(role);
        c.ViewRender();
    }
Beispiel #6
0
        public static void ClearRuntime(WorkerRole role)
        {
            Task startupTask = GetRuntimeStartupTask(role.Startup);

            if (startupTask != null)
            {
                ClearEnvironmentValue(startupTask.Environment, Resources.RuntimeUrlKey);
                ClearEnvironmentValue(startupTask.Environment, Resources.CacheRuntimeUrl);
            }
        }
        public static void AddWorkerRoleToDef(string path, Dictionary <string, object> parameters)
        {
            RoleInfo                  role       = parameters["Role"] as RoleInfo;
            ServiceComponents         components = parameters["Components"] as ServiceComponents;
            PowerShellProjectPathInfo paths      = parameters["Paths"] as PowerShellProjectPathInfo;
            WorkerRole                workerRole = XmlUtilities.DeserializeXmlFile <ServiceDefinition>(path).WorkerRole[0];

            role.AddRoleToDefinition(components.Definition, workerRole);
            components.Save(paths);
        }
        public static void FireRegularWorker(GameEntity company, WorkerRole workerRole = WorkerRole.Programmer)
        {
            if (company.team.Workers[workerRole] > 0)
            {
                company.team.Workers[workerRole]--;

                ReduceOrganisationPoints(company, (int)(100 * GetTeamChangeImpact(company)));
                ChangeMorale(company, (int)(-60 * GetTeamChangeImpact(company)));
            }
        }
Beispiel #9
0
    TeamType GetTeamTypeByManagerRole(WorkerRole role)
    {
        switch (role)
        {
        case WorkerRole.MarketingLead: return(TeamType.MarketingTeam);

        case WorkerRole.TeamLead: return(TeamType.DevelopmentTeam);

        default: return(TeamType.CrossfunctionalTeam);
        }
    }
        /// <summary>
        /// Create a cloud runtime application, essentialy this is a tuple of runtime X package X role
        /// </summary>
        /// <param name="cloudRuntime">The runtime in the tuple</param>
        /// <param name="cloudRuntimePackage">The package in the tuple</param>
        /// <param name="role">The role to apply the package to</param>
        /// <returns>The tuple, use the apply method to apply the runtime as specified</returns>
        public static CloudRuntimeApplicator CreateCloudRuntimeApplicator(CloudRuntime cloudRuntime, CloudRuntimePackage cloudRuntimePackage, WorkerRole role)
        {
            CloudRuntimeApplicator applicator = new CloudRuntimeApplicator
            {
                Runtime = cloudRuntime,
                Package = cloudRuntimePackage,
                WorkerRole = role
            };

            return applicator;
        }
Beispiel #11
0
        private static Dictionary <string, string> GetStartupEnvironment(WorkerRole workerRole)
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            foreach (Variable variable in workerRole.Startup.Task[0].Environment)
            {
                settings[variable.name] = variable.value;
            }

            return(settings);
        }
Beispiel #12
0
        public virtual void ApplyRuntime(CloudRuntimePackage package, WorkerRole workerRole)
        {
            Dictionary <string, string> changes;

            if (this.GetChanges(package, out changes))
            {
                ApplyRoleXmlChanges(changes, workerRole);
            }

            ApplyScaffoldingChanges(package);
        }
Beispiel #13
0
        /// <summary>
        /// Main entry for enabling memcache.
        /// </summary>
        /// <param name="roleName">The web role name</param>
        /// <param name="cacheWorkerRoleName">The cache worker role name</param>
        /// <param name="rootPath">The service root path</param>
        /// <param name="message">The resulted message</param>
        /// <param name="azureService">The azure service instance</param>
        /// <param name="webRole">The web role to enable caching one</param>
        private void EnableMemcache(string roleName, string cacheWorkerRoleName, ref string message, ref AzureService azureService)
        {
            // Add MemcacheShim runtime installation.
            azureService.AddRoleRuntime(azureService.Paths, roleName, Resources.CacheRuntimeValue, CacheRuntimeVersion);

            // Fetch web role information.
            Startup startup = azureService.Components.GetRoleStartup(roleName);

            // Assert that cache runtime is added to the runtime startup.
            Debug.Assert(Array.Exists <Variable>(CloudRuntime.GetRuntimeStartupTask(startup).Environment,
                                                 v => v.name.Equals(Resources.RuntimeTypeKey) && v.value.Contains(Resources.CacheRuntimeValue)));

            if (azureService.Components.IsWebRole(roleName))
            {
                WebRole webRole = azureService.Components.GetWebRole(roleName);
                webRole.LocalResources = General.InitializeIfNull <LocalResources>(webRole.LocalResources);
                DefinitionConfigurationSetting[] configurationSettings = webRole.ConfigurationSettings;

                CachingConfigurationFactoryMethod(
                    azureService,
                    roleName,
                    true,
                    cacheWorkerRoleName,
                    webRole.Startup,
                    webRole.Endpoints,
                    webRole.LocalResources,
                    ref configurationSettings,
                    CacheRuntimeVersion);
                webRole.ConfigurationSettings = configurationSettings;
            }
            else
            {
                WorkerRole workerRole = azureService.Components.GetWorkerRole(roleName);
                workerRole.LocalResources = General.InitializeIfNull <LocalResources>(workerRole.LocalResources);
                DefinitionConfigurationSetting[] configurationSettings = workerRole.ConfigurationSettings;

                CachingConfigurationFactoryMethod(
                    azureService,
                    roleName,
                    false,
                    cacheWorkerRoleName,
                    workerRole.Startup,
                    workerRole.Endpoints,
                    workerRole.LocalResources,
                    ref configurationSettings,
                    CacheRuntimeVersion);
                workerRole.ConfigurationSettings = configurationSettings;
            }

            // Save changes
            azureService.Components.Save(azureService.Paths);

            message = string.Format(Resources.EnableMemcacheMessage, roleName, cacheWorkerRoleName, Resources.MemcacheEndpointPort);
        }
Beispiel #14
0
    static int GetWorkerOrder(WorkerRole role)
    {
        if (role == WorkerRole.CEO)
        {
            return(15);
        }

        if (role == WorkerRole.Universal)
        {
            return(11);
        }

        if (role == WorkerRole.TechDirector)
        {
            return(9);
        }

        if (role == WorkerRole.MarketingDirector)
        {
            return(8);
        }

        if (role == WorkerRole.TeamLead)
        {
            return(7);
        }

        if (role == WorkerRole.MarketingLead)
        {
            return(6);
        }

        if (role == WorkerRole.ProjectManager)
        {
            return(5);
        }

        if (role == WorkerRole.ProductManager)
        {
            return(4);
        }

        if (role == WorkerRole.Marketer)
        {
            return(3);
        }

        if (role == WorkerRole.Programmer)
        {
            return(2);
        }

        return(0);
    }
Beispiel #15
0
        public static bool IsNeedsToHireRole(WorkerRole role, TeamInfo teamInfo)
        {
            var roles = GetRolesForTeam(teamInfo);

            if (!roles.Contains(role))
            {
                return(false);
            }

            return(!HasRole(role, teamInfo));
        }
Beispiel #16
0
        public static int GetWorkerOrder(WorkerRole role)
        {
            if (role == WorkerRole.CEO)
            {
                return(150);
            }

            if (role == WorkerRole.Universal)
            {
                return(110);
            }

            if (role == WorkerRole.TechDirector)
            {
                return(90);
            }

            if (role == WorkerRole.MarketingDirector)
            {
                return(80);
            }

            if (role == WorkerRole.TeamLead)
            {
                return(70);
            }

            if (role == WorkerRole.MarketingLead)
            {
                return(60);
            }

            if (role == WorkerRole.ProjectManager)
            {
                return(50);
            }

            if (role == WorkerRole.ProductManager)
            {
                return(40);
            }

            if (role == WorkerRole.Marketer)
            {
                return(30);
            }

            if (role == WorkerRole.Programmer)
            {
                return(20);
            }

            return(0);
        }
Beispiel #17
0
        // TODO duplicates? This seems more effective
        public static GameEntity GetWorkerByRole(WorkerRole role, TeamInfo teamInfo, GameContext gameContext)
        {
            foreach (var pair in teamInfo.Roles)
            {
                if (pair.Value == role)
                {
                    return(Humans.Get(gameContext, pair.Key));
                }
            }

            return(null);
        }
        private void assignmentMenu_OnAddRequestSent(Object sender, WorkerRole role)
        {
            if (role == WorkerRole.Builder)
            {
                this.Enabled = false;
                this.Visible = false;
            }

            if (this.listOfRecallAddWorkersEvents.ContainsKey(role))
            {
                this.listOfRecallAddWorkersEvents[role].InvokeAddRequest();
            }
        }
        /// <summary>
        /// Gets role startup.
        /// </summary>
        /// <param name="roleName">The role name</param>
        /// <returns>The role startup</returns>
        public Startup GetRoleStartup(string roleName)
        {
            if (!RoleExists(roleName))
            {
                throw new ArgumentException(string.Format(Resources.RoleNotFoundMessage, roleName));
            }

            WebRole    webRole    = GetWebRole(roleName);
            WorkerRole workerRole = GetWorkerRole(roleName);
            Startup    startup    = webRole != null ? webRole.Startup : workerRole.Startup;

            return(startup);
        }
        public static int CreateNewWorker(WorkerRole role, String email, String password)
        {
            DataTable dataTableId = connector.ExecuteQuery("SELECT MAX(workerId)+1 FROM workers");

            int.TryParse(dataTableId.Rows[0]["MAX(workerId)+1"].ToString(), out int workerId);

            String command = "INSERT INTO workers(workerId,role,email,password) VALUES "
                             + "(" + workerId + ",'" + role + "','" + email + "','"
                             + password + "')";

            connector.ExecuteCommand(command);
            return(workerId);
        }
Beispiel #21
0
        // TODO duplicates?
        public static HumanFF GetWorkerInRole(TeamInfo team, WorkerRole workerRole, GameContext gameContext)
        {
            var managers = team.Managers
                           .Where(worker => worker.WorkerComponent.WorkerRole == workerRole)
                           .ToList();

            if (managers.Any())
            {
                return(managers.First());
            }

            return(null);
        }
        private WorkerRole Setup()
        {
            //Arrange
            // ShimRoleEnvironment.GetConfigurationSettingValueString = (key) =>
            // {
            //     if (key == "IDTOContext")
            //     {
            //         return realContextConnectionString;

            //     }
            //     if (key == "StorageConnectionString")
            //     {
            //         return realCloudStorageAccount;

            //     }
            //     if (key == "RunTConnectMonitor")
            //     {
            //         return "true";

            //     }
            //     if (key == "TConnectMonitorSleepTime")//sleep time in seconds
            //     {
            //         return "5";

            //     }
            //     if (key == "RunVehicleLocationMonitor")
            //     {
            //         return "false";

            //     }
            //     else
            //     {
            //         return "mockedSettingValue";
            //     }
            // };
            // //ShimCloudStorageAccount.FromConfigurationSettingString = (key2) =>
            // //{
            // //    return CloudStorageAccount.Parse(realCloudStorageAccount);
            // //};
            // ShimCloudConfigurationManager.GetSettingString = (key2) =>
            // {
            //     return  realCloudStorageAccount;
            //};
            // ShimCloudStorageAccount cloud = new ShimCloudStorageAccount(CloudStorageAccount.Parse(realCloudStorageAccount));
            WorkerRole workerRole = new WorkerRole();

            workerRole.SetUpBindingForDiagnostics();

            SetupProbeTable();
            return(workerRole);
        }
        public void ThenTheDataLockEventsWithMultipleErrorsAreStored()
        {
            ConfigureEventsApi();

            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken       = cancellationTokenSource.Token;

            Task.Run(() => WorkerRole.Run(), cancellationToken);

            var databaseAsExpected = TestHelper.ConditionMet(IsDatabaseInExpectedState, TimeSpan.FromSeconds(60));

            cancellationTokenSource.Cancel();
            Assert.IsTrue(databaseAsExpected);
        }
Beispiel #24
0
        public ActionResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest dsRequest)
        {
            if (!ViewBag.HasAccessToAdminModule)
            {
                WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
            }
            //create a new instance of role
            ViewBag.IsWorkerAdministrator = (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 ? false : true);
            WorkerRole role = new WorkerRole();

            //return view result
            return(View(role));
        }
Beispiel #25
0
        private IQueryable <WorkerRole> GetAllTest()
        {
            var        list = new List <WorkerRole>();
            WorkerRole a1   = new WorkerRole {
                Id = 1
            };
            WorkerRole a2 = new WorkerRole {
                Id = 2
            };

            list.Add(a1);
            list.Add(a2);
            return(list.AsQueryable());
        }
        public void ThenTheAccountDetailsIsRenamed()
        {
            ConfigureEventsApi();
            ConfigureAccountsApi();

            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = cancellationTokenSource.Token;
            Task.Run(() => WorkerRole.Run(), cancellationToken);

            var databaseAsExpected = TestHelper.ConditionMet(IsDatabaseInExpectedState, TimeSpan.FromSeconds(60));

            cancellationTokenSource.Cancel();
            Assert.IsTrue(databaseAsExpected);
        }
Beispiel #27
0
        public static void AttachToTeam(GameEntity company, GameEntity worker, WorkerRole role)
        {
            // add humanId to team
            var team = company.team;

            var humanId = worker.human.Id;

            team.Managers[humanId] = role;

            ReplaceTeam(company, team);

            // add companyId to human
            Humans.AttachToCompany(worker, company.company.Id, role);
        }
Beispiel #28
0
        public async Task <IActionResult> AddToRole(WorkerRole item)
        {
            var user = await UserManager.FindByIdAsync(item.UserId);

            var role = await RoleManager.FindByIdAsync(item.RoleId);

            if (user == null || role == null)
            {
                return(BadRequest("User or role not found"));
            }

            var res = await UserManager.AddToRoleAsync(user, role.Name);

            return(Ok(res.Succeeded));
        }
Beispiel #29
0
        public void Create2()
        {
            WorkerRole workerRole = new WorkerRole()
            {
                Id = 1
            };
            var mock = new Mock <IRepository <WorkerRole> >();

            mock.Setup(repo => repo.Create(workerRole));
            var factoryMock = new Mock <IRepositoryFactory>();

            factoryMock.Setup(f => f.GetRepository <WorkerRole>()).Returns(mock.Object);
            _workerRoleController = new WorkerRoleController(factoryMock.Object);
            //Assert.AreEqual(workerRole, factoryMock);
        }
Beispiel #30
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Role = await _context.Roles.FirstOrDefaultAsync(m => m.ID == id);

            if (Role == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Beispiel #31
0
        internal override void AddRoleToDefinition(ServiceDefinition def, object template)
        {
            base.AddRoleToDefinition(def, template);
            WorkerRole workerRole = template as WorkerRole;
            var        toAdd      = new WorkerRole[] { workerRole };

            if (def.WorkerRole != null)
            {
                def.WorkerRole = def.WorkerRole.Concat(toAdd).ToArray();
            }
            else
            {
                def.WorkerRole = toAdd;
            }
        }
        internal override void AddRoleToDefinition(ServiceDefinition def, object template)
        {
            base.AddRoleToDefinition(def, template);
            WorkerRole workerRole = template as WorkerRole;
            var toAdd = new WorkerRole[] { workerRole };

            if (def.WorkerRole != null)
            {
                def.WorkerRole = def.WorkerRole.Concat(toAdd).ToArray();
            }
            else
            {
                def.WorkerRole = toAdd;
            }
        }
Beispiel #33
0
        public void AddNewCacheWorkerRoleDoesNotHaveAnyRuntime()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                string rootPath = Path.Combine(files.RootPath, "AzureService");
                string roleName = "WorkerRole";
                int    expectedInstanceCount = 10;
                newServiceCmdlet.NewAzureServiceProcess(files.RootPath, "AzureService");

                WorkerRole cacheWorkerRole = addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(roleName, expectedInstanceCount, rootPath);

                Variable runtimeId = Array.Find <Variable>(cacheWorkerRole.Startup.Task[0].Environment, v => v.name.Equals(Resources.RuntimeTypeKey));
                Assert.AreEqual <string>(string.Empty, runtimeId.value);
            }
        }
Beispiel #34
0
        private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles)
        {
            string     forwarderName   = null;
            WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder"));

            if (workerForwarder != null)
            {
                // a worker role has the forwarder
                forwarderName = workerForwarder.name;
            }
            else
            {
                WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
                if (webForwarder != null)
                {
                    // a web role has the forwarder
                    forwarderName = webForwarder.name;
                }
                else
                {
                    // no role has the forwarder yet
                    WorkerRole firstWorkerRole = workerRoles.FirstOrDefault();
                    if (firstWorkerRole != null)
                    {
                        firstWorkerRole.Imports = General.Append(firstWorkerRole.Imports, new Import {
                            moduleName = "RemoteForwarder"
                        });
                        forwarderName = firstWorkerRole.name;
                    }
                    else // no worker role, use a web role
                    {
                        WebRole firstWebRole = webRoles.FirstOrDefault();
                        if (firstWebRole != null)
                        {
                            firstWebRole.Imports = General.Append(firstWebRole.Imports, new Import {
                                moduleName = "RemoteForwarder"
                            });
                            forwarderName = firstWebRole.name;
                        }
                        else
                        {
                            throw new InvalidOperationException(Resources.EnableAzureRemoteDesktop_Enable_NoRoles);
                        }
                    }
                }
            }
            return(forwarderName);
        }
        private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles)
        {
            string forwarderName = null;
            WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null &&
                r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
            if (workerForwarder != null)
            {
                // a worker role has the forwarder
                forwarderName = workerForwarder.name;
            }
            else
            {
                WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null &&
                    r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
                if (webForwarder != null)
                {
                    // a web role has the forwarder
                    forwarderName = webForwarder.name;
                }
            }

            return forwarderName;
        }
        /// <summary>
        /// Checks if the worker role is configured as caching worker role.
        /// </summary>
        /// <param name="workerRole">The worker role object</param>
        /// <returns>True if its caching worker role, false if not</returns>
        private bool IsCacheWorkerRole(WorkerRole workerRole)
        {
            if (workerRole.Imports != null)
            {
                return Array.Exists<Import>(workerRole.Imports, i => i.moduleName == Resources.CachingModuleName);
            }

            return false;
        }
 public ClientInputServiceHost()
 {
     WorkerRole rol = new WorkerRole();
     ClientInputRecieved += new ClientInputRecievedEventHandler(rol.ServiceHost_ClientInputRecieved);
 }
Beispiel #38
0
        public virtual void ApplyRuntime(CloudRuntimePackage package, WorkerRole workerRole)
        {
            Dictionary<string, string> changes;
            if (this.GetChanges(package, out changes))
            {
                ApplyRoleXmlChanges(changes, workerRole);
            }

            ApplyScaffoldingChanges(package);
        }
 private static void AddRemoteAccess(WebRole[] webRoles, WorkerRole[] workerRoles)
 {
     // Add RemoteAccess to all roles
     foreach (WebRole webRole in webRoles.Where(r => r.Imports == null || !r.Imports.Any(i => i.moduleName == "RemoteAccess")))
     {
         webRole.Imports = GeneralUtilities.Append(webRole.Imports, new Import { moduleName = "RemoteAccess" });
     }
     foreach (WorkerRole workerRole in workerRoles.Where(r => r.Imports == null || !r.Imports.Any(i => i.moduleName == "RemoteAccess")))
     {
         workerRole.Imports = GeneralUtilities.Append(workerRole.Imports, new Import { moduleName = "RemoteAccess" });
     }
 }
Beispiel #40
0
        private static Dictionary<string, string> GetStartupEnvironment(WorkerRole workerRole)
        {
            Dictionary<string, string> settings = new Dictionary<string, string>();
            foreach (Variable variable in GetRuntimeStartupTask(workerRole.Startup).Environment)
            {
                settings[variable.name] = variable.value;
            }

            return settings;
        }
Beispiel #41
0
 public static Collection<CloudRuntime> CreateRuntime(WorkerRole workerRole, string rolePath)
 {
     return GetRuntimes(GetStartupEnvironment(workerRole), workerRole.name, rolePath);
 }
 public static void VerifyWorkerRole(WorkerRole role, bool isForwarder)
 {
     Assert.AreEqual(isForwarder ? 1 : 0, role.Imports.Where(i => i.moduleName == "RemoteForwarder").Count());
     Assert.AreEqual(1, role.Imports.Where(i => i.moduleName == "RemoteAccess").Count());
 }
 public JobSubmissionServiceHost()
 {
     WorkerRole role = new WorkerRole();
     JobSubmissionRecieved += new JobSubmissionRecievedEventHandler(role.ServiceHost_JobSubmissionRecieved);
 }
Beispiel #44
0
 public static void WorkerRoleImportsExists(Import expected, WorkerRole actual)
 {
     Assert.IsTrue(Array.Exists<Import>(actual.Imports, i => i.moduleName.Equals(expected.moduleName)));
 }
Beispiel #45
0
 private static void Main(string[] args)
 {
     WorkerRole workerRole = new WorkerRole();
     workerRole.Run();
 }
 /// <summary>
 /// Try to get the specified worker role from the given definiiton
 /// </summary>
 /// <param name="definition">The service definiiton</param>
 /// <param name="roleName">The name of the role</param>
 /// <param name="role">output variable where the worker role is returned</param>
 /// <returns>true if the web role is found in the given definition</returns>
 private static bool TryGetWorkerRole(ServiceDefinition definition, string roleName, out WorkerRole role)
 {
     role = definition.WorkerRole.FirstOrDefault<WorkerRole>(r => string.Equals(r.name, roleName,
         StringComparison.OrdinalIgnoreCase));
     return role != null;
 }
 private static string GetForwarderName(WebRole[] webRoles, WorkerRole[] workerRoles)
 {
     string forwarderName = null;
     WorkerRole workerForwarder = workerRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
     if (workerForwarder != null)
     {
         // a worker role has the forwarder
         forwarderName = workerForwarder.name;
     }
     else
     {
         WebRole webForwarder = webRoles.FirstOrDefault(r => r.Imports != null && r.Imports.Any(i => i.moduleName == "RemoteForwarder"));
         if (webForwarder != null)
         {
             // a web role has the forwarder
             forwarderName = webForwarder.name;
         }
         else
         {
             // no role has the forwarder yet
             WorkerRole firstWorkerRole = workerRoles.FirstOrDefault();
             if (firstWorkerRole != null)
             {
                 firstWorkerRole.Imports = GeneralUtilities.Append(firstWorkerRole.Imports, new Import { moduleName = "RemoteForwarder" });
                 forwarderName = firstWorkerRole.name;
             }
             else // no worker role, use a web role
             {
                 WebRole firstWebRole = webRoles.FirstOrDefault();
                 if (firstWebRole != null)
                 {
                     firstWebRole.Imports = GeneralUtilities.Append(firstWebRole.Imports, new Import { moduleName = "RemoteForwarder" });
                     forwarderName = firstWebRole.name;
                 }
                 else
                 {
                     throw new InvalidOperationException(Resources.EnableAzureRemoteDesktop_Enable_NoRoles);
                 }
             }
         }
     }
     return forwarderName;
 }
Beispiel #48
0
 private static void ApplyRoleXmlChanges(Dictionary<string, string> changes, WorkerRole workerRole)
 {
     GetRuntimeStartupTask(workerRole.Startup).Environment = ApplySettingChanges(changes, GetRuntimeStartupTask(workerRole.Startup).Environment);
 }
 private static void RemoveOtherRemoteForwarders(WebRole[] webRoles, WorkerRole[] workerRoles, string forwarderName)
 {
     // Remove RemoteForwarder from all but the chosen role
     foreach (WebRole webRole in webRoles)
     {
         if (webRole.name != forwarderName &&
             webRole.Imports != null &&
             webRole.Imports.Any(i => i.moduleName == "RemoteForwarder"))
         {
             webRole.Imports = webRole.Imports.Where(i => i.moduleName != "RemoteForwarder").ToArray();
         }
     }
     foreach (WorkerRole workerRole in workerRoles)
     {
         if (workerRole.name != forwarderName &&
             workerRole.Imports != null &&
             workerRole.Imports.Any(i => i.moduleName == "RemoteForwarder"))
         {
             workerRole.Imports = workerRole.Imports.Where(i => i.moduleName != "RemoteForwarder").ToArray();
         }
     }
 }
 protected override void OnStart(string[] args)
 {
     var tasks = new ProviderCollection<WorkerRoleTask>(typeof(WorkerRole));
     workerRole_ = new WorkerRole(tasks);
     workerRole_.OnStart();
 }
Beispiel #51
0
 public static void ClearRuntime(WorkerRole role)
 {
      Task startupTask = GetRuntimeStartupTask(role.Startup);
      if (startupTask != null)
      {
          ClearEnvironmentValue(startupTask.Environment, Resources.RuntimeUrlKey);
          ClearEnvironmentValue(startupTask.Environment, Resources.CacheRuntimeUrl);
      }
 }