/// <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); }
/// <summary> /// 启动定时任务 /// </summary> internal DeployState Start() { if (IsCancel) { return(DeployState.Canceled); } ClientObject client = DeployInfo.Client; Log log = new Log { DeployIndex = DeployInfo.Index }; 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(Server.GetBakDirectoryName(DeployInfo.Index))).Create(); log.Type = LogType.OnCreateBakDirectory; isLog |= onLog.Callback(log); while (TaskIndex != DeployInfo.Tasks.Length && !IsCancel) { ClientTask.Task task = DeployInfo.Tasks.Array[TaskIndex]; log.Set(TaskIndex, task.Type); isLog |= onLog.Callback(log); DeployState state = task.Call(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); }