Esempio n. 1
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);
 }