/// <summary>
		/// Creates and adds a time track objects into the Items collection.
		/// </summary>
		public async void LoadData() {

			var fileList = await ApplicationData.Current.LocalFolder.GetFilesAsync();
			var file = fileList.FirstOrDefault(f => f.Name == localFileName);
			if (file != null) {
				using (var stream = await file.OpenReadAsync()) {
					using (var dr = new Windows.Storage.Streams.DataReader(stream)) {
						try {
							await dr.LoadAsync(unchecked((uint)stream.Size));
							var numberOfItems = dr.ReadInt32();
							ObservableCollection<TrackItem> loadingItems = new ObservableCollection<TrackItem>();
							for (int x = 0; x < numberOfItems; x++) {
								TrackItem item = new TrackItem();
								item.Start = dr.ReadDateTime();
								item.End = dr.ReadDateTime();
								int topicLength = dr.ReadInt32();
								item.Topic = dr.ReadString((uint)topicLength);
								loadingItems.Add(item);
							}
							bool currentItemExists = dr.ReadBoolean();
							TrackItem loadingCurrentItem = null;
							if (currentItemExists) {
								loadingCurrentItem = new TrackItem();
								loadingCurrentItem.Start = dr.ReadDateTime();
								int topicLength = dr.ReadInt32();
								loadingCurrentItem.Topic = dr.ReadString((uint)topicLength);
							}
							dr.DetachStream();

							Items = loadingItems;
							OnPropertyChanged(nameof(Items));
							CurrentItem = loadingCurrentItem;
							IsDataLoaded = true;
						} catch {
							try {
								await file.DeleteAsync();
							} catch { }
							CurrentItem = null;
							IsDataLoaded = true;
						}
					}
				}
			} else {
				// Sample data; replace with real data
				Items.Add(new TrackItem() {
					Topic = "First Tracked Item",
					Start = new DateTimeOffset(new DateTime(2015, 11, 5, 9, 0, 0), new TimeSpan(-6, 0, 0)),
					End = new DateTimeOffset(new DateTime(2015, 11, 5, 11, 30, 0), new TimeSpan(-6, 0, 0)),
				});
				Items.Add(new TrackItem() {
					Topic = "Second Tracked Item",
					Start = new DateTimeOffset(new DateTime(2015, 11, 5, 12, 30, 0), new TimeSpan(-6, 0, 0)),
					End = new DateTimeOffset(new DateTime(2015, 11, 5, 17, 0, 0), new TimeSpan(-6, 0, 0)),
				});
				CurrentItem = null;
				this.IsDataLoaded = true;
			}
		}
        // Read out and print the message received from the socket.
        private async void StartReader(Windows.Networking.Proximity.ProximityStreamSocket socket,
                                       Windows.Storage.Streams.DataReader reader)
        {
            uint initialLength = 4;

            try
            {
                await reader.LoadAsync(initialLength);

                uint msgLength = (uint)reader.ReadInt32();

                try
                {
                    await reader.LoadAsync(msgLength);

                    string message = reader.ReadString(msgLength);
                    WriteMessageText("Received message: " + message + "\n");

                    // After receiving a message, listen for the next message.
                    StartReader(socket, reader);
                }
                catch (Exception e)
                {
                    WriteMessageText("Error: " + e.Message + "\n");
                    socket.Dispose();
                }
            }
            catch (Exception e)
            {
                WriteMessageText("Error: " + e.Message + "\n");
                socket.Dispose();
            }
        }
Example #3
0
		public static async Task<List<Session>> DeserializeLocalSessions(StorageFile file) {
			using (var stream = await file.OpenSequentialReadAsync()) {
				using (var dr = new Windows.Storage.Streams.DataReader(stream)) {
					var numberOfSessions = dr.ReadInt32();
					List<Session> rv = new List<Session>(numberOfSessions);
					for (int x = 0; x < numberOfSessions; x++) {
						rv.Add(LoadSession(dr));
					}
					return rv;
				}
			}
		}
Example #4
0
        public static async Task <int[]> ReadFile(StorageFile file)
        {
            int[] result;
            var   stream = await file.OpenAsync(FileAccessMode.Read);

            ulong size = stream.Size;

            using (var inputStream = stream.GetInputStreamAt(0))
            {
                using (var dataReader = new Windows.Storage.Streams.DataReader(inputStream))
                {
                    await dataReader.LoadAsync((uint)size);

                    int quantity = dataReader.ReadInt32();
                    result = new int[quantity];

                    for (int i = 0; i < quantity; i++)
                    {
                        result[i] = dataReader.ReadInt32();
                    }
                }
            }
            return(result);
        }