Exemple #1
0
        private void HoloOASIS_OnZomeFunctionCallBack(object sender, ZomeFunctionCallBackEventArgs e)
        {
            if (!e.IsCallSuccessful)
            {
                HandleError(string.Concat("Zome function ", e.ZomeFunction, " on zome ", e.Zome, " returned an error. Error Details: ", e.ZomeReturnData), null, null);
            }
            //OnHoloOASISError?.Invoke(this, new ErrorEventArgs() { EndPoint = HoloNETClient.EndPoint, Reason = string.Concat("Zome function ", e.ZomeFunction, " on zome ", e.Zome, " returned an error. Error Details: ", e.ZomeReturnData) });
            else
            {
                switch (e.ZomeFunction)
                {
                case LOAD_PROFILE_FUNC:
                    HcProfile hcProfile = JsonConvert.DeserializeObject <HcProfile>(string.Concat("{", e.ZomeReturnData, "}"));
                    OnPlayerProfileLoaded?.Invoke(this, new ProfileLoadedEventArgs {
                        HcProfile = hcProfile, Profile = ConvertHcProfileToProfile(hcProfile)
                    });

                    //TODO: Want to use these eventually so the async methods can return the results without having to use events/callbacks!
                    _taskCompletionSourceLoadProfile.SetResult(ConvertHcProfileToProfile(JsonConvert.DeserializeObject <HcProfile>(string.Concat("{", e.ZomeReturnData, "}"))));
                    break;

                case SAVE_PROFILE_FUNC:
                    // TODO: Eventually want to return the Profile object from HC with the HCAddressHash set when I work out how! ;-)
                    // The dictonary below can then be removed.

                    //if (string.IsNullOrEmpty(_savingProfiles[e.Id].HcAddressHash))
                    //{
                    //    //TODO: Forced to re-save the object with the address (wouldn't that create a new hash entry?!)
                    _savingProfiles[e.Id].hc_address_hash = e.ZomeReturnData;
                    _savingProfiles[e.Id].provider_key    = e.ZomeReturnData;  //Generic field for providers to store their key (in this case the address hash)

                    //    SaveProfileAsync(_savingProfiles[e.Id]);
                    //}
                    //else
                    //{

                    Profile profile = ConvertHcProfileToProfile(_savingProfiles[e.Id]);
                    OnPlayerProfileSaved?.Invoke(this, new ProfileSavedEventArgs {
                        Profile = profile, HcProfile = _savingProfiles[e.Id]
                    });
                    _taskCompletionSourceSaveProfile.SetResult(profile);
                    _savingProfiles.Remove(e.Id);
                    //}

                    //TODO: Want to use these eventually so the async methods can return the results without having to use events/callbacks!
                    // _taskCompletionSourceIProfile.SetResult(JsonConvert.DeserializeObject<IProfile>(e.ZomeReturnData));
                    break;
                }
            }
        }
Exemple #2
0
 private Profile ConvertHcProfileToProfile(HcProfile profile)
 {
     return(new Profile
     {
         DOB = profile.dob,
         Email = profile.email,
         FirstName = profile.first_name,
         HolonType = profile.holon_type,
         Id = profile.id,
         Karma = profile.karma,
         LastName = profile.last_name,
         Password = profile.password,
         PlayerAddress = profile.player_address,
         ProviderKey = profile.provider_key,
         Title = profile.title,
         Username = profile.username
     });
 }
Exemple #3
0
        /*
         * public override async Task<API.Core.IProfile> SaveProfileAsync(API.Core.IProfile profile)
         * {
         *  await _taskCompletionSourceGetInstance.Task;
         *
         *  if (HoloNETClient.State == System.Net.WebSockets.WebSocketState.Open && !string.IsNullOrEmpty(_hcinstance))
         *  {
         *      if (profile.Id == Guid.Empty)
         *          profile.Id = Guid.NewGuid();
         *
         *      Profile hcProfile = profile as Profile;
         *
         *      if (hcProfile == null)
         *          hcProfile = ConvertProfileToHoloOASISProfile(profile);
         *      else
         *      {
         *          // Rust/HC does not like null strings so need to set to empty string.
         *          if (hcProfile.HcAddressHash == null)
         *              hcProfile.HcAddressHash = string.Empty;
         *
         *          if (hcProfile.ProviderKey == null)
         *              hcProfile.ProviderKey = string.Empty;
         *      }
         *
         *      _currentId++;
         *      _savingProfiles[_currentId.ToString()] = ConvertProfileToHoloOASISProfile(hcProfile);
         *      await HoloNETClient.CallZomeFunctionAsync(_currentId.ToString(), _hcinstance, OURWORLD_ZOME, SAVE_PROFILE_FUNC, new { entry = hcProfile });
         *      return await _taskCompletionSourceSaveProfile.Task;
         *  }
         *
         *  return null;
         * }
         */

        public override async Task <IProfile> SaveProfileAsync(API.Core.IProfile profile)
        {
            await _taskCompletionSourceGetInstance.Task;

            if (HoloNETClient.State == System.Net.WebSockets.WebSocketState.Open && !string.IsNullOrEmpty(_hcinstance))
            {
                if (profile.Id == Guid.Empty)
                {
                    profile.Id = Guid.NewGuid();
                }

                HcProfile hcProfile = profile as HcProfile;

                if (hcProfile == null)
                {
                    hcProfile = ConvertProfileToHoloOASISProfile(profile);
                }
                else
                {
                    // Rust/HC does not like null strings so need to set to empty string.
                    if (hcProfile.hc_address_hash == null)
                    {
                        hcProfile.hc_address_hash = string.Empty;
                    }

                    if (hcProfile.provider_key == null)
                    {
                        hcProfile.provider_key = string.Empty;
                    }
                }

                _currentId++;
                //_savingProfiles[_currentId.ToString()] = ConvertProfileToHoloOASISProfile(hcProfile);
                _savingProfiles[_currentId.ToString()] = hcProfile;
                await HoloNETClient.CallZomeFunctionAsync(_currentId.ToString(), _hcinstance, OURWORLD_ZOME, SAVE_PROFILE_FUNC, new { entry = hcProfile });

                return(await _taskCompletionSourceSaveProfile.Task);
            }

            return(null);
        }