public void TestEquals()
        {
            var reference1 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586),
                Languages = {"en-US"}
            };
            var reference2 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586),
                Languages = {"en-US"}
            };
            reference2.Should().Be(reference1);

            reference2 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586),
                Languages = {"de-DE"}
            };
            reference2.Should().NotBe(reference1);

            reference2 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Languages = {"en-US"}
            };
            reference2.Should().NotBe(reference1);
        }
        public void TestEquals()
        {
            var reference1 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586),
                Languages = {"en-US"}
            };
            var reference2 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586),
                Languages = {"en-US"}
            };
            Assert.AreEqual(reference1, reference2);

            reference2 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586),
                Languages = {"de-DE"}
            };
            Assert.AreNotEqual(reference1, reference2);

            reference2 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Languages = {"en-US"}
            };
            Assert.AreNotEqual(reference1, reference2);
        }
Beispiel #3
0
    public void Equality()
    {
        var reference1 = new FeedReference
        {
            Source       = FeedTest.Test1Uri,
            Architecture = new(OS.Windows, Cpu.I586),
            Languages    = { "en-US" }
        };
        var reference2 = new FeedReference
        {
            Source       = FeedTest.Test1Uri,
            Architecture = new(OS.Windows, Cpu.I586),
            Languages    = { "en-US" }
        };

        reference2.Should().Be(reference1);

        reference2 = new FeedReference
        {
            Source       = FeedTest.Test1Uri,
            Architecture = new(OS.Windows, Cpu.I586),
            Languages    = { "de-DE" }
        };
        reference2.Should().NotBe(reference1);

        reference2 = new FeedReference
        {
            Source    = FeedTest.Test1Uri,
            Languages = { "en-US" }
        };
        reference2.Should().NotBe(reference1);
    }
Beispiel #4
0
        /// <summary>
        /// Removes a <see cref="FeedReference"/> from one or more <see cref="InterfacePreferences"/>.
        /// </summary>
        /// <returns>The interfaces that were actually affected.</returns>
        protected override ICollection <FeedUri> ApplyFeedToInterfaces(FeedUri feedUri, IEnumerable <FeedUri> interfaces)
        {
            #region Sanity checks
            if (feedUri == null)
            {
                throw new ArgumentNullException("feedUri");
            }
            if (interfaces == null)
            {
                throw new ArgumentNullException("interfaces");
            }
            #endregion

            var modified  = new List <FeedUri>();
            var reference = new FeedReference {
                Source = feedUri
            };
            foreach (var interfaceUri in interfaces)
            {
                var preferences = InterfacePreferences.LoadFor(interfaceUri);
                if (preferences.Feeds.Remove(reference))
                {
                    modified.Add(interfaceUri);
                }
                preferences.SaveFor(interfaceUri);
            }
            return(modified);
        }
Beispiel #5
0
        /// <inheritdoc/>
        protected override ExitCode ExecuteHelper(IEnumerable <FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy)
        {
            #region Sanity checks
            if (interfaces == null)
            {
                throw new ArgumentNullException(nameof(interfaces));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            #endregion

            var modifiedInterfaces = new List <FeedUri>();
            foreach (var interfaceUri in interfaces)
            {
                var preferences = InterfacePreferences.LoadFor(interfaceUri);
                if (preferences.Feeds.AddIfNew(source))
                {
                    modifiedInterfaces.Add(interfaceUri);
                }

                var effectiveStabilityPolicy = (preferences.StabilityPolicy == Stability.Unset)
                    ? (Config.HelpWithTesting ? Stability.Testing : Stability.Stable)
                    : preferences.StabilityPolicy;
                if (effectiveStabilityPolicy < suggestedStabilityPolicy)
                {
                    string stabilityMessage = string.Format(Resources.StabilityPolicySingleImplementation, suggestedStabilityPolicy);
                    if (Handler.Ask(
                            stabilityMessage + Environment.NewLine + string.Format(Resources.StabilityPolicyAutoSet, interfaceUri.ToStringRfc()),
                            defaultAnswer: false, alternateMessage: stabilityMessage))
                    {
                        preferences.StabilityPolicy = suggestedStabilityPolicy;
                    }
                }
                preferences.SaveFor(interfaceUri);
            }

            if (modifiedInterfaces.Count == 0)
            {
                Handler.OutputLow(Resources.FeedManagement, Resources.FeedAlreadyRegistered);
                return(ExitCode.NoChanges);
            }
            else
            {
                Handler.OutputLow(Resources.FeedManagement,
                                  Resources.FeedRegistered + Environment.NewLine +
                                  StringUtils.Join(Environment.NewLine, modifiedInterfaces.Select(x => x.ToStringRfc())));
                return(ExitCode.OK);
            }
        }
        public void TestClone()
        {
            var reference1 = new FeedReference
            {
                Source = FeedTest.Test1Uri,
                Architecture = new Architecture(OS.Windows, Cpu.I586), Languages = {"en-US"}
            };
            var reference2 = reference1.Clone();

            // Ensure data stayed the same
            reference2.Should().Be(reference1, because: "Cloned objects should be equal.");
            reference2.GetHashCode().Should().Be(reference1.GetHashCode(), because: "Cloned objects' hashes should be equal.");
            ReferenceEquals(reference1, reference2).Should().BeFalse(because: "Cloning should not return the same reference.");
        }
Beispiel #7
0
        public void Hook(Item[] items, Sitecore.Tasks.CommandItem command, Sitecore.Tasks.ScheduleItem schedule)
        {
            var feed = new FeedReference();

            if (!IsCorrectTime(feed))
            {
                return;
            }

            using (new DatabaseSwitcher(Sitecore.Configuration.Factory.GetDatabase("web")))
            {
                /// Bazaar Voice Export Command Item
                if (command.ID.ToString() == feed.Config.BvExportCommandId)
                {
                    new BaExport(command.ID);
                }
            }
        }
Beispiel #8
0
        /// <inheritdoc/>
        protected override ExitCode ExecuteHelper(IEnumerable <FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy)
        {
            #region Sanity checks
            if (interfaces == null)
            {
                throw new ArgumentNullException(nameof(interfaces));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            #endregion

            var modifiedInterfaces = new List <FeedUri>();
            foreach (var interfaceUri in interfaces)
            {
                var preferences = InterfacePreferences.LoadFor(interfaceUri);
                if (preferences.Feeds.Remove(source))
                {
                    modifiedInterfaces.Add(interfaceUri);
                    if (preferences.StabilityPolicy == suggestedStabilityPolicy && suggestedStabilityPolicy != Stability.Unset)
                    {
                        if (Handler.Ask(string.Format(Resources.StabilityPolicyReset, interfaceUri.ToStringRfc()), defaultAnswer: false))
                        {
                            preferences.StabilityPolicy = Stability.Unset;
                        }
                    }
                    preferences.SaveFor(interfaceUri);
                }
            }

            if (modifiedInterfaces.Count == 0)
            {
                Handler.OutputLow(Resources.FeedManagement, Resources.FeedNotRegistered);
                return(ExitCode.NoChanges);
            }
            else
            {
                Handler.OutputLow(Resources.FeedManagement,
                                  Resources.FeedUnregistered + Environment.NewLine +
                                  StringUtils.Join(Environment.NewLine, modifiedInterfaces.Select(x => x.ToStringRfc())));
                return(ExitCode.OK);
            }
        }
Beispiel #9
0
        /// <inheritdoc/>
        protected override ExitCode ExecuteHelper(IEnumerable<FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy)
        {
            #region Sanity checks
            if (interfaces == null) throw new ArgumentNullException(nameof(interfaces));
            if (source == null) throw new ArgumentNullException(nameof(source));
            #endregion

            var modifiedInterfaces = new List<FeedUri>();
            foreach (var interfaceUri in interfaces)
            {
                var preferences = InterfacePreferences.LoadFor(interfaceUri);
                if (preferences.Feeds.AddIfNew(source))
                    modifiedInterfaces.Add(interfaceUri);

                var effectiveStabilityPolicy = (preferences.StabilityPolicy == Stability.Unset)
                    ? (Config.HelpWithTesting ? Stability.Testing : Stability.Stable)
                    : preferences.StabilityPolicy;
                if (effectiveStabilityPolicy < suggestedStabilityPolicy)
                {
                    string stabilityMessage = string.Format(Resources.StabilityPolicySingleImplementation, suggestedStabilityPolicy);
                    if (Handler.Ask(
                        stabilityMessage + Environment.NewLine + string.Format(Resources.StabilityPolicyAutoSet, interfaceUri.ToStringRfc()),
                        defaultAnswer: false, alternateMessage: stabilityMessage))
                        preferences.StabilityPolicy = suggestedStabilityPolicy;
                }
                preferences.SaveFor(interfaceUri);
            }

            if (modifiedInterfaces.Count == 0)
            {
                Handler.OutputLow(Resources.FeedManagement, Resources.FeedAlreadyRegistered);
                return ExitCode.NoChanges;
            }
            else
            {
                Handler.OutputLow(Resources.FeedManagement,
                    Resources.FeedRegistered + Environment.NewLine +
                    StringUtils.Join(Environment.NewLine, modifiedInterfaces.Select(x => x.ToStringRfc())));
                return ExitCode.OK;
            }
        }
Beispiel #10
0
        /// <inheritdoc/>
        protected override ExitCode ExecuteHelper(IEnumerable<FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy)
        {
            #region Sanity checks
            if (interfaces == null) throw new ArgumentNullException(nameof(interfaces));
            if (source == null) throw new ArgumentNullException(nameof(source));
            #endregion

            var modifiedInterfaces = new List<FeedUri>();
            foreach (var interfaceUri in interfaces)
            {
                var preferences = InterfacePreferences.LoadFor(interfaceUri);
                if (preferences.Feeds.Remove(source))
                {
                    modifiedInterfaces.Add(interfaceUri);
                    if (preferences.StabilityPolicy == suggestedStabilityPolicy && suggestedStabilityPolicy != Stability.Unset)
                    {
                        if (Handler.Ask(string.Format(Resources.StabilityPolicyReset, interfaceUri.ToStringRfc()), defaultAnswer: false))
                            preferences.StabilityPolicy = Stability.Unset;
                    }
                    preferences.SaveFor(interfaceUri);
                }
            }

            if (modifiedInterfaces.Count == 0)
            {
                Handler.OutputLow(Resources.FeedManagement, Resources.FeedNotRegistered);
                return ExitCode.NoChanges;
            }
            else
            {
                Handler.OutputLow(Resources.FeedManagement,
                    Resources.FeedUnregistered + Environment.NewLine +
                    StringUtils.Join(Environment.NewLine, modifiedInterfaces.Select(x => x.ToStringRfc())));
                return ExitCode.OK;
            }
        }
 /// <summary>
 /// Removes a feed from the list of custom feeds.
 /// </summary>
 private void RemoveCustomFeed(FeedReference feed)
 {
     listBoxFeeds.Items.Remove(feed);
     _interfacePreferences.Feeds.Remove(feed);
 }
        /// <summary>
        /// Adds a feed to the list of custom feeds.
        /// </summary>
        private void AddCustomFeed(string input)
        {
            FeedUri feedUri;
            try
            {
                feedUri = new FeedUri(input);
            }
            catch (UriFormatException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }

            if (_interfaceUri.IsFile)
            {
                if (!File.Exists(_interfaceUri.LocalPath))
                {
                    Msg.Inform(this, string.Format(Resources.FileOrDirNotFound, _interfaceUri.LocalPath), MsgSeverity.Warn);
                    return;
                }
            }
            else
            {
                Feed feed = null;
                try
                {
                    using (var handler = new GuiTaskHandler(this))
                    {
                        handler.RunTask(new SimpleTask(Resources.CheckingFeed,
                            delegate
                            {
                                using (var webClient = new WebClientTimeout())
                                    feed = XmlStorage.FromXmlString<Feed>(webClient.DownloadString(feedUri));
                            }));
                    }
                }
                    #region Error handling
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (WebException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                #endregion

                // Ensure a matching <feed-for> is present for online feeds
                if (feed.FeedFor.All(entry => entry.Target != _interfaceUri))
                    if (!Msg.YesNo(this, Resources.IgnoreMissingFeedFor, MsgSeverity.Warn)) return;
            }

            var reference = new FeedReference {Source = feedUri};
            if (_interfacePreferences.Feeds.Contains(reference)) return;
            _interfacePreferences.Feeds.Add(reference);
            listBoxFeeds.Items.Add(reference);
        }
Beispiel #13
0
 public bool IsCorrectTime(FeedReference feed)
 {
     return DateTime.UtcNow >= DateTime.Parse(feed.Config.EarliestTimeToRun) && DateTime.UtcNow <= DateTime.Parse(feed.Config.LatestTimeToRun)
 }
Beispiel #14
0
 /// <summary>
 /// Removes a feed from the list of custom feeds.
 /// </summary>
 private void RemoveCustomFeed(FeedReference feed)
 {
     listBoxFeeds.Items.Remove(feed);
     _interfacePreferences.Feeds.Remove(feed);
 }
Beispiel #15
0
        /// <summary>
        /// Adds a feed to the list of custom feeds.
        /// </summary>
        private void AddCustomFeed(string input)
        {
            FeedUri feedUri;

            try
            {
                feedUri = new FeedUri(input);
            }
            catch (UriFormatException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }

            if (_interfaceUri.IsFile)
            {
                if (!File.Exists(_interfaceUri.LocalPath))
                {
                    Msg.Inform(this, string.Format(Resources.FileOrDirNotFound, _interfaceUri.LocalPath), MsgSeverity.Warn);
                    return;
                }
            }
            else
            {
                Feed feed = null;
                try
                {
                    using (var handler = new DialogTaskHandler(this))
                    {
                        handler.RunTask(new SimpleTask(Resources.CheckingFeed,
                                                       delegate
                        {
                            using (var webClient = new WebClientTimeout())
                                feed = XmlStorage.FromXmlString <Feed>(webClient.DownloadString(feedUri));
                        }));
                    }
                }
                #region Error handling
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (WebException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                #endregion

                // Ensure a matching <feed-for> is present for online feeds
                if (feed.FeedFor.All(entry => entry.Target != _interfaceUri))
                {
                    if (!Msg.YesNo(this, Resources.IgnoreMissingFeedFor, MsgSeverity.Warn))
                    {
                        return;
                    }
                }
            }

            var reference = new FeedReference {
                Source = feedUri
            };
            if (_interfacePreferences.Feeds.Contains(reference))
            {
                return;
            }
            _interfacePreferences.Feeds.Add(reference);
            listBoxFeeds.Items.Add(reference);
        }
 /// <summary>
 /// Registers or unregisters an additional feed source for a set of interfaces.
 /// </summary>
 /// <param name="interfaces">The set of interface URIs to register the feed <paramref name="source"/> for.</param>
 /// <param name="source">The feed reference to register for the <paramref name="interfaces"/>.</param>
 /// <param name="suggestedStabilityPolicy">The suggested value for <see cref="InterfacePreferences.StabilityPolicy"/>. Will be <see cref="Stability.Unset"/> unless there is exactly one <see cref="Implementation"/> in the <see cref="Feed"/>.</param>
 /// <returns></returns>
 protected abstract ExitCode ExecuteHelper(IEnumerable <FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy);
 /// <summary>
 /// Registers or unregisters an additional feed source for a set of interfaces.
 /// </summary>
 /// <param name="interfaces">The set of interface URIs to register the feed <paramref name="source"/> for.</param>
 /// <param name="source">The feed reference to register for the <paramref name="interfaces"/>.</param>
 /// <param name="suggestedStabilityPolicy">The suggested value for <see cref="InterfacePreferences.StabilityPolicy"/>. Will be <see cref="Stability.Unset"/> unless there is exactly one <see cref="Implementation"/> in the <see cref="Feed"/>.</param>
 /// <returns></returns>
 protected abstract ExitCode ExecuteHelper(IEnumerable<FeedUri> interfaces, FeedReference source, Stability suggestedStabilityPolicy);