Dispose() публичный Метод

public Dispose ( ) : void
Результат void
Пример #1
0
 /// <summary>
 /// 读取本地文件信息,SilverLight缓存中
 /// </summary>
 /// <param name="rFileName">存储文件名</param>
 /// <returns>返回文件数据</returns>
 public static byte[] ReadSlByteFile(string rFileName)
 {
     System.IO.IsolatedStorage.IsolatedStorageFile isf = null;
     System.IO.Stream stream = null;
     byte[]           buffer = null;
     try
     {
         isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
         if (!isf.FileExists(rFileName))
         {
             return(null);
         }
         stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(rFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, isf);
         buffer = new byte[stream.Length];
         stream.Read(buffer, 0, (int)stream.Length);
     }
     finally
     {
         if (stream != null)
         {
             stream.Close(); // Close the stream
             stream.Dispose();
         }
         isf.Dispose();
     }
     return(buffer);
 }
Пример #2
0
 public static T LoadFromFile(string fileName)
 {
     System.IO.IsolatedStorage.IsolatedStorageFile       isoFile   = null;
     System.IO.IsolatedStorage.IsolatedStorageFileStream isoStream = null;
     System.IO.StreamReader sr = null;
     try
     {
         isoFile   = IsolatedStorageFile.GetUserStoreForApplication();
         isoStream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(fileName, FileMode.Open, isoFile);
         sr        = new System.IO.StreamReader(isoStream);
         string xmlString = sr.ReadToEnd();
         isoStream.Close();
         sr.Close();
         return(Deserialize(xmlString));
     }
     finally
     {
         if ((isoFile != null))
         {
             isoFile.Dispose();
         }
         if ((isoStream != null))
         {
             isoStream.Dispose();
         }
         if ((sr != null))
         {
             sr.Dispose();
         }
     }
 }
Пример #3
0
 public virtual void SaveToFile(string fileName)
 {
     System.IO.StreamWriter streamWriter = null;
     System.IO.IsolatedStorage.IsolatedStorageFile       isoFile   = null;
     System.IO.IsolatedStorage.IsolatedStorageFileStream isoStream = null;
     try
     {
         isoFile      = IsolatedStorageFile.GetUserStoreForApplication();
         isoStream    = new System.IO.IsolatedStorage.IsolatedStorageFileStream(fileName, FileMode.Create, isoFile);
         streamWriter = new System.IO.StreamWriter(isoStream);
         string             xmlString = Serialize();
         System.IO.FileInfo xmlFile   = new System.IO.FileInfo(fileName);
         streamWriter = xmlFile.CreateText();
         streamWriter.WriteLine(xmlString);
         streamWriter.Close();
         isoStream.Close();
     }
     finally
     {
         if ((streamWriter != null))
         {
             streamWriter.Dispose();
         }
         if ((isoFile != null))
         {
             isoFile.Dispose();
         }
         if ((isoStream != null))
         {
             isoStream.Dispose();
         }
     }
 }
Пример #4
0
 internal static void ClearSlFiles(string rFileName)
 {
     System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
     if (rFileName == null || rFileName.TrimEnd() == "")
     {
         isf.Remove();
     }
     else
     {
         if (isf.FileExists(rFileName))
         {
             isf.DeleteFile(rFileName);
         }
     }
     isf.Dispose();
 }
Пример #5
0
        /// <summary>
        /// 保存信息至本地文件,SilverLight缓存中
        /// </summary>
        /// <param name="rFileName">存储文件名</param>
        /// <param name="rText">消息文本</param>
        public static void WriteSlTextFile(string rFileName, string rText)
        {
            System.IO.IsolatedStorage.IsolatedStorageFile isf = null;
            System.IO.Stream     stream = null;
            System.IO.TextWriter writer = null;
            try
            {
                isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
                if (rFileName.IndexOf(':') >= 0)
                {
                    rFileName = rFileName.Substring(rFileName.LastIndexOf(':') + 1);
                }
                string rPath = System.IO.Path.GetDirectoryName(rFileName);
                if (isf.DirectoryExists(rPath) == false)
                {
                    isf.CreateDirectory(rPath);
                }
                stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(rFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, isf);
                //stream.Seek(0, System.IO.SeekOrigin.End);
                writer = new System.IO.StreamWriter(stream);
                writer.Write(rText);

                writer.Flush();
            }
            finally
            {
                try
                {
                    writer.Close();
                    stream.Close();
                    isf.Dispose();
                }
                catch
                {
                }
            }
        }
Пример #6
0
 /// <summary>
 /// 读取本地文件信息,SilverLight缓存中
 /// </summary>
 /// <param name="rFileName">存储文件名</param>
 /// <returns>返回消息文本</returns>
 public static string ReadSlTextFile(string rFileName)
 {
     System.IO.IsolatedStorage.IsolatedStorageFile isf = null;
     System.IO.Stream     stream = null;
     System.IO.TextReader reader = null;
     try
     {
         isf    = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
         stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(rFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, isf);
         reader = new System.IO.StreamReader(stream);
         string sLine = reader.ReadToEnd();
         //string sLine=reader.ReadLine();
         return(sLine);
     }
     catch
     {
         return(string.Empty);
     }
     finally
     {
         try
         {
             if (reader != null)
             {
                 reader.Close(); // Close the reader
             }
             if (reader != null)
             {
                 stream.Close();
             }// Close the stream
             isf.Dispose();
         }
         catch
         {
         }
     }
 }
Пример #7
0
        /// <summary>
        /// 保存信息至本地文件,SilverLight缓存中
        /// </summary>
        /// <param name="rFileName"></param>
        /// <param name="buffer"></param>
        public static void WriteSlByteFile(string rFileName, byte[] buffer)
        {
            System.IO.IsolatedStorage.IsolatedStorageFile isf = null;
            System.IO.Stream stream = null;
            try
            {
                isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();

                if (rFileName.IndexOf(':') >= 0)
                {
                    rFileName = rFileName.Substring(rFileName.LastIndexOf(':') + 1);
                }
                ClearSlFile(rFileName);
                string rPath = System.IO.Path.GetDirectoryName(rFileName);
                if (rPath != "")
                {
                    isf.CreateDirectory(rPath);
                }

                stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(rFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.Write, isf);
                stream.Write(buffer, 0, buffer.Length);
                stream.Flush();
            }
            finally
            {
                try
                {
                    stream.Close(); // Close the stream too
                    stream.Dispose();
                    isf.Dispose();
                }
                catch
                {
                }
            }
        }