protected override bool InternalExecute(ProcessExecutingContext context) { if (!ContactId.IsEmpty() && string.IsNullOrEmpty(SearchCriteria)) { var entitySchemaManager = UserConnection.EntitySchemaManager; EntitySchemaQuery query = new EntitySchemaQuery(entitySchemaManager, "Contact"); query.AddColumn("Name"); var contact = (Terrasoft.Configuration.Contact)query.GetEntity(UserConnection, ContactId); if (contact != null) { SearchCriteria = contact.Name.Trim(); } } SocialNetwork socialNetwork = 0; var netwoks = SocialNetworks.Split('|'); if (netwoks == null || netwoks.Length == 0) { socialNetwork = SocialNetwork.All; } foreach (var netwok in netwoks) { socialNetwork = socialNetwork | (SocialNetwork)Enum.Parse(typeof(SocialNetwork), netwok, true); } SocialCommutator commutator = new SocialCommutator(UserConnection, socialNetwork); Users = commutator.FindUsers(SearchCriteria); return(true); }
public virtual bool SearchSocialUsersScriptTaskExecute(ProcessExecutingContext context) { if (string.IsNullOrEmpty(SearchCriteria)) { return(true); } SocialNetwork network = SocialNetwork.All; if (!string.IsNullOrEmpty(SocialNetworks)) { network = (SocialNetwork)Enum.Parse(typeof(SocialNetwork), SocialNetworks, true); } var commutator = new SocialCommutator(UserConnection, network); ExceptionNetworks = SocialNetwork.None; AccessTokenExceptionNetworks = SocialNetwork.None; commutator.ExceptionOccurred += delegate(ISocialNetwork n, Exception e) { if (e is AccessTokenExpired) { AccessTokenExceptionNetworks = (SocialNetwork)AccessTokenExceptionNetworks | (e as AccessTokenExpired).SocialNetwork; } else if (e is SocialNetworkException) { ExceptionNetworks = (SocialNetwork)ExceptionNetworks | (e as SocialNetworkException).SocialNetwork; } else { throw e; } }; var users = JsonConvert.SerializeObject(commutator.FindUsers(SearchCriteria)); SearchResult = string.Format("{{users: {0}, accessTokenExNetworks:'{1}', exeptionNetworks:'{2}'}}", users, AccessTokenExceptionNetworks.ToString(), ExceptionNetworks.ToString()); return(true); }
public string FindUsers(string searchCriteria, string socialNetworks) { if (string.IsNullOrEmpty(searchCriteria)) { return(""); } SocialNetwork network = SocialNetwork.All; if (!string.IsNullOrEmpty(socialNetworks)) { network = (SocialNetwork)Enum.Parse(typeof(SocialNetwork), socialNetworks, true); } var commutator = new SocialCommutator(UserConnection, network); var exceptionNetworks = SocialNetwork.None; var accessTokenExceptionNetworks = SocialNetwork.None; commutator.ExceptionOccurred += delegate(ISocialNetwork n, Exception e) { if (e is AccessTokenExpired) { accessTokenExceptionNetworks = (SocialNetwork)accessTokenExceptionNetworks | (e as AccessTokenExpired).SocialNetwork; } else if (e is SocialNetworkException) { exceptionNetworks = (SocialNetwork)exceptionNetworks | (e as SocialNetworkException).SocialNetwork; } else { throw e; } }; List <ISocialNetworkUser> bag = new List <ISocialNetworkUser>(commutator.FindUsers(searchCriteria)); string users = ServiceStackTextHelper.Serialize(bag); return(string.Format("{{\"users\":{0}, \"accessTokenExNetworks\":\"{1}\", \"exeptionNetworks\":\"{2}\"}}", users, accessTokenExceptionNetworks.ToString(), exceptionNetworks.ToString())); }
public string GetSocialNetworkLogin(string socialNetworkName, string socialId, string accessToken) { string login = "******"; if (socialNetworkName == "Google") { login = Terrasoft.Social.Google.GoogleConsumer.GetUserEmail(accessToken); } var network = SocialCommutator.CreateSocialNetwork(UserConnection, socialNetworkName); try { login = network.GetProfile(socialId).Name; } catch {} return(login); }
public string GetOAuthTokens(string socialNetworkName) { // NOT USED, FOR FUTURE NEEDS if (string.IsNullOrEmpty(socialNetworkName)) { throw new ArgumentNullOrEmptyException("socialNetworkName"); } string accessToken = string.Empty; string accessSecretToken = string.Empty; string socialId = string.Empty; string userId = UserConnection.CurrentUser.ContactId.ToString(); //TODO check is always should be current user string errorMessage; AuthResult authResult = SocialCommutator.CompleteAuthentication(UserConnection, socialNetworkName, out accessToken, out accessSecretToken, out socialId, out errorMessage); if (authResult == AuthResult.Failed) { if (string.IsNullOrEmpty(errorMessage)) { var userToken = new UserToken(userId, true); try { SocialCommutator.StartAuthentication(UserConnection, socialNetworkName, userToken); } catch (SocialNetworkException) { // TODO !!!! } } else { // TODO } return(string.Empty); } if (authResult == AuthResult.Success) { string result = @" { ""Token"": """ + accessToken + @""", ""Secret"": """ + accessSecretToken + @""", ""SocialId"": """ + socialId + @""" }" ; } // TODO !!! return(string.Empty); }
public string GetPublicProfileUrl(string socialMediaId, string socialNetworkName) { SocialCommutator commutator = null; switch (socialNetworkName) { case "Facebook": commutator = new SocialCommutator(UserConnection, SocialNetwork.Facebook); break; case "Twitter": commutator = new SocialCommutator(UserConnection, SocialNetwork.Twitter); break; } if (commutator != null) { return(commutator.GetPublicProfileUrl(socialMediaId)); } return(string.Empty); }
public string GetSocialProfile(string socialMediaId, string socialNetworkName, string socialAccountId) { SocialProfile resultProfile = null; SocialCommutator commutator = null; if (string.IsNullOrEmpty(socialNetworkName)) { socialNetworkName = ((SocialNetwork)int.Parse(socialMediaId)).ToString(); } switch (socialNetworkName) { case "Facebook": commutator = new SocialCommutator(UserConnection, SocialNetwork.Facebook); break; case "Twitter": commutator = new SocialCommutator(UserConnection, SocialNetwork.Twitter); break; } if (commutator != null) { SocialNetwork AccessTokenExceptionNetworks = SocialNetwork.None; SocialNetwork ExceptionNetworks = SocialNetwork.None; commutator.ExceptionOccurred += delegate(ISocialNetwork network, Exception e) { if (e is AccessTokenExpired) { AccessTokenExceptionNetworks = (SocialNetwork)AccessTokenExceptionNetworks | (e as AccessTokenExpired).SocialNetwork; } else if (e is SocialNetworkException) { ExceptionNetworks = (SocialNetwork)ExceptionNetworks | (e as SocialNetworkException).SocialNetwork; } else { throw e; } }; var profile = commutator.GetProfile(socialAccountId); resultProfile = new SocialProfile(); resultProfile.SocialNetwork = socialNetworkName; if (profile == null && (AccessTokenExceptionNetworks != SocialNetwork.None || ExceptionNetworks != SocialNetwork.None)) { return(string.Format("{{\"accessTokenExNetworks\":\"{0}\", \"exeptionNetworks\":\"{1}\"}}", AccessTokenExceptionNetworks.ToString(), ExceptionNetworks.ToString())); } resultProfile.ProdileId = profile.Id; if (!string.IsNullOrEmpty(profile.Name)) { resultProfile.Name = profile.Name; } if (!string.IsNullOrEmpty(profile.Email)) { resultProfile.Email = profile.Email; } if (!string.IsNullOrEmpty(profile.PhoneNumber)) { resultProfile.Phone = profile.PhoneNumber; } if (!string.IsNullOrEmpty(profile.IM)) { resultProfile.Skype = profile.IM; } if (!string.IsNullOrEmpty(profile.BirthDay) && !profile.BirthDay.Contains("<")) { var birthDay = DateTime.Now; if (DateTime.TryParse(profile.BirthDay, out birthDay)) { resultProfile.BirthDate = birthDay.ToString("dd-MM-yyyy"); } } if (!string.IsNullOrEmpty(profile.Address)) { resultProfile.Address = profile.Address; } if (!string.IsNullOrEmpty(profile.Work)) { resultProfile.JobTitle = profile.Work; } if (!string.IsNullOrEmpty(profile.AboutMe)) { resultProfile.AboutMe = profile.AboutMe; } var gender = profile.Gender; if (gender != 0) { resultProfile.GenderId = profile.Gender == Terrasoft.Social.Gender.Male ? new Guid("EEAC42EE-65B6-DF11-831A-001D60E938C6") : new Guid("FC2483F8-65B6-DF11-831A-001D60E938C6"); resultProfile.Gender = GetNameById(UserConnection, "Gender", resultProfile.GenderId); } if (!string.IsNullOrEmpty(profile.Country)) { resultProfile.Country = profile.Country; var id = GetIdByName(UserConnection, "Country", profile.Country); if (id != Guid.Empty) { resultProfile.CountryId = id; } } if (!string.IsNullOrEmpty(profile.HomeTown)) { resultProfile.City = profile.HomeTown; var id = GetIdByName(UserConnection, "City", profile.HomeTown); if (id != Guid.Empty) { resultProfile.CityId = id; } } } return(ServiceStackTextHelper.Serialize(resultProfile)); }