예제 #1
0
        public override void Excute()
        {
            try
            {
                uri = new Uri(Source);
                Client = new WebClient();
                Client.DownloadDataAsync(uri);
                Client.DownloadDataCompleted += OnDownloadComplete;
                Client.DownloadProgressChanged += OnDownloadProgressChange;

                ExcutionResult excutionresult = new ExcutionResult();
                excutionresult.ResultDetail = String.Format("Start download \"{0}\".",Source);
                CallProcess(excutionresult);
            }
            catch (WebException e)
            {
                CallProcess(new ExcutionResult(ResultFlag.Error, e.ToString(), ""));
                DownloadCmdList.Remove(this);
            }
            catch (UriFormatException e)
            {
                CallProcess(new ExcutionResult(ResultFlag.Error, "Invalid URL", ""));
                DownloadCmdList.Remove(this);
            }
        }
예제 #2
0
        public override void Excute()
        {
            string mode = Word[0].ToString().ToLower();
            StreamReader sr = new StreamReader(@".\DB\" + mode + ".txt",Encoding.GetEncoding("windows-874"));
            string txt = "";
            string result = "";
            string result2 = "";
            while (!sr.EndOfStream)
            {
                txt = sr.ReadLine();
                string[] txt2 = txt.Trim().Split('\t');
                if (txt2[0] == Word)
                {
                    result += txt + "\r\n";
                }
            }
            result2 = result.Replace(Word, "");
            sr.Close();

            ExcutionResult excutionresult = new ExcutionResult();
            if (result != "")
            {
                excutionresult.ResultDetail = Word + result2 ;

            }
            else
            {
                excutionresult.ResultDetail = "not found!";

            }
            CallProcess(excutionresult);
        }
예제 #3
0
파일: SysCommand.cs 프로젝트: charuwat/code
        public override void Excute()
        {
            //throw new NotImplementedException();
            ExcutionResult excutionresult=new ExcutionResult();
            switch (DoAction)
            {
                case SysAction.LogOff:
                    excutionresult.ResultDetail = "Logging off...";
                    CallProcess(excutionresult);
                    System.Diagnostics.Process.Start("shutdown", "-f -l -t 30 -c \"Log Off\""); ;

                    break;
                case SysAction.Reboot:
                    excutionresult.ResultDetail = "Restarting...";
                    CallProcess(excutionresult);
                    System.Diagnostics.Process.Start("shutdown", "-f -r -t 30 -c \"Restart by eXsistant\""); ;

                    break;
                case SysAction.Shutdown:
                    excutionresult.ResultDetail = "Shutting down...";
                    CallProcess(excutionresult);
                    System.Diagnostics.Process.Start("shutdown", "-f -s -t 30 -c \"Shutdown by eXsistant\""); ;

                    break;
            }
               // return ecr;
        }
예제 #4
0
 public void OnNotify(ExcutionResult excutionresult)
 {
     string MSG="";
     if (excutionresult.Flag==ResultFlag.Error)
     {
         MSG = "[Error]\r\n" + excutionresult.ErrorDetail;
         LogEvent.LogMessage(MSG);
         chatsession.SendMessage(MSG);
         return;
     }
     else if (excutionresult.Flag==ResultFlag.Result)
     {
         MSG = "[Result]\r\n" + excutionresult.ResultDetail;
         LogEvent.LogMessage(MSG);
         chatsession.SendMessage(MSG);
     }
     else if (excutionresult.Flag == ResultFlag.Info)
     {
         MSG = "[Info]\r\n" + excutionresult.ResultDetail;
         LogEvent.LogMessage(MSG);
         chatsession.SendMessage(MSG);
     }
 }
예제 #5
0
        /*public void Process(string CommandString)
        {

            LastCommand = CommandString;
            bool ValidCommand = true;

            CommandString = CommandString.ToLower();
            CommandString = CommandString.Trim();
            while(CommandString.IndexOf("  ")>=0)
                CommandString = CommandString.Replace("  ", " ");

            string[] Comm = CommandString.Split(' ');
            string parameter = CommandString.Substring(CommandString.IndexOf(' ')+1);
            ExcutionResult excutionresult=new ExcutionResult();
            try
            {
                switch (Comm[0])
                {
                    case "shutdown": syscmd.SetAction(SysAction.Shutdown);
                        new Thread(new ThreadStart(syscmd.Excute)).Start();
                        syscmd.Excute();
                        break;

                    case "reboot": syscmd.SetAction(SysAction.Reboot);
                        new Thread(new ThreadStart(syscmd.Excute)).Start();
                        break;

                    case "logoff": syscmd.SetAction(SysAction.LogOff);
                        new Thread(new ThreadStart(syscmd.Excute)).Start();
                        break;

                    case "dict": dictcmd.SetWord(parameter);
                        new Thread(new ThreadStart(dictcmd.Excute)).Start();
                        break;

                    case "sendme":
                        string filename = GetDefaultPath() + Comm[1];
                        if (File.Exists(filename))
                        {
                            msn.SendFile(chatsession.GetRemoteMail(), filename);
                        }
                        else
                        {
                            OnNotify(new ExcutionResult(ResultFlag.Error, "Invalid filename.", ""));
                        }
                        break;
                    case "download":
                        downloadcmd = new DownloadCommand(OnNotify);
                        downloadcmd.SetPath(Comm[1], GetDefaultPath() + Comm[2]);
                        new Thread(new ThreadStart(downloadcmd.Excute)).Start();
                        break;

                    case "status":
                        listdownloadcmd.Excute();
                        break;

                    case "oilprice":
                        oilpricecmd.Excute();
                        break;

                    case "task":
                        new Thread(new ThreadStart( taskcmd.Excute)).Start();
                        break ;

                    case "appointment":
                        new Thread(new ThreadStart(calendarcmd.Excute)).Start();
                        break;

                    default:
                        excutionresult = new ExcutionResult(ResultFlag.Error, "Invalid command", "");
                        break;
                }
            }
            catch (IndexOutOfRangeException e)
            {
                excutionresult = new ExcutionResult(ResultFlag.Error, "Invalid numbers of argument.", "");
            }
            ////////// Notify to Core /////
           if(excutionresult.Flag==ResultFlag.Error)
                OnNotify(excutionresult);*/
        public void Process(string CommandString)
        {
            string parameter="";
            LastCommand = CommandString;
            bool ValidCommand = true;

            CommandString = CommandString.ToLower();
            CommandString = CommandString.Trim();
            while(CommandString.IndexOf("  ")>=0)
                CommandString = CommandString.Replace("  ", " ");

            string[] Comm = CommandString.Split(' ');
            if (CommandString.IndexOf(' ') > 0)
            {
                parameter = CommandString.Substring(CommandString.IndexOf(' ') + 1);
            }

            ExcutionResult excutionresult=new ExcutionResult();
            try
            {
                switch (Comm[0])
                {
                    case "shutdown": syscmd.SetAction(SysAction.Shutdown);
                        new Thread(new ThreadStart(syscmd.Excute)).Start();
                        syscmd.Excute();
                        break;

                    case "reboot": syscmd.SetAction(SysAction.Reboot);
                        new Thread(new ThreadStart(syscmd.Excute)).Start();
                        break;

                    case "logoff": syscmd.SetAction(SysAction.LogOff);
                        new Thread(new ThreadStart(syscmd.Excute)).Start();
                        break;

                    case "dict": dictcmd.SetWord(parameter);
                        new Thread(new ThreadStart(dictcmd.Excute)).Start();
                        break;

                    case "sendme":
                        string filename = GetDefaultPath() + Comm[1];
                        if (File.Exists(filename))
                        {
                            msn.SendFile(chatsession.GetRemoteMail(), filename);
                        }
                        else
                        {
                            OnNotify(new ExcutionResult(ResultFlag.Error, "Invalid filename.", ""));
                        }
                        break;
                    case "download":
                        downloadcmd = new DownloadCommand(OnNotify);
                        downloadcmd.SetPath(Comm[1], GetDefaultPath() + "\\" + Comm[2]);
                        new Thread(new ThreadStart(downloadcmd.Excute)).Start();
                        break;

                    case "status":
                        listdownloadcmd.Excute();
                        break;

                    case "oilprice":
                        oilpricecmd.Excute();
                        break;

                    case "task":
                        new Thread(new ThreadStart( taskcmd.Excute)).Start();
                        break ;

                    case "appointment":
                        new Thread(new ThreadStart(calendarcmd.Excute)).Start();
                        break;

                    case "dir":
                        dircmd.SetParameter(parameter);
                        new Thread(new ThreadStart(dircmd.Excute)).Start();
                        break;

                    default:
                        excutionresult = new ExcutionResult(ResultFlag.Error, "Invalid command", "");
                        break;
                }
            }
            catch (IndexOutOfRangeException e)
            {
                excutionresult = new ExcutionResult(ResultFlag.Error, "Invalid numbers of argument", "");
            }
            ////////// Notify to Core /////
               if(excutionresult.Flag==ResultFlag.Error)
                OnNotify(excutionresult);
        }