예제 #1
0
        /// <summary>
        /// Loads the specified publish profile for the specified project.
        /// </summary>
        /// <param name="project">The Visual Studio EnvDTE project. Cannot be null.</param>
        /// <param name="path">Absolute path to the publish profile to load. If the file does not exist, defaults will be loaded for the object.</param>
        /// <returns>A new SelectedPublishProfile.</returns>
        /// <exception cref="System.ArgumentNullException">project</exception>
        public static PublishProfile Load(PushEnvironment pushEnvironment)
        {
            PublishProfile publishProfile = null;

            if (pushEnvironment == null)
            {
                throw new InvalidOperationException("Push environment cannot be null");
            }

            try
            {
                if (File.Exists(pushEnvironment.ProfileFilePath))
                {
                    // If the file exists, we load it
                    XmlSerializer serializer = new XmlSerializer(typeof(PublishProfile));

                    using (XmlReader xmlReader = XmlReader.Create(pushEnvironment.ProfileFilePath))
                    {
                        xmlReader.ReadToDescendant("PropertyGroup");
                        publishProfile = (PublishProfile)serializer.Deserialize(xmlReader.ReadSubtree());
                    }

                    if (string.IsNullOrWhiteSpace(publishProfile.Version))
                    {
                        throw new VisualStudioException("This publish profile is not compatible with the current version, please recreate it");
                    }
                }
                else
                {
                    // If the file does not exist, we set defaults
                    publishProfile = new PublishProfile()
                    {
                        Organization      = string.Empty,
                        Password          = null,
                        RefreshToken      = null,
                        SavedPassword     = true,
                        ServerUri         = null,
                        SkipSSLValidation = false,
                        Space             = string.Empty,
                        User             = string.Empty,
                        DeployTargetFile = null,
                        WebPublishMethod = "CloudFoundry"
                    };
                }

                publishProfile.path        = pushEnvironment.ProfileFilePath;
                publishProfile.environment = pushEnvironment;
                publishProfile.LoadManifest();
            }
            catch (VisualStudioException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new VisualStudioException("Error loading profile", ex);
            }

            return(publishProfile);
        }
예제 #2
0
        public PublishProfileEditorResources(PublishProfile publishProfile, CancellationToken cancellationToken)
        {
            this.selectedPublishProfile = publishProfile;
            this.selectedPublishProfile.PropertyChanged += this.PublishProfile_PropertyChanged;
            this.cancellationToken = cancellationToken;

            this.CloudTargets = CloudTargetManager.GetTargets();

            var publishProfiles = new List <PublishProfile>();

            var publishDirectory = Directory.GetParent(this.selectedPublishProfile.Path);

            if (Directory.Exists(publishDirectory.FullName))
            {
                foreach (var file in publishDirectory.GetFiles())
                {
                    if (file.Name.EndsWith(PushEnvironment.Extension, StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            var             selectedProject = VsUtils.GetSelectedProject();
                            PushEnvironment env             = new PushEnvironment(selectedProject);
                            env.ProfileFilePath = file.FullName;
                            var profile = PublishProfile.Load(env);
                            publishProfiles.Add(profile);
                        }
                        catch (Exception ex)
                        {
                            // Ignore profiles that cannot be loaded.
                            Logger.Warning(string.Format(CultureInfo.InvariantCulture, "Cloud not load profile from {0}: {1}", file.Name, ex));
                        }
                    }
                }
            }

            this.PublishProfiles = publishProfiles.ToArray();
        }