public Writer <T> AddInput <T>(string name) { if (_state != 0) { throw new InvalidOperationException(); } if (name == null) { throw new ArgumentException(); } var n = Get(NameType.From <T>(name)); if (n.SourceWriter != null) { throw new InvalidOperationException(); } if (Log.IsInfo) { Log.Info($"AddInput: {name}, {typeof(T)}"); } var w = new WriterSetAction <T>(); var wi = new WriterInfo(name, w, n); _writers.Add(wi); n.SourceWriter = wi; return(w); }
/// <summary> /// 根据要导出的单元类型,返回一个 StreamWriter,以存储用于在Flac3D中创建此类结构的命令语句 /// </summary> /// <param name="commandType"> 要写入的命令文本的类型 </param> /// <param name="writerName">写入的文本文件的名称,不包括后缀名 </param> /// <param name="fileSuffix"> 用户强行指定的文本后缀,如果不指定,则由<paramref name="commandType"/>来确定文件后缀。 </param> /// <param name="selId"> 结构单元所属的集合Id,如果没有Id,则赋值为 null </param> /// <returns></returns> public StreamWriter GetWriter(Flac3DCommandType commandType, string writerName, int?selId) { // 确定文件名 string fileName = writerName + GetFileSuffix(commandType); if (_openedWriters.ContainsKey(fileName)) { return(_openedWriters[fileName].Writer); } else // 说明此文本还未创建 { string filePath = Path.Combine(GetCommandDirectory(), fileName); // 新建一个文本文档并将相关信息保存下来 FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); // WriterInfo wi = new WriterInfo(commandType, fileName, sw) { Id = selId, }; _openedWriters.Add(fileName, wi); return(sw); } }
public async Task <ApiResult> Create(string name, string username, string userpwd) { //数据校验 WriterInfo writer = new WriterInfo { Name = name, //加密密码 UserPwd = MD5Helper.MD5Encrypt32(userpwd), UserName = username }; //判断数据库中是否已经存在账号跟要添加的账号相同的数据 var oldWriter = await _iWriterInfoService.FindAsync(c => c.UserName == username); if (oldWriter != null) { return(ApiResultHelper.Error("账号已经存在")); } bool b = await _iWriterInfoService.CreateAsync(writer); if (!b) { return(ApiResultHelper.Error("添加失败")); } return(ApiResultHelper.Success(writer)); }
/// <summary> /// 新增一个命令文本,用来统领整个建模过程 /// </summary> private void WriteMain() { var names = _openedWriters.Keys.ToList(); if (names.Count > 0) { string filePath = Path.Combine(GetCommandDirectory(), FileMain + FileSuffixSel); FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); // sw.WriteLine( @"new set pr 30 ; 使用的cpu核数 set fish safe_conversion off set nmd on ; When nmd is on, any tetrahedral zones will use the nmd algorithm during the stress calculations. set notice on ; controls whether informational messages generated by the program during command processing will be sent to the screen and the log file set warning off ; controls whether warning messages generated by the program during command processing will be sent to the screen and the log file set echo off; ; This file is just for reference of calling the exported components. "); // 因为土体单元的文件后缀不同,所以进行特殊处理 const string zoneCommandFile = FileZone + FileSuffixZone; if (names.Contains(zoneCommandFile, StringComparer.OrdinalIgnoreCase)) { sw.WriteLine($"ImpGrid {zoneCommandFile}"); names.Remove(zoneCommandFile); } // 其他结构单元 foreach (var name in names) { WriterInfo wi = _openedWriters[name]; //添加注释 string comments = null; if (wi.Id != null) { comments = $" \t; Id: {wi.Id}"; } // sw.WriteLine($"Call {name}{comments}"); } // sw.Close(); sw.Dispose(); } }
/** * Add a new writer's memory allocation to the pool. We use the path * as a unique key to ensure that we don't get duplicates. * @param path the file that is being written * @param requestedAllocation the requested buffer size */ public virtual void addWriter(string path, long requestedAllocation, Callback callback) { checkOwner(); WriterInfo oldVal = writerList.get(path); // this should always be null, but we handle the case where the memory // manager wasn't told that a writer wasn't still in use and the task // starts writing to the same path. if (oldVal == null) { oldVal = new WriterInfo(requestedAllocation, callback); writerList.Add(path, oldVal); totalAllocation += requestedAllocation; } else { // handle a new writer that is writing to the same path totalAllocation += requestedAllocation - oldVal.allocation; oldVal.allocation = requestedAllocation; oldVal.callback = callback; } updateScale(true); }
/** * Remove the given writer from the pool. * @param path the file that has been closed */ public virtual void removeWriter(string path) { checkOwner(); WriterInfo val = writerList.get(path); if (val != null) { writerList.Remove(path); totalAllocation -= val.allocation; if (writerList.Count == 0) { rowsAddedSinceCheck = 0; } updateScale(false); } else { System.Diagnostics.Debugger.Break(); } if (writerList.Count == 0) { rowsAddedSinceCheck = 0; } }