Beispiel #1
0
        static void KillMysql()
        {
            var mysqls = Process.GetProcessesByName("mysqld_z");

            if (mysqls.Length != 0)
            {
                using (var _ = new ChangingOutput("Termininating existing MySql servers . . ."))
                {
                    _.FinishLine();

                    var success = true;

                    foreach (var p in mysqls)
                    {
                        using (var t = new ChangingOutput("Terminating process {0} . . .", p.Id))
                        {
                            p.Kill();
                            var killed = p.WaitForExit(10 * 1000);
                            t.PrintResult(killed);

                            if (!killed)
                            {
                                success = false;
                            }
                        }
                    }

                    _.PrintResult(success);
                }
            }
        }
Beispiel #2
0
        bool Compile(params string[] targets)
        {
            using (var t = new ChangingOutput("Compiling target(s) {0} . . .", string.Join(", ", targets)))
            {
                t.FinishLine();

                var logger = new ConsoleLogger(LoggerVerbosity.Quiet);

                logger.SkipProjectStartedText = true;

                var props = new Dictionary <string, string>
                {
                    { "Configuration", _release ? "Release" : "Debug" },
                };

                var request = new BuildRequestData(_slnPath, props, null, targets, null);
                var p       = new BuildParameters()
                {
                    Loggers          = new[] { logger },
                    GlobalProperties = props
                };

                var result = BuildManager.DefaultBuildManager.Build(p, request);

                t.PrintResult(result.OverallResult == BuildResultCode.Success);

                return(result.OverallResult == BuildResultCode.Success);
            }
        }
Beispiel #3
0
        bool Compile(params string[] targets)
        {
            using (var t = new ChangingOutput("Compiling target(s) {0} . . .", string.Join(", ", targets)))
            {
                t.FinishLine();

                var logger = new ConsoleLogger(LoggerVerbosity.Quiet);

                logger.SkipProjectStartedText = true;

                var props = new Dictionary<string, string>
                {
                    {"Configuration", _release ? "Release" : "Debug"},
                };

                var request = new BuildRequestData(_slnPath, props, null, targets, null);
                var p = new BuildParameters()
                {
                    Loggers = new[] {logger},
                    GlobalProperties = props
                };

                var result = BuildManager.DefaultBuildManager.Build(p, request);

                t.PrintResult(result.OverallResult == BuildResultCode.Success);

                return result.OverallResult == BuildResultCode.Success;
            }
        }
Beispiel #4
0
        public bool Test()
        {
            using (var t = new ChangingOutput("Checking Ports . . ."))
            {
                t.FinishLine();

                var pass = true;

                foreach (var kvp in _ports)
                {
                    var result = TestPort(kvp.Key, kvp.Value.Item1);
                    if (result != null)
                    {
                        Console.WriteLine(result);
                        Console.WriteLine("{0} services will not be avalible.", kvp.Value.Item1);
                        Console.WriteLine();
                        if (kvp.Value.Item2)
                        {
                            pass = false;
                        }
                    }
                }

                t.PrintResult(pass);
                return(pass);
            }
        }
Beispiel #5
0
        public bool Test()
        {
            using (var t = new ChangingOutput("Checking Ports . . ."))
            {
                t.FinishLine();

                var pass = true;

                foreach (var kvp in _ports)
                {
                    var result = TestPort(kvp.Key, kvp.Value.Item1);
                    if (result != null)
                    {
                        Console.WriteLine(result);
                        Console.WriteLine("{0} services will not be avalible.", kvp.Value.Item1);
                        Console.WriteLine();
                        if (kvp.Value.Item2)
                            pass = false;
                    }
                }

                t.PrintResult(pass);
                return pass;
            }
        }
