Ejemplo n.º 1
0
        public static AbstractSource DoCreateNewSource(string name, List <IMetaDataObject> metaData) //URL is in meta
        {
            int tmp;

            //Set defaults
            IMetaDataObject mdo = MetaDataObject.FindIn(metaData, JobsProvider.META_PAGES);

            bool hasUrl   = false;
            bool hasPages = false;

            foreach (var m in metaData)
            {
                switch (m.ID)
                {
                case JobsProvider.META_URL:
                    hasUrl = true;
                    break;

                case JobsProvider.META_PAGES:

                    string value = m.GetValueAsString();

                    if (String.IsNullOrEmpty(value))
                    {
                        mdo.SetValue(DefaultPages);
                    }
                    else if (int.TryParse(value, out tmp))
                    {
                        mdo.SetValue(tmp);
                    }
                    else
                    {
                        throw new Exception("Not a valid number");
                    }

                    hasPages = true;

                    break;
                }
            }

            if (!hasUrl)
            {
                throw new Exception("Url must be provided.");
            }

            if (!hasPages)
            {
                mdo = JobsProvider.MetaPages.Create();
                mdo.SetValue(DefaultPages);

                metaData.Add(mdo);
            }

            AbstractSource s = new JobsSource(name);

            s.SetMetaData(metaData);

            return(s);
        }
Ejemplo n.º 2
0
        protected override List <IDataItem> GetNewItems(ISource source)
        {
            JobsSource js = JobsSource.CreateFrom(source);

            switch (js.Source)
            {
            case SourceNames.Dice:
                return(DiceProvider.GetNewItems(source));

            //case SourceNames.Monster:
            //    return MonsterProvider.GetNewItems(source);
            default:
                throw new Exception("Unrecognized source: " + js.Source);
            }
        }
Ejemplo n.º 3
0
        internal static JobsSource CreateFrom(ISource source)
        {
            if (source is JobsSource)
            {
                return((JobsSource)source);
            }

            JobsSource js = new JobsSource(source.SourceName);

            js.SetMetaData(source.GetMetaData()); //Only has non-protected
            js.SetID(source.ID.Value);

            if (source is ISource2)
            {
                js.Services = ((ISource2)source).Services;
            }

            return(js);
        }
Ejemplo n.º 4
0
 public override ISource CastSource(ISource src)
 {
     return(JobsSource.CreateFrom(src));
 }
Ejemplo n.º 5
0
        public static AbstractSource DoCreateNewSource(string name, string url, List <IMetaDataObject> metaData)
        {
            Dictionary <string, bool> hasFields = new Dictionary <string, bool>();

            foreach (var s in GetFieldList())
            {
                hasFields.Add(s, false);
            }


            string query = null, location = null;

            foreach (var md in metaData)
            {
                //TODO: Are nulls included here?

                switch (md.ID)
                {
                case JobsProvider.META_QUERY:
                    if (String.IsNullOrEmpty(md.GetValueAsString()))
                    {
                        throw new Exception("Query is required");
                    }
                    query = md.GetValueAsString();
                    break;

                case JobsProvider.META_LOCATION:
                    if (String.IsNullOrEmpty(md.GetValueAsString()))
                    {
                        throw new Exception("Location is required");
                    }

                    location = md.GetValueAsString();
                    break;

                case JobsProvider.META_PAGES:
                case JobsProvider.META_PAGE_SIZE:
                case JobsProvider.META_RANGE:

                    string val = md.GetValueAsString();

                    if (!String.IsNullOrEmpty(val))
                    {
                        IsInt(val);
                    }
                    else
                    {
                        switch (md.ID)
                        {
                        case JobsProvider.META_PAGES:
                            md.SetValue(DefaultPages);
                            break;

                        case JobsProvider.META_PAGE_SIZE:
                            md.SetValue(DefaultPageSize);
                            break;

                        case JobsProvider.META_RANGE:
                            md.SetValue(DefaultRange);
                            break;
                        }
                    }
                    break;
                }

                if (hasFields.ContainsKey(md.ID))
                {
                    hasFields[md.ID] = true;
                }
            }

            if (!hasFields[JobsProvider.META_QUERY] ||
                !hasFields[JobsProvider.META_LOCATION])
            {
                throw new Exception("Query and location are required");
            }

            //Check this

            name = String.Format("{0} | {1}", query, location);


            AbstractSource source = new JobsSource(name);

            source.SetMetaData(metaData);

            return(source);
        }