/// <summary>
        /// Creates a file using the given file path, contents, and creation option
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="contents"></param>
        /// <param name="collisionOption"></param>
        /// <returns></returns>
        public Task <IFile> CreateFileAsync(string fileName, string contents, CreationOption collisionOption)
        {
            AssertDirectoryExists();

            return(Task.Factory.StartNew(() =>
            {
                IFile createdFile = null;
                string filePath = Path.Combine(_systemPathMapper.GetUserContextFolder(this.FullPath), fileName);

                // File exists
                if (File.Exists(filePath))
                {
                    switch (collisionOption)
                    {
                    case CreationOption.OpenIfExists:
                        File.AppendAllText(filePath, contents);
                        break;

                    case CreationOption.ReplaceExisting:
                        File.WriteAllText(filePath, contents);
                        break;

                    case CreationOption.ThrowIfExists:
                        throw new Exceptions.FileAlreadyExistsException("The file to be created already exists in the target directory");

                    default:
                        goto case CreationOption.ReplaceExisting;
                    }
                }
                // File does not already exist
                else
                {
                    if (contents != null)
                    {
                        // Contents are not null, write all the text to the new file
                        File.WriteAllText(filePath, contents);
                    }
                    else
                    {
                        // Contents were null, just create a new, empty file
                        File.Create(filePath).Dispose();
                    }
                }

                // Create a new WinFile object using FileInfo for the filePath
                createdFile = new SystemContextFile(new FileInfo(filePath));

                return createdFile;
            }));
        }
        /// <summary>
        /// Creates a directory using the given path and creation option
        /// </summary>
        /// <param name="directoryName"></param>
        /// <param name="collisionOption"></param>
        /// <returns></returns>
        public Task <IDirectory> CreateDirectoryAsync(string directoryPath, CreationOption collisionOption)
        {
            AssertDirectoryExists();

            return(Task.Factory.StartNew(() =>
            {
                IDirectory createdDirectory = null;
                string expandedPath = _systemPathMapper.GetUserContextFolder(directoryPath);

                // Check to see if the path is a relative or full path
                if (!Path.IsPathRooted(expandedPath))
                {
                    // If it's a relative path, then create the new full path using this directory's full path
                    expandedPath = Path.Combine(this.FullPath, directoryPath);
                }

                // Verify the directory exists
                if (Directory.Exists(expandedPath))
                {
                    switch (collisionOption)
                    {
                    case CreationOption.OpenIfExists:
                        // Just open the directory if it already exists
                        createdDirectory = new SystemContextDirectory(new DirectoryInfo(expandedPath));
                        break;

                    case CreationOption.ReplaceExisting:
                        // Replace the existing directory with a new one, must first delete it (recursively delete all sub directories as well)
                        Directory.Delete(expandedPath, true);
                        createdDirectory = new SystemContextDirectory(Directory.CreateDirectory(expandedPath));
                        break;

                    case CreationOption.ThrowIfExists:
                        throw new Exceptions.DirectoryAlreadyExistsException("The directory to be created already exists!");

                    default:
                        goto case CreationOption.ReplaceExisting;
                    }
                }
                else
                {
                    // Directory does not already exist, just go ahead and create it
                    createdDirectory = new SystemContextDirectory(Directory.CreateDirectory(expandedPath));
                }

                return createdDirectory;
            }));
        }
Exemplo n.º 3
0
 public void SetValue(string attributeName, IJavascriptObject element, CreationOption ioption = CreationOption.None)
 {
     _CfrV8Value.SetValue(attributeName, element.Convert(), (CfxV8PropertyAttribute)ioption);
 }
 private static CefV8PropertyAttribute Convert(CreationOption value)
 {
     return (CefV8PropertyAttribute)value;
 }
 public void SetValue(string AttributeName, IJavascriptObject element, CreationOption ioption = CreationOption.None)
 {
     _CefV8Value.SetValue(AttributeName, Convert(element),Convert(ioption));
 }
 public void SetValue(string attributeName, IJavascriptObject element, CreationOption ioption = CreationOption.None) 
 {
     _CfrV8Value.SetValue(attributeName, element.Convert(), (CfxV8PropertyAttribute) ioption);
 }
Exemplo n.º 7
0
 public void SetValue(string AttributeName, IJavascriptObject element, CreationOption ioption = CreationOption.None)
 {
     ((JSObject)_JSValue)[AttributeName] = element.Convert();
 }
 private static CefV8PropertyAttribute Convert(CreationOption value)
 {
     return((CefV8PropertyAttribute)value);
 }
 public void SetValue(string AttributeName, IJavascriptObject element, CreationOption option = CreationOption.None)
 {
     _CefV8Value.SetValue(AttributeName, Convert(element), Convert(option));
 }
 public void SetValue(string AttributeName, IJavascriptObject element, CreationOption ioption = CreationOption.None)
 {
     ((JSObject)_JSValue)[AttributeName] = element.Convert();
 }