Пример #1
0
        /// <summary>
        /// Alienbrain base constructor.
        /// </summary>
        /// <param name="Data">renbar memory database object instance.</param>
        /// <param name="Log">renbar log record object instance.</param>
        /// <param name="Info">alienbrain properties information.</param>
        public AlienbrainBase(DataStructure Data, Log LogObj, AlienbrainInfo Info)
        {
            // assign relationship object ..
            this.EnvData = Data;
            this.EnvLog  = LogObj;

            // create alienbrain project list ..
            this.ProjectList = new List <string>();

            // create alienbrain work data ..
            WorkData = new DataTable("ABWorkData");
            WorkData.Columns.Add(new DataColumn("Id", typeof(string)));
            WorkData.Columns.Add(new DataColumn("Name", typeof(string)));
            WorkData.Columns.Add(new DataColumn("Path", typeof(string)));
            WorkData.Columns.Add(new DataColumn("IsUpdateOnly", typeof(bool)));
            WorkData.Columns.Add(new DataColumn("Priority", typeof(int)));

            // set primary key ..
            WorkData.PrimaryKey = new DataColumn[] { WorkData.Columns[0] };

            //
            Thread abWork_Thread = new Thread(new ParameterizedThreadStart(this.DoWork));

            abWork_Thread.Priority     = ThreadPriority.BelowNormal;
            abWork_Thread.IsBackground = true;
            abWork_Thread.Start(Info);
        }
Пример #2
0
        /// <summary>
        /// Server base constructor.
        /// </summary>
        public ServerBase()
        {
            // view change settings ..
            this.ViewChangeSettings();

            // 構造AlienbrainInfo用戶實體(用戶名、密碼、服務器名、工作路徑) initialize alienbrain extension structure ..
            AlienbrainInfo AbInfo = new AlienbrainInfo()
            {
                User     = this.__AbUser,
                Password = this.__AbPass,
                Server   = this.__AbServer,
                WorkPath = this.__AbWorkPath
            };

            //  獲取數據庫(鏈接字符串)結構及數據 initialize relationship object instance ..
            this.EnvData = new DataStructure(ConnectionString);

            // 通過用戶實體驗證,根據數據調用Alienbrain.SDK的API去GetLaste檔案,並更改任務狀態標識到數據庫
            this.AbBase = new AlienbrainBase(this.EnvData, this.EnvLog, AbInfo);

            // 過期數據清理
            this.__Cleanup = new Cleanup(this.EnvData, this.EnvLog);

            //構建新的緩存數據,接收客戶端更新,再刷新EnvData中數據
            this.ShowBase = new DisplayBase(this.EnvData, this.EnvLog);

            ////監聽客戶端
            //this.PortalBase = new ProtocolBase(this.EnvData, this.EnvLog)
            //{
            //    ConnectPort = this.__ListenRenderPort,
            //    ListenPort = this.__ListenClientPort,
            //    MaxHistory = this.__JobHistoryMaxRecord,
            //};

            //////操作Render
            //this.OperationBase = new RenderBase(this.EnvData, this.EnvLog)
            //{
            //    ConnectPort = this.__ListenRenderPort
            //};

            Thread SlaveThreading = new Thread(new ThreadStart(SlaveThread));

            SlaveThreading.IsBackground = true;
            SlaveThreading.Priority     = ThreadPriority.Normal;
            SlaveThreading.Start();
        }
Пример #3
0
        /// <summary>
        /// Dowork background thread method.
        /// </summary>
        /// <param name="parameters">alienbrain properties parameter.</param>
        private void DoWork(object parameters)
        {
            do
            {
                try
                {
                    // declare filter conditions ..//CHECKING = 3,
                    string expression1 = string.Format("Status = '{0}'", Convert.ToUInt16(JobStatusFlag.CHECKING));

                    // find update status jobs ...從Job_Group中篩選Checking的Unchanged數據
                    DataTable
                        primary_view = this.EnvData.FindData("Job_Group", expression1, string.Empty, DataViewRowState.Unchanged).ToTable();

                    foreach (DataRow row in primary_view.Rows)
                    {
                        string expression2 = string.Format("Job_Group_Id = '{0}'", row["Job_Group_Id"]);

                        // find high priority jobs ...從Job_Attr中篩選於上次篩選ID相同的數據
                        DataView second_view = this.EnvData.FindData("Job_Attr", expression2, "Priority Desc", DataViewRowState.Unchanged);

                        if (second_view.Count > 0)
                        {
                            if (!WorkData.Rows.Contains(row["Job_Group_Id"]))
                            {
                                DataRow _row = WorkData.NewRow();
                                _row["Id"]           = row["Job_Group_Id"];
                                _row["Name"]         = second_view[0]["ABName"];
                                _row["Path"]         = second_view[0]["ABPath"];
                                _row["IsUpdateOnly"] = Convert.ToBoolean(second_view[0]["ABUpdateOnly"]);
                                _row["Priority"]     = second_view[0]["Priority"];
                                WorkData.Rows.Add(_row);
                            }
                        }
                    }

                    // add to alienbrain work list ..
                    foreach (DataRow row in WorkData.AsEnumerable().OrderByDescending(pri => pri.Field <int>("Priority")))//按Priority降序
                    {
                        // analysis connect object ..
                        AlienbrainInfo info = (AlienbrainInfo)parameters;

                        // confirm the project whether exist in project list ..
                        if (!this.ProjectList.Contains(row["Name"].ToString()))
                        {
                            this.ProjectList.Add(row["Name"].ToString());

                            // login project ..
                            AbLib.Instance.Login(info.Server, row["Name"].ToString(), info.User, info.Password);

                            // set working path ..
                            AbLib.Instance.SetWorkingPath(string.Format(@"{0}\{1}", info.WorkPath, row["Name"].ToString()));
                        }

                        // dependency and get latest ..
                        this.GetLatest(row["Path"].ToString(), row["Id"].ToString());

                        // update status ..
                        string    exp        = string.Format("Job_Group_Id = '{0}'", row["Id"]);
                        DataRow[] memory_row = this.EnvData.ReadData("Job_Group").Select(exp);

                        if (memory_row.Length > 0)
                        {
                            if (Convert.ToBoolean(row["IsUpdateOnly"]))
                            {
                                memory_row[0]["Status"] = Convert.ToUInt16(JobStatusFlag.UPDATEONLY);
                            }
                            else
                            {
                                memory_row[0]["Status"] = Convert.ToUInt16(JobStatusFlag.QUEUING);
                            }

                            // sync data to database ..
                            this.SyncData(memory_row[0]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string ExceptionMsg = ex.Message + ex.StackTrace;

                    // write to log file ..
                    EnvLog.Writer(AssemblyInfoClass.ProductInfo, Log.Level.Error, ExceptionMsg, true);
                }
                finally
                {
                    if (WorkData.Rows.Count > 0)
                    {
                        WorkData.Rows.Clear();
                    }
                }

                Thread.Sleep(5000);
            } while (!requestStop);
        }