/// <summary> /// Adds a file to a target path. /// </summary> /// <param name="fileName">The name of the file</param> /// <param name="targetPath">The path target where you want to copy a file to </param> /// <param name="oDataFileOptions">The options to use when adding a file to a target path.</param> /// <returns>Returns the path to the file that was added</returns> public async Task <string> AddFileAsync(string fileName, string targetPath, ODataFileOptions oDataFileOptions) { if (oDataFileOptions != null) { return(await this.Context.HandlerHelper.AddFileAsync(fileName, targetPath, new AddFileOptions { SuppressOverwritePrompt = oDataFileOptions.SuppressOverwritePrompt, OpenOnComplete = oDataFileOptions.OpenOnComplete }).ConfigureAwait(true)); } else { return(await this.Context.HandlerHelper.AddFileAsync(fileName, targetPath).ConfigureAwait(true)); } }
/// <summary> /// Copies a file to a target path. /// </summary> /// <param name="fileName">The name of the source file to copy.</param> /// <param name="targetPath">The target path to copy the file to.</param> /// <param name="oDataFileOptions">The options to use when adding a file to a target path.</param> /// <returns>Returns the path to the file that was added</returns> public Task <string> AddFileAsync(string fileName, string targetPath, ODataFileOptions oDataFileOptions = null) { if (!File.Exists(fileName)) { return(Task.FromException <string>(new FileNotFoundException("The filename provided does not exist"))); } try { File.Copy(fileName, targetPath, true); if (this.project != null) { this.project = ProjectHelper.ReloadProject(this.project.DirectoryPath); string[] projectTargetFrameworks = this.project.GetProjectTargetFrameworks(); foreach (string projectTargetFramework in projectTargetFrameworks) { if (projectTargetFramework.Contains("net4")) { //If the filename being copied to the project folder is not 'Csdl.xml' and it has not already been copied, //then add it to the project file. //Example of what the if statement below will output if true: //<ItemGroup> // <Compile Include="Reference.cs" /> //</ItemGroup> if (!Path.GetFileName(targetPath).Equals(Constants.DefaultServiceName + "Csdl.xml") && project.GetItemsByEvaluatedInclude(Path.GetFileName(targetPath)).Count == 0) { ProjectHelper.AddProjectItem(this.project, "Compile", Path.GetFileName(targetPath)); } } } } string path = Path.GetFullPath(fileName); return(Task.FromResult(path)); } catch (Exception e) { return(Task.FromException <string>(new Exception(e.Message))); } }