Exemplo n.º 1
0
        /// <summary>Create a new instance of the MultiRecordEngine</summary>
        /// <param name="recordTypes">The Types of the records that this engine can handle.</param>
        /// <param name="recordSelector">
        /// Used only in read operations. The selector indicates to the engine
        /// what Type to use in each read line.
        /// </param>
        public MultiRecordEngine(RecordTypeSelector recordSelector, params Type[] recordTypes)
            : base(GetFirstType(recordTypes))
        {
            mTypes              = recordTypes;
            mMultiRecordInfo    = new IRecordInfo[mTypes.Length];
            mRecordInfoHash     = new Hashtable(mTypes.Length);
            mMultiRecordOptions = new RecordOptions[mTypes.Length];

            for (int i = 0; i < mTypes.Length; i++)
            {
                if (mTypes[i] == null)
                {
                    throw new BadUsageException("The type at index " + i + " is null.");
                }

                if (mRecordInfoHash.Contains(mTypes[i]))
                {
                    throw new BadUsageException("The type '" + mTypes[i].Name +
                                                " is already in the engine. You can't pass the same type twice to the constructor.");
                }

                mMultiRecordInfo[i]    = FileHelpers.RecordInfo.Resolve(mTypes[i]);
                mMultiRecordOptions[i] = CreateRecordOptionsCore(mMultiRecordInfo[i]);

                mRecordInfoHash.Add(mTypes[i], mMultiRecordInfo[i]);
            }
            mRecordSelector = recordSelector;
        }
Exemplo n.º 2
0
        /// <summary>Create a new instance of the MultiRecordEngine</summary>
        /// <param name="recordTypes">The Types of the records that this engine can handle.</param>
        /// <param name="recordSelector">
        /// Used only in read operations. The selector indicates to the engine
        /// what Type to use in each read line.
        /// </param>
        public MultiRecordEngine(RecordTypeSelector recordSelector, params Type[] recordTypes)
            : base(GetFirstType(recordTypes))
        {
            int recordTypesLength = recordTypes.Length;

            mMultiRecordInfo = new IRecordInfo[recordTypesLength];
            mRecordInfoTable = new Dictionary <Type, IRecordInfo>();

            for (int i = 0; i < recordTypesLength; i++)
            {
                Type recordType = recordTypes[i];
                if (recordType == null)
                {
                    throw new BadUsageException("The type at index " + i + " is null.");
                }

                if (mRecordInfoTable.ContainsKey(recordType))
                {
                    throw new BadUsageException("The type '" + recordType.Name +
                                                " is already in the engine. You can't pass the same type twice to the constructor.");
                }

                mMultiRecordInfo[i] = FileHelpers.RecordInfo.Resolve(recordType);
                CreateRecordOptionsCore(mMultiRecordInfo[i]);

                mRecordInfoTable.Add(recordType, mMultiRecordInfo[i]);
            }
            mRecordSelector = recordSelector;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new instance of the MultiRecordEngine
 /// </summary>
 /// <param name="recordTypes">The Types of the records that this engine can handle.</param>
 /// <param name="recordSelector">The selector that indicates to the engine what Type to use in each line.</param>
 public MultiRecordEngine(Type[] recordTypes, RecordTypeSelector recordSelector) : base(recordTypes[0])
 {
     mTypes           = recordTypes;
     mMultiRecordInfo = new RecordInfo[mTypes.Length];
     mRecordInfoHash  = new Hashtable(mTypes.Length);
     for (int i = 0; i < mTypes.Length; i++)
     {
         mMultiRecordInfo[i] = new RecordInfo(mTypes[i]);
         mRecordInfoHash.Add(mTypes[i], mMultiRecordInfo[i]);
     }
     mRecordSelector = recordSelector;
 }
        public static async Task RunAsync()
        {
            Directory.CreateDirectory("www");

            var github  = new Github();
            var plotter = new Plotter("plots");

            var dailyReportFileInfo = await github.GetFileInfoAsync(
                "CSSEGISandData",
                "COVID-19",
                "csse_covid_19_data/csse_covid_19_daily_reports");

            RecordTypeSelector recordSelector = (engine, line)
                                                => line.Replace("\".*\"", "\"\"").Count(c => c == ',') >= 10
                    ? typeof(ReportData2)
                    : typeof(ReportData);

            var dailyReportCsvEngine = new MultiRecordEngine(
                recordSelector,
                typeof(ReportData),
                typeof(ReportData2));
            var dailyReportData = new List <KeyValuePair <DateTime, List <ReportData> > >();