Exemple #1
0
        //--- Begin Custom Code ---

        public void SetKeywords(string keywordString)
        {
            if (keywords == null)
            {
                keywords = new YariMediaKeywordCollection();
            }
            else
            {
                keywords.Clear();
            }

            string[] keywordArray = keywordString.Split(';');

            YariMediaKeywordManager m = new YariMediaKeywordManager();

            for (int x = 0; x < keywordArray.Length; x++)
            {
                keywords.Add(m.FindByKeyword(keywordArray[x], true));
            }
        }
Exemple #2
0
        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));
        }