コード例 #1
0
ファイル: FimClient.cs プロジェクト: Predica/FimClient
        public IEnumerable <TResource> EnumerateAll <TResource>(string query, AttributesToFetch attributes = null) where TResource : RmResource
        {
            attributes = attributes ?? AttributesToFetch.All;

            var ctx = LogContext.WithConfigFormat();

            Initialize();

            try
            {
                _log.Debug(ctx.Format("Executing simple enumeration: {0} with attributes {1}"), query, attributes.GetNames().ToJSON());

                var results = _defaultClient.Enumerate(query, attributes.GetNames())
                              .Cast <TResource>()
                              .ToList();

                log_query_executed(ctx, "Simple enumeration {0} returned {1} results", query, results.Count);

                return(results);
            }
            catch (Exception exc)
            {
                var qee = new QueryExecutionException(query, exc);

                _log.ErrorException(ctx.Format("Error when trying to execute query " + query), qee);

                throw qee;
            }
        }
コード例 #2
0
        public static void UpdateUser(string manager, PersonModel _fp)
        {
            using (DefaultClient _client = new DefaultClient())
            {
                _client.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                _client.RefreshSchema();
                List <RmResource> _res = _client.Enumerate("/Person[ObjectID='" + _fp.ObjectID + "']").ToList();
                foreach (RmPerson _r in _res)
                {
                    RmResourceChanges changes = new RmResourceChanges(_r);
                    try
                    {
                        changes.BeginChanges();
                        if (string.IsNullOrWhiteSpace(manager))
                        {
                            RmAttributeName _attr = new RmAttributeName("Manager");
                            _r.Attributes.Remove(_attr);
                        }
                        else
                        {
                            _r.Manager = new RmReference(manager);
                        }

                        _client.Put(changes);
                        changes.AcceptChanges();
                    }
                    catch
                    {
                        changes.DiscardChanges();
                    }
                }
            }
        }
コード例 #3
0
        public static List <PersonModel> GetFimPersonListFromCostCenter(string _cdcCode)
        {
            PersonModel        _per     = null;
            List <PersonModel> _lperson = new List <PersonModel>();

            string xPathQuery = "/Person[CostCenter='" + _cdcCode + "']";

            using (DefaultClient _client = new DefaultClient())
            {
                _client.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                _client.RefreshSchema();
                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format("Enumerate with filter: {0}", xPathQuery));
                }
                List <RmResource> _res = _client.Enumerate(xPathQuery).ToList();
                if (log.IsDebugEnabled)
                {
                    log.Debug("End enumerate ");
                }

                if (_res == null)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Enumeration null!");
                    }
                    //throw new UserNotFoundException("");
                }
                else
                {
                    foreach (RmPerson person in _res)
                    {
                        _per                = new PersonModel();
                        _per.ObjectID       = person.ObjectID.Value;
                        _per.Manager        = (person.Manager != null) ? person.Manager.Value : string.Empty;
                        _per.CostCenterCode = person.CostCenter;
                        _per.AccountName    = person.AccountName;
                        _lperson.Add(_per);
                    }
                }
            }

            return(_lperson);
        }
コード例 #4
0
        public static PersonModel GetManagerThroughSamAccount(string _managerSamAccount)
        {
            PersonModel _res = null;

            string xPathQuery = "/Person[AccountName='" + _managerSamAccount + "']";

            using (DefaultClient _client = new DefaultClient())
            {
                _client.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                _client.RefreshSchema();
                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format("Enumerate with filter: {0}", xPathQuery));
                }
                List <RmResource> _ls = _client.Enumerate(xPathQuery).ToList();
                if (log.IsDebugEnabled)
                {
                    log.Debug("End enumerate ");
                }

                if (_ls.Count != 1)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Error found more than 1 account");
                    }
                    //throw new UserNotFoundException("");
                }
                else
                {
                    foreach (RmPerson person in _ls)
                    {
                        PersonModel _per = new PersonModel();
                        _per.ObjectID    = person.ObjectID.Value;
                        _per.AccountName = person.AccountName;
                        _res             = _per;
                    }
                }
            }
            return(_res);
        }