/// <summary> /// Saves the YariMediaRecord object state to the database. /// </summary> public int Save() { if (mediaType != null) { mediaType.Save(); } if (keywords != null) { foreach (YariMediaKeyword item in keywords) { item.Save(); } } if (isSynced) { return(iD); } if (iD == -1) { throw (new Exception("Invalid record; cannot be saved.")); } if (iD == 0) { iD = YariMediaRecordManager._insert(this); } else { YariMediaRecordManager._update(this); } isSynced = iD != -1; return(iD); }
/// <summary> /// Duplicates YariMediaRecord object into a database; may or may not be the same database /// as the parent object. /// </summary> /// <returns> A new YariMediaRecord object reflecting the replicated YariMediaRecord object.</returns> public YariMediaRecord Duplicate() { YariMediaRecord clonedYariMediaRecord = this.Clone(); // Insert must be called after children are replicated! clonedYariMediaRecord.iD = YariMediaRecordManager._insert(clonedYariMediaRecord); clonedYariMediaRecord.isSynced = true; return(clonedYariMediaRecord); }
/// <summary> /// Ensures that the object's fields and children are /// pre-loaded before any updates or reads. /// </summary> public void EnsurePreLoad() { if (!isPlaceHolder) { return; } YariMediaRecordManager._fill(this); isPlaceHolder = false; }
/// <summary> /// Render this control to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void RenderContent(HtmlTextWriter output) { YariMediaRecordManager m = new YariMediaRecordManager(); YariMediaRecordCollection yariMediaRecordCollection = m.GetCollection(string.Empty, string.Empty, null); // Render Header Row this.headerLockEnabled = true; RenderRow(this.HeaderRowCssClass, ); bool rowflag = false; string rowCssClass; // // Render Records // foreach (YariMediaRecord yariMediaRecord in yariMediaRecordCollection) { if (rowflag) { rowCssClass = defaultRowCssClass; } else { rowCssClass = alternateRowCssClass; } rowflag = !rowflag; output.WriteBeginTag("tr"); output.WriteAttribute("i", yariMediaRecord.ID.ToString()); output.WriteLine(HtmlTextWriter.TagRightChar); output.Indent++; output.Indent--; output.WriteEndTag("tr"); output.WriteLine(); } }
public void ImportEndNoteXml(XmlDataDocument xmlDocument) { GreyFoxContactManager authorsManager = new GreyFoxContactManager("kitYari_Authors"); GreyFoxContactManager publishersManager = new GreyFoxContactManager("kitYari_Publishers"); YariMediaRecordManager mediaRecordManager = new YariMediaRecordManager(); YariMediaKeywordManager mediaKeywordManager = new YariMediaKeywordManager(); XmlNodeList bookNodes = xmlDocument.SelectNodes("//XML/RECORDS/RECORD"); XmlNode bookNode; externalRecordCount = bookNodes.Count; OnStart(new YariImporterEventArgs("Started Import.", 0)); for (int bookIndex = 0; bookIndex < bookNodes.Count; bookIndex++) { bookNode = bookNodes[bookIndex]; YariMediaRecord r = new YariMediaRecord(); foreach (XmlNode childNode in bookNode.ChildNodes) { // check for null records which signify existing titles of // the same name. if (r == null) { break; } switch (childNode.Name) { case "ISBN": if (childNode.InnerText.Length > 15) { r.Isbn = childNode.InnerText.Substring(0, 15); } else { r.Isbn = childNode.InnerText; } break; case "REFNUM": r.EndNoteReferenceID = int.Parse(childNode.InnerText); // if(mediaRecordManager.EndNoteReferenceIDExists(r.EndNoteReferenceID)) // { // OnRecordSkipped(new YariImporterEventArgs( // "Record Skipped - '" + r.EndNoteReferenceID + "'; EndNote Reference ID already exists.", bookIndex)); // r = null; // } break; case "YEAR": try { r.PublishYear = int.Parse(childNode.InnerText); } catch { r.PublishYear = 0; } break; case "TITLE": r.Title = childNode.InnerText; if (mediaRecordManager.TitleExists(r.title)) { OnRecordSkipped(new YariImporterEventArgs( "Record Skipped - '" + r.title + "'; title already exists.", bookIndex)); r = null; } break; case "PUBLISHER": r.Publisher = childNode.InnerText; break; case "PAGES": try { r.Pages = int.Parse(childNode.InnerText); } catch {} break; case "EDITION": r.Edition = childNode.InnerText; break; case "LABEL": r.Label = childNode.InnerText; break; case "KEYWORDS": r.keywords = new YariMediaKeywordCollection(); foreach (XmlNode keywordNode in childNode.ChildNodes) { string[] keywords = keywordNode.InnerText.Split(new char[] { ',', ';' }); foreach (string keyword in keywords) { r.Keywords.Add(mediaKeywordManager.FindByKeyword(keyword.Trim().ToLower(), true)); } } break; case "ABSTRACT": r.AbstractText = childNode.InnerText; break; case "NOTES": r.ContentsText = childNode.InnerText; break; case "AUTHORS": foreach (XmlNode authorNode in childNode.ChildNodes) { // // Split author fields in case the firstName is joined with // an ampersand or 'and' text. // string authorText = authorNode.InnerText.Replace(" & ", " and "); int andIndex = authorText.ToLower().IndexOf(" and "); if (andIndex != -1) { string authorA = authorText.Substring(0, andIndex).Trim(); string authorB = authorText.Substring(andIndex + 5, authorText.Length - (authorA.Length + 6)).Trim(); } r.Authors += authorText + " "; } break; } } // save the record if it does not exist. if (r != null) { r.AmazonRefreshDate = DateTime.MinValue; r.AmazonFillDate = DateTime.MinValue; r.AmazonReleaseDate = DateTime.MinValue; r.Save(); OnRecordImported( new YariImporterEventArgs("Imported Record - '" + r.Title + "'.", bookIndex, r)); } } OnFinish(new YariImporterEventArgs("Finished import.", bookNodes.Count)); }
/// <summary> /// Render this control to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void RenderContent(HtmlTextWriter output) { YariMediaRecordCollection yariMediaRecordCollection = null; EnsureChildControls(); if (Page.Cache["Yari_NewBooks"] != null) { yariMediaRecordCollection = (YariMediaRecordCollection)Page.Cache["Yari_NewBooks"]; } else { YariMediaRecordManager m = new YariMediaRecordManager(); yariMediaRecordCollection = m.SearchByPublishDate(8, DateTime.Now.Subtract(TimeSpan.FromDays(365)), DateTime.Now.Add(TimeSpan.FromDays(365))); Page.Cache.Add("Yari_NewBooks", yariMediaRecordCollection, null, DateTime.MaxValue, TimeSpan.FromMinutes(5), System.Web.Caching.CacheItemPriority.Normal, null); } bool rowflag = false; string rowCssClass; thumbsEnabled &= yariMediaRecordCollection.Count < 25; // // Render Records // foreach (YariMediaRecord yariMediaRecord in yariMediaRecordCollection) { if (yariMediaRecord.ID == selectedID) { rowCssClass = selectedRowCssClass; } else if (rowflag) { rowCssClass = defaultRowCssClass; } else { rowCssClass = alternateRowCssClass; } rowflag = !rowflag; output.WriteFullBeginTag("tr"); // // Render Book Image If Available // if (thumbsEnabled) { output.WriteBeginTag("td"); output.WriteAttribute("align", "middle"); output.WriteAttribute("class", rowCssClass); output.Write(HtmlTextWriter.TagRightChar); if (yariMediaRecord.ImageUrlSmall.Length > 0) { output.WriteBeginTag("img"); output.WriteAttribute("src", yariMediaRecord.ImageUrlSmall); output.WriteAttribute("border", "0"); output.Write(HtmlTextWriter.TagRightChar); } output.WriteEndTag("td"); } // // Render Main Representation of Record // output.WriteBeginTag("td"); output.WriteAttribute("valign", "top"); output.WriteAttribute("width", "100%"); output.WriteAttribute("class", rowCssClass); output.Write(HtmlTextWriter.TagRightChar); if (selectEnabled) { output.WriteBeginTag("a"); if (selectionUrl != "") { output.WriteAttribute("href", selectionUrl + "?id=" + yariMediaRecord.ID); } else { output.WriteAttribute("href", "javascript:" + Page.ClientScript.GetPostBackEventReference(this, "select_" + yariMediaRecord.ID)); } output.Write(HtmlTextWriter.TagRightChar); output.Write(yariMediaRecord.Title); output.WriteEndTag("a"); } else { output.Write(yariMediaRecord.Title); } output.WriteEndTag("td"); output.WriteEndTag("tr"); } }
/// <summary> /// Overwrites and existing YariMediaRecord object in the database. /// </summary> public void Overwrite(int id) { iD = id; YariMediaRecordManager._update(this); isSynced = true; }
public void Delete() { YariMediaRecordManager._delete(this.iD); this.iD = 0; isSynced = false; }
public YariMediaRecord(int id) { this.iD = id; isSynced = YariMediaRecordManager._fill(this); }
/// <summary> /// Render this control to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void RenderContent(HtmlTextWriter output) { string searchText = tbSearchText.Text.Trim().Replace("'", "''"); string searchType = ddSearchType.SelectedItem.Value; string cacheString = string.Empty; if (!emptySearchEnabled & searchText == string.Empty) { return; } EnsureChildControls(); YariMediaRecordCollection yariMediaRecordCollection = null; if (cacheEnabled) { cacheString = "yariSearchCache_" + searchType + "_" + searchText; if (Context.Cache[cacheString] != null) { yariMediaRecordCollection = (YariMediaRecordCollection)Context.Cache[cacheString]; } else { yariMediaRecordCollection = null; } } if (yariMediaRecordCollection == null) { YariMediaRecordManager m = new YariMediaRecordManager(); switch (searchType) { case "Title": if (searchText == string.Empty) { goto default; } yariMediaRecordCollection = m.SearchByTitle(searchText); break; case "Author": yariMediaRecordCollection = m.SearchByAuthor(searchText); break; case "Keywords": yariMediaRecordCollection = m.SearchByKeywords(searchText); break; case "Contents": yariMediaRecordCollection = m.SearchByContents(searchText); initializeSearchResult(searchText); // Replaces contents text with highlighted search result for (int x = 0; x < yariMediaRecordCollection.Count; x++) { yariMediaRecordCollection[x].ContentsText = constructSearchResult(searchText, yariMediaRecordCollection[x].ContentsText); } break; case "Abstract": yariMediaRecordCollection = m.SearchByAbstract(searchText); initializeSearchResult(searchText); // Replaces abstract text with highlighted search result for (int x = 0; x < yariMediaRecordCollection.Count; x++) { yariMediaRecordCollection[x].AbstractText = constructSearchResult(searchText, yariMediaRecordCollection[x].AbstractText); } break; default: yariMediaRecordCollection = m.GetCollection(string.Empty, "Title", null); break; } if (cacheEnabled) { Context.Cache.Add(cacheString, yariMediaRecordCollection, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); } } bool rowflag = false; string rowCssClass; thumbsEnabled &= yariMediaRecordCollection.Count < 25; output.WriteFullBeginTag("tr"); output.WriteBeginTag("td"); if (thumbsEnabled) { output.WriteAttribute("colspan", "2"); } output.Write(HtmlTextWriter.TagRightChar); output.Write(yariMediaRecordCollection.Count); output.Write(" results found."); output.WriteEndTag("td"); output.WriteEndTag("tr"); // // Render Records // YariMediaRecord yariMediaRecord; for (int x = 0; x < yariMediaRecordCollection.Count; x++) { yariMediaRecord = yariMediaRecordCollection[x]; if (yariMediaRecord.ID == selectedID) { rowCssClass = selectedRowCssClass; } else if (rowflag) { rowCssClass = defaultRowCssClass; } else { rowCssClass = alternateRowCssClass; } rowflag = !rowflag; output.WriteFullBeginTag("tr"); // // Render Book Image If Available // if (thumbsEnabled) { output.WriteBeginTag("td"); output.WriteAttribute("align", "middle"); output.WriteAttribute("class", rowCssClass); output.Write(HtmlTextWriter.TagRightChar); if (yariMediaRecord.ImageUrlSmall != string.Empty) { output.WriteBeginTag("img"); output.WriteAttribute("src", yariMediaRecord.ImageUrlSmall); output.WriteAttribute("border", "0"); output.Write(HtmlTextWriter.TagRightChar); } output.WriteEndTag("td"); } // // Render Main Representation of Record // output.WriteBeginTag("td"); output.WriteAttribute("valign", "top"); output.WriteAttribute("width", "100%"); output.WriteAttribute("class", rowCssClass); output.Write(HtmlTextWriter.TagRightChar); if (selectEnabled) { output.WriteBeginTag("a"); if (selectionUrl != "") { output.WriteAttribute("href", selectionUrl + "?id=" + yariMediaRecord.ID); } else { output.WriteAttribute("href", "javascript:" + Page.ClientScript.GetPostBackEventReference(this, "select_" + yariMediaRecord.ID)); } output.Write(HtmlTextWriter.TagRightChar); output.Write(yariMediaRecord.Title); output.WriteEndTag("a"); } else { output.Write(yariMediaRecord.Title); } output.Write("<br>"); if (yariMediaRecord.Authors == null) { output.Write("Unknown"); } else { output.Write(yariMediaRecord.Authors.ToString()); } if (searchType == "Abstract") { output.WriteFullBeginTag("br"); output.Write(yariMediaRecord.AbstractText); output.WriteFullBeginTag("br"); } else if (searchType == "Contents") { output.WriteFullBeginTag("br"); output.Write(yariMediaRecord.ContentsText); output.WriteFullBeginTag("br"); } output.WriteEndTag("td"); output.WriteEndTag("tr"); } }