当前位置: 首页>>代码示例>>C#>>正文


C# IFile.Open方法代码示例

本文整理汇总了C#中IFile.Open方法的典型用法代码示例。如果您正苦于以下问题:C# IFile.Open方法的具体用法?C# IFile.Open怎么用?C# IFile.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFile的用法示例。


在下文中一共展示了IFile.Open方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

 public void Save(IImage image, IFile file)
 {
     var actual = ((ImageAdapter)image).Image;
     using (var stream = file.Open(FileLockMode.ReadWrite, FileOpenMode.Recreate)) {
         actual.Save(stream, this.codec, this.parameters);
     }
 }
开发者ID:ashmind,项目名称:gallery,代码行数:7,代码来源:ImageCodecAdapter.cs

示例2: LoadMDL

 // Model loader for MDL files. Reference Valve's studiohdr_t struct definition for the most part.
 public DataStructures.Models.Model LoadMDL(IFile file, ModelLoadItems loadItems)
 {
     using (var fs = file.Open())
     {
         using(var br = new BinaryReader(fs))
         {
             return ReadModel(br, file, loadItems);
         }
     }
 }
开发者ID:jpiolho,项目名称:sledge,代码行数:11,代码来源:MdlProvider.cs

示例3: TestSameCore

		private void TestSameCore(IFile memTempFile, IFile localTempFile, FileMode mode, FileAccess access, FileShare share)
		{
			Stream memStream = null, localStream = null;
			Exception memException = null, localException = null;
			try
			{
				memStream = memTempFile.Open(mode, access, share);
			}
			catch (Exception e)
			{
				memException = e;
			}
			try
			{
				localStream = localTempFile.Open(mode, access, share);
			}
			catch (Exception e)
			{
				localException = e;
			}
			if (memException != null || localException != null)
			{
				if (memStream != null) memStream.Dispose();
				if (localStream != null) localStream.Dispose();

				var anyException = (memException ?? localException).GetType();

				Assert.That(memException, Is.InstanceOf(anyException), string.Format("In-Memory ex was {0}, but file was: {1}", 
					memException != null ? memException.ToString() : "NULL", 
					localException != null ? localException.ToString() : "NULL"));
				
				Assert.That(localException, Is.InstanceOf(anyException), string.Format("Local file ex was {0}, but in mem was: {1}.",
					localException != null ? localException.ToString() : "NULL", 
					memException != null ? memException.ToString() : "NULL"));

				if (!(memException.GetType() == anyException && localException.GetType() == anyException))
					Console.WriteLine("Memory exception: " + (memException != null ? memException.GetType().Name : null) +
					                  " Local exception: " + (localException != null ? localException.GetType().Name : null));
				return;
			}
			if (memStream.CanWrite)
				memStream.WriteByte(99);
			if (localStream.CanWrite)
				localStream.WriteByte(99);
			memStream.Dispose();
			localStream.Dispose();

			using (memStream = memTempFile.OpenRead())
			using (localStream = localTempFile.OpenRead())
			{
				memStream.ReadToEnd().ShouldBe(localStream.ReadToEnd());
				localStream.Close();
				memStream.Close();
			}
		}
开发者ID:hammett,项目名称:Castle.Transactions,代码行数:55,代码来源:open_behavior_is_same.cs

示例4: GetSize

        private static Size GetSize(IFile file)
        {
            using (var br = new BinaryReader(file.Open()))
            {
                var idst = br.ReadFixedLengthString(Encoding.ASCII, 4);
                if (idst != "IDSP") return Size.Empty;
                var version = br.ReadInt32();
                if (version != 2) return Size.Empty;
                var type = (SpriteOrientation) br.ReadInt32();
                var texFormat = (SpriteRenderMode) br.ReadInt32();
                var boundingRadius = br.ReadSingle();
                var width = br.ReadInt32();
                var height = br.ReadInt32();

                return new Size(width, height);
            }
        }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:17,代码来源:SprProvider.cs

