コード例 #1
0
        private void OnIdentityButton_Click(object sender, RoutedEventArgs e)
        {
            string content         = ((Button)sender).Content as string;
            var    customerId      = (FindName("customerIdInput") as TextBox).Text;
            var    email           = (FindName("emailInput") as TextBox).Text;
            var    identityRequest = IdentityApiRequest.EmptyUser()
                                     .CustomerId(customerId)
                                     .Email(email)
                                     .Build();
            Task <IdentityApiResult> task = null;

            switch (content)
            {
            case "Identify":
                task = MParticle.Instance.Identity.IdentifyAsync(identityRequest);
                break;

            case "Login":
                task = MParticle.Instance.Identity.LoginAsync(identityRequest);
                break;

            case "Logout":
                task = MParticle.Instance.Identity.LogoutAsync(identityRequest);
                break;

            case "Modify":
                task = MParticle.Instance.Identity.CurrentUser?.ModifyAsync(identityRequest);
                break;
            }

            App.HandleIdentityTaskAsync(task);
        }
コード例 #2
0
        internal AndroidJavaObject ConvertToMpIdentifyRequest(IdentityApiRequest request)
        {
            AndroidJavaObject builder = new AndroidJavaClass("com.mparticle.identity.IdentityApiRequest").CallStatic <AndroidJavaObject>("withEmptyUser");

            request.UserIdentities.ToList().ForEach(pair => builder.Call <AndroidJavaObject>("userIdentity", new object[] { ConvertToMpUserIdentity(pair.Key), pair.Value }));
            if (request.UserAliasHandler != null)
            {
                builder.Call <AndroidJavaObject>("userAliasHandler", new object[] { new AndroidUserAliasHandler(request.UserAliasHandler) });
            }
            return(builder.Call <AndroidJavaObject>("build"));
        }
コード例 #3
0
        internal static iOSBinding.MPIdentityApiRequest ConvertToMpIdentityRequest(IdentityApiRequest request)
        {
            var mpRequest = new iOSBinding.MPIdentityApiRequest();

            request.UserIdentities.ToList().ForEach(pair =>
            {
                mpRequest.UserIdentities.Add(
                    new NSNumber((float)(int)pair.Key),
                    new NSString(pair.Value));
            });
            mpRequest.OnUserAlias = new iOSBinding.OnUserAlias((previousUser, newUser) => request.UserAliasHandler.Invoke(new MParticleUserWrapper(previousUser), new MParticleUserWrapper(newUser)));
            return(mpRequest);
        }
コード例 #4
0
        public IMParticleTask <IdentityApiResult> Modify(IdentityApiRequest request)
        {
            string userAliasUuid = request.UserAliasHandler != null?getRandomKey() : null;

            string taskUuid    = getRandomKey();
            string requestJSON = toUtils.SerializeDictionary(new IdentityApiRequestDto(request, taskUuid, userAliasUuid));

            MParticleiOS._Identity_Modify(requestJSON);
            BaseTask baseTask = new BaseTask();

            _taskCallbacks.Add(taskUuid, baseTask);
            return(baseTask);
        }
コード例 #5
0
        public IMParticleTask <IdentityApiResult> Logout(IdentityApiRequest request = null)
        {
            AndroidJavaObject task;

            if (request == null)
            {
                task = identityObject.Call <AndroidJavaObject>("logout");
            }
            else
            {
                task = identityObject.Call <AndroidJavaObject>("logout", new object[] { toUtils.ConvertToMpIdentifyRequest(request) });
            }
            return(new IdentifyTaskImpl(task));
        }
コード例 #6
0
        internal static iOSBinding.MPIdentityApiRequest ConvertToMpIdentityRequest(IdentityApiRequest request)
        {
            if (request == null)
            {
                return(null);
            }
            var mpRequest = new iOSBinding.MPIdentityApiRequest();

            if (request.UserIdentities != null)
            {
                request.UserIdentities.ToList().ForEach(pair =>
                {
                    mpRequest.SetIdentity(new NSString(pair.Value), (MPUserIdentity)pair.Key);
                });
            }
            return(mpRequest);
        }
コード例 #7
0
 internal IdentityApiRequestDto(IdentityApiRequest request, string taskUUID = null, string userAliasUUID = null)
 {
     if (userAliasUUID != null)
     {
         Add(UserAliasUUID, userAliasUUID);
     }
     if (request != null)
     {
         Dictionary <string, string> userIdentities = new Dictionary <string, string>();
         request.UserIdentities.ToList().ForEach(pair => userIdentities.Add(((int)pair.Key).ToString(), pair.Value));
         Add(UserIdentities, userIdentities);
     }
     if (taskUUID != null)
     {
         Add(TaskUUID, taskUUID);
     }
 }
コード例 #8
0
        public IMParticleTask <IdentityApiResult> Logout(IdentityApiRequest request = null)
        {
            string   taskUuid = getRandomKey();
            BaseTask baseTask = new BaseTask();

            _taskCallbacks.Add(taskUuid, baseTask);
            string userAliasUuid = null;

            if (request != null)
            {
                userAliasUuid = addUserAliasHandler(request.UserAliasHandler);
            }
            string requestJSON = toUtils.SerializeDictionary(new IdentityApiRequestDto(request, taskUuid, userAliasUuid));

            MParticleiOS._Identity_Logout(requestJSON);
            return(baseTask);
        }
コード例 #9
0
        protected override void OnLaunched(LaunchActivatedEventArgs launchArgs)
        {
            // Create an Identity Request:
            // The SDK will automatically make an Identify() request during initialization,
            // if you know identities of the current-user, you should provide them.
            // Otherwise, the SDK will use the Identities of the most recent user.
            var identifyRequest = IdentityApiRequest.EmptyUser()
                                  .CustomerId("foo")
                                  .Email("bar")
                                  .Build();

            // Create an MParticleOptions object:
            // You must at least provide an mParticle workspace key and secret
            MParticleOptions options =
                MParticleOptions.Builder(apiKey: "REPLACE ME", apiSecret: "REPLACE ME")
                .IdentifyRequest(identifyRequest)
                .LaunchArgs(launchArgs)
                .Logger(new ExampleConsoleLogger())
                .Build();

            // Initialize the mParticle SDK:
            // You must do this prior to calling MParticle.Instance
            var task = MParticle.StartAsync(options);

            HandleIdentityTaskAsync(task);

            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }

            if (launchArgs.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    rootFrame.Navigate(typeof(MainPage), launchArgs.Arguments);
                }
                Window.Current.Activate();
            }
        }
コード例 #10
0
        public override IMParticleTask <IdentityApiResult> Login(IdentityApiRequest request = null)
        {
            BaseTaskWrapper             task     = new BaseTaskWrapper();
            MPIdentityApiResultCallback callback = (MPIdentityApiResult apiResult, Foundation.NSError error) =>
            {
                if (error != null)
                {
                    task.Failure = new IdentityHttpResponseWrapper(error);
                }
                if (apiResult != null && apiResult.User != null)
                {
                    task.Result = new IdentityApiResult()
                    {
                        User = apiResult != null ? new MParticleUserWrapper(apiResult.User) : null
                    };
                }
            };

            _identityApi.Login(Utils.ConvertToMpIdentityRequest(request), callback);
            return(task);
        }
コード例 #11
0
        public override IMParticleTask <IdentityApiResult> Identify(IdentityApiRequest request = null)
        {
            BaseTaskWrapper             task     = new BaseTaskWrapper();
            MPIdentityApiResultCallback callback = (MPIdentityApiResult apiResult, Foundation.NSError error) =>
            {
                if (error != null)
                {
                    task.Failure = new IdentityHttpResponseWrapper(error);
                }
                if (apiResult != null && apiResult.User != null)
                {
                    task.Result = new IdentityApiResult()
                    {
                        User = new MParticleUserWrapper(apiResult.User)
                    };
                }
            };

            iOSBinding.MParticle.SharedInstance.Identity.Identify(Utils.ConvertToMpIdentityRequest(request), callback);
            return(task);
        }
コード例 #12
0
 internal static IdentityBinding.IdentityApiRequest ConvertToMpIdentityRequest(IdentityApiRequest request)
 {
     if (request == null)
     {
         return(null);
     }
     Android.IdentityBinding.IdentityApiRequest.Builder builder = Android.IdentityBinding.IdentityApiRequest.WithEmptyUser();
     if (request.UserIdentities != null)
     {
         foreach (var identityType in request.UserIdentities.Keys)
         {
             builder.UserIdentity(AndroidBinding.MParticle.IdentityType.ValueOf(identityType.ToString()), request.UserIdentities.GetValueOrDefault(identityType));
         }
     }
     if (request.UserAliasHandler != null)
     {
         builder.UserAliasHandler(new UserAliasHandlerWrapper(request.UserAliasHandler));
     }
     return(builder.Build());
 }
コード例 #13
0
        public IMParticleTask <IdentityApiResult> Modify(IdentityApiRequest request)
        {
            var task = identityObject.Call <AndroidJavaObject>("modify", new object[] { toUtils.ConvertToMpIdentifyRequest(request) });

            return(new IdentifyTaskImpl(task));
        }
コード例 #14
0
        public override IMParticleTask <IdentityApiResult> Modify(IdentityApiRequest request)
        {
            var task = _identity.Modify(Utils.ConvertToMpIdentityRequest(request));

            return(task == null ? null : new MParticleTaskWrapper((BaseIdentityTask)task));
        }