public void CollectionShouldBeCleared(PropertyValueCollection collection) { // Fixture setup // Exercise system collection.SetValue(DirectoryProperty.Member, john); collection.Clear(); // Verify outcome collection[DirectoryProperty.Member].Should().BeEmpty(); }
protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible) { PropertyValueCollection adapterData = property.adapterData as PropertyValueCollection; if (adapterData != null) { try { adapterData.Clear(); } catch (COMException exception) { if ((exception.ErrorCode != -2147467259) || (setValue == null)) { throw; } } IEnumerable enumerable = LanguagePrimitives.GetEnumerable(setValue); if (enumerable == null) { adapterData.Add(setValue); } else { foreach (object obj2 in enumerable) { adapterData.Add(obj2); } } } else { DirectoryEntry baseObject = (DirectoryEntry)property.baseObject; ArrayList list = new ArrayList(); IEnumerable enumerable2 = LanguagePrimitives.GetEnumerable(setValue); if (enumerable2 == null) { list.Add(setValue); } else { foreach (object obj3 in enumerable2) { list.Add(obj3); } } baseObject.InvokeSet(property.name, list.ToArray()); } }
private static void UpdateMetaBaseProperty(DirectoryEntry entry, string metaBasePropertyName, string metaBaseProperty) { if (metaBaseProperty.IndexOf('|') == -1) { string propertyTypeName; using (DirectoryEntry di = new DirectoryEntry(entry.SchemaEntry.Parent.Path + "/" + metaBasePropertyName)) { propertyTypeName = (string)di.Properties["Syntax"].Value; } if (string.Compare(propertyTypeName, "binary", StringComparison.OrdinalIgnoreCase) == 0) { object[] metaBasePropertyBinaryFormat = new object[metaBaseProperty.Length / 2]; for (int i = 0; i < metaBasePropertyBinaryFormat.Length; i++) { metaBasePropertyBinaryFormat[i] = metaBaseProperty.Substring(i * 2, 2); } PropertyValueCollection propValues = entry.Properties[metaBasePropertyName]; propValues.Clear(); propValues.Add(metaBasePropertyBinaryFormat); entry.CommitChanges(); } else { if (string.Compare(metaBasePropertyName, "path", StringComparison.OrdinalIgnoreCase) == 0) { DirectoryInfo f = new DirectoryInfo(metaBaseProperty); metaBaseProperty = f.FullName; } entry.Invoke("Put", metaBasePropertyName, metaBaseProperty); entry.Invoke("SetInfo"); } } else { entry.Invoke("Put", metaBasePropertyName, string.Empty); entry.Invoke("SetInfo"); string[] metabaseProperties = metaBaseProperty.Split('|'); foreach (string metabasePropertySplit in metabaseProperties) { entry.Properties[metaBasePropertyName].Add(metabasePropertySplit); } entry.CommitChanges(); } }
/// <summary> /// Sets the value of a property coming from a previous call to GetMember /// </summary> /// <param name="property">PSProperty coming from a previous call to GetMember</param> /// <param name="setValue">value to set the property with</param> /// <param name="convertIfPossible">instructs the adapter to convert before setting, if the adapter supports conversion</param> protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible) { PropertyValueCollection values = property.adapterData as PropertyValueCollection; if (null != values) { // This means GetMember returned PropertyValueCollection try { values.Clear(); } catch (System.Runtime.InteropServices.COMException e) { if (e.ErrorCode != unchecked ((int)0x80004005) || (setValue == null)) { // When clear is called, DirectoryEntry calls PutEx on AD object with Clear option and Null Value // WinNT provider throws E_FAIL when null value is specified though actually ADS_PROPERTY_CLEAR option is used, // we need to catch this exception here. // But at the same time we don't want to catch the exception if user explicitly sets the value to null. throw; } } IEnumerable enumValues = LanguagePrimitives.GetEnumerable(setValue); if (enumValues == null) { values.Add(setValue); } else { foreach (object objValue in enumValues) { values.Add(objValue); } } } else { // This means GetMember returned the value from InvokeGet..So set the value using InvokeSet. DirectoryEntry entry = (DirectoryEntry)property.baseObject; Diagnostics.Assert(entry != null, "Object should be of type DirectoryEntry in DirectoryEntry adapter."); List <object> setValues = new List <object>(); IEnumerable enumValues = LanguagePrimitives.GetEnumerable(setValue); if (enumValues == null) { setValues.Add(setValue); } else { foreach (object objValue in enumValues) { setValues.Add(objValue); } } entry.InvokeSet(property.name, setValues.ToArray()); } return; }
private void Prepare(PropertyValueCollection propVals) { propVals.Clear(); currentValues.Clear(); // I do not trust the long-term stability of the PropertyValueCollection // // So what we do is load it up once with LiteralValue references and manipulate these // outside of the collection (via a cached dictionary). We cache everything from the wrapper API // that can be cached in the managed world so that we only have minimal contact with it // Omit read-only properties using (FdoFeatureService service = _conn.CreateFeatureService()) { ClassDefinition c = service.GetClassByName(this.ClassName); foreach (PropertyDefinition p in c.Properties) { string name = p.Name; PropertyValue pv = new PropertyValue(name, null); if (p.PropertyType == PropertyType.PropertyType_DataProperty) { DataPropertyDefinition d = p as DataPropertyDefinition; if (!d.ReadOnly && !d.IsAutoGenerated) { DataValue dv = null; switch (d.DataType) { case DataType.DataType_BLOB: dv = new BLOBValue(); break; case DataType.DataType_Boolean: dv = new BooleanValue(); break; case DataType.DataType_Byte: dv = new ByteValue(); break; case DataType.DataType_CLOB: dv = new CLOBValue(); break; case DataType.DataType_DateTime: dv = new DateTimeValue(); break; case DataType.DataType_Decimal: dv = new DecimalValue(); break; case DataType.DataType_Double: dv = new DoubleValue(); break; case DataType.DataType_Int16: dv = new Int16Value(); break; case DataType.DataType_Int32: dv = new Int32Value(); break; case DataType.DataType_Int64: dv = new Int64Value(); break; case DataType.DataType_Single: dv = new SingleValue(); break; case DataType.DataType_String: dv = new StringValue(); break; } if (dv != null) { pv.Value = dv; propVals.Add(pv); } } } else if (p.PropertyType == PropertyType.PropertyType_GeometricProperty) { GeometricPropertyDefinition g = p as GeometricPropertyDefinition; if (!g.ReadOnly) { GeometryValue gv = new GeometryValue(); pv.Value = gv; propVals.Add(pv); } } } c.Dispose(); } //Load property values into temp dictionary foreach (PropertyValue p in propVals) { currentValues[p.Name.Name] = p.Value as LiteralValue; } if (propertySnapshot == null) { propertySnapshot = new List<string>(); foreach (PropertyValue p in propVals) { propertySnapshot.Add(p.Name.Name); } } }
/// <summary> /// SetMultiValued method implementation /// </summary> internal static void SetMultiValued(PropertyValueCollection props, bool ismultivalued, string value) { if (props == null) { return; } if (!ismultivalued) { if (string.IsNullOrEmpty(value)) { props.Clear(); } else { props.Value = value; } } else { switch (props.Count) { case 0: if (!string.IsNullOrEmpty(value)) { props.Add(SetMultiValuedHeader(value)); } break; case 1: if (props.Value == null) { return; } if (props.Value is string) { string so = props.Value as string; if (string.IsNullOrEmpty(value)) { props.Remove(so); // Clean value anyway return; } if (HasSetMultiValued(so)) { props.Value = SetMultiValuedHeader(value); } else { props.Add(SetMultiValuedHeader(value)); } } break; default: int j = props.Count; for (int i = 0; i < j; i++) { if (props[i] != null) { if (props[i] is string) { string so2 = props[i] as string; if (HasSetMultiValued(so2)) { if (string.IsNullOrEmpty(value)) { props.Remove(so2); } else { props[i] = SetMultiValuedHeader(value); } return; } } } } if (!string.IsNullOrEmpty(value)) { props.Add(SetMultiValuedHeader(value)); // Add tagged value if not null } break; } } }
public static void ClearADObjectPropertyValue(DirectoryEntry oDE, string name) { PropertyValueCollection collection = oDE.Properties[name]; collection.Clear(); }
private void Prepare(PropertyValueCollection propVals) { propVals.Clear(); currentValues.Clear(); // I do not trust the long-term stability of the PropertyValueCollection // // So what we do is load it up once with LiteralValue references and manipulate these // outside of the collection (via a cached dictionary). We cache everything from the wrapper API // that can be cached in the managed world so that we only have minimal contact with it // Omit read-only properties using (FdoFeatureService service = _conn.CreateFeatureService()) { ClassDefinition c = service.GetClassByName(this.ClassName); foreach (PropertyDefinition p in c.Properties) { string name = p.Name; PropertyValue pv = new PropertyValue(name, null); if (p.PropertyType == PropertyType.PropertyType_DataProperty) { DataPropertyDefinition d = p as DataPropertyDefinition; if (!d.ReadOnly && !d.IsAutoGenerated) { DataValue dv = null; switch (d.DataType) { case DataType.DataType_BLOB: dv = new BLOBValue(); break; case DataType.DataType_Boolean: dv = new BooleanValue(); break; case DataType.DataType_Byte: dv = new ByteValue(); break; case DataType.DataType_CLOB: dv = new CLOBValue(); break; case DataType.DataType_DateTime: dv = new DateTimeValue(); break; case DataType.DataType_Decimal: dv = new DecimalValue(); break; case DataType.DataType_Double: dv = new DoubleValue(); break; case DataType.DataType_Int16: dv = new Int16Value(); break; case DataType.DataType_Int32: dv = new Int32Value(); break; case DataType.DataType_Int64: dv = new Int64Value(); break; case DataType.DataType_Single: dv = new SingleValue(); break; case DataType.DataType_String: dv = new StringValue(); break; } if (dv != null) { pv.Value = dv; propVals.Add(pv); } } } else if (p.PropertyType == PropertyType.PropertyType_GeometricProperty) { GeometricPropertyDefinition g = p as GeometricPropertyDefinition; if (!g.ReadOnly) { GeometryValue gv = new GeometryValue(); pv.Value = gv; propVals.Add(pv); } } } c.Dispose(); } //Load property values into temp dictionary foreach (PropertyValue p in propVals) { currentValues[p.Name.Name] = p.Value as LiteralValue; } if (propertySnapshot == null) { propertySnapshot = new List <string>(); foreach (PropertyValue p in propVals) { propertySnapshot.Add(p.Name.Name); } } }
public static void Test_LargeDataVolumeInsert(string SDFFile, string tableName) { try { IConnection mConnection = SDFHelper.SDFConnection(SDFFile); mConnection.Open(); IInsert insertCmd = (IInsert)mConnection.CreateCommand(CommandType.CommandType_Insert); insertCmd.SetFeatureClassName("Civil_schema:" + tableName); 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; IFeatureReader reader; //reader.Dispose(); for (Int32 counter = 0; counter < 1000; counter++) { //intVal.Int32 = counter; 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()); } }
public static void Test_LargeDataVolumeInsert2(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 propVals = insertCmd.PropertyValues; Debug.Write("\n================CHECK INSERT TO SDF ================= " + data.Count()); Debug.Write("\n==========Dict==="); foreach (var it in data) { Debug.Write("\n== Key: " + "'" + it.Key + "'"); Debug.Write("\n== val: " + "'" + it.Value[0] + "'"); Debug.Write("\n== val: " + "'" + it.Value[1] + "'"); } Debug.Write("\n==========Dict==="); //Debug.Write("\n== name: " + "'" + data["Name"][1] + "'"); //Debug.Write("\n== NetworkName: " + "'" + data["NetworkName"][1] + "'"); //Debug.Write("\n== PartSizeName: " + "'" + data["PartSizeName"][1] + "'"); //Debug.Write("\n== Geometry: " + "GEOMFROMTEXT('" + data["Geometry"][1] + "')"); //Expression expr1 = Expression.Parse("'" + data["Name"][1] + "'"); //Expression expr2 = Expression.Parse("'" + data["NetworkName"][1] + "'"); //Expression expr3 = Expression.Parse("'" + data["PartSizeName"][1] + "'"); //Expression expr5 = Expression.Parse("GEOMFROMTEXT('" + data["Geometry"][1] + "')"); Debug.Write("\n================CHECK INSERT TO SDF ================="); 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; 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()); } }
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()); } }