예제 #1
0
        private void AddContactNames(MASchemaType type)
        {
            AdapterSubfield givenName = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "givenName",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                PropertyName            = "GivenName",
                AttributeNamePart       = "givenName",
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder
            };

            AdapterSubfield familyName = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "familyName",
                IsMultivalued           = false,
                PropertyName            = "FamilyName",
                Operation               = AttributeOperation.ImportExport,
                AttributeNamePart       = "familyName",
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder
            };

            AdapterSubfield fullName = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "fullName",
                IsMultivalued           = false,
                PropertyName            = "FullName",
                Operation               = AttributeOperation.ImportExport,
                AttributeNamePart       = "fullName",
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder
            };

            AdapterNestedType schemaItem = new AdapterNestedType
            {
                Api           = "contact",
                AttributeName = "name",
                Fields        = new List <AdapterSubfield>()
                {
                    givenName, familyName, fullName
                },
                FieldName     = "name",
                PropertyName  = "Name",
                SupportsPatch = false
            };

            type.AttributeAdapters.Add(schemaItem);
        }
        private static void AddUserNotes(MASchemaType type)
        {
            AdapterSubfield notesValue = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "value",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                PropertyName            = "Value",
                AttributeNamePart       = "value",
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder
            };

            AdapterSubfield notesContentType = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "contentType",
                IsMultivalued           = false,
                PropertyName            = "ContentType",
                Operation               = AttributeOperation.ImportExport,
                AttributeNamePart       = "contentType",
                NullValueRepresentation = NullValueRepresentation.NullPlaceHolder
            };

            AdapterNestedType notesType = new AdapterNestedType
            {
                Api           = "user",
                AttributeName = "notes",
                Fields        = new List <AdapterSubfield>()
                {
                    notesContentType, notesValue
                },
                FieldName     = "notes",
                PropertyName  = "Notes",
                SupportsPatch = false
            };

            type.AttributeAdapters.Add(notesType);
        }
        public IEnumerable <MASchemaType> GetSchemaTypes(IManagementAgentParameters config)
        {
            MASchemaType type = new MASchemaType
            {
                AttributeAdapters = new List <IAttributeAdapter>(),
                Name = "building",
                AnchorAttributeNames = new[] { "id" },
                SupportsPatch        = true,
            };

            type.ApiInterface = new ApiInterfaceBuilding(config.CustomerID, type, config);

            type.AttributeAdapters.Add(new AdapterPropertyValue
            {
                AttributeType = AttributeType.String,
                FieldName     = "buildingId",
                IsMultivalued = false,
                Operation     = AttributeOperation.ImportOnly,
                AttributeName = "id",
                PropertyName  = "BuildingId",
                Api           = "building",
                SupportsPatch = true,
                IsAnchor      = true
            });

            type.AttributeAdapters.Add(new AdapterPropertyValue
            {
                AttributeType           = AttributeType.String,
                FieldName               = "buildingName",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "buildingName",
                PropertyName            = "BuildingName",
                Api                     = "building",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.EmptyString,
                IsAnchor                = false
            });

            type.AttributeAdapters.Add(new AdapterPropertyValue
            {
                AttributeType           = AttributeType.String,
                FieldName               = "description",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "description",
                PropertyName            = "Description",
                Api                     = "building",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.EmptyString,
                IsAnchor                = false
            });

            type.AttributeAdapters.Add(new AdapterPropertyValue
            {
                AttributeType           = AttributeType.String,
                FieldName               = "floorNames",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                AttributeName           = "floorNames",
                PropertyName            = "FloorNames",
                Api                     = "building",
                SupportsPatch           = true,
                NullValueRepresentation = NullValueRepresentation.EmptyString,
                CastForExport           = i => ((string)i)?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
                CastForImport           = i => i == null ? null : string.Join(",", ((IList <string>)i)),
                IsAnchor                = false
            });

            AdapterSubfield latitude = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "latitude",
                IsMultivalued           = false,
                Operation               = AttributeOperation.ImportExport,
                PropertyName            = "Latitude",
                AttributeNamePart       = "latitude",
                NullValueRepresentation = NullValueRepresentation.DoubleZero,
                CastForExport           = value =>
                {
                    if (value == null)
                    {
                        return(null);
                    }

                    return(double.Parse(value.ToString()));
                },
                CastForImport = value => ((double?)value)?.ToString("R")
            };

            AdapterSubfield longitude = new AdapterSubfield
            {
                AttributeType           = AttributeType.String,
                FieldName               = "longitude",
                IsMultivalued           = false,
                PropertyName            = "Longitude",
                Operation               = AttributeOperation.ImportExport,
                AttributeNamePart       = "longitude",
                NullValueRepresentation = NullValueRepresentation.DoubleZero,
                CastForExport           = value =>
                {
                    if (value == null)
                    {
                        return(null);
                    }

                    return(double.Parse(value.ToString()));
                },
                CastForImport = value => ((double?)value)?.ToString("R")
            };

            AdapterNestedType schemaItem = new AdapterNestedType
            {
                Api           = "building",
                AttributeName = "coordinates",
                Fields        = new List <AdapterSubfield>()
                {
                    latitude, longitude
                },
                FieldName     = "coordinates",
                PropertyName  = "Coordinates",
                SupportsPatch = false
            };

            type.AttributeAdapters.Add(schemaItem);

            yield return(type);
        }