// Initialize the default starting properties. Should only be called once by MobileAppTracker.
        public MATParameters(string advId, string advKey, byte[] bytes)
        {
            this.culture = new CultureInfo("en-US");

            this.advertiserId  = advId;
            this.advertiserKey = advKey;

            this.localSettings = ApplicationData.Current.LocalSettings;

            this.urlEncrypter = new MATEncryption(advKey, MATConstants.IV);

            this.matResponse = null;

            // Default values
            this.AllowDuplicates = false;
            this.DebugMode       = false;
            this.ExistingUser    = false;
            this.AppAdTracking   = true;
            this.Gender          = MATGender.NONE;

            this.WindowsAid = AdvertisingManager.AdvertisingId;

            // Get app name asynchronously from appxmanifest
            this.AppName = GetAppName();

            var version = Package.Current.Id.Version;

            this.AppVersion = String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);

            // Use local package name by default
            this.PackageName = Package.Current.Id.Name;
            try
            {
                // If there's a store app id, use it
                if (CurrentApp.AppId != Guid.Empty)
                {
                    this.PackageName = CurrentApp.AppId.ToString();
                }
            }
            catch
            {
            }

            // Get device info
            EasClientDeviceInformation info = new EasClientDeviceInformation();

            this.DeviceBrand = info.SystemManufacturer.ToString();
            this.DeviceModel = info.SystemProductName.ToString();
            this.DeviceType  = info.OperatingSystem.ToString(); //Windows or WindowsPhone

            // Get ASHWID
            this.ASHWID = BitConverter.ToString(bytes);

            // Check if we can restore existing MAT ID or should generate new one
            if (localSettings.Values.ContainsKey(MATConstants.SETTINGS_MATID_KEY))
            {
                this.MatId = (string)localSettings.Values[MATConstants.SETTINGS_MATID_KEY];
            }
            else // Don't have MAT ID, generate new guid
            {
                this.MatId = System.Guid.NewGuid().ToString();
                SaveLocalSetting(MATConstants.SETTINGS_MATID_KEY, this.MatId);
            }

            // Get saved values from LocalSettings
            if (GetLocalSetting(MATConstants.SETTINGS_PHONENUMBER_KEY) != null)
            {
                this.PhoneNumber       = (string)GetLocalSetting(MATConstants.SETTINGS_PHONENUMBER_KEY);
                this.PhoneNumberMd5    = MATEncryption.Md5(this.PhoneNumber);
                this.PhoneNumberSha1   = MATEncryption.Sha1(this.PhoneNumber);
                this.PhoneNumberSha256 = MATEncryption.Sha256(this.PhoneNumber);
            }

            if (GetLocalSetting(MATConstants.SETTINGS_USEREMAIL_KEY) != null)
            {
                this.UserEmail       = (string)GetLocalSetting(MATConstants.SETTINGS_USEREMAIL_KEY);
                this.UserEmailMd5    = MATEncryption.Md5(this.UserEmail);
                this.UserEmailSha1   = MATEncryption.Sha1(this.UserEmail);
                this.UserEmailSha256 = MATEncryption.Sha256(this.UserEmail);
            }

            this.UserId = (string)GetLocalSetting(MATConstants.SETTINGS_USERID_KEY);

            if (GetLocalSetting(MATConstants.SETTINGS_USERNAME_KEY) != null)
            {
                this.UserName       = (string)GetLocalSetting(MATConstants.SETTINGS_USERNAME_KEY);
                this.UserNameMd5    = MATEncryption.Md5(this.UserName);
                this.UserNameSha1   = MATEncryption.Sha1(this.UserName);
                this.UserNameSha256 = MATEncryption.Sha256(this.UserName);
            }
        }
