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


C# IsolatedStorageFileStream.Read方法代码示例

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


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

示例1: Convert

        public override object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            _values = values;
            if (values.Any(w => w == null || string.IsNullOrEmpty(w.ToString())))
                return null;

            byte[] imageBytes;
            var path = string.Concat("/Shared/ShellContent/", string.Format("{0}.jpg", string.Join("_", values)));

            using (var iso = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!iso.FileExists(path))
                    return null;

                using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, iso))
                {
                    imageBytes = new byte[fileStream.Length];

                    fileStream.Read(imageBytes, 0, imageBytes.Length);
                }
            }

            using (var memoryStream = new MemoryStream(imageBytes))
            {
                BitmapImage bitmapImage = new BitmapImage();

                bitmapImage.SetSource(memoryStream);
                return bitmapImage;
            }
        }
开发者ID:XVincentX,项目名称:SimInfo,代码行数:30,代码来源:ImageConverter.cs

示例2: MainPage_Loaded

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            List<Run> runList = new List<Run>();
            string time, dist;

            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("SavedSessions.txt", FileMode.Open, IsolatedStorageFile.GetUserStoreForApplication()))
            {
                if (!stream.CanRead) return;

                long length = stream.Length;
                byte[] decoded = new byte[length];
                stream.Read(decoded, 0, (int)length);

                string str = "";
                for (int i = 0; i < decoded.Length; i++)
                    str += (char)decoded[i];

                string[] val = Regex.Split(str, " ");

                time = val[0] + ":" + val[1] + ":" + val[2] + val[3];
                dist = val[4];

                runList.Add(new Run(time, dist));
            }

            TransactionList.ItemsSource = runList;
        }
开发者ID:frank44,项目名称:Just-Run,代码行数:27,代码来源:History.xaml.cs

示例3: SendSongOverSocket

        //send song data over the socket
        //this uses an app specific socket protocol: send title, artist, then song data
        public async Task<bool> SendSongOverSocket(StreamSocket socket, string fileName, string songTitle, string songFileSize)
        {
            try
            {
                // Create DataWriter for writing to peer.
                _dataWriter = new DataWriter(socket.OutputStream);

                //send song title
                await SendStringOverSocket(songTitle);

                //send song file size
                await SendStringOverSocket(songFileSize);

                // read song from Isolated Storage and send it
                using (var fileStream = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication()))
                {
                    byte[] buffer = new byte[1024];
                    int bytesRead;
                    int readCount = 0;
                    _length = fileStream.Length;

                    //Initialize the User Interface elements
                    InitializeUI(fileName);

                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        readCount += bytesRead;
                        //UpdateUI
                        UpdateProgressBar(readCount);
                        //size of the packet
                        _dataWriter.WriteInt32(bytesRead);
                        //packet data sent
                        _dataWriter.WriteBytes(buffer);
                        try
                        {
                            await _dataWriter.StoreAsync();
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                    }
                }

                return true;
            }
            catch
            {
                return false;
            }

        }
开发者ID:WillVandergrift,项目名称:OneTone,代码行数:54,代码来源:NFCConnection.cs

示例4: ReadBytesFromIsolatedStorage

 /// <summary>
 /// Reads all byte content from an isolated storage file.
 /// </summary>
 /// <param name="path">Path to the file.</param>
 /// <returns>The bytes read from the file.</returns>
 public static byte[] ReadBytesFromIsolatedStorage(string path)
 {
     // Access the file in the application's isolated storage.
     using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (IsolatedStorageFileStream readstream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, file))
         {
             byte[] valueArray = new byte[readstream.Length];
             readstream.Read(valueArray, 0, valueArray.Length);
             return valueArray;
         }
     }
 }
开发者ID:LarryPavanery,项目名称:Yammer-OAuth-SDK,代码行数:18,代码来源:StorageUtils.cs

示例5: GetSubscriptionCertificate

        public static byte[] GetSubscriptionCertificate(string subscriptionId)
        {
            IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
            byte[] certificateBytes = null;

            // Go into the isolated storage and retrieve the certificate.
            //
            using (var isoFileStream = new IsolatedStorageFileStream(subscriptionId + "\\management.cer", FileMode.Open, myStore))
            {
                certificateBytes = new byte[isoFileStream.Length];
                isoFileStream.Read(certificateBytes, 0, (int)isoFileStream.Length);
            }

            return certificateBytes;
        }
开发者ID:tomasmcguinness,项目名称:AzureManager,代码行数:15,代码来源:SubscriptionManager.cs

示例6: ReadFile

 public static string ReadFile(string filename)
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
     {
         try
         {
             IsolatedStorageFileStream filestream = new IsolatedStorageFileStream(filename, System.IO.FileMode.Open, isf);
             byte[] buffer = new byte[filestream.Length];
             filestream.Read(buffer,0,buffer.Length);
             string data = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
             return data;
         }
         catch (System.IO.FileNotFoundException)
         {
             return string.Empty;
         }
     }
 }
