Пример #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);
 }
Пример #2
0
        private ExchangePrincipal GetExchangePrincipalFromWindowsIdentity(WindowsIdentity windowsIdentity, string smtpAddress)
        {
            OwaIdentity       owaIdentity  = OwaWindowsIdentity.CreateFromWindowsIdentity(windowsIdentity);
            OwaIdentity       owaIdentity2 = null;
            bool              flag         = false;
            bool              flag2        = false;
            ExchangePrincipal result;

            try
            {
                ExchangePrincipal exchangePrincipal = null;
                if (smtpAddress != null)
                {
                    owaIdentity2 = OwaIdentity.CreateOwaIdentityFromSmtpAddress(owaIdentity, smtpAddress, out exchangePrincipal, out flag, out flag2);
                }
                else
                {
                    owaIdentity2 = owaIdentity;
                }
                if (flag && owaIdentity2.IsPartial)
                {
                    OwaMiniRecipientIdentity owaMiniRecipientIdentity = owaIdentity2 as OwaMiniRecipientIdentity;
                    try
                    {
                        owaMiniRecipientIdentity.UpgradePartialIdentity();
                    }
                    catch (DataValidationException ex)
                    {
                        PropertyValidationError propertyValidationError = ex.Error as PropertyValidationError;
                        if (propertyValidationError == null || propertyValidationError.PropertyDefinition != MiniRecipientSchema.Languages)
                        {
                            return(null);
                        }
                        OWAMiniRecipient owaminiRecipient = owaIdentity2.FixCorruptOWAMiniRecipientCultureEntry();
                        if (owaminiRecipient != null)
                        {
                            owaIdentity2.Dispose();
                            owaIdentity2 = OwaMiniRecipientIdentity.CreateFromOWAMiniRecipient(owaminiRecipient);
                        }
                    }
                }
                if (owaIdentity == owaIdentity2 && exchangePrincipal != null)
                {
                    result = exchangePrincipal;
                }
                else
                {
                    try
                    {
                        result = owaIdentity2.InternalCreateExchangePrincipal();
                    }
                    catch (UserHasNoMailboxException)
                    {
                        result = null;
                    }
                }
            }
            finally
            {
                if (owaIdentity != owaIdentity2 && owaIdentity2 != null)
                {
                    owaIdentity2.Dispose();
                    owaIdentity2 = null;
                }
                if (owaIdentity != null)
                {
                    owaIdentity.Dispose();
                    owaIdentity = null;
                }
            }
            return(result);
        }