Ejemplo n.º 1
0
        public static void DoBuild(CallbackQuery query)
        {
            var msg = query.Message.Text + $"\n\nBeginning build...\n";

            Bot.ReplyToCallback(query, msg);
            //determine what we are building
            var updateType = query.Data.Split('|')[1];
            var beta       = updateType.StartsWith("beta");
            var control    = !updateType.Contains("node");
            var node       = !updateType.Contains("control");

            msg += "Build Definition(s) to Use:";
            var definitions = new List <string>();
            var env         = beta ? "Beta" : "Release";

            //var what = control ? node ? "Both" : "Control" : "Node";
            if (control)
            {
                definitions.Add($"{env} Control");
            }
            if (node)
            {
                definitions.Add($"{env} Node");
            }

            msg = definitions.Aggregate(msg, (current, a) => current + "\n" + a);
            Thread.Sleep(500);

            Bot.Edit(query, msg);
            Thread.Sleep(500);
            //now let's actually kick off that build
            msg = definitions.Aggregate(msg, (current, def) => current + ("\n" + QueueBuild(def).Result));
            Bot.Edit(query, msg);
        }
Ejemplo n.º 2
0
        public static void UseNewLanguageFile(string fileName, long id, int msgId)
        {
            var msg = "Moving file to production..\n";

            msg += "Checking paths for duplicate language file...\n";
            Bot.Api.EditMessageTextAsync(id, msgId, msg);
            fileName += ".xml";
            var tempPath    = Bot.TempLanguageDirectory;
            var langPath    = Bot.LanguageDirectory;
            var newFilePath = Path.Combine(tempPath, fileName);
            var copyToPath  = Path.Combine(langPath, fileName);

            //get the new files language
            var doc = XDocument.Load(newFilePath);

            var newFileLang = new
            {
                Name    = doc.Descendants("language").First().Attribute("name").Value,
                Base    = doc.Descendants("language").First().Attribute("base").Value,
                Variant = doc.Descendants("language").First().Attribute("variant").Value
            };


            //check for existing file
            var langs = Directory.GetFiles(langPath).Select(x => new LangFile(x)).ToList();
            var lang  = langs.FirstOrDefault(x => x.Name == newFileLang.Name && x.FilePath != copyToPath);

            if (lang != null)
            {
                msg       += $"Found duplicate language (name attribute) with filename {Path.GetFileNameWithoutExtension(lang.FilePath)}\n";
                copyToPath = lang.FilePath;
            }
            else
            {
                lang = langs.FirstOrDefault(x => x.Base == newFileLang.Base && x.Variant == newFileLang.Variant && x.Name != newFileLang.Name);
                if (lang != null)
                {
                    msg += $"Found duplicate language (matching base and variant) with filename {Path.GetFileNameWithoutExtension(lang.FilePath)}\n";
                    msg += "Aborting!";
                    Bot.Api.EditMessageTextAsync(id, msgId, msg);
                    return;
                }
            }


            System.IO.File.Copy(newFilePath, copyToPath, true);
            msg += "File copied to bot\n";
//#if RELEASE
//            msg += $"File copied to bot 1\n";
//#elif RELEASE2
//            msg += $"File copied to bot 2\n";
//#endif
            //Bot.Api.EditMessageTextAsync(id, msgId, msg);
//#if RELEASE
//            copyToPath = copyToPath.Replace("Werewolf 3.0", "Werewolf 3.0 Clone");
//            System.IO.File.Copy(newFilePath, copyToPath, true);
//            msg += $"File copied to bot 2\n";
//            Bot.Api.EditMessageTextAsync(id, msgId, msg);
//#endif
            var gitPath = Path.Combine(@"C:\Werewolf Source\Werewolf\Werewolf for Telegram\Languages", Path.GetFileName(copyToPath));

            File.Copy(newFilePath, gitPath, true);
            System.IO.File.Delete(newFilePath);
            msg += $"File copied to git directory\n";
            if (newFilePath.EndsWith("English.xml"))
            {
                var p = new Process
                {
                    StartInfo =
                    {
                        FileName               = @"C:\Werewolf Source\Werewolf\Werewolf for Telegram\Languages\commit.bat",
                        Arguments              = $"\"Syncing langfiles from Telegram (English.xml update)\"",
                        WorkingDirectory       = @"C:\Werewolf Source\Werewolf\Werewolf for Telegram\Languages",
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true,
                        CreateNoWindow         = true
                    }
                };

                p.Start();
                msg += "Started the committing process. Reading output from git...";
                Bot.Edit(id, msgId, msg);

                var output = "";
                while (!p.StandardOutput.EndOfStream)
                {
                    output += p.StandardOutput.ReadLine() + Environment.NewLine;
                }
                while (!p.StandardError.EndOfStream)
                {
                    output += p.StandardError.ReadLine() + Environment.NewLine;
                }

                msg += "\nValidating the output...";
                Bot.Edit(id, msgId, msg);

                //validate the output
                if (output.Contains("failed"))
                {
                    msg += "\n<b>Failed</b> to commit files. See control output for information";
                    Console.WriteLine(output);
                }
                else if (output.Contains("nothing to commit"))
                {
                    msg += "\nNothing to commit.";
                }
                else
                {
                    //try to grab the commit
                    var regex  = new Regex("(\\[master .*])");
                    var match  = regex.Match(output);
                    var commit = "";
                    if (match.Success)
                    {
                        commit = match.Value.Replace("[master ", "").Replace("]", "");
                    }
                    msg += $"\n<b>Files committed successfully.</b> {(String.IsNullOrEmpty(commit) ? "" : $"<a href=\"https://github.com/GreyWolfDev/Werewolf/commit/" + commit + $"\">{commit}</a>")}";
                }
            }
            msg += "\n<b>Operation complete.</b>";

            Bot.Api.EditMessageTextAsync(id, msgId, msg, parseMode: ParseMode.Html);
        }
