예제 #1
0
파일: BlockDevice.cs 프로젝트: Spaxys/Kean
        public static IBlockDevice Create(Uri.Locator resource)
        {
            IBlockDevice result = BlockDevice.Open(resource, System.IO.FileMode.Create);

            if (result.IsNull() && resource.NotNull())
            {
                System.IO.Directory.CreateDirectory(resource.Path.FolderPath.PlatformPath);
                result = BlockDevice.Open(resource, System.IO.FileMode.Create);
            }
            return(result);
        }
예제 #2
0
파일: BlockDevice.cs 프로젝트: Spaxys/Kean
        static IBlockDevice Open(Uri.Locator resource, System.IO.FileMode mode)
        {
            IBlockDevice result = null;

            if (resource.NotNull())
            {
                switch (resource.Scheme)
                {
                case "assembly":
                    result = resource.Authority == "" ? BlockDevice.Open(System.Reflection.Assembly.GetEntryAssembly(), resource.Path) : BlockDevice.Open(System.Reflection.Assembly.Load(new System.Reflection.AssemblyName(resource.Authority)), resource.Path);
                    break;

                case "file":
                    try
                    {
                        System.IO.FileStream stream = System.IO.File.Open(System.IO.Path.GetFullPath(resource.PlatformPath), mode, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
                        if (stream.NotNull())
                        {
                            result = new BlockDevice(stream, resource);
                        }
                    }
                    catch (System.IO.DirectoryNotFoundException)
                    {
                        result = null;
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        result = null;
                    }
                    break;

                case "http":
                case "https":
                    if (mode == System.IO.FileMode.Open)
                    {
                        // TODO: support http and https.
                    }
                    break;
                }
            }
            return(result);
        }
예제 #3
0
파일: BlockDevice.cs 프로젝트: Spaxys/Kean
 public static IBlockDevice Open(Uri.Locator resource)
 {
     return(BlockDevice.Open(resource, System.IO.FileMode.Open));
 }