Ejemplo n.º 1
0
        private string GetTarget(TeaseAction action)
        {
            var possibilities = new List <string>();

            var match = Regex.Match(action.Target, @"(?<pre>.*)\((?<min>\d+)\.\.(?<max>\d+)\)(?<post>.*)");

            if (match.Success)
            {
                int min = Convert.ToInt32(match.Groups["min"].Value);
                int max = Convert.ToInt32(match.Groups["max"].Value);
                for (var i = min; i < max; i++)
                {
                    string pageId = String.Format("{0}{1}{2}", match.Groups["pre"].Value, i, match.Groups["post"].Value);
                    if (Pages.Exists(p => p.Id.Equals(pageId)) && AllowedToShowPage(pageId))
                    {
                        possibilities.Add(pageId);
                    }
                }
            }
            else
            {
                string pageId = action.Target;
                if (Pages.Exists(p => p.Id.Equals(pageId)) && AllowedToShowPage(pageId))
                {
                    possibilities.Add(pageId);
                }
            }
            if (possibilities.Count == 0)
            {
                throw new ArgumentException(String.Format("Page '{0}' does not exist or is already marked as seen.\n\nFor the author of this tease:\nUse the set/unset commands to to correct this situation.", action.Target));
            }
            return(possibilities[random.Next(possibilities.Count)]);
        }
Ejemplo n.º 2
0
        public void ExecuteTeaseAction(TeaseAction action)
        {
            if (Settings.AutoSetPageWhenSeen)
            {
                SetFlags(currentPage.Id);
            }

            if (!String.IsNullOrEmpty(currentPage.SetFlags))
            {
                SetFlags(currentPage.SetFlags);
            }
            if (!String.IsNullOrEmpty(currentPage.UnsetFlags))
            {
                UnsetFlags(currentPage.UnsetFlags);
            }

            if (action != null)
            {
                if (!String.IsNullOrEmpty(action.SetFlags))
                {
                    SetFlags(action.SetFlags);
                }
                if (!String.IsNullOrEmpty(action.UnsetFlags))
                {
                    UnsetFlags(action.UnsetFlags);
                }

                var target = GetTarget(action);

                NavigateToPage(target);
            }
        }
Ejemplo n.º 3
0
        public void ExecuteTeaseAction(TeaseAction action)
        {
            if (Settings.AutoSetPageWhenSeen)
            {
                SetFlags(currentPage.Id);
            }

            if (!String.IsNullOrEmpty(currentPage.SetFlags))
            {
                SetFlags(currentPage.SetFlags);
            }
            if (!String.IsNullOrEmpty(currentPage.UnsetFlags))
            {
                UnsetFlags(currentPage.UnsetFlags);
            }

            if (action != null)
            {
                if (!String.IsNullOrEmpty(action.SetFlags))
                {
                    SetFlags(action.SetFlags);
                }
                if (!String.IsNullOrEmpty(action.UnsetFlags))
                {
                    UnsetFlags(action.UnsetFlags);
                }

                var target = GetTarget(action);

                NavigateToPage(target);
            }
        }
Ejemplo n.º 4
0
        private string GetTarget(TeaseAction action)
        {
            var possibilities = new List<string>();

            var match = Regex.Match(action.Target, @"(?<pre>.*)\((?<min>\d+)\.\.(?<max>\d+)\)(?<post>.*)");
            if (match.Success)
            {
                int min = Convert.ToInt32(match.Groups["min"].Value);
                int max = Convert.ToInt32(match.Groups["max"].Value);
                for (var i = min; i <= max; i++)
                {
                    string pageId = String.Format("{0}{1}{2}", match.Groups["pre"].Value, i, match.Groups["post"].Value);
                    if (Pages.Exists(p => p.Id.Equals(pageId)) && AllowedToShowPage(pageId))
                    {
                        possibilities.Add(pageId);
                    }
                }
            }
            else
            {
                if (Pages.Exists(p => p.Id.Equals(action.Target)))
                {
                    return action.Target;
                }
            }
            if (possibilities.Count == 0)
            {
                throw new ArgumentException(String.Format("Page '{0}' does not exist or is already marked as seen.\n\nFor the author of this tease:\nUse the set/unset commands to to correct this situation.", action.Target));
            }
            return possibilities[random.Next(possibilities.Count)];
        }
Ejemplo n.º 5
0
 private void ExecuteTeaseAction(TeaseAction teaseAction)
 {
     try
     {
         CurrentTease.ExecuteTeaseAction(teaseAction);
     }
     catch (Exception err)
     {
         MessageBox.Show("Error: " + err.Message);
     }
 }