Esempio n. 2
0
        // Initialize the default starting properties. Should only be called once by MobileAppTracker.
        public MATParameters(string advId, string advKey, byte[] bytes)
        {
            this.culture = new CultureInfo("en-US");

            this.advertiserId = advId;
            this.advertiserKey = advKey;

            this.localSettings = ApplicationData.Current.LocalSettings;

            this.urlEncrypter = new MATEncryption(advKey, MATConstants.IV);

            this.matResponse = null;

            // Default values
            this.AllowDuplicates = false;
            this.DebugMode = false;
            this.ExistingUser = false;
            this.AppAdTracking = true;
            this.Gender = MATGender.NONE;

            this.WindowsAid = AdvertisingManager.AdvertisingId;

            // Get app name asynchronously from appxmanifest
            this.AppName = GetAppName();

            var version = Package.Current.Id.Version;
            this.AppVersion = String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);

            // Use local package name by default
            this.PackageName = Package.Current.Id.Name;
            try
            {
                // If there's a store app id, use it
                if (CurrentApp.AppId != Guid.Empty)
                {
                    this.PackageName = CurrentApp.AppId.ToString();
                }
            }
            catch
            {
            }

            // Get device info
            EasClientDeviceInformation info = new EasClientDeviceInformation();

            this.DeviceBrand = info.SystemManufacturer.ToString();
            this.DeviceModel = info.SystemProductName.ToString();
            this.DeviceType = info.OperatingSystem.ToString(); //Windows or WindowsPhone

            // Get ASHWID
            this.ASHWID = BitConverter.ToString(bytes);

            // Check if we can restore existing MAT ID or should generate new one
            if (localSettings.Values.ContainsKey(MATConstants.SETTINGS_MATID_KEY))
            {
                this.MatId = (string)localSettings.Values[MATConstants.SETTINGS_MATID_KEY];
            }
            else // Don't have MAT ID, generate new guid
            {
                this.MatId = System.Guid.NewGuid().ToString();
                SaveLocalSetting(MATConstants.SETTINGS_MATID_KEY, this.MatId);
            }

            // Get saved values from LocalSettings
            if (GetLocalSetting(MATConstants.SETTINGS_PHONENUMBER_KEY) != null) {
                this.PhoneNumber = (string)GetLocalSetting(MATConstants.SETTINGS_PHONENUMBER_KEY);
                this.PhoneNumberMd5 = MATEncryption.Md5(this.PhoneNumber);
                this.PhoneNumberSha1 = MATEncryption.Sha1(this.PhoneNumber);
                this.PhoneNumberSha256 = MATEncryption.Sha256(this.PhoneNumber);
            }

            if (GetLocalSetting(MATConstants.SETTINGS_USEREMAIL_KEY) != null)
            {
                this.UserEmail = (string)GetLocalSetting(MATConstants.SETTINGS_USEREMAIL_KEY);
                this.UserEmailMd5 = MATEncryption.Md5(this.UserEmail);
                this.UserEmailSha1 = MATEncryption.Sha1(this.UserEmail);
                this.UserEmailSha256 = MATEncryption.Sha256(this.UserEmail);
            }

            this.UserId = (string)GetLocalSetting(MATConstants.SETTINGS_USERID_KEY);

            if (GetLocalSetting(MATConstants.SETTINGS_USERNAME_KEY) != null)
            {
                this.UserName = (string)GetLocalSetting(MATConstants.SETTINGS_USERNAME_KEY);
                this.UserNameMd5 = MATEncryption.Md5(this.UserName);
                this.UserNameSha1 = MATEncryption.Sha1(this.UserName);
                this.UserNameSha256 = MATEncryption.Sha256(this.UserName);
            }
        }
        //Initialize the default starting properties. Should only be called once by MobileAppTracker.
        internal MATParameters(string advId, string advKey)
        {
            // Initialize Parameters
            this.advertiserId  = advId;
            this.advertiserKey = advKey;

            matResponse = null;

            this.AllowDuplicates = false;
            this.DebugMode       = false;
            this.ExistingUser    = false;
            this.AppAdTracking   = true;
            this.Gender          = MATGender.NONE;

            // Get Windows AID through Reflection if app on WP8.1 device
            var type = Type.GetType("Windows.System.UserProfile.AdvertisingManager, Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime");

            this.WindowsAid = type != null ? (string)type.GetProperty("AdvertisingId").GetValue(null, null) : null;


            // If app has a Store app id, use it as package name
            if (CurrentApp.AppId != Guid.Empty)
            {
                this.PackageName = CurrentApp.AppId.ToString();
            }
            else
            {
                // Fallback is to try to get WMAppManifest ProductID
                XElement app = XDocument.Load("WMAppManifest.xml").Root.Element("App");
                this.AppName    = GetValue(app, "Title");
                this.AppVersion = GetValue(app, "Version");

                string productId = GetValue(app, "ProductID");
                if (productId != null)
                {
                    this.PackageName = Regex.Match(productId, "(?<={).*(?=})").Value;
                }
            }

            byte[] deviceUniqueId = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");
            this.DeviceUniqueId = Convert.ToBase64String(deviceUniqueId);
            this.DeviceBrand    = DeviceStatus.DeviceManufacturer;
            this.DeviceModel    = DeviceStatus.DeviceName;
            this.DeviceCarrier  = DeviceNetworkInformation.CellularMobileOperator;

            Version version = Environment.OSVersion.Version;

            this.OSVersion        = String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
            this.DeviceScreenSize = GetScreenRes();

            // Check if we can restore existing MAT ID or should generate new one
            if (IsolatedStorageSettings.ApplicationSettings.Contains(MATConstants.SETTINGS_MATID_KEY))
            {
                this.MatId = (string)IsolatedStorageSettings.ApplicationSettings[MATConstants.SETTINGS_MATID_KEY];
            }
            else // Don't have MAT ID, generate new guid
            {
                this.MatId = System.Guid.NewGuid().ToString();
                SaveLocalSetting(MATConstants.SETTINGS_MATID_KEY, this.MatId);
            }

            // Get saved values from LocalSettings
            if (GetLocalSetting(MATConstants.SETTINGS_PHONENUMBER_KEY) != null)
            {
                this.PhoneNumber       = (string)GetLocalSetting(MATConstants.SETTINGS_PHONENUMBER_KEY);
                this.PhoneNumberMd5    = MATEncryption.Md5(this.PhoneNumber);
                this.PhoneNumberSha1   = MATEncryption.Sha1(this.PhoneNumber);
                this.PhoneNumberSha256 = MATEncryption.Sha256(this.PhoneNumber);
            }

            if (GetLocalSetting(MATConstants.SETTINGS_USEREMAIL_KEY) != null)
            {
                this.UserEmail       = (string)GetLocalSetting(MATConstants.SETTINGS_USEREMAIL_KEY);
                this.UserEmailMd5    = MATEncryption.Md5(this.UserEmail);
                this.UserEmailSha1   = MATEncryption.Sha1(this.UserEmail);
                this.UserEmailSha256 = MATEncryption.Sha256(this.UserEmail);
            }

            this.UserId = (string)GetLocalSetting(MATConstants.SETTINGS_USERID_KEY);

            if (GetLocalSetting(MATConstants.SETTINGS_USERNAME_KEY) != null)
            {
                this.UserName       = (string)GetLocalSetting(MATConstants.SETTINGS_USERNAME_KEY);
                this.UserNameMd5    = MATEncryption.Md5(this.UserName);
                this.UserNameSha1   = MATEncryption.Sha1(this.UserName);
                this.UserNameSha256 = MATEncryption.Sha256(this.UserName);
            }
        }