Пример #1
0
        private void UpdatePackageSource(PackageSource source)
        {
            if (WhatIf)
            {
                var p = new PSObject(source);

                if (!string.IsNullOrWhiteSpace(NewName))
                {
                    p.Properties.Remove("Name");
                    p.Properties.Add(new PSNoteProperty("Name", NewName));
                }

                if (!string.IsNullOrWhiteSpace(NewLocation))
                {
                    p.Properties.Remove("Location");
                    p.Properties.Add(new PSNoteProperty("Location", NewLocation));
                }

                if (Trusted.IsPresent)
                {
                    p.Properties.Remove("Trusted");
                    p.Properties.Add(new PSNoteProperty("Trusted", Trusted.ToBool()));
                }

                WriteObject(p);
                return;
            }
            if (string.IsNullOrWhiteSpace(NewName))
            {
                // this is a replacement of an existing package source, we're *not* changing the name. (easy)

                foreach (var src in source.Provider.AddPackageSource(string.IsNullOrWhiteSpace(NewName) ? source.Name : NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted, UpdatePackageSourceRequest))
                {
                    WriteObject(src);
                }
            }
            else
            {
                // we're renaming a source.
                // a bit more messy at this point
                // create a new package source first

                bool removed = false;

                foreach (var src in source.Provider.AddPackageSource(NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted.IsPresent ? Trusted.ToBool() : source.IsTrusted, this))
                {
                    WriteObject(src);
                    if (!removed)
                    {
                        // if we are able to successfully add a source, then we remove the original source that was supposed to be replace.
                        // This will only happen once (as there is only one original source)
                        source.Provider.RemovePackageSource(source.Name, this);
                        removed = true;
                    }
                }
            }
        }
Пример #2
0
        private void UpdatePackageSource(PackageSource source)
        {
            if (string.IsNullOrEmpty(NewName))
            {
                // this is a replacement of an existing package source, we're *not* changing the name. (easy)

                foreach (var src in source.Provider.AddPackageSource(string.IsNullOrEmpty(NewName) ? source.Name : NewName, string.IsNullOrEmpty(NewLocation) ? source.Location : NewLocation, Trusted, WithUpdatePackageSource))
                {
                    WriteObject(src);
                }
            }
            else
            {
                // we're renaming a source.
                // a bit more messy at this point
                // create a new package source first

                foreach (var src in source.Provider.AddPackageSource(NewName, string.IsNullOrEmpty(NewLocation) ? source.Location : NewLocation, Trusted.IsPresent ? Trusted.ToBool() : source.IsTrusted, this))
                {
                    WriteObject(src);
                }

                // remove the old one.
                source.Provider.RemovePackageSource(source.Name, this).Wait();
            }
        }
Пример #3
0
        private void UpdatePackageSource(PackageSource source)
        {
            if (WhatIf)
            {
                var p = new PSObject(source);

                if (!string.IsNullOrWhiteSpace(NewName))
                {
                    p.Properties.Remove("Name");
                    p.Properties.Add(new PSNoteProperty("Name", NewName));
                }

                if (!string.IsNullOrWhiteSpace(NewLocation))
                {
                    p.Properties.Remove("Location");
                    p.Properties.Add(new PSNoteProperty("Location", NewLocation));
                }

                if (Trusted.IsPresent)
                {
                    p.Properties.Remove("Trusted");
                    p.Properties.Add(new PSNoteProperty("Trusted", Trusted.ToBool()));
                }

                WriteObject(p);
                return;
            }
            if (string.IsNullOrWhiteSpace(NewName))
            {
                // this is a replacement of an existing package source, we're *not* changing the name. (easy)

                foreach (var src in source.Provider.AddPackageSource(string.IsNullOrWhiteSpace(NewName) ? source.Name : NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted, UpdatePackageSourceRequest))
                {
                    WriteObject(src);
                }
            }
            else
            {
                // we're renaming a source.
                // a bit more messy at this point
                // create a new package source first

                foreach (var src in source.Provider.AddPackageSource(NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted.IsPresent ? Trusted.ToBool() : source.IsTrusted, this))
                {
                    WriteObject(src);
                }

                // remove the old one.
                source.Provider.RemovePackageSource(source.Name, this).Wait();
            }
        }
Пример #4
0
        public void SetRememberOpenIDLogin(string domain, bool remember)
        {
            domain = domain.ToLowerInvariant();
            this.persistedUserData.Write(userData =>
            {
                Trusted trusted;
                if (!userData.trusted.TryGetValue(domain, out trusted))
                    userData.trusted[domain] = trusted = new Trusted();

                trusted.login = remember;
            });
        }