Ejemplo n.º 1
0
        /// <summary>
        /// 启动定时任务
        /// </summary>
        internal DeployResultData Start()
        {
            if (IsCancel)
            {
                return(DeployState.Canceled);
            }
            ClientObject client = DeployInfo.Client;
            Log          log    = new Log {
                DeployIndex = DeployInfo.Index
            };
            bool isLog = true;

            try
            {
                AutoCSer.Net.TcpServer.ServerCallback <Log> onLog = client.OnLog ?? AutoCSer.Net.TcpServer.ServerCallback <Log> .Null.Default;
                byte[] data = null;
                while (TaskIndex != DeployInfo.Tasks.Length && !IsCancel)
                {
                    ClientTask.Task task = DeployInfo.Tasks.Array[TaskIndex];
                    log.Set(TaskIndex, task.Type);
                    isLog |= onLog.Callback(log);
                    DeployResultData state = task.Call(this);
                    log.Type = LogType.OnRun;
                    isLog   |= onLog.Callback(log);
                    if (state.State != DeployState.Success)
                    {
                        return(state);
                    }
                    if (state.Data != null)
                    {
                        data = state.Data;
                    }
                    ++TaskIndex;
                }
                return(new DeployResultData {
                    State = DeployState.Success, Data = data
                });
            }
            catch (Exception error)
            {
                Console.WriteLine(error.ToString());
                Error = error;
            }
            finally
            {
                //Server.Clear(ref Identity);
                if (Error == null)
                {
                    log.Type = LogType.Completed;
                }
                else
                {
                    AutoCSer.LogHelper.Exception(Error, null, LogLevel.Exception | LogLevel.AutoCSer);
                    log.Type = LogType.Error;
                }
                //if (!(isLog |= onLog(log))) Server.ClearClient(ref clientId);
            }
            return(DeployState.Exception);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 启动定时任务
        /// </summary>
        internal DeployState Start()
        {
            if (IsCancel)
            {
                return(DeployState.Canceled);
            }
            //IndexIdentity clientId = new IndexIdentity();
            ClientObject client = DeployInfo.Client;
            Log          log    = new Log {
                Identity = Identity
            };
            bool isLog = true;

            try
            {
                //Func<AutoCSer.Net.TcpServer.ReturnValue<Log>, bool> onLog = Server.GetLog(ref Identity, ref clientId) ?? Timer.onLog;
                AutoCSer.Net.TcpServer.ServerCallback <Log> onLog = client.OnLog ?? AutoCSer.Net.TcpServer.ServerCallback <Log> .Null.Default;
                log.Type = LogType.CreateBakDirectory;
                isLog   |= onLog.Callback(log);
                (BakDirectory = new DirectoryInfo(Date.NowTime.Set().ToString("yyyyMMddHHmmss_" + Identity.Index.toString() + "_" + Identity.Identity.toString()))).Create();
                log.Type = LogType.OnCreateBakDirectory;
                isLog   |= onLog.Callback(log);
                while (TaskIndex != DeployInfo.Tasks.Length && !IsCancel)
                {
                    Task task = DeployInfo.Tasks.Array[TaskIndex];
                    log.Set(TaskIndex, task.Type);
                    isLog |= onLog.Callback(log);
                    DeployState state = task.Run(this);
                    log.Type = LogType.OnRun;
                    isLog   |= onLog.Callback(log);
                    if (state != DeployState.Success)
                    {
                        return(state);
                    }
                    ++TaskIndex;
                }
                return(DeployState.Success);
            }
            catch (Exception error)
            {
                Console.WriteLine(error.ToString());
                Error = error;
            }
            finally
            {
                Server.Clear(ref Identity);
                if (Error == null)
                {
                    log.Type = LogType.Completed;
                }
                else
                {
                    AutoCSer.Log.Pub.Log.Add(AutoCSer.Log.LogType.Error, Error);
                    log.Type = LogType.Error;
                }
                //if (!(isLog |= onLog(log))) Server.ClearClient(ref clientId);
            }
            return(DeployState.Exception);
        }
Ejemplo n.º 3
0
 internal void OnLog(AutoCSer.Net.TcpServer.ServerCallback <Log> onLog)
 {
     foreach (Log log in Servers)
     {
         onLog.Callback(log);
     }
     onLog.Callback(Server);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     if (BufferCount != null)
     {
         BufferCount.Free();
     }
     if (onReturn != null)
     {
         onReturn.Callback(new ReturnParameter(ReturnType.MessageQueueBufferDisposed));
     }
 }
Ejemplo n.º 5
0
 internal bool OnLog(AutoCSer.Net.TcpServer.ServerCallback <ServerLog> onLog)
 {
     foreach (ServerLog log in Servers)
     {
         if (!onLog.Callback(log))
         {
             return(false);
         }
     }
     return(onLog.Callback(Server));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 申请锁
        /// </summary>
        /// <returns></returns>
        internal bool Enter()
        {
            ReturnParameter returnParameter = new ReturnParameter();

            returnParameter.Parameter.ReturnParameterSet(++node.RandomNo);
            if (OnReturn.Callback(returnParameter))
            {
                AutoCSer.Threading.SecondTimer.InternalTaskArray.Append(onTimeout, AutoCSer.Threading.SecondTimer.SetNow().AddTicks(timeOutTicks));
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 操作数据
        /// </summary>
        /// <param name="buffer">数据缓冲区</param>
        /// <param name="onOperation"></param>
        internal void Operation(Buffer buffer, AutoCSer.Net.TcpServer.ServerCallback <ReturnParameter> onOperation)
        {
            int isReturn = 0;

            try
            {
                if (CanWrite)
                {
                    fixed(byte *dataFixed = buffer.GetFixedBuffer())
                    {
                        OperationParameter.NodeParser parser        = new OperationParameter.NodeParser(this, buffer, dataFixed);
                        ServerDataStructure           dataStructure = parser.Get(Array);

                        if (dataStructure != null)
                        {
                            parser.OnReturn = onOperation;
                            try
                            {
                                dataStructure.Node.Operation(ref parser);
                            }
                            finally
                            {
                                if (parser.OnReturn == null)
                                {
                                    isReturn = 1;
                                }
                            }
                            if (parser.IsOperation)
                            {
                                this.onOperation(buffer);
                            }
                            else
                            {
                                buffer.FreeReference();
                            }
                            return;
                        }
                    }
                    buffer.FreeReference();
                    isReturn = 1;
                    onOperation.Callback(new ReturnParameter(ReturnType.DataStructureIdentityError));
                    return;
                }
                buffer.FreeReference();
            }
            finally
            {
                if (isReturn == 0)
                {
                    onOperation.Callback(new ReturnParameter(ReturnType.CanNotWrite));
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 申请锁
        /// </summary>
        /// <returns></returns>
        internal bool Enter()
        {
            ReturnParameter returnParameter = new ReturnParameter();

            returnParameter.Parameter.ReturnParameterSet(++node.RandomNo);
            if (OnReturn.Callback(returnParameter))
            {
                AutoCSer.Threading.TimerTask.Default.Add(onTimeout, Date.NowTime.Set().AddTicks(timeOutTicks));
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 释放资源
 /// </summary>
 internal void Free()
 {
     if (fileStream != null)
     {
         fileStream.Dispose();
         fileStream = null;
     }
     if (!isOnReadError)
     {
         isOnReadError = true;
         onRead.Callback(default(ReadFileParameter));
     }
 }
Ejemplo n.º 10
0
 internal ReadRequest Error()
 {
     if (WriteRequest == null)
     {
         OnRead.Callback(new ClientBuffer {
             State = MemberState.ServerException
         });
     }
     else
     {
         WriteRequest.AppendWrite();
     }
     return(LinkNext);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 获取当前读取数据标识
 /// </summary>
 public override void RunTask()
 {
     try
     {
         MessageQueue.GetReadIdentity(this);
     }
     finally
     {
         if (onReturn != null)
         {
             onReturn.Callback(new ReturnParameter(ReturnType.MessageQueueCreateReaderError));
         }
     }
 }
 internal bool Send(ulong identity, ref ValueData.Data data, ref bool isNext)
 {
     data.IsReturnDeSerializeStream = isGetMessageStream;
     if (OnGetMessage.Callback(new IdentityReturnParameter(identity, ref data)))
     {
         if (--sendCount == 0)
         {
             isNext    = true;
             sendCount = maxSendCount;
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 获取当前读取数据标识
 /// </summary>
 /// <returns></returns>
 internal override Node RunTask()
 {
     try
     {
         MessageQueue.GetReadIdentity(this);
     }
     finally
     {
         if (onReturn != null)
         {
             onReturn.Callback(new ReturnParameter(ReturnType.MessageQueueCreateReaderError));
         }
     }
     return(LinkNext);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="queryData">查询数据</param>
        /// <param name="onQuery"></param>
        /// <param name="isDeSerializeStream">是否反序列化网络流,否则需要 Copy 数据</param>
        internal void Query(ref SubArray <byte> queryData, AutoCSer.Net.TcpServer.ServerCallback <IdentityReturnParameter> onQuery, bool isDeSerializeStream)
        {
            try
            {
                queryBuffer.Set(ref queryData);
                fixed(byte *dataFixed = queryData.GetFixedBuffer())
                {
                    OperationParameter.NodeParser parser        = new OperationParameter.NodeParser(this, queryBuffer, dataFixed);
                    ServerDataStructure           dataStructure = parser.Get(Array);

                    if (dataStructure != null)
                    {
                        parser.SetOnReturn(onQuery, isDeSerializeStream);
                        onQuery = null;
                        try
                        {
                            dataStructure.Node.Query(ref parser);
                        }
                        finally
                        {
                            parser.CallOnReturnDistributionMessage();
                        }
                    }
                }
            }
            finally
            {
                if (onQuery != null)
                {
                    onQuery.Callback(new IdentityReturnParameter(ReturnType.DataStructureIdentityError));
                }
            }
        }
 /// <summary>
 /// 获取当前读取数据标识
 /// </summary>
 public override void RunTask()
 {
     try
     {
         new UnionType {
             Value = MessageQueue
         }.Distributor.GetSendCount(this);
     }
     finally
     {
         if (onReturn != null)
         {
             onReturn.Callback(new ReturnParameter(ReturnType.MessageQueueCreateReaderError));
         }
     }
 }
Ejemplo n.º 16
0
 internal CacheGetter Cancel()
 {
     if (step != CacheGetStep.Error)
     {
         onCache.Callback(default(CacheReturnParameter));
         step = CacheGetStep.Error;
     }
     return(LinkNext);
 }
Ejemplo n.º 17
0
 internal void OnLog(Log log)
 {
     if (onLog != null && !onLog.Callback(log))
     {
         ++Identity;
         onLog = null;
     }
 }
Ejemplo n.º 18
0
 internal void CallOnReturn()
 {
     if (OnReturn != null)
     {
         OnReturn.Callback(new ReturnParameter(ref ReturnParameter));
         OnReturn = null;
     }
 }
Ejemplo n.º 19
0
 void Add(int left, int right, int count, AutoCSer.Net.TcpServer.ServerCallback <int> onAdd)
 {
     while (count != 0)
     {
         onAdd.Callback(left + right);
         --count;
     }
 }
Ejemplo n.º 20
0
 internal void CallOnReturnDistributionMessage()
 {
     AutoCSer.Net.TcpServer.ServerCallback <IdentityReturnParameter> onReturn = ReturnParameter.Value as AutoCSer.Net.TcpServer.ServerCallback <IdentityReturnParameter>;
     if (onReturn != null)
     {
         onReturn.Callback(new IdentityReturnParameter(ref ReturnParameter));
         ReturnParameter.Value = null;
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 错误回调
 /// </summary>
 /// <param name="returnType"></param>
 internal void Error(ReturnType returnType)
 {
     FreeBuffer();
     AutoCSer.Net.TcpServer.ServerCallback <ReturnParameter> onReturn = this.onReturn;
     if (onReturn != null)
     {
         this.onReturn = null;
         onReturn.Callback(new ReturnParameter(returnType));
     }
 }
        /// <summary>
        /// 搜索树字典获取数据
        /// </summary>
        public override void RunTask()
        {
            ReturnParameter returnParameter = default(ReturnParameter);

            try
            {
                returnParameter.Parameter.ReturnParameterSetBinary(new ReturnArray <valueType>(getCount > 0 ? dictionary.Dictionary.GetRange(skipCount, getCount) : dictionary.Dictionary.GetRangeDesc(skipCount, -getCount)));
            }
            finally { OnReturn.Callback(returnParameter); }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     if (Interlocked.CompareExchange(ref isDisposed, 1, 0) == 0)
     {
         dispose();
         while (messageIndex != writeMessageIndex)
         {
             messages[messageIndex].FreeBuffer();
             if (++messageIndex == messages.Length)
             {
                 messageIndex = 0;
             }
         }
         if (onGetMessage != null)
         {
             onGetMessage.Callback(new ReturnParameter(ReturnType.MessageQueueNotFoundReader));
             onGetMessage = null;
         }
     }
 }
Ejemplo n.º 24
0
 private void append(AppendBuffer buffer, AutoCSer.Net.TcpServer.ServerCallback <ulong> onWrite)
 {
     if (buffer.CheckBlockIndex(index))
     {
         block.Append(ref buffer, onWrite);
     }
     else
     {
         onWrite.Callback(0);
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="getMessage"></param>
        internal void Get(QueueTaskThread.GetMessage getMessage)
        {
            ReturnType returnType = ReturnType.MessageQueueNotFoundReader;

            try
            {
                if (isDisposed == 0)
                {
                    if (getMessage.Identity == Identity)
                    {
                        if (onGetMessage == null || !onGetMessage.Callback(new ReturnParameter(ReturnType.Success)))
                        {
                            onGetMessage       = getMessage.OnReturn;
                            isGetMessageStream = getMessage.IsReturnStream;
                            ulong endIdentity = Math.Min(Identity + Config.SendClientCount, writeIdentity);
                            sendIdentity     = Identity;
                            sendMessageIndex = messageIndex;
                            getMessage       = null;
                            ReturnParameter returnParameter = default(ReturnParameter);
                            while (sendIdentity != endIdentity)
                            {
                                returnParameter.Set(messages[sendMessageIndex].Data, isGetMessageStream);
                                if (onGetMessage.Callback(returnParameter))
                                {
                                    nextSendIndex();
                                }
                                else
                                {
                                    onGetMessage = null;
                                    return;
                                }
                            }
                            return;
                        }
                        else
                        {
                            returnType = ReturnType.MessageQueueGetMessageExists;
                        }
                    }
                    else
                    {
                        returnType = ReturnType.MessageQueueReaderIdentityError;
                    }
                }
            }
            finally
            {
                if (getMessage != null)
                {
                    getMessage.OnReturn.Callback(new ReturnParameter(returnType));
                }
            }
        }
Ejemplo n.º 26
0
 private void read(ClientBuffer buffer, ulong index, AutoCSer.Net.TcpServer.ServerCallback <ClientBuffer> onRead)
 {
     if ((int)(index >> IndexShift) == this.index)
     {
         block.Read((long)(index & MaxIndex), buffer.Buffer.Start, onRead);
     }
     else
     {
         onRead.Callback(new ClientBuffer {
             State = MemberState.BlockIndexError
         });
     }
 }
Ejemplo n.º 27
0
 private void getLog(ClientId clientId, AutoCSer.Net.TcpServer.ServerCallback <Log> onLog)
 {
     if (clientId.Tick == ticks)
     {
         object arrayLock = clientPool.ArrayLock;
         Monitor.Enter(arrayLock);
         if (clientPool.Array[clientId.Index].Set(clientId.Identity, onLog))
         {
             try
             {
                 foreach (ServerSet serverSet in serverSets.Values)
                 {
                     serverSet.OnLog(onLog);
                 }
                 onLog.Callback(Log.RegisterLoaded);
             }
             finally { Monitor.Exit(arrayLock); }
             return;
         }
         Monitor.Exit(arrayLock);
     }
     onLog.Callback(Log.ClientError);
 }
Ejemplo n.º 28
0
        internal void GetCache(AutoCSer.Net.TcpServer.ServerCallback <CacheReturnParameter> onCache)
        {
            CacheManager cache = Cache;

            if (cache != null)
            {
                new CacheGetter(cache, onCache);
            }
            //if (cache != null) AutoCSer.Net.TcpServer.ServerCallQueue.Default.Add(new ServerCall.GetCache(cache, onCache));
            else
            {
                onCache.Callback(default(CacheReturnParameter));
            }
        }
        /// <summary>
        /// 搜索树字典获取数据
        /// </summary>
        public override void Call()
        {
            ReturnParameter returnParameter = default(ReturnParameter);

            try
            {
                returnParameter.Parameter.ReturnParameterSetBinary(new ReturnArray <valueType>(getCount > 0 ? dictionary.Dictionary.GetRange(skipCount, getCount) : dictionary.Dictionary.GetRangeDesc(skipCount, -getCount)));
            }
            catch (Exception error)
            {
                cache.TcpServer.AddLog(error);
            }
            finally { OnReturn.Callback(returnParameter); }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <param name="buffer">数据</param>
 /// <param name="onWrite">添加数据回调委托</param>
 void IBlock.Append(ref AppendBuffer buffer, AutoCSer.Net.TcpServer.ServerCallback <ulong> onWrite)
 {
     if (isDisposed == 0)
     {
         ulong index = buffer.Index & Server.MaxIndex;
         if (index == 0 || (long)index + (buffer.Buffer.Length + sizeof(int)) > fileLength)
         {
             if (writeRequests.IsPushHead(new WriteRequest(ref buffer, onWrite)))
             {
                 writeWait.Set();
             }
             if (isDisposed != 0)
             {
                 for (WriteRequest head = writeRequests.GetClear(); head != null; head = head.Error())
                 {
                     ;
                 }
             }
         }
         else
         {
             ReadRequest readRequest = new ReadRequest {
                 Index = (long)index, Size = buffer.Buffer.Length
             };
             readRequest.WriteRequest = new FileWriteRequest(ref buffer, onWrite, this);
             if (readRequests.IsPushHead(readRequest))
             {
                 readWait.Set();
             }
             if (isDisposed != 0)
             {
                 for (ReadRequest head = readRequests.GetClear(); head != null; head = head.Error())
                 {
                     ;
                 }
                 for (WriteRequest head = writeRequests.GetClear(); head != null; head = head.Error())
                 {
                     ;
                 }
             }
         }
     }
     else
     {
         onWrite.Callback(0);
     }
 }