EventFromString() public static method

Parse the given string to a HistoryEvent.
public static EventFromString ( string s ) : HistoryEvent
s string Comma separated string representing a HistoryEvent.
return HistoryEvent
Ejemplo n.º 1
0
        public async Task SetEventsAsDelivered(IList <HistoryEvent> sendEvents)
        {
            {
                StorageFolder folder = await GetFolder(BackgroundEventsFolder, true);

                IReadOnlyList <StorageFolder> folders = await folder.GetFoldersAsync();

                foreach (StorageFolder storageFolder in folders)
                {
                    IReadOnlyList <StorageFile> files = await storageFolder.GetFilesAsync();

                    //ignore unlocked folders
                    if (files.FirstOrDefault(f => f.Name == FolderLockFile) == null)
                    {
                        continue;
                    }
                    await storageFolder.DeleteAsync();
                }
            }
            await ForegroundHistoryEventWriter.RewriteFile((l, l2) =>
            {
                foreach (string s in l)
                {
                    HistoryEvent e = FileStorageHelper.EventFromString(s);
                    if (!sendEvents.Contains(e))
                    {
                        l2.Add(s);
                    }
                }
            });
        }
Ejemplo n.º 2
0
        private async Task <IList <HistoryEvent> > GetUndeliveredEvents(bool lockFolder)
        {
            IList <HistoryEvent> events = new List <HistoryEvent>();

            {
                StorageFolder folder = await GetFolder(BackgroundEventsFolder);

                if (lockFolder)
                {
                    await CreateEventMarker(folder);
                }
                IReadOnlyList <StorageFolder> folders = await(await folder.GetParentAsync()).GetFoldersAsync();
                foreach (StorageFolder storageFolder in folders)
                {
                    IReadOnlyList <StorageFile> files = await storageFolder.GetFilesAsync();

                    //when no lock ignore unlocked folders
                    if (!lockFolder && files.FirstOrDefault(f => f.Name == FolderLockFile) == null)
                    {
                        continue;
                    }

                    foreach (StorageFile file in files)
                    {
                        if (file.Name == FolderLockFile)
                        {
                            continue;
                        }
                        List <HistoryEvent> fileEvents = FileStorageHelper.EventsFromStrings(await FileIO.ReadLinesAsync(file));
                        if (fileEvents != null)
                        {
                            foreach (HistoryEvent historyEvent in fileEvents)
                            {
                                if (!historyEvent.Delivered)
                                {
                                    events.Add(historyEvent);
                                }
                            }
                        }
                    }
                }
            }
            if (ForegroundHistoryEventWriter != null)
            {
                List <string> list = await ForegroundHistoryEventWriter.ReadLines();

                foreach (string s in list)
                {
                    HistoryEvent historyEvent = FileStorageHelper.EventFromString(s);
                    if (historyEvent != null && !historyEvent.Delivered)
                    {
                        events.Add(historyEvent);
                    }
                }
            }
            return(events);
        }