Beispiel #1
0
        protected override AbstractSource DoCreateNewSource(string name, string url, Dictionary <string, string> metaData)
        {
            if (metaData.ContainsKey(Site))
            {
                if (metaData[Site].Equals(JapanType, StringComparison.OrdinalIgnoreCase))
                {
                    metaData[Site] = JapanType;
                }
                else if (metaData[Site].Equals(ChinaType, StringComparison.OrdinalIgnoreCase))
                {
                    metaData[Site] = ChinaType;
                }
                else
                {
                    ThrowBadSiteException();
                }
            }
            else
            {
                ThrowBadSiteException();
            }

            var source = new GenericSource(metaData[Site], PROVIDER);

            source.SetMetaData(metaData);

            return(source);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }