Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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.º 4
0
        public void CreatePackage(ServiceDefinition definition, 
            CloudProjectPathInfo paths, 
            DevEnv type,
            string azureSdkBinDirectory,
            out string standardOutput, 
            out string standardError)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(
                    "definition",
                    string.Format(Resources.InvalidOrEmptyArgumentMessage, "Service definition"));
            }
            if (string.IsNullOrEmpty(paths.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(paths.RolesPath, 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, paths.RolesPath))))
                    // 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,
                    paths.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));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get or create a path to the role.  This is used to sanitize the
        /// contents of a role before it's packaged if it contains files that
        /// shouldn't be packaged.  We copy the contents to a temp directory,
        /// delete the offending files, and use the temp directory for
        /// packaging.  The temp directories are collected in the
        /// tempDirectories list so they can be cleaned up when packaging is
        /// complete.
        /// </summary>
        /// <remarks>
        /// This is a temporary workaround to prevent node logging information
        /// from being packaged and deployed with production applications. 
        /// This method should be removed when we have a proper fix to bug
        /// https://github.com/WindowsAzure/azure-sdk-tools/issues/111
        /// </remarks>
        /// <param name="root">The root path.</param>
        /// <param name="name">Name of the role.</param>
        /// <param name="tempDirectories">
        /// A collection of temporary directories that have been created to
        /// remove files that should not be published.  This will be added to
        /// by GetOrCreateCleanPath if a new directory is created that should
        /// be cleaned up once the package has been generated.
        /// </param>
        /// <returns>
        /// A pair containing the path to the role and the name of the role.
        /// </returns>
        private static KeyValuePair<string, string> GetOrCreateCleanPath(string root, string name, Dictionary<string, string> tempDirectories, DevEnv type)
        {
            string path = Path.Combine(root, name);

            // Check if the role has any "*.logs" directories that iisnode may
            // have left during emulation
            if (type == DevEnv.Local || GetLogDirectories(path).Length == 0)
            {
                return new KeyValuePair<string, string>(name, root);
            }
            else
            {
                // Create a temporary directory
                string tempPath = FileUtilities.CreateTempDirectory();
                tempDirectories[name] = tempPath;
                
                // Copy the role's directory to the temp directory
                string newPath = Path.Combine(tempPath, name);
                FileUtilities.CopyDirectory(Path.Combine(root, name), newPath);

                // Remove the offending files
                GetLogDirectories(newPath)
                    .ForEach(dir => Directory.Delete(dir, true));

                return new KeyValuePair<string, string>(name, tempPath);
            }
        }
 public void CreatePackage(DevEnv type, out string standardOutput, out string standardError)
 {
     VerifyCloudServiceProjectComponents();
     CsPack packageTool = new CsPack();
     packageTool.CreatePackage(Components.Definition, Paths, type, AzureTool.GetAzureSdkBinDirectory(), out standardOutput, out standardError);
 }
Ejemplo n.º 7
0
 public void CreatePackage(DevEnv type, out string standardOutput, out string standardError)
 {
     var packageTool = new CsPack();
     packageTool.CreatePackage(Components.Definition, Paths.RootPath, type, out standardOutput, out standardError);
 }
 public void CreatePackage(DevEnv type)
 {
     string standardOutput, standardError;
     VerifyCloudServiceProjectComponents();
     CsPack packageTool = new CsPack();
     packageTool.CreatePackage(Components.Definition, Paths, type, AzureTool.GetAzureSdkBinDirectory(), out standardOutput, out standardError);
     if (!string.IsNullOrWhiteSpace(standardError))
     {
         //The error of invalid xpath expression about endpoint in the configuration file is expected. Hence, we do not throw.
         if (!standardError.Contains("/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port"))
         {
             throw new InvalidOperationException(string.Format(Properties.Resources.FailedToCreatePackage, standardError));
         }
     }
 }
Ejemplo n.º 9
0
 public void CreatePackage(DevEnv type, out string standardOutput, out string standardError)
 {
     VerifyCloudServiceProjectComponents();
     CsPack packageTool = new CsPack();
     packageTool.CreatePackage(Components.Definition, Paths.RootPath, type, out standardOutput, out standardError);
 }