private static SchemaType GetSchemaTypeGroup(IOktaClient client)
        {
            SchemaType      mmsType      = SchemaType.Create("group", true);
            SchemaAttribute mmsAttribute = SchemaAttribute.CreateAnchorAttribute("id", AttributeType.String, AttributeOperation.ImportOnly);

            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("created", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("lastUpdated", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("lastMembershipUpdated", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("type", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("name", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("description", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("member", AttributeType.Reference, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            return(mmsType);
        }
예제 #2
0
        public Schema GetMmsSchema()
        {
            Schema schema = Schema.Create();

            foreach (AcmaSchemaObjectClass schemaObject in ActiveConfig.DB.ObjectClassesBindingList)
            {
                SchemaType schemaType = SchemaType.Create(schemaObject.Name, true);
                schemaType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute("objectId", AttributeType.String, AttributeOperation.ImportOnly));

                foreach (AcmaSchemaAttribute attribute in schemaObject.Attributes.Where(t => t.Name != "objectId"))
                {
                    if (attribute.Operation == AcmaAttributeOperation.AcmaInternal || attribute.Operation == AcmaAttributeOperation.AcmaInternalTemp)
                    {
                        continue;
                    }

                    if (attribute.IsMultivalued)
                    {
                        schemaType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(attribute.Name, attribute.MmsType, attribute.MmsOperationType));
                    }
                    else
                    {
                        schemaType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(attribute.Name, attribute.MmsType, attribute.MmsOperationType));
                    }
                }

                schema.Types.Add(schemaType);
            }

            return(schema);
        }
        private static IEnumerable <SchemaAttribute> GetAttributesFromDefinition(IDictionary <string, object> definitions, string definitionName)
        {
            if (!definitions.ContainsKey(definitionName))
            {
                logger.Error($"The definition for type {definitionName} was not found in the response");
                yield break;
            }

            if (!(definitions[definitionName] is IDictionary <string, object> definitionObject))
            {
                logger.Info($"The definition for type {definitionName} was null");
                yield break;
            }

            if (!definitionObject.ContainsKey("properties"))
            {
                logger.Error($"The definition for type {definitionName} was did not contain any properties");
                yield break;
            }

            if (!(definitionObject["properties"] is IDictionary <string, object> properties))
            {
                logger.Info($"The properties definition for {definitionName} were missing");
                yield break;
            }

            foreach (KeyValuePair <string, object> property in properties)
            {
                string name = property.Key;

                if (!(property.Value is IDictionary <string, object> values))
                {
                    logger.Warn($"Missing value set for property {name}");
                    continue;
                }

                AttributeOperation operation = SchemaProvider.GetAttributeOperationFromMutability(values["mutability"].ToString());

                bool          ismultivalued = SchemaProvider.IsMultivalued(values);
                AttributeType type          = SchemaProvider.GetTypeForAttribute(values, ismultivalued);

                if (name == "managerId")
                {
                    type = AttributeType.Reference;
                }

                logger.Info($"Got attribute {name} of type {type} and is mv {ismultivalued}");

                if (ismultivalued)
                {
                    yield return(SchemaAttribute.CreateMultiValuedAttribute(name, type, operation));
                }
                else
                {
                    yield return(SchemaAttribute.CreateSingleValuedAttribute(name, type, operation));
                }
            }
        }
예제 #4
0
 public IEnumerable <SchemaAttribute> GetSchemaAttributes()
 {
     if (this.IsMultivalued)
     {
         yield return(SchemaAttribute.CreateMultiValuedAttribute(this.AttributeName, this.AttributeType, this.Operation));
     }
     else
     {
         yield return(SchemaAttribute.CreateSingleValuedAttribute(this.AttributeName, this.AttributeType, this.Operation));
     }
 }
예제 #5
0
        public SchemaAttribute GetSchemaAttribute(string prefix)
        {
            string attributeName = this.GetAttributeName(prefix);

            if (this.IsMultivalued)
            {
                return(SchemaAttribute.CreateMultiValuedAttribute(attributeName, this.AttributeType, this.Operation));
            }
            else
            {
                return(SchemaAttribute.CreateSingleValuedAttribute(attributeName, this.AttributeType, this.Operation));
            }
        }
        private static SchemaType GetSchemaTypeUser(IOktaClient client)
        {
            SchemaType      mmsType      = SchemaType.Create("user", true);
            SchemaAttribute mmsAttribute = SchemaAttribute.CreateAnchorAttribute("id", AttributeType.String, AttributeOperation.ImportOnly);

            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("status", AttributeType.String);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("created", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("activated", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("statusChanged", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("lastLogin", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("lastUpdated", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("passwordChanged", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("provider.type", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("provider.name", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("enrolledFactors", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("availableFactors", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("suspended", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            foreach (SchemaAttribute a in SchemaProvider.GetSchemaJson(client))
            {
                mmsType.Attributes.Add(a);
            }

            return(mmsType);
        }
 internal SchemaAttribute GetObject()
 {
     if (this.IsAnchor)
     {
         return(SchemaAttribute.CreateAnchorAttribute(this.Name, this.DataType, this.AllowedAttributeOperation));
     }
     else if (this.IsMultiValued)
     {
         return(SchemaAttribute.CreateMultiValuedAttribute(this.Name, this.DataType, this.AllowedAttributeOperation));
     }
     else
     {
         return(SchemaAttribute.CreateSingleValuedAttribute(this.Name, this.DataType, this.AllowedAttributeOperation));
     }
 }
예제 #8
0
        private static SchemaAttribute GetSchemaAttribute(string name, Type type)
        {
            SchemaAttribute schemaAttribute;
            bool            isMultivalued = typeof(IEnumerable).IsAssignableFrom(type);

            if (isMultivalued)
            {
                schemaAttribute = SchemaAttribute.CreateMultiValuedAttribute(name, GetSchemaAttributeType(type));
            }
            else
            {
                schemaAttribute = SchemaAttribute.CreateSingleValuedAttribute(name, GetSchemaAttributeType(type));
            }

            return(schemaAttribute);
        }
예제 #9
0
        public Schema GetSchema(KeyedCollection <string, ConfigParameter> configParameters)
        {
            Microsoft.MetadirectoryServices.SchemaType personType = Microsoft.MetadirectoryServices.SchemaType.Create("Person", false);

            this.GetMAConfig(configParameters);


            string[] rsaAttributes = new string[10];
            rsaAttributes[0] = "First Name";
            rsaAttributes[1] = "Last Name";
            rsaAttributes[2] = "Middle Name";
            rsaAttributes[3] = "User ID";
            rsaAttributes[4] = "Manager Email Address";
            rsaAttributes[5] = "Identity Source";
            rsaAttributes[6] = "Security Domain";
            rsaAttributes[7] = "Lockout Status";
            rsaAttributes[8] = "Token Serial Number";
            rsaAttributes[9] = "Token GUID";


            foreach (string attribName in rsaAttributes)
            {
                if (attribName == "User ID")
                {
                    personType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(attribName, AttributeType.String));
                }

                else if (attribName == "Token Serial Number" || attribName == "Token GUID")
                {
                    personType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(attribName, AttributeType.String));
                }

                else
                {
                    personType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(attribName, AttributeType.String));
                }
            }

            Schema schema = Schema.Create();

            schema.Types.Add(personType);

            return(schema);
        }
예제 #10
0
        /// <summary>
        /// Gets the schema that applies to the objects in this management agent
        /// </summary>
        /// <param name="configParameters">The configuration parameters supplied to this management agent</param>
        /// <returns>The Schema defining objects and attributes applicable to this management agent</returns>
        Schema IMAExtensible2GetSchema.GetSchema(KeyedCollection <string, ConfigParameter> configParameters)
        {
            try
            {
                ManagementAgent.MAParameters = new MAParameters(configParameters);
                Logger.LogPath = ManagementAgent.MAParameters.LogPath;
                Logger.WriteSeparatorLine('*');
                Logger.WriteLine("Loading Schema");

                MAConfig.Load(ManagementAgent.MAParameters.MAConfigurationFilePath);

                Schema schema = Schema.Create();

                foreach (MASchemaObject schemaObject in MASchema.Objects)
                {
                    SchemaType schemaType = SchemaType.Create(schemaObject.ObjectClass, true);
                    schemaType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute("entry-dn", AttributeType.String, AttributeOperation.ImportOnly));

                    foreach (MASchemaAttribute attribute in schemaObject.Attributes)
                    {
                        if (attribute.IsMultiValued)
                        {
                            schemaType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(attribute.Name, attribute.Type, attribute.Operation));
                        }
                        else
                        {
                            schemaType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(attribute.Name, attribute.Type, attribute.Operation));
                        }
                    }

                    schema.Types.Add(schemaType);
                }

                Logger.WriteLine("Schema loaded successfully");
                return(schema);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                throw new ExtensibleExtensionException("The schema could not be loaded: " + ex.Message, ex);
            }
        }
        private static SchemaType GetSchemaTypePrivateChannel()
        {
            SchemaType mmsType = SchemaType.Create("privateChannel", true);

            SchemaAttribute mmsAttribute = SchemaAttribute.CreateAnchorAttribute("id", AttributeType.String, AttributeOperation.ImportOnly);

            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateAnchorAttribute("teamid", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("description", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("displayName", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("email", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("webUrl", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("team", AttributeType.Reference, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("isFavoriteByDefault", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("member", AttributeType.Reference, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("owner", AttributeType.Reference, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            return(mmsType);
        }
예제 #12
0
        Schema IMAExtensible2GetSchema.GetSchema(KeyedCollection <string, ConfigParameter> configParameters)
        {
            Tracer.Enter("getschema");
            try
            {
                Schema schema = Schema.Create();
                InitializeConfigParameters(configParameters);

                OpenRunspace();
                Command cmd = new Command(Path.GetFullPath(SchemaScript));
                cmd.Parameters.Add(new CommandParameter("Username", Username));
                cmd.Parameters.Add(new CommandParameter("Password", Password));
                cmd.Parameters.Add(new CommandParameter("Credentials", GetSecureCredentials()));
                schemaResults = InvokePowerShellScript(cmd, null);
                CloseRunspace();

                if (schemaResults != null)
                {
                    foreach (PSObject obj in schemaResults)
                    {
                        string objectTypeName = null;
                        HashSet <AttributeDefinition> attrs = new HashSet <AttributeDefinition>();

                        foreach (PSPropertyInfo p in obj.Properties)
                        {
                            string[] elements = p.Name.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                            string   attrName = elements[0].Trim();
                            string   attrType = elements[1].Trim();

                            if (string.Equals(attrName, Constants.ControlValues.ObjectClass, StringComparison.OrdinalIgnoreCase))
                            {
                                objectTypeName = p.Value.ToString();
                                Tracer.TraceInformation("object-class '{0}'", objectTypeName);
                            }
                            else
                            {
                                AttributeDefinition ad = new AttributeDefinition();
                                ad.Name         = Regex.Replace(attrName, "^Anchor-", "", RegexOptions.IgnoreCase);
                                ad.IsAnchor     = p.Name.StartsWith("anchor-", StringComparison.OrdinalIgnoreCase);
                                ad.IsMultiValue = p.Name.EndsWith("[]", StringComparison.OrdinalIgnoreCase);
                                switch (attrType.Replace("[]", "").ToLower())
                                {
                                case "boolean":
                                    ad.Type = AttributeType.Boolean;
                                    break;

                                case "binary":
                                    ad.Type = AttributeType.Binary;
                                    break;

                                case "integer":
                                    ad.Type = AttributeType.Integer;
                                    break;

                                case "reference":
                                    ad.Type = AttributeType.Reference;
                                    break;

                                case "string":
                                    ad.Type = AttributeType.String;
                                    break;

                                default:
                                    ad.Type = AttributeType.String;
                                    break;
                                }
                                Tracer.TraceInformation("name '{0}', isanchor: {1}, ismultivalue: {2}, type: {3}", ad.Name, ad.IsAnchor, ad.IsMultiValue, ad.Type.ToString());
                                attrs.Add(ad);
                            }
                        }
                        if (string.IsNullOrEmpty(objectTypeName))
                        {
                            Tracer.TraceError("missing-object-class");
                            throw new Microsoft.MetadirectoryServices.NoSuchObjectTypeException();
                        }

                        SchemaType objectClass = SchemaType.Create(objectTypeName, true);
                        foreach (AttributeDefinition def in attrs)
                        {
                            if (def.IsAnchor)
                            {
                                objectClass.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(def.Name, def.Type));
                            }
                            else
                            {
                                if (def.IsMultiValue)
                                {
                                    objectClass.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(def.Name, def.Type));
                                }
                                else
                                {
                                    objectClass.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(def.Name, def.Type));
                                }
                            }
                        }
                        if (objectClass.AnchorAttributes.Count == 1)
                        {
                            schema.Types.Add(objectClass);
                        }
                        else
                        {
                            Tracer.TraceError("missing-anchor-definition-on-object");
                            throw new Microsoft.MetadirectoryServices.AttributeNotPresentException();
                        }
                    }
                }
                schemaResults.Clear();
                return(schema);
            }
            catch (Exception ex)
            {
                Tracer.TraceError("getschema", ex);
                throw;
            }
            finally
            {
                Tracer.Exit("getschema");
            }
        }
        private static SchemaType GetSchemaTypeTeam()
        {
            SchemaType mmsType = SchemaType.Create("team", true);

            //Group

            SchemaAttribute mmsAttribute = SchemaAttribute.CreateAnchorAttribute("id", AttributeType.String, AttributeOperation.ImportOnly);

            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("displayName", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("description", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("mailNickname", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("visibility", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            // Group member
            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("member", AttributeType.Reference, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateMultiValuedAttribute("owner", AttributeType.Reference, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            // Teams

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("webUrl", AttributeType.String, AttributeOperation.ImportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("isArchived", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("template", AttributeType.String, AttributeOperation.ExportOnly);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("memberSettings_allowCreateUpdateChannels", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("memberSettings_allowDeleteChannels", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("memberSettings_allowAddRemoveApps", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("memberSettings_allowCreateUpdateRemoveTabs", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("memberSettings_allowCreateUpdateRemoveConnectors", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("guestSettings_allowCreateUpdateChannels", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("guestSettings_allowDeleteChannels", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("messagingSettings_allowUserEditMessages", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("messagingSettings_allowUserDeleteMessages", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("messagingSettings_allowOwnerDeleteMessages", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("messagingSettings_allowTeamMentions", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("messagingSettings_allowChannelMentions", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("funSettings_allowGiphy", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("funSettings_giphyContentRating", AttributeType.String, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("funSettings_allowStickersAndMemes", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            mmsAttribute = SchemaAttribute.CreateSingleValuedAttribute("funSettings_allowCustomMemes", AttributeType.Boolean, AttributeOperation.ImportExport);
            mmsType.Attributes.Add(mmsAttribute);

            return(mmsType);
        }
예제 #14
0
        public Schema GetSchemaDetached()
        {
            Tracer.Enter(nameof(GetSchemaDetached));
            Schema schema = Schema.Create();

            try
            {
                using (SqlMethods methods = new SqlMethods())
                {
                    methods.OpenConnection();
                    List <string> objectClasses = new List <string>();

                    Tracer.TraceInformation($"objectclass-type {Configuration.ObjectClassType}");
                    if (Configuration.ObjectClassType == ObjectClassType.Column)
                    {
                        objectClasses = methods.GetObjectClasses().ToList(); //since we are using yield, we need to call ToList() to get results
                    }
                    else
                    {
                        objectClasses.Add(Configuration.ObjectClass);
                    }

                    List <AttributeDefinition> sva = new List <AttributeDefinition>();
                    sva = methods.GetSchema(Configuration.TableNameSingle).ToList(); //since we are using yield, we need to call ToList() to get results

                    List <AttributeDefinition> mva = new List <AttributeDefinition>();
                    if (Configuration.HasMultivalueTable)
                    {
                        mva = methods.GetSchema(Configuration.TableNameMulti).ToList(); //since we are using yield, we need to call ToList() to get results
                    }

                    foreach (string obj in objectClasses)
                    {
                        Tracer.TraceInformation($"start-object-class {obj}");
                        SchemaType schemaObj = SchemaType.Create(obj, true);

                        ObjectClass objectClass = Configuration.Schema.ObjectClasses.FirstOrDefault(c => c.Name.Equals(obj));
                        Tracer.TraceInformation($"found-schemaxml-information-for {obj}");

                        // single-values
                        Tracer.TraceInformation("start-detect-single-value-attributes");
                        List <string> excludeSv = Configuration.ReservedColumnNames.ToList();
                        foreach (AttributeDefinition ad in sva)
                        {
                            AttributeType attrType = ad.AttributeType;
                            if (objectClass != null)
                            {
                                if (objectClass.Excludes.Exists(x => x.Name.Equals(ad.Name)))
                                {
                                    Tracer.TraceInformation($"skipping-excluded-attribute {ad.Name}");
                                    continue;
                                }
                                attrType = GetAttributeOverride(objectClass, ad, attrType);
                            }
                            if (ad.Name.Equals(Configuration.AnchorColumn))
                            {
                                Tracer.TraceInformation($"adding-anchor name: {ad.Name}, type: {attrType} [{ad.AttributeOperation}]");
                                schemaObj.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(ad.Name, attrType));
                                continue;
                            }
                            if (excludeSv.Contains(ad.Name))
                            {
                                Tracer.TraceInformation($"skipping-reserved-column {ad.Name}");
                                continue;
                            }
                            Tracer.TraceInformation($"add-singlevalue name: {ad.Name}, type: {attrType} [{ad.AttributeOperation}]");
                            schemaObj.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(ad.Name, attrType, ad.AttributeOperation));
                        }
                        Tracer.TraceInformation("end-detect-single-value-attributes");

                        // multivalues
                        if (Configuration.HasMultivalueTable)
                        {
                            Tracer.TraceInformation("start-detect-multi-value-attributes");
                            foreach (AttributeDefinition ad in mva)
                            {
                                AttributeType attrType = ad.AttributeType;
                                if (objectClass != null)
                                {
                                    if (objectClass.Excludes.Exists(x => x.Name.Equals(ad.Name)))
                                    {
                                        Tracer.TraceInformation($"skipping-excluded-attribute {ad.Name}");
                                        continue;
                                    }
                                    attrType = GetAttributeOverride(objectClass, ad, attrType);
                                }
                                if (excludeSv.Contains(ad.Name))
                                {
                                    Tracer.TraceInformation($"skipping-reserved-column {ad.Name}");
                                    continue;
                                }
                                if (schemaObj.Attributes.Contains(ad.Name) || schemaObj.AnchorAttributes.Contains(ad.Name))
                                {
                                    Tracer.TraceInformation($"skipping-existing-column {ad.Name} (already defined in single-value-table)");
                                    continue;
                                }
                                Tracer.TraceInformation($"add-multivalue name: {ad.Name}, type: {attrType} [{ad.AttributeOperation}]");
                                schemaObj.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(ad.Name, attrType, ad.AttributeOperation));
                            }
                            Tracer.TraceInformation("end-detect-multi-value-attributes");
                        }

                        schema.Types.Add(schemaObj);
                        Tracer.TraceInformation($"end-object-class {obj}");
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.TraceError(nameof(GetSchemaDetached), ex);
                throw;
            }
            finally
            {
                Tracer.Exit(nameof(GetSchemaDetached));
            }
            return(schema);
        }
 public IEnumerable <SchemaAttribute> GetSchemaAttributes()
 {
     yield return(SchemaAttribute.CreateMultiValuedAttribute(this.AttributeName, this.AttributeType, this.Operation));
 }
예제 #16
0
        public Schema GetSchema(KeyedCollection <string, ConfigParameter> configParameters)
        {
            //TODO: Refactor object discover to a function
            Schema schema = Schema.Create();
            // person
            SchemaType personType = Microsoft.MetadirectoryServices.SchemaType.Create(CS_OBJECTTYPE_PERSON, false);

            PersonDiscoveryJsonTypes.Result personSchema = new PersonDiscoveryJsonTypes.Result();
            // movie
            SchemaType movieType = Microsoft.MetadirectoryServices.SchemaType.Create(CS_OBJECTTYPE_MOVIE, false);

            MovieDiscoveryJsonTypes.Result movieSchema = new MovieDiscoveryJsonTypes.Result();
            foreach (PropertyInfo item in personSchema)
            {
                if (item.Name.ToLower().Equals("id"))
                {
                    string itemName = string.Format("{0}_{1}", CS_OBJECTTYPE_PERSON, item.Name);
                    personType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(itemName, AttributeType.String));
                }
                else if (item.PropertyType.IsArray)
                {
                    switch (item.Name.ToLower())
                    {
                    case "known_for":
                        personType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(item.Name, AttributeType.Reference));
                        break;

                    default:
                        personType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(item.Name, AttributeType.String));
                        break;
                    }
                }
                else if (item.Name.ToLower().Equals("item"))
                {
                }
                else
                {
                    personType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(item.Name, AttributeType.String));
                }
            }

            foreach (PropertyInfo item in movieSchema)
            {
                if (item.Name.ToLower().Equals("id"))
                {
                    string itemName = string.Format("{0}_{1}", CS_OBJECTTYPE_MOVIE, item.Name);
                    movieType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(itemName, AttributeType.String));
                }
                else if (item.PropertyType.IsArray)
                {
                    switch (item.Name.ToLower())
                    {
                    default:
                        movieType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(item.Name, AttributeType.String));
                        break;
                    }
                }
                else if (item.Name.ToLower().Equals("item"))
                {
                }
                else
                {
                    movieType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(item.Name, AttributeType.String));
                }
            }

            schema.Types.Add(personType);
            schema.Types.Add(movieType);
            return(schema);
        }