Universal Bible API 1.0.2011.1274
|
00001 using System; 00002 using System.ComponentModel; 00003 using System.Collections.Generic; 00004 using System.Linq; 00005 using System.Xml.Linq; 00006 using System.Xml; 00007 using System.Text; 00008 namespace UniversalBibleAPI 00009 { 00015 public class OsisBible : IBibleModul 00016 { 00017 private List<CurrentContentKey> FMyVerses = new List<CurrentContentKey>(); 00018 private VplBible InternalVPL = new VplBible(); 00019 private Scriptureparser ParseScripture = new Scriptureparser(); 00020 private string FModuleName = "No Name"; 00021 private string FModulePath = ""; 00022 private XDocument FOsisBibleModul; 00023 private BackgroundWorker BackGroundWorkerLoadModul; 00024 private XNamespace NS = "http://www.bibletechnologies.net/2003/OSIS/namespace"; 00025 00026 #region IBibleModul Members 00027 public event EventHandler<ModulConnectedEventArgs> OnConnected; 00028 public event EventHandler<ParseEventArgs> OnQueryFinished; 00029 public void Connect(string PathToBibleModul) 00030 { 00031 FModulePath = PathToBibleModul; 00032 InternalVPL.Connect(); 00033 InternalVPL.OnQueryFinished += new EventHandler<ParseEventArgs>(InternalVPL_OnQueryFinished); 00034 this.BackGroundWorkerLoadModul = new BackgroundWorker(); 00035 this.BackGroundWorkerLoadModul.DoWork += new DoWorkEventHandler(BackGroundWorkerLoadModul_DoWork); 00036 this.BackGroundWorkerLoadModul.RunWorkerAsync(PathToBibleModul); 00037 } 00038 00039 void InternalVPL_OnQueryFinished(object sender, ParseEventArgs e) 00040 { 00041 if (OnQueryFinished != null) 00042 { 00043 ParseEventArgs PEV = new ParseEventArgs(); 00044 PEV.QueryResultList = e.QueryResultList; 00045 OnQueryFinished(this, PEV); 00046 00047 } 00048 } 00049 void BackGroundWorkerLoadModul_DoWork(object sender, DoWorkEventArgs e) 00050 { 00051 FOsisBibleModul = XDocument.Load((e.Argument as String)); 00052 if (OnConnected != null) 00053 { 00054 var book = from b in FOsisBibleModul.Descendants(NS + "div") where (b.HasAttributName("type")) where (b.Attribute("type").Value == "book") select b; 00055 var verses = book.Descendants(NS + "verse"); 00056 00057 foreach (var vers in verses) 00058 { 00059 InternalVPL.SetCurrentContentKeys.Add(GetContentKey(vers)); 00060 } 00061 00062 ModulConnectedEventArgs args = new ModulConnectedEventArgs(); 00063 args.ModulName = FOsisBibleModul.Descendants(NS + "work").ElementAt(0).Element(NS + "title").Value; 00064 FModuleName = args.ModulName; 00065 OnConnected(this, args); 00066 00067 } 00068 } 00069 00070 private CurrentContentKey GetContentKey(XElement vers) 00071 { 00072 CurrentContentKey CK = new CurrentContentKey(); 00073 try 00074 { 00075 string OsisID = vers.Attribute("osisID").Value; 00076 string[] OsisIDParts = OsisID.Split('.'); 00077 if (OsisIDParts.Length == 3) 00078 { 00079 CK.Book = ParseScripture.GetBookNumber(OsisIDParts[0]); 00080 CK.Chapter = OsisIDParts[1]; 00081 CK.Verse = OsisIDParts[2]; 00082 } 00083 CK.ContentText = vers.ToString(); 00084 if (vers.Name == NS + "verse") 00085 { 00086 CK.ContentType = CurrentContentKey.TypeOfContentKey.Verse; 00087 } 00088 else 00089 { 00090 00091 CK.ContentType = CurrentContentKey.TypeOfContentKey.Nothing; 00092 } 00093 return CK; 00094 } 00095 catch (Exception e) 00096 { 00097 00098 throw e; 00099 } 00100 } 00101 00102 public bool HasVersRef(string SingleVersRef) 00103 { 00104 try 00105 { 00106 return InternalVPL.HasVersRef(SingleVersRef); 00107 } 00108 catch (Exception) 00109 { 00110 00111 throw; 00112 } 00113 } 00114 public void ParseQuery(string BibleQuery) 00115 { 00116 try 00117 { 00118 if (BibleQuery != string.Empty) 00119 { 00120 InternalVPL.ParseQuery(BibleQuery); 00121 } 00122 } 00123 catch (Exception e) 00124 { 00125 00126 throw e; 00127 } 00128 } 00129 public void NextVerse() 00130 { 00131 try 00132 { 00133 InternalVPL.NextVerse(); 00134 } 00135 catch (Exception e) 00136 { 00137 00138 throw e; 00139 } 00140 } 00141 public void PreviousVerse() 00142 { 00143 00144 try 00145 { 00146 00147 InternalVPL.PreviousVerse(); 00148 00149 } 00150 catch (Exception e) 00151 { 00152 00153 throw e; 00154 } 00155 } 00156 public void NextChapter() 00157 { 00158 try 00159 { 00160 00161 InternalVPL.NextChapter(); 00162 00163 } 00164 00165 catch (Exception e) 00166 { 00167 00168 throw e; 00169 } 00170 } 00171 public void PreviousChapter() 00172 { 00173 try 00174 { 00175 00176 InternalVPL.PreviousChapter(); 00177 00178 } 00179 00180 catch (Exception e) 00181 { 00182 00183 throw e; 00184 } 00185 } 00186 public void NextBook() 00187 { 00188 try 00189 { 00190 00191 InternalVPL.NextBook(); 00192 } 00193 catch (Exception e) 00194 { 00195 00196 throw e; 00197 } 00198 } 00199 public void PreviousBook() 00200 { 00201 try 00202 { 00203 InternalVPL.PreviousBook(); 00204 } 00205 catch (Exception e) 00206 { 00207 00208 throw e; 00209 } 00210 } 00211 public IFilter MyFilter { 00212 get { return InternalVPL.MyFilter; } 00213 set { InternalVPL.MyFilter = value; } 00214 } 00215 public bool IsOnEnd() 00216 { 00217 try 00218 { 00219 return InternalVPL.IsOnEnd(); 00220 } 00221 catch (Exception e) 00222 { 00223 00224 throw e; 00225 } 00226 } 00227 public bool IsOnStart() 00228 { 00229 try 00230 { 00231 return InternalVPL.IsOnStart(); 00232 } 00233 catch (Exception e) 00234 { 00235 00236 throw e; 00237 } 00238 } 00239 public string ModuleName 00240 { 00241 get 00242 { 00243 return FModuleName; 00244 } 00245 set 00246 { 00247 FModuleName = value; 00248 } 00249 } 00250 public string ModulePath 00251 { 00252 get { return FModulePath; } 00253 } 00254 public List<CurrentContentKey> GetAllVerses() 00255 { 00256 try 00257 { 00258 return InternalVPL.GetAllVerses(); 00259 } 00260 catch (Exception e) 00261 { 00262 00263 throw e; 00264 } 00265 } 00266 00267 00268 public void ConvertTo(IBibleModul ModulToConvert) 00269 { 00270 throw new NotImplementedException(); 00271 } 00272 00273 #endregion 00274 } 00275 }