예제 #1
0
        public static async Task <RelayResponse> SetUserStatus(ADUser user, StagedUser stagedUser)
        {
            try
            {
                var client = new SigRClient(Settings.AdminSiteUrl, Settings.STSApiKey, "SiteHub");
                var data   = JsonConvert.SerializeObject(user);

                var msg = new RelayMessage
                {
                    ApiKey     = Settings.AdminApiKey,
                    Data       = data,
                    DestSiteId = stagedUser.SiteId,
                    Identifier = stagedUser.Upn,
                    Operation  = SiteOperation.SetUserStatus
                };

                await client.StartAsync();

                RelayResponse res = await client.ProcessRelayMessage(msg);

                return(res);
            }
            catch (Exception ex)
            {
                Utils.AddLogEntry("Error setting user status", EventLogEntryType.Error, 0, ex);
                return(new RelayResponse
                {
                    Success = false,
                    ErrorMessage = ex.Message
                });
            }
        }
예제 #2
0
        public static async Task <bool> ProcessCollection(IEnumerable <StagedUser> users)
        {
            var        res            = true;
            StagedUser currStagedUser = null;

            try
            {
                foreach (var user in users)
                {
                    currStagedUser = user;
                    switch (currStagedUser.LoadState)
                    {
                    case LoadStageEnum.PendingHQAdd:
                        await DocDBRepo.DB <StagedUser> .CreateItemAsync(currStagedUser);

                        break;

                    case LoadStageEnum.NewNothingPending:
                        currStagedUser.LoadState = LoadStageEnum.NothingPending;
                        await DocDBRepo.DB <StagedUser> .CreateItemAsync(currStagedUser);

                        break;

                    case LoadStageEnum.Deleted:
                        //We will leave this "deleted" record in the database for posterity
                        //await DocDBRepo.DB<StagedUser>.DeleteItemAsync(currStagedUser);
                        break;

                    default:
                        await DocDBRepo.DB <StagedUser> .UpdateItemAsync(currStagedUser);

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                res = false;
                await SyncLogEntryUtil.AddLog(new SyncLogEntry
                {
                    Source       = "StagedUser.ProcessCollection",
                    StagedUserId = (currStagedUser != null) ? currStagedUser.Id : null,
                    Detail       = string.Format("User: {0}\n\rError: {1}", ((currStagedUser != null) ? currStagedUser.Upn : "N/A"), ex.Message),
                    ErrorType    = System.Diagnostics.EventLogEntryType.Error.ToString(),
                    LogDate      = DateTime.UtcNow
                });
            }

            return(res);
        }
예제 #3
0
        public static async Task <bool> Update(StagedUser user)
        {
            try
            {
                var item = await DocDBRepo.DB <StagedUser> .UpdateItemAsync(user);

                return(item != null);
            }
            catch (Exception ex)
            {
                Logging.WriteToSyncLog("StagedUser/Update", ex.Message, System.Diagnostics.EventLogEntryType.Error, ex);
                return(false);
            }
        }
        public static RelayResponse UpdateUser(StagedUser user)
        {
            var res = new RelayResponse
            {
                Operation = SiteOperation.UpdateUser
            };

            try
            {
                var principal = GetUserPrincipal(user.Upn);
                principal.GivenName            = user.GivenName;
                principal.Surname              = user.Surname;
                principal.DisplayName          = user.DisplayName;
                principal.Name                 = user.Name;
                principal.EmailAddress         = user.Mail;
                principal.VoiceTelephoneNumber = user.TelephoneNumber;

                var de = (DirectoryEntry)principal.GetUnderlyingObject();
                de.Properties["title"].Value         = user.Title;
                de.Properties["streetAddress"].Value = user.StreetAddress;
                de.Properties["st"].Value            = user.State;
                de.Properties["postalCode"].Value    = user.PostalCode;
                de.Properties["mobile"].Value        = user.Mobile;
                de.Properties["homePhone"].Value     = user.HomePhone;
                de.Properties["department"].Value    = user.Department;
                de.Properties["c"].Value             = user.Country;
                de.Properties["l"].Value             = user.City;
                de.CommitChanges();
                principal.Save();
                return(res);
            }
            catch (Exception ex)
            {
                res.Success      = false;
                res.ErrorMessage = ex.Message;
                return(res);
            }
        }
        private static StagedUser GetResults(SearchResult result)
        {
            var oRes = result.Properties;

            if (result == null)
            {
                return(null);
            }

            var user = new StagedUser
            {
                Name            = oRes["SAMAccountName"][0].ToString().ToLower(),
                DisplayName     = (oRes["DisplayName"].Count > 0) ? oRes["DisplayName"][0].ToString() : "",
                GivenName       = (oRes["givenName"].Count > 0) ? oRes["givenName"][0].ToString() : "",
                Surname         = (oRes["sn"].Count > 0) ? oRes["sn"][0].ToString() : "",
                Title           = (oRes["title"].Count > 0) ? oRes["title"][0].ToString() : "",
                Mail            = (oRes["mail"].Count > 0) ? oRes["mail"][0].ToString().ToLower() : "",
                TelephoneNumber = (oRes["telephoneNumber"].Count > 0) ? oRes["telephoneNumber"][0].ToString() : "",
                Mobile          = (oRes["mobile"].Count > 0) ? oRes["mobile"][0].ToString() : "",
                StreetAddress   = (oRes["streetAddress"].Count > 0) ? oRes["streetAddress"][0].ToString() : "",
                State           = (oRes["st"].Count > 0) ? oRes["st"][0].ToString() : "",
                PostalCode      = (oRes["postalCode"].Count > 0) ? oRes["postalCode"][0].ToString() : "",
                City            = (oRes["l"].Count > 0) ? oRes["l"][0].ToString() : "",
                Country         = (oRes["c"].Count > 0) ? oRes["c"][0].ToString() : "US",
                Upn             = (oRes["userPrincipalName"].Count > 0) ? oRes["userPrincipalName"][0].ToString() : "",
                Department      = (oRes["department"].Count > 0) ? oRes["department"][0].ToString() : "",
                HomePhone       = (oRes["homePhone"].Count > 0) ? oRes["homePhone"][0].ToString() : ""
            };

            var localGuid  = (oRes["objectGuid"].Count > 0) ? (oRes["objectGuid"][0] as Byte[]) : null;
            var masterGuid = (oRes["mS-DS-ConsistencyGuid"].Count > 0) ? (oRes["mS-DS-ConsistencyGuid"][0] as Byte[]) : null;

            user.LocalGuid  = (localGuid != null) ? Convert.ToBase64String(localGuid) : "";
            user.MasterGuid = (masterGuid != null) ? Convert.ToBase64String(masterGuid) : "";

            return(user);
        }
예제 #6
0
 public static void AddUserToQueue(StagedUser user)
 {
     //this will be queued
     StorageRepo.AddQueueItem(user, "stageduser");
 }