/// <summary> /// Ejecuta las funciones llamadas desde el explorador /// </summary> public void ExecuteFromExplorer(string arguments) { if (!arguments.IsEmpty()) { string[] parameters = arguments.Split('|'); if (parameters.Length == 2) { BlogEntryViewModel entry = Entries.Search(parameters[1]); if (entry != null) { BlogEntriesCollectionViewModel entries = new BlogEntriesCollectionViewModel { entry }; EntryAction action = parameters[0].GetEnum(EntryAction.Unknown); switch (action) { case EntryAction.MarkRead: if (entry.Entry.Status == EntryModel.StatusEntry.Read) { SetStatusEntries(entries, EntryModel.StatusEntry.NotRead); } else { SetStatusEntries(entries, EntryModel.StatusEntry.Read); } break; case EntryAction.MarkInteresting: if (entry.Entry.Status == EntryModel.StatusEntry.Interesting) { SetStatusEntries(entries, EntryModel.StatusEntry.Read); } else { SetStatusEntries(entries, EntryModel.StatusEntry.Interesting); } break; case EntryAction.Delete: DeleteEntries(entries); break; case EntryAction.Play: PlayEntry(); break; } } } } }
/// <summary> /// Comprueba si se puede cambiar el estado de una entrada /// </summary> private bool CanChangeStatus(BlogEntryViewModel entry, EntryModel.StatusEntry idNewStatus) { bool canChange = false; // Comprueba si se puede cambiar el estado de una entrada if (entry.Status != idNewStatus) { // Indica que por ahora se puede cambiar canChange = true; // Comprueba el nuevo valor if (idNewStatus == EntryModel.StatusEntry.Read && entry.Status == EntryModel.StatusEntry.Interesting) { canChange = false; } } // Devuelve el valor que indica si se puede cambiar el estado return(canChange); }
/// <summary> /// Obtiene un vínculo a una llamada de función externa en JavaScript /// </summary> private string GetJavaScriptExternalFuction(BlogEntryViewModel entry, string title, EntryAction action) { return($"<a href='' onclick=\"window.external.ExternalFunction('{action.ToString()}|{entry.Entry.URL}');return false;\">{title}</a>"); }
/// <summary> /// Obtiene el HTML de las entradas seleccionadas para mostrarlas en el explorador /// </summary> private string GetHtmlNews() { BlogEntriesCollectionViewModel entries = EntriesForView; System.Text.StringBuilder sbHtml = new System.Text.StringBuilder(); string lastBlog = null; int startIndex, endIndex; // Actualiza el número de entradas y de páginas EntriesNumber = entries.Count; if (RecordsPerPage == 0) { RecordsPerPage = 25; } Pages = EntriesNumber / RecordsPerPage; if (EntriesNumber % RecordsPerPage != 0) { Pages++; } // Normaliza la página actual if (ActualPage > Pages) { ActualPage = Pages; } else if (ActualPage < 1) { ActualPage = 1; } // Asigna el índice de inicio y fin startIndex = (ActualPage - 1) * RecordsPerPage; endIndex = startIndex + RecordsPerPage; // Cabecera HTML sbHtml.AppendLine("<html><head>"); sbHtml.AppendLine("<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>"); sbHtml.AppendLine("<meta name = 'Content-Type' content = 'Content-Type: text/html; charset=utf-8'>"); sbHtml.AppendLine("<meta name='lang' content='es'>"); sbHtml.AppendLine("</head><body>"); // Obtiene el HTML for (int index = startIndex; index < endIndex; index++) { if (index >= 0 && index < entries.Count) { BlogEntryViewModel entry = entries[index]; // Título del blog if (!lastBlog.EqualsIgnoreCase(entry.BlogName)) { // Cabecera de blog sbHtml.AppendLine($"<h1 style='clear:both;'>{entry.BlogName}</h1>"); // Guarda la última cabecera de blog lastBlog = entry.BlogName; } // Cabecera de entrada sbHtml.AppendLine($"<h2 style='clear:both;'><a href='{entry.URL}'>{entry.Title}</a></h2>"); // Comandos sobre la entrada sbHtml.AppendLine("<p>"); if (entry.Entry.Status == EntryModel.StatusEntry.NotRead) { sbHtml.AppendLine(GetJavaScriptExternalFuction(entry, "Marcar leído", EntryAction.MarkRead)); } if (entry.Entry.Status == EntryModel.StatusEntry.Read) { sbHtml.AppendLine(GetJavaScriptExternalFuction(entry, "Marcar no leído", EntryAction.MarkRead)); } if (entry.Entry.Status == EntryModel.StatusEntry.Read || entry.Entry.Status == EntryModel.StatusEntry.NotRead) { sbHtml.AppendLine(GetJavaScriptExternalFuction(entry, "Marcar interesante", EntryAction.MarkInteresting)); } sbHtml.AppendLine(GetJavaScriptExternalFuction(entry, "Borrar", EntryAction.Delete)); sbHtml.AppendLine("</p>"); // Cuerpo sbHtml.AppendLine(RemoveIframe(entry.Content) + "<br>"); // Adjunto if (!string.IsNullOrEmpty(entry.UrlEnclosure)) { sbHtml.AppendLine($"<p><strong>Adjunto: </strong>{GetJavaScriptExternalFuction(entry, System.IO.Path.GetFileName(entry.UrlEnclosure), EntryAction.Play)}</p><br>"); } // Autor - Fecha sbHtml.AppendLine($@"<p style='text-align:right;'> <strong>Autor: </strong>{entry.Author} - <strong>Fecha: </strong>{entry.DatePublish:dd-MM-yyyy HH:mm} </p>" ); // Separador sbHtml.AppendLine("<hr>"); } } // Cierre HTML sbHtml.AppendLine("</body></html>"); // Devuelve el HTML return(sbHtml.ToString()); }