//KeyValuePair<相対パス, 完全パス>のリストを返す。 private static List <KeyValuePair <string, string> > getFiles(string dir, string rootdir, string pattern, bool toponly, bool sort) { StringComparison strComp = StringComparison.OrdinalIgnoreCase; List <KeyValuePair <string, string> > retList = new List <KeyValuePair <string, string> >(); if (!toponly) { //サブフォルダ内の検索 string[] dirList = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly); if (dirList.Length > 0) { if (sort) { Array.Sort(dirList, ignoreCaseComparer); } for (int i = 0; i < dirList.Length; i++) { retList.AddRange(getFiles(dirList[i], rootdir, pattern, toponly, sort)); } } } string RelativePath = ""; //相対ディレクトリ名 if (string.Equals(dir, rootdir, strComp)) //現在のパスが検索ルートパスに等しい { RelativePath = ""; } else { if (!dir.StartsWith(rootdir, strComp)) { RelativePath = dir; } else { RelativePath = dir.Substring(rootdir.Length); //前方が検索ルートパスと一致するならその部分を切り取る } if (!RelativePath.EndsWith("\\") && !RelativePath.EndsWith("/")) { RelativePath += "\\"; //末尾が\又は/で終わるように。後でFile名を直接加算できるようにしておく } } //filepathsは完全パスである string[] filepaths = Directory.GetFiles(dir, pattern, SearchOption.TopDirectoryOnly); if (sort) { Array.Sort(filepaths, ignoreCaseComparer); } for (int i = 0; i < filepaths.Length; i++) { if (Path.GetExtension(filepaths[i]).Length <= 4) //".erb"や".csv"であること。放置すると".erb*"等を拾う。 { retList.Add(new KeyValuePair <string, string>(RelativePath + Path.GetFileName(filepaths[i]), filepaths[i])); } } return(retList); }
public override Task <IEnumerable <FileInformation> > MigrateFileAsync() { LogStart(); _metricsContext.CollectActionMetrics(WebFormsActionType.FileConversion, ChildActionType); // We want to add the relative path to _Host.cshtml before // prepending wwwroot/ because the web root folder is ignored // when fetching static files if (RelativePath.EndsWith(Constants.StyleSheetFileExtension, StringComparison.InvariantCultureIgnoreCase)) { _hostPageService.AddStyleSheetPath(RelativePath); } var newPath = FilePathHelper.RemoveDuplicateDirectories(Path.Combine(Constants.WebRootDirectoryName, RelativePath)); var fullPath = Path.Combine(ProjectPath, RelativePath); FileInformation fi = new FileInformation(newPath, File.ReadAllBytes(fullPath)); var fileList = new[] { fi }; DoCleanUp(); LogEnd(); return(Task.FromResult((IEnumerable <FileInformation>)fileList)); }
// View file converters will return razor file contents with // only view layer, code behind will be created in another file public override Task <IEnumerable <FileInformation> > MigrateFileAsync() { LogStart(); _metricsContext.CollectActionMetrics(WebFormsActionType.FileConversion, ChildActionType); var result = new List <FileInformation>(); try { var htmlString = File.ReadAllText(FullPath); // Replace directives first to build up list of user controls to be converted later by the ControlConverters var projectName = Path.GetFileName(ProjectPath); htmlString = EmbeddedCodeReplacers.ReplaceDirectives(htmlString, RelativePath, projectName, _viewImportService, _metricsContext); // Convert the Web Forms controls to Blazor equivalent var migratedDocument = GetRazorContents(htmlString); var contents = migratedDocument.DocumentNode.WriteTo(); // We comment out the unknown user controls here instead of during // traversal because the post-order nature may comment out controls // that are migrated as part of an ancestor control before that ancestor // can be processed contents = ControlConverter.ConvertEmbeddedCode(contents, RelativePath, _viewImportService); contents = UnknownControlRemover.RemoveUnknownTags(contents); // Currently just changing extension to .razor, keeping filename and directory the same // but Razor files are renamed and moved around, can't always use same filename/directory in the future var newRelativePath = FilePathHelper.AlterFileName(RelativePath, newExtension: ".razor"); if (RelativePath.EndsWith(Constants.WebFormsPageMarkupFileExtension, StringComparison.InvariantCultureIgnoreCase)) { newRelativePath = Path.Combine(Constants.RazorPageDirectoryName, newRelativePath); } else if (RelativePath.EndsWith(Constants.WebFormsMasterPageMarkupFileExtension, StringComparison.InvariantCultureIgnoreCase)) { newRelativePath = Path.Combine(Constants.RazorLayoutDirectoryName, newRelativePath); } else if (RelativePath.EndsWith(Constants.WebFormsControlMarkupFileExtenion, StringComparison.InvariantCultureIgnoreCase)) { newRelativePath = Path.Combine(Constants.RazorComponentDirectoryName, newRelativePath); } else { // Default action: file type is not supported. Set newRelativePath to null to // prevent file creation. newRelativePath = null; } DoCleanUp(); LogEnd(); if (newRelativePath != null) { var fileInformation = new FileInformation(FilePathHelper.RemoveDuplicateDirectories(newRelativePath), Encoding.UTF8.GetBytes(contents)); result.Add(fileInformation); } } catch (Exception e) { LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Error migrating view file {FullPath}. A new file could not be generated."); } return(Task.FromResult((IEnumerable <FileInformation>)result)); }
public void Release(bool unloadAllLoadedObjects) //, bool forceUnloadAsset = false { if (unloadAllLoadedObjects && m_object) //&& (forceUnloadAsset || (!m_neverUnloadAsset && !forceUnloadAsset)) { //UnloadAsset(); if (!RelativePath.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase) && !RelativePath.EndsWith(".fbx", StringComparison.OrdinalIgnoreCase)) { Resources.UnloadAsset(m_object); } m_object = null; LoggerHelper.Warning("set m_object null: " + RelativePath);//Debug.LogWarning } //if (SystemSwitch.UseFileSystem) //{ // if (this.createRequest != null) // { // if (this.createRequest.assetBundle) // this.createRequest.assetBundle.Unload(unloadAllLoadedObjects); // this.createRequest = null; // } //} //else //{ if (this.www != null) { if (this.www.assetBundle) { this.www.assetBundle.Unload(unloadAllLoadedObjects); } this.www = null; } //} }