Exemple #1
0
        public Tease ConvertToTease()
        {
            if (!CanConvert())
            {
                return null;
            }

            var result = new Tease();

            var authorNode = xmldoc.SelectSingleNode("/pages/@author");
            if (authorNode != null)
            {
                result.Author = new Author { Name = authorNode.Value };
            }

            var titleNode = xmldoc.SelectSingleNode("/pages/@title");
            if (titleNode != null)
            {
                result.Title = titleNode.Value;
            }

            var urlNode = xmldoc.SelectSingleNode("/pages/@url");
            if (urlNode != null)
            {
                result.Url = urlNode.Value;
            }

            var mediafolderNode = xmldoc.SelectSingleNode("/pages/@mediafolder");
            if (mediafolderNode != null)
            {
                result.MediaDirectory = mediafolderNode.Value.TrimStart('/', '\\');
            }

            var pageNodes = xmldoc.SelectNodes("/pages/page");
            if (pageNodes != null)
            {
                foreach (XmlNode pageNode in pageNodes)
                {
                    var page = new TeasePage();

                    page.Id = pageNode.SelectSingleNode("pageid").InnerText;

                    var textNode = pageNode.SelectSingleNode("instruction");
                    if (textNode != null)
                    {
                        page.Text = textNode.InnerText;
                    }

                    page.Image = CreateImage(pageNode);
                    page.Video = CreateVideo(pageNode);
                    page.Delay = CreateDelay(pageNode);
                    page.Metronome = CreateMetronome(pageNode);
                    page.ButtonList.AddRange(CreateButtons(pageNode));

                    result.Pages.Add(page);
                }
            }
            return result;
        }
        public static TeasePage CreatePage(string id, string originalHtml)
        {
            var result = new TeasePage { Id = id };

            var text = originalHtml.Remove('\n', '\r', '\t');
            text = text.AfterFirst("<a name=\"t\"></a>");

            string nextPage;
            string imageUrl;

            if (text.Contains("<a name=\"rate\"></a>"))
            {
                // Last page.
                text = text.BeforeFirst("<div class=\"item\"><a name=\"rate\"></a>");

                Match m = Regex.Match(text, "<img src=\"(?<imageUrl>.*?)\"");
                nextPage = String.Empty;
                imageUrl = m.Success ? m.Groups["imageUrl"].Value : String.Empty;
            }
            else
            {
                text = text.BeforeFirst("<script type=\"text/javascript\">document.onkeypress=function(e)");

                Match m = Regex.Match(text, "<a href=\"webteases/showtease.php\\?id=(?<teaseId>\\d+)&p=(?<nextPage>\\d+)#t\"><img src=\"(?<imageUrl>.*?)\"");
                nextPage = m.Success ? m.Groups["nextPage"].Value : String.Empty;
                imageUrl = m.Success ? m.Groups["imageUrl"].Value : String.Empty;
            }

            text = text.AfterFirst("<div id=\"tease_content\">");

            if (text.StartsWith("<p class=\"breaker\"></p>"))
            {
                text = text.AfterFirst("<p class=\"breaker\"></p>");
            }
            if (text.Contains("<p class=\"link\"><a href=\"webteases/showtease.php?id="))
            {
                text = text.BeforeLast("<p class=\"link\"><a href=\"webteases/showtease.php?id=");
            }
            if (text.Contains("</div><h1>The End</h1>"))
            {
                text = text.Replace("</div><h1>The End</h1>", "<h1>The End</h1>");
            }

            result.Text = text;

            if (!String.IsNullOrEmpty(imageUrl))
            {
                result.ImageList.Add(new TeaseMedia { Id = imageUrl });
            }
            if (!String.IsNullOrEmpty(nextPage))
            {
                result.ButtonList.Add(new TeaseButton { Target = nextPage, Text = "Continue" });
            }

            return result;
        }
Exemple #3
0
 public Tease EmptyTease()
 {
     var tease = new Tease
     {
         ScriptDirectory = applicationDirectory
     };
     var welcomePage = new TeasePage();
     welcomePage.Id = "start";
     welcomePage.Text = "Welcome. Please open a tease.";
     welcomePage.AudioList.Add(new TeaseMedia { Id = ConfigurationManager.AppSettings["WelcomeAudio"] });
     welcomePage.ImageList.Add(new TeaseMedia { Id = ConfigurationManager.AppSettings["WelcomeImage"] });
     tease.Pages.Add(welcomePage);
     return tease;
 }
