Esempio n. 1
0
 private void CreateNovoContacto(ClientContext siteContexto, List listaTelefonica, ItemListaTelefonicaProperties itemListaTelefonicaProperties)
 {
     try
     {
         ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
         ListItem addItem = listaTelefonica.AddItem(itemCreateInfo);
         addItem["Title"]       = itemListaTelefonicaProperties.PreferredName;
         addItem["FirstName"]   = itemListaTelefonicaProperties.FirstName;
         addItem["LastName"]    = itemListaTelefonicaProperties.LastName;
         addItem["Email"]       = itemListaTelefonicaProperties.Email;
         addItem["PagerNumber"] = itemListaTelefonicaProperties.Pager;
         addItem["Department"]  = itemListaTelefonicaProperties.Department;
         addItem["CellPhone"]   = itemListaTelefonicaProperties.CellPhone;
         addItem["PictureURL"]  = itemListaTelefonicaProperties.PictureURL;
         addItem["Office"]      = itemListaTelefonicaProperties.Office;
         addItem["WorkFax"]     = itemListaTelefonicaProperties.WorkFax;
         addItem["WorkPhone"]   = itemListaTelefonicaProperties.WorkPhone;
         addItem["WorkState"]   = itemListaTelefonicaProperties.WorkState;
         addItem["WorkCity"]    = itemListaTelefonicaProperties.WorkCity;
         addItem["WorkCountry"] = itemListaTelefonicaProperties.WorkCountry;
         addItem["WorkZip"]     = itemListaTelefonicaProperties.WorkZip;
         addItem["IpPhone"]     = itemListaTelefonicaProperties.IpPhone;
         addItem["WorkAddress"] = itemListaTelefonicaProperties.WorkAddress;
         addItem["AboutMe"]     = itemListaTelefonicaProperties.AboutMe;
         addItem["JobTitle"]    = itemListaTelefonicaProperties.JobTitle;
         addItem["Company"]     = itemListaTelefonicaProperties.Company;
         addItem.Update();
         siteContexto.ExecuteQuery();
     }
     catch (Exception ex)
     {
         _log.Error($"-> CreateNovoContacto no processo: SharepointSyncJob: {ex}", ex);
     }
 }
