예제 #1
0
파일: IotHubClient.cs 프로젝트: ebragge/SDE
        private static async Task LoadQueueInternalAsync(IotHubClient client)
        {
            System.Collections.Generic.Queue<DataPoint> tmp = new System.Collections.Generic.Queue<DataPoint>();
            try
            {
                StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                StorageFile file = await storageFolder.GetFileAsync(FILE_NAME);

                var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
                ulong size = stream.Size;

                using (var inputStream = stream.GetInputStreamAt(0))
                {
                    using (var dataReader = new DataReader(inputStream))
                    {
                        uint numBytesLoaded = await dataReader.LoadAsync((uint)size);
                        int count = dataReader.ReadInt32();
                        for (int i = 0; i < count; i++)
                        {
                            DataPoint p = new DataPoint();
                            p.Read(dataReader);
                            tmp.Enqueue(p);
                        }
                    }

                }
                stream.Dispose();
                lock (client.thisLock)
                {
                    client.queue.Clear();
                    client.queue = null;
                    client.queue = new System.Collections.Generic.Queue<DataPoint>(tmp);
                }
            }
            catch (Exception) { }
        }