private string ConstructArgs(ServiceDefinition serviceDefinition, string rootPath, DevEnv type) { string arguments; string rolesArg = ""; string sitesArg = ""; if (serviceDefinition == null) throw new ArgumentNullException("serviceDefinition", string.Format(Resources.InvalidOrEmptyArgumentMessage, "Service definition")); if (string.IsNullOrEmpty(rootPath) || System.IO.File.Exists(rootPath)) throw new ArgumentException(Resources.InvalidRootNameMessage, "rootPath"); if (serviceDefinition.WebRole != null) { foreach (WebRole webRole in serviceDefinition.WebRole) { rolesArg += string.Format(Resources.RoleArgTemplate, webRole.name, rootPath); foreach (Site site in webRole.Sites.Site) { sitesArg += string.Format(Resources.SitesArgTemplate, webRole.name, site.name, rootPath); } } } if (serviceDefinition.WorkerRole != null) { foreach (WorkerRole workerRole in serviceDefinition.WorkerRole) { rolesArg += string.Format(Resources.RoleArgTemplate, workerRole.name, rootPath); } } arguments = string.Format((type == DevEnv.Local) ? Resources.CsPackLocalArg : Resources.CsPackCloudArg, rootPath, rolesArg, sitesArg); return arguments; }
public void CreatePackage(ServiceDefinition definition, string rootPath, DevEnv type, out string standardOutput, out string standardError) { string arguments; arguments = ConstructArgs(definition, rootPath, type); Execute(arguments, out standardOutput, out standardError); }
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; } }
/// <summary> /// Validates that given service definition is valid for a service. Validation steps: /// 1. Validates name element matches serviceName /// 2. Validates web role element has all webRoles with same configuration. /// 3. Validates worker role element has all workerRoles with same configuration. /// </summary> /// <param name="actual">Service definition to be checked</param> /// <param name="serviceName">New created service name</param> public static void IsValidServiceDefinition(ServiceDefinition actual, string serviceName, WebRoleInfo[] webRoles = null, WorkerRoleInfo[] workerRoles = null) { Assert.AreEqual<string>(serviceName, actual.name); if (webRoles != null) { Assert.AreEqual<int>(webRoles.Length, actual.WebRole.Length); int length = webRoles.Length; for (int i = 0; i < length; i++) { Assert.IsTrue(webRoles[i].Equals(actual.WebRole[i])); } } else { Assert.IsNull(actual.WebRole); } if (workerRoles != null) { Assert.AreEqual<int>(workerRoles.Length, actual.WorkerRole.Length); int length = workerRoles.Length; for (int i = 0; i < length; i++) { Assert.IsTrue(workerRoles[i].Equals(actual.WorkerRole[i])); } } else { Assert.IsNull(actual.WorkerRole); } }
internal virtual void AddRoleToDefinition(ServiceDefinition serviceDefinition, object template) { Validate.ValidateNullArgument(template, string.Format(Resources.NullRoleSettingsMessage, "service definition")); Validate.ValidateNullArgument(serviceDefinition, Resources.NullServiceDefinitionMessage); }
public void CreatePackage(ServiceDefinition definition, string rootPath, DevEnv type, out string standardOutput, out string standardError) { if (definition == null) { throw new ArgumentNullException( "definition", string.Format(Resources.InvalidOrEmptyArgumentMessage, "Service definition")); } if (string.IsNullOrEmpty(rootPath) || File.Exists(rootPath)) { throw new ArgumentException(Resources.InvalidRootNameMessage, "rootPath"); } // Track the directories that are created by GetOrCreateCleanPath // to avoid publishing iisnode log files so we can delete the temp // copies when we're finished packaging Dictionary<string, string> tempDirectories = new Dictionary<string, string>(); try { string roles = // Get the names of all web and worker roles Enumerable.Concat( definition.WebRole.NonNull().Select(role => role.name), definition.WorkerRole.NonNull().Select(role => role.name)) // Get the name and safe path for each role (i.e., if the // role has files that shouldn't be packaged, it'll be // copied to a temp location without those files) .Select(name => GetOrCreateCleanPath(rootPath, name, tempDirectories, type)) // Format the role name and path as a role argument .Select(nameAndPath => string.Format(Resources.RoleArgTemplate, nameAndPath.Key, nameAndPath.Value)) // Join all the role arguments together into one .DefaultIfEmpty(string.Empty) .Aggregate(string.Concat); string sites = // Get all of the web roles definition.WebRole.NonNull() // Get all the sites in each role and format them all as // site arguments .SelectMany(role => // Format each site as a site argument role.Sites.Site.Select(site => string.Format( Resources.SitesArgTemplate, role.name, site.name, tempDirectories.GetValueOrDefault(role.name, rootPath)))) // Join all the site arguments together into one .DefaultIfEmpty(string.Empty) .Aggregate(string.Concat); string args = string.Format( type == DevEnv.Local ? Resources.CsPackLocalArg : Resources.CsPackCloudArg, rootPath, roles, sites); // Run CsPack to generate the package ProcessHelper.StartAndWaitForProcess( new ProcessStartInfo( Path.Combine(AzureSdkBinDirectory, Resources.CsPackExe), args), out standardOutput, out standardError); } finally { // Cleanup any temp directories tempDirectories.Values.ForEach(dir => Directory.Delete(dir, true)); } }