开发者ID:ahmeda8,项目名称:engadget-reader,代码行数:18,代码来源:ISO.cs

示例7: GetRecordByteArray

        public static byte[] GetRecordByteArray(string name)
        {
            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

            MemoryStream stream = new MemoryStream();
            using (IsolatedStorageFileStream fStream = new IsolatedStorageFileStream("Music/" + name,
                FileMode.Open, file))
            {
                byte[] readBuffer = new byte[4096];
                int bytesRead = 0;

                while ((bytesRead = fStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    stream.Write(readBuffer, 0, bytesRead);
                }
            }

            return stream.ToArray();
        }
开发者ID:NickCulbertson,项目名称:beem,代码行数:19,代码来源:RecordManager.cs

示例8: get

        /// <summary>
        /// 获取上传进度记录
        /// </summary>
        /// <param name="key">记录文件名</param>
        /// <returns>上传进度数据</returns>
        public byte[] get(string key)
        {
            byte[] data = null;
            string filePath = Path.Combine(this.dir, StringUtils.urlSafeBase64Encode(key));
            try
            {
                using (IsolatedStorageFileStream stream =
                    new IsolatedStorageFileStream(filePath, FileMode.Open, this.storage))
                {
                    data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                }
            }
            catch (Exception)
            {

            }
            return data;
        }
开发者ID:bleupierre,项目名称:wp-sdk,代码行数:24,代码来源:ResumeRecorder.cs

示例9: Load

 public void Load()
 {
     XmlSerializer serializer = new XmlSerializer(typeof(Configrations));
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("a.txt", FileMode.Open, isf))
         {
             byte[] buffer = new byte[fs.Length];
             fs.Read(buffer, 0, buffer.Length);
             using (MemoryStream ms = new MemoryStream(buffer))
             {
                 Configrations config = serializer.Deserialize(ms) as Configrations;
                 if (null != config)
                 {
                     Clone(this, config);
                 }
             }
         }
     }
 }
开发者ID:kjiwu,项目名称:GuessNumberRemaster,代码行数:20,代码来源:Configrations.cs

示例10: OnNavigatedTo

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.TryGetValue("imageUri", out imageFileName))
            {
                FilenameText.Text = imageFileName;

                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(imageFileName, System.IO.FileMode.Open, IsolatedStorageFile.GetUserStoreForApplication()))
                {
                    // Allocate an array large enough for the entire file
                    byte[] data = new byte[stream.Length];
                    // Read the entire file and then close it
                    stream.Read(data, 0, data.Length);
                    stream.Close();

                    ExtendedImage image = new ExtendedImage();
                    image.LoadingCompleted +=
                        (o, ea) => Dispatcher.BeginInvoke(() => { AnimatedImage.Source = image; });

                    image.SetSource(new MemoryStream(data));
                }
            }
        }
开发者ID:henrikstromberg,项目名称:image-sequencer,代码行数:24,代码来源:GifViewer.xaml.cs

示例11: Retrieve

        public byte[] Retrieve(string key)
        {
            var mutex = new Mutex(false, key);

            try
            {
                mutex.WaitOne();
                if (!File.FileExists(key))
                {
                    throw new Exception(string.Format("No entry found for key {0}.", key));
                }

                using (var stream = new IsolatedStorageFileStream(key, FileMode.Open, FileAccess.Read, File))
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    return ProtectedData.Unprotect(data, this.optionalEntropy);
                }
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
开发者ID:HugeLawn-MiracleApps,项目名称:Xamarin-Forms-Labs,代码行数:24,代码来源:SecureStorage.cs

示例12: GetMainPageString

 private static string GetMainPageString(string elementName)
 {
     using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) {
         using (var file = new IsolatedStorageFileStream("mainpage.xml", FileMode.Open, iso)) {
             var bb = new byte[file.Length];
             file.Read(bb, 0, bb.Length);
             using (var oStream = new MemoryStream(bb)) {
                 XDocument xDoc = XDocument.Load(oStream);
                 try {
                     return xDoc.Element("items").Element(elementName).Value;
                 }
                 catch (NullReferenceException) {
                     return string.Empty;
                 }
             }
         }
     }
 }
开发者ID:tymiles003,项目名称:FieldService,代码行数:18,代码来源:MainViewModel.cs

示例13: RegressionBNC354539

		public void RegressionBNC354539 ()
		{
			string filename = "test-bnc-354539";
			byte[] expected = new byte[] { 0x01, 0x42, 0x00 };
			byte[] actual = new byte [expected.Length];

			using (IsolatedStorageFile file = IsolatedStorageFile.GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) {
				using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream (filename, FileMode.Create, FileAccess.Write, FileShare.None, file)) {
					stream.Write (expected, 0, expected.Length);
				}
			}

			using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly ()) {
				using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream (filename, FileMode.Open, FileAccess.Read, FileShare.Read, file)) {
					stream.Read (actual, 0, actual.Length);
				}

				file.DeleteFile (filename);
			}
			
			Assert.AreEqual (expected, actual);
		}
