Exemple #1
0
 public virtual ITaskInfo Handle(string serverCode, ITaskInfo taskInfo)
 {
     try
     {
         IServerInfo s = ServerManager.Get(serverCode);
         if (s.ServerStatus == ServerStatus.Active)
         {
             if (s.TaskBeginHandler != null)
             {
                 s.TaskBeginHandler(serverCode, taskInfo);
             }
             if (s.TaskHandler != null)
             {
                 s.TaskHandler(serverCode, taskInfo);
             }
             if (s.TaskEndHandler != null)
             {
                 s.TaskEndHandler(serverCode, taskInfo);
             }
         }
     }
     catch (Exception ex)
     {
         taskInfo.TaskRemark  = ex.Message + "|" + ex.Source + "|" + ex.StackTrace;
         taskInfo.TaskProcess = TaskProcess.Completed;
         taskInfo.TaskStatus  = TaskStatus.Failed;
     }
     return(taskInfo);
 }
Exemple #2
0
        public override ITaskInfo Handle(string serverCode, ITaskInfo taskInfo)
        {
            try
            {
                LogMessageTaskInfo log = taskInfo as LogMessageTaskInfo;
                IServerInfo        s   = ServerManager.Get(serverCode);

                if (log != null && s != null && s.ServerStatus == ServerStatus.Active)
                {
                    if (s.TaskBeginHandler != null)
                    {
                        s.TaskBeginHandler(serverCode, taskInfo);
                    }
                    if (s.TaskHandler != null)
                    {
                        s.TaskHandler(serverCode, taskInfo);
                    }
                    else
                    {
                        MsmqLogger logger = MsmqLogger.GetInstance();
                        if (log.IsList)
                        {
                            List <LogMessage> ls = log.CurrLogMessageList;
                            foreach (LogMessage logMessage in ls)
                            {
                                logger.SendMessage(logMessage);
                            }
                            taskInfo.TaskProcess = TaskProcess.Completed;
                            taskInfo.TaskStatus  = TaskStatus.Success;
                        }
                        else
                        {
                            LogMessage lm = log.CurrLogMessage;
                            logger.SendMessage(lm);
                            taskInfo.TaskProcess = TaskProcess.Completed;
                            taskInfo.TaskStatus  = TaskStatus.Success;
                        }
                    }
                    if (s.TaskEndHandler != null)
                    {
                        s.TaskEndHandler(serverCode, taskInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                taskInfo.TaskRemark  = ex.Message + "|" + ex.Source + "|" + ex.StackTrace;
                taskInfo.TaskProcess = TaskProcess.Completed;
                taskInfo.TaskStatus  = TaskStatus.Failed;
            }
            return(taskInfo);
        }
Exemple #3
0
        public override ITaskInfo Handle(string serverCode, ITaskInfo taskInfo)
        {
            GetFileTransTaskInfo task = taskInfo as GetFileTransTaskInfo;

            try
            {
                string[] res = Directory.GetFiles(@"D:\APP\JinRi.App.Server\", "*.txt");
                task.AllFiles = string.Join("|", res);
            }
            catch (Exception)
            {
            }

            IServerInfo serverInfo = ServerManager.Get(serverCode);

            try
            {
                if (serverInfo.TaskBeginHandler != null)
                {
                    serverInfo.TaskBeginHandler(serverCode, taskInfo);
                }
                if (serverInfo.TaskHandler != null)
                {
                    serverInfo.TaskHandler(serverCode, taskInfo);
                }
                else
                {
                    if (task.TransProcess == FileTransProcess.TransDatas)
                    {
                        string filename = task.Filename;
                        if (File.Exists(filename))
                        {
                            using (FileStream stream = new FileStream(filename, FileMode.Open))
                            {
                                task.FileLength = (int)stream.Length;

                                task.ReadedBytes = Math.Min(task.FileLength - task.StartPos, task.ReadedBytes);

                                if (task.ReadedBytes > 0)
                                {
                                    stream.Position  = task.StartPos;
                                    task.Data        = new byte[task.ReadedBytes];
                                    task.ReadedBytes = stream.Read(task.Data, 0, task.ReadedBytes);
                                    stream.Close();
                                }
                                else
                                {
                                    task.ReadedBytes = 0;
                                }
                            }
                        }
                        else
                        {
                            task.ReadedBytes = 0;
                        }

                        task.TaskStatus       = TaskStatus.Success;
                        task.EmitServerCode   = serverInfo.ServerCode;
                        task.TransProcess     = FileTransProcess.TransDatas;
                        task.TaskCompleteTime = DateTime.Now;
                    }
                }
                if (serverInfo.TaskEndHandler != null)
                {
                    serverInfo.TaskEndHandler(serverCode, taskInfo);
                }
            }
            catch (Exception ex)
            {
                task.TaskRemark = ex.Message + "|" + ex.Source + "|" + ex.StackTrace;
                task.TaskStatus = TaskStatus.Failed;
            }

            return(task);
        }
Exemple #4
0
        public override ITaskInfo Handle(string serverCode, ITaskInfo taskInfo)
        {
            FileTransTaskInfo task       = taskInfo as FileTransTaskInfo;
            IServerInfo       serverInfo = ServerManager.Get(serverCode);

            try
            {
                if (serverInfo.TaskBeginHandler != null)
                {
                    serverInfo.TaskBeginHandler(serverCode, taskInfo);
                }
                if (serverInfo.TaskHandler != null)
                {
                    serverInfo.TaskHandler(serverCode, taskInfo);
                }
                else
                {
                    if (task.TransProcess == FileTransProcess.TransDatas)
                    {
                        ITaskInfo newTask = null;
                        if (serverInfo.IsDistributionServer)
                        {
                            newTask = (ITaskInfo)taskInfo.Clone();
                        }
                        if (task.Data != null && task.Data.Length > 0)
                        {
                            string     filename = task.SaveFilename;
                            FileStream fs       = null;
                            if (!File.Exists(filename))
                            {
                                fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
                            }
                            else
                            {
                                fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
                            }
                            task.TaskStartTime = DateTime.Now;
                            fs.Write(task.Data, 0, task.Data.Length);
                            fs.Close();
                            task.TaskStatus = TaskStatus.Success;

                            if (serverInfo.IsDistributionServer)
                            {
                                Console.WriteLine("开始分发数据");
                                object[] objArr = new object[] { serverCode, newTask };
                                ThreadPool.QueueUserWorkItem(new WaitCallback(TaskDistribution), objArr);
                            }
                            task.EmitServerCode   = serverInfo.ServerCode;
                            task.TransProcess     = FileTransProcess.TransDatas;
                            task.Data             = null;
                            task.TaskCompleteTime = DateTime.Now;
                        }
                    }
                }
                if (serverInfo.TaskEndHandler != null)
                {
                    serverInfo.TaskEndHandler(serverCode, taskInfo);
                }
            }
            catch (Exception ex)
            {
                task.TaskRemark = ex.Message + "|" + ex.Source + "|" + ex.StackTrace;
                task.TaskStatus = TaskStatus.Failed;
            }

            return(task);
        }