internal static object QuotaSettingGetter(ADPropertyDefinition adPropertyDefinition, IPropertyBag propertyBag)
        {
            if (adPropertyDefinition == null)
            {
                throw new ArgumentNullException("adPropertyDefinition");
            }
            MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[DataClassificationConfigSchema.DataClassificationConfigQuotaSettings];
            string quotaSettingIdentifier = adPropertyDefinition.Name + ':';
            object result = adPropertyDefinition.DefaultValue;

            if (multiValuedProperty != null && multiValuedProperty.Count > 0)
            {
                string text = multiValuedProperty.FirstOrDefault((string item) => item.StartsWith(quotaSettingIdentifier, StringComparison.Ordinal));
                if (!string.IsNullOrEmpty(text))
                {
                    try
                    {
                        result = ValueConvertor.ConvertValueFromString(text.Substring(quotaSettingIdentifier.Length), adPropertyDefinition.Type, null);
                    }
                    catch (FormatException ex)
                    {
                        PropertyValidationError error = new PropertyValidationError(DirectoryStrings.CannotCalculateProperty(adPropertyDefinition.Name, ex.Message), adPropertyDefinition, propertyBag[DataClassificationConfigSchema.DataClassificationConfigQuotaSettings]);
                        throw new DataValidationException(error, ex);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        object ICustomTextConverter.Parse(Type resultType, string s, IFormatProvider provider)
        {
            if (resultType == null)
            {
                throw new ArgumentNullException("resultType");
            }
            s = (s ?? string.Empty);
            object obj = this.PreParseObject(resultType, s, provider);

            if (obj != null && obj.GetType() != resultType)
            {
                if (obj.GetType() == typeof(string))
                {
                    obj = this.ParseObject((string)obj, provider);
                }
                if (obj != null && obj.GetType() != resultType)
                {
                    try
                    {
                        obj = ValueConvertor.ConvertValue(obj, resultType, provider);
                    }
                    catch (NotImplementedException)
                    {
                    }
                }
            }
            return(obj);
        }
        internal static void QuotaSettingSetter(ADPropertyDefinition adPropertyDefinition, object quota, IPropertyBag propertyBag)
        {
            if (adPropertyDefinition == null)
            {
                throw new ArgumentNullException("adPropertyDefinition");
            }
            MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[DataClassificationConfigSchema.DataClassificationConfigQuotaSettings];
            string text = adPropertyDefinition.Name + ':';

            if (multiValuedProperty != null && multiValuedProperty.Count != 0)
            {
                for (int i = multiValuedProperty.Count - 1; i >= 0; i--)
                {
                    if (string.IsNullOrEmpty(multiValuedProperty[i]) || multiValuedProperty[i].StartsWith(text, StringComparison.Ordinal))
                    {
                        multiValuedProperty.RemoveAt(i);
                    }
                }
            }
            if (!object.Equals(quota, adPropertyDefinition.DefaultValue))
            {
                string arg  = ValueConvertor.ConvertValueToString(quota, null);
                string item = string.Format("{0}{1}", text, arg);
                multiValuedProperty.Add(item);
            }
            propertyBag[DataClassificationConfigSchema.DataClassificationConfigQuotaSettings] = multiValuedProperty;
        }
Exemplo n.º 4
0
 internal static bool TryCreateGenericMultiValuedProperty(ProviderPropertyDefinition propertyDefinition, bool createAsReadOnly, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage, out MultiValuedPropertyBase mvp)
 {
     mvp = null;
     if (propertyDefinition.Type == typeof(MigrationBatchError))
     {
         mvp = new MultiValuedProperty <MigrationBatchError>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     if (propertyDefinition.Type == typeof(MigrationError))
     {
         mvp = new MultiValuedProperty <MigrationError>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     if (propertyDefinition.Type == typeof(MigrationUserSkippedItem))
     {
         mvp = new MultiValuedProperty <MigrationUserSkippedItem>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     if (propertyDefinition.Type == typeof(MigrationReportSet))
     {
         mvp = new MultiValuedProperty <MigrationReportSet>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     if (propertyDefinition.Type == typeof(E164Number))
     {
         mvp = new MultiValuedProperty <E164Number>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     if (propertyDefinition.Type == typeof(ADObjectId))
     {
         mvp = new MultiValuedProperty <ADObjectId>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     if (propertyDefinition.Type == typeof(ADRecipientOrAddress))
     {
         mvp = new MultiValuedProperty <ADRecipientOrAddress>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     return(mvp != null || ValueConvertor.TryCreateGenericMultiValuedProperty(propertyDefinition, createAsReadOnly, values, invalidValues, readOnlyErrorMessage, out mvp));
 }
Exemplo n.º 5
0
        private static void FillDataToCollection(XmlReader reader, object objectData, Dictionary <string, Type> typeMapping, Type elementType, Type parentType)
        {
            const string addMethodName = "Add";
            int          currentDepth  = reader.Depth;
            bool         isValueType   = elementType.IsValueType || typeof(string).Equals(elementType) || elementType.IsEnum;
//            Type genericType = rawType.GetGenericArguments()[0];
            Type       genericType = ModuleUtils.GetRawGenericElementType(parentType);
            MethodInfo addMethod   = parentType.GetMethod(addMethodName, BindingFlags.Instance | BindingFlags.Public, null,
                                                          CallingConventions.Standard, new Type[] { genericType }, new ParameterModifier[0]);
            GenericCollectionAttribute collectionAttribute =
                elementType.GetCustomAttribute <GenericCollectionAttribute>();

            reader.Read();
            // xml层级等于或者小于父节点时说明集合已经遍历结束,停止遍历
            // Reader的更新在Read
            while (reader.Depth > currentDepth)
            {
                // 如果不是节点或者是空节点或者是结束节点,则继续下一行读取
                if (reader.NodeType != XmlNodeType.Element || (reader.IsEmptyElement && !reader.HasAttributes) ||
                    reader.NodeType == XmlNodeType.EndElement)
                {
                    bool readNotOver = reader.Read();
                    if (!readNotOver)
                    {
                        return;
                    }
                    continue;
                }
                if (isValueType)
                {
                    string value = reader.GetAttribute(Constants.ValueTypeName);
                    if (null != value)
                    {
                        object element = ValueConvertor.ReadData(elementType, value);
                        addMethod.Invoke(objectData, new object[] { element });
                    }
                    // Value模式时需要手动去调整reader的位置
                    reader.Read();
                }
                else
                {
                    // 填充集合或者类时,reader的shift在FillDataToObject和FillDataToCollection中调用
                    object element = CreateTypeInstance(typeMapping, GetTypeName(elementType));
                    if (null == collectionAttribute)
                    {
                        FillDataToObject(reader, element, typeMapping);
                    }
                    else
                    {
                        FillDataToCollection(reader, element, typeMapping, collectionAttribute.GenericType, genericType);
                    }
                    addMethod.Invoke(objectData, new object[] { element });
                }
            }
            // 如果是endElement则直接跳过
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                reader.Read();
            }
        }
Exemplo n.º 6
0
        internal void SetCmdletProperty(object ffoTask, object value)
        {
            PropertyInfo property = ffoTask.GetType().GetProperty(this.propertyName);

            if (property == null)
            {
                throw new NullReferenceException("Property does not exist.");
            }
            if (typeof(IList).IsAssignableFrom(property.PropertyType))
            {
                IList list = ODataInput.ConvertToList(value);
                if (list == null || list.Count <= 0)
                {
                    return;
                }
                IList list2 = (IList)property.GetValue(ffoTask, null);
                list2.Clear();
                using (IEnumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        object value2 = enumerator.Current;
                        list2.Add(value2);
                    }
                    return;
                }
            }
            object value3 = ValueConvertor.ConvertValue(value, property.PropertyType, null);

            property.SetValue(ffoTask, value3);
        }
Exemplo n.º 7
0
        private static ICollection ConvertValue(object value, ArrayList newValues)
        {
            if (newValues == null)
            {
                newValues = new ArrayList();
            }
            ApprovedApplication approvedApplication = (ApprovedApplication)ValueConvertor.ConvertValue(value, typeof(ApprovedApplication), null);

            if (approvedApplication != null)
            {
                if (approvedApplication.IsCab)
                {
                    MultiValuedProperty <ApprovedApplication> multiValuedProperty = ApprovedApplication.ParseCab(approvedApplication.CabName);
                    using (MultiValuedProperty <ApprovedApplication> .Enumerator enumerator = multiValuedProperty.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ApprovedApplication value2 = enumerator.Current;
                            newValues.Add(value2);
                        }
                        return(newValues);
                    }
                }
                newValues.Add(value);
                return(newValues);
            }
            throw new DataValidationException(new PropertyValidationError(DirectoryStrings.ExceptionInvalidApprovedApplication(value.ToString()), MobileMailboxPolicySchema.ADApprovedApplicationList, value));
        }
 private void OnSerializing(StreamingContext context)
 {
     if (null != this.securityIdentifier)
     {
         this.binarySecurityIdentifier = ValueConvertor.ConvertValueToBinary(this.securityIdentifier, null);
     }
 }
 private void OnDeserialized(StreamingContext context)
 {
     if (this.binarySecurityIdentifier != null)
     {
         this.securityIdentifier       = (SecurityIdentifier)ValueConvertor.ConvertValueFromBinary(this.binarySecurityIdentifier, typeof(SecurityIdentifier), null);
         this.binarySecurityIdentifier = null;
     }
 }
Exemplo n.º 10
0
        private void ValueFromTask(object reportingObject, PropertyInfo property, object dalObject, object task)
        {
            Type   type   = task.GetType();
            object value  = type.GetProperty(this.dalPropertyName).GetValue(task, null);
            object value2 = ValueConvertor.ConvertValue(value, property.PropertyType, null);

            property.SetValue(reportingObject, value2, null);
        }
Exemplo n.º 11
0
        private object PreParseObject(Type resultType, string s, IFormatProvider formatProvider)
        {
            object result = s;

            if (typeof(IList).IsAssignableFrom(resultType))
            {
                throw new NotSupportedException();
            }
            if (resultType.IsGenericType)
            {
                Type type = resultType.GetGenericArguments()[0];
                if (resultType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Unlimited <>))
                    {
                        resultType = type;
                        type       = resultType.GetGenericArguments()[0];
                    }
                    else if (string.IsNullOrEmpty(s))
                    {
                        result = null;
                    }
                    else
                    {
                        result = ValueConvertor.ConvertValue(this.Parse(type, s, formatProvider), resultType, formatProvider);
                    }
                }
                if (resultType.GetGenericTypeDefinition() == typeof(Unlimited <>))
                {
                    if (string.Compare(Strings.UnlimitedString.ToString(), s) == 0)
                    {
                        result = TextConverter.GetPropertyValue(resultType, null, "UnlimitedValue");
                    }
                    else
                    {
                        result = ValueConvertor.ConvertValue(this.Parse(type, s, formatProvider), resultType, formatProvider);
                    }
                }
            }
            else if (resultType == typeof(bool) && s != null)
            {
                bool flag;
                if (bool.TryParse(s, out flag))
                {
                    result = flag;
                }
                else if (string.Compare(s, Strings.TrueString) == 0)
                {
                    result = true;
                }
                else if (string.Compare(s, Strings.FalseString) == 0)
                {
                    result = false;
                }
            }
            return(result);
        }
 // Token: 0x06000E80 RID: 3712 RVA: 0x00045B76 File Offset: 0x00043D76
 internal static bool TryCreateGenericMultiValuedProperty(ProviderPropertyDefinition propertyDefinition, bool createAsReadOnly, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage, out MultiValuedPropertyBase mvp)
 {
     mvp = null;
     if (propertyDefinition.Type == typeof(ADObjectId))
     {
         mvp = new MultiValuedProperty <ADObjectId>(createAsReadOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage);
     }
     return(mvp != null || ValueConvertor.TryCreateGenericMultiValuedProperty(propertyDefinition, createAsReadOnly, values, invalidValues, readOnlyErrorMessage, out mvp));
 }
Exemplo n.º 13
0
        public override string ToJavaScript(IControlResolver resolver)
        {
            object obj = this.Value ?? this.DefaultValue;

            if (this.TargetType != null)
            {
                obj = ValueConvertor.ConvertValue(obj, this.TargetType, null);
            }
            return(string.Format("new StaticBinding({0})", obj.ToJsonString(null)));
        }
Exemplo n.º 14
0
            public object Validate(string propertyValue)
            {
                object    result;
                Exception innerException;

                if (!ValueConvertor.TryConvertValueFromString(propertyValue, base.Type, null, out result, out innerException))
                {
                    throw new ArgumentException("Invalid property", base.Name, innerException);
                }
                return(result);
            }
Exemplo n.º 15
0
        private static byte[] CalculateEffectiveId(IGenericADUser adUser)
        {
            byte[]             result             = null;
            SecurityIdentifier securityIdentifier = IdentityHelper.CalculateEffectiveSid(adUser.Sid, adUser.MasterAccountSid);

            if (securityIdentifier != null)
            {
                result = ValueConvertor.ConvertValueToBinary(securityIdentifier, null);
            }
            return(result);
        }
 public bool TryCalculateOnSave(ICorePropertyBag itemPropertyBag, ConversationIndex.FixupStage stage, ConversationIndex conversationIndex, CoreItemOperation operation, out byte[] conversationCreatorSid)
 {
     conversationCreatorSid = null;
     if (operation != CoreItemOperation.Save)
     {
         return(false);
     }
     byte[] itemOwnerSid = ValueConvertor.ConvertValueToBinary(this.mailboxSession.MailboxOwner.Sid, null);
     ConversationCreatorSidCalculator.MessageType messageType = this.CalculateMessageTypeOnSave(stage);
     return(this.TryCalculateConversationCreatorSid(conversationIndex, messageType, itemOwnerSid, out conversationCreatorSid));
 }
        public LogicalValue Resolve(Value source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options, bool forInheritance)
        {
#if DEBUG
            //Log($"source = {source}");
#endif

            var sourceKind = source.KindOfValue;

            switch (sourceKind)
            {
            case KindOfValue.NullValue:
                return(ValueConvertor.ConvertNullValueToLogicalValue(source.AsNullValue, _context));

            case KindOfValue.LogicalValue:
                return(source.AsLogicalValue);

            case KindOfValue.NumberValue:
                return(ValueConvertor.ConvertNumberValueToLogicalValue(source.AsNumberValue, _context));

            case KindOfValue.StrongIdentifierValue:
            {
                ReasonOfFuzzyLogicResolving reasonOfFuzzyLogicResolving = null;

                if (forInheritance)
                {
                    reasonOfFuzzyLogicResolving = new ReasonOfFuzzyLogicResolving()
                    {
                        Kind = KindOfReasonOfFuzzyLogicResolving.Inheritance
                    };
                }

                return(ValueConvertor.ConvertNumberValueToLogicalValue(_context.DataResolversFactory.GetFuzzyLogicResolver().Resolve(source.AsStrongIdentifierValue, reasonOfFuzzyLogicResolving, localCodeExecutionContext, options), _context));
            }


            case KindOfValue.FuzzyLogicNonNumericSequenceValue:
            {
                ReasonOfFuzzyLogicResolving reasonOfFuzzyLogicResolving = null;

                if (forInheritance)
                {
                    reasonOfFuzzyLogicResolving = new ReasonOfFuzzyLogicResolving()
                    {
                        Kind = KindOfReasonOfFuzzyLogicResolving.Inheritance
                    };
                }

                return(ValueConvertor.ConvertNumberValueToLogicalValue(_context.DataResolversFactory.GetFuzzyLogicResolver().Resolve(source.AsFuzzyLogicNonNumericSequenceValue, reasonOfFuzzyLogicResolving, localCodeExecutionContext, options), _context));
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }
        }
Exemplo n.º 18
0
        public override string ToString()
        {
            NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(string.Empty);

            foreach (object obj in this.propertyBag.Keys)
            {
                string text = (string)obj;
                object obj2 = this.propertyBag[text];
                if (obj2 != null)
                {
                    nameValueCollection[text] = ValueConvertor.ConvertValueToString(obj2, null);
                }
            }
            return(Convert.ToBase64String(Encoding.UTF8.GetBytes(nameValueCollection.ToString())));
        }
Exemplo n.º 19
0
        public MultiValuedProperty(Dictionary <string, object> table) : this(false, true, null, new T[0], null, null)
        {
            this.isChangesOnlyCopy = true;
            bool copyChangesOnly = base.CopyChangesOnly;

            base.CopyChangesOnly = true;
            foreach (string text in table.Keys)
            {
                object values = ValueConvertor.UnwrapPSObjectIfNeeded(table[text]);
                if (!this.TryAddValues(text, values) && !this.TryRemoveValues(text, values))
                {
                    throw new NotSupportedException(DataStrings.ErrorUnknownOperation(text, MultiValuedProperty <T> .ArrayToString(MultiValuedProperty <T> .AddKeys), MultiValuedProperty <T> .ArrayToString(MultiValuedProperty <T> .RemoveKeys)));
                }
            }
            base.CopyChangesOnly = copyChangesOnly;
            this.isReadOnly      = true;
        }
        internal static object ConvertValueToStore(EwsStoreObjectPropertyDefinition property, object originalValue)
        {
            if (originalValue == null)
            {
                return(null);
            }
            Type type = originalValue.GetType();

            if (type == typeof(ADRecipientOrAddress))
            {
                ADRecipientOrAddress adrecipientOrAddress = (ADRecipientOrAddress)originalValue;
                return(new EmailAddress(adrecipientOrAddress.DisplayName, adrecipientOrAddress.Address, adrecipientOrAddress.RoutingType));
            }
            if (type == typeof(MultiValuedProperty <ADRecipientOrAddress>))
            {
                return((from x in (MultiValuedProperty <ADRecipientOrAddress>) originalValue
                        select x.Address).ToArray <string>());
            }
            if (type == typeof(AuditLogSearchId))
            {
                return(((AuditLogSearchId)originalValue).Guid);
            }
            if (type == typeof(ADObjectId) && property.StorePropertyDefinition.Type == typeof(byte[]))
            {
                return(((ADObjectId)originalValue).GetBytes());
            }
            if (type == typeof(MultiValuedProperty <ADObjectId>) && property.IsMultivalued && property.StorePropertyDefinition is ExtendedPropertyDefinition && ((ExtendedPropertyDefinition)property.StorePropertyDefinition).MapiType == 3)
            {
                return((from x in (MultiValuedProperty <ADObjectId>) originalValue
                        select x.GetBytes()).ToArray <byte[]>());
            }
            if (type != typeof(byte[]) && property.StorePropertyDefinition.Type == typeof(byte[]))
            {
                return(EwsStoreValueConverter.SerializeToBinary(originalValue));
            }
            if (!(property.StorePropertyDefinition.Type == typeof(PolicyTag)))
            {
                return(ValueConvertor.ConvertValue(StoreValueConverter.ConvertValueToStore(originalValue), EwsStoreValueConverter.GetStorePropertyDefinitionActualType(property), null));
            }
            if ((Guid?)originalValue == null)
            {
                return(null);
            }
            return(new PolicyTag(true, (Guid)originalValue));
        }
Exemplo n.º 21
0
        private T ObjectFromItem <T>(Item item) where T : IConfigurable, new()
        {
            EwsStoreObject        ewsStoreObject  = (EwsStoreObject)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T)));
            object                originalValue   = null;
            ExchangeObjectVersion exchangeVersion = (ExchangeObjectVersion)EwsStoreObjectSchema.ExchangeVersion.DefaultValue;

            if (item.TryGetProperty(EwsStoreObjectSchema.ExchangeVersion.StorePropertyDefinition, ref originalValue))
            {
                exchangeVersion = (ExchangeObjectVersion)ValueConvertor.ConvertValue(originalValue, typeof(ExchangeObjectVersion), null);
                ewsStoreObject.SetExchangeVersion(exchangeVersion);
                if (ewsStoreObject.ExchangeVersion.Major > ewsStoreObject.MaximumSupportedExchangeObjectVersion.Major)
                {
                    ExTraceGlobals.StorageTracer.TraceWarning <ItemId, byte, byte>(0L, "{0} has major version {1} which is greater than current one ({2}) and will be ignored", item.Id, ewsStoreObject.ExchangeVersion.Major, ewsStoreObject.MaximumSupportedExchangeObjectVersion.Major);
                    return(default(T));
                }
            }
            if (!string.IsNullOrEmpty(ewsStoreObject.ItemClass) && !ewsStoreObject.ItemClass.Equals(item.ItemClass, StringComparison.OrdinalIgnoreCase))
            {
                return(default(T));
            }
            ewsStoreObject.CopyFromItemObject(item, this.RequestedServerVersion);
            if (ewsStoreObject.MaximumSupportedExchangeObjectVersion.IsOlderThan(ewsStoreObject.ExchangeVersion))
            {
                ExTraceGlobals.StorageTracer.TraceWarning <ItemId, ExchangeObjectVersion, ExchangeObjectVersion>(0L, "{0} has version {1} which is greater than current one ({2}) and will be read-only", item.Id, ewsStoreObject.ExchangeVersion, ewsStoreObject.MaximumSupportedExchangeObjectVersion);
                ewsStoreObject.SetIsReadOnly(true);
            }
            ValidationError[] array = ewsStoreObject.ValidateRead();
            ewsStoreObject.ResetChangeTracking(true);
            if (array.Length > 0)
            {
                foreach (ValidationError validationError in array)
                {
                    PropertyValidationError propertyValidationError = validationError as PropertyValidationError;
                    ExTraceGlobals.StorageTracer.TraceDebug((long)this.GetHashCode(), "Object '{0}' read from '{1}' failed validation. Attribute: '{2}'. Invalid data: '{3}'. Error message: '{4}'.", new object[]
                    {
                        ewsStoreObject.Identity,
                        this.Mailbox.ToString() + "\\" + this.DefaultFolder.ToString(),
                        (propertyValidationError != null) ? propertyValidationError.PropertyDefinition.Name : "<null>",
                        (propertyValidationError != null) ? (propertyValidationError.InvalidData ?? "<null>") : "<null>",
                        validationError.Description
                    });
                }
            }
            return((T)((object)this.FilterObject(ewsStoreObject)));
        }
Exemplo n.º 22
0
        private static void FillValueToObject(PropertyInfo propertyInfo, object objectData, string attribute)
        {
            Type   propertyType = propertyInfo.PropertyType;
            object value        = null;

            if (propertyType.IsEnum)
            {
                value = EnumConvertor.ReadData(propertyType, attribute);
            }
            else
            {
                value = ValueConvertor.ReadData(propertyType, attribute);
            }
            if (null != value)
            {
                propertyInfo.SetValue(objectData, value);
            }
        }
        public string GenerateTypeScript(IEnumerable <Type> types)
        {
            var typeDefinitions = types
                                  .ResolveRelations()
                                  .ResolveConfigs()
                                  .ResolveNames()
                                  .ResolveDuplications();

            var processDefinitions = typeDefinitions.Where(x => x.ProcessConfig?.OutputType != OutputType.None);

            var nameConvertor  = new NameConvertor(typeDefinitions);
            var valueConvertor = new ValueConvertor(typeDefinitions, nameConvertor);

            var codeGeneratorFactory = new CodeGeneratorFactory(nameConvertor, valueConvertor);
            var codeBuilder          = new StringBuilder();

            var pluralizationBuilder = new PluralizationApiBuilder();

            pluralizationBuilder.AddEnglishProvider();

            var pluralizationApi = pluralizationBuilder.Build();
            var cultureInfo      = new CultureInfo("en-US");

            codeBuilder.Append(_assemblyHelper.GetAssemblyContent());

            Enum.GetValues(typeof(OutputType)).Cast <OutputType>().ToList()
            .ForEach(x =>
            {
                var codeGenerator = codeGeneratorFactory.GetInstance(x);
                if (codeGenerator != null)
                {
                    var sectionName = pluralizationApi.Pluralize(x.ToString(), cultureInfo);
                    codeBuilder.Append(_assemblyHelper.GetSectionSeparator(sectionName));

                    processDefinitions.GetProcessingTypes(x).ForEach(t =>
                                                                     codeBuilder.AppendLine(codeGenerator.Generate(t))
                                                                     );
                }
            });

            return(codeBuilder.ToString());
        }
Exemplo n.º 24
0
        public SerializableMap(SerializationInfo info, StreamingContext context)
        {
            this._innerCollection = new Dictionary <TKey, TValue>(UtilityConstants.DefaultEntityCount);
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                TKey key;
                Type keyType = typeof(TKey);
                if (keyType.IsEnum)
                {
                    key = (TKey)EnumConvertor.ReadData(keyType, enumerator.Name);
                }
                else
                {
                    key = (TKey)ValueConvertor.ReadData(keyType, enumerator.Name);
                }
                this._innerCollection.Add(key, (TValue)enumerator.Value);
            }
        }
Exemplo n.º 25
0
        public static object ConvertFromString(string item, PropertyDefinition definition)
        {
            ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)definition;

            if (providerPropertyDefinition.IsMultivalued && !string.IsNullOrEmpty(item))
            {
                List <object> list = new List <object>();
                int           num  = 0;
                do
                {
                    int num2 = item.IndexOf("|", num);
                    int num3 = int.Parse(item.Substring(num, num2 - num));
                    num2++;
                    string item2 = item.Substring(num2, num3);
                    num = num2 + num3;
                    list.Add(SearchHelper.ConvertFromString(item2, definition.Type));
                }while (num < item.Length);
                return(ValueConvertor.CreateGenericMultiValuedProperty(providerPropertyDefinition, false, list, null, null));
            }
            return(SearchHelper.ConvertFromString(item, definition.Type));
        }
Exemplo n.º 26
0
        private void ReadObject(string folderPath, string folderName, ref RegistryObject instance)
        {
            RegistryObjectSchema registrySchema = instance.RegistrySchema;

            using (RegistryKey registryKey = this.RootKey.OpenSubKey(folderPath))
            {
                if (registryKey == null || !registryKey.GetSubKeyNames().Contains(folderName, StringComparer.OrdinalIgnoreCase))
                {
                    return;
                }
                foreach (PropertyDefinition propertyDefinition in registrySchema.AllProperties)
                {
                    SimpleProviderPropertyDefinition simpleProviderPropertyDefinition = (SimpleProviderPropertyDefinition)propertyDefinition;
                    if (!simpleProviderPropertyDefinition.IsCalculated && !this.excludedPersistentProperties.Contains(simpleProviderPropertyDefinition))
                    {
                        object obj = RegistryReader.Instance.GetValue <object>(registryKey, folderName, simpleProviderPropertyDefinition.Name, simpleProviderPropertyDefinition.DefaultValue);
                        try
                        {
                            obj = ValueConvertor.ConvertValue(obj, simpleProviderPropertyDefinition.Type, null);
                        }
                        catch (Exception ex)
                        {
                            instance.AddValidationError(new PropertyValidationError(DataStrings.ErrorCannotConvertFromString(obj as string, simpleProviderPropertyDefinition.Type.Name, ex.Message), simpleProviderPropertyDefinition, obj));
                            continue;
                        }
                        try
                        {
                            instance[simpleProviderPropertyDefinition] = obj;
                        }
                        catch (DataValidationException ex2)
                        {
                            instance.AddValidationError(ex2.Error);
                        }
                    }
                }
            }
            instance.propertyBag[SimpleProviderObjectSchema.Identity] = new RegistryObjectId(folderPath, folderName);
            instance.ResetChangeTracking(true);
        }
        public NumberValue Resolve(Value source, LocalCodeExecutionContext localCodeExecutionContext, ResolverOptions options)
        {
#if DEBUG
            //Log($"source = {source}");
#endif

            var sourceKind = source.KindOfValue;

            switch (sourceKind)
            {
            case KindOfValue.NullValue:
                return(ValueConvertor.ConvertNullValueToNumberValue(source.AsNullValue, _context));

            case KindOfValue.LogicalValue:
                return(ValueConvertor.ConvertLogicalValueToNumberValue(source.AsLogicalValue, _context));

            case KindOfValue.NumberValue:
                return(source.AsNumberValue);

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }
        }
        public override PropertyConstraintViolationError Validate(object value, PropertyDefinition propertyDefinition, IPropertyBag propertyBag)
        {
            T t;

            try
            {
                t = (T)((object)ValueConvertor.ConvertValue(value, typeof(T), null));
            }
            catch (NotImplementedException ex)
            {
                return(new PropertyConstraintViolationError(new LocalizedString(ex.Message), propertyDefinition, value, this));
            }
            catch (TypeConversionException ex2)
            {
                return(new PropertyConstraintViolationError(ex2.LocalizedString, propertyDefinition, value, this));
            }
            if (this.specifyAllowedValues)
            {
                foreach (T t2 in this.valuesArray)
                {
                    if (object.Equals(t2, t))
                    {
                        return(null);
                    }
                }
                return(new PropertyConstraintViolationError(DataStrings.ConstraintViolationValueIsNotAllowed(this.GetValuesString(this.valuesArray), t.ToString()), propertyDefinition, t, this));
            }
            foreach (T t3 in this.valuesArray)
            {
                if (object.Equals(t3, t))
                {
                    return(new PropertyConstraintViolationError(DataStrings.ConstraintViolationValueIsDisallowed(this.GetValuesString(this.valuesArray), t.ToString()), propertyDefinition, t, this));
                }
            }
            return(null);
        }
Exemplo n.º 29
0
 public static object ConvertFromString(string item, Type type)
 {
     if (!string.IsNullOrEmpty(item))
     {
         type = (type ?? item.GetType());
         if (type == typeof(ExchangeObjectVersion))
         {
             return(new ExchangeObjectVersion(long.Parse(item)));
         }
         if (typeof(Enum).IsAssignableFrom(type))
         {
             return(Enum.Parse(type, item));
         }
         if (type == typeof(ADObjectId))
         {
             return(new ADObjectId(SearchHelper.ConvertFromString <byte[]>(item)));
         }
         if (type == typeof(ProxyAddressCollection))
         {
             ProxyAddressCollection proxyAddressCollection = new ProxyAddressCollection();
             foreach (string item2 in item.Split(new char[]
             {
                 ','
             }, StringSplitOptions.RemoveEmptyEntries))
             {
                 proxyAddressCollection.Add(SearchHelper.ConvertFromString <ProxyAddress>(item2));
             }
             return(proxyAddressCollection);
         }
         if (type == typeof(OrganizationId))
         {
             OrganizationId result;
             if (OrganizationId.TryCreateFromBytes(SearchHelper.ConvertFromString <byte[]>(item), Encoding.Unicode, out result))
             {
                 return(result);
             }
         }
         else
         {
             if (type == typeof(string))
             {
                 return(item);
             }
             if (type == typeof(ProxyAddress))
             {
                 return(ProxyAddress.Parse(item));
             }
             if (type == typeof(SmtpAddress))
             {
                 return(new SmtpAddress(SearchHelper.ConvertFromString <byte[]>(item)));
             }
             if (type == typeof(Guid))
             {
                 return(new Guid(item));
             }
             if (type == typeof(SmtpDomain))
             {
                 return(SmtpDomain.Parse(item));
             }
             if (type == typeof(SecurityIdentifier))
             {
                 return(new SecurityIdentifier(item));
             }
             if (type == typeof(byte[]))
             {
                 return(Convert.FromBase64String(item));
             }
             return(ValueConvertor.ConvertValueFromString(item, type, null));
         }
     }
     return(null);
 }
Exemplo n.º 30
0
        public static string ConvertToString(object item, Type type)
        {
            if (item != null)
            {
                type = (type ?? item.GetType());
                if (type == typeof(ExchangeObjectVersion))
                {
                    return(((ExchangeObjectVersion)item).ToInt64().ToString());
                }
                if (typeof(Enum).IsAssignableFrom(type))
                {
                    return(item.ToString());
                }
                if (type == typeof(ProxyAddressCollection))
                {
                    ProxyAddressCollection proxyAddressCollection = (ProxyAddressCollection)item;
                    if (proxyAddressCollection.Count <= 0)
                    {
                        goto IL_21C;
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    using (MultiValuedProperty <ProxyAddress> .Enumerator enumerator = proxyAddressCollection.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ProxyAddress item2 = enumerator.Current;
                            stringBuilder.Append(SearchHelper.ConvertToString(item2, typeof(ProxyAddress)));
                            stringBuilder.Append(',');
                        }
                        goto IL_21C;
                    }
                }
                if (type == typeof(ADObjectId))
                {
                    return(SearchHelper.ConvertToString(((ADObjectId)item).GetBytes(), typeof(byte[])));
                }
                if (type == typeof(OrganizationId))
                {
                    return(SearchHelper.ConvertToString(((OrganizationId)item).GetBytes(Encoding.Unicode), typeof(byte[])));
                }
                if (type == typeof(string))
                {
                    return((string)item);
                }
                if (type == typeof(ProxyAddress))
                {
                    return(((ProxyAddress)item).ProxyAddressString);
                }
                if (type == typeof(SmtpAddress))
                {
                    return(SearchHelper.ConvertToString(((SmtpAddress)item).GetBytes(), typeof(byte[])));
                }
                if (type == typeof(Guid))
                {
                    return(((Guid)item).ToString());
                }
                if (type == typeof(SmtpDomain))
                {
                    return(((SmtpDomain)item).ToString());
                }
                if (type == typeof(SecurityIdentifier))
                {
                    return(((SecurityIdentifier)item).ToString());
                }
                if (type == typeof(byte[]))
                {
                    return(Convert.ToBase64String((byte[])item));
                }
                return(ValueConvertor.ConvertValueToString(item, null));
            }
IL_21C:
            return(string.Empty);
        }