Esempio n. 2
0
        private void Init()
        {
            _log.Info("Início do processo: SharepointSyncJob");
            var listItemListaTelefonicaProperties = new List <ItemListaTelefonicaProperties>();

            using (ClientContext tenantContext = new ClientContext(_configuration.TenantUrl))
            {
                SecureString passWord = new SecureString();
                foreach (char c in _configuration.Password.ToCharArray())
                {
                    passWord.AppendChar(c);
                }
                tenantContext.Credentials = new SharePointOnlineCredentials(_configuration.EmailAccount, passWord);
                PeopleManager peopleManager = new PeopleManager(tenantContext);

                UserCollection users = tenantContext.Web.SiteUsers;
                tenantContext.Load(users);
                tenantContext.ExecuteQuery();
                StringBuilder items = new StringBuilder();
                string[]      userProfileProperties =
                {
                    UserProfileProperties.FirstName,
                    UserProfileProperties.LastName,
                    UserProfileProperties.PreferredName,
                    UserProfileProperties.WorkEmail,
                    UserProfileProperties.Pager,
                    UserProfileProperties.Department,
                    UserProfileProperties.CellPhone,
                    UserProfileProperties.PictureURL,
                    UserProfileProperties.Office,
                    UserProfileProperties.IpPhone,
                    UserProfileProperties.WorkPhone,
                    UserProfileProperties.IpPhone,
                    UserProfileProperties.AboutMe,
                    UserProfileProperties.StreetAddress,
                    UserProfileProperties.CityAddress,
                    UserProfileProperties.StateAddress,
                    UserProfileProperties.ZIPAddress,
                    UserProfileProperties.CountryAddress,
                    UserProfileProperties.SPS_Location,
                    UserProfileProperties.Title,
                    UserProfileProperties.Fax,
                    UserProfileProperties.AccountName,
                };

                foreach (string propertyKey in userProfileProperties)
                {
                    items.Append(propertyKey);
                    items.Append(",");
                }
                items.AppendLine();
                _log.Info("A ler os Users profile: SharepointSyncJob");
                foreach (User user in users)
                {
                    try
                    {
                        if (user.PrincipalType != Microsoft.SharePoint.Client.Utilities.PrincipalType.User)
                        {
                            continue;
                        }

                        UserProfilePropertiesForUser userProfilePropertiesForUser = new UserProfilePropertiesForUser(tenantContext, user.LoginName, userProfileProperties);
                        var profileProperties = peopleManager.GetUserProfilePropertiesFor(userProfilePropertiesForUser);
                        tenantContext.Load(userProfilePropertiesForUser);
                        tenantContext.ExecuteQuery();
                        var listProfileProperties = profileProperties.ToList();
                        if (listProfileProperties.Any())
                        {
                            ItemListaTelefonicaProperties itemListaTelefonicaProperties = new ItemListaTelefonicaProperties();

                            itemListaTelefonicaProperties.FirstName     = listProfileProperties[0];
                            itemListaTelefonicaProperties.LastName      = listProfileProperties[1];
                            itemListaTelefonicaProperties.PreferredName = listProfileProperties[2];
                            itemListaTelefonicaProperties.Email         = user.Email;
                            itemListaTelefonicaProperties.Pager         = listProfileProperties[4];
                            itemListaTelefonicaProperties.Department    = listProfileProperties[5];
                            itemListaTelefonicaProperties.CellPhone     = listProfileProperties[6];
                            itemListaTelefonicaProperties.Office        = listProfileProperties[8];
                            itemListaTelefonicaProperties.WorkFax       = listProfileProperties[9];
                            itemListaTelefonicaProperties.WorkPhone     = listProfileProperties[10];
                            itemListaTelefonicaProperties.IpPhone       = listProfileProperties[11];
                            itemListaTelefonicaProperties.AboutMe       = listProfileProperties[12];
                            itemListaTelefonicaProperties.WorkAddress   = listProfileProperties[13];
                            itemListaTelefonicaProperties.WorkCity      = listProfileProperties[14];
                            itemListaTelefonicaProperties.WorkState     = listProfileProperties[15];
                            itemListaTelefonicaProperties.WorkZip       = listProfileProperties[16];
                            itemListaTelefonicaProperties.WorkCountry   = listProfileProperties[17];
                            itemListaTelefonicaProperties.Company       = listProfileProperties[18];
                            itemListaTelefonicaProperties.JobTitle      = listProfileProperties[19];
                            itemListaTelefonicaProperties.WorkFax       = listProfileProperties[20];
                            itemListaTelefonicaProperties.PictureURL    = $"{this._configuration.TenantUrl}{PICTURE_URL}{ user.Email}";

                            listItemListaTelefonicaProperties.Add(itemListaTelefonicaProperties);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error($"-> users no processo: SharepointSyncJob: {ex}", ex);
                    }
                }

                InsertOrUpdateContactoToListContactos(listItemListaTelefonicaProperties);
            }
            _log.Info("Fim do processo: SharepointSyncJob");
        }
Esempio n. 3
0
 private void UpdateContacto(ClientContext siteContexto, Microsoft.SharePoint.Client.List listaTelefonica, ItemListaTelefonicaProperties itemListaTelefonicaProperties, int id)
 {
     try
     {
         Microsoft.SharePoint.Client.ListItem updateItem = listaTelefonica.GetItemById(id);
         updateItem["Title"]       = itemListaTelefonicaProperties.PreferredName;
         updateItem["FirstName"]   = itemListaTelefonicaProperties.FirstName;
         updateItem["LastName"]    = itemListaTelefonicaProperties.LastName;
         updateItem["Email"]       = itemListaTelefonicaProperties.Email;
         updateItem["Department"]  = itemListaTelefonicaProperties.Department;
         updateItem["CellPhone"]   = itemListaTelefonicaProperties.CellPhone;
         updateItem["PictureURL"]  = itemListaTelefonicaProperties.PictureURL;
         updateItem["Office"]      = itemListaTelefonicaProperties.Office;
         updateItem["WorkFax"]     = itemListaTelefonicaProperties.WorkFax;
         updateItem["WorkPhone"]   = itemListaTelefonicaProperties.WorkPhone;
         updateItem["WorkState"]   = itemListaTelefonicaProperties.WorkState;
         updateItem["WorkCity"]    = itemListaTelefonicaProperties.WorkCity;
         updateItem["WorkCountry"] = itemListaTelefonicaProperties.WorkCountry;
         updateItem["WorkZip"]     = itemListaTelefonicaProperties.WorkZip;
         updateItem["IpPhone"]     = itemListaTelefonicaProperties.IpPhone;
         updateItem["WorkAddress"] = itemListaTelefonicaProperties.WorkAddress;
         updateItem["AboutMe"]     = itemListaTelefonicaProperties.AboutMe;
         updateItem["JobTitle"]    = itemListaTelefonicaProperties.JobTitle;
         updateItem["Company"]     = itemListaTelefonicaProperties.Company;
         updateItem.Update();
         siteContexto.ExecuteQuery();
     }
     catch (Exception ex)
     {
         _log.Error($"-> UpdateContacto no processo: SharepointSyncJob: {ex}", ex);
     }
 }