Beispiel #1
0
 public static void Search(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, IUserDatabase userDatabase, Action <IInternalUnidentifiedUser> successCallback, Action failureCallback)
 {
     try
     {
         DisplayNameSearchRequest displayNameSearchRequest = new DisplayNameSearchRequest();
         displayNameSearchRequest.DisplayName = displayName;
         DisplayNameSearchRequest request = displayNameSearchRequest;
         IWebCall <DisplayNameSearchRequest, DisplayNameSearchResponse> webCall = mixWebCallFactory.SearchDisplaynamePost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <DisplayNameSearchResponse> e)
         {
             DisplayNameSearchResponse response = e.Response;
             if (ValidateResponse(response))
             {
                 userDatabase.InsertUserDocument(new UserDocument
                 {
                     DisplayName = response.DisplayName,
                     FirstName   = response.FirstName,
                     Swid        = null,
                     HashedSwid  = null
                 });
                 IInternalUnidentifiedUser obj = RemoteUserFactory.CreateUnidentifiedUser(response.DisplayName, response.FirstName, userDatabase);
                 successCallback(obj);
             }
             else
             {
                 logger.Critical("Failed to validate display name search response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate(object sender, WebCallErrorEventArgs e)
         {
             logger.Debug("Failed to find user: "******"Unhandled exception: " + arg);
         failureCallback();
     }
 }
 public static void Recommend(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IUserDatabase userDatabase, Action <IEnumerable <IInternalUnidentifiedUser> > successCallback, Action failureCallback)
 {
     try
     {
         BaseUserRequest request = new BaseUserRequest();
         IWebCall <BaseUserRequest, GetFriendshipRecommendationResponse> webCall = mixWebCallFactory.FriendshipRecommendPost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetFriendshipRecommendationResponse> e)
         {
             List <FriendRecommendation> friendRecommendations = e.Response.FriendRecommendations;
             if (friendRecommendations == null)
             {
                 failureCallback();
             }
             else
             {
                 foreach (FriendRecommendation item in friendRecommendations)
                 {
                     userDatabase.InsertUserDocument(new UserDocument
                     {
                         DisplayName = item.DisplayName,
                         FirstName   = item.FirstName,
                         Swid        = null,
                         HashedSwid  = null
                     });
                 }
                 IInternalUnidentifiedUser[] obj = (from item in friendRecommendations
                                                    select RemoteUserFactory.CreateUnidentifiedUser(item.DisplayName, item.FirstName, userDatabase)).ToArray();
                 successCallback(obj);
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception arg)
     {
         logger.Critical("Unhandled exception: " + arg);
         failureCallback();
     }
 }