Beispiel #6
0
        Repository GetGitRepo(out bool created)
        {
            created = false;

            using (var t = new ChangingOutput("Reading Git repository . . ."))
            {
                if (Repository.IsValid(_repoDir))
                {
                    t.PrintResult(true);
                    return new Repository(_repoDir);
                }

                t.PrintResult(false);
            }

            using (var t = new ChangingOutput("Repository not valid - redownloading Aura source . . ."))
            {
                Repository.Clone(_gitClonePath, _repoDir, new CloneOptions()
                {
                    OnTransferProgress = (x) =>
                    {
                        t.PrintProgress((double) x.ReceivedObjects/x.TotalObjects);
                        return true;
                    }
                });

                t.PrintResult(true);

                created = true;
            }

            return new Repository(_repoDir);
        }
Beispiel #7
0
        Process StartMySql()
        {
            var p = new Process
            {
                StartInfo =
                {
                    FileName         = _mySqlDPath,
                    CreateNoWindow   = true,
                    UseShellExecute  = false,
                    WindowStyle      = ProcessWindowStyle.Hidden,
                    WorkingDirectory = _mySqlDir
                }
            };

            using (var t = new ChangingOutput("Starting MySql server . . ."))
            {
                var success = p.Start();

                t.PrintResult(success);

                if (!success)
                {
                    p = null;
                }
            }

            using (var _ = new ChangingOutput("Waiting for MySql to accept connections . . ."))
            {
                var i     = 0;
                var timer = new Timer(1000);

                timer.Elapsed += (e, o) =>
                {
                    _.PrintNumber(i++);
                };

                timer.Start();

                while (!CheckMysqlPort())
                {
                    Thread.Sleep(1000);
                }

                timer.Stop();

                _.PrintResult(true);
            }

            return(p);
        }
Beispiel #8
0
        public bool RunMainSql(string mainSqlPath)
        {
            using (var t = new ChangingOutput("Applying main.sql"))
            {
                using (var p = new Process())
                {
                    p.StartInfo.FileName = _mySqlPath;
                    p.StartInfo.Arguments = _mySqlArgs;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.RedirectStandardError = p.StartInfo.RedirectStandardInput = p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.WorkingDirectory = _mySqlDir;
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                    t.PrintNumber(0);

                    var i = 0;

                    var ti = new Timer(1000);
                    ti.Elapsed += (e, o) => { t.PrintNumber(++i); };

                    ti.Start();

                    p.Start();

                    p.StandardInput.Write(File.ReadAllText(mainSqlPath));
                    p.StandardInput.WriteLine();
                    p.StandardInput.WriteLine("exit");
                    p.StandardInput.Flush();

                    p.WaitForExit();

                    ti.Stop();

                    var success = true;

                    if (!p.StandardError.EndOfStream)
                    {
                        t.FinishLine();
                        Console.WriteLine("MySql reports errors: {0}", p.StandardError.ReadToEnd());
                        success = false;
                    }

                    t.PrintResult(success);

                    return success;
                }
            }
        }
Beispiel #9
0
        public bool RunMainSql(string mainSqlPath)
        {
            using (var t = new ChangingOutput("Applying main.sql"))
            {
                using (var p = new Process())
                {
                    p.StartInfo.FileName              = _mySqlPath;
                    p.StartInfo.Arguments             = _mySqlArgs;
                    p.StartInfo.CreateNoWindow        = true;
                    p.StartInfo.RedirectStandardError = p.StartInfo.RedirectStandardInput = p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.UseShellExecute       = false;
                    p.StartInfo.WorkingDirectory      = _mySqlDir;
                    p.StartInfo.WindowStyle           = ProcessWindowStyle.Hidden;

                    t.PrintNumber(0);

                    var i = 0;

                    var ti = new Timer(1000);
                    ti.Elapsed += (e, o) => { t.PrintNumber(++i); };

                    ti.Start();

                    p.Start();

                    p.StandardInput.Write(File.ReadAllText(mainSqlPath));
                    p.StandardInput.WriteLine();
                    p.StandardInput.WriteLine("exit");
                    p.StandardInput.Flush();

                    p.WaitForExit();

                    ti.Stop();

                    var success = true;

                    if (!p.StandardError.EndOfStream)
                    {
                        t.FinishLine();
                        Console.WriteLine("MySql reports errors: {0}", p.StandardError.ReadToEnd());
                        success = false;
                    }

                    t.PrintResult(success);

                    return(success);
                }
            }
        }
