Example #1
0
        public static void SDFInsert_bulk(string SDFFile, string tableName, IndexedDictionary <string, string[]> data)
        {
            try
            {
                IConnection mConnection = SDFHelper.SDFConnection(SDFFile);
                mConnection.Open();
                IInsert insertCmd = (IInsert)mConnection.CreateCommand(CommandType.CommandType_Insert);

                insertCmd.SetFeatureClassName("Civil_schema:" + tableName);

                PropertyValueCollection propValmain = insertCmd.PropertyValues;
                propValmain.Clear();
                //remove coordinates - which is not needed for sdf
                data.Remove("coordinates");
                foreach (var item in data)
                {
                    PropertyValue propVal = new PropertyValue();
                    propVal.Name = new Identifier(item.Key);
                    Expression expValue;
                    string     dataType = data[item.Key][0];
                    string     value    = data[item.Key][1];

                    Debug.Write("\nProperty: " + item.Key);
                    Debug.Write("\ndataType: " + dataType);
                    Debug.Write("\nvalue: " + value);

                    if (data[item.Key][0].Equals("geometry"))
                    {
                        expValue = Expression.Parse(value);
                    }
                    else if (data[item.Key][0].Equals("String"))
                    {
                        Debug.Write("\nInside String");
                        DataType dt = FDODataHelper.getDataType(dataType);
                        expValue = FDODataHelper.ParseByDataType("'" + value + "'", dt);
                    }
                    else
                    {
                        Debug.Write("\nInside Else");
                        DataType dt = FDODataHelper.getDataType(dataType);
                        expValue = FDODataHelper.ParseByDataType(value, dt);
                    }
                    propValmain.Add(propVal);
                    propVal.Value = (ValueExpression)expValue;
                }
                #region MyRegion

                /*
                 * PropertyValueCollection propVals = insertCmd.PropertyValues;
                 * PropertyValue propVal1 = new PropertyValue();
                 * propVal1.Name = new Identifier("Name");
                 * PropertyValue propVal2 = new PropertyValue();
                 * propVal2.Name = new Identifier("NetworkName");
                 * PropertyValue propVal3 = new PropertyValue();
                 * propVal3.Name = new Identifier("PartSizeName");
                 * //PropertyValue propVal4 = new PropertyValue();
                 * //propVal4.Name = new Identifier("RimElevation");
                 * PropertyValue propVal5 = new PropertyValue();
                 * propVal5.Name = new Identifier("Geometry");
                 *
                 * Expression expr1 = Expression.Parse("'AB'");
                 * Expression expr2 = Expression.Parse("'Poor'");
                 * Expression expr4 = Expression.Parse("'Down'");
                 * Expression expr5 = Expression.Parse("GEOMFROMTEXT('LINESTRING XY (100000.0 100000.0, 200000.0 200000.0, 100000.0 300000.0)')");
                 * //Int32Value intVal = new Int32Value(0);
                 *
                 * propVals.Clear();
                 * propVals.Add(propVal1);
                 * propVals.Add(propVal2);
                 * propVals.Add(propVal3);
                 * //propVals.Add(propVal4);
                 * propVals.Add(propVal5);
                 *
                 * propVal1.Value = (ValueExpression)expr1;
                 * propVal2.Value = (ValueExpression)expr2;
                 * //propVal3.Value = (ValueExpression)intVal;
                 * //propVal4.Value = (ValueExpression)expr4;
                 * propVal5.Value = (ValueExpression)expr5;
                 */

                #endregion

                IFeatureReader reader;
                //reader.Dispose();
                reader = insertCmd.Execute();
                reader.Close();

                mConnection.Close();
                Debug.Write("Test_LargeDataVolumeInsert runs successfully !");
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }
        }
Example #2
0
        public static void SDFRead(string SDFFile, string schemaName, string filter_value)
        {
            //this is to read value of a property
            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Read Data module running...", true);
            //ed.WriteMessage("\nRead Data module running...");
            try
            {
                IConnection con = SDFHelper.SDFConnection(SDFFile);
                con.Open();
                using (con)
                {
                    using (osgeo_command.Feature.ISelect get_data = con.CreateCommand(osgeo_command.CommandType.CommandType_Select) as osgeo_command.Feature.ISelect)
                    {
                        //set target schema
                        get_data.SetFeatureClassName("Civil_schema:Pipes");
                        var filter = "(Name='R-1P1')";
                        //var filter = "(" + filter_value + ")";
                        get_data.SetFilter(filter);
                        //get_data.Filter.

                        //count the number of rowms
                        int count = 0;

                        //execute the select command
                        using (IFeatureReader reader = get_data.Execute())
                        {
                            //get class definition
                            ClassDefinition cdef = reader.GetClassDefinition();
                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Class definition: " + cdef.Name, true);
                            //ed.WriteMessage("\nClass definition: " + cdef.Name);

                            //string array to print each row
                            ArrayList row = new ArrayList();

                            //print the column name
                            foreach (PropertyDefinition def in cdef.Properties)
                            {
                                if (def is DataPropertyDefinition)
                                {
                                    var p = (DataPropertyDefinition)def;
                                    row.Add(def.Name);
                                    //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Property Header Name: " + def.Name, true);
                                    //ed.WriteMessage("\nProperty Header Name: " + def.Name);
                                }
                                // Print the header row (property names)
                                //ed.WriteMessage(string.Join("\t", row.ToArray()));
                            }
                            while (reader.ReadNext())
                            {
                                row.Clear();
                                try
                                {
                                    //for each property print value
                                    foreach (PropertyDefinition def in cdef.Properties)
                                    {
                                        try
                                        {
                                            //only data properties
                                            if (!(def is DataPropertyDefinition))
                                            {
                                                continue;
                                            }
                                            var    p     = (DataPropertyDefinition)def;
                                            string value = "";
                                            value = FDODataHelper.expressionToString(FDODataHelper.ParseByDataType(reader.ToString(), p.DataType));
                                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Value: " + value, true);
                                            //depending upon the data type, use the approriate "GET"
                                            //method on the reader
                                            switch (p.DataType)
                                            {
                                            case OSGeo.FDO.Schema.DataType.DataType_Boolean:
                                                value = reader.IsNull(p.Name) ? "" : reader.GetBoolean(p.Name).ToString();
                                                break;

                                            case OSGeo.FDO.Schema.DataType.DataType_String:
                                                value = reader.IsNull(p.Name) ? "" : reader.GetString(p.Name).ToString();
                                                break;
                                            }
                                            row.Add(value);
                                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Value: " + value, true);
                                            //ed.WriteMessage("\nvalue == " + value);
                                        }
                                        catch (System.Exception ex)
                                        {
                                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Exception: " + ex, true);
                                            //System.Windows.MessageBox.Show(ex.Message);
                                        }
                                    }
                                }
                                catch (System.Exception ex)
                                {
                                    //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Exception: " + ex, true);
                                    //System.Windows.MessageBox.Show(ex.Message);
                                }

                                //ed.WriteMessage(string.Join("\t", row.ToArray()));
                                count++;
                            }
                            reader.Close();
                        }
                        //ed.WriteMessage("{0} rows.", count);
                    }
                    con.Close();
                }
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Exception: " + ex, true);
                //ed.WriteMessage("\nException:" + ge.Message);
                //bool ok = ge.Message.Contains("read-only");

                //ed.WriteMessage("no read-only for the schema", ok);
            }
        }