Ejemplo n.º 1
0
 public void SetUp(ITCTask task)
 {
     _ipAddr    = task.ipAddr;
     _username  = task.username;
     _password  = task.password;
     _filePath  = task.filePath;
     _terminals = task.terminals;
     _volume    = task.volume;
 }
Ejemplo n.º 2
0
 public static string Start(ITCTask task)
 {
     try
     {
         primaryTimer.Stop();
         currentTask = task;
         player      = new ITCPlayer();
         player.SetUp(task);
         player.MessageComing += player_MessageComing;
         player.Start();
         return("task status: " + task.output);
     }
     catch (Exception ex)
     {
         primaryTimer.Start();
         return("operation failed: " + ex.ToString());
     }
 }
Ejemplo n.º 3
0
 public static string AddTask(ITCTask task)
 {
     try
     {
         if (task != null)
         {
             AllTasks.Add(task);
         }
         else
         {
             return("operation failed: invalid task");
         }
         SaveToFile();
         return("operation complete: added task");
     }
     catch (Exception ex)
     {
         return("operation failed: " + ex.ToString());
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// giving file name only
 /// </summary>
 /// <param name="info">including file name</param>
 /// <returns></returns>
 public static ITCTask ToITCTask_ShortName(string info)
 {
     try
     {
         ITCTask tmp = new ITCTask();
         tmp.taskName = info.Split('|')[0];
         tmp.isEnabled = Convert.ToBoolean(info.Split('|')[1]);
         tmp.ipAddr = info.Split('|')[2];
         tmp.username = info.Split('|')[3];
         tmp.password = info.Split('|')[4];
         tmp.filePath = ServiceLayer.AppPath + info.Split('|')[5];
         tmp.terminals = info.Split('|')[6];
         tmp.volume = Convert.ToByte(info.Split('|')[7]);
         tmp.schedule = Convert.ToDateTime(info.Split('|')[8]);
         return tmp;
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 5
0
 public static string LoadFromFile()
 {
     try
     {
         using (FileStream fs = new FileStream(Program.StartupPath + "tasks.cst", FileMode.Open, FileAccess.Read))
         {
             AllTasks.Clear();
             StreamReader sr = new StreamReader(fs);
             while (!sr.EndOfStream)
             {
                 AllTasks.Add(ITCTask.ToITCTask_LongPath(SecurityCoder.Decrypt(sr.ReadLine())));
             }
             sr.Close();
         }
         return("operation complete: loaded from file");
     }
     catch (Exception ex)
     {
         return("operation failed: " + ex.ToString());
     }
 }
Ejemplo n.º 6
0
 public static string Start(string taskName)
 {
     try
     {
         foreach (ITCTask task in AllTasks)
         {
             if (task.taskName == taskName)
             {
                 primaryTimer.Stop();
                 currentTask = task;
                 player      = new ITCPlayer();
                 player.SetUp(task);
                 player.MessageComing += player_MessageComing;
                 player.Start();
                 return("task status: " + task.output);
             }
         }
         return("operation failed: task not found");
     }
     catch (Exception ex)
     {
         return("operation failed: " + ex.ToString());
     }
 }
Ejemplo n.º 7
0
        private void ReceiveMessage(IAsyncResult ar)
        {
            int bytesRead;

            try
            {
                lock (_client.GetStream())
                {
                    bytesRead = _client.GetStream().EndRead(ar);
                }
                if (bytesRead < 1)
                {
                    AllClients.Remove(_clientIP);
                    return;
                }
                else
                {
                    string messageReceived = Encoding.UTF8.GetString(data, 0, bytesRead);
                    #region MessageHandler
                    try
                    {
                        if (messageReceived.StartsWith("recvfile|"))
                        {
                            string   fileName   = messageReceived.Split('|')[1];
                            long     totalBytes = Convert.ToInt64(messageReceived.Split('|')[2]);
                            DateTime startTime  = DateTime.Now;
                            SendMessage("begin to receive file|" + fileName + "|" + totalBytes.ToString());
                            ReceiveFile(fileName, totalBytes);
                            SendMessage("transfered " + totalBytes + " Bytes in " + DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString() + " milliseconds");
                        }
                        else if (messageReceived.StartsWith("addtask|"))
                        {
                            SendMessage(ServiceLayer.AddTask(ITCTask.ToITCTask_ShortName(messageReceived.Substring(8))));
                        }
                        else if (messageReceived.StartsWith("removetask|"))
                        {
                            SendMessage(ServiceLayer.RemoveTask(messageReceived.Split('|')[1]));
                        }
                        else if (messageReceived == "gettasks")
                        {
                            SendMessage(ServiceLayer.GetAllTasks());
                        }
                        else if (messageReceived.StartsWith("start|"))
                        {
                            SendMessage(ServiceLayer.Start(messageReceived.Split('|')[1]));
                            SendMessage(ServiceLayer.GetAllTasks());
                        }
                        else if (messageReceived == "stop")
                        {
                            SendMessage(ServiceLayer.Stop());
                            SendMessage(ServiceLayer.GetAllTasks());
                        }
                        else if (messageReceived == "savetasks")
                        {
                            SendMessage(ServiceLayer.SaveTasksToFile());
                        }
                        else if (messageReceived == "loadtasks")
                        {
                            SendMessage(ServiceLayer.LoadTasksFromFile());
                        }
                        else if (messageReceived == "cleartasks")
                        {
                            SendMessage(ServiceLayer.ClearTasks());
                        }
                        else if (messageReceived == "deltasksfile")
                        {
                            SendMessage(ServiceLayer.DeleteTasksFile());
                        }
                        else if (messageReceived == "enable autoboot")
                        {
                            SendMessage(SetAutoBootStatus(true));
                        }
                        else if (messageReceived == "disable autoboot")
                        {
                            SendMessage(SetAutoBootStatus(false));
                        }
                        else if (messageReceived == "delete mp3")
                        {
                            try
                            {
                                string[] allMusic = Directory.GetFiles(ServiceLayer.AppPath, "*.mp3");
                                foreach (string file in allMusic)
                                {
                                    FileInfo fi = new FileInfo(file);
                                    fi.Delete();
                                }
                                SendMessage("operation complete: all mp3 deleted");
                            }
                            catch (Exception ex)
                            {
                                SendMessage("operation failed: " + ex.ToString());
                            }
                        }
                        else if (messageReceived.StartsWith("cmd|"))
                        {
                            Process p = new Process();
                            p.StartInfo.FileName               = "cmd.exe";
                            p.StartInfo.UseShellExecute        = false;
                            p.StartInfo.RedirectStandardInput  = true;
                            p.StartInfo.RedirectStandardOutput = true;
                            p.StartInfo.CreateNoWindow         = true;
                            p.Start();
                            p.StandardInput.WriteLine(messageReceived.Split('|')[1]);
                            p.StandardInput.Flush();
                            p.StandardInput.WriteLine("exit");
                            p.StandardInput.Flush();
                            SendMessage("operation done: " + p.StandardOutput.ReadToEnd());
                        }
                        else if (messageReceived == "exit")
                        {
                            SendMessage("server stopped.");
                            Environment.Exit(0);
                        }
                        else if (messageReceived == "info")
                        {
                            SendMessage("Version: CastStation Server " + Application.ProductVersion + Environment.NewLine
                                        + "StartTime: " + ServiceLayer.startTime.ToString("g") + Environment.NewLine
                                        + "SysTime: " + DateTime.Now.ToString("g") + Environment.NewLine
                                        + "AppPath: " + Application.StartupPath + Environment.NewLine
                                        + Environment.NewLine
                                        + "   #####       ####   " + Environment.NewLine
                                        + "  #     #     #    #  " + Environment.NewLine
                                        + " #       #   ##     # " + Environment.NewLine
                                        + " #            ##      " + Environment.NewLine
                                        + " #             #####  " + Environment.NewLine
                                        + " #                 ## " + Environment.NewLine
                                        + " #       #   #      ##" + Environment.NewLine
                                        + "  #     #     #     # " + Environment.NewLine
                                        + "   #####       #####  ");
                        }
                        else
                        {
                            SendMessage("unknown command: " + messageReceived);
                        }
                    }
                    catch (Exception ex)
                    {
                        SendMessage("operation failed: " + ex.ToString());
                    }
                    #endregion
                }
                lock (_client.GetStream())
                {
                    _client.GetStream().BeginRead(data, 0, _client.ReceiveBufferSize, ReceiveMessage, null);
                }
            }
            catch
            {
                AllClients.Remove(_clientIP);
            }
        }