/// <summary> /// 启动定时任务 /// </summary> internal DeployState Start() { if (IsCancel) { return(DeployState.Canceled); } IndexIdentity clientId = new IndexIdentity(); 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; log.Type = LogType.CreateBakDirectory; isLog |= onLog(log); (BakDirectory = new DirectoryInfo(Date.NowTime.Set().ToString("yyyyMMddHHmmss_" + Identity.Index.toString() + "_" + Identity.Identity.toString()))).Create(); log.Type = LogType.OnCreateBakDirectory; isLog |= onLog(log); while (TaskIndex != DeployInfo.Tasks.Length && !IsCancel) { Task task = DeployInfo.Tasks.Array[TaskIndex]; log.Set(TaskIndex, task.Type); isLog |= onLog(log); DeployState state = task.Run(this); log.Type = LogType.OnRun; isLog |= onLog(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); }
/// <summary> /// 清除客户端信息 /// </summary> /// <param name="clientId"></param> internal void ClearClient(ref IndexIdentity clientId) { object arrayLock = clientPool.ArrayLock; Monitor.Enter(arrayLock); clientPool.Array[clientId.Index].Clear(clientId.Identity); Monitor.Exit(arrayLock); }
private void getLog(IndexIdentity clientId, Func <AutoCSer.Net.TcpServer.ReturnValue <Log>, bool> onLog) { object arrayLock = clientPool.ArrayLock; Monitor.Enter(arrayLock); clientPool.Array[clientId.Index].Set(clientId.Identity, onLog); Monitor.Exit(arrayLock); }
private bool clear(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity identity) { if (checkCommand(sender, Command.clear)) { Clear(ref identity); return(true); } return(false); }
internal bool GetClientId(int identity, ref IndexIdentity clientId) { if (Identity == identity) { clientId = ClientId; return(true); } return(false); }
private bool setFileSource(IndexIdentity identity, byte[][] files) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); if (deployPool.Array[identity.Index].SetFiles(identity.Identity, files)) { Monitor.Exit(arrayLock); return(true); } Monitor.Exit(arrayLock); } return(false); }
private DeployState start(IndexIdentity identity, DateTime time) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].Start(identity.Identity, time, new Timer { Server = this, Identity = identity })); } finally { Monitor.Exit(arrayLock); } } return(DeployState.IdentityError); }
private int addRun(IndexIdentity identity, KeyValue <string, int>[] files, ClientTask.Run run) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { FileIndexs = files, ServerDirectory = new DirectoryInfo(run.ServerPath), Type = TaskType.Run, RunFileName = run.FileName, RunSleep = run.Sleep, IsWaitRun = run.IsWait })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
private int addWaitRunSwitch(IndexIdentity identity, int taskIndex) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { TaskIndex = taskIndex, Type = TaskType.WaitRunSwitch })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
private IndexIdentity create(IndexIdentity clientId) { int index, identity; object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { index = deployPool.GetIndexContinue(); identity = deployPool.Array[index].Set(ref clientId); } finally { Monitor.Exit(arrayLock); } return(new IndexIdentity { Index = index, Identity = identity }); }
private int addAssemblyFiles(IndexIdentity identity, KeyValue <string, int>[] files, ClientTask.AssemblyFile assemblyFile) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { FileIndexs = files, ServerDirectory = new DirectoryInfo(assemblyFile.ServerPath), Type = TaskType.AssemblyFile })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
private int addCustom(IndexIdentity identity, ClientTask.Custom custom) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { RunFileName = custom.CallName, CustomData = custom.CustomData, Type = TaskType.Custom })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
/// <summary> /// 清除部署信息 /// </summary> /// <param name="identity">部署信息索引标识</param> internal void Clear(ref IndexIdentity identity) { if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); if (deployPool.Array[identity.Index].Clear(identity.Identity)) { deployPool.FreeExit(identity.Index); GC.Collect(); } else { Monitor.Exit(arrayLock); } } }
private int addFiles(IndexIdentity identity, Directory directory, ClientTask.WebFile webFile, TaskType taskType) { //System.IO.FileInfo file = new System.IO.FileInfo(@"ServerDeSerializeError" + AutoCSer.Date.NowTime.Set().Ticks.ToString()); //System.IO.File.WriteAllBytes(file.FullName, data.ToArray()); //Console.WriteLine(file.FullName); if ((uint)identity.Index < (uint)deployPool.PoolIndex) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { Directory = directory, ServerDirectory = new DirectoryInfo(webFile.ServerPath), Type = taskType })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
/// <summary> /// 获取部署任务状态更新回调 /// </summary> /// <param name="deployIdentity"></param> /// <param name="clientId"></param> /// <returns></returns> internal Func <AutoCSer.Net.TcpServer.ReturnValue <Log>, bool> GetLog(ref IndexIdentity deployIdentity, ref IndexIdentity clientId) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); if (deployPool.Array[deployIdentity.Index].GetClientId(deployIdentity.Identity, ref clientId)) { Monitor.Exit(arrayLock); arrayLock = clientPool.ArrayLock; Monitor.Enter(arrayLock); Func <AutoCSer.Net.TcpServer.ReturnValue <Log>, bool> onLog = clientPool.Array[clientId.Index].GetLog(clientId.Identity); Monitor.Exit(arrayLock); return(onLog); } else { Monitor.Exit(arrayLock); } return(null); }
internal int Set(ref IndexIdentity clientId) { ClientId = clientId; return(Identity); }
private int addWaitRunSwitch(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity identity, int taskIndex) { if ((uint)identity.Index < (uint)deployPool.PoolIndex && checkCommand(sender, Command.addWaitRunSwitch)) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { TaskIndex = taskIndex, Type = TaskType.WaitRunSwitch })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
private IndexIdentity create(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity clientId) { if (checkCommand(sender, Command.create)) { int index, identity; object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { index = deployPool.GetIndexContinue(); identity = deployPool.Array[index].Set(ref clientId); } finally { Monitor.Exit(arrayLock); } return(new IndexIdentity { Index = index, Identity = identity }); } return(new IndexIdentity { Index = -1 }); }
private DeployState start(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity identity, DateTime time) { if ((uint)identity.Index < (uint)deployPool.PoolIndex && checkCommand(sender, Command.start)) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].Start(identity.Identity, time, new Timer { Server = this, Identity = identity })); } finally { Monitor.Exit(arrayLock); } } return(DeployState.IdentityError); }
private bool setFileSource(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity identity, byte[][] files) { if ((uint)identity.Index < (uint)deployPool.PoolIndex && checkCommand(sender, Command.setFileSource)) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); if (deployPool.Array[identity.Index].SetFiles(identity.Identity, files)) { Monitor.Exit(arrayLock); return(true); } Monitor.Exit(arrayLock); } return(false); }
private int addCustom(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity identity, ClientTask.Custom custom) { if ((uint)identity.Index < (uint)deployPool.PoolIndex && checkCustom(sender, custom.CallName)) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { Sender = sender, RunFileName = custom.CallName, CustomData = custom.CustomData, Type = TaskType.Custom })); } finally { Monitor.Exit(arrayLock); } } return(-1); }
private void clear(IndexIdentity identity) { Clear(ref identity); }
/// <summary> /// 创建缓存节点后的回调操作 /// </summary> /// <param name="identity"></param> private unsafe void onDataStructureCreated(IndexIdentity identity) { fixed(byte *dataFixed = packet) identity.UnsafeSerialize(dataFixed); start(); }
private int addAssemblyFiles(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, IndexIdentity identity, KeyValue <string, int>[] files, ClientTask.AssemblyFile assemblyFile) { if ((uint)identity.Index < (uint)deployPool.PoolIndex && checkCommand(sender, Command.addAssemblyFiles)) { object arrayLock = deployPool.ArrayLock; Monitor.Enter(arrayLock); try { return(deployPool.Array[identity.Index].AddTask(identity.Identity, new Task { FileIndexs = files, ServerDirectory = new DirectoryInfo(assemblyFile.ServerPath), Type = TaskType.AssemblyFile })); } finally { Monitor.Exit(arrayLock); } } return(-1); }