Example #1
0
 public static Domain OpenDomainFile()
 {
     using (OpenFileDialog openFileDialog = new OpenFileDialog())
     {
         openFileDialog.Filter           = "解决方案文件|*.domain|所有文件|*.*";
         openFileDialog.RestoreDirectory = true;
         openFileDialog.FilterIndex      = 1;
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 IFormatter formatter = new SoapFormatter();
                 using (Stream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                 {
                     try
                     {
                         Domain d = (Domain)formatter.Deserialize(stream);
                         if (DomainManager.IsDomainExist(d.DomainGUID))
                         {
                             d.NewDomainGUID();
                         }
                         DomainManager.AddDomain(d);
                         return(d);
                     }
                     catch (SerializationException e)
                     {
                         log.Error("反序列化失败: " + openFileDialog.FileName + "不是解决方案文件!", e);
                         MessageBox.Show(openFileDialog.FileName + "不是解决方案文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                         return(null);
                     }
                     catch (Exception e)
                     {
                         log.Error("未知错误: " + openFileDialog.FileName, e);
                         MessageBox.Show(openFileDialog.FileName + "出现未知错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                         return(null);
                     }
                 }
             }
             catch (System.IO.FileNotFoundException e)
             {
                 log.Error("打开文件失败: " + openFileDialog.FileName, e);
                 MessageBox.Show("打开文件失败: " + openFileDialog.FileName, "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                 return(null);
             }
         }
         return(null);
     }
 }
Example #2
0
        /// <summary>
        /// 构造函数(输入站点domainGUID, 将自动从站点中抽取PreparationScript)
        /// </summary>
        public RemotePreparationVBAScriptTask(string domainGUID)
        {
            Domain d = DomainManager.GetDomain(domainGUID);

            if (d != null)
            {
                m_domainGUID    = d.DomainGUID;
                m_script        = d.PreparationScript;
                m_vbaobjs       = GetVBAObjectForNewTaskChain(d);
                m_taskchainGUID = Guid.NewGuid().ToString();
                m_timestamp     = GetTimeStamp();
            }
            else
            {
                throw new Exception("Invalid DomainGUID: " + domainGUID);
            }
        }
Example #3
0
        private void CheckAvailableClientTaskResourceThread()
        {
            lock (m_waitingclienttasks)
            {
                while (true)
                {
                    if (ServerControlManager.IsServerModeRemote)
                    {
                        while (
                            (ServerControlManager.IsServerModeRemote == true) &&
                            (
                                !m_enable ||
                                !DomainManager.IsHavingAvaibleDomain ||
                                m_taskmanager.CountOfAllTask + m_waitingclienttasks.Count >= m_MinimalAcceptableWaitingclienttask
                            )
                            )
                        {
                            Monitor.Wait(m_waitingclienttasks, 30000);
                        }
                    }
                    else
                    {
                        while (
                            (ServerControlManager.IsServerModeRemote == false) &&
                            (
                                !m_enable ||
                                !DomainManager.IsHavingAvaibleDomain ||
                                m_taskmanager.CountOfAllTask >= m_MinimalAcceptableWaitingclienttask
                            )
                            )
                        {
                            Monitor.Wait(m_waitingclienttasks, 3000);
                        }
                    }

                    DomainManager.TaskManagerAddTaskFromAvaibleDomains(m_taskmanager);
                }
            }
        }
        private void DownloadTasks()
        {
            BaseVBAScriptTask bt = null;

            if (m_WaitingLocalTasks.Count <= m_SingerTransportation)
            {
                log.Debug("Start Download...");
                List <IRemoteTask> ts = ConnectionManagerClient.TTMFeachTasks(m_SingerTransportation);
                if (ts != null && ts.Count > 0)
                {
                    foreach (IRemoteTask t in ts)
                    {
                        bt = t as BaseVBAScriptTask;
                        if (DomainManager.IsDomainNeedUpdated(bt.DomainGUID, bt.TimeStamp))
                        {
                            Domain d = GetDomainFromServer(bt.DomainGUID);
                            if (d != null)
                            {
                                DomainManager.AddDomain(d);
                                log.Debug("Fetching A Domain for " + t.Name);
                            }
                            else
                            {
                                log.Debug("Weird DomainGUID With No Domian IN SERVER!:" + bt.DomainGUID);
                            }
                        }
                        this.AddTask(t);
                        log.Debug("Fetching one " + t.Name);
                    }
                }
                else
                {
                    log.Debug("No avaible remotetask for downloading...");
                }
            }
        }
 protected override string GetScript()
 {
     return(DomainManager.GetDomain(this.DomainGUID).StorageScript);
 }
Example #6
0
 protected override string GetScript()
 {
     return(DomainManager.GetDomain(this.DomainGUID).PreparationScript);
 }
Example #7
0
        protected void ScriptThreadRunner()
        {
            //实现BeforeTask事件
            if (BeforeScript != null)
            {
                BeforeScript(this, null);
            }

            try
            {
                //Log开始
                GetLogger().LogListLog(VBALogLevelFlag.Debug, this.Name + " start...[running time: " + m_runningtime.ToString() + "] [at " + System.Net.Dns.GetHostName() + "]");

                //执行脚本,带空脚本处理
                if (m_script != null && m_script != "")
                {
                    m_engine.Run();
                }

                //关闭引擎
                EngineClose();

                //从VBATask中得到Task状态
                VBATaskStatus ts = (m_vbaobjs["Task"] as VBATask).CurrentVBATaskStatus;
                switch (ts)
                {
                case VBATaskStatus.Failure:
                    GetLogger().LogListLog(VBALogLevelFlag.Debug, this.Name + " fail...");
                    m_taskstatus = TaskStatus.Failure;
                    break;

                case VBATaskStatus.RestartADSL:
                    //重置ADSL(Client)
                    if (ADSLFactory.Reconnect())
                    {
                        GetLogger().LogListLog(VBALogLevelFlag.Debug, this.Name + " restart ADSL...succeed!");
                        m_taskstatus = TaskStatus.Restart;
                    }
                    else
                    {
                        GetLogger().LogListLog(VBALogLevelFlag.Debug, this.Name + " restarting ADSL failed... setting this task failure!");
                        m_taskstatus = TaskStatus.Failure;
                    }
                    break;

                case VBATaskStatus.Ready:
                    m_taskstatus = TaskStatus.Succeed;
                    GetLogger().LogListLog(VBALogLevelFlag.Debug, this.Name + " succeed...");
                    break;

                case VBATaskStatus.Error:
                    m_taskstatus = TaskStatus.Error;
                    GetLogger().LogListLog(VBALogLevelFlag.Error, this.Name + " set error by customer...");
                    break;

                case VBATaskStatus.Close:
                    m_taskstatus = TaskStatus.Succeed;
                    GetLogger().LogListLog(VBALogLevelFlag.Warn, this.Name + " close whole domain!");
                    Domain d = DomainManager.GetDomain(m_domainGUID);
                    if (d.Enable)
                    {
                        d.Enable = false;
                    }
                    break;

                case VBATaskStatus.TurnToNext:
                    m_taskstatus = TaskStatus.Succeed;
                    GetLogger().LogListLog(VBALogLevelFlag.Warn, this.Name + " close and turn to next domain!");
                    Domain dd = DomainManager.GetDomain(m_domainGUID);
                    if (dd.Enable || dd.Priority == DomainPriority.OneTime)
                    {
                        DomainManager.TurnToNextDomain(m_domainGUID);
                    }
                    break;

                default:
                    m_taskstatus = TaskStatus.Succeed;
                    GetLogger().LogListLog(VBALogLevelFlag.Debug, this.Name + " succeed...");
                    break;
                }
            }
            catch (Exception e)
            {
                if (m_IsClosing)
                {
                    log.Warn(this.Name + " closed by force...");
                    GetLogger().LogListLog(VBALogLevelFlag.Warn, this.Name + " closed...");
                    m_taskstatus = TaskStatus.Closing;
                }
                else
                {
                    GetLogger().LogListLog(VBALogLevelFlag.Error, this.Name + " runtime error..." + ParserErrorString(e));
                    log.Error(this.Name + " runtime error: ", e);
                    m_errortime++;
                    m_taskstatus = TaskStatus.Error;
                }
            }
            finally
            {
                //实现AfterTask事件
                if (AfterScript != null)
                {
                    AfterScript(this, null);
                }
            }
        }
Example #8
0
 /// <summary>
 ///重写该方法,得到时间戳
 /// </summary>
 protected virtual DateTime GetTimeStamp()
 {
     return(DomainManager.GetDomain(m_domainGUID).TimeStamp);
 }