Beispiel #10
0
        private static void CheckForHpd()
        {
            using (
                var key =
                    Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                        @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"))
            {
                if (key == null || key.GetValueNames().All(n => n.ToLower() != "platform"))
                {
                    return;
                }

                PrintWarning("Platform environmental variable exists. This may interfere with compilation.");

                Console.Write("Would you like to attempt to autoremove this value? (y/n): ");

                if (!Console.ReadLine().Trim().ToLower().StartsWith("y"))
                {
                    Console.WriteLine("User selected to not remove value");
                    return;
                }

                using (var _ = new ChangingOutput("Deleting platform key"))
                {
                    _.FinishLine();

                    var r = false;

                    try
                    {
                        using (var k2 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true))
                        {
                            k2.DeleteValue("Platform", true);
                        }
                        r = true;
                    }
                    catch (Exception ex)
                    {
                        PrintError("Failed to delete registry key. Try running Frontend as an Administrator. Details: {0}", ex.Message);
                    }

                    _.PrintResult(r);
                }
            }
        }
Beispiel #11
0
        private static void CheckForHpd()
        {
            using (
                var key =
                    Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                        @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"))
            {
                if (key == null || key.GetValueNames().All(n => n.ToLower() != "platform"))
                    return;

                PrintWarning("Platform environmental variable exists. This may interfere with compilation.");

                Console.Write("Would you like to attempt to autoremove this value? (y/n): ");

                if (!Console.ReadLine().Trim().ToLower().StartsWith("y"))
                {
                    Console.WriteLine("User selected to not remove value");
                    return;
                }

                using (var _ = new ChangingOutput("Deleting platform key"))
                {
                    _.FinishLine();

                    var r = false;

                    try
                    {
                        using (var k2 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true))
                        {
                            k2.DeleteValue("Platform", true);
                        }
                        r = true;
                    }
                    catch (Exception ex)
                    {
                        PrintError("Failed to delete registry key. Try running Frontend as an Administrator. Details: {0}", ex.Message);
                    }

                    _.PrintResult(r);
                }
            }
        }
Beispiel #12
0
        Repository GetGitRepo(out bool created)
        {
            created = false;

            using (var t = new ChangingOutput("Reading Git repository . . ."))
            {
                if (Repository.IsValid(_repoDir))
                {
                    t.PrintResult(true);
                    return(new Repository(_repoDir));
                }

                t.PrintResult(false);
            }

            using (var t = new ChangingOutput("Repository not valid - redownloading Aura source . . ."))
            {
                try
                {
                    Repository.Clone(_gitClonePath, _repoDir, new CloneOptions()
                    {
                        OnTransferProgress = (x) =>
                        {
                            t.PrintProgress((double)x.ReceivedObjects / x.TotalObjects);
                            return(true);
                        }
                    });
                }
                catch
                {
                    t.PrintResult(false);
                    throw;
                }

                t.PrintResult(true);

                created = true;
            }

            return(new Repository(_repoDir));
        }
Beispiel #13
0
        private static string TestPort(int number, string name)
        {
            using (var t = new ChangingOutput("Testing port {0} ({1}) . . .", number, name))
            {
                using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    socket.ExclusiveAddressUse = true;
                    try
                    {
                        socket.Bind(new IPEndPoint(IPAddress.Any, number));
                    }
                    catch (SocketException ex)
                    {
                        t.PrintResult(false);
                        return ex.Message;
                    }
                }

                t.PrintResult(true);
                return null;
            }
        }
Beispiel #14
0
        private static string TestPort(int number, string name)
        {
            using (var t = new ChangingOutput("Testing port {0} ({1}) . . .", number, name))
            {
                using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    socket.ExclusiveAddressUse = true;
                    try
                    {
                        socket.Bind(new IPEndPoint(IPAddress.Any, number));
                    }
                    catch (SocketException ex)
                    {
                        t.PrintResult(false);
                        return(ex.Message);
                    }
                }

                t.PrintResult(true);
                return(null);
            }
        }
