private static void RestProcessorForOperation(string groupKey, FileNameInfo file, ConcurrentDictionary <string, ConcurrentBag <Operation> > groupOperations) { var folder = Path.GetDirectoryName(file.FilePath); var ymlPath = Path.Combine(folder, $"{Path.GetFileNameWithoutExtension(file.FilePath)}.yml"); try { var operation = RestTransformer.ProcessOperation(groupKey, ymlPath, file.FilePath); if (operation != null) { var key = string.IsNullOrEmpty(file.Version) ? operation.GroupId : $"{file.Version}_{operation.GroupId}"; var operations = groupOperations.GetOrAdd(key, new ConcurrentBag <Operation>()); operations.Add(operation); } Console.WriteLine($"Done generate yml model for {file.FilePath}"); } catch (Exception ex) { ErrorList.Add($"Error generate yml files for {file.FilePath}, details: {ex}"); } finally { if (File.Exists(file.FilePath)) { File.Delete(file.FilePath); } } }
private static string GetFilePathFromHandle([NotNull] SafeFileHandle handle) { FileNameInfo fileInfo = default; var bufferSize = Marshal.SizeOf(fileInfo) + (NativeMethods.FileNameCapacity * 2); var pointerToBuffer = Marshal.AllocHGlobal(bufferSize); try { Marshal.StructureToPtr(fileInfo, pointerToBuffer, false); NativeMethods.GetFileInformationByHandleEx( handle, FileInfoByHandleClass.FileNameInfo, out fileInfo, bufferSize); try { return(fileInfo.FileName.Length != 0 ? Path.GetFullPath(fileInfo.FileName) : null); } catch (NotSupportedException) { return(null); } } finally { Marshal.FreeHGlobal(pointerToBuffer); } }
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report) { //The Resources folder path string resourcsPath = Application.dataPath + "/Resources"; //Get file names except the ".meta" extension string[] fileNames = Directory.GetFiles(resourcsPath) .Where(x => Path.GetExtension(x) != ".meta").ToArray(); //Convert the Names to Json to make it easier to access when reading it FileNameInfo fileInfo = new FileNameInfo(fileNames); string fileInfoJson = JsonUtility.ToJson(fileInfo); //Save the json to the Resources folder as "FileNames.txt" File.WriteAllText(Application.dataPath + "/Resources/FileNames.txt", fileInfoJson); AssetDatabase.Refresh(); }
public static extern bool GetFileInformationByHandleEx( [In] SafeFileHandle file, [In] FileInfoByHandleClass fileInformationClass, [Out] out FileNameInfo fileInformation, [In] int bufferSize);
} // in bytes protected DownloadableLink(string name = "", string url = "", ISection parentSection = null) : base(name, url) { ParentSection = parentSection; FileFromCourses = new FileNameInfo(); FileFromUrl = new FileNameInfo(); }
public override IEnumerable <FileNameInfo> Generate() { var pathsJObj = (JObject)RootJObj["paths"]; var tags = GetTags(pathsJObj); if (tags.Count == 0) { Console.WriteLine($"tags is null or empty for file {FilePath}."); } foreach (var tag in tags) { Dictionary <string, JToken> pathsParameters = new Dictionary <string, JToken>(); var filteredPaths = FindPathsByTag(pathsJObj, tag, ref pathsParameters); if (filteredPaths.Count > 0) { MergePathParametersToOperations(filteredPaths, pathsParameters); var fileNameInfo = new FileNameInfo { TocName = Utility.ExtractPascalNameByRegex(tag, OrgsMappingFile.NoSplitWords) }; RootJObj["x-internal-operation-group-name"] = tag; // Get file name from operation group mapping string newTagName = tag; if (OperationGroupMapping != null && OperationGroupMapping.TryGetValueOrDefault(tag, out newTagName, tag)) { fileNameInfo.TocName = newTagName; RootJObj["x-internal-operation-group-name"] = newTagName; } // Reset paths to filtered paths RootJObj["paths"] = filteredPaths; RootJObj["x-internal-toc-name"] = fileNameInfo.TocName; RootJObj["x-internal-product-uid"] = OrgsMappingFile.ProductUid; // Only split when the children count larger than MappingConfig.SplitOperationCountGreaterThan if (OrgsMappingFile.IsOperationLevel && Utility.ShouldSplitToOperation(RootJObj, OrgsMappingFile.SplitOperationCountGreaterThan)) { // Split operation group to operation fileNameInfo.ChildrenFileNameInfo = new List <FileNameInfo>( GenerateOperations( RootJObj, (JObject)RootJObj["paths"], TargetDir, newTagName ) ); // Sort fileNameInfo.ChildrenFileNameInfo.Sort((a, b) => string.CompareOrdinal(a.TocName, b.TocName)); // Clear up original paths in operation group RootJObj["paths"] = new JObject(); // Add split members into operation group var splitMembers = new JArray(); foreach (var childInfo in fileNameInfo.ChildrenFileNameInfo) { var relativePath = FileUtility.NormalizePath(childInfo.FileName); var dotIndex = relativePath.LastIndexOf('.'); var relativePathWithoutExt = relativePath; if (dotIndex > 0) { // Remove ".json" relativePathWithoutExt = relativePath.Remove(dotIndex); } splitMembers.Add(new JObject { { "displayName", childInfo.TocName }, { "relativePath", relativePathWithoutExt }, }); } RootJObj["x-internal-split-members"] = splitMembers; RootJObj["x-internal-split-type"] = OrgsMappingFile.UseYamlSchema ? SplitType.TagGroup.ToString() : SplitType.OperationGroup.ToString(); } var file = Utility.Serialize(TargetDir, Utility.TryToFormalizeUrl(newTagName, OrgsMappingFile.FormalizeUrl), RootJObj); fileNameInfo.FileName = OrgsMappingFile.UseYamlSchema ? Path.ChangeExtension(file.Item1, "yml") : file.Item1; fileNameInfo.FilePath = file.Item2; fileNameInfo.Version = Version; // Clear up internal data ClearKey(RootJObj, "x-internal-split-members"); ClearKey(RootJObj, "x-internal-split-type"); ClearKey(RootJObj, "x-internal-toc-name"); ClearKey(RootJObj, "x-internal-product-uid"); yield return(fileNameInfo); } } }
private void LoadInput(FileNameInfo fileNameInfo) { Excel.Application excel = null; Excel.Workbook wkb = null; try { excel = new Excel.Application(); wkb = OpenBook(excel, fileNameInfo.FilePath); excel.DisplayAlerts = false; Excel.Range xlRange = null; if (wkb.Sheets[1] is Excel.Worksheet sheet) { xlRange = sheet.UsedRange; } string a, b, c, d; double e, f; if (xlRange != null) { object[,] values = xlRange.Value2; int row = xlRange.Rows.Count; RecordTotal = row; for (int i = 2; i <= row; i++) { RecordNumber = i; SetProcessReadFile(); a = values[i, 1].ToString(); b = values[i, 2].ToString(); c = values[i, 3].ToString(); d = values[i, 4].ToString(); d = FontHelper.TCVN3ToUnicode(d); e = Convert.ToDouble(values[i, 5] ?? 0); f = Convert.ToDouble(values[i, 6] ?? 0); Vouchers.Add(new Voucher { VoucherType = a, VoucherNo = b, VoucherDate = c, VoucherDescription = d, PSNo = e, PSCo = f, AccountID = fileNameInfo.AccountID, AccountDetailID = fileNameInfo.AccountDetailID, CustomerID = fileNameInfo.CustomerID }); } } excel.Quit(); } catch (Exception ex) { ErrorMessage.AppendLine(string.Format("Load file fail: {0} => Err: {1}", fileNameInfo.FileName, ex.Message)); Console.WriteLine(ex.Message); if (excel != null) { excel.Quit(); } } }