示例#1
0
        internal static string GetSuggestedValueXmlFromSuggestedValueEntryList(ADSuggestedValueEntry[] claimValues, ADSuggestedValueType valueType)
        {
            XmlSerializer           xmlSerializer           = new XmlSerializer(typeof(PossibleClaimValuesType));
            PossibleClaimValuesType possibleClaimValuesType = new PossibleClaimValuesType();
            ADSuggestedValueType    aDSuggestedValueType    = valueType;

            if (aDSuggestedValueType == ADSuggestedValueType.Int64)
            {
                IntegerListType         integerListType            = new IntegerListType();
                List <IntegerItemType>  integerItemTypes           = new List <IntegerItemType>();
                ADSuggestedValueEntry[] aDSuggestedValueEntryArray = claimValues;
                for (int i = 0; i < (int)aDSuggestedValueEntryArray.Length; i++)
                {
                    ADSuggestedValueEntry aDSuggestedValueEntry = aDSuggestedValueEntryArray[i];
                    IntegerItemType       integerItemType       = new IntegerItemType();
                    integerItemType.Value            = Convert.ToInt64(aDSuggestedValueEntry.Value, CultureInfo.InvariantCulture);
                    integerItemType.ValueDescription = aDSuggestedValueEntry.ValueDescription;
                    integerItemType.ValueDisplayName = aDSuggestedValueEntry.ValueDisplayName;
                    integerItemType.ValueGUID        = aDSuggestedValueEntry.ValueGUID;
                    integerItemTypes.Add(integerItemType);
                }
                integerListType.Item         = integerItemTypes.ToArray();
                possibleClaimValuesType.Item = integerListType;
            }
            else if (aDSuggestedValueType == ADSuggestedValueType.UInt64)
            {
                UnsignedIntegerListType        unsignedIntegerListType     = new UnsignedIntegerListType();
                List <UnsignedIntegerItemType> unsignedIntegerItemTypes    = new List <UnsignedIntegerItemType>();
                ADSuggestedValueEntry[]        aDSuggestedValueEntryArray1 = claimValues;
                for (int j = 0; j < (int)aDSuggestedValueEntryArray1.Length; j++)
                {
                    ADSuggestedValueEntry   aDSuggestedValueEntry1  = aDSuggestedValueEntryArray1[j];
                    UnsignedIntegerItemType unsignedIntegerItemType = new UnsignedIntegerItemType();
                    unsignedIntegerItemType.Value            = Convert.ToUInt64(aDSuggestedValueEntry1.Value, CultureInfo.InvariantCulture);
                    unsignedIntegerItemType.ValueDescription = aDSuggestedValueEntry1.ValueDescription;
                    unsignedIntegerItemType.ValueDisplayName = aDSuggestedValueEntry1.ValueDisplayName;
                    unsignedIntegerItemType.ValueGUID        = aDSuggestedValueEntry1.ValueGUID;
                    unsignedIntegerItemTypes.Add(unsignedIntegerItemType);
                }
                unsignedIntegerListType.Item = unsignedIntegerItemTypes.ToArray();
                possibleClaimValuesType.Item = unsignedIntegerListType;
            }
            else if (aDSuggestedValueType == ADSuggestedValueType.String)
            {
                StringListType          stringListType              = new StringListType();
                List <StringItemType>   stringItemTypes             = new List <StringItemType>();
                ADSuggestedValueEntry[] aDSuggestedValueEntryArray2 = claimValues;
                for (int k = 0; k < (int)aDSuggestedValueEntryArray2.Length; k++)
                {
                    ADSuggestedValueEntry aDSuggestedValueEntry2 = aDSuggestedValueEntryArray2[k];
                    StringItemType        stringItemType         = new StringItemType();
                    stringItemType.Value            = (string)aDSuggestedValueEntry2.Value;
                    stringItemType.ValueDescription = aDSuggestedValueEntry2.ValueDescription;
                    stringItemType.ValueDisplayName = aDSuggestedValueEntry2.ValueDisplayName;
                    stringItemType.ValueGUID        = aDSuggestedValueEntry2.ValueGUID;
                    stringItemTypes.Add(stringItemType);
                }
                stringListType.Item          = stringItemTypes.ToArray();
                possibleClaimValuesType.Item = stringListType;
            }
            else
            {
                throw new ADException("Unable to create Suggested Values Xml for the given Claim Type");
            }
            StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture);

            xmlSerializer.Serialize(stringWriter, possibleClaimValuesType);
            return(stringWriter.ToString());
        }