示例5: Sign

        public static void Sign(this IFile sourceAssembly, IFile destinationAssembly, StrongNameKeyPair key, Version version = null)
        {
            var sourcePdbFile = sourceAssembly.Parent.GetFile(sourceAssembly.NameWithoutExtension + ".pdb");
            var sourcePdbStream = (Stream)null; //sourcePdbFile.Exists ? sourcePdbFile.OpenRead() : null;

            using(var sourceStream = sourceAssembly.OpenRead())
            {
                var readerParameters = new ReaderParameters();
                if (sourcePdbStream != null)
                {
                    readerParameters.SymbolStream = sourcePdbStream;
                    readerParameters.ReadSymbols = true;
                }
                var assembly = AssemblyDefinition.ReadAssembly(sourceStream, readerParameters);
                var name = assembly.Name;
                name.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
                name.PublicKey = key.PublicKey;
                if (version != null)
                    name.Version = version;
                assembly.Name.HasPublicKey = true;
                var writerParameters = new WriterParameters() { StrongNameKeyPair = key };
                var destinationPdbStream = sourcePdbStream != null ? destinationAssembly.Parent.GetFile(destinationAssembly.NameWithoutExtension + ".pdb").OpenWrite() : null;
                if (sourcePdbStream != null)
                {
                    writerParameters.SymbolStream = destinationPdbStream;
                    writerParameters.WriteSymbols = true;
                }
                using (var destinationStream = destinationAssembly.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.None))
                {
                    assembly.Write(destinationStream, writerParameters);
                }
                if (sourcePdbStream != null)
                {
                    sourcePdbStream.Close();
                    destinationPdbStream.Close();
                }
            }
        }
开发者ID:modulexcite,项目名称:openwrap,代码行数:38,代码来源:AssemblyFiddler.cs

示例6: GetImage

 public static Bitmap GetImage(IFile file, int maxWidth = 0, int maxHeight = 0)
 {
     return GetImage(file.Open(), maxWidth, maxHeight);
 }
开发者ID:silky,项目名称:sledge,代码行数:4,代码来源:VtfProvider.cs

示例7: GetSize

 public static Size GetSize(IFile file)
 {
     return GetSize(file.Open());
 }
开发者ID:silky,项目名称:sledge,代码行数:4,代码来源:VtfProvider.cs

示例8: Parse

        private static Bitmap Parse(IFile file)
        {
            // Sprite file spec taken from the spritegen source in the Half-Life SDK.
            using (var br = new BinaryReader(file.Open()))
            {
                var idst = br.ReadFixedLengthString(Encoding.ASCII, 4);
                if (idst != "IDSP") return null;
                var version = br.ReadInt32();
                if (version != 2) return null;
                var type = (SpriteOrientation) br.ReadInt32();
                var texFormat = (SpriteRenderMode) br.ReadInt32();
                var boundingRadius = br.ReadSingle();
                var width = br.ReadInt32();
                var height = br.ReadInt32();
                var numframes = br.ReadInt32();
                var beamlength = br.ReadSingle();
                var synctype = br.ReadInt32();
                var paletteSize = br.ReadInt16();
                var palette = br.ReadBytes(paletteSize * 3);

                if (paletteSize > 256) paletteSize = 256; // Don't accept anything higher
                var colours = new Color[256];
                for (var i = 0; i < paletteSize; i++)
                {
                    var r = palette[i * 3 + 0];
                    var g = palette[i * 3 + 1];
                    var b = palette[i * 3 + 2];
                    colours[i] = Color.FromArgb(255, r, g, b);
                }

                // Only read the first frame.
                var frametype = br.ReadInt32();
                if (frametype != 0)
                {
                    var num = br.ReadInt32();
                    var intervals = br.ReadSingleArray(num);
                }
                var originX = br.ReadInt32();
                var originY = br.ReadInt32();
                var framewidth = br.ReadInt32();
                var frameheight = br.ReadInt32();
                var pixels = br.ReadBytes(framewidth * frameheight);

                var bitmap = new Bitmap(framewidth, frameheight, PixelFormat.Format8bppIndexed);

                // Pre-process the palette
                var pal = bitmap.Palette;
                var last = colours[255];
                for (var i = 0; i < paletteSize; i++)
                {
                    var c = colours[i];
                    if (texFormat == SpriteRenderMode.Additive)
                    {
                        var a = (int) ((c.R + c.G + c.B) / 3f);
                        c = Color.FromArgb(a, c);
                    }
                    else if (texFormat == SpriteRenderMode.IndexAlpha && i < 255)
                    {
                        var a = (int) ((c.R + c.G + c.B) / 3f);
                        c = Color.FromArgb(a, last);
                    }
                    pal.Entries[i] = c;
                }
                if (texFormat == SpriteRenderMode.AlphaTest)
                {
                    pal.Entries[255] = Color.FromArgb(0, 0, 0, 0);
                }
                bitmap.Palette = pal;

                // Set the pixel data
                var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
                Marshal.Copy(pixels, 0, data.Scan0, data.Width * data.Height);
                bitmap.UnlockBits(data);

                return bitmap;
            }
        }
