/// <summary> /// Create a special file. /// </summary> private async Task <string> CreateFileAsync(SpecialFiles fileId, string specialFileName) { IProjectTree rootNode = await GetParentFolderAsync(createIfNotExists : true).ConfigureAwait(false); string parentPath = _projectTree.TreeProvider.GetRootedAddNewItemDirectory(rootNode); string specialFilePath = Path.Combine(parentPath, specialFileName); // If we can create the file from the template do it, otherwise just create an empty file. if (_templateFileCreationService != null) { await _templateFileCreationService.Value.CreateFileAsync(TemplateName, parentPath, specialFileName).ConfigureAwait(false); } else { using (_fileSystem.Create(specialFilePath)) { } IProjectItem item = await _sourceItemsProvider.AddAsync(specialFilePath).ConfigureAwait(false); if (item != null) { await _projectTree.TreeService.PublishLatestTreeAsync(waitForFileSystemUpdates : true).ConfigureAwait(false); } } return(specialFilePath); }
/// <summary> /// We follow this algorithm for looking up files: /// /// if (not asked to create) /// Look in AppDesigner folder /// Look in root folder /// /// if (asked to create) /// Look in AppDesigner folder /// Look in root folder /// Force-create in app-designer folder unless that file is not created there by default. /// In that case create under the root node. /// </summary> public async Task <string> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default(CancellationToken)) { // Search for the file in the app designer and root folders. IProjectTree specialFileNode = await FindFileAsync(Name).ConfigureAwait(false); if (specialFileNode != null) { if (await IsNodeInSyncWithDiskAsync(specialFileNode, forceSync: flags.HasFlag(SpecialFileFlags.CreateIfNotExist), cancellationToken: cancellationToken).ConfigureAwait(false)) { return(specialFileNode.FilePath); } } // File doesn't exist. Create it if we've been asked to. if (flags.HasFlag(SpecialFileFlags.CreateIfNotExist)) { string createdFilePath = await CreateFileAsync(fileId, Name).ConfigureAwait(false); if (createdFilePath != null) { return(createdFilePath); } } // We haven't found the file but return the default file path as that's the contract. IProjectTree rootNode = _projectTree.CurrentTree; string rootFilePath = _projectTree.TreeProvider.GetPath(rootNode); string fullPath = Path.Combine(Path.GetDirectoryName(rootFilePath), Name); return(fullPath); }
/// <summary> /// Create a special file. /// </summary> private async Task <string> CreateFileAsync(SpecialFiles fileId, string specialFileName) { string templateFile = GetTemplateForSpecialFile(fileId); IProjectTree rootNode = _projectTreeService.CurrentTree.Tree; IProjectTree appDesignerFolder = rootNode.Children.FirstOrDefault(child => child.IsFolder && child.Flags.HasFlag(ProjectTreeFlags.Common.AppDesignerFolder)); if (appDesignerFolder == null && CreatedByDefaultUnderAppDesignerFolder) { return(null); } var parentNode = CreatedByDefaultUnderAppDesignerFolder ? appDesignerFolder : rootNode; bool fileCreated = false; // If we can create the file from the template do it, otherwise just create an empty file. if (_templateFileCreationService != null) { fileCreated = await _templateFileCreationService.Value.CreateFileAsync(templateFile, parentNode, specialFileName).ConfigureAwait(false); } else { var parentPath = _projectTreeService.CurrentTree.TreeProvider.GetPath(parentNode); var specialFilePath = Path.Combine(parentPath, specialFileName); _fileSystem.Create(specialFilePath); IProjectItem item = await _sourceItemsProvider.AddAsync(specialFilePath).ConfigureAwait(false); if (item != null) { fileCreated = true; await _projectTreeService.PublishLatestTreeAsync(waitForFileSystemUpdates : true).ConfigureAwait(false); } } if (fileCreated) { // The tree would have changed. So fetch the nodes again from the current tree. var specialFilePath = FindFile(specialFileName); if (specialFilePath != null) { return(specialFilePath.FilePath); } Diagnostics.Debug.Fail("We added the file successfully but didn't find it!"); } return(null); }
public virtual async Task <string?> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) { // Make sure at least have a tree before we start searching it IProjectTreeServiceState state = await _treeService.PublishAnyNonLoadingTreeAsync(cancellationToken); // Attempt to find an existing file/folder first string?path = await FindFileAsync(state.TreeProvider, state.Tree, flags); if (path == null) { // Otherwise, fall back and create it path = await CreateDefaultFileAsync(state.TreeProvider, state.Tree, flags); } return(path); }
public async Task <string?> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags) { await _projectVsServices.ThreadingService.SwitchToUIThread(); var files = (IVsProjectSpecialFiles)_projectVsServices.VsHierarchy; HResult result = files.GetFile((int)fileId, (uint)flags, out _, out string fileName); if (result.IsOK) { return(fileName); } if (result.IsNotImplemented) { return(null); // Not handled } throw result.Exception !; }
public async Task <string> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default(CancellationToken)) { string path = FindAppDesignerFolder(); if (path == null) { // Not found, let's find the default path and create it if needed path = await GetDefaultAppDesignerFolderPathAsync().ConfigureAwait(false); if (path != null && (flags & SpecialFileFlags.CreateIfNotExist) == SpecialFileFlags.CreateIfNotExist) { await _projectTree.Value.TreeStorage.CreateFolderAsync(path) .ConfigureAwait(false); } } // We always return the default path, regardless of whether we created it or it exists, as per contract return(path); }
public virtual async Task <string> GetFileAsync(SpecialFiles fileId, SpecialFileFlags flags, CancellationToken cancellationToken = default) { // Make sure at least have a tree before we start searching it await _projectTree.Value.TreeService.PublishAnyNonLoadingTreeAsync(cancellationToken); string path = FindAppDesignerFolder(); if (path == null) { // Not found, let's find the default path and create it if needed path = await GetDefaultAppDesignerFolderPathAsync(); if (path != null && (flags & SpecialFileFlags.CreateIfNotExist) == SpecialFileFlags.CreateIfNotExist) { await _projectTree.Value.TreeStorage.CreateFolderAsync(path); } } // We always return the default path, regardless of whether we created it or it exists, as per contract return(path); }
/// <summary> /// 파일동기화 확인 /// </summary> /// <returns></returns> private bool CheckSyncFileExists() { bool result = true; try { for (int i = 0; i < SyncResourceData.ServerConfig.Files.Count; i++) { if (FileHelper.ExistsFile(SyncResourceData.ServerConfig.Files[i].ClientPath) == false) { result = false; break; } if (string.IsNullOrEmpty(SyncResourceData.ClientConfig.Files[i].SpecialFileType) == false) { SpecialFiles.Add(SyncResourceData.ClientConfig.Files[i]); } } //if(result) if (true) { OnStatusUpdate("CheckSyncFileExists", PublishProcessStatus.Exists_True); } else { OnStatusUpdate("CheckSyncFileExists", PublishProcessStatus.Exists_False); } } catch (Exception ex) { OnStatusUpdate("CheckClientData", PublishProcessStatus.Fail, ex.Message); } return(GetSyncStatusBoolean()); }
protected override string GetTemplateForSpecialFile(SpecialFiles fileId) { Assert(fileId == SpecialFiles.AssemblyResource); return("ResourceInternal.zip"); }
protected override string GetTemplateForSpecialFile(SpecialFiles fileId) { Assert(fileId == SpecialFiles.AppConfig); return("AppConfigurationInternal.zip"); }
protected override string GetFileNameOfSpecialFile(SpecialFiles fileId) { Assert(fileId == SpecialFiles.AppConfig); return("App.config"); }
protected override string GetFileNameOfSpecialFile(SpecialFiles fileId) { return("AssemblyInfo.vb"); }
protected override string GetTemplateForSpecialFile(SpecialFiles fileId) { return("AssemblyInfoInternal.zip"); }
protected override string GetTemplateForSpecialFile(SpecialFiles fileId) { Assert(fileId == SpecialFiles.AppSettings); return("SettingsInternal.zip"); }
protected override string GetFileNameOfSpecialFile(SpecialFiles fileId) { Assert(fileId == SpecialFiles.AppSettings); return("Settings.settings"); }
/// <summary> /// Gets the name of a special file. /// </summary> protected abstract string GetFileNameOfSpecialFile(SpecialFiles fileId);
/// <summary> /// Gets the name of a template that can be used to create a new special file. /// </summary> protected abstract string GetTemplateForSpecialFile(SpecialFiles fileId);
protected override string GetFileNameOfSpecialFile(SpecialFiles fileId) { Assert(fileId == SpecialFiles.AssemblyResource); return("Resources.resx"); }