Beispiel #1
0
        public static string ExecuteTryCatch(
            ConfBot config, bool answer, Func <string> action, Action <string> errorHandler)
        {
            try {
                return(action());
            } catch (CommandException ex) {
                NLog.LogLevel commandErrorLevel = answer ? NLog.LogLevel.Debug : NLog.LogLevel.Warn;
                Log.Log(commandErrorLevel, ex, "Command Error ({0})", ex.Message);
                if (answer)
                {
                    errorHandler(TextMod.Format(config.Commands.Color,
                                                "Error: {0}".Mod().Color(Color.Red).Bold(),
                                                ex.Message));
                }
            } catch (Exception ex) {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    errorHandler(TextMod.Format(config.Commands.Color,
                                                "An unexpected error occured: {0}".Mod().Color(Color.Red).Bold(), ex.Message));
                }
            }

            return(null);
        }
Beispiel #2
0
        public void TextToXmlAndBack()
        {
            DirectoryInfo di = new DirectoryInfo(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug\xmlandback");

            FileInfo[] modFiles = di.GetFiles();
            foreach (FileInfo modFile in modFiles)
            {
                string input = OpenTextFile(modFile.FullName);
                Console.WriteLine(modFile.FullName);
                TextMod newMod = new TextMod(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug");
                newMod.ReadString(input);
                string xmlFileName = Path.Combine(Path.Combine(modFile.DirectoryName, "xml"), modFile.Name + ".xml");
                ((ModxMod)newMod).Write(xmlFileName);
                TextMod ultraMod = new TextMod(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug");
                ((ModxMod)ultraMod).Read(xmlFileName);
                ultraMod.AuthorNotesIndent      = newMod.AuthorNotesIndent;
                ultraMod.AuthorNotesStartLine   = newMod.AuthorNotesStartLine;
                ultraMod.DescriptionIndent      = newMod.DescriptionIndent;
                ultraMod.ModFilesToEditIndent   = newMod.ModFilesToEditIndent;
                ultraMod.ModIncludedFilesIndent = newMod.ModIncludedFilesIndent;
                string temp = ultraMod.ToString();

                /*Console.Error.WriteLine("Actions");
                 * Assert.AreEqual(true, newMod.Actions.Equals(ultraMod.Actions));
                 * Console.Error.WriteLine("Header");
                 * Assert.AreEqual(true, newMod.Header.Equals(ultraMod.Header));*/
                Assert.AreEqual(newMod.ToString(), temp);
            }
        }
        public void Color6Test()
        {
            var res = TextMod.Format("Hello {0} but {1}",
                                     "World".Mod().Bold().Color(Color.Red),
                                     ", How are you?".Mod().Bold().Color(Color.Red));

            Assert.AreEqual("Hello [B][COLOR=red]World[/B] but [B][COLOR=red], How are you?", res);
        }
        public void Color4Test()
        {
            var res = TextMod.Format("Hello {0} but {1}".Mod().Color(new Color(0, 0, 1)).Bold(),
                                     "World".Mod().Bold().Italic(),
                                     ", How are you?".Mod().Underline());

            Assert.AreEqual("[B][COLOR=#000001]Hello [/COLOR][I]World[/I][COLOR=#000001] but [/B][U], How are you?", res);
        }
        public void Color3Test()
        {
            var res = TextMod.Format("Hello {0}{1}".Mod().Color(Color.Orange).Bold(),
                                     "World".Mod().Bold().Italic(),
                                     ", How are you?".Mod().Underline());

            Assert.AreEqual("[B][COLOR=#FF8000]Hello [/COLOR][I]World[/B][U], How are you?", res);
        }
Beispiel #6
0
        public void Color5Test()
        {
            var res = TextMod.Format("Hello {0} but {1}".Mod().Color(Color.Red).Bold(),
                                     "World".Mod().Bold().Italic().Strike(),
                                     ", How are you?".Mod().Underline());

            Assert.AreEqual("[B][COLOR=#FF0000]Hello [/COLOR][I][S]World[/I][COLOR=#FF0000] but [/B][U], How are you?", res);
        }
        public void Color7Test()
        {
            var res = TextMod.Format("Hello {0} but {1}".Mod().Color(Color.Red),
                                     "World".Mod().Color(Color.Blue),
                                     ", How are you?".Mod().Color(Color.Blue));

            Assert.AreEqual("[COLOR=red]Hello [/COLOR][COLOR=#00F]World[/COLOR][COLOR=red] but [/COLOR][COLOR=#00F], How are you?", res);
        }
Beispiel #8
0
        private void CallScript(ExecutionInformation info, string command, bool answer, bool skipRights)
        {
            Log.Debug("Calling script (skipRights:{0}, answer:{1}): {2}", skipRights, answer, command);

            info.AddDynamicObject(new CallerInfo(command, false)
            {
                SkipRightsChecks = skipRights
            });

            try
            {
                // parse (and execute) the command
                var res = CommandManager.CommandSystem.Execute(info, command);

                if (!answer)
                {
                    return;
                }

                // Write result to user
                switch (res.ResultType)
                {
                case CommandResultType.String:
                    var sRes = (StringCommandResult)res;
                    if (!string.IsNullOrEmpty(sRes.Content))
                    {
                        info.Write(sRes.Content).UnwrapToLog(Log);
                    }
                    break;

                case CommandResultType.Empty:
                    break;

                default:
                    Log.Warn("Got result which is not a string/empty. Result: {0}", res.ToString());
                    break;
                }
            }
            catch (CommandException ex)
            {
                Log.Debug(ex, "Command Error ({0})", ex.Message);
                if (answer)
                {
                    info.Write(TextMod.Format(config.Commands.Color, strings.error_call_error.Mod().Color(Color.Red).Bold(), ex.Message))
                    .UnwrapToLog(Log);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected command error: {0}", ex.UnrollException());
                if (answer)
                {
                    info.Write(TextMod.Format(config.Commands.Color, strings.error_call_unexpected_error.Mod().Color(Color.Red).Bold(), ex.Message))
                    .UnwrapToLog(Log);
                }
            }
        }
Beispiel #9
0
        public void SimpleTest()
        {
            DirectoryInfo di = new DirectoryInfo(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug\simpletest");

            FileInfo[] modFiles = di.GetFiles();
            foreach (FileInfo modFile in modFiles)
            {
                string  input  = OpenTextFile(modFile.FullName);
                TextMod newMod = new TextMod(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug");
                newMod.ReadString(input);
                input = input.Replace("\r\n", "\n");
                input = input.Replace("\r", "\n");
                Console.Out.WriteLine(modFile.FullName);
                Assert.AreEqual(input, newMod.ToString());
            }
        }
Beispiel #10
0
        public void AdvancedTest_DeepCompare()
        {
            DirectoryInfo di = new DirectoryInfo(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug\advancedtest");

            FileInfo[] modFiles = di.GetFiles();
            foreach (FileInfo modFile in modFiles)
            {
                string input = OpenTextFile(modFile.FullName);
                Console.WriteLine(modFile.FullName);
                TextMod newMod = new TextMod(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug");
                newMod.ReadString(input);
                TextMod ultraMod = new TextMod(@"C:\Users\Lachlan\Documents\Visual Studio Projects\Phpbb.ModTeam.Tools\bin\Debug");
                ultraMod.ReadString(newMod.ToString());
                string temp = ultraMod.ToString();
                Console.Error.WriteLine("Actions");
                Assert.AreEqual(true, newMod.Actions.Equals(ultraMod.Actions));
                Console.Error.WriteLine("Header");
                Assert.AreEqual(true, newMod.Header.Equals(ultraMod.Header));
            }
        }
Beispiel #11
0
 public AppliedTextMod Color(Color color)
 {
     Mod = Mod.Color(color); return(this);
 }
Beispiel #12
0
        public void Color1Test()
        {
            var res = TextMod.Format("Hello {0}".Mod().Color(Color.Red).Bold(), "World".Mod().Bold());

            Assert.AreEqual("[B][COLOR=#FF0000]Hello [/COLOR]World", res);
        }
Beispiel #13
0
 public AppliedTextMod Strike()
 {
     Mod = Mod.Strike(); return(this);
 }
Beispiel #14
0
 public AppliedTextMod(string?text, TextMod mod)
 {
     Text = text;
     Mod  = mod;
 }
Beispiel #15
0
 public AppliedTextMod Underline()
 {
     Mod = Mod.Underline(); return(this);
 }
Beispiel #16
0
 public AppliedTextMod Italic()
 {
     Mod = Mod.Italic(); return(this);
 }
Beispiel #17
0
 public AppliedTextMod Bold()
 {
     Mod = Mod.Bold(); return(this);
 }
Beispiel #18
0
 public AppliedTextMod(string?text)
 {
     Text = text;
     Mod  = TextMod.None;
 }
        public void Color2Test()
        {
            var res = TextMod.Format("Hello {0}".Mod().Color(Color.Blue).Bold(), "World".Mod().Bold().Italic());

            Assert.AreEqual("[B][COLOR=#00F]Hello [/COLOR][I]World", res);
        }