Load() public static method

public static Load ( string path ) : ServiceSettings
path string
return ServiceSettings
        private void LoadComponents(CloudProjectPathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);

            try
            {
                Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);
            }
            catch (FileNotFoundException)
            {
                // Try recreating the settings file
                File.WriteAllText(paths.Settings, Resources.SettingsFileEmptyContent);
            }

            Definition  = General.DeserializeXmlFile <ServiceDefinition>(paths.Definition);
            CloudConfig = General.DeserializeXmlFile <ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = General.DeserializeXmlFile <ServiceConfiguration>(paths.LocalConfiguration);
            Settings    = ServiceSettings.Load(paths.Settings);
        }
示例#2
0
        /// <summary>
        /// Resolves the service runtimes into downloadable URLs.
        /// </summary>
        /// <param name="manifest">The custom manifest file</param>
        /// <returns>Warning text if any</returns>
        public string ResolveRuntimePackageUrls(string manifest = null)
        {
            ServiceSettings settings = ServiceSettings.Load(Paths.Settings);

            CloudRuntimeCollection availableRuntimePackages;

            if (!CloudRuntimeCollection.CreateCloudRuntimeCollection(out availableRuntimePackages, manifest))
            {
                throw new ArgumentException(
                          string.Format(Resources.ErrorRetrievingRuntimesForLocation,
                                        settings.Location));
            }

            ServiceDefinition             definition  = this.Components.Definition;
            StringBuilder                 warningText = new StringBuilder();
            List <CloudRuntimeApplicator> applicators = new List <CloudRuntimeApplicator>();

            if (definition.WebRole != null)
            {
                foreach (WebRole role in
                         definition.WebRole.Where(role => role.Startup != null &&
                                                  CloudRuntime.GetRuntimeStartupTask(role.Startup) != null))
                {
                    CloudRuntime.ClearRuntime(role);
                    string rolePath = Path.Combine(this.Paths.RootPath, role.name);
                    foreach (CloudRuntime runtime in CloudRuntime.CreateRuntime(role, rolePath))
                    {
                        CloudRuntimePackage package;
                        runtime.CloudServiceProject = this;
                        if (!availableRuntimePackages.TryFindMatch(runtime, out package))
                        {
                            string warning;
                            if (!runtime.ValidateMatch(package, out warning))
                            {
                                warningText.AppendFormat("{0}\r\n", warning);
                            }
                        }

                        applicators.Add(CloudRuntimeApplicator.CreateCloudRuntimeApplicator(
                                            runtime,
                                            package,
                                            role));
                    }
                }
            }

            if (definition.WorkerRole != null)
            {
                foreach (WorkerRole role in
                         definition.WorkerRole.Where(role => role.Startup != null &&
                                                     CloudRuntime.GetRuntimeStartupTask(role.Startup) != null))
                {
                    string rolePath = Path.Combine(this.Paths.RootPath, role.name);
                    CloudRuntime.ClearRuntime(role);
                    foreach (CloudRuntime runtime in CloudRuntime.CreateRuntime(role, rolePath))
                    {
                        CloudRuntimePackage package;
                        runtime.CloudServiceProject = this;
                        if (!availableRuntimePackages.TryFindMatch(runtime, out package))
                        {
                            string warning;
                            if (!runtime.ValidateMatch(package, out warning))
                            {
                                warningText.AppendFormat(warning + Environment.NewLine);
                            }
                        }
                        applicators.Add(CloudRuntimeApplicator.CreateCloudRuntimeApplicator(runtime,
                                                                                            package, role));
                    }
                }
            }

            applicators.ForEach <CloudRuntimeApplicator>(a => a.Apply());
            this.Components.Save(this.Paths);

            return(warningText.ToString());
        }