Exemplo n.º 1
0
        internal static T FindById <T>(IIdentityParameter idParameter, IConfigDataProvider dataProvider) where T : IConfigurable, new()
        {
            IEnumerable <T> objects = idParameter.GetObjects <T>(null, dataProvider);
            T result;

            using (IEnumerator <T> enumerator = objects.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    throw new ManagementObjectNotFoundException(Strings.ErrorManagementObjectNotFound(idParameter.ToString()));
                }
                result = enumerator.Current;
                if (enumerator.MoveNext())
                {
                    throw new ManagementObjectAmbiguousException(Strings.ErrorManagementObjectAmbiguous(idParameter.ToString()));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        protected IEnumerable <TObject> GetDataObjects <TObject>(IIdentityParameter id, IConfigDataProvider session, ObjectId rootID, OptionalIdentityData optionalData, out LocalizedString?notFoundReason) where TObject : IConfigurable, new()
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            notFoundReason = null;
            base.WriteVerbose(TaskVerboseStringHelper.GetFindByIdParameterVerboseString(id, session ?? this.DataSession, typeof(TObject), rootID));
            IEnumerable <TObject> objects;

            try
            {
                objects = id.GetObjects <TObject>(rootID, session ?? this.DataSession, optionalData, out notFoundReason);
            }
            finally
            {
                base.WriteVerbose(TaskVerboseStringHelper.GetSourceVerboseString(session ?? this.DataSession));
            }
            return(objects);
        }
Exemplo n.º 3
0
        protected IConfigurable GetDataObject <TObject>(IIdentityParameter id, IConfigDataProvider session, ObjectId rootID, OptionalIdentityData optionalData, LocalizedString notFoundError, LocalizedString multipleFoundError) where TObject : IConfigurable, new()
        {
            IConfigurable         result          = null;
            LocalizedString?      localizedString = null;
            IEnumerable <TObject> objects         = id.GetObjects <TObject>(rootID, session, optionalData, out localizedString);

            using (IEnumerator <TObject> enumerator = objects.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    result = enumerator.Current;
                    if (enumerator.MoveNext())
                    {
                        Exception innerException = new ManagementObjectAmbiguousException(multipleFoundError);
                        base.WriteError(new TaskInvalidOperationException(multipleFoundError, innerException), ExchangeErrorCategory.Client, this.Identity);
                    }
                }
                else
                {
                    LocalizedString message;
                    if (localizedString != null)
                    {
                        string          notFound         = notFoundError;
                        LocalizedString?localizedString2 = localizedString;
                        message = Strings.ErrorNotFoundWithReason(notFound, (localizedString2 != null) ? localizedString2.GetValueOrDefault() : null);
                    }
                    else
                    {
                        message = notFoundError;
                    }
                    Exception innerException = new ManagementObjectNotFoundException(message);
                    base.WriteError(new TaskInvalidOperationException(notFoundError, innerException), ExchangeErrorCategory.Client, this.Identity);
                }
            }
            return(result);
        }