private AbstractSource ParseToSource(string data) { string[] fields = data.Split(FieldDelim); int idx = 0; int id = Int32.Parse(fields[idx++]); string providerId = fields[idx++]; string catName = fields[idx++]; string url = fields[idx++]; string meta = fields[idx++]; Dictionary <string, string> metaDict = new Dictionary <string, string>(); foreach (string kv in meta.Split(new char[] { MetaDelim }, StringSplitOptions.RemoveEmptyEntries)) { int split = kv.IndexOf('='); string key = kv.Substring(0, split); string val = kv.Substring(split + 1); metaDict.Add(key, val); } AbstractSource s = new GenericSource(catName, providerId); s.SetID(id); s.SetMetaData(metaDict); //Don't need, url return(s); }
protected override List <GenericSource> LoadSources() { string command = "select ID, ProviderID, Name, MetaData from " + SourcesTable; var results = sqlWrapper.ExecuteSelect(command); List <GenericSource> sources = new List <GenericSource>(); foreach (DataRow row in results.Rows) { GenericSource source = new GenericSource(row["Name"].ToString(), row["ProviderID"].ToString(), false); //TODO: new function source.SetID(Int32.Parse(row["ID"].ToString())); source.SetMetaData(DeserializeMeta(row["MetaData"].ToString())); sourceLookup.Add(source.ID.Value, source); sources.Add(source); } return(sources); }
public static SourceAdapter CreateSourceAdapter(V1.AbstractSource src, V1.AbstractProvider provider) { string strDisabled = src.GetMetaDataValue(AbstractSource.DISABLED); bool disabled = strDisabled == null ? false : Convert.ToBoolean(strDisabled); GenericSource gs = new GenericSource(src.SourceName, src.ProviderID, disabled); //Update Meta Dictionary <string, MetaDataObject> newMeta = new Dictionary <string, MetaDataObject>(); List <string> providerMeta = provider.GetMetaFields(); { foreach (string name in providerMeta) { var mdo = new MetaDataObject(name, name); if (src.GetMetaData().ContainsKey(name)) { mdo.SetValue(src.GetMetaDataValue(name)); } newMeta.Add(mdo.ID, mdo); } } gs.SetMetaData(newMeta); if (src.ID.HasValue) { gs.SetID(src.ID.Value); } var sa = new SourceAdapter(gs); return(sa); }