开发者ID:nkuln,项目名称:mono,代码行数:22,代码来源:IsolatedStorageFileTest.cs

示例14: uploadCallback

        /// <summary>
        /// Read file from Isolated Storage and sends it to server
        /// </summary>
        /// <param name="asynchronousResult"></param>
        private void uploadCallback(IAsyncResult asynchronousResult)
        {
            DownloadRequestState reqState = (DownloadRequestState)asynchronousResult.AsyncState;
            HttpWebRequest webRequest = reqState.request;
            string callbackId = reqState.options.CallbackId;

            try
            {
                using (Stream requestStream = (webRequest.EndGetRequestStream(asynchronousResult)))
                {
                    string lineStart = "--";
                    string lineEnd = Environment.NewLine;
                    byte[] boundaryBytes = System.Text.Encoding.UTF8.GetBytes(lineStart + Boundary + lineEnd);
                    string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"" + lineEnd + lineEnd + "{1}" + lineEnd;

                    if (!string.IsNullOrEmpty(reqState.options.Params))
                    {
                        Dictionary<string, string> paramMap = parseHeaders(reqState.options.Params);
                        foreach (string key in paramMap.Keys)
                        {
                            requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
                            string formItem = string.Format(formdataTemplate, key, paramMap[key]);
                            byte[] formItemBytes = System.Text.Encoding.UTF8.GetBytes(formItem);
                            requestStream.Write(formItemBytes, 0, formItemBytes.Length);
                        }
                        requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
                    }
                    using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (!isoFile.FileExists(reqState.options.FilePath))
                        {
                            DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new FileTransferError(FileNotFoundError, reqState.options.Server, reqState.options.FilePath, 0)));
                            return;
                        }

                        byte[] endRequest = System.Text.Encoding.UTF8.GetBytes(lineEnd + lineStart + Boundary + lineStart + lineEnd);
                        long totalBytesToSend = 0;

                        using (FileStream fileStream = new IsolatedStorageFileStream(reqState.options.FilePath, FileMode.Open, isoFile))
                        {
                            string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"" + lineEnd + "Content-Type: {2}" + lineEnd + lineEnd;
                            string header = string.Format(headerTemplate, reqState.options.FileKey, reqState.options.FileName, reqState.options.MimeType);
                            byte[] headerBytes = System.Text.Encoding.UTF8.GetBytes(header);

                            byte[] buffer = new byte[4096];
                            int bytesRead = 0;
                            //sent bytes needs to be reseted before new upload
                            bytesSent = 0;
                            totalBytesToSend = fileStream.Length;

                            requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);

                            requestStream.Write(headerBytes, 0, headerBytes.Length);

                            while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                            {
                                if (!reqState.isCancelled)
                                {
                                    requestStream.Write(buffer, 0, bytesRead);
                                    bytesSent += bytesRead;
                                    DispatchFileTransferProgress(bytesSent, totalBytesToSend, callbackId);
                                    System.Threading.Thread.Sleep(1);
                                }
                                else
                                {
                                    throw new Exception("UploadCancelledException");
                                }
                            }
                        }

                        requestStream.Write(endRequest, 0, endRequest.Length);
                    }
                }
                // webRequest

                webRequest.BeginGetResponse(ReadCallback, reqState);
            }
            catch (Exception /*ex*/)
            {
                if (!reqState.isCancelled)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, new FileTransferError(ConnectionError)), callbackId);
                }
            }
        }
开发者ID:tommasoR,项目名称:cesana-cordova-3,代码行数:89,代码来源:FileTransfer.cs

示例15: RestoreFromIsolatedStorage

        /// <summary>
        /// Restore the user settings from isolated storage.
        /// </summary>
        /// <param name="Type">The type of the settings object.</param>
        /// <param name="Section">The section in which the settings are stored.</param>
        /// <returns>A populated settings object.</returns>
        private static UserSettingsBase RestoreFromIsolatedStorage(Type Type, string Section)
        {
            XmlSerializer formatter = new XmlSerializer(Type);
            IsolatedStorageFileStream settingsFile;

            try
            {
                settingsFile = new IsolatedStorageFileStream(Section + ".Config", FileMode.Open, IsolatedStorageFile.GetUserStoreForDomain());

            }
            catch (Exception ex)
            {
                throw (new UserSettingsException("User settings not found in isolated storage", ex));

            }

            try
            {
                byte[] buffer = new byte[Convert.ToInt32(settingsFile.Length) - 1 + 1];

                settingsFile.Read(buffer, 0, Convert.ToInt32(settingsFile.Length));

                MemoryStream stream = new MemoryStream(buffer);

                return ((UserSettingsBase) formatter.Deserialize(stream));

            }
            catch (Exception ex)
            {
                throw (new UserSettingsException("User settings could not be loaded from isolated storage", ex));
            }
            finally
            {
                settingsFile.Close();
            }
        }
开发者ID:romeobk,项目名称:HRMS_7Cua,代码行数:42,代码来源:UserSettingsBase.cs


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