Exemple #4
0
        public Tease EmptyTease()
        {
            var tease = new Tease
            {
                ScriptDirectory = applicationDirectory
            };
            var welcomePage = new TeasePage();

            welcomePage.Id   = "start";
            welcomePage.Text = "Welcome. Please open a tease.";
            welcomePage.AudioList.Add(new TeaseMedia {
                Id = ConfigurationManager.AppSettings["WelcomeAudio"]
            });
            welcomePage.ImageList.Add(new TeaseMedia {
                Id = ConfigurationManager.AppSettings["WelcomeImage"]
            });
            tease.Pages.Add(welcomePage);
            return(tease);
        }
Exemple #5
0
 public void NavigateToPage(string pageId)
 {
     CurrentPage = Pages.Find(page => page.Id.Equals(pageId, StringComparison.InvariantCultureIgnoreCase));
 }
        void DownloadMedia(DownloadTask task, TeasePage page, TeaseMedia teaseMedia)
        {
            string mediaName = teaseMedia.Id;
            if (teaseMedia.Id.Contains("*"))
            {
                mediaName = teaseMedia.Id.Replace("*", String.Format("[{0}]", Guid.NewGuid()));
            }
            if (teaseMedia.Id.StartsWith("http://") || teaseMedia.Id.StartsWith("https://"))
            {
                mediaName = new Uri(teaseMedia.Id).Segments.Last();
            }
            string fileName = Path.Combine(task.MediaDirectory.FullName, mediaName);
            if (!File.Exists(fileName))
            {
                string url = String.Format("{0}/media/get.php?folder={1}/{2}&name={3}", MilovanaRootUrl, task.AuthorId, task.TeaseId, teaseMedia.Id);
                if (teaseMedia.Id.StartsWith("http://") || teaseMedia.Id.StartsWith("https://"))
                {
                    url = teaseMedia.Id;
                }
                try
                {
                    using (var client = new WebClient())
                    {
                        backgroundWorker.ReportProgress(0, "Downloading " + url);

                        // Be nice to the Milovana webserver and wait a bit before the next request...
                        Thread.Sleep(800);

                        client.DownloadFile(url, fileName);
                        backgroundWorker.ReportProgress(0, "Ok");
                    }
                }
                catch (Exception err)
                {
                    backgroundWorker.ReportProgress(1, String.Format("Error: [{0}] {1}", err.GetType(), err.Message));
                    page.Errors = String.Format("Error while downloading file '{0}'. {1}.", url, page.Errors);
                }
            }
            if (teaseMedia.Id.StartsWith("http://") || teaseMedia.Id.StartsWith("https://"))
            {
                teaseMedia.Id = mediaName;
            }
        }
        private TeasePage CreatePage(string line)
        {
            var result = new TeasePage { Comments = line };

            var stream = new ANTLRStringStream(line);
            var lexer = new FlashTeaseScriptLexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new FlashTeaseScriptParser(tokens);

            try
            {
                IAstRuleReturnScope<CommonTree> teaseReturn = parser.tease();
                if (teaseReturn.Tree != null)
                {
                    var pageNode = teaseReturn.Tree;
                    if (pageNode.Type != FlashTeaseScriptLexer.PAGE)
                    {
                        pageNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.PAGE) as CommonTree;
                    }

                    if (pageNode != null && pageNode.Type == FlashTeaseScriptLexer.PAGE)
                    {
                        var idNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.ID) as CommonTree;
                        if (idNode != null)
                        {
                            result.Id = GetPageId(idNode);
                        }

                        var propertiesNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.PROPERTIES) as CommonTree;
                        if (propertiesNode != null)
                        {
                            result.Text = GetText(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.TEXT) as CommonTree);

                            var image = GetImage(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.PIC) as CommonTree);
                            if (image != null)
                            {
                                result.ImageList.Add(image);
                            }
                            var audio = GetAudio(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.SOUND) as CommonTree);
                            if (audio != null)
                            {
                                result.AudioList.Add(audio);
                            }
                            var delay =  GetDelay(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.DELAY) as CommonTree);
                            if (delay != null)
                            {
                                result.DelayList.Add(delay);
                            }

                            result.ButtonList.AddRange(GetButtons(propertiesNode));

                            result.SetFlags = GetFlags(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.SET) as CommonTree);
                            result.UnsetFlags = GetFlags(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.UNSET) as CommonTree);
                        }
                    }
                }

                if (parser.HasError)
                {
                    result.Errors = String.Format("ParserError ({0}): {1}. Please correct by hand.", parser.ErrorPosition, parser.ErrorMessage);
                }
            }
            catch (Exception)
            {
                result.Errors = String.Format("ParserError ({0}): {1}. Please correct by hand.", parser.ErrorPosition, parser.ErrorMessage);
            }

            if (String.IsNullOrEmpty(result.Id))
            {
                result.Id = Guid.NewGuid().ToString();
                result.Errors = String.Format("This page had no id, so one is generated. {0}", result.Errors);
            }

            return result;
        }