ApplyRuntime() public method

public ApplyRuntime ( CloudRuntimePackage package, WebRole webRole ) : void
package CloudRuntimePackage
webRole Microsoft.WindowsAzure.Commands.Utilities.Common.XmlSchema.ServiceDefinitionSchema.WebRole
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Add the specified runtime to a role, checking that the runtime and version are currently available int he cloud
        /// </summary>
        /// <param name="paths">service path info</param>
        /// <param name="roleName">Name of the role to change</param>
        /// <param name="runtimeType">The runtime identifier</param>
        /// <param name="runtimeVersion">The runtime version</param>
        /// <param name="manifest">Location fo the manifest file, default is the cloud manifest</param>
        public void AddRoleRuntime(
            CloudProjectPathInfo paths,
            string roleName,
            string runtimeType,
            string runtimeVersion,
            string manifest = null)
        {
            if (this.Components.RoleExists(roleName))
            {
                CloudRuntimeCollection collection;
                CloudRuntimeCollection.CreateCloudRuntimeCollection(out collection, manifest);
                CloudRuntime        desiredRuntime = CloudRuntime.CreateCloudRuntime(runtimeType, runtimeVersion, roleName, Path.Combine(paths.RootPath, roleName));
                CloudRuntimePackage foundPackage;
                if (collection.TryFindMatch(desiredRuntime, out foundPackage))
                {
                    WorkerRole worker = (this.Components.Definition.WorkerRole == null ? null :
                                         this.Components.Definition.WorkerRole.FirstOrDefault <WorkerRole>(r => string.Equals(r.name, roleName,
                                                                                                                              StringComparison.OrdinalIgnoreCase)));
                    WebRole web = (this.Components.Definition.WebRole == null ? null :
                                   this.Components.Definition.WebRole.FirstOrDefault <WebRole>(r => string.Equals(r.name, roleName,
                                                                                                                  StringComparison.OrdinalIgnoreCase)));
                    desiredRuntime.CloudServiceProject = this;
                    if (worker != null)
                    {
                        desiredRuntime.ApplyRuntime(foundPackage, worker);
                    }
                    else if (web != null)
                    {
                        desiredRuntime.ApplyRuntime(foundPackage, web);
                    }

                    this.Components.Save(this.Paths);
                }
            }
        }