Пример #1
0
        public bool PutTask(DBTask task)
        {
            var ret = false;
            try
            {
                using (var stream = StreamConvert.ObjectToStream(task, false))
                {
                    var bytes = (stream as MemoryStream).GetBuffer();
                    var key = task.Sequence.ToString();
                    _DB.Put(key, bytes);
                    ret = true;
                }
            }
            catch (Exception e)
            {
                Show(string.Format("Save Task[{0}] Faild.",task.Sequence) + e.Message,DebugType.Both, LogLevels.Fatal);
                ret = false;
            }

            return ret;
        }
Пример #2
0
        private void ProcessTask(DBTask task)
        {
            var index = task.Sequence % _PendingLocker.Length;
            var locker = _PendingLocker[index];
            Monitor.Enter(locker);
            try
            {
                if (task.Stored)
                    _PendingLocker[index] = task;

                DataPool pool;
                if (_DBManager.TryGetValue(task.DataBase, out pool))
                {
                    retry:
                    try
                    {
                        pool.execSP(task.Procedure, task.Parameter);
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(1000);
                        goto retry;
                    }

                    Interlocked.Exchange(ref _ProcessedSequence, task.Sequence);
                    task.Excuted = true;
                    if (task.Stored)
                    {
                        Trunk.TaskStorage.DelTask(task.Sequence);
                    }
                }
            }
            finally
            {
                Monitor.Exit(locker);
            }
        }
Пример #3
0
 private void InvokeData(DBTask data)
 {
     if (!data.Stored)
     {
         if (data.Sequence != _ProcessedSequence + 1)
         {
             for (int seq = _ProcessedSequence + 1; seq < data.Sequence; seq++)
             {
                 var find = Trunk.TaskStorage.GetTask(seq);
                 if (find != null)
                 {
                     ProcessTask(find);
                 }
             }
         }
         else
         {
             ProcessTask(data);
         }
     } else
     {
        ProcessTask(data);
     }
 }
Пример #4
0
        public bool Excute(string instance,string dataBase,
            string procedure,object[] parameter)
        {
            var add=new DBTask()
            {
                Instance = instance,
                DataBase   = dataBase,
                Procedure = procedure,
                Parameter = parameter,
                Excuted = false,
                Sequence = NextSeq
            };

            var ret = PushTask(add);
            if (!ret)
            {
                return Trunk.TaskStorage.PutTask(add);
            }
            return ret;
        }
Пример #5
0
        internal bool PushTask(DBTask add)
        {
            if (add == null)
                return false;

            var added = false;
            var index = add.Sequence % _PendingLocker.Length;
            var locker = _PendingLocker[index];

            if (Monitor.TryEnter(locker))
            {
                try
                {
                    var exist = _Pending[index];
                    if (exist != null)
                    {
                        if (!exist.Excuted)
                        {
                            _PendingLocker[index] = add;
                            added = true;
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(locker);
                }
            }

            if (added)
            {
                _ProcessThread.PushData(add);
            }
            else
            {
                Show(string.Format("Push Task[{0}] Faild.",add.Sequence),DebugType.Both,LogLevels.Error);
            }
            return added;
        }