public RawChannelLogModel GetLogs(string title, string id) { var loggingPath = StringExtensions.MakeSafeFolderPath(CurrentCharacter, title, id); var toReturn = new RawChannelLogModel(); if (!Directory.Exists(loggingPath)) return toReturn; var file = new DirectoryInfo(loggingPath) .GetFiles("*.txt") .OrderByDescending(x => x.LastWriteTime).FirstOrDefault(); if (file == null) return toReturn; try { var lines = File.ReadLines(file.FullName); var enumerable = lines as IList<string> ?? lines.ToList(); var toSkip = Math.Max(enumerable.Count() - 25, 0); toReturn.RawLogs = enumerable.Skip(toSkip).ToList(); toReturn.DateOfLog = file.LastWriteTime; } catch { // file operations run the risk of exceptions return toReturn; } return toReturn; }
public RawChannelLogModel GetLogs(string title, string id) { var loggingPath = StringExtensions.MakeSafeFolderPath(CurrentCharacter, title, id); var toReturn = new RawChannelLogModel(); if (!Directory.Exists(loggingPath)) { return(toReturn); } var file = new DirectoryInfo(loggingPath) .GetFiles("*.txt") .OrderByDescending(x => x.LastWriteTime).FirstOrDefault(); if (file == null) { return(toReturn); } try { var lines = File.ReadLines(file.FullName); var enumerable = lines as IList <string> ?? lines.ToList(); var toSkip = Math.Max(enumerable.Count() - 25, 0); toReturn.RawLogs = enumerable.Skip(toSkip).ToList(); toReturn.DateOfLog = file.LastWriteTime; } catch { // file operations run the risk of exceptions return(toReturn); } return(toReturn); }
private void RequestNavigate(string channelId) { automation.UserDidAction(); Log("Requested " + channelId); var wantsNoteView = false; var wantsProfileView = false; if (channelId.EndsWith("/notes")) { channelId = channelId.Substring(0, channelId.Length - "/notes".Length); wantsNoteView = true; } if (channelId.EndsWith("/profile")) { channelId = channelId.Substring(0, channelId.Length - "/profile".Length); wantsProfileView = true; } if (lastSelected != null) { if (lastSelected.Id.Equals(channelId, StringComparison.OrdinalIgnoreCase)) { return; } Dispatcher.Invoke(() => { var toUpdate = cm.CurrentChannels.FirstByIdOrNull(lastSelected.Id) ?? (ChannelModel)cm.CurrentPms.FirstByIdOrNull(lastSelected.Id); if (toUpdate == null) { lastSelected = null; } else { toUpdate.IsSelected = false; } }); } var channelModel = cm.CurrentChannels.FirstByIdOrNull(channelId) ?? (ChannelModel)cm.CurrentPms.FirstByIdOrNull(channelId); if (channelModel == null) { throw new ArgumentOutOfRangeException(nameof(channelId), "Cannot navigate to unknown channel"); } var pmChannelModel = channelModel as PmChannelModel; if (pmChannelModel != null) { pmChannelModel.ShouldViewNotes = wantsNoteView || pmChannelModel.ShouldViewNotes; pmChannelModel.ShouldViewProfile = wantsProfileView || pmChannelModel.ShouldViewProfile; } channelModel.IsSelected = true; cm.CurrentChannel = channelModel; if (!channelModel.Messages.Any() && !channelModel.Ads.Any()) { var history = new RawChannelLogModel(); if (!channelId.Equals("Home")) { history = logger.GetLogs(channelModel.Title, channelModel.Id); } if (history.RawLogs.Any()) { Dispatcher.Invoke(() => history.RawLogs .Select(item => new MessageModel(item, characters.Find, history.DateOfLog)) .Each(item => channelModel.AddMessage(item) )); } } Log("Requesting " + channelModel.Id + " channel view"); Dispatcher.Invoke(() => { foreach (var r in region.Regions[ChatWrapperView.ConversationRegion].Views) { var view = r as DisposableView; if (view != null) { var toDispose = view; toDispose.Dispose(); region.Regions[ChatWrapperView.ConversationRegion].Remove(toDispose); } else { region.Regions[ChatWrapperView.ConversationRegion].Remove(r); } } region.Regions[ChatWrapperView.ConversationRegion].RequestNavigate( StringExtensions.EscapeSpaces(channelModel.Id)); }); lastSelected = channelModel; }
private void RequestNavigate(string channelId) { automation.UserDidAction(); Log("Requested " + channelId); var wantsNoteView = false; var wantsProfileView = false; if (channelId.EndsWith("/notes")) { channelId = channelId.Substring(0, channelId.Length - "/notes".Length); wantsNoteView = true; } if (channelId.EndsWith("/profile")) { channelId = channelId.Substring(0, channelId.Length - "/profile".Length); wantsProfileView = true; } if (lastSelected != null) { if (lastSelected.Id.Equals(channelId, StringComparison.OrdinalIgnoreCase)) return; Dispatcher.Invoke(() => { var toUpdate = cm.CurrentChannels.FirstByIdOrNull(lastSelected.Id) ?? (ChannelModel) cm.CurrentPms.FirstByIdOrNull(lastSelected.Id); if (toUpdate == null) lastSelected = null; else toUpdate.IsSelected = false; }); } var channelModel = cm.CurrentChannels.FirstByIdOrNull(channelId) ?? (ChannelModel) cm.CurrentPms.FirstByIdOrNull(channelId); if (channelModel == null) throw new ArgumentOutOfRangeException(nameof(channelId), "Cannot navigate to unknown channel"); var pmChannelModel = channelModel as PmChannelModel; if (pmChannelModel != null) { pmChannelModel.ShouldViewNotes = wantsNoteView || pmChannelModel.ShouldViewNotes; pmChannelModel.ShouldViewProfile = wantsProfileView || pmChannelModel.ShouldViewProfile; } channelModel.IsSelected = true; cm.CurrentChannel = channelModel; if (!channelModel.Messages.Any() && !channelModel.Ads.Any()) { var history = new RawChannelLogModel(); if (!channelId.Equals("Home")) history = logger.GetLogs(channelModel.Title, channelModel.Id); if (history.RawLogs.Any()) { Dispatcher.Invoke(() => history.RawLogs .Select(item => new MessageModel(item, characters.Find, history.DateOfLog)) .Each(item => channelModel.AddMessage(item) )); } } Log("Requesting " + channelModel.Id + " channel view"); Dispatcher.Invoke(() => { foreach (var r in region.Regions[ChatWrapperView.ConversationRegion].Views) { var view = r as DisposableView; if (view != null) { var toDispose = view; toDispose.Dispose(); region.Regions[ChatWrapperView.ConversationRegion].Remove(toDispose); } else region.Regions[ChatWrapperView.ConversationRegion].Remove(r); } region.Regions[ChatWrapperView.ConversationRegion].RequestNavigate( StringExtensions.EscapeSpaces(channelModel.Id)); }); lastSelected = channelModel; }