static async Task SendFileAsync(FilesConfig config, Resource resource, bool headOnly) { if (resource.Length > 0) { resource.Context.Response.Headers.ContentLength = resource.Length; } resource.Context.Response.Headers.ContentType = resource.ContentType; if (resource.ModifiedDateUtc > DateTime.MinValue) { resource.Context.Response.Headers.Append(HttpHeaderNames.LastModified, resource.ModifiedDateUtc.ToString("R")); } //resource.Context.Response.Headers.Append(HttpHeaders.ContentDisposition, "inline; filename=" + Uri.EscapeUriString(resource.DisplayName)); if (!headOnly) { using (Stream fs = config.DataStore.Open(resource)) { byte[] buff = new byte[4096]; int read = 0; while ((read = await fs.ReadAsync(buff, 0, buff.Length).ConfigureAwait(false)) > 0) { await resource.Context.Response.Body.WriteAsync(buff, 0, read, resource.Context.CancellationToken).ConfigureAwait(false); } } } }
async Task ShowDirectoryListingAsync(FilesConfig config, Resource resource, bool headOnly) { resource.Context.Response.Headers.ContentType = config.MimeTypeProvider.GetMimeType(".html"); if (!headOnly) { var subRes = config.DataStore.GetSubResources(resource.Context, resource); var content = await config.DirectoryGenerator.GenerateAsync(resource.Context, resource, subRes.Select(r => r.Resource)).ConfigureAwait(false); await resource.Context.Response.WriteAsync(content, resource.Context.CancellationToken).ConfigureAwait(false); } }
public static void Load() { if (Settings.CurrentContainer.Values.ContainsKey(KEY_FILES)) { string content = Settings.CurrentContainer.Values[KEY_FILES] as string; InternalConfig = PortableConfigHelper.ReadConfig <FilesConfig>(content: ref content); Settings.CurrentContainer.Values[KEY_FILES] = content; InternalConfig.RecentFiles = InternalConfig.RecentFiles.Where(f => !string.IsNullOrWhiteSpace(f.Token)).ToList(); Save(); } else { InternalConfig = new FilesConfig(); Settings.CurrentContainer.Values[KEY_FILES] = PortableConfigHelper.WriteConfig <FilesConfig>(InternalConfig); } }
public StringBuilder GetTextoWordDocModelo(long IdModeloDoc, string ServerPath) { StringBuilder textoDoc = new StringBuilder(); FilesConfig fileConfig = new FilesConfig(); string fileName = Path.Combine(ServerPath, fileConfig.GetModeloDocFileName(IdModeloDoc)); using (AtoWordDocx atoWordDocx = new AtoWordDocx(this, this.IdCtaAcessoSist, fileName)) { //textoDoc.Append(atoWordDocx.WordDocument.Content.ToString()); foreach (Paragraph paragraph in atoWordDocx.WordDocument.GetChildElements(true, ElementType.Paragraph)) { textoDoc.Append(paragraph.Content.ToString()); } } return(textoDoc); }
/// <summary> /// 获取版本号 /// </summary> public static string GetLocalPatchVersion() { string version = string.Empty; if (string.IsNullOrEmpty(AppConst.Version)) { if (File.Exists(Util.DataPath + AppConst.PatchList)) { FilesConfig filelist = JsonHelp.LoadFromJsonFile <FilesConfig>(Util.DataPath + AppConst.PatchList); if (filelist != null) { string versionFloder = filelist.VerRevision.GetTxt(); version = versionFloder; } } } else { version = AppConst.Version; } return(version); }
static void FileJasonBuild(List <ResInfo> resInfoList) { string FileList = AppConst.AssetDir + "/" + AppConst.PatchList; FilesConfig filelist = new FilesConfig(); filelist.VerRevision = new VersionInfo(); filelist.mShardInfos = resInfoList; filelist.PatchUrl = AppConst.PathWebUrl; filelist.VerRevision.Init(AppConst.VER_MAJOR, AppConst.VER_MINOR, AppConst.VER_REVISION); JsonHelp.SaveToJsonFile(filelist, FileList); AssetDatabase.Refresh(); #if UNITY_STANDALONE || UNITY_ANDROID Process process = new Process(); //设定程序名 process.StartInfo.FileName = "cmd.exe"; //关闭Shell的使用 process.StartInfo.UseShellExecute = false; //重新定向标准输入,输入,错误输出 process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; //设置cmd窗口不显示 process.StartInfo.CreateNoWindow = true; //开始 process.Start(); //输入命令,退出 process.StandardInput.WriteLine(@"set SVN_PATH=D:\Program Files\TortoiseSVN\bin"); process.StandardInput.WriteLine(@"set WORK_DIR=%cd% "); process.StandardInput.WriteLine(@"set VERSION_TEMPLATE=%cd%\Assets\" + FileList); process.StandardInput.WriteLine(@"set VERSION_RELEASE=%cd%\Assets\" + FileList); process.StandardInput.WriteLine(@"cd %SVN_PATH% "); process.StandardInput.WriteLine(@"SubWCRev.exe ""%WORK_DIR%"" ""%VERSION_TEMPLATE%"" ""%VERSION_RELEASE%"" "); //process.StandardInput.WriteLine("netstat"); process.StandardInput.WriteLine("exit"); string strRst = process.StandardOutput.ReadToEnd(); #endif }
public void Configuration(IAppBuilder app) { //app.UseErrorPage(); // serve files from a fs folder. app.Map("/loose", mapped => { var path = Path.Combine(Environment.CurrentDirectory, @"..\..\wwwroot"); var cfg = new FilesConfig(new LooseFilesDataStore(path)) { AllowDirectoryBrowsing = true, Log = new TraceLog(System.Diagnostics.TraceLevel.Verbose) }; mapped.Use <FilesMiddleware>(cfg); }); // server only a single file. app.Map("/single", mapped => { var filePath = Path.Combine(Environment.CurrentDirectory, @"..\..\wwwroot\dummy.txt"); if (File.Exists(filePath)) { var store = new SingleFilesDataStore(); store.SetFile(filePath); mapped.Use <FilesMiddleware>(new FilesConfig(store) { AllowDirectoryBrowsing = true }); } }); // serve files from a zip file app.Map("/pdfjs", mapped => { var zipPath = Path.Combine(Environment.CurrentDirectory, @"pdfjs-1.1.114-dist.zip"); if (File.Exists(zipPath)) { var cfg = new FilesConfig(new ZippedFileDataStore(File.ReadAllBytes(zipPath))) { AllowDirectoryBrowsing = true, Log = new TraceLog(System.Diagnostics.TraceLevel.Verbose) }; mapped.Use <FilesMiddleware>(cfg); } }); // server files from windows zip (path is a\b\c) app.Map("/winzip", mapped => { var zipPath = Path.Combine(Environment.CurrentDirectory, @"help.zip"); if (File.Exists(zipPath)) { var cfg = new FilesConfig(new ZippedFileDataStore(File.ReadAllBytes(zipPath))) { AllowDirectoryBrowsing = false, Log = new TraceLog(System.Diagnostics.TraceLevel.Verbose) }; mapped.Use <FilesMiddleware>(cfg); } }); // serve files from this assembly's resource app.Use <FilesMiddleware>(new FilesConfig(new AssemblyResourceDataStore(Assembly.GetExecutingAssembly(), "FilesRunner.Resources")) { AllowDirectoryBrowsing = true, }); }
IEnumerator OnExtractResource() { string dataPath = Util.DataPath; //数据目录 string resPath = Util.AppContentPath(); //游戏包资源目录 StringBuilder kTips = null; if (Directory.Exists(dataPath)) { Directory.Delete(dataPath, true); } Directory.CreateDirectory(dataPath); string infile = resPath + AppConst.PublishServerList; string outfile = dataPath + AppConst.PublishServerList; if (File.Exists(outfile)) { File.Delete(outfile); } string message = "正在解包文件:>" + AppConst.PublishServerList; Util.Log("Serverlist", infile); Util.Log("Serverlist", outfile); if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } www.Dispose(); www = null; yield return(0); } else { File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); infile = resPath + AppConst.PatchList; outfile = dataPath + AppConst.PatchList; if (File.Exists(outfile)) { File.Delete(outfile); } message = "正在解包文件:>" + AppConst.PatchList; Util.Log("Game", infile); Util.Log("Game", outfile); if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } www.Dispose(); www = null; yield return(0); } else { File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); //释放所有文件到数据目录 FilesConfig filelist = JsonHelp.LoadFromJsonFile <FilesConfig>(outfile); List <ResInfo> mShardInfos = filelist.mShardInfos; int filesLen = mShardInfos.Count; int cur = 0; for (int i = 0; i < filesLen; i++) { string f = mShardInfos[i].ResName; infile = resPath + f; // outfile = dataPath + f; cur++; float value = cur / (float)filesLen; message = "正在解包文件:>" + f; kTips = new StringBuilder(); kTips.Append(message); kTips.Append(string.Format("{0:P}", value)); AppFacade.Instance.SendMessageCommand(NotiConst.UPDATE_MESSAGE, kTips.ToString()); AppFacade.Instance.SendMessageCommand(NotiConst.UPDATE_PROGRESS, value); string dir = Path.GetDirectoryName(outfile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } www.Dispose(); www = null; yield return(0); } else { if (File.Exists(outfile)) { File.Delete(outfile); } File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); } message = "解包完成!!!"; AppFacade.Instance.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); yield return(new WaitForSeconds(0.1f)); message = string.Empty; if (AppConst.UpdateMode) { StartCoroutine(OnUpdateResource());//释放完成,开始启动更新资源 } else { OnResourceInited(); Invoke("OnUpdateFinsh", 0.1f); } }
/// <summary> /// 启动更新下载,启动线程下载更新 /// </summary> IEnumerator OnUpdateResource() { string message = string.Empty; if (!AppConst.UpdateMode) { message = "完成"; OnResourceInited(); //yield return new WaitForSeconds(0.1f); Invoke("OnUpdateFinsh", 0.1f); yield break; } string LocalServerList = Util.GetLocalServerList(); string random = DateTime.Now.ToString("yyyymmddhhmmss"); string dataPath = Util.DataPath; //数据目录 WWW www = new WWW(AppConst.PublishServerListUrl + "?v=" + random); yield return(www); if (www.error != null) { OnResourceInited(); Invoke("OnUpdateFailed", 0.1f); Invoke("OnUpdateFinsh", 0.1f); www.Dispose(); www = null; yield break; } if (www.isDone) { if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } if (File.Exists(LocalServerList)) { File.Delete(LocalServerList); } FileStream fileStream = null; StreamWriter streamWriter = null; fileStream = new FileStream(LocalServerList, FileMode.Create); string data = www.text; streamWriter = new StreamWriter(fileStream); streamWriter.Write(data); streamWriter.Flush(); streamWriter.Close(); fileStream.Close(); } yield return(0); yield return(new WaitForEndOfFrame()); string url = AppConst.PatchListUrl; string listUrl = url + Util.GetPlatformWebUrl() + AppConst.PatchList + "?v=" + random; Util.Log("Game", "LoadUpdate---->>>" + listUrl); yield return(new WaitForSeconds(0.1f)); message = "正在验证资源...."; AppFacade.Instance.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); www = new WWW(listUrl); yield return(www); if (www.error != null) { OnResourceInited(); Invoke("OnUpdateFailed", 0.1f); Invoke("OnUpdateFinsh", 0.1f); www.Dispose(); www = null; yield break; } if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } File.WriteAllBytes(dataPath + AppConst.PatchList, www.bytes); string filesText = www.text; FilesConfig filelist = JsonHelp.ReadFromJsonString <FilesConfig>(filesText); List <ResInfo> mShardInfos = filelist.mShardInfos; string versionFloder = filelist.VerRevision.GetTxt(); AppConst.Version = versionFloder; versionFloder = versionFloder.Replace('.', '_'); string resUrl = filelist.PatchUrl + Util.GetPlatformWebUrl() + versionFloder + "/"; if (filelist.AutoUpdate == false) { OnResourceInited(); Invoke("OnUpdateFailed", 0.1f); Invoke("OnUpdateFinsh", 0.1f); www.Dispose(); www = null; yield break; } for (int i = 0; i < mShardInfos.Count; i++) { string f = mShardInfos[i].ResName; string localfile = (dataPath + f).Trim(); string path = Path.GetDirectoryName(localfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string fileUrl = resUrl + f + "?v=" + random; bool canUpdate = !File.Exists(localfile); if (!canUpdate) { string remoteMd5 = mShardInfos[i].md5; string localMd5 = Util.md5file(localfile); canUpdate = !remoteMd5.Equals(localMd5); if (canUpdate) { File.Delete(localfile); } } if (canUpdate) { //本地缺少文件 message = "downloading>>" + fileUrl; AppFacade.Instance.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message); BeginDownload(fileUrl, localfile); while (!(IsDownOK(localfile))) { yield return(new WaitForEndOfFrame()); } } } yield return(new WaitForEndOfFrame()); OnResourceInited(); message = "更新完成!!"; Invoke("OnUpdateFinsh", 0.08f); www.Dispose(); www = null; //AppFacade.Instance.SendMessageCommand(NotiConst.UPDATE_FINISHED, message); }
public PutFilesConsumer(ILogger <PutFilesConsumer> logger, IOptionsMonitor <FilesConfig> options) { this.logger = logger; this.options = options.CurrentValue; }
public FilesController(IRequestClient <IGetBookByIdRequest> client, IOptionsMonitor <FilesConfig> options, ILogger <FilesController> logger) { this.client = client; this.logger = logger; this.options = options.CurrentValue; }
public string ProcessFile(string filePath, FilesConfig fileConfig) { StringBuilder sb = new StringBuilder(); var fileName = Path.GetFileName(filePath); int totalReportedInFile = 0; switch (fileConfig.FileType) { case "TOUFile": var touEngine = new FileHelperEngine <TOUFile>(); var touRecords = touEngine.ReadFile(filePath); var dataTypeInFile = touRecords.Select(tou => tou.DataType).Distinct(); foreach (var dataType in dataTypeInFile) { var matchingrecords = touRecords.Where(tou => tou.DataType == dataType && tou.Energy != null) .ToList(); var recordsToCalculate = new List <Records>(); foreach (var record in matchingrecords) { recordsToCalculate.Add(new Records(record.Energy.Value, record.DateTime)); } sb.Append(ReportOutlier(recordsToCalculate, fileName, fileConfig.DevianceThresholdPercentage, ref totalReportedInFile)); } break; case "LPFile": var lpEngine = new FileHelperEngine <LPFile>(); var lpRecords = lpEngine.ReadFile(filePath); var lpdataTypeInFile = lpRecords.Select(lp => lp.DataType).Distinct(); foreach (var dataType in lpdataTypeInFile) { var matchingrecords = lpRecords.Where(lp => lp.DataType == dataType && lp.DataValue != null) .ToList(); var recordsToCalculate = new List <Records>(); foreach (var record in matchingrecords) { recordsToCalculate.Add(new Records(record.DataValue.Value, record.DateTime)); } sb.Append(ReportOutlier(recordsToCalculate, fileName, fileConfig.DevianceThresholdPercentage, ref totalReportedInFile)); } break; default: throw new NotImplementedException($"{fileConfig.FileType} File Type has not been implemented"); } if (totalReportedInFile > 0) { sb.AppendLine($"Total Reported in File {totalReportedInFile}"); } return(sb.ToString()); }
public StringBuilder GetTextoAto(DtoInfAto dtoInfAto) { StringBuilder textoDoc = new StringBuilder(); FilesConfig fileConfig = new FilesConfig(); DtoDadosAto dtoDadosAto = new DtoDadosAto { Id = dtoInfAto.IdAto, IdTipoAto = dtoInfAto.IdTipoAto, IdLivro = dtoInfAto.IdLivro, IdModeloDoc = dtoInfAto.IdModeloDoc, IdPrenotacao = dtoInfAto.IdPrenotacao, NumMatricula = dtoInfAto.NumMatricula, DataRegPrenotacao = dtoInfAto.DataRegPrenotacao, DataAto = dtoInfAto.DataAto }; DadosAtoSimplificado dadosAto = new DadosAtoSimplificado { IdAto = dtoInfAto.IdAto, IdTipoAto = dtoInfAto.IdTipoAto, IdLivro = dtoInfAto.IdLivro, IdModeloDoc = dtoInfAto.IdModeloDoc, IdPrenotacao = dtoInfAto.IdPrenotacao, NumMatricula = dtoInfAto.NumMatricula, DataRegPrenotacao = dtoInfAto.DataRegPrenotacao, DataAto = dtoInfAto.DataAto }; if (dtoInfAto.IdAto.HasValue && (dtoInfAto.IdAto > 0)) { //dtoDadosAto = GetDadosAto(dtoInfAto.IdAto ?? 0); //todo: catregar do ato fazer } else { dtoDadosAto.ListaCamposValor.AddRange(this.GetListCamposPovoados("Ato", dadosAto)); dtoDadosAto.ListaCamposValor.AddRange(this.GetListCamposPovoados("Prenotacao", dadosAto)); dtoDadosAto.ListaCamposValor.AddRange(this.GetListCamposPovoados("Imovel", dadosAto)); dtoDadosAto.Pessoas = this.GetListPessoas(dtoInfAto.IdTipoAto, dtoInfAto.ListIdsPessoas, dtoInfAto.IdPrenotacao).ToList(); //obter filename string fileName = Path.Combine(dtoInfAto.ServerPath, fileConfig.GetModeloDocFileName(dtoInfAto.IdModeloDoc)); //dtoDadosAto.Pessoas = this.GerarFichas using (AtoWordDocx atoWordDocx = new AtoWordDocx(this, dtoInfAto.IdCtaAcessoSist, fileName)) { StringBuilder textoTmp = new StringBuilder(); // Get content from each paragraph foreach (Paragraph paragraph in atoWordDocx.WordDocument.GetChildElements(true, ElementType.Paragraph)) { textoTmp.Append(paragraph.Content.ToString()); } string texto = textoTmp.ToString(); if (texto != "") { string strAto = string.Empty; string strBloco = string.Empty; bool flagBloco = false; TipoPessoaPrenotacao tipoPes = TipoPessoaPrenotacao.indefinido; for (int i = 0; i < texto.Length; i++) { if (texto[i] == '[') { i++; string nomeCampo = string.Empty; string resultadoQuery = string.Empty; while (texto[i] != ']') { nomeCampo += texto[i].ToString().Trim(); i++; if (i >= texto.Length || texto[i] == '[') { throw new FormatException("Arquivo com campos corrompidos, verifique o modelo"); } } //Buscar dado da pessoa aqui //resultadoQuery = "teste query"; var CampoValor = dtoDadosAto.ListaCamposValor.Where(c => c.Campo == nomeCampo).FirstOrDefault(); if (CampoValor != null) { resultadoQuery = StringFunctions.Capitalize(CampoValor.Valor); } else { var CampoOutorgado = dtoDadosAto.Pessoas .Where(p => p.TipoPessoa == TipoPessoaPrenotacao.outorgado).FirstOrDefault().ListaCamposValor .Where(c => c.Campo == nomeCampo).FirstOrDefault(); if (CampoOutorgado != null) { resultadoQuery = StringFunctions.Capitalize(CampoOutorgado.Valor); } else { var CampoOutorgante = dtoDadosAto.Pessoas .Where(p => p.TipoPessoa == TipoPessoaPrenotacao.outorgante).FirstOrDefault().ListaCamposValor .Where(c => c.Campo == nomeCampo).FirstOrDefault(); if (CampoOutorgante != null) { resultadoQuery = StringFunctions.Capitalize(CampoOutorgante.Valor); } } } if (!string.IsNullOrEmpty(resultadoQuery)) { strAto += resultadoQuery; } else { strAto += "[" + nomeCampo + "]"; } } else if (texto[i] == '<') { i++; string tipoTag = string.Empty; while (texto[i] != '>') { tipoTag += texto[i].ToString().Trim(); i++; if (i >= texto.Length || texto[i] == '<') { throw new FormatException("Tags de repetição corrompidas, verifique o modelo"); } } i++; if (flagBloco) { strAto += GetTextoBloco(tipoPes, dtoDadosAto.Pessoas, strBloco); } if (tipoTag.ToLower().Equals("outorgantes")) { tipoPes = TipoPessoaPrenotacao.outorgante; } else if (tipoTag.Equals("outorgados")) { tipoPes = TipoPessoaPrenotacao.outorgado; } strBloco = string.Empty; flagBloco = !flagBloco; } else { //caso não seja um campo somente adiciona o caractere strAto += texto[i].ToString(); } strBloco += texto[i].ToString(); } // Populando campo de retorno textoDoc.Append($"<p>{strAto}</p>"); } } } return(textoDoc); }