Esempio n. 1
0
        /// <summary>
        /// Registers the SDK license. This class method and must be called before
        /// creating any actual MapView instances.
        /// </summary>
        /// <param name="licenseKey">The license string provided for this application.</param>
        /// <returns>True if license is valid, false if not.</returns>
        public static bool RegisterLicense(string licenseKey)
        {
            ReadKeyDelegate  readKey  = (string key) => { return(NSUserDefaults.StandardUserDefaults.StringForKey(key)); };
            WriteKeyDelegate writeKey = (string key, string value) => { NSUserDefaults.StandardUserDefaults.SetString(value, key); NSUserDefaults.StandardUserDefaults.Synchronize(); };

            return(RegisterLicenseInternal(licenseKey, readKey, writeKey));
        }
Esempio n. 2
0
        /// <summary>
        /// Registers the SDK license. This class method and must be called before
        /// creating any actual MapView instances.
        /// </summary>
        /// <param name="licenseKey">The license string provided for this application.</param>
        /// <returns>True if license is valid, false if not.</returns>
        public static bool RegisterLicense(string licenseKey)
        {
            Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            ReadKeyDelegate  readKey  = (string key) => { return(localSettings.Values[key] as string); };
            WriteKeyDelegate writeKey = (string key, string value) => { localSettings.Values[key] = value; };

            return(RegisterLicenseInternal(licenseKey, readKey, writeKey));
        }
Esempio n. 3
0
        /// <summary>
        /// Registers the SDK license. This class method and must be called before
        /// creating any actual MapView instances.
        /// </summary>
        /// <param name="licenseKey">The license string provided for this application.</param>
        /// <param name="context">Application context for the license.</param>
        /// <returns>True if license is valid, false if not.</returns>
        public static bool RegisterLicense(string licenseKey, Context context) {
            // Connect context info and assets manager to native part
            AndroidUtils.SetContext (context);
            if (_assetManager == null) {
                _assetManager = context.ApplicationContext.Assets;
                AssetUtils.SetAssetManagerPointer(_assetManager);
            }

            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName + "_carto_mobile_sdk1_preferences", FileCreationMode.Private);
            ReadKeyDelegate readKey = (string key) => { return prefs.GetString(key, null); };
            WriteKeyDelegate writeKey = (string key, string value) => { prefs.Edit().PutString(key, value); };
            return RegisterLicenseInternal(licenseKey, readKey, writeKey);
        }
Esempio n. 4
0
File: RdMap.cs Progetto: yvvan/rd
        public override void OnWireReceived(UnsafeReader stream)
        {
            var header       = stream.ReadInt();
            var msgVersioned = (header >> versionedFlagShift) != 0;
            var opType       = header & ((1 << versionedFlagShift) - 1);

            var version = msgVersioned ? stream.ReadLong() : 0L;

            var key = ReadKeyDelegate(SerializationContext, stream);

            if (opType == Ack)
            {
                string error = null;

                if (!msgVersioned)
                {
                    error = "Received ACK while msg hasn't versioned flag set";
                }
                else if (!IsMaster)
                {
                    error = "Received ACK when not a Master";
                }
                else if (!myPendingForAck.TryGetValue(key, out var pendingVersion))
                {
                    error = "No pending for ACK";
                }
                else if (pendingVersion < version)
                {
                    error = $"Pending version `{pendingVersion}` < ACK version `{version}`";
                }
                // Good scenario
                else if (pendingVersion == version)
                {
                    myPendingForAck.Remove(key);
                }
                //else do nothing, silently drop

                var isError = !string.IsNullOrEmpty(error);
                if (ourLogReceived.IsTraceEnabled() || isError)
                {
                    ourLogReceived.LogFormat(isError ? LoggingLevel.ERROR : LoggingLevel.TRACE,
                                             "{0}  :: ACK :: key = {1} :: version = {2}{3}", this, key.PrintToString(), version,
                                             isError ? " >> " + error : "");
                }
            }
            else
            {
                using (UsingDebugInfo())
                {
                    var kind = (AddUpdateRemove)opType;
                    switch (kind)
                    {
                    case AddUpdateRemove.Add:
                    case AddUpdateRemove.Update:
                        var value = ReadValueDelegate(SerializationContext, stream);

                        ReceiveTrace?.Log($"{this} :: {kind} :: key = {key.PrintToString()}" +
                                          (msgVersioned ? " :: version = " + version : "") +
                                          $" :: value = {value.PrintToString()}"
                                          );


                        if (msgVersioned || !IsMaster || !myPendingForAck.ContainsKey(key))
                        {
                            myMap[key] = value;
                        }
                        else
                        {
                            ReceiveTrace?.Log(">> CHANGE IGNORED");
                        }

                        break;

                    case AddUpdateRemove.Remove:

                        ReceiveTrace?.Log($"{this} :: {kind} :: key = {key.PrintToString()}"
                                          + (msgVersioned ? " :: version = " + version : "")
                                          );


                        if (msgVersioned || !IsMaster || !myPendingForAck.ContainsKey(key))
                        {
                            myMap.Remove(key);
                        }
                        else
                        {
                            ReceiveTrace?.Log(">> CHANGE IGNORED");
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(kind.ToString());
                    }
                }

                if (msgVersioned)
                {
                    Wire.Send(RdId, (innerWriter) =>
                    {
                        innerWriter.Write((1 << versionedFlagShift) | Ack);
                        innerWriter.Write(version);
                        WriteKeyDelegate.Invoke(SerializationContext, innerWriter, key);

                        SendTrace?.Log($"{this} :: ACK :: key = {key.PrintToString()} :: version = {version}");
                    });

                    if (IsMaster)
                    {
                        ourLogReceived.Error("Both ends are masters: {0}", Location);
                    }
                }
            }
        }
Esempio n. 5
0
        private static bool RegisterLicenseInternal(string licenseKey, ReadKeyDelegate readKey, WriteKeyDelegate writeKey)
        {
            string oldKey = "license_key_old";
            string newKey = "license_key_new";
            LicenseManagerListener listener = new MapLicenseManagerListener((string updatedLicenseKey) => {
                try {
                    writeKey(newKey, updatedLicenseKey);
                }
                catch (System.Exception e) {
                    Carto.Utils.Log.Error("MapView.RegisterLicense: Failed to save license key: " + e);
                }
            });
            string newLicenseKey = null;

            try {
                string oldLicenseKey = readKey(oldKey);
                if (oldLicenseKey != null && oldLicenseKey != licenseKey)
                {
                    newLicenseKey = readKey(newKey);
                }
            }
            catch (System.Exception e) {
                Carto.Utils.Log.Error("MapView.RegisterLicense: Failed to read license key: " + e);
            }
            return(BaseMapView.RegisterLicense(newLicenseKey != null ? newLicenseKey : licenseKey, listener));
        }