예제 #1
0
 public SyncService()
 {
     AdUserService = new AdUserService();
     DbUserService = new DbUserService();
     HelperService = new HelperService();
     FaxApiService = new FaxApiService();
     LogService    = new LogService();
 }
        private Dictionary <Attorney, bool> SyncUsersWithFaxSolution(List <Attorney> listAttorney)
        {
            this.LogService.LogEvent("START: Getting data from FAX Solution, API calls to get FaxNumbers and FaxUsers");
            var faxNumbers      = FaxApiService.GetAllFaxNumbers().data;
            var faxUsers        = FaxApiService.GetAllUsers().data;
            var listOfExecution = new Dictionary <Attorney, bool>();

            this.LogService.LogEvent("FINISH: Getting data from FAX Solution, API calls to get FaxNumbers and FaxUsers");
            this.LogService.LogEvent("START: MAIN Processing the API calls to the FAX Solution to sync data.");
            foreach (var attr in listAttorney)
            {
                if (attr.ActionList.NotNull() && attr.ActionList.Count() > 0)
                {
                    var apiSuccess = ProcessActionItems(attr.ActionList, faxUsers, faxNumbers);
                    listOfExecution.Add(attr, apiSuccess);
                }
            }
            this.LogService.LogEvent("FINISH: MAIN Processing the API calls to the FAX Solution to sync data.");
            return(listOfExecution);
        }
        private bool ProcessActionItems(List <ActionSync> actionItems, List <FaxApiUser> faxUsers, List <FaxApiNumber> faxNumbers)
        {
            if (actionItems.NotNull() && actionItems.Count() > 0)
            {
                foreach (var action in actionItems)
                {
                    MapFaxSolutionIdsWithActionItems(action, faxUsers, faxNumbers);

                    if (action.ActionType == ActionSyncType.AssignUser && action.AssistantSnycObj.FaxNumberIsShared.Not())
                    {
                        action.Result = FaxApiService.AssignUser(action.AssistantSnycObj.FaxNumberId, action.AssistantSnycObj.FaxUserId);
                    }
                    else if (action.ActionType == ActionSyncType.DeAssignUser)
                    {
                        action.Result = FaxApiService.UnAssignUser(action.AssistantSnycObj.FaxNumberId, action.AssistantSnycObj.FaxUserId);
                    }
                }
            }

            return(actionItems.NotNull() && actionItems.Where(x => x.Result.Result.Not()).Count() == 0);
        }
예제 #4
0
        public void Sync(int?logSessionId = null)
        {
            LogService.LogStartEvent("START - xMedius Script - Sync Users Script");
            LogService.LogEvent("Pulling users from Active Directory");
            var adUsers = AdUserService.GetCachedUsers();

            LogService.LogEvent("Pulling data from xMedius - Users,Groups,FaxNumbeers");
            var blackListedNumbers  = HelperService.GetBlackListedFaxNumbers();
            var faxNumbers          = FaxApiService.GetAllFaxNumbers().data;
            var faxUsers            = FaxApiService.GetAllUsers().data;
            var faxGroups           = FaxApiService.GetAllFaxGroups().data;
            var lstXMediusDomainObj = new List <XMediusUser>();

            LogService.LogEvent("Analyzing data...");
            foreach (var usr in adUsers)
            {
                var buildUser = new XMediusUser(usr as AdUser, faxGroups, faxUsers, faxNumbers, blackListedNumbers);
                lstXMediusDomainObj.Add(buildUser);
            }

            var usersWithActions       = lstXMediusDomainObj.Where(x => x.ActionList.Any()).ToList();
            var disabledUsers          = usersWithActions.Where(x => x.AdUser.Disabled).ToList();
            var updatedUsers           = usersWithActions.Where(x => x.ActionList.Where(y => y.ActionReason == ActionSyncReason.UpdateUserFaxGroup).Any()).ToList();
            var updatedUsersFax        = usersWithActions.Where(x => x.ActionList.Where(y => y.ActionReason == ActionSyncReason.UserIsUpdated).Any()).ToList();
            var userWithouFaxAndOFfice = usersWithActions.Where(x => x.ActionList.Where(y => y.ActionReason == ActionSyncReason.UserWihtoutFaxAndOffice).Any()).ToList();
            var restOfUsersNew         = usersWithActions.Where(x => x.ActionList.Where(y => y.ActionType == ActionSyncType.AddUser).Any()).ToList();
            var restOfUsersRemove      = usersWithActions.Where(x => x.ActionList.Where(y => y.ActionType == ActionSyncType.RemoveUser).Any()).ToList();
            var restOfUsersUpdate      = usersWithActions.Where(x => x.ActionList.Where(y => y.ActionType == ActionSyncType.UpdateUser).Any()).ToList();

            LogService.LogEvent($"Stats - AddUsers:{restOfUsersNew.Count()} RemoveUsers:{restOfUsersRemove.Count()} UpdateUsers:{restOfUsersUpdate.Count()}", false);

            restOfUsersNew.ForEach(x => x.ActionList.ForEach(y => LogService.LogEvent(y.ToString())));
            restOfUsersUpdate.ForEach(x => x.ActionList.ForEach(y => LogService.LogEvent(y.ToString())));
            restOfUsersRemove.ForEach(x => x.ActionList.ForEach(y => LogService.LogEvent(y.ToString())));

            LogService.LogEvent("Sync DONE!");

            File.WriteAllLines("XMedius_SyncUsers_Log_" + DateTime.Now.ToString("yyyyMMddHHmmssffff"), LogService.LogEventsList);
        }