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="fileSources"></param> ///// <param name="run"></param> ///// <param name="serverTask"></param> //private void appendSource(Dictionary<HashString, FileSource> fileSources, ClientTask.Run run, ref ClientTaskInfo serverTask) //{ // appendSource(fileSources, run, ref serverTask, run.FileName); //} /// <summary> /// 添加文件数据源 /// </summary> /// <param name="fileSources"></param> /// <param name="webFile"></param> /// <param name="serverTask"></param> /// <param name="runFileName"></param> private void appendSource(Dictionary <HashString, FileSource> fileSources, ClientTask.WebFile webFile, ref ClientTaskInfo serverTask, string runFileName = null) { Client client = TcpClient.Client; if (webFile.ClientPath != null) { DirectoryInfo directory = new DirectoryInfo(webFile.ClientPath); string directoryName = directory.fullName(); if (runFileName != null) { appendSource(fileSources, directoryName, runFileName, ref serverTask); } foreach (FileInfo file in directory.GetFiles("*.exe")) { if (file.LastWriteTimeUtc > client.Config.FileLastWriteTime && file.Name != runFileName && !client.IgnoreFileNames.Contains(file.Name) && !file.Name.EndsWith(".vshost.exe", StringComparison.Ordinal)) { appendSource(fileSources, directoryName, file.Name, ref serverTask); } } foreach (FileInfo file in directory.GetFiles("*.dll")) { if (file.LastWriteTimeUtc > client.Config.FileLastWriteTime && !client.IgnoreFileNames.Contains(file.Name)) { appendSource(fileSources, directoryName, file.Name, ref serverTask); } } foreach (FileInfo file in directory.GetFiles("*.pdb")) { if (file.LastWriteTimeUtc > client.Config.FileLastWriteTime && !client.IgnoreFileNames.Contains(file.Name)) { appendSource(fileSources, directoryName, file.Name, ref serverTask); } } } }
protected virtual int addFiles(AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, ClientTask.WebFile webFile) { DeployInfo deployInfo = ((ClientObject)sender.ClientObject).CurrentDeploy; if (deployInfo != null) { return(deployInfo.AddTask(webFile)); } return(-1); }
/// <summary> /// 启动部署 /// </summary> /// <returns>部署结果</returns> internal async Task <DeployResult> DeployAsync() { #if NoAutoCSer throw new Exception(); #else if (TcpClient.IsClient) { AutoCSer.Net.TcpServer.ReturnValue <int> indexReuslt = await TcpClient.TcpInternalClient.createAwaiter(); if (indexReuslt.Type != AutoCSer.Net.TcpServer.ReturnType.Success) { return(new DeployResult { Index = -1, State = DeployState.CreateError, ReturnType = indexReuslt.Type }); } try { Client client = TcpClient.Client; Dictionary <HashString, FileSource> fileSources = DictionaryCreator.CreateHashString <FileSource>(); ClientTaskInfo[] tasks = new ClientTaskInfo[Tasks.Length]; AutoCSer.Net.TcpServer.ReturnValue <AutoCSer.Deploy.Directory> getFileDifferentReuslt; for (int taskIndex = 0; taskIndex != Tasks.Length; ++taskIndex) { switch (Tasks[taskIndex].Type) { case TaskType.AssemblyFile: appendSource(fileSources, (ClientTask.WebFile)Tasks[taskIndex], ref tasks[taskIndex]); break; case TaskType.File: ClientTask.File file = (ClientTask.File)Tasks[taskIndex]; DirectoryInfo clientDirectory = new DirectoryInfo(file.ClientPath); Directory directory = Directory.Create(clientDirectory, client.Config.FileLastWriteTime, file.SearchPatterns); getFileDifferentReuslt = await TcpClient.TcpInternalClient.getFileDifferentAwaiter(directory, file.ServerPath); if (getFileDifferentReuslt.Type != AutoCSer.Net.TcpServer.ReturnType.Success) { return(new DeployResult { Index = -1, State = DeployState.GetFileDifferentError, ReturnType = getFileDifferentReuslt.Type }); } tasks[taskIndex].Directory = getFileDifferentReuslt.Value; tasks[taskIndex].Directory.Load(clientDirectory); break; case TaskType.WebFile: ClientTask.WebFile webFile = (ClientTask.WebFile)Tasks[taskIndex]; DirectoryInfo webClientDirectory = new DirectoryInfo(webFile.ClientPath); Directory webDirectory = Directory.CreateWeb(webClientDirectory, client.Config.FileLastWriteTime); getFileDifferentReuslt = await TcpClient.TcpInternalClient.getFileDifferentAwaiter(webDirectory, webFile.ServerPath); if (getFileDifferentReuslt.Type != AutoCSer.Net.TcpServer.ReturnType.Success) { return(new DeployResult { Index = -1, State = DeployState.GetFileDifferentError, ReturnType = getFileDifferentReuslt.Type }); } tasks[taskIndex].Directory = getFileDifferentReuslt.Value; tasks[taskIndex].Directory.Load(webClientDirectory); break; } } if (fileSources.Count != 0) { AutoCSer.Net.TcpServer.ReturnValue <bool> result = await TcpClient.TcpInternalClient.setFileSourceAwaiter(fileSources.getArray(value => value.Value.Data)); if (!result.Value) { return new DeployResult { Index = -1, State = DeployState.SetFileSourceError, ReturnType = result.Type } } ; } for (int taskIndex = 0; taskIndex != Tasks.Length; ++taskIndex) { AutoCSer.Net.TcpServer.ReturnValue <int> result; switch (Tasks[taskIndex].Type) { case TaskType.Run: result = await TcpClient.TcpInternalClient.addRunAwaiter((ClientTask.Run) Tasks[taskIndex]); if (result.Type == AutoCSer.Net.TcpServer.ReturnType.Success) { tasks[taskIndex].TaskIndex = result.Value; } break; case TaskType.WebFile: case TaskType.File: ClientTask.WebFile webFile = (ClientTask.WebFile)Tasks[taskIndex]; webFile.Directory = tasks[taskIndex].Directory; result = await TcpClient.TcpInternalClient.addFilesAwaiter(webFile); break; case TaskType.AssemblyFile: ClientTask.AssemblyFile assemblyFile = (ClientTask.AssemblyFile)Tasks[taskIndex]; assemblyFile.FileIndexs = tasks[taskIndex].FileIndexs.ToArray(); result = await TcpClient.TcpInternalClient.addAssemblyFilesAwaiter(assemblyFile); break; case TaskType.WaitRunSwitch: result = await TcpClient.TcpInternalClient.addWaitRunSwitchAwaiter(tasks[((ClientTask.WaitRunSwitch)Tasks[taskIndex]).TaskIndex].TaskIndex); break; case TaskType.UpdateSwitchFile: result = await TcpClient.TcpInternalClient.addUpdateSwitchFileAwaiter((ClientTask.UpdateSwitchFile) Tasks[taskIndex]); break; case TaskType.Custom: result = await TcpClient.TcpInternalClient.addCustomAwaiter((ClientTask.Custom) Tasks[taskIndex]); break; default: return(new DeployResult { Index = -1, State = DeployState.UnknownTaskType, ReturnType = AutoCSer.Net.TcpServer.ReturnType.Unknown }); } if (result.Type != AutoCSer.Net.TcpServer.ReturnType.Success || result.Value == -1) { return(new DeployResult { Index = -1, State = getErrorState(Tasks[taskIndex].Type), ReturnType = result.Type }); } } AutoCSer.Net.TcpServer.ReturnValue <AutoCSer.Deploy.DeployState> startResult = await TcpClient.TcpInternalClient.startAwaiter(DateTime.MinValue); if (startResult.Type == AutoCSer.Net.TcpServer.ReturnType.Success) { return(new DeployResult { Index = indexReuslt.Value, State = startResult.Value, ReturnType = AutoCSer.Net.TcpServer.ReturnType.Success }); } return(new DeployResult { Index = -1, State = DeployState.StartError, ReturnType = startResult.Type }); } finally { await TcpClient.TcpInternalClient.cancelAwaiter();// && TcpClient.TcpInternalClient.clear(identity).Type != AutoCSer.Net.TcpServer.ReturnType.Success } } #endif return(new DeployResult { Index = -1, State = DeployState.NoClient }); }
/// <summary> /// 启动部署 /// </summary> /// <param name="startTime">部署任务启动时间</param> /// <returns>部署结果</returns> internal DeployResult Deploy(DateTime startTime = default(DateTime)) { #if NoAutoCSer throw new Exception(); #else if (TcpClient.IsClient) { //AutoCSer.Net.IndexIdentity identity = TcpClient.TcpInternalClient.create(TcpClient.ClientId); AutoCSer.Net.IndexIdentity identity = TcpClient.TcpInternalClient.create(); bool isClear = false; try { Client client = TcpClient.Client; Dictionary <HashString, FileSource> fileSources = DictionaryCreator.CreateHashString <FileSource>(); ClientTaskInfo[] tasks = new ClientTaskInfo[Tasks.Length]; for (int taskIndex = 0; taskIndex != Tasks.Length; ++taskIndex) { switch (Tasks[taskIndex].Type) { case TaskType.Run: appendSource(fileSources, (ClientTask.Run)Tasks[taskIndex], ref tasks[taskIndex]); break; case TaskType.AssemblyFile: appendSource(fileSources, (ClientTask.WebFile)Tasks[taskIndex], ref tasks[taskIndex]); break; case TaskType.File: ClientTask.File file = (ClientTask.File)Tasks[taskIndex]; DirectoryInfo clientDirectory = new DirectoryInfo(file.ClientPath); Directory directory = Directory.Create(clientDirectory, client.Config.FileLastWriteTime, file.SearchPatterns); tasks[taskIndex].Directory = TcpClient.TcpInternalClient.getFileDifferent(directory, file.ServerPath); tasks[taskIndex].Directory.Load(clientDirectory); break; case TaskType.WebFile: ClientTask.WebFile webFile = (ClientTask.WebFile)Tasks[taskIndex]; DirectoryInfo webClientDirectory = new DirectoryInfo(webFile.ClientPath); Directory webDirectory = Directory.CreateWeb(webClientDirectory, client.Config.FileLastWriteTime); tasks[taskIndex].Directory = TcpClient.TcpInternalClient.getFileDifferent(webDirectory, webFile.ServerPath); tasks[taskIndex].Directory.Load(webClientDirectory); break; } } if (fileSources.Count != 0 && !TcpClient.TcpInternalClient.setFileSource(identity, fileSources.getArray(value => value.Value.Data))) { return(new DeployResult { Index = -1, State = DeployState.SetFileSourceError }); } for (int taskIndex = 0; taskIndex != Tasks.Length; ++taskIndex) { switch (Tasks[taskIndex].Type) { case TaskType.Run: if ((tasks[taskIndex].TaskIndex = TcpClient.TcpInternalClient.addRun(identity, tasks[taskIndex].FileIndexs.ToArray(), (ClientTask.Run)Tasks[taskIndex])) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddRunError }); } break; case TaskType.WebFile: case TaskType.File: if (TcpClient.TcpInternalClient.addFiles(identity, tasks[taskIndex].Directory, (ClientTask.WebFile)Tasks[taskIndex], Tasks[taskIndex].Type) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddFileError }); } break; case TaskType.AssemblyFile: if (TcpClient.TcpInternalClient.addAssemblyFiles(identity, tasks[taskIndex].FileIndexs.ToArray(), (ClientTask.AssemblyFile)Tasks[taskIndex]) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddAssemblyFileError }); } break; case TaskType.WaitRunSwitch: if (TcpClient.TcpInternalClient.addWaitRunSwitch(identity, tasks[((ClientTask.WaitRunSwitch)Tasks[taskIndex]).TaskIndex].TaskIndex) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddWaitRunSwitchError }); } break; case TaskType.Custom: if (TcpClient.TcpInternalClient.addCustom(identity, (ClientTask.Custom)Tasks[taskIndex]) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddCustomError }); } break; } } AutoCSer.Net.TcpServer.ReturnValue <AutoCSer.Deploy.DeployState> result = TcpClient.TcpInternalClient.start(identity, startTime); if (result.Type == AutoCSer.Net.TcpServer.ReturnType.Success) { isClear = checkIsClear(result.Value); return(new DeployResult { Index = identity.Index, State = result.Value }); } return(new DeployResult { Index = -1, State = DeployState.StartError }); } finally { if (isClear) { TcpClient.TcpInternalClient.clear(identity); // && TcpClient.TcpInternalClient.clear(identity).Type != AutoCSer.Net.TcpServer.ReturnType.Success } } } #endif return(new DeployResult { Index = -1, State = DeployState.NoClient }); }
/// <summary> /// 启动部署 /// </summary> /// <returns>部署结果</returns> internal async Task <DeployResult> DeployAsync() { #if NoAutoCSer throw new Exception(); #else if (TcpClient.IsClient) { AutoCSer.Net.IndexIdentity identity = await TcpClient.TcpInternalClient.createAwaiter(TcpClient.ClientId); byte isStart = 0; try { Client client = TcpClient.Client; Dictionary <HashString, FileSource> fileSources = DictionaryCreator.CreateHashString <FileSource>(); ClientTaskInfo[] tasks = new ClientTaskInfo[Tasks.Length]; for (int taskIndex = 0; taskIndex != Tasks.Length; ++taskIndex) { switch (Tasks[taskIndex].Type) { case TaskType.Run: appendSource(fileSources, (ClientTask.Run)Tasks[taskIndex], ref tasks[taskIndex]); break; case TaskType.AssemblyFile: appendSource(fileSources, (ClientTask.WebFile)Tasks[taskIndex], ref tasks[taskIndex]); break; case TaskType.File: ClientTask.File file = (ClientTask.File)Tasks[taskIndex]; DirectoryInfo clientDirectory = new DirectoryInfo(file.ClientPath); Directory directory = Directory.Create(clientDirectory, client.Config.FileLastWriteTime, file.SearchPatterns); tasks[taskIndex].Directory = await TcpClient.TcpInternalClient.getFileDifferentAwaiter(directory, file.ServerPath); tasks[taskIndex].Directory.Load(clientDirectory); break; case TaskType.WebFile: ClientTask.WebFile webFile = (ClientTask.WebFile)Tasks[taskIndex]; DirectoryInfo webClientDirectory = new DirectoryInfo(webFile.ClientPath); Directory webDirectory = Directory.CreateWeb(webClientDirectory, client.Config.FileLastWriteTime); tasks[taskIndex].Directory = await TcpClient.TcpInternalClient.getFileDifferentAwaiter(webDirectory, webFile.ServerPath); tasks[taskIndex].Directory.Load(webClientDirectory); break; } } if (fileSources.Count != 0 && !(await TcpClient.TcpInternalClient.setFileSourceAwaiter(identity, fileSources.getArray(value => value.Value.Data)))) { return(new DeployResult { Index = -1, State = DeployState.SetFileSourceError }); } for (int taskIndex = 0; taskIndex != Tasks.Length; ++taskIndex) { switch (Tasks[taskIndex].Type) { case TaskType.Run: if ((tasks[taskIndex].TaskIndex = await TcpClient.TcpInternalClient.addRunAwaiter(identity, tasks[taskIndex].FileIndexs.ToArray(), (ClientTask.Run)Tasks[taskIndex])) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddRunError }); } break; case TaskType.WebFile: case TaskType.File: if (await TcpClient.TcpInternalClient.addFilesAwaiter(identity, tasks[taskIndex].Directory, (ClientTask.WebFile)Tasks[taskIndex], Tasks[taskIndex].Type) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddFileError }); } break; case TaskType.AssemblyFile: if (await TcpClient.TcpInternalClient.addAssemblyFilesAwaiter(identity, tasks[taskIndex].FileIndexs.ToArray(), (ClientTask.AssemblyFile)Tasks[taskIndex]) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddAssemblyFileError }); } break; case TaskType.WaitRunSwitch: if (await TcpClient.TcpInternalClient.addWaitRunSwitchAwaiter(identity, tasks[((ClientTask.WaitRunSwitch)Tasks[taskIndex]).TaskIndex].TaskIndex) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddWaitRunSwitchError }); } break; case TaskType.Custom: if (await TcpClient.TcpInternalClient.addCustomAwaiter(identity, (ClientTask.Custom)Tasks[taskIndex]) == -1) { return(new DeployResult { Index = -1, State = DeployState.AddCustomError }); } break; } } if (await TcpClient.TcpInternalClient.startAwaiter(identity, DateTime.MinValue)) { isStart = 1; return(new DeployResult { Index = identity.Index, State = DeployState.Success }); } return(new DeployResult { Index = -1, State = DeployState.StartError }); } finally { if (isStart == 0) { await TcpClient.TcpInternalClient.clearAwaiter(identity); // && TcpClient.TcpInternalClient.clear(identity).Type != AutoCSer.Net.TcpServer.ReturnType.Success } } } #endif return(new DeployResult { Index = -1, State = DeployState.NoClient }); }