public static NodeDevice BuildWith( FieldIdentifier Code, FieldGuid TypeId, FieldString Address, FieldBase64 Configuration, FieldDeviceName DeviceName) { //build fields Dictionary <FieldIdentifier, FieldBase> mutableFields = new Dictionary <FieldIdentifier, FieldBase>(); mutableFields.Add(new FieldIdentifier(m_CodeName), Code); mutableFields.Add(new FieldIdentifier(m_TypeIdName), TypeId); mutableFields.Add(new FieldIdentifier(m_AddressName), Address); mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration); mutableFields.Add(new FieldIdentifier(m_DeviceNameName), DeviceName); //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code); //build children KeyedNodeCollection <NodeBase> mutableChildren = new KeyedNodeCollection <NodeBase>(); //Add Children here: mutableChildren.Add(SomeChild); //build node NodeDevice Builder = new NodeDevice( new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields), new ReadOnlyCollection <NodeBase>(mutableChildren)); return(Builder); }
public static NodeAnalogInput BuildWith(FieldIdentifier Code, FieldString Address, FieldSignalName InputName) { //build fields Dictionary <FieldIdentifier, FieldBase> mutableFields = new Dictionary <FieldIdentifier, FieldBase>(); mutableFields.Add(new FieldIdentifier(m_CodeName), Code); mutableFields.Add(new FieldIdentifier(m_AddressName), Address); mutableFields.Add(new FieldIdentifier(m_ForcedName), new FieldBool(false)); mutableFields.Add(new FieldIdentifier(m_ForcedValueName), new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, FieldDataType.DefaultValue(FieldDataType.DataTypeEnum.NUMBER))); mutableFields.Add(new FieldIdentifier(m_InputNameName), InputName); //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code); //build children KeyedNodeCollection <NodeBase> mutableChildren = new KeyedNodeCollection <NodeBase>(); mutableChildren.Add(NodeSignal.BuildWith( InputName, new FieldDataType(FieldDataType.DataTypeEnum.NUMBER), new FieldBool(false), new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, FieldDataType.DefaultValue(FieldDataType.DataTypeEnum.NUMBER)))); //Add Children here: mutableChildren.Add(SomeChild); //build node NodeAnalogInput Builder = new NodeAnalogInput( new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields), new ReadOnlyCollection <NodeBase>(mutableChildren)); return(Builder); }
public NodeInstruction SetComment(FieldString Comment) { if (Comment == null) { throw new ArgumentNullException(m_CommentName); } return(new NodeInstruction(this.SetField(new FieldIdentifier(m_CommentName), Comment), ChildCollection)); }
public NodeDriver SetDriverName(FieldString DriverName) { if (DriverName == null) { throw new ArgumentNullException(m_DriverNameName); } return(new NodeDriver(this.SetField(new FieldIdentifier(m_DriverNameName), DriverName), ChildCollection)); }
public NodeAnalogInput SetAddress(FieldString Address) { if (Address == null) { throw new ArgumentNullException(m_AddressName); } return(new NodeAnalogInput(this.SetField(new FieldIdentifier(m_AddressName), Address), ChildCollection)); }
public static NodeRuntimeApplication BuildWith( FieldIdentifier Code, FieldGuid TypeId, FieldGuid RuntimeId, FieldString Address, FieldBase64 Configuration, FieldBool ExecuteOnStartup, NodePageCollection Logic, NodeDeviceConfiguration DeviceConfiguration) { var rta = NodeRuntimeApplication.BuildWith( Code, TypeId, RuntimeId, Address, Configuration, ExecuteOnStartup); rta = rta.SetLogic(Logic); return(rta.SetDeviceConfiguration(DeviceConfiguration)); }
public FormDialog AddFieldString(string title, string dataname, Predicate <string> condition, bool hide = false) { FieldString field = new FieldString(); field.Title = title; field.Dataname = dataname; field.Condition = condition; field.Hidden = hide; fields.Add(field); return(this); }
public ArchetypeField(string _name_, FieldType _type_) { if (_name_ == null) { Error.BadArg("Got null archetype parse_field name"); } if (!Token.is_bare_multi_word(_name_)) { Error.BadArg("Got invalid parse_field name '{0}'", _name_); } if (_type_ == null) { Error.BadArg("Got null FieldType"); } name = _name_; type = _type_; // Initialize default_value with a suitable IObjField instance // // Yes, doing an switch on types in an OO system is often a code smell. // Does anyone have an aesthetically better means of implementing Duck-Typing in C# prior to C# 4.0 ? // switch (_type_.semantic_type) { case SemanticTypes.INT: default_value = new FieldInt(); break; case SemanticTypes.STRING: default_value = new FieldString(); break; case SemanticTypes.DECIMAL: default_value = new FieldDecimal(); break; case SemanticTypes.ID: default_value = new FieldID(); break; case SemanticTypes.LIST_INT: default_value = new FieldListInt(); break; case SemanticTypes.LIST_STRING: default_value = new FieldListString(); break; case SemanticTypes.LIST_DECIMAL: default_value = new FieldListDecimal(); break; case SemanticTypes.LIST_ID: default_value = new FieldListID(); break; default: Error.BadArg("Got unknown field type '{0}'", _type_); break; } // This method sets up an IObjField with the default C# value for the storage type // (0, "", 0.0M, or an empty list of one of these). // The additional constructors below (with additional args) are called // when a default field value (or a non-empty default list) is specified, // which is possibly the more common case. }
protected override void Run() { base.Run(); var deviceItem = Context as IDeviceSolutionItem; if (deviceItem != null) { FieldString newAddress = authenticateDialog.Value.ShowDialog(); if (newAddress != null && newAddress.ToString() != string.Empty) { deviceItem.Device = deviceItem.Device.SetAddress(newAddress); } } }
public static NodeDevice StaticBuild() { FieldIdentifier code; FieldGuid typeId; FieldString address; FieldBase64 configuration; FieldDeviceName deviceName; code = new FieldIdentifier(CODE); typeId = new FieldGuid(TYPE_ID); address = new FieldString(string.Empty); configuration = new FieldBase64(string.Empty); deviceName = new FieldDeviceName(Resources.Strings.Unknown_Phidget_Name); NodeDevice device = NodeDevice.BuildWith(code, typeId, address, configuration, deviceName); return(device); }
public static NodeRuntimeApplication BuildWith( FieldIdentifier Code, FieldGuid TypeId, FieldGuid RuntimeId, FieldString Address, FieldBase64 Configuration, FieldBool ExecuteOnStartup) { //build fields Dictionary <FieldIdentifier, FieldBase> mutableFields = new Dictionary <FieldIdentifier, FieldBase>(); mutableFields.Add(new FieldIdentifier(m_CodeName), Code); mutableFields.Add(new FieldIdentifier(m_TypeIdName), TypeId); mutableFields.Add(new FieldIdentifier(m_RuntimeIdName), RuntimeId); mutableFields.Add(new FieldIdentifier(m_AddressName), Address); mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration); mutableFields.Add(new FieldIdentifier(m_ExecuteOnStartupName), ExecuteOnStartup); mutableFields.Add(new FieldIdentifier(m_TryModeName), new FieldBool(false)); //Add Fields here: mutableFields.Add(new FieldIdentifier("Code"), Code); //build children KeyedNodeCollection <NodeBase> mutableChildren = new KeyedNodeCollection <NodeBase>(); var pc = NodePageCollection.BuildWith( new FieldPageCollectionName(m_LogicName) ); pc = pc.SetLogicRoot(new FieldBool(true)); mutableChildren.Add(pc); mutableChildren.Add( NodeDeviceConfiguration.BuildWith( new ReadOnlyCollection <NodeDriver>(new Collection <NodeDriver>()) )); //Add Children here: mutableChildren.Add(SomeChild); //build node NodeRuntimeApplication Builder = new NodeRuntimeApplication( new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields), new ReadOnlyCollection <NodeBase>(mutableChildren)); return(Builder); }
/// <summary> /// Returns the new Address field for the NodeDevice /// </summary> public FieldString ShowDialog() { Window dlg = new AuthenticateDialogView(); dlg.Owner = mainWindowExport.Value; dlg.DataContext = this; dlg.ShowDialog(); FieldString retVal = null; if (Username != string.Empty) { var twitter = FluentTwitter.CreateRequest() .Configuration.UseHttps() .Authentication.GetClientAuthAccessToken(TwitterConsumer.ConsumerKey, TwitterConsumer.ConsumerSecret, Username, Password.ConvertToUnsecureString()); var response = twitter.Request(); try { var token = response.AsToken(); // the token and token secret seem to be base-64 encoded already, but there's no guarantee, so let's encode them again var item1 = FieldBase64.Encode(token.Token).ToString(); var item2 = FieldBase64.Encode(token.TokenSecret).ToString(); retVal = new FieldString(item1 + AbstractTwitterDevice.ADDRESS_SEPARATOR + item2); messagingService.ShowMessage(Resources.Strings.ContextMenu_Authenticate_Success, Resources.Strings.ContextMenu_Authenticate_Success_Title); } catch (Exception ex) { logger.Error("Error authenticating Twitter", ex); messagingService.ShowMessage(Resources.Strings.ContextMenu_Authenticate_Fail, Resources.Strings.ContextMenu_Authenticate_Fail_Title); } } return(retVal); }
public static NodeDevice StaticBuildHelper(string deviceName, string typeId, Guid instanceId, string code, int buttons, int axes, int povhats) { FieldIdentifier c; FieldGuid typ; FieldString address; FieldBase64 configuration; FieldDeviceName dName; c = new FieldIdentifier(code); typ = new FieldGuid(typeId); address = new FieldString(instanceId.ToString()); configuration = new FieldBase64(string.Empty); dName = new FieldDeviceName(deviceName); NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName); // Add the inputs var inputsMutable = new Collection <NodeDiscreteInput>(); for (int i = 0; i < buttons; i++) { int buttonNumber = i + 1; inputsMutable.Add(NodeDiscreteInput.BuildWith( new FieldIdentifier(Resources.Strings.Button + buttonNumber), new FieldString(i.ToString()), new FieldSignalName(Resources.Strings.Button + " " + buttonNumber))); } var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable); device = device.NodeDiscreteInputChildren.Append(inputs); var analogInputsMutable = new Collection <NodeAnalogInput>(); for (int i = 0; i < axes; i++) { if (i == 3) { break; // only supports up to 3 axes } int axisNumber = i + 1; string axisName = axisNumber == 1 ? "X" : axisNumber == 2 ? "Y" : axisNumber == 3 ? "Z" : null; analogInputsMutable.Add(NodeAnalogInput.BuildWith( new FieldIdentifier(axisName), new FieldString(axisName), new FieldSignalName(axisName))); string rotationName = "Rotation" + axisName; analogInputsMutable.Add(NodeAnalogInput.BuildWith( new FieldIdentifier(rotationName), new FieldString(rotationName), new FieldSignalName(rotationName))); } for (int i = 0; i < povhats; i++) { int povNumber = i + 1; analogInputsMutable.Add(NodeAnalogInput.BuildWith( new FieldIdentifier(Resources.Strings.PoVHat + povNumber.ToString()), new FieldString(i.ToString()), new FieldSignalName(Resources.Strings.PoVHat + " " + povNumber.ToString()))); } device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable)); return(device); }
private static IReportElement BuildTestGroup() { ElementGroupDynamic testGroup = new ElementGroupDynamic("TestGroup"); IReportElement bool1 = new FieldBoolean("bool1", false); IReportElement bool2 = new FieldBoolean("bool2", true); IReportElement bool3 = new FieldBoolean("bool3", false); IReportElement specialBool = new FieldBoolean("specialBool", false, "tooltip!"); IReportElement specialBool2 = new FieldBoolean("specialBool2", false, "tooltip!"); IReportField textField = new FieldString("textField"); textField.SetData("This is some text for the text field!"); IReportElement comment = new ElementComment("comment1", "This is a comment text block!"); IReportField intField1 = new FieldInteger("intField1", "int field description"); intField1.SetData(5); IReportElement specialString = new FieldString("specialString", "field Description"); ElementGroupDynamic row = new ElementGroupDynamic("testRow"); row.AddElement(new FieldBoolean("boolField", false)); row.AddElement(new FieldInteger("intField")); FieldRows fieldRow = new FieldRows("fieldRows", row); fieldRow.AddRow(); fieldRow.AddRow(); IReportField intField2 = new FieldInteger("intField2"); intField2.SetData("41"); string[] radioOptions = { "op1", "op2", "op3", "op3" }; FieldRadio radioTest = new FieldRadio("radioTest", radioOptions); radioTest.SetData("op3"); string[] listOptions = { "li1", "li2", "li3", "li4" }; FieldList listTest = new FieldList("listTest", listOptions); listTest.SetData("li2"); //testGroup.AddElement(specialBool); //testGroup.AddElement(specialBool2); //testGroup.AddElement(textField); //testGroup.AddElement(comment); //testGroup.AddElement(intField1); //testGroup.AddElement(intField2); //testGroup.AddElement(specialString); //testGroup.AddElement(radioTest); //testGroup.AddElement(listTest); testGroup.AddElement(fieldRow); testGroup.AddElement(bool1); testGroup.AddElement(bool2); testGroup.AddElement(bool3); return(testGroup); }
public static NodeDevice StaticBuildHelper(string deviceName, int serialNumber, string code, string typeId, int discreteInputs, int discreteOutputs, int analogInputs, int analogOutputs, int stringInputs, int stringOutputs, string analogOutputNameOverride, string discreteOutputNameOverride) { FieldIdentifier c; FieldGuid typ; FieldString address; FieldBase64 configuration; FieldDeviceName dName; c = new FieldIdentifier(code); typ = new FieldGuid(typeId); address = new FieldString(serialNumber.ToString()); configuration = new FieldBase64(string.Empty); dName = new FieldDeviceName(deviceName); NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName); // Add the inputs var inputsMutable = new Collection <NodeDiscreteInput>(); for (int i = 0; i < discreteInputs; i++) { inputsMutable.Add(NodeDiscreteInput.BuildWith( new FieldIdentifier(Resources.Strings.Input + i), new FieldString(i.ToString()), new FieldSignalName(Resources.Strings.Input + " " + i))); } var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable); device = device.NodeDiscreteInputChildren.Append(inputs); var analogInputsMutable = new Collection <NodeAnalogInput>(); for (int i = 0; i < analogInputs; i++) { analogInputsMutable.Add(NodeAnalogInput.BuildWith( new FieldIdentifier(Resources.Strings.AnalogInput + i), new FieldString(i.ToString()), new FieldSignalName(Resources.Strings.AnalogInput + " " + i))); } device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable)); var stringInputsMutable = new Collection <NodeStringInput>(); for (int i = 0; i < stringInputs; i++) { stringInputsMutable.Add(NodeStringInput.BuildWith( new FieldIdentifier(Resources.Strings.StringInput + i), new FieldString(i.ToString()), new FieldSignalName(Resources.Strings.StringInput + " " + i))); } device = device.NodeStringInputChildren.Append(new ReadOnlyCollection <NodeStringInput>(stringInputsMutable)); // Add the outputs var outputsMutable = new Collection <NodeDiscreteOutput>(); for (int i = 0; i < discreteOutputs; i++) { outputsMutable.Add(NodeDiscreteOutput.BuildWith( new FieldIdentifier(Resources.Strings.Output + i), new FieldString(i.ToString()), new FieldSignalName(discreteOutputNameOverride + " " + i))); } var outputs = new ReadOnlyCollection <NodeDiscreteOutput>(outputsMutable); device = device.NodeDiscreteOutputChildren.Append(outputs); var analogOutputsMutable = new Collection <NodeAnalogOutput>(); for (int i = 0; i < analogOutputs; i++) { analogOutputsMutable.Add(NodeAnalogOutput.BuildWith( new FieldIdentifier(Resources.Strings.AnalogOutput + i), new FieldString(i.ToString()), new FieldSignalName(analogOutputNameOverride + " " + i))); } device = device.NodeAnalogOutputChildren.Append(new ReadOnlyCollection <NodeAnalogOutput>(analogOutputsMutable)); var stringOutputsMutable = new Collection <NodeStringOutput>(); for (int i = 0; i < stringOutputs; i++) { stringOutputsMutable.Add(NodeStringOutput.BuildWith( new FieldIdentifier(Resources.Strings.StringOutput + i), new FieldString(i.ToString()), new FieldSignalName(Resources.Strings.StringOutput + " " + i))); } device = device.NodeStringOutputChildren.Append(new ReadOnlyCollection <NodeStringOutput>(stringOutputsMutable)); return(device); }
private FieldBase GetField(ContractPropertyInfo property) { FieldBase field; if (property.IsDictionary) { if (property.TypeName == "TranslatedStringDictionary") { field = new FieldTranslatedString { Required = false, Fixed = false, Index = true, SimpleSearch = true, MultiLine = false, Boost = 1, IndexAnalyzers = new List <AnalyzerBase> { new LanguageAnalyzer() }, SimpleSearchAnalyzers = new List <AnalyzerBase> { new LanguageAnalyzer() } }; } else if (property.IsArray) { field = new FieldDictionaryArray(); } else { field = new FieldDictionary(); } } else if (property.IsEnum) { throw new NotSupportedException("Enum types are not supported in Class to Schema conversion"); } else if (property.IsSimpleType) { if (!Enum.TryParse(property.TypeName, out TypeCode typeCode)) { throw new Exception($"Parsing to TypeCode enumerated object failed for string value: {property.TypeName}."); } if (property.IsArray) { switch (typeCode) { case TypeCode.String: field = new FieldStringArray { Index = true }; break; case TypeCode.DateTime: field = new FieldDateTimeArray { Index = true }; break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: field = new FieldLongArray { Index = true }; break; default: throw new Exception($"TypeCode {typeCode} is not supported."); } } else { var stringInfos = property.PictureparkAttributes.OfType <PictureparkStringAttribute>().SingleOrDefault(); switch (typeCode) { case TypeCode.String: field = new FieldString { Index = true, SimpleSearch = true, Boost = 1, IndexAnalyzers = new List <AnalyzerBase> { new SimpleAnalyzer() }, SimpleSearchAnalyzers = new List <AnalyzerBase> { new SimpleAnalyzer() }, MultiLine = stringInfos?.MultiLine ?? false }; break; case TypeCode.DateTime: field = CreateDateTypeField(property); break; case TypeCode.Boolean: field = new FieldBoolean { Index = true }; break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: field = new FieldLong { Index = true }; break; case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Single: field = new FieldDecimal { Index = true }; break; default: throw new Exception($"TypeCode {typeCode} is not supported."); } } } else { var schemaIndexingAttribute = property.PictureparkAttributes.OfType <PictureparkSchemaIndexingAttribute>().SingleOrDefault(); var listItemCreateTemplateAttribute = property.PictureparkAttributes.OfType <PictureparkListItemCreateTemplateAttribute>().SingleOrDefault(); var tagboxAttributes = property.PictureparkAttributes.OfType <PictureparkTagboxAttribute>().SingleOrDefault(); var contentRelationAttributes = property.PictureparkAttributes.OfType <PictureparkContentRelationAttribute>().ToList(); var relationTypes = new List <RelationType>(); if (contentRelationAttributes.Any()) { relationTypes = contentRelationAttributes.Select(i => new RelationType { Id = i.Name, Filter = i.Filter, TargetDocType = i.TargetDocType, Names = new TranslatedStringDictionary { { _defaultLanguage, i.Name } } }).ToList(); } if (property.IsArray) { if (contentRelationAttributes.Any()) { field = new FieldMultiRelation { Index = true, RelationTypes = relationTypes, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } else if (property.IsReference) { field = new FieldMultiTagbox { Index = true, SimpleSearch = true, SchemaId = property.TypeName, Filter = tagboxAttributes?.Filter, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo, ListItemCreateTemplate = listItemCreateTemplateAttribute?.ListItemCreateTemplate }; } else { field = new FieldMultiFieldset { Index = true, SimpleSearch = true, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } } else { if (contentRelationAttributes.Any()) { field = new FieldSingleRelation { Index = true, SimpleSearch = true, RelationTypes = relationTypes, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } else if (property.TypeName == "GeoPoint") { field = new FieldGeoPoint { Index = true }; } else if (property.IsReference) { field = new FieldSingleTagbox { Index = true, SimpleSearch = true, SchemaId = property.TypeName, Filter = tagboxAttributes?.Filter, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo, ListItemCreateTemplate = listItemCreateTemplateAttribute?.ListItemCreateTemplate }; } else { field = new FieldSingleFieldset { Index = true, SimpleSearch = true, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } } } if (field == null) { throw new Exception($"Could not find type for {property.Name}"); } foreach (var attribute in property.PictureparkAttributes) { if (attribute is PictureparkSearchAttribute searchAttribute) { field.Index = searchAttribute.Index; field.SimpleSearch = searchAttribute.SimpleSearch; if (field.GetType().GetRuntimeProperty("Boost") != null) { field.GetType().GetRuntimeProperty("Boost").SetValue(field, searchAttribute.Boost); } } if (attribute is PictureparkRequiredAttribute) { field.Required = true; } if (attribute is PictureparkMaximumLengthAttribute maxLengthAttribute) { field.GetType().GetRuntimeProperty("MaximumLength").SetValue(field, maxLengthAttribute.Length); } if (attribute is PictureparkPatternAttribute patternAttribute) { field.GetType().GetRuntimeProperty("Pattern").SetValue(field, patternAttribute.Pattern); } if (attribute is PictureparkNameTranslationAttribute nameTranslationAttribute) { if (field.Names == null) { field.Names = new TranslatedStringDictionary(); } var language = string.IsNullOrEmpty(nameTranslationAttribute.LanguageAbbreviation) ? _defaultLanguage : nameTranslationAttribute.LanguageAbbreviation; field.Names[language] = nameTranslationAttribute.Translation; } if (attribute is PictureparkSortAttribute) { if (field is FieldSingleRelation || field is FieldMultiRelation) { throw new InvalidOperationException($"Relation property {property.Name} must not be marked as sortable."); } if (field is FieldGeoPoint) { throw new InvalidOperationException($"GeoPoint property {property.Name} must not be marked as sortable."); } field.Sortable = true; } } var fieldName = property.Name; field.Id = fieldName.ToLowerCamelCase(); if (field.Names == null) { field.Names = new TranslatedStringDictionary { [_defaultLanguage] = fieldName }; } if (property.PictureparkAttributes.OfType <PictureparkAnalyzerAttribute>().Any(a => !a.Index && !a.SimpleSearch)) { throw new InvalidOperationException( $"Property {property.Name} has invalid analyzer configuration: Specify one or both of {nameof(PictureparkAnalyzerAttribute.Index)}, {nameof(PictureparkAnalyzerAttribute.SimpleSearch)}."); } var fieldIndexAnalyzers = property.PictureparkAttributes .OfType <PictureparkAnalyzerAttribute>() .Where(a => a.Index) .Select(a => a.CreateAnalyzer()) .ToList(); if (fieldIndexAnalyzers.Any()) { field.GetType().GetRuntimeProperty("IndexAnalyzers").SetValue(field, fieldIndexAnalyzers); } var fieldSimpleSearchAnalyzers = property.PictureparkAttributes .OfType <PictureparkAnalyzerAttribute>() .Where(a => a.SimpleSearch) .Select(a => a.CreateAnalyzer()) .ToList(); if (fieldSimpleSearchAnalyzers.Any()) { field.GetType().GetRuntimeProperty("SimpleSearchAnalyzers").SetValue(field, fieldSimpleSearchAnalyzers); } return(field); }
public void add_field(string field_name, FieldType type) { IObjField field = null; // or perhaps: new FieldTempNull(this, field_name); switch (type.semantic_type) { case SemanticTypes.INT: field = new FieldInt(); break; case SemanticTypes.STRING: field = new FieldString(); break; case SemanticTypes.DECIMAL: field = new FieldDecimal(); break; case SemanticTypes.ID: field = new FieldID(); break; case SemanticTypes.LIST_INT: field = new FieldListInt(); break; case SemanticTypes.LIST_STRING: field = new FieldListString(); break; case SemanticTypes.LIST_DECIMAL: field = new FieldListDecimal(); break; case SemanticTypes.LIST_ID: field = new FieldListID(); break; default: Error.BadArg("Got unknown field type '{0}'", type); break; } fields[field_name] = field; }
private FieldBase GetField(ContractPropertyInfo property) { FieldBase field = null; if (property.IsDictionary) { if (property.TypeName == "TranslatedStringDictionary") { field = new FieldTranslatedString { Required = false, Fixed = false, Index = true, SimpleSearch = true, MultiLine = false, Boost = 1, Analyzers = new List <AnalyzerBase> { new LanguageAnalyzer { SimpleSearch = true } } }; } else if (property.IsArray) { field = new FieldDictionaryArray(); } else { field = new FieldDictionary(); } } else if (property.IsEnum) { Type enumType = Type.GetType($"{property.FullName}, {property.AssemblyFullName}"); // TODO: Handle enums } else if (property.IsSimpleType) { if (!Enum.TryParse(property.TypeName, out TypeCode typeCode)) { throw new Exception($"Parsing to TypeCode enumarated object failed for string value: {property.TypeName}."); } if (property.IsArray) { switch (typeCode) { case TypeCode.String: field = new FieldStringArray { Index = true }; break; case TypeCode.DateTime: field = new FieldDateTimeArray { Index = true }; break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: field = new FieldLongArray { Index = true }; break; default: throw new Exception($"TypeCode {typeCode} is not supported."); } } else { var stringInfos = property.PictureparkAttributes.OfType <PictureparkStringAttribute>().SingleOrDefault(); switch (typeCode) { case TypeCode.String: field = new FieldString { Index = true, SimpleSearch = true, Boost = 1, Analyzers = new List <AnalyzerBase> { new SimpleAnalyzer { SimpleSearch = true } }, MultiLine = stringInfos?.MultiLine ?? false }; break; case TypeCode.DateTime: field = new FieldDateTime { Index = true }; break; case TypeCode.Boolean: field = new FieldBoolean { Index = true }; break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: field = new FieldLong { Index = true }; break; case TypeCode.Decimal: case TypeCode.Double: case TypeCode.Single: field = new FieldDecimal { Index = true }; break; default: throw new Exception($"TypeCode {typeCode} is not supported."); } } } else { var schemaIndexingAttribute = property.PictureparkAttributes.OfType <PictureparkSchemaIndexingAttribute>().SingleOrDefault(); var listItemCreateTemplateAttribute = property.PictureparkAttributes.OfType <PictureparkListItemCreateTemplateAttribute>().SingleOrDefault(); var maximumRecursionAttribute = property.PictureparkAttributes.OfType <PictureparkMaximumRecursionAttribute>().SingleOrDefault(); var tagboxAttributes = property.PictureparkAttributes.OfType <PictureparkTagboxAttribute>().SingleOrDefault(); var contentRelationAttributes = property.PictureparkAttributes.OfType <PictureparkContentRelationAttribute>().ToList(); var relationTypes = new List <RelationType>(); if (contentRelationAttributes.Any()) { relationTypes = contentRelationAttributes.Select(i => new RelationType { Id = i.Name, Filter = i.Filter, TargetDocType = i.TargetDocType, Names = new TranslatedStringDictionary { { "x-default", i.Name } } }).ToList(); } if (property.IsArray) { if (contentRelationAttributes.Any()) { field = new FieldMultiRelation { Index = true, RelationTypes = relationTypes, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } else if (property.IsReference) { field = new FieldMultiTagbox { Index = true, SimpleSearch = true, SchemaId = property.TypeName, Filter = tagboxAttributes?.Filter, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo, ListItemCreateTemplate = listItemCreateTemplateAttribute?.ListItemCreateTemplate }; } else { field = new FieldMultiFieldset { Index = true, SimpleSearch = true, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } } else { if (contentRelationAttributes.Any()) { field = new FieldSingleRelation { Index = true, SimpleSearch = true, RelationTypes = relationTypes, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } else if (property.TypeName == "GeoPoint") { field = new FieldGeoPoint { Index = true }; } else if (property.IsReference) { field = new FieldSingleTagbox { Index = true, SimpleSearch = true, SchemaId = property.TypeName, Filter = tagboxAttributes?.Filter, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo, ListItemCreateTemplate = listItemCreateTemplateAttribute?.ListItemCreateTemplate }; } else { field = new FieldSingleFieldset { Index = true, SimpleSearch = true, SchemaId = property.TypeName, SchemaIndexingInfo = schemaIndexingAttribute?.SchemaIndexingInfo }; } } } if (field == null) { throw new Exception($"Could not find type for {property.Name}"); } foreach (var attribute in property.PictureparkAttributes) { if (attribute is PictureparkSearchAttribute searchAttribute) { field.Index = searchAttribute.Index; field.SimpleSearch = searchAttribute.SimpleSearch; if (field.GetType().GetRuntimeProperty("Boost") != null) { field.GetType().GetRuntimeProperty("Boost").SetValue(field, searchAttribute.Boost); } } if (attribute is PictureparkRequiredAttribute) { field.Required = true; } if (attribute is PictureparkMaximumLengthAttribute maxLengthAttribute) { field.GetType().GetRuntimeProperty("MaximumLength").SetValue(field, maxLengthAttribute.Length); } if (attribute is PictureparkPatternAttribute patternAttribute) { field.GetType().GetRuntimeProperty("Pattern").SetValue(field, patternAttribute.Pattern); } if (attribute is PictureparkNameTranslationAttribute nameTranslationAttribute) { if (field.Names == null) { field.Names = new TranslatedStringDictionary(); } field.Names[nameTranslationAttribute.LanguageAbbreviation] = nameTranslationAttribute.Translation; } } var fieldName = property.Name; field.Id = fieldName.ToLowerCamelCase(); if (field.Names == null) { field.Names = new TranslatedStringDictionary { ["x-default"] = fieldName }; } var fieldAnalyzers = property.PictureparkAttributes .OfType <PictureparkAnalyzerAttribute>() .Select(a => a.CreateAnalyzer()) .ToList(); if (fieldAnalyzers.Any()) { field.GetType().GetRuntimeProperty("Analyzers").SetValue(field, fieldAnalyzers); } return(field); }
/// <summary> /// NB: This code creates a point feature service if nothing has been selected in the "My Feature Services Info -> Items combobox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddDefinitionToLayer_Click(object sender, EventArgs e) { Item item = null; Extent extent = null; Symbol symbol = null; Renderer renderer = null; DrawingInfo drawingInfo = null; object[] fields = null; Template template = null; EditorTrackingInfo editorTrackingInfo = null; AdminLayerInfoAttribute adminLayerInfo = null; DefinitionLayer layer = null; string formattedRequest = string.Empty; string jsonResponse = string.Empty; FeatureLayerAttributes featLayerAttributes = null; this.Cursor = Cursors.WaitCursor; //NB: From the Items combobox if you have a feature service selected, this is the attribute table structure that will be used for the //creation of the new service. Otherwise create a new featureLayerAttributes class as set up in this code. // if (chkbxUseSelectedFS.Checked) { string[] concatenatedText = cboItems.Text.Split(':'); string split = concatenatedText[1].Replace(" ID", ""); if (_myOrganizationalContent.TryGetValue(cboItems.Text, out item)) if(item != null) if(item.url != null) featLayerAttributes = RequestAndResponseHandler.GetFeatureServiceAttributes(item.url, _token, out formattedRequest, out jsonResponse); try { if (featLayerAttributes == null) _featureServiceAttributesDataDictionary.TryGetValue(split.Trim(), out _featureLayerAttributes); } catch { } } if (featLayerAttributes == null) if (_featureLayerAttributes != null) featLayerAttributes = _featureLayerAttributes; else featLayerAttributes = new FeatureLayerAttributes(); //ensure that we have all that we need for a successful feature layer attributes push // if(featLayerAttributes.extent != null) extent = featLayerAttributes.extent; else { //write in your default extent values here: extent = new Extent() { xmin = -14999999.999999743, ymin = 1859754.5323447795, xmax = -6199999.999999896, ymax = 7841397.327701188, spatialReference = new SpatialReference() { wkid = 102100, latestWkid = 3857 }, }; } if (featLayerAttributes.drawingInfo != null) drawingInfo = featLayerAttributes.drawingInfo; else { symbol = new PointSymbol() { type = "esriPMS", url = "RedSphere.png", imageData = "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", contentType = "image/png", color = null, width = 15, height = 15, angle = 0, xoffset = 0, yoffset = 0 }; renderer = new PointRenderer() { type = "simple", symbol = symbol, label = "", description = "" }; drawingInfo = new DrawingInfo() { renderer = renderer, labelingInfo = null }; } if (featLayerAttributes.fields != null) fields = featLayerAttributes.fields; else { Field field = new Field() { name = "Longitude", type = "esriFieldTypeDouble", alias = "Longitude", sqlType = "sqlTypeFloat", nullable = true, editable = true, domain = null, defaultValue = null }; Field field2 = new Field() { name = "Latitude", type = "esriFieldTypeDouble", alias = "Latitude", sqlType = "sqlTypeFloat", nullable = true, editable = true, domain = null, defaultValue = null }; FieldString field3 = new FieldString() { name = "Name", type = "esriFieldTypeString", alias = "Name", sqlType = "sqlTypeNVarchar", length = 256, nullable = true, editable = true, domain = null, defaultValue = null }; FieldString field4 = new FieldString() { name = "Address", type = "esriFieldTypeString", alias = "Address", sqlType = "sqlTypeNVarchar", length = 256, nullable = true, editable = true, domain = null, defaultValue = null }; //DO NOT CHANGE PROPERTIES BELOW Field fieldFID = new Field() { name = "FID", type = "esriFieldTypeInteger", alias = "FID", sqlType = "sqlTypeInteger", nullable = false, editable = false, domain = null, defaultValue = null }; //object array so that we can contain different types within. //Field type double for example does not contain a length parameter. Hence we need different field type //representation. Unexpected properties for data types will cause a failure on the server end. fields = new object[5] { field, field2, field3, field4, fieldFID }; } if (featLayerAttributes.templates != null) template = featLayerAttributes.templates[0]; else { template = new Template() { name = "New Feature", description = "", drawingTool = "esriFeatureEditToolPoint", prototype = new Prototype() { attributes = new Attributes() } }; } editorTrackingInfo = new EditorTrackingInfo() { enableEditorTracking = false, enableOwnershipAccessControl = false, allowOthersToUpdate = true, allowOthersToDelete = true }; adminLayerInfo = new AdminLayerInfoAttribute() { geometryField = new GeometryField() { name = "Shape", srid = 102100 } }; layer = new DefinitionLayer() { currentVersion = featLayerAttributes != null ? featLayerAttributes.currentVersion : 10.11, id = 0, name = featLayerAttributes != null ? featLayerAttributes.name != null ? featLayerAttributes.name : txtFeatureServiceName.Text : txtFeatureServiceName.Text, type = featLayerAttributes != null ? featLayerAttributes.type != null ? featLayerAttributes.type : "Feature Layer" : "Feature Layer", displayField = featLayerAttributes != null ? featLayerAttributes.displayField != null ? featLayerAttributes.displayField : "" : "", description = "", copyrightText = featLayerAttributes != null ? featLayerAttributes.copyrightText != null ? featLayerAttributes.copyrightText : "" : "", defaultVisibility = featLayerAttributes != null ? featLayerAttributes.defaultVisibility != null ? featLayerAttributes.defaultVisibility : true : true, relationships = featLayerAttributes != null ? featLayerAttributes.relationShips != null ? featLayerAttributes.relationShips : new object[]{} : new object[] { }, isDataVersioned = featLayerAttributes != null ? featLayerAttributes.isDataVersioned : false, supportsRollbackOnFailureParameter = true, supportsAdvancedQueries = true, geometryType = featLayerAttributes != null ? featLayerAttributes.geometryType != null ? featLayerAttributes.geometryType : "esriGeometryPoint" : "esriGeometryPoint", minScale = featLayerAttributes != null ? featLayerAttributes.minScale : 0, maxScale = featLayerAttributes != null ? featLayerAttributes.maxScale : 0, extent = extent, drawingInfo = _javaScriptSerializer.Serialize(drawingInfo), allowGeometryUpdates = featLayerAttributes != null ? featLayerAttributes.allowGeometryUpdates != null ? featLayerAttributes.allowGeometryUpdates : true : true, hasAttachments = featLayerAttributes != null ? featLayerAttributes.hasAttachments : false, htmlPopupType = featLayerAttributes != null ? featLayerAttributes.htmlPopupType != null ? featLayerAttributes.htmlPopupType : "esriServerHTMLPopupTypeNone" : "esriServerHTMLPopupTypeNone", hasM = featLayerAttributes != null ? featLayerAttributes.hasM : false, hasZ = featLayerAttributes != null ? featLayerAttributes.hasZ : false, objectIdField = featLayerAttributes != null ? featLayerAttributes.objectIdField != null ? featLayerAttributes.objectIdField : "FID" : "FID", globalIdField = featLayerAttributes != null ? featLayerAttributes.globalIdField != null ? featLayerAttributes.globalIdField : "" : "", typeIdField = featLayerAttributes != null ? featLayerAttributes.typeIdField != null ? featLayerAttributes.typeIdField : "" : "", fields = fields, types = featLayerAttributes != null ? featLayerAttributes.types != null ? featLayerAttributes.types : new object[0] : new object[0], templates = new Template[1] { template }, supportedQueryFormats = featLayerAttributes != null ? featLayerAttributes.supportedQueryFormats != null ? featLayerAttributes.supportedQueryFormats: "JSON" : "JSON", hasStaticData = featLayerAttributes != null ? featLayerAttributes.hasStaticData : false, maxRecordCount = 2000,//featLayerAttributes != null ? featLayerAttributes.maxRecordCount != null ? featLayerAttributes.maxRecordCount : 200000 : 200000, capabilities = featLayerAttributes != null ? featLayerAttributes.capabilities != null ? featLayerAttributes.capabilities : "Query,Editing,Create,Update,Delete" : "Query,Editing,Create,Update,Delete", //editorTrackingInfo = editorTrackingInfo, adminLayerInfo = adminLayerInfo }; DefinitionLayer[] layers = new DefinitionLayer[1] { layer }; AddDefinition definition = new AddDefinition() { layers = layers }; string serviceEndPoint = "http://services1.arcgis.com/"; //NB: Trial Account endpoint!!!! string serviceEndPoint2 = "http://services.arcgis.com/"; string requestURL = string.Format("{0}{1}/arcgis/admin/services/{2}.FeatureServer/AddToDefinition", serviceEndPoint, _organizationID, _featureServiceCreationResponse.Name); bool b = RequestAndResponseHandler.AddToFeatureServiceDefinition(requestURL, definition, _token, txtOrgURL.Text, out formattedRequest, out jsonResponse); if (!b) { requestURL = string.Format("{0}{1}/arcgis/admin/services/{2}.FeatureServer/AddToDefinition", serviceEndPoint2, _organizationID, _featureServiceCreationResponse.Name); b = RequestAndResponseHandler.AddToFeatureServiceDefinition(requestURL, definition, _token, txtOrgURL.Text, out formattedRequest, out jsonResponse); } ShowRequestResponseStrings(formattedRequest, jsonResponse); lblSuccess.Text = b == true ? "true" : "false"; this.Cursor = Cursors.Default; }