Ejemplo n.º 3
0
        public static void UseNewLanguageFile(string fileName, long id, int msgId)
        {
            var msg = "Moving file to production..\n";

            msg += "Checking paths for duplicate language file...\n";
            Bot.Api.EditMessageTextAsync(id, msgId, msg).Wait();
            fileName += ".xml";
            var tempPath    = Bot.TempLanguageDirectory;
            var langPath    = Bot.LanguageDirectory;
            var newFilePath = Path.Combine(tempPath, fileName);
            var copyToPath  = Path.Combine(langPath, fileName);

            //get the new files language
            var doc = XDocument.Load(newFilePath);

            var newFileLang = new
            {
                Name    = doc.Descendants("language").First().Attribute("name").Value,
                Base    = doc.Descendants("language").First().Attribute("base").Value,
                Variant = doc.Descendants("language").First().Attribute("variant").Value
            };


            //check for existing file
            var langs = Directory.GetFiles(langPath, "*.xml").Select(x => new LangFile(x)).ToList();
            var lang  = langs.FirstOrDefault(x => x.Name == newFileLang.Name && x.FilePath != copyToPath);

            if (lang != null)
            {
                msg       += $"Found duplicate language (name attribute) with filename {Path.GetFileNameWithoutExtension(lang.FilePath)}\n";
                copyToPath = lang.FilePath;
            }
            else
            {
                lang = langs.FirstOrDefault(x => x.Base == newFileLang.Base && x.Variant == newFileLang.Variant && x.Name != newFileLang.Name);
                if (lang != null)
                {
                    msg += $"Found duplicate language (matching base and variant) with filename {Path.GetFileNameWithoutExtension(lang.FilePath)}\n";
                    msg += "Aborting!";
                    Bot.Api.EditMessageTextAsync(id, msgId, msg);
                    return;
                }
            }


            System.IO.File.Copy(newFilePath, copyToPath, true);
            msg += "File copied to bot\n";
            //#if RELEASE
            //            msg += $"File copied to bot 1\n";
            //#elif RELEASE2
            //            msg += $"File copied to bot 2\n";
            //#endif
            //Bot.Api.EditMessageTextAsync(id, msgId, msg);
            //#if RELEASE
            //            copyToPath = copyToPath.Replace("Werewolf 3.0", "Werewolf 3.0 Clone");
            //            System.IO.File.Copy(newFilePath, copyToPath, true);
            //            msg += $"File copied to bot 2\n";
            //            Bot.Api.EditMessageTextAsync(id, msgId, msg);
            //#endif
#if !DEBUG
            try
            {
                var gitPath = Path.Combine(@"C:\Werewolf Source\Werewolf\Werewolf for Telegram\Languages", Path.GetFileName(copyToPath));
                File.Copy(newFilePath, gitPath, true);
                System.IO.File.Delete(newFilePath);
                msg += $"File copied to git directory\n";
                if (Path.GetFileName(newFilePath) == Program.MasterLanguage)
                {
                    var p = new Process
                    {
                        StartInfo =
                        {
                            FileName               = @"C:\Werewolf Source\Werewolf\Werewolf for Telegram\Languages\commit.bat",
                            Arguments              = $"\"Syncing langfiles from Telegram (English.xml update)\"",
                            WorkingDirectory       = @"C:\Werewolf Source\Werewolf\Werewolf for Telegram\Languages",
                            UseShellExecute        = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError  = true,
                            CreateNoWindow         = true
                        }
                    };

                    p.Start();
                    msg += "Started the committing process. Reading output from git...";
                    Bot.Edit(id, msgId, msg).Wait();

                    var output = "";
                    while (!p.StandardOutput.EndOfStream)
                    {
                        output += p.StandardOutput.ReadLine() + Environment.NewLine;
                    }
                    while (!p.StandardError.EndOfStream)
                    {
                        output += p.StandardError.ReadLine() + Environment.NewLine;
                    }

                    msg += "\nValidating the output...";
                    Bot.Edit(id, msgId, msg).Wait();

                    //validate the output
                    if (output.Contains("failed"))
                    {
                        msg += "\n<b>Failed</b> to commit files. See control output for information";
                        Console.WriteLine(output);
                    }
                    else if (output.Contains("nothing to commit"))
                    {
                        msg += "\nNothing to commit.";
                    }
                    else
                    {
                        //try to grab the commit
                        var regex  = new Regex("(\\[master .*])");
                        var match  = regex.Match(output);
                        var commit = "";
                        if (match.Success)
                        {
                            commit = match.Value.Replace("[master ", "").Replace("]", "");
                        }
                        msg += $"\n<b>Files committed successfully.</b> {(String.IsNullOrEmpty(commit) ? "" : $"<a href=\"https://github.com/GreyWolfDev/Werewolf/commit/" + commit + $"\">{commit}</a>")}";
                    }
                }
            }
            catch (Exception e)
            {
                var trace = e.StackTrace;
                var error = e.Message;
                do
                {
                    e = e.InnerException;
                    if (e == null)
                    {
                        break;
                    }
                    error += "\n" + e.Message;
                }while (true);

                Bot.Send("Error while trying to commit to git:\n" + error + "\n\n" + trace, id);
            }
#endif
            using (var db = new WWContext())
            {
                var newFile = new LangFile(copyToPath);

                // search for language file entry and update it or add it if it's not present yet
                Language language = db.Language.FirstOrDefault(x => x.FileName == newFile.FileName);
                if (language == null)
                {
                    language = db.Language.Add(new Language {
                        FileName = newFile.FileName
                    });
                }
                language.Base      = newFile.Base;
                language.IsDefault = newFile.IsDefault;
                language.LangCode  = newFile.LangCode;
                language.Name      = newFile.Name;
                language.Variant   = newFile.Variant;

                db.SaveChanges();
            }

            var info = new ReloadLangInfo
            {
                LangName = Path.GetFileNameWithoutExtension(copyToPath)
            };
            var json = JsonConvert.SerializeObject(info);

            foreach (var n in Bot.Nodes)
            {
                n.Broadcast(json);
            }

            msg += "\n<b>Operation complete.</b>";
            Bot.Edit(id, msgId, msg, parsemode: ParseMode.Html);
        }