开发者ID:KonstantinUb,项目名称:sledge,代码行数:77,代码来源:SprProvider.cs

示例9: RenameTo

        /// <summary>
        ///  Renames/Moves this file to the specified file instance.
        /// </summary>
        /// <param name="dest">File to rename/move to.</param>
        /// <returns>boolean true - success, false - failure</returns>
        public virtual bool RenameTo(IFile dest)
        {
            // Copy to local FS
            if (dest is LocalFile) {
                this.ExportFile(dest.AbsolutePath);
                this.Delete(true);
                return true;
            }

            // Move to other fs
            if (this.IsDirectory) {
                if (!dest.Exists)
                    dest.MkDir();

                foreach (IFile fromFile in this.ListTree()) {
                    IFile toFile = this.manager.GetFile(dest.AbsolutePath, fromFile.AbsolutePath.Substring(this.AbsolutePath.Length + 1));

                    if (fromFile.IsFile)
                        IOUtils.StreamFromTo(fromFile.Open(FileMode.Open), toFile.Open(FileMode.Create), 1024);
                    else
                        toFile.MkDir();
                }
            } else
                IOUtils.StreamFromTo(this.Open(FileMode.Open), dest.Open(FileMode.Create), 1024);

            this.Delete(true);

            return true;
        }
开发者ID:nhtera,项目名称:CrowdCMS,代码行数:34,代码来源:BaseFile.cs

示例10: SingleCopy

        private void SingleCopy(IFile srcfile, IDirectory dstdirpar)
        {
            IElement dstelem = dstdirpar.GetChild(srcfile.Name); // TODO: try catch

            if(dstelem != null) {
                throw new Exception(dstelem.FullName + " already exists.");
            }

            _wnd.Invoke( (FVoid) delegate { _wnd.Line1 = "Copying " + srcfile.FullName + " ..."; }  );

            bool retry;
            do {
                retry = false;
                try {
                    using(Stream srcstm = srcfile.Open(true, false)) {
                        using(Stream dststm = dstdirpar.CreateFileAndOpen(srcfile.Name, srcfile.Size, srcfile.ContentType, false, true) /* dstfile.Open(false, true) */) {

                            long   pos = 0;
                            long   len = srcstm.Length;
                            byte[] buf = new byte[4096]; // Setting a lower value seems to help against timeouts at Amazon S3 (before: 65536)

                            while(len > 0) {
                                int now = (len > buf.Length) ? buf.Length : (int) len;

                                now = srcstm.Read (buf, 0, now);
                                      dststm.Write(buf, 0, now);
                                      dststm.Flush();

                                len -= now;
                                pos += now;

                                _wnd.Invoke( (FVoid) delegate { _wnd.Line2 = ((pos + 1023) >> 10) + " KB copied."; }  );

                                if(_cancel) break;
                            }
                        }
                    }
                } catch(Exception ex) {
                    switch(MessageBox.Show("Failed to copy '" + srcfile.FullName + "' to '" + dstdirpar.FullName + "'.\n" + ex.Message + "\n\nDo you want to retry?\nSelect 'Cancel' to abort.", "Error", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error)) {
                        case DialogResult.Yes:    retry   = true;  break;
                        case DialogResult.No:     retry   = false; break;
                        case DialogResult.Cancel: _cancel = true;  break;
                    }
                    try {
                        dstelem = dstdirpar.GetChild(srcfile.Name);
                        if(dstelem != null) dstelem.Delete();
                    } catch { }
                }
            } while(retry && !_cancel);

            _wnd.Invoke( (FVoid) delegate { _wnd.Line2 = null; }  );
        }
开发者ID:njmube,项目名称:amazon-s3-tools,代码行数:52,代码来源:BackgroundJob.cs


注:本文中的IFile.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。