Universal Bible API 1.0.2011.1274

ZefaniaBible.cs

Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Linq;
00005 using System.IO;
00006 using System.Text;
00007 using System.Xml.Linq;
00008 
00009 
00010 namespace UniversalBibleAPI
00011 {
00017     public class ZefaniaBible : IBibleModul
00018     {
00019         private List<CurrentContentKey> FMyVerses = new List<CurrentContentKey>();
00020         private VplBible InternalVPL = new VplBible();
00021         private Scriptureparser BibleParser = new Scriptureparser();
00022         private string FModuleName = "No Name";
00023         private string FModulePath = "";
00024         private XDocument FZefaniaBibleModul;
00025         private BackgroundWorker BackGroundWorkerLoadModul;
00026        
00027         #region IBibleModul Members
00028         public event EventHandler<ModulConnectedEventArgs> OnConnected;
00029         public event EventHandler<ParseEventArgs> OnQueryFinished;
00030         public void Connect(string PathToBibleModul)
00031         {
00032             FModulePath = PathToBibleModul;
00033             BackGroundWorkerLoadModul = new BackgroundWorker();
00034             BackGroundWorkerLoadModul.DoWork += new DoWorkEventHandler(BackGroundWorkerLoadModul_DoWork);
00035             BackGroundWorkerLoadModul.RunWorkerAsync(PathToBibleModul);
00036 
00037         }
00038         void BackGroundWorkerLoadModul_DoWork(object sender, DoWorkEventArgs e)
00039         {
00040             InternalVPL.Connect();
00041             InternalVPL.OnQueryFinished += new EventHandler<ParseEventArgs>(InternalVPL_OnQueryFinished);
00042             FZefaniaBibleModul = XDocument.Load((e.Argument as String));
00043             var verses  = FZefaniaBibleModul.Descendants("VERS");            
00044             foreach (var vers in verses)
00045             {
00046                 InternalVPL.SetCurrentContentKeys.Add(GetContentKey(vers));
00047             }
00048 
00049             if (OnConnected != null)
00050             {
00051 
00052                 ModulConnectedEventArgs args = new ModulConnectedEventArgs();
00053                 args.ModulName = FZefaniaBibleModul.Descendants("title").ElementAt(0).Value;
00054                 FModuleName = args.ModulName;
00055                 OnConnected(this, args);
00056 
00057             }
00058 
00059 
00060         }
00061         private CurrentContentKey GetContentKey(XElement vers)
00062         {
00063             CurrentContentKey CK = new CurrentContentKey();
00064             try
00065             {
00066                 CK.Book = vers.Parent.Parent.Attribute("bnumber").Value;
00067                 CK.Chapter = vers.Parent.Attribute("cnumber").Value;
00068                 CK.Verse = vers.Attribute("vnumber").Value;
00069                 CK.ContentText = vers.ToString();
00070                 CK.ContentType = CurrentContentKey.TypeOfContentKey.Verse;
00071 
00072                 return CK;
00073             }
00074             catch (Exception e)
00075             {
00076                 
00077                 throw e;
00078             }
00079         }
00080         void InternalVPL_OnQueryFinished(object sender, ParseEventArgs e)
00081         {
00082             if (OnQueryFinished != null)
00083             {
00084                 ParseEventArgs PEV = new ParseEventArgs();
00085                 PEV.QueryResultList = e.QueryResultList;
00086                 OnQueryFinished(this, PEV);
00087 
00088             }
00089         }     
00090         public bool HasVersRef(string SingleVersRef)
00091         {
00092 
00093             try
00094             {
00095                 return InternalVPL.HasVersRef(SingleVersRef);
00096             }
00097             catch (Exception e)
00098             {
00099 
00100                 throw e;
00101             }
00102         }
00103         public void ParseQuery(string BibleQuery)
00104         {
00105             try
00106             {
00107                 if (BibleQuery != string.Empty)
00108                 {
00109                     InternalVPL.ParseQuery(BibleQuery);
00110                 }
00111             }
00112             catch (Exception e)
00113             {
00114 
00115                 throw e;
00116             }
00117         }
00118         public void NextVerse()
00119         {
00120 
00121             try
00122             {
00123 
00124                 InternalVPL.NextVerse();
00125 
00126             }
00127             catch (Exception e)
00128             {
00129 
00130                 throw e;
00131             }
00132         }
00133         public void PreviousVerse()
00134         {
00135 
00136             try
00137             {
00138                 InternalVPL.PreviousVerse();
00139             }
00140             catch (Exception e)
00141             {
00142 
00143                 throw e;
00144             }
00145         }
00146         public void NextChapter()
00147         {
00148             try
00149             {
00150                 InternalVPL.NextChapter();
00151             }
00152 
00153             catch (Exception e)
00154             {
00155 
00156                 throw e;
00157             }
00158         }
00159         public void PreviousChapter()
00160         {
00161             try
00162             {
00163                 InternalVPL.PreviousChapter();
00164             }
00165 
00166             catch (Exception e)
00167             {
00168 
00169                 throw e;
00170             }
00171         }
00172         public void NextBook()
00173         {
00174             try
00175             {
00176 
00177                 InternalVPL.NextBook();
00178             }
00179             catch (Exception e)
00180             {
00181 
00182                 throw e;
00183             }
00184         }
00185         public void PreviousBook()
00186         {
00187             try
00188             {
00189                 InternalVPL.PreviousBook();
00190             }
00191             catch (Exception e)
00192             {
00193 
00194                 throw e;
00195             }
00196         }
00197         public IFilter MyFilter {
00198 
00199             get { return InternalVPL.MyFilter; }
00200             set {InternalVPL.MyFilter=value; }
00201         
00202         }
00203         public bool IsOnEnd()
00204         {
00205             try
00206             {
00207                 return InternalVPL.IsOnEnd();
00208             }
00209             catch (Exception e)
00210             {
00211 
00212                 throw e;
00213             }
00214         }
00215         public bool IsOnStart()
00216         {
00217             try
00218             {
00219                 return InternalVPL.IsOnStart();
00220             }
00221             catch (Exception e)
00222             {
00223 
00224                 throw e;
00225             }
00226         }
00227         public string ModuleName
00228         {
00229             get
00230             {
00231                 return FModuleName;
00232             }
00233             set
00234             {
00235                 FModuleName = value;
00236             }
00237         }
00238         public string ModulePath
00239         {
00240             get { return FModulePath; }
00241         }
00242         public List<CurrentContentKey> GetAllVerses()
00243         {
00244             try
00245             {
00246                 return InternalVPL.GetAllVerses();
00247             }
00248 
00249             catch (Exception e)
00250             {
00251 
00252                 throw e;
00253             }
00254         }
00255 
00256         public void ConvertTo(IBibleModul ModulToConvert)
00257         {
00258             try
00259             {
00260                 string OutPath = Path.ChangeExtension(ModulToConvert.ModulePath, ".xml");
00261                 string FileName = Path.GetFileNameWithoutExtension(OutPath);
00262                 
00263                 OutPath = OutPath.Replace(FileName, FileName + "_convto");
00264                 File.Delete(OutPath);
00265                 File.AppendAllText(OutPath, "<XMLBIBLE>\n", Encoding.UTF8);
00266                 File.AppendAllText(OutPath, "<INFORMATION><title>NoName</title></INFORMATION>\n", Encoding.UTF8);
00267 
00268                 var BGR = from BG in ModulToConvert.GetAllVerses() group BG by BG.Book;
00269                 foreach (var Book in BGR) {
00270                     File.AppendAllText(OutPath, "<BIBLEBOOK bnumber=\""+Book.Key+"\">\n", Encoding.UTF8);
00271                     var CGR = from CG in Book group CG by CG.Chapter;
00272                     foreach (var Chapter in CGR) {
00273                         File.AppendAllText(OutPath, "<CHAPTER cnumber=\""+Chapter.Key+"\">\n", Encoding.UTF8);
00274                         foreach (var item in Chapter){
00275 
00276                             if (item.ContentType == CurrentContentKey.TypeOfContentKey.Verse) {
00277                                 File.AppendAllText(OutPath, "<VERS vnumber=\"" + item.Verse + "\">"+item.ContentText+ "</VERS>\n", Encoding.UTF8);
00278                                 continue;
00279                             }
00280                             if (item.ContentType == CurrentContentKey.TypeOfContentKey.Caption)
00281                             {
00282                                 File.AppendAllText(OutPath, "<CAPTION>"+item.ContentText+"</CAPTION>\n", Encoding.UTF8);
00283                                 continue;
00284                             }
00285                         } 
00286                       File.AppendAllText(OutPath, "</CHAPTER>\n", Encoding.UTF8);
00287                     }
00288                    
00289                     File.AppendAllText(OutPath, "</BIBLEBOOK>\n", Encoding.UTF8);
00290                 
00291                 }
00292                 
00293                
00294 
00295                 File.AppendAllText(OutPath, "</XMLBIBLE>\n", Encoding.UTF8);
00296                 this.Connect(OutPath);
00297 
00298             }
00299             catch (Exception e)
00300             {
00301                 
00302                 throw e;
00303             }
00304         }
00305 
00306         #endregion
00307     }
00308 }
 All Classes Namespaces Files Functions Enumerations Properties Events