示例#2
0
        internal static List <ADSuggestedValueEntry> ConvertSuggestedValueXmlToSuggestedValueEntryList(string suggestedValuesXmlBlob, out bool hasUnknownElements)
        {
            ADCBACUtil.VerifyADSuggestedValuesXml(suggestedValuesXmlBlob);
            List <ADSuggestedValueEntry> aDSuggestedValueEntries = new List <ADSuggestedValueEntry>();

            hasUnknownElements = false;
            XmlSerializer           xmlSerializer           = new XmlSerializer(typeof(PossibleClaimValuesType));
            PossibleClaimValuesType possibleClaimValuesType = (PossibleClaimValuesType)xmlSerializer.Deserialize(new StringReader(suggestedValuesXmlBlob));

            if (possibleClaimValuesType.Item as StringListType == null)
            {
                if (possibleClaimValuesType.Item as IntegerListType == null)
                {
                    if (possibleClaimValuesType.Item as UnsignedIntegerListType == null)
                    {
                        hasUnknownElements = true;
                    }
                    else
                    {
                        UnsignedIntegerListType   item = (UnsignedIntegerListType)possibleClaimValuesType.Item;
                        UnsignedIntegerItemType[] unsignedIntegerItemTypeArray = item.Item;
                        for (int i = 0; i < (int)unsignedIntegerItemTypeArray.Length; i++)
                        {
                            UnsignedIntegerItemType unsignedIntegerItemType = unsignedIntegerItemTypeArray[i];
                            ADSuggestedValueEntry   aDSuggestedValueEntry   = new ADSuggestedValueEntry((object)unsignedIntegerItemType.Value, unsignedIntegerItemType.ValueDisplayName, unsignedIntegerItemType.ValueDescription, unsignedIntegerItemType.ValueGUID);
                            aDSuggestedValueEntries.Add(aDSuggestedValueEntry);
                            if (unsignedIntegerItemType.Any != null)
                            {
                                hasUnknownElements = true;
                            }
                        }
                    }
                }
                else
                {
                    IntegerListType   integerListType      = (IntegerListType)possibleClaimValuesType.Item;
                    IntegerItemType[] integerItemTypeArray = integerListType.Item;
                    for (int j = 0; j < (int)integerItemTypeArray.Length; j++)
                    {
                        IntegerItemType       integerItemType        = integerItemTypeArray[j];
                        ADSuggestedValueEntry aDSuggestedValueEntry1 = new ADSuggestedValueEntry((object)integerItemType.Value, integerItemType.ValueDisplayName, integerItemType.ValueDescription, integerItemType.ValueGUID);
                        aDSuggestedValueEntries.Add(aDSuggestedValueEntry1);
                        if (integerItemType.Any != null)
                        {
                            hasUnknownElements = true;
                        }
                    }
                }
            }
            else
            {
                StringListType   stringListType      = (StringListType)possibleClaimValuesType.Item;
                StringItemType[] stringItemTypeArray = stringListType.Item;
                for (int k = 0; k < (int)stringItemTypeArray.Length; k++)
                {
                    StringItemType        stringItemType         = stringItemTypeArray[k];
                    ADSuggestedValueEntry aDSuggestedValueEntry2 = new ADSuggestedValueEntry(stringItemType.Value, stringItemType.ValueDisplayName, stringItemType.ValueDescription, stringItemType.ValueGUID);
                    aDSuggestedValueEntries.Add(aDSuggestedValueEntry2);
                    if (stringItemType.Any != null)
                    {
                        hasUnknownElements = true;
                    }
                }
            }
            return(aDSuggestedValueEntries);
        }