Beispiel #15
0
        public override bool Start()
        {
            using (var t = new ChangingOutput("Starting Aura servers . . ."))
            {
                using (var p = new Process
                {
                    StartInfo =
                    {
                        FileName = _startServersPath,
                        CreateNoWindow = true,
                        UseShellExecute = true,
                        WorkingDirectory = _auraDir
                    }
                })
                {
                    p.Start();
                    p.WaitForExit();

                    t.PrintResult(p.ExitCode == 0);
                    return p.ExitCode == 0;
                }
            }
        }
Beispiel #16
0
        public override bool Start()
        {
            using (var t = new ChangingOutput("Starting Aura servers . . ."))
            {
                using (var p = new Process
                {
                    StartInfo =
                    {
                        FileName         = _startServersPath,
                        CreateNoWindow   = true,
                        UseShellExecute  = true,
                        WorkingDirectory = _auraDir
                    }
                })
                {
                    p.Start();
                    p.WaitForExit();

                    t.PrintResult(p.ExitCode == 0);
                    return(p.ExitCode == 0);
                }
            }
        }
Beispiel #17
0
        bool UpdateGit(IRepository repo)
        {
            var recompileNeeded = true;

            using (var _ = new ChangingOutput("Updating source code . . ."))
            {
                _.FinishLine();

                // Update origin URL and re-initialize repo
                var origin = repo.Network.Remotes["origin"];
                if (origin.Url != _gitClonePath)
                {
                    repo.Network.Remotes.Update(origin, r => r.Url = _gitClonePath);
                }

                using (var t = new ChangingOutput("Fetching updates from remote . . ."))
                {
                    repo.Fetch("origin", new FetchOptions()
                    {
                        OnTransferProgress = (x) =>
                        {
                            t.PrintProgress((double)x.ReceivedObjects / x.TotalObjects);
                            return(true);
                        }
                    });

                    t.PrintResult(true);
                }

                var         currentCommit = repo.Head.Tip;
                MergeResult result;
                try
                {
                    using (var t = new ChangingOutput("Merging in updates . . ."))
                    {
                        result = repo.Merge(repo.Branches["origin/master"], new Signature(Environment.UserName, "*****@*****.**", DateTime.Now),
                                            new MergeOptions
                        {
                            CommitOnSuccess      = true,
                            FileConflictStrategy = CheckoutFileConflictStrategy.Ours,
                            MergeFileFavor       = MergeFileFavor.Normal,
                            OnCheckoutProgress   = (n, processed, total) =>
                            {
                                t.PrintProgress((double)processed / total);
                            },
                        });

                        t.PrintResult(result.Status != MergeStatus.Conflicts);
                    }

                    if (result.Status == MergeStatus.UpToDate)
                    {
                        Console.WriteLine("Source was already up to date");
                        recompileNeeded = RestoreDeleteFiles(repo);
                        _.PrintResult(true);
                    }
                    else if (result.Status == MergeStatus.Conflicts)
                    {
                        throw new MergeConflictException();
                    }
                    else
                    {
                        Console.WriteLine("Updated to {0} : {1}", result.Commit.Sha.Substring(0, 10), result.Commit.MessageShort);
                        _.PrintResult(true);
                    }
                }
                catch (MergeConflictException)
                {
                    Console.WriteLine("Merge resulted in conflicts. This usually indictates a user-edited source");
                    Console.WriteLine("Your Aura will NOT be updated until you undo your changes to the files.");
                    Console.WriteLine("This is a bad thing, so fix it ASAP.");
                    Console.WriteLine("NOTE: If you're trying to make configuration changes, use the \"user\" folders instead.");
                    Console.WriteLine("Rolling back merge...");
                    repo.Reset(currentCommit);
                    recompileNeeded = false;
                    _.PrintResult(false);
                }

                return(recompileNeeded);
            }
        }
Beispiel #18
0
        static void KillMysql()
        {
            var mysqls = Process.GetProcessesByName("mysqld_z");

            if (mysqls.Length != 0)
            {
                using (var _ = new ChangingOutput("Termininating existing MySql servers . . ."))
                {
                    _.FinishLine();

                    var success = true;

                    foreach (var p in mysqls)
                    {
                        using (var t = new ChangingOutput("Terminating process {0} . . .", p.Id))
                        {
                            p.Kill();
                            var killed = p.WaitForExit(10 * 1000);
                            t.PrintResult(killed);

                            if (!killed)
                                success = false;
                        }
                    }

                    _.PrintResult(success);
                }
            }
        }
Beispiel #19
0
        Process StartMySql()
        {
            var p = new Process
            {
                StartInfo =
                {
                    FileName = _mySqlDPath,
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    WorkingDirectory = _mySqlDir
                }
            };

            using (var t = new ChangingOutput("Starting MySql server . . ."))
            {
                var success = p.Start();

                t.PrintResult(success);

                if (!success)
                    p = null;
            }

            using (var _ = new ChangingOutput("Waiting for MySql to accept connections . . ."))
            {
                var i = 0;
                var timer = new Timer(1000);

                timer.Elapsed += (e, o) =>
                {
                    _.PrintNumber(i++);
                };

                timer.Start();

                while (!CheckMysqlPort())
                    Thread.Sleep(1000);

                timer.Stop();

                _.PrintResult(true);
            }

            return p;
        }
Beispiel #20
0
        bool UpdateGit(IRepository repo)
        {
            var recompileNeeded = true;
            using (var _ = new ChangingOutput("Updating source code . . ."))
            {
                _.FinishLine();

                using (var t = new ChangingOutput("Fetching updates from GitHub . . ."))
                {
                    repo.Fetch("origin", new FetchOptions()
                    {
                        OnTransferProgress = (x) =>
                        {
                            t.PrintProgress((double) x.ReceivedObjects/x.TotalObjects);
                            return true;
                        }
                    });

                    t.PrintResult(true);
                }

                var currentCommit = repo.Head.Tip;
                MergeResult result;
                try
                {
                    using (var t = new ChangingOutput("Merging in updates . . ."))
                    {
                        result = repo.Merge(repo.Head.TrackedBranch, new Signature(Environment.UserName, "*****@*****.**", DateTime.Now),
                            new MergeOptions
                            {
                                CommitOnSuccess = true,
                                FileConflictStrategy = CheckoutFileConflictStrategy.Ours,
                                MergeFileFavor = MergeFileFavor.Normal,
                                OnCheckoutProgress = (n, processed, total) =>
                                {
                                    t.PrintProgress((double) processed/total);
                                },
                            });

                        t.PrintResult(result.Status != MergeStatus.Conflicts);

                    }

                    if (result.Status == MergeStatus.UpToDate)
                    {
                        Console.WriteLine("Source was already up to date");
                        recompileNeeded = RestoreDeleteFiles(repo);
                        _.PrintResult(true);
                    }
                    else if (result.Status == MergeStatus.Conflicts)
                    {
                        throw new MergeConflictException();
                    }
                    else
                    {
                        Console.WriteLine("Updated to {0} : {1}", result.Commit.Sha.Substring(0, 10), result.Commit.MessageShort);
                        _.PrintResult(true);
                    }
                }
                catch (MergeConflictException)
                {
                    Console.WriteLine("Merge resulted in conflicts. This usually indictates a user-edited source");
                    Console.WriteLine("Your Aura will NOT be updated until you undo your changes to the files.");
                    Console.WriteLine("This is a bad thing, so fix it ASAP.");
                    Console.WriteLine("NOTE: If you're trying to make configuration changes, use the \"user\" folders instead.");
                    Console.WriteLine("Rolling back merge...");
                    repo.Reset(currentCommit);
                    recompileNeeded = false;
                    _.PrintResult(false);
                }

                return recompileNeeded;
            }
        }