public FileObject AddFile(string relativeFileName, Stream fileContent, FileOption fileOption, int bufferSize) { var file = new FileObject(FullName + relativeFileName); file.Write(fileContent, fileOption, bufferSize); return(file); }
/// <inheritdoc /> public void SerializeToFile <T>(T obj, string file, FileOption mode) where T : class { obj.IsNullThrow(nameof(obj)); file.IsNullThrow(nameof(file)); mode.IsNullThrow(nameof(mode)); SerializeToFile(obj, typeof(T), file, mode); }
/// <summary> /// 构造函数 /// </summary> /// <param name="gpt2FilePath"></param> public Gpt2DataService(FileOption gpt2FilePath) : base(gpt2FilePath) { Gpt2File = new Gpt2FileReader(this.Option.FilePath).Read(); Data = new Dictionary <string, Gpt2Res>(); }
public void Add(string fileFullPath, FileOption option = FileOption.Overwrite, WriterOptions writerOptions = null) { Add(new List <string>() { fileFullPath }, option, writerOptions); }
/// <summary> /// Prepares for stream use. Prevents Exeception From Being Throwned When working with file Streams /// </summary> /// <param name="option">The option.</param> /// <exception cref="ArgumentOutOfRangeException">option - null</exception> internal void PrepareForStreamUse(FileOption option) { switch (option) { case FileOption.Append: CreateOrTruncate(false); break; case FileOption.Overwrite: CreateOrTruncate(); break; case FileOption.DoNothingIfExist: if (Exist == true) { return; } CreateOrTruncate(); break; case FileOption.IncrementFileNameIfExist: case FileOption.IncrementFileExtensionIfExist: break; case FileOption.ReadOnly: break; default: throw new ArgumentOutOfRangeException(nameof(option), option, null); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="gpt2FilePath"></param> public Gpt2DataService1Degree(FileOption gpt2FilePath) : base(gpt2FilePath) { gpt2File1Degree = new Gpt2FileReader1Degree(this.Option.FilePath).Read(); Data = new ConcurrentDictionary <string, Gpt2Res1Degree>(); }
/// <inheritdoc /> /// <summary> /// Serializes to file. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list">The list.</param> /// <param name="fullFilePath">The full file path.</param> /// <param name="mode">The mode.</param> public void SerializeToFile <T>(IEnumerable <T> list, string fullFilePath, FileOption option) where T : class { list.IsNullThrow(nameof(list)); fullFilePath.IsNullThrow(nameof(fullFilePath)); option.IsNullThrow(nameof(option)); var a = new FileObject(fullFilePath); if (option == FileOption.DoNothingIfExist) { if (a.Exist == true) { return; } } using (var sw = a.GetStreamWriter(false)) { var csv = new CsvWriter(sw, Configuration); csv.WriteRecords(list); } // using (var stream = a.GetFileStream(mode)) // { // SerializeToStream(list, stream); // } }
/// <summary> /// Returns a dictionary where file names are /// used as keys, and absolute file paths are /// values. /// </summary> /// /// <exception cref="FileNotFoundException"/> /// /// <exception cref="ArgumentException"> public virtual ReadOnlyDictionary <string, string> GetIncludeItems(ReferenceType type) { FileOption option = GetFileOption(type); Dictionary <string, string> output = new Dictionary <string, string>(30); foreach (string directory in option.Include) { if (!Directory.Exists(directory)) { MessageHelper.AddMessage($"Directory: { directory } does not exist and will be skipped", TaskErrorCategory.Warning); continue; } foreach (string absolutePath in Directory.GetFiles(directory, option.Pattern, SearchOption.AllDirectories).Where(i => !Contains(option.Exclude, i))) { string key = Path.GetFileNameWithoutExtension(absolutePath); if (!output.ContainsKey(key)) { output.Add(key, absolutePath); } else { MessageHelper.AddMessage($"Project: { absolutePath } is a duplicate and will be skipped", TaskErrorCategory.Warning); } } } return(new ReadOnlyDictionary <string, string>(output)); }
/// <summary> /// 构造函数。可以指定文件路径,但此处并不读取,。 /// </summary> /// <param name="filePath"></param> public SphericalHarmonicsService(FileOption filePath) { var reader = new SphericalHarmonicsReader(filePath); this.File = reader.Read(); Name = Path.GetFileName(filePath.FilePath); }
/// <summary> /// 构造函数。可以指定文件路径,但此处并不读取,需要调用Read()方法才读取。 /// </summary> /// <param name="filePath"></param> public SatExcludeFileService(FileOption filePath) : base(filePath) { SatExcludeReader reader = new SatExcludeReader(filePath); reader.Read(); this.ExcludeSats = reader.ExcludeSats; }
public void Add(FileObject fileObject, FileOption option = FileOption.Overwrite, WriterOptions writerOptions = null) { Add(new List <FileObject>() { fileObject }, option, writerOptions); }
/// <summary> /// 卫星状态数据源 /// </summary> /// <param name="filePath">文件路径</param> public SatInfoService(FileOption filePath) : base(filePath) { if (filePath != null) { this.SatInfoFile = new SatInfoReader(filePath.FilePath).Read(); } }
/// <summary> /// 天线数据源。 /// </summary> /// <param name="antennaPath">天线文件路径</param> public AntennaFileService(FileOption antennaPath) : base(antennaPath) { this.Option = antennaPath; this.antexReader = new AntexReader(antennaPath.FilePath); this.typedBuffer = new Dictionary <string, Antenna>(); this.serialEpochBuffer = new Dictionary <string, Dictionary <BufferedTimePeriod, Antenna> >(); }
/// <summary> /// Changes the extension of the current file. Does nothing if file doesn't exist return boolean on whether or not the file extension actually got change /// /// </summary> /// <param name="newExtension"></param> /// <param name="option"></param> /// <param name="cancellationToken"></param> /// <param name="bufferSize"></param> /// <exception cref="Exception"></exception> /// <exception cref="UnauthorizedAccessException"> throws if the application doesn't have the required permission </exception> public async Task <bool> ChangeExtensionAsync(string newExtension, FileOption option, CancellationToken cancellationToken = default, int bufferSize = 4096) { if (newExtension == null) { throw new NullReferenceException($"Could not change the extension of file {FullName} Because Developer Provided A Null Value"); } return(await MoveToAsync(Path.ChangeExtension(FullName, newExtension), option, cancellationToken, bufferSize)); }
public FileObject AddFile(string relativeFileName, byte[] fileContent, FileOption fileOption, int offset = 0, int?count = null) { var file = new FileObject(FullName + relativeFileName); file.Write(fileContent, fileOption, offset, count); return(file); }
///// <summary> ///// Sets the file attribute. ///// </summary> ///// <param name="option">The option.</param> ///// <param name="list">The list.</param> //public void SetFolderAttribute(AddOrRemoveEnum option, List<FileAttributes> list) //{ // if (Exist != true) // return; // try // { // if (option == AddOrRemoveEnum.Add) // { // foreach (var attr in list) // { // var di = new DirectoryInfo(FullName); // di.Attributes &= ~attr; // } // } // else if (option == AddOrRemoveEnum.Remove) // { // foreach (var attr in list) // { // var di = new DirectoryInfo(FullName); // di.Attributes &= attr; // } // } // } // catch (Exception) // { // // ignored because this require the user to have full control permission set and we don't problems over that // // if developer is doing something that require full conrol permission let the application throw the error // } //} public FileObject AddFile(string relativeFileName, string fileContent, FileOption fileOption, Encoding encoding = null, int bufferSize = 4096) { var file = new FileObject(FullName + relativeFileName); file.Write(fileContent, fileOption, encoding, bufferSize); return(file); }
/// <summary> /// 坐标服务 /// </summary> public SiteCoordService(FileOption option) { this.FileOption = option; this.Name = Path.GetFileName(option.FilePath); this.NamedRmsXyzes = new BaseDictionary <string, NamedRmsXyz>(); log.Info("启用了坐标文件服务。"); }
/// <summary> /// Gets the file stream. /// </summary> /// <param name="option">The option.</param> /// <param name="bufferSize"></param> /// <param name="useAsync"></param> /// <returns>FileStream.</returns> /// <exception cref="ArgumentOutOfRangeException">option - null</exception> /// <exception cref="FileNotFoundException"></exception> public (FileStream fileStream, string fullName) GetFileStream(FileOption option, int bufferSize = 4096, bool useAsync = false) { var fileOptions = useAsync ? (FileOptions.Asynchronous | FileOptions.SequentialScan) : FileOptions.None; (FileStream fileStream, string fullName)stream; switch (option) { case FileOption.ReadOnly: stream = (new FileStream(FullName, FileMode.Open, FileAccess.Read, FileShare.Read), FullName); break; case FileOption.Append: PrepareForStreamUse(option); stream = GetFileStream(FileMode.Append, FileAccess.Write, FileShare.Read, bufferSize, fileOptions); if (stream.fileStream.CanSeek) { stream.fileStream.Seek(0, SeekOrigin.End); } break; case FileOption.Overwrite: PrepareForStreamUse(option); stream = GetFileStream(FileMode.Truncate, FileAccess.Write, FileShare.Read, bufferSize, fileOptions); stream.fileStream.Seek(0, SeekOrigin.Begin); break; case FileOption.IncrementFileNameIfExist: stream = GetFileStream(FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferSize, fileOptions, true); stream.fileStream.Seek(0, SeekOrigin.Begin); break; case FileOption.IncrementFileExtensionIfExist: stream = GetFileStream(FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferSize, fileOptions, false, true); stream.fileStream.Seek(0, SeekOrigin.Begin); break; case FileOption.DoNothingIfExist: if (Exist) { stream = GetFileStream(FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, fileOptions); stream.fileStream.Seek(0, SeekOrigin.Begin); break; } else { stream = GetFileStream(FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferSize, fileOptions); if (stream.fileStream.CanSeek) { stream.fileStream.Seek(0, SeekOrigin.End); } break; } default: throw new ArgumentOutOfRangeException(nameof(option), option, null); } return(stream); }
static void Main() { try { // load runsource.runsource.config.xml (config of runsource.runsource.exe) XmlConfig config = new XmlConfig(); FormatInfo.SetInvariantCulture(); Application.CurrentCulture = FormatInfo.CurrentFormat.CurrentCulture; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RemoteRunSource remoteRunSource = new RemoteRunSource(); remoteRunSource.RunsourceDllFilename = config.GetExplicit("RunsourceDllFilename"); remoteRunSource.RunsourceClassName = config.GetExplicit("RunsourceClassName"); remoteRunSource.TraceManagerClassName = config.GetExplicit("TraceManagerClassName"); remoteRunSource.TraceClassName = config.GetExplicit("TraceClassName"); // ATTENTION si CreateRunSourceDomain = true runsource.launch.exe ne peut pas mettre à jour runsource.runsource.exe remoteRunSource.CreateRunSourceDomain = config.Get("CreateRunSourceDomain").zTryParseAs <bool>(false); IRunSource runSource = remoteRunSource.GetRunSource(); //remoteRunSource.LoadRunsourceCommand(); //runSource.AllowMultipleExecution = config.Get("AllowMultipleExecution").zTryParseAs(false); ///////////////////////// donc il faut utiliser RemoteRunSource.GetTrace() //ITrace trace = remoteRunSource.GetTrace(); //trace.SetWriter(config.Get("Log"), config.Get("Log/@option").zTextDeserialize(FileOption.None)); // ATTENTION Trace exists in both 'runsource.runsource.exe' and 'runsource.dll' // both Trace are connected to TraceManager and can be used string logFile = config.Get("Log"); FileOption logFileOption = config.Get("Log/@option").zTextDeserialize(FileOption.None); TraceManager.Current.AddTrace(Trace.Current); //TraceManager.Current.SetWriter(logFile, logFileOption); TraceManager.Current.SetWriter(WriteToFile.Create(logFile, logFileOption)); ITraceManager remoteTraceManager = remoteRunSource.GetTraceManager(); remoteTraceManager.AddTrace(remoteRunSource.GetTrace()); //remoteTraceManager.SetWriter(logFile, logFileOption); remoteTraceManager.SetWriter(WriteToFile.Create(logFile, logFileOption)); // ATTENTION appeler DeleteGeneratedAssemblies() après SetRunSourceConfig() //RunSourceForm form = new RunSourceForm(runSource, trace, config, GetRunSourceRestartParameters()); //RunSourceForm_v3 form = new RunSourceForm_v3(runSource, trace, config, GetRunSourceRestartParameters()); //RunSourceFormExe form = new RunSourceFormExe(runSource, trace, config, GetRunSourceRestartParameters()); RunSourceFormExe form = new RunSourceFormExe(runSource, config, remoteRunSource, GetRunSourceRestartParameters()); RunSourceFormExe.Current = form; form.SetRestartRunsource += FormSetRestartRunsource; Application.Run(form); TraceManager.Current.RemoveTrace(Trace.Current); TraceManager.Current.RemoveTrace(remoteRunSource.GetTrace()); SetRunSourceRestartParameters(); } catch (Exception ex) { zerrf.ErrorMessageBox(ex); } }
public JsonTraceDataWriter(string file, FileOption option, Encoding encoding = null, JsonWriterSettings settings = null) { file = file.zRootPath(zapp.GetAppDirectory()); if (option == FileOption.IndexedFile) file = zfile.GetNewIndexedFileName(zPath.GetDirectoryName(file), zPath.GetFileName(file)); //_streamWriter = zFile.CreateText(file); Open(file, encoding, option != FileOption.RazFile); _closeStreamWriter = true; InitSettings(settings); }
private async void LoadTextEncryptionButton_Click(object sender, RoutedEventArgs e) { var sourceTextFile = await FileOption.SelectTextSourceImageFile(); if (sourceTextFile == null) { return; } this.readContentsofTheFile(sourceTextFile); }
/// <summary> /// Writes the content to file. Returns the full file name content was written to. This method is not thread safe /// </summary> /// <param name="content">The content.</param> /// <param name="encoding">default to UTF-8</param> /// <param name="option">The option.</param> /// <param name="bufferSize"></param> public string Write(string content, FileOption option = FileOption.Overwrite, Encoding encoding = null, int bufferSize = 4096) { if (option == FileOption.DoNothingIfExist && Exist) { return(FullName); } var(fileStream, fullName) = GetFileStream(option); using var sw = new StreamWriter(fileStream, encoding ?? DefaultEncoding, bufferSize, false); sw.Write(content); return(fullName); }
/// <summary> /// Writes the content to file. Returns the full file name content was written to. This method is not thread safe /// </summary> /// <param name="stream"></param> /// <param name="progress">Report progress in stream bytes not percentages. </param> /// <param name="option">The option.</param> /// <param name="bufferSize"></param> public string Write(Stream stream, IProgress <long> progress, FileOption option = FileOption.Overwrite, int bufferSize = 4096) { if (option == FileOption.DoNothingIfExist && Exist) { return(FullName); } var(fileStream, fullName) = GetFileStream(option); using (fileStream) stream.CopyTo(fileStream, progress, bufferSize); return(fullName); }
/// <summary> /// Copy the current file to the destination. Returns the destination file name /// </summary> /// <param name="copyToFullName"></param> /// <param name="option"></param> /// <param name="cancellationToken"></param> /// <param name="bufferSize"></param> /// <returns>The copy to file</returns> public async Task <string> CopyToAsync(string copyToFullName, FileOption option, CancellationToken cancellationToken = default, int bufferSize = 4096) { using var sourceStream = GetFileStream(FileOption.ReadOnly, bufferSize, true).fileStream; var fileStreamAndFileName = new FileObject(copyToFullName).GetFileStream(option, bufferSize, true); using (var destinationStream = fileStreamAndFileName.fileStream) { await sourceStream.CopyToAsync(destinationStream, bufferSize, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); } return(fileStreamAndFileName.fullName); }
public JsonTraceDataWriter(string file, FileOption option, Encoding encoding = null, JsonWriterSettings settings = null) { file = file.zRootPath(zapp.GetAppDirectory()); if (option == FileOption.IndexedFile) { file = zfile.GetNewIndexedFileName(zPath.GetDirectoryName(file), zPath.GetFileName(file)); } //_streamWriter = zFile.CreateText(file); Open(file, encoding, option != FileOption.RazFile); _closeStreamWriter = true; InitSettings(settings); }
public static WriteToFile Create(string file, FileOption option, Encoding encoding = null) { if (file != null) { file = file.zRootPath(zapp.GetAppDirectory()); if (option == FileOption.IndexedFile) return new WriteToFile(() => zfile.GetNewIndexedFileName(zPath.GetDirectoryName(file), zPath.GetFileName(file)), encoding); else return new WriteToFile(file, encoding, appendToFile: option != FileOption.RazFile); } else return null; }
private static void ReplaceSelectableOption(string replaceOptionName, FileOption <FileStream> newOption, List <IOption> selectableOptions) { IOption currentOption = selectableOptions.FirstOrDefault(x => x.Name == replaceOptionName); if (currentOption != null) { newOption.ApiName = currentOption.ApiName; newOption.IsAssigned = false; newOption.Name = currentOption.Name; selectableOptions.Remove(currentOption); selectableOptions.Add(newOption); } }
/// <summary> /// Writes the bytes to file. Returns the full file name content was written to. This method is not thread safe /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="option">The option.</param> /// <param name="offset"></param> /// <param name="count"></param> /// <param name="cancellationToken"></param> public async Task <string> WriteAsync(byte[] bytes, FileOption option = FileOption.Overwrite, int offset = 0, int?count = null, CancellationToken cancellationToken = default) { if (option == FileOption.DoNothingIfExist && Exist) { return(FullName); } var(fileStream, fullName) = GetFileStream(option); using (fileStream) { await fileStream.WriteAsync(bytes, offset, count.GetValueOrDefault(bytes.Length), cancellationToken); } return(fullName); }
/// <summary> /// Writes the bytes to file. Returns the full file name content was written to. This method is not thread safe /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="option">The option.</param> /// <param name="offset"></param> /// <param name="count"></param> public string Write(byte[] bytes, FileOption option = FileOption.Overwrite, int offset = 0, int?count = null) { if (option == FileOption.DoNothingIfExist && Exist) { return(FullName); } var(fileStream, fullName) = GetFileStream(option); using (fileStream) { fileStream.Write(bytes, offset, count.GetValueOrDefault(bytes.Length)); } return(fullName); }
public ValueTask <FileOption <long> > GetFileOptionAsync(long ID, string alternateDataStream) { var ret = FileOption <long> .Create(ID, alternateDataStream); if (!string.IsNullOrEmpty(alternateDataStream)) { return(new ValueTask <FileOption <long> >(ret)); } using (var da = new Models.Context()) { var row = da.Files.Find(ID); if (row == null) { return(default);
private async void LoadPictureEncryptionButton_Click(object sender, RoutedEventArgs e) { this.sizeErrorMessage.Visibility = Visibility.Collapsed; var sourceImageFile = await FileOption.SelectSourceImageFile(); if (sourceImageFile == null) { return; } var copyBitmapImage = await sourceImageFile.MakeCopyOfImage(); this.imageUsedToEncrypt = sourceImageFile; this.encryptingImage.Source = copyBitmapImage; }
/// <inheritdoc /> /// <summary> /// Serializes to file. /// </summary> /// <param name="obj">The obj.</param> /// <param name="file">The file.</param> /// <exception cref="T:System.ArgumentNullException">obj</exception> public void SerializeToFile(object obj, string fullFilePath, FileOption option = FileOption.DoNothingIfExist) { var file = new FileObject(fullFilePath); if (option == FileOption.DoNothingIfExist) { if (file.Exist == true) { return; } } using (Stream stream = file.GetFileStream(option)) { SerializeToStream(obj, stream); } }
public ImagesBrowseViewModel( Action<FileModel> callback, string path = "", bool onlyImage = false) { //_window = window; _callback = callback; _rootPath = _path = path; if (onlyImage) // 将不能创建和 显示 删除 文件夹 { _fileOption = FileOption.File; } _okCommand = new DelegateCommand(OK, CanOK); _uploadCommand = new DelegateCommand(Upload); _createDirectoryCommand = new DelegateCommand(CreateDirectory, CanCreateDirectory); _backCommand = new DelegateCommand(Back, CanBack); _deleteCommand = new DelegateCommand(Delete, CanDelete); _refreshCommand = new DelegateCommand(Refresh, CanRefresh); _openCommand = new DelegateCommand<FileModel>(Open); _renameCommand = new DelegateCommand(Rename, CanRename); _selectedItems.CollectionChanged += SelectedItems_CollectionChanged; Refresh(); }
public CustomizedAppSettings(string fileName, FileOption fileOption) : base(fileName, fileOption) { }
public IEnumerable<FileModel> SearchFiles(string searchPattern, FileOption fileOption) { var root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Upload"); var length = root.Length; var physicalPath = root; if (!Directory.Exists(physicalPath)) { Directory.CreateDirectory(physicalPath); } var rootDirectoryInfo = new DirectoryInfo(physicalPath); if (fileOption != FileOption.File) { var directoryInfos = rootDirectoryInfo.GetDirectories(searchPattern, SearchOption.AllDirectories); foreach (var directoryInfo in directoryInfos) { yield return new FileModel() { Url = "Directory", Name = directoryInfo.Name, DisplayName = directoryInfo.Name, CreationTime = directoryInfo.CreationTime, ModifyTime = directoryInfo.LastWriteTime, IsDirectory = true, DirectoryName = directoryInfo.Parent.FullName.Remove(0, length), }; } } if (fileOption != FileOption.Directory) { var fileInfos = rootDirectoryInfo.GetFiles(searchPattern, fileOption != FileOption.File ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Where( file => string.Compare("*.jpg", file.Extension, true) == 0 || string.Compare("*.png", file.Extension, true) == 0 ); foreach (var fileInfo in fileInfos) { using (var pic = Image.FromFile(fileInfo.FullName)) { yield return new FileModel() { Url = fileInfo.FullName.Remove(0, length).Replace("\\", "/").Trim('/'), Name = fileInfo.Name, DisplayName = fileInfo.Name, FileSize = fileInfo.Length, CreationTime = fileInfo.CreationTime, ModifyTime = fileInfo.LastWriteTime, Height = pic.Height, Width = pic.Width, DirectoryName = fileInfo.DirectoryName.Remove(0, length), }; } } } }
public IEnumerable<FileModel> GetImages(string path, FileOption fileOption) { var root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Upload"); var length = root.Length; var physicalPath = Path.Combine(root, path.Trim('\\')); if (!Directory.Exists(physicalPath)) { Directory.CreateDirectory(physicalPath); } var rootDirectoryInfo = new DirectoryInfo(physicalPath); if (fileOption != FileOption.File) { var directoryInfos = rootDirectoryInfo.GetDirectories(); foreach (var directoryInfo in directoryInfos) { yield return new FileModel() { Url = "Directory", Name = directoryInfo.Name, DisplayName = directoryInfo.Name, CreationTime = directoryInfo.CreationTime, ModifyTime = directoryInfo.LastWriteTime, IsDirectory = true, DirectoryName = directoryInfo.Parent.FullName.Remove(0, length), }; } } if (fileOption != FileOption.Directory) { var fileInfos = rootDirectoryInfo.GetFiles("*.jpg").Union(rootDirectoryInfo.GetFiles("*.png")); foreach (var fileInfo in fileInfos) { using (var pic = Image.FromFile(fileInfo.FullName)) { yield return new FileModel() { Url = fileInfo.FullName.Remove(0, length).Replace("\\", "/").Trim('/'), Name = fileInfo.Name, DisplayName = fileInfo.Name, FileSize = fileInfo.Length, CreationTime = fileInfo.CreationTime, ModifyTime = fileInfo.LastWriteTime, Height = pic.Height, Width = pic.Width, DirectoryName = fileInfo.DirectoryName.Remove(0, length), }; } } } }
public void SetWriter(string file, FileOption option, Encoding encoding = null) { SetWriter(WriteToFile.Create(file, option, encoding)); }