Beispiel #1
0
        //Installation take cares for some other situation.
        private Task <string> RemoteServiceInstall(string host)
        {
            //Be caution with the space in between the = and value, they are mandatory.
            var args = string.Format(@"create {0} binPath= ""{1}"" DisplayName= ""Gamma Agent"" start= auto", ServiceName, Path.Combine(Target_location, ServiceBinName));

            var t = Task.Run(() =>
            {
                var status = GammaUtility.ShellExecutor("sc.exe", string.Format(@"\\{0} query {1}", host, ServiceName));
                if (status.Contains("STATE"))
                {
                    return("Serivce already exist!");
                }
                else
                {
                    return(GammaUtility.ShellExecutor("sc.exe", string.Format(@"\\{0} {1}", host, args)));
                }
            });

            t.GetAwaiter().OnCompleted(() =>
            {
                OnOpCompleted(new OpResultArgs()
                {
                    OpResult = t.Result, Hostname = host, OpType = "service setup"
                });
            });

            return(t);
        }
Beispiel #2
0
        public static string NetUse(string hostname, string domain, string username, string password, char drive = 'c')
        {
            var net_path    = string.Format(@"\\{0}\{1}$", hostname, drive);
            var domain_user = string.Format(@"{0}\{1}", domain, username);

            return(GammaUtility.ShellExecutor("net.exe", string.Format(@"use {0} {1} /USER:{2}", net_path, password, domain_user)));
        }
Beispiel #3
0
        //Use for start/stop/query
        private Task <string> SvcMgrShellExecuteAsyncPrototype(string host, string args, Action <OpResultArgs> result_callback, string op_type, bool callback = true)
        {
            var t = Task.Run(() =>
            {
                return(GammaUtility.ShellExecutor(@"sc.exe", String.Format(@"\\{0} {1}", host, args)));
            });

            if (callback)
            {
                t.GetAwaiter().OnCompleted(() =>
                {
                    result_callback(new OpResultArgs()
                    {
                        OpResult = t.Result, Hostname = host, OpType = op_type
                    });
                });
            }
            return(t);
        }
Beispiel #4
0
        public void UninstallMc()
        {
            try
            {
                if (uninstall[enterprise] != null)
                {
                    string[] s = uninstall[enterprise].Split(' ');
                    GammaUtility.ShellExecutor(s[0], s[1]);
                }

                if (uninstall[agent] != null)
                {
                    GammaUtility.ShellExecutor(agent_uninstall_exe, agent_uninstall_argument);
                }
            }
            catch (Exception ex)
            {
                //todo
            }
        }
Beispiel #5
0
        public static string RemoteCopyFiles(string hostname, string source, string target)
        {
            string source_fixed;
            string target_fixed;

            //XCopy directory does not allow the path ends with slash.
            if (source.EndsWith(@"\"))
            {
                source_fixed = source.Substring(0, source.Length - 1);
            }
            else
            {
                source_fixed = source;
            }
            if (target.EndsWith(@"\"))
            {
                target_fixed = target.Substring(0, target.Length - 1);
            }
            else
            {
                target_fixed = target;
            }
            return(GammaUtility.ShellExecutor(@"C:\windows\system32\xcopy.exe", string.Format(@"/E /I /Y /V ""{0}"" ""{1}""", source_fixed, ConvertPathToNetPath(hostname, target_fixed)), @"C:\Windows\System32"));
        }
Beispiel #6
0
        private async Task <string> InstallSingleNode(string host, bool callback = true)
        {
            //Pre-req. Setup net use
            VerifyNodes();
            var status = await RemoteServiceQuery(host, false);

            string rs = string.Empty;

            //Pre-req. Clean service
            if (status.Contains("STATE"))
            {
                if (!status.Contains("STOPPED"))
                {
                    rs = await RemoteServiceStop(host);

                    if (rs.Contains("error"))
                    {
                        return(rs);
                    }
                }
                rs = await RemoteServiceDelete(host);

                if (rs.Contains("error"))
                {
                    return(rs);
                }
            }

            //Step1. Copy file
            if (!host.ToLower().Contains(localhost.Trim().ToLower()))
            {
                rs = await RemoteCopyBinaries(host);

                if (rs.Contains("error"))
                {
                    OnOpCompleted(new OpResultArgs()
                    {
                        OpResult = rs, Hostname = host, OpType = "remote copy file"
                    });
                    return(rs);
                }
            }
            else
            {
                //local node copy file
                if (!Source_location.Trim().ToLower().Equals(Target_location.Trim().ToLower()))
                {
                    rs = GammaUtility.ShellExecutor(@"xcopy.exe", String.Format(@"/I /Y /E /V ""{0}"" ""{1}"" ", Source_location, Target_location));
                    if (rs.Contains("error"))
                    {
                        OnOpCompleted(new OpResultArgs()
                        {
                            OpResult = rs, Hostname = host, OpType = "local copy file"
                        });
                        return(rs);
                    }
                }
            }

            //Step2. Install service
            rs = await RemoteServiceInstall(host);

            if (rs.Contains("error"))
            {
                return(rs);
            }
            //Step extra, hook to do something else  before starting
            if (HasExtraTask())
            {
                ExtraTask(host);
            }
            //Step4. Start service
            rs = await RemoteServiceStart(host);

            if (rs.Contains("error"))
            {
                return(rs);
            }
            await Task.Delay(TimeSpan.FromSeconds(1));

            //Step5. Query service
            rs = await RemoteServiceQuery(host);

            return(rs);
        }