Exemple #1
0
 /// <summary>
 /// XML to JSON conversion
 /// </summary>
 /// Convert an XML string or file into JSON
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> XmlToJsonAsync(this IConvertData operations, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.XmlToJsonWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #2
0
 /// <summary>
 /// CSV to JSON conversion
 /// </summary>
 /// Convert a CSV file to a JSON object array
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='inputFile'>
 /// Input file to perform the operation on.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> CsvToJsonAsync(this IConvertData operations, System.IO.Stream inputFile, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CsvToJsonWithHttpMessagesAsync(inputFile, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #3
0
 public string GetName(IConvertData item)
 {
     if (!data.ContainsValue(item))
     {
         return(null);
     }
     return(data.FirstOrDefault((p) => p.Value == item).Key);
 }
Exemple #4
0
 /// <summary>
 /// XML to JSON conversion
 /// </summary>
 /// Convert an XML string or file into JSON
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 public static object XmlToJson(this IConvertData operations)
 {
     return(Task.Factory.StartNew(s => ((IConvertData)s).XmlToJsonAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemple #5
0
 /// <summary>
 /// CSV to JSON conversion
 /// </summary>
 /// Convert a CSV file to a JSON object array
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='inputFile'>
 /// Input file to perform the operation on.
 /// </param>
 public static object CsvToJson(this IConvertData operations, System.IO.Stream inputFile)
 {
     return(Task.Factory.StartNew(s => ((IConvertData)s).CsvToJsonAsync(inputFile), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Exemple #6
0
        private void DoConversion(ProviderItem input, IEnumerable <ProcessorItem> processors, ProviderItem output)
        {
            using (IConfigureFeatureSource csource = (IConfigureFeatureSource)Activator.CreateInstance(input.Builder))
            {
                IFeatureProvider psource    = csource.ConstructSourceProvider(_geometryServices);
                Type             srcOidType = GetTypeParamsOfImplementedInterface(psource.GetType(), typeof(IFeatureProvider <>))[0];
                List <IProcessFeatureDataRecords> realProcessors = new List <IProcessFeatureDataRecords>();

                foreach (ProcessorItem pi in processors)
                {
                    realProcessors.Add((IProcessFeatureDataRecords)Activator.CreateInstance(pi.ProcessorType));
                }

                FeatureDataRecordProcessor processChain = null;

                foreach (IProcessFeatureDataRecords processor in realProcessors)
                {
                    processChain = Equals(processChain, null)
                                       ? processor.Processor
                                       : ((IEnumerable <IFeatureDataRecord> o, ref int i) =>
                                          processor.Processor(processChain(o, ref i), ref i));
                }

                processChain = processChain ??
                               new FeatureDataRecordProcessor((IEnumerable <IFeatureDataRecord> o, ref int i) => o);

                if (!psource.IsOpen)
                {
                    psource.Open();
                }

                FeatureQueryExpression exp         = csource.ConstructSourceQueryExpression();
                FeatureDataTable       sourceModel = psource.CreateNewTable();
                int index = sourceModel.Columns.IndexOf(sourceModel.PrimaryKey[0]);
                IEnumerable <IFeatureDataRecord> sourceRecords = processChain(psource.ExecuteFeatureQuery(exp), ref index);

                //jd: TODO: need to test what happens if the IFeatureDataRecord shape is changed by the processor chain

                IConvertData converter = null;

                /* Some Data Providers do not respect the oidType param passed in.
                 * For instance Shapefile will always be IWritableFeatureProvider<UInt32>
                 * so we need to make sure we can coerce OID values  */



                using (
                    IConfigureFeatureTarget ctarget =
                        (IConfigureFeatureTarget)Activator.CreateInstance(output.Builder))
                {
                    Type oidType = csource.OidType;



                    using (IWritableFeatureProvider ptarget =
                               ctarget.ConstructTargetProvider(oidType, sourceModel.GeometryFactory,
                                                               _geometryServices.CoordinateSystemFactory,
                                                               sourceModel))
                    {
                        if (!ptarget.IsOpen)
                        {
                            ptarget.Open();
                        }

                        converter = GetConverter(csource.OidType, ctarget.OidType, sourceModel.NewRow(), index, sourceModel.GeometryFactory);



                        Console.WriteLine("Beginning Import.");
                        List <FeatureDataRow> features = new List <FeatureDataRow>();
                        int count = 0;
                        foreach (IFeatureDataRecord fdr in sourceRecords)
                        {
                            try
                            {
                                features.Add(converter.ConvertRecord(fdr));
                                if (++count % 100 == 0)
                                {
                                    ptarget.Insert(features);
                                    features.Clear();
                                }
                            }
                            catch (GeometryInvalidException ex)
                            {
                                Console.WriteLine("An Error Occured : " + ex.Message);
                                continue;
                            }
                        }

                        if (features.Count > 0)
                        {
                            ptarget.Insert(features);
                        }

                        count += features.Count;

                        features = null;

                        ptarget.Close();
                        Console.WriteLine(string.Format("{0} records processed", count));

                        ctarget.PostImport();
                    }
                }
            }

            Console.WriteLine("Finished");
        }