///<summary> /// Retrieves the Type field</summary> /// <returns>Returns nullable File enum representing the Type field</returns> new public File?GetType() { object obj = GetFieldValue(0, 0, Fit.SubfieldIndexMainField); File? value = obj == null ? (File?)null : (File)obj; return(value); }
/// <summary> /// Add existing files to the folder. /// </summary> /// <returns>A list of <see cref="File"/> items added to the folder.</returns> public async Task <IEnumerable <File> > AddExistingFilesAsync(params string[] filePaths) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out _); VSADDRESULT[] result = new VSADDRESULT[filePaths.Count()]; IVsProject ip = (IVsProject)hierarchy; ErrorHandler.ThrowOnFailure(ip.AddItem(itemId, VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE, string.Empty, (uint)filePaths.Count(), filePaths, IntPtr.Zero, result)); List <File> files = new(); foreach (string filePath in filePaths) { File?file = await File.FromFileAsync(filePath); if (file != null) { files.Add(file); } } return(files); }
public AnalyseDependenciesSettings( File?project, Folder?folder) { Project = project; Folder = folder; }
public override Response Execute() { switch (data.r) { case Response.None: File?fn = (shell.CurrentMachine as DataBase).GetFile(data.parameters[0]); if (fn == null) { return(Response.NameError); } File f = fn.Value; shell.Print("==== File begin ====", true); shell.Print(f.file.text); shell.Print("==== File end ====\n", true); break; case Response.NameError: shell.Print("Could not open the requested file since there's no file named " + data.parameters[0] + ". Did you misspel the name?"); break; } return(Response.Finished); }
public long AddFileData(byte[] data, int pos, int len) { long totalSize = currentFile !.CurrentSize + len; if (totalSize > currentFile.Size) { throw new ApplicationException("totalSize > currentFile.Size"); } if (currentFile.Compress == false) { fifo.Write(data, pos, len); } else { Basic.Internal.ZStream zs = currentFile.ZStream !; byte[] srcData = Util.ExtractByteArray(data, pos, len); byte[] dstData = new byte[srcData.Length * 2 + 100]; zs.next_in = srcData; zs.avail_in = srcData.Length; zs.next_in_index = 0; zs.next_out = dstData; zs.avail_out = dstData.Length; zs.next_out_index = 0; if (currentFile.Size == (currentFile.CurrentSize + len)) { zs.deflate(Basic.Internal.zlibConst.Z_FINISH); } else { zs.deflate(Basic.Internal.zlibConst.Z_SYNC_FLUSH); } fifo.Write(dstData, 0, dstData.Length - zs.avail_out); currentFile.CompressSize += dstData.Length - zs.avail_out; Util.NoOP(); } currentFile.CurrentSize += len; currentFile.Crc32 = ZipUtil.Crc32Next(data, pos, len, currentFile.Crc32); long ret = currentFile.Size - currentFile.CurrentSize; if (ret == 0) { currentFile.Crc32 = ~currentFile.Crc32; addFileFooter(); currentFile = null; } return(ret); }
public bool Equals(File?other) { if (other is null) { return(IsEmpty); } return(Equals(other.Value)); }
public async Task <Either <ActionResult, Unit> > ValidateDataFilesForUpload( Guid releaseId, IFormFile dataFile, IFormFile metaFile, File?replacingFile = null) { return(await ValidateDataFileNames(releaseId, dataFile.FileName, metaFile.FileName, replacingFile) .OnSuccess(async _ => await ValidateDataFileSizes(dataFile.Length, metaFile.Length)) .OnSuccess(async _ => await ValidateDataFileTypes(dataFile, metaFile))); }
private async Task <File> FetchRemoteStorageInfo() { if (_remoteStorageInfo != null) { return(_remoteStorageInfo); } var request = _service.Files.List(); request.Spaces = "appDataFolder"; request.Fields = "nextPageToken, files(id, name)"; request.PageSize = 10; var result = await request.ExecuteAsync(); _remoteStorageInfo = result.Files.FirstOrDefault(x => x.Name == GoogleDriveRemoteStorage.DataFileName); return(_remoteStorageInfo); }
/// <summary> /// Finds the item in the solution matching the specified file path. /// </summary> /// <param name="filePaths">The absolute file paths of files that exist in the solution.</param> public static async Task <IEnumerable <File> > FromFilesAsync(params string[] filePaths) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); List <File> items = new(); foreach (string filePath in filePaths) { File?item = await FromFileAsync(filePath); if (item != null) { items.Add(item); } } return(items); }
private async Task <Either <ActionResult, Unit> > ValidateDataFileNames( Guid releaseId, string dataFileName, string metaFileName, File?replacingFile) { if (string.Equals(dataFileName.ToLower(), metaFileName.ToLower(), OrdinalIgnoreCase)) { return(ValidationActionResult(DataAndMetadataFilesCannotHaveTheSameName)); } if (FileContainsSpacesOrSpecialChars(dataFileName)) { return(ValidationActionResult(DataFilenameCannotContainSpacesOrSpecialCharacters)); } if (FileContainsSpacesOrSpecialChars(metaFileName)) { return(ValidationActionResult(MetaFilenameCannotContainSpacesOrSpecialCharacters)); } if (!metaFileName.ToLower().Contains(".meta.")) { return(ValidationActionResult(MetaFileIsIncorrectlyNamed)); } if (!ValidateFileExtension(dataFileName, ".csv")) { return(ValidationActionResult(DataFileMustBeCsvFile)); } if (!ValidateFileExtension(metaFileName, ".csv")) { return(ValidationActionResult(MetaFileMustBeCsvFile)); } if (IsFileExisting(releaseId, FileType.Data, dataFileName) && (replacingFile == null || replacingFile.Filename != dataFileName)) { return(ValidationActionResult(CannotOverwriteDataFile)); } return(Unit.Instance); }
/// <summary> /// Convierte una columna /// </summary> private int ConvertColumn(File?file) { if (file == null) { return(-1); } else { switch (file) { case File.A: return(0); case File.B: return(1); case File.C: return(2); case File.D: return(3); case File.E: return(4); case File.F: return(5); case File.G: return(6); case File.H: return(7); default: throw new NotImplementedException(); } } }
/// <summary> /// Loads a file from the given xml reader. /// </summary> /// <param name="reader"></param> /// <returns></returns> public static File Load(XmlReader reader) { // init File?result = null; // read to first element while (reader.NodeType != XmlNodeType.Element && !reader.EOF) { reader.Read(); } // element present? if (reader.NodeType == XmlNodeType.Element) { // namespace valid? if (reader.NamespaceURI != NAMESPACE_URI) { throw new XmlException(string.Format("Unexpected namespace '{0}' encountered.", reader.NamespaceURI)); } Type?type = null; type = reader.LocalName switch { "style" => typeof(StyleFile), "locale" => typeof(LocaleFile), _ => throw new XmlException(string.Format("Unexpected element '{0}' of encountered.", reader.LocalName)), }; // deserialize var xs = new XmlSerializer(type); xs.UnknownNode += XmlSerializer_UnknownNode; xs.UnknownAttribute += XS_UnknownAttribute; result = (File)xs.Deserialize(reader); } // done return(result ?? throw new InvalidOperationException()); }
public void AddFileStart(string name, long size, DateTime dt, FileAttributes attribute, bool compress) { if (currentFile != null) { throw new ApplicationException("currentFile != null"); } name = name.Replace("/", "\\"); File f = new File(); f.Encoding = this.Encoding; f.Name = name; f.Size = size; f.DateTime = dt; f.Attributes = attribute; f.Compress = compress; this.fileList.Add(f); ZipDataHeader h = new ZipDataHeader(); f.HeaderPos = (uint)fifo.TotalWriteSize; f.WriteZipDataHeader(ref h, false); fifo.Write(Util.Legacy_StructToByte(h)); fifo.Write(this.Encoding.GetBytes(f.Name)); f.Crc32 = 0xffffffff; if (compress) { f.ZStream = new Basic.Internal.ZStream(); f.ZStream.deflateInit(-1, -15); } currentFile = f; }
/// <summary> /// Set File field</summary> /// <param name="file_">Nullable field value to be set</param> public void SetFile(File?file_) { SetFieldValue(0, 0, file_, Fit.SubfieldIndexMainField); }
/// <summary> /// Initializes a new instance of the <see cref="FileSchemaTestClass" /> class. /// </summary> /// <param name="file">file.</param> /// <param name="files">files.</param> public FileSchemaTestClass(File?file = default, List <File>?files = default) { this.File = file; this.Files = files; this.AdditionalProperties = new Dictionary <string, object>(); }
/// <summary> /// Helper function to try private different paths private to find and /// fetch the index file from a web site container. /// </summary> /// <param name="fileMdInfo">File MdInfo</param> /// <param name="initialPath">Path</param> /// <returns>WebFile</returns> public async Task <WebFile> TryDifferentPaths(MDataInfo fileMdInfo, string initialPath) { void HandleNfsFetchException(FfiException exception) { Logger.Error(exception); if (exception.ErrorCode != WebFetchConstants.FileNotFound) { throw exception; } } File?file = null; var filePath = string.Empty; try { filePath = initialPath; (file, _) = await _session.NFS.DirFetchFileAsync(fileMdInfo, filePath); } catch (Exception ex) { if (ex.GetType() == typeof(FfiException)) { HandleNfsFetchException((FfiException)ex); } } if (file == null && initialPath.StartsWith("/")) { try { filePath = initialPath.Substring(1, initialPath.Length - 1); (file, _) = await _session.NFS.DirFetchFileAsync(fileMdInfo, filePath); } catch (Exception ex) { if (ex.GetType() == typeof(FfiException)) { HandleNfsFetchException((FfiException)ex); } } } if (file == null && initialPath.StartsWith("/")) { try { filePath = $"{initialPath}/{WebFetchConstants.IndexFileName}"; (file, _) = await _session.NFS.DirFetchFileAsync(fileMdInfo, filePath); } catch (Exception ex) { if (ex.GetType() == typeof(FfiException)) { HandleNfsFetchException((FfiException)ex); } } } if (file == null) { try { filePath = $"{initialPath}/{WebFetchConstants.IndexFileName}"; filePath = filePath.Substring(1, filePath.Length - 1); (file, _) = await _session.NFS.DirFetchFileAsync(fileMdInfo, filePath); } catch (Exception ex) { if (ex.GetType() == typeof(FfiException)) { HandleNfsFetchException((FfiException)ex); } throw new WebFetchException(WebFetchConstants.FileNotFound, WebFetchConstants.FileNotFoundMessage); } } var extension = filePath.Substring(filePath.LastIndexOf('.') + 1); var mimeType = MimeUtility.GetMimeMapping(extension); return(new WebFile { File = file.Value, MimeType = mimeType }); }
private static MoveInfo GetMoveInfo(Game game, string moveText, Color sideToMove) { MoveInfo moveInfo = new MoveInfo(); // Very free-style parsing, based on the assumption that this is a recognized move. if (moveText == "O-O") { moveInfo.MoveType = MoveType.CastleKingside; if (sideToMove == Color.White) { moveInfo.SourceSquare = Square.E1; moveInfo.TargetSquare = Square.G1; } else { moveInfo.SourceSquare = Square.E8; moveInfo.TargetSquare = Square.G8; } } else if (moveText == "O-O-O") { moveInfo.MoveType = MoveType.CastleQueenside; if (sideToMove == Color.White) { moveInfo.SourceSquare = Square.E1; moveInfo.TargetSquare = Square.C1; } else { moveInfo.SourceSquare = Square.E8; moveInfo.TargetSquare = Square.C8; } } else { // Piece, disambiguation, capturing 'x', target square, promotion, check/mate/nag. Piece movingPiece = Piece.Pawn; int index = 0; if (moveText[index] >= 'A' && moveText[index] <= 'Z') { movingPiece = GetPiece(moveText[index]); index++; } File? disambiguatingSourceFile = null; Rank? disambiguatingSourceRank = null; File? targetFile = null; Rank? targetRank = null; Piece?promoteTo = null; while (index < moveText.Length) { char currentChar = moveText[index]; if (currentChar == '=') { index++; promoteTo = GetPiece(moveText[index]); break; } else if (currentChar >= 'a' && currentChar <= 'h') { if (targetFile != null) { disambiguatingSourceFile = targetFile; } targetFile = (File)(currentChar - 'a'); } else if (currentChar >= '1' && currentChar <= '8') { if (targetRank != null) { disambiguatingSourceRank = targetRank; } targetRank = (Rank)(currentChar - '1'); } // Ignore 'x', '+', '#', '!', '?', increase index. index++; } moveInfo.TargetSquare = ((File)targetFile).Combine((Rank)targetRank); // Get vector of pieces of the correct color that can move to the target square. ulong occupied = ~game.CurrentPosition.GetEmptyVector(); ulong sourceSquareCandidates = game.CurrentPosition.GetVector(sideToMove) & game.CurrentPosition.GetVector(movingPiece); if (movingPiece == Piece.Pawn) { // Capture or normal move? if (disambiguatingSourceFile != null) { // Capture, go backwards by using the opposite side to move. sourceSquareCandidates &= Constants.PawnCaptures[sideToMove.Opposite(), moveInfo.TargetSquare]; foreach (Square sourceSquareCandidate in sourceSquareCandidates.AllSquares()) { if (disambiguatingSourceFile == (File)sourceSquareCandidate.X()) { moveInfo.SourceSquare = sourceSquareCandidate; break; } } // En passant special move type, if the target capture square is empty. if (!moveInfo.TargetSquare.ToVector().Test(occupied)) { moveInfo.MoveType = MoveType.EnPassant; } } else { // One or two squares backwards. Func <ulong, ulong> direction; if (sideToMove == Color.White) { direction = ChessExtensions.South; } else { direction = ChessExtensions.North; } ulong straightMoves = direction(moveInfo.TargetSquare.ToVector()); if (!straightMoves.Test(occupied)) { straightMoves |= direction(straightMoves); } sourceSquareCandidates &= straightMoves; foreach (Square sourceSquareCandidate in sourceSquareCandidates.AllSquares()) { moveInfo.SourceSquare = sourceSquareCandidate; break; } } if (promoteTo != null) { moveInfo.MoveType = MoveType.Promotion; moveInfo.PromoteTo = (Piece)promoteTo; } } else { switch (movingPiece) { case Piece.Knight: sourceSquareCandidates &= Constants.KnightMoves[moveInfo.TargetSquare]; break; case Piece.Bishop: sourceSquareCandidates &= Constants.ReachableSquaresDiagonal(moveInfo.TargetSquare, occupied); break; case Piece.Rook: sourceSquareCandidates &= Constants.ReachableSquaresStraight(moveInfo.TargetSquare, occupied); break; case Piece.Queen: sourceSquareCandidates &= Constants.ReachableSquaresDiagonal(moveInfo.TargetSquare, occupied) | Constants.ReachableSquaresStraight(moveInfo.TargetSquare, occupied); break; case Piece.King: sourceSquareCandidates &= Constants.Neighbours[moveInfo.TargetSquare]; break; default: sourceSquareCandidates = 0; break; } foreach (Square sourceSquareCandidate in sourceSquareCandidates.AllSquares()) { if (disambiguatingSourceFile != null) { if (disambiguatingSourceFile == (File)sourceSquareCandidate.X()) { if (disambiguatingSourceRank != null) { if (disambiguatingSourceRank == (Rank)sourceSquareCandidate.Y()) { moveInfo.SourceSquare = sourceSquareCandidate; break; } } else { moveInfo.SourceSquare = sourceSquareCandidate; break; } } } else if (disambiguatingSourceRank != null) { if (disambiguatingSourceRank == (Rank)sourceSquareCandidate.Y()) { moveInfo.SourceSquare = sourceSquareCandidate; break; } } else { moveInfo.SourceSquare = sourceSquareCandidate; break; } } } } return(moveInfo); }
internal AnalyseDependenciesSettingsBuilder WithProject( File project) { _project = project; return(this); }
public bool Equals(File?input) { return(OpenAPIClientUtils.compareLogic.Compare(this, input).AreEqual); }
/// <summary> /// Convierte una celda /// </summary> internal CellModel ConvertCell(int?row, File?file) { return(new CellModel(ConvertRow(row), ConvertColumn(file))); }
/// <summary> /// Set Type field</summary> /// <param name="type_">Nullable field value to be set</param> public void SetType(File?type_) { SetFieldValue(0, 0, type_, Fit.SubfieldIndexMainField); }
/// <summary> /// Loads a file from the given xml reader. /// </summary> /// <param name="reader"></param> /// <returns></returns> public static File Load(XmlReader reader) { // init File?result = null; // locked? if (_Current != null) { throw new NotSupportedException(); } // lock _Current = reader; // try/catch try { // read to first element while (reader.NodeType != XmlNodeType.Element && !reader.EOF) { reader.Read(); } // element present? if (reader.NodeType == XmlNodeType.Element) { // namespace valid? if (reader.NamespaceURI != NAMESPACE_URI) { throw new XmlException(string.Format("Unexpected namespace '{0}' encountered.", reader.NamespaceURI)); } // version var version = reader.GetAttribute("version"); Type?type = null; switch (version) { case "1.0": // type switch (reader.LocalName) { case "style": type = typeof(StyleFile); break; case "locale": type = typeof(LocaleFile); break; } break; default: throw new XmlException(string.Format("Version '{0}' is not supported.", version)); } // type found? if (type == null) { throw new XmlException(string.Format("Unexpected element '{0}' of version '{1}' encountered.", reader.LocalName, version)); } // deserialize var xs = new XmlSerializer(type); xs.UnknownNode += XmlSerializer_UnknownNode; xs.UnknownAttribute += XS_UnknownAttribute; result = (File)xs.Deserialize(reader); } } finally { // unlock _Current = null; } // done return(result ?? throw new InvalidOperationException()); }
public FileSchemaTestClass(File?file = default, List <File>?files = default) { File = file; Files = files; }
public void ExecuteCommand(CommandData commandData) { if (commandData.c == Command.Error) { return; } List <string> parameters = commandData.parameters; Command c = commandData.c; //WARNING! DON'T UNCOLLAPSE! ALL CODE FOR EACH OF THE COMMANDS INSIDE! switch (c) { case Command.Help: string str = string.Empty; IEnumerable <string> sNames; IEnumerable <string> sDocumentation; sNames = CommandHelper.GetAllNamesOfType(CommandType.Basic); sDocumentation = CommandHelper.GetAllDocumentationOfType(CommandType.Basic); Print("=== Basic Commands ===\n", true); List <ListElement> names = new List <ListElement>(); List <ListElement> documentation = new List <ListElement>(); foreach (string n in sNames) { names.Add(new ListElement(n)); } foreach (string d in sDocumentation) { documentation.Add(new ListElement(d)); } List <ListColumn> columns = new List <ListColumn>(); columns.Add(new ListColumn("Name", names)); columns.Add(new ListColumn("Description", documentation)); PrintList(columns); if (CurrentMachine.type == MachineType.Shell) { Print("\n === For a list of Advanced Commands visit the help module === ", true); } break; case Command.Modules: columns = new List <ListColumn>(); List <ListElement> modules = new List <ListElement>(); List <ListElement> status = new List <ListElement>(); foreach (ModuleType m in windowManager.GetModules()) { modules.Add(new ListElement(m.ToString())); status.Add(new ListElement(windowManager.ModuleToStatus[m].ToString())); if (windowManager.ModuleToStatus[m] == Status.Used) { status[status.Count - 1].color = new Color(1, 0, 0, 0.5f); modules[modules.Count - 1].color = new Color(1, 0, 0, 0.5f); } } columns.Add(new ListColumn("Name", modules)); columns.Add(new ListColumn("Status", status)); PrintList(columns); break; case Command.Windows: string output = string.Empty; foreach (int window in windowManager.GetWindows()) { output += "\t\n" + window + " - " + windowManager.WindowToStatus[windowManager.IndexToWindow[window]].ToString(); } Print(output.Substring(2)); break; case Command.Load: string mString = FormatString(parameters[0]); ModuleType mod = ModuleType.None; try { mod = (ModuleType)Enum.Parse(typeof(ModuleType), mString); } catch (ArgumentException) { Print("The module requested is not avalible. Type 'Modules' for a list of avalible modules."); return; } if (!windowManager.ModuleIsOpenableByPlayer(mod) || windowManager.ModuleToStatus[mod] == Status.Used) { Print("The module requested is not avalible. Type 'Modules' for a list of avalible modules."); return; } int w = int.Parse(parameters[1]); if (!windowManager.WindowAvalible(w)) { Print("The requested window is currently in use or doesn't exist. Type 'Windows' for a list of avalible windows"); return; } windowManager.LoadModuleOnWindow(mod, w); Print("The requested module " + parameters[0] + " has succesfully been loaded on window " + parameters[1] + "."); break; case Command.Unload: if (windowManager.WindowAvalible(int.Parse(parameters[0]))) { Print("Window either doesn't exist or already has module loaded on it. For more info, tpye 'help' or visit the 'commands' page in the shell help menu."); return; } if (windowManager.WindowToModule[windowManager.IndexToWindow[int.Parse(parameters[0])]] == ModuleType.Shell) { Print("You can't unload the shell from shell!"); return; } windowManager.UnloadOnWindow(int.Parse(parameters[0])); break; case Command.Load_database: string name = parameters[0]; if (!databaseMan.HasDatabaseByName(name)) { Print("The database you are trying to access doesn't exist. Did you spell the name right?"); return; } CurrentMachine = databaseMan.GetDataBase(name); Print("You are now in database " + parameters[0] + ". To get back, type the command 'Back'."); break; case Command.Back: CurrentMachine = new Shell(); Print("You're now in the shell."); break; case Command.Files: if ((CurrentMachine as DataBase).files.Length == 0) { Print("Could not list the files on this database since it doesn't have any."); return; } string tempS = string.Empty; foreach (File file in (CurrentMachine as DataBase).files) { tempS += file.name + "\n"; } Print(tempS); break; case Command.Open: File?fn = (CurrentMachine as DataBase).GetFile(parameters[0]); if (fn == null) { Print("Could not open the requested file since there's no file named " + parameters[0] + ". Did you misspel the name?"); return; } File f = fn.Value; Print("==== File begin ====", true); Print(f.file.text); Print("==== File end ====\n", true); break; } }