public void TestSessionStorage()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(new PackageVersion());
            Session fooSession = new Session();

            fooSession.AddMpid(new MParticleUser(4, persistenceManager));
            persistenceManager.LastSession = fooSession;
            Session fooSession2 = persistenceManager.LastSession;

            Assert.AreEqual(fooSession.Id, fooSession2.Id);
            Assert.AreEqual(fooSession.StartTimeMillis, fooSession2.StartTimeMillis);
            CollectionAssert.AreEqual((List <long>)fooSession.Mpids, (List <long>)fooSession2.Mpids);

            Session fooSession3 = new Session();

            fooSession3.LastEventTimeMillis = 123;
            fooSession3.AddMpid(new MParticleUser(10, persistenceManager));
            fooSession3.BackgroundTime     = 456;
            persistenceManager.LastSession = fooSession3;

            Session fooSession4 = persistenceManager.LastSession;

            Assert.AreEqual(fooSession3.Id, fooSession4.Id);
            Assert.AreEqual(fooSession3.StartTimeMillis, fooSession4.StartTimeMillis);
            Assert.AreEqual(fooSession3.LastEventTimeMillis, fooSession4.LastEventTimeMillis);
            Assert.AreEqual(fooSession3.BackgroundTime, fooSession4.BackgroundTime);
            CollectionAssert.AreEqual((List <long>)fooSession3.Mpids, (List <long>)fooSession4.Mpids);
        }
Example #2
0
        public void CleanupTests()
        {
            var manager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            manager.Initialize(new PackageVersion());
            manager.Clear();
        }
Example #3
0
 /// <summary>
 /// Initializes the SDK. This method must be called prior to any other method.
 /// </summary>
 /// <example>
 /// This method should be called within
 /// the <see cref="Application.OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)"/> method.
 /// <code>
 ///
 /// protected override void OnLaunched(LaunchActivatedEventArgs launchArgs)
 /// {
 ///    MParticleOptions options = new MParticleOptions()
 ///    {
 ///        ApiKey = "REPLACE ME",
 ///        ApiSecret = "REPLACE ME",
 ///        LaunchArgs = launchArgs
 ///    };
 ///
 ///    MParticle.Start(options);
 /// }
 /// </code>
 /// </example>
 /// <param name="options">Required - at minimum you must supply an mParticle workspace key and secret.</param>
 public static async Task <IdentityApiResult> StartAsync(MParticleOptions options)
 {
     if (instance == null)
     {
         lock (mutex)
         {
             if (instance == null)
             {
                 instance = new MParticle(Application.Current, options);
                 instance.Application_Launched();
                 instance.Identity.IdentityStateChange += instance.Identity_IdentityStateChange;
             }
         }
         var request = options.IdentifyRequest ?? IdentityApiRequest.WithUser(instance.Identity.CurrentUser).Build();
         return(await instance.Identity.IdentifyAsync(request));
     }
     return(new IdentityApiResult()
     {
         Error = new ErrorResponse()
         {
             StatusCode = IdentityApi.UnknownError,
             Errors = new Error[] {
                 new Error()
                 {
                     Message = "The SDK has already started."
                 }
             }
         }
     });
 }
        public void TestDeviceApplicationStamp()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            Assert.IsNull(persistenceManager.DeviceApplicationStamp);
            persistenceManager.DeviceApplicationStamp = "foo das";
            Assert.AreEqual("foo das", persistenceManager.DeviceApplicationStamp);
        }
        public void TestIsFirstRun()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            Assert.AreEqual(true, persistenceManager.IsFirstRun);
            persistenceManager.Initialize(Package.Current.Id.Version);
            Assert.AreEqual(false, persistenceManager.IsFirstRun);
        }
Example #6
0
        public void TestGetUserIdentitiesNoIdentities()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            var user       = new MParticleUser(5, persistenceManager);
            var identities = user.UserIdentities;

            Assert.AreEqual(0, identities.Count);
        }
        public void TestNoUserIdentities()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            var identities = persistenceManager.UserIdentities(1);

            Assert.IsNotNull(identities);
            Assert.AreEqual(0, identities.Count);
        }
Example #8
0
        public void TestSetUserAttributes()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            var user = new MParticleUser(5, persistenceManager);

            user.UserAttribute("foo attribute key", "foo value");
            Assert.AreEqual("foo value", user.UserAttributes["foo attribute key"]);
        }
Example #9
0
        public void TestSetUserAttributeTag()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            var user = new MParticleUser(5, persistenceManager);

            user.UserTag("foo user attribute tag");
            Assert.AreEqual(1, user.UserAttributes.Count);
            Assert.IsTrue(user.UserAttributes.ContainsKey("foo user attribute tag"));
        }
Example #10
0
        public void TestSetUserAttributeList()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            var user = new MParticleUser(5, persistenceManager);
            var attributeValueList = new List <string>();

            attributeValueList.Add("foo item 1");
            user.UserAttribute("foo attribute list key", attributeValueList);
            Assert.AreEqual("foo item 1", ((IList <string>)user.UserAttributes["foo attribute list key"])[0]);
        }
Example #11
0
        public void TestRemoveUserAttribute()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            var user = new MParticleUser(5, persistenceManager);

            user.UserTag("foo user attribute tag 1");
            user.UserTag("foo user attribute tag 2");
            Assert.AreEqual(2, user.UserAttributes.Count);
            user.RemoveUserAttribute("foo user attribute tag 1");
            Assert.AreEqual(1, user.UserAttributes.Count);
        }
        public void TestGenerateDeviceApplicationStamp()
        {
            var manager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            manager.Initialize(new PackageVersion());
            Assert.IsNull(manager.DeviceApplicationStamp);
            var identityApi = new IdentityApi("foo", "bar", manager);
            var das         = identityApi.GenerateDasIfNeeded();

            Assert.IsTrue(!string.IsNullOrEmpty(das));
            var das2 = identityApi.GenerateDasIfNeeded();

            Assert.AreEqual(das, das2);
            Assert.AreEqual(das, manager.DeviceApplicationStamp);
        }
        public void TestAddDeviceIdentities()
        {
            var manager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            manager.Initialize(new PackageVersion());
            var identityApi = new IdentityApi("foo", "bar", manager);
            var identities  = new Identities();

            Assert.AreEqual(0, identities.Count);
            identityApi.AddDeviceIdentities(identities);
            Assert.IsNotNull(identities[IdentityType.DeviceApplicationStamp]);
            Assert.AreEqual(identityApi.GenerateDasIfNeeded(), identities[IdentityType.DeviceApplicationStamp]);
            Assert.IsNotNull(identities[IdentityType.MicrosoftAdvertisingId]);
            Assert.AreEqual(DeviceInfoBuilder.QueryAdvertisingId(), identities[IdentityType.MicrosoftAdvertisingId]);
            Assert.IsNotNull(identities[IdentityType.MicrosoftPublisherId]);
            Assert.AreEqual(DeviceInfoBuilder.QueryPublisherId(), identities[IdentityType.MicrosoftPublisherId]);
        }
        public void TestIsUpgrade()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());
            PackageVersion     version1           = new PackageVersion()
            {
                Major = 1
            };
            PackageVersion version2 = new PackageVersion()
            {
                Major = 2
            };

            persistenceManager.Initialize(version1);
            Assert.AreEqual(false, persistenceManager.IsUpgrade);
            persistenceManager.Initialize(version2);
            Assert.AreEqual(true, persistenceManager.IsUpgrade);
            persistenceManager.Initialize(version2);
            Assert.AreEqual(false, persistenceManager.IsUpgrade);
        }
        public void TestAddUserIdentities()
        {
            var manager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            manager.Initialize(new PackageVersion());
            var identityApi = new IdentityApi("foo", "bar", manager);
            var identities  = new Identities();

            Assert.AreEqual(0, identities.Count);
            var apiRequest = IdentityApiRequest.EmptyUser()
                             .CustomerId("foo customer id")
                             .Email("foo email")
                             .UserIdentity(Core.Dto.Events.UserIdentityType.Google, "foo google")
                             .Build();

            IdentityApi.AddUserIdentities(identities, apiRequest);
            Assert.AreEqual(identities[IdentityType.CustomerId], "foo customer id");
            Assert.AreEqual(identities[IdentityType.Email], "foo email");
            Assert.AreEqual(identities[IdentityType.Google], "foo google");
        }
Example #16
0
        public void TestGetUserIdentities()
        {
            PersistenceManager persistenceManager = new PersistenceManager(MParticleOptions.Builder("foo", "bar").Build());

            persistenceManager.Initialize(Package.Current.Id.Version);
            IList <UserIdentity> userIdentities = new List <UserIdentity>();
            UserIdentity         identity       = new UserIdentity();

            identity.DateFirstSet = 123;
            identity.Identity     = "foo identity";
            identity.IsFirstSeen  = true;
            identity.Name         = UserIdentityType.Twitter;
            userIdentities.Add(identity);
            persistenceManager.SetUserIdentities(5, userIdentities);
            var user       = new MParticleUser(5, persistenceManager);
            var identities = user.UserIdentities;

            Assert.AreEqual(1, identities.Count);
            Assert.AreEqual("foo identity", identities[UserIdentityType.Twitter]);
        }
Example #17
0
        private MParticle(Application application, MParticleOptions options)
        {
            this.Options                        = options ?? throw new InvalidOperationException("MParticle must be initialized with a non-null MParticleOptions object.");
            this.application                    = application;
            this.application.Suspending        += Application_Suspending;
            this.application.Resuming          += Application_Resuming;
            this.application.EnteredBackground += Application_EnteredBackground;
            this.application.LeavingBackground += Application_LeavingBackground;

            this.apiManager = new EventsApiClient(options.ApiKey, options.ApiSecret);
            this.apiManager.UploadInterval = TimeSpan.FromSeconds(options.UploadIntervalSeconds);
            this.apiManager.UserAgent      = UserAgent;
            this.apiManager.Logger         = options.Logger;
            this.persistenceManager        = new PersistenceManager(options);
            this.persistenceManager.Initialize(Package.Current.Id.Version);
            this.messageManager         = new MessageManager(apiManager, persistenceManager);
            this.messageManager.Enabled = !persistenceManager.IsOptOut;
            this.sessionManager         = new SessionManager(messageManager, persistenceManager);
            this.Identity        = new IdentityApi(options.ApiKey, options.ApiSecret, persistenceManager);
            this.Identity.Logger = options.Logger;
        }
Example #18
0
 public PersistenceManager(MParticleOptions options)
 {
     this.options = options;
 }