Esempio n. 1
0
        public static void RegisterEnum(Type enumType)
        {
            ExTraceGlobals.OehCallTracer.TraceDebug(0L, "OwaEventRegistry.RegisterEnum");
            if (enumType == null)
            {
                throw new ArgumentNullException("enumType");
            }
            if (!enumType.IsEnum || enumType.BaseType != typeof(Enum))
            {
                throw new OwaNotSupportedException("Type is not an enum");
            }
            if (OwaEventRegistry.enumTable.ContainsKey(enumType))
            {
                return;
            }
            Array values = Enum.GetValues(enumType);

            if (values == null || values.Length == 0)
            {
                throw new OwaNotSupportedException("Enum doesn't have any members");
            }
            OwaEventEnumAttribute owaEventEnumAttribute = new OwaEventEnumAttribute();

            for (int i = 0; i < values.Length; i++)
            {
                object value = values.GetValue(i);
                owaEventEnumAttribute.AddValueInfo((int)value, value);
            }
            OwaEventRegistry.enumTable[enumType] = owaEventEnumAttribute;
        }
Esempio n. 2
0
 protected object ConvertToStrongType(Type paramType, string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Failed to parse type. Type = {0}, Value = {1}", new object[]
         {
             paramType,
             value
         }));
     }
     try
     {
         if (paramType.IsEnum)
         {
             OwaEventEnumAttribute owaEventEnumAttribute = OwaEventRegistry.FindEnumInfo(paramType);
             int    intValue = int.Parse(value, CultureInfo.InvariantCulture);
             object obj      = owaEventEnumAttribute.FindValueInfo(intValue);
             if (obj == null)
             {
                 this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Failed to parse enum type. Type = {0}, Value = {1}", new object[]
                 {
                     paramType,
                     value
                 }));
             }
             return(obj);
         }
         if (paramType == typeof(int))
         {
             return(int.Parse(value, CultureInfo.InvariantCulture));
         }
         if (paramType == typeof(double))
         {
             return(double.Parse(value, CultureInfo.InvariantCulture));
         }
         if (paramType == typeof(ExDateTime))
         {
             return(DateTimeUtilities.ParseIsoDate(value, this.EventHandler.OwaContext.SessionContext.TimeZone));
         }
         if (paramType == typeof(bool))
         {
             if (string.Equals(value, "0", StringComparison.Ordinal))
             {
                 return(false);
             }
             if (string.Equals(value, "1", StringComparison.Ordinal))
             {
                 return(true);
             }
             this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Failed to parse type. Type = {0}, Value = {1}", new object[]
             {
                 paramType,
                 value
             }));
         }
         else
         {
             if (paramType == typeof(StoreObjectId))
             {
                 UserContext userContext = this.EventHandler.OwaContext.UserContext;
                 return(Utilities.CreateStoreObjectId(userContext.MailboxSession, value));
             }
             if (paramType == typeof(ADObjectId))
             {
                 ADObjectId adobjectId = DirectoryAssistance.ParseADObjectId(value);
                 if (adobjectId == null)
                 {
                     this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Failed to parse type. Type = {0}, Value = {1}", new object[]
                     {
                         paramType,
                         value
                     }));
                 }
                 return(adobjectId);
             }
             if (paramType == typeof(DocumentLibraryObjectId))
             {
                 UserContext userContext2 = this.EventHandler.OwaContext.UserContext;
                 Uri         uri;
                 if (null == (uri = Utilities.TryParseUri(value)))
                 {
                     return(null);
                 }
                 ClassifyResult[]   array = null;
                 OwaWindowsIdentity owaWindowsIdentity = userContext2.LogonIdentity as OwaWindowsIdentity;
                 if (owaWindowsIdentity != null && owaWindowsIdentity.WindowsPrincipal != null)
                 {
                     array = LinkClassifier.ClassifyLinks(owaWindowsIdentity.WindowsPrincipal, new Uri[]
                     {
                         uri
                     });
                 }
                 if (array == null || array.Length == 0)
                 {
                     return(null);
                 }
                 return(array[0].ObjectId);
             }
             else if (paramType == typeof(OwaStoreObjectId))
             {
                 UserContext userContext3 = this.EventHandler.OwaContext.UserContext;
                 if (OwaStoreObjectId.IsDummyArchiveFolder(value))
                 {
                     return(userContext3.GetArchiveRootFolderId());
                 }
                 return(OwaStoreObjectId.CreateFromString(value));
             }
             else
             {
                 this.ThrowParserException("Internal error: unknown type");
             }
         }
     }
     catch (FormatException)
     {
         this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Failed to parse type. Type = {0}, Value = {1}", new object[]
         {
             paramType,
             value
         }));
     }
     catch (OwaParsingErrorException)
     {
         this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Failed to parse type. Type = {0}, Value = {1}", new object[]
         {
             paramType,
             value
         }));
     }
     catch (OverflowException)
     {
         this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Type overflow. Type = {0}, Value = {1}", new object[]
         {
             paramType,
             value
         }));
     }
     return(null);
 }