Example #1
0
        public void TwitchClient_OnMessageReceived(Object sender, OnMessageReceivedArgs e)
        {
            String cleanMessage = e.ChatMessage.Message.Trim(' ', Data.InvisibleCharacter);

            String[] tokens = cleanMessage.Split(' ');

            if (tokens.Length < 4)
            {
                CurrentStage = JimboxStage.None;
                return;
            }

            if (IsTop(tokens))
            {
                // Differentiate between top and bottom.
                if (CurrentStage == JimboxStage.Mouth)
                {
                    // We are at the bottom and have completed the jimbox.
                    CurrentStage = JimboxStage.Bottom;
                    Contributors.Add(e.ChatMessage.DisplayName);
                    SpoolSuccessMessage();
                    Border = null;
                    Contributors.Clear();
                }
                else
                {
                    // We just started a new jimbox.
                    CurrentStage = JimboxStage.Top;
                    Border       = tokens[0];
                    Contributors.Clear();
                    Contributors.Add(e.ChatMessage.DisplayName);
                }
            }
            else if (CurrentStage == JimboxStage.Top && IsEyes(tokens))
            {
                CurrentStage = JimboxStage.Eyes;
                Contributors.Add(e.ChatMessage.DisplayName);
            }
            else if (CurrentStage == JimboxStage.Eyes && IsMouth(tokens))
            {
                CurrentStage = JimboxStage.Mouth;
                Contributors.Add(e.ChatMessage.DisplayName);
            }
            else
            {
                CurrentStage = JimboxStage.None;
                Border       = null;
                Contributors.Clear();
            }
        }
        /////////////////////////////////////////////////////////////////////////////

        #endregion

        //////////////////////////////////////////////////////////////////////

        /// <summary>given a stream, parses it to construct the Feed object out of it</summary>
        /// <param name="stream"> a stream representing hopefully valid XML</param>
        /// <param name="format"> indicates if the stream is Atom or Rss</param>
        //////////////////////////////////////////////////////////////////////
        public void Parse(Stream stream, AlternativeFormat format)
        {
            Tracing.TraceCall("parsing stream -> Start:" + format.ToString());
            BaseFeedParser feedParser = null;

            // make sure we reset our collections
            Authors.Clear();
            Contributors.Clear();
            Links.Clear();
            Categories.Clear();

            feedParser = new AtomFeedParser(this);

            // create a new delegate for the parser
            feedParser.NewAtomEntry        += new FeedParserEventHandler(OnParsedNewEntry);
            feedParser.NewExtensionElement += new ExtensionElementEventHandler(OnNewExtensionElement);
            feedParser.Parse(stream, this);

            Tracing.TraceInfo("Parsing stream -> Done");
            // done parsing
        }
Example #3
0
        /// <summary>
        ///   This needs to be called after anything in the model is changed.
        /// </summary>
        public void SyncFromModel()
        {
            // this pulls down information from the Model element into the atom item.
            Id          = Model.CanonicalName;
            Title       = new TextSyndicationContent(Model.CosmeticName);
            Summary     = new TextSyndicationContent(Model.PackageDetails.SummaryDescription);
            PublishDate = Model.PackageDetails.PublishDate;
            Authors.Clear();
            Contributors.Clear();
            Categories.Clear();
            Links.Clear();

            if (Model.PackageDetails.Publisher != null)
            {
                Authors.Add(CreatePerson().With(a => {
                    a.Name  = Model.PackageDetails.Publisher.Name;
                    a.Email = Model.PackageDetails.Publisher.Email;
                    a.Uri   = Model.PackageDetails.Publisher.Location == null ? string.Empty : Model.PackageDetails.Publisher.Location.ToString();
                }));
            }
            if (!Model.PackageDetails.Contributors.IsNullOrEmpty())
            {
                foreach (var c in Model.PackageDetails.Contributors)
                {
                    var contributor = c;
                    Contributors.Add(CreatePerson().With(a => {
                        a.Name  = contributor.Name;
                        a.Email = contributor.Email;
                        a.Uri   = contributor.Location == null ? string.Empty : contributor.Location.ToString();
                    }));
                }
            }

            if (!string.IsNullOrEmpty(Model.PackageDetails.CopyrightStatement))
            {
                Copyright = new TextSyndicationContent(Model.PackageDetails.CopyrightStatement);
            }

            if (!Model.PackageDetails.Tags.IsNullOrEmpty())
            {
                foreach (var tag in Model.PackageDetails.Tags)
                {
                    Categories.Add(new SyndicationCategory(tag, "/Tags", tag));
                }
            }

            if (!Model.PackageDetails.Categories.IsNullOrEmpty())
            {
                foreach (var category in Model.PackageDetails.Categories)
                {
                    Categories.Add(new SyndicationCategory(category, "/Categories", category));
                }
            }

            if (Model.PackageDetails.Description != null)
            {
                Content = SyndicationContent.CreateHtmlContent(Model.PackageDetails.Description);
            }

            if (!Model.Locations.IsNullOrEmpty())
            {
                foreach (var l in Model.Locations)
                {
                    var location = l;
                    Links.Add(CreateLink().With(link => {
                        link.RelationshipType = "enclosure";
                        link.MediaType        = "application/package";
                        link.Uri   = location;
                        link.Title = Model.Name;
                    }));

                    Links.Add(CreateLink().With(link => {
                        link.Uri = location;
                    }));
                }
            }
            // and serialize that out.
            ElementExtensions.Add(Model, Model.XmlSerializer);
        }