示例#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));
        }
示例#2
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));
        }
示例#3
0
        public static char ReadKey(int secTimeOut, char @default)
        {
            rendererEvent.Reset();

            try
            {
                ReadKeyDelegate d      = Console.ReadKey;
                IAsyncResult    result = d.BeginInvoke(null, null);
                result.AsyncWaitHandle.WaitOne(secTimeOut * 1000); // timeout e.g. 15000 for 15 secs

                if (result.IsCompleted)
                {
                    ConsoleKeyInfo resultstr = d.EndInvoke(result);
                    //Console.WriteLine("Read: " + resultstr.KeyChar);

                    Console.WriteLine();
                    return(resultstr.KeyChar);
                }
                else
                {
                    //Console.WriteLine("Timed out!");
                    //throw new TimedoutException("Timed Out!");

                    Console.WriteLine();
                    return(@default);
                }
            }
            finally
            {
                rendererEvent.Set();
            }
        }
示例#4
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));
        }
示例#5
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);
        }
示例#6
0
文件: Game.cs 项目: tdisaster/snake
        Direction GetDirection(Direction defaultDirection, int duration)
        {
            ReadKeyDelegate d = Console.ReadKey;

            if (duration <= 0)
            {
                return(defaultDirection);
            }

            if (ReadResult == null || ReadResult.IsCompleted)
            {
                ReadResult   = d.BeginInvoke(null, null);
                _oldDelegate = d;
            }

            ReadResult.AsyncWaitHandle.WaitOne(duration);
            if (ReadResult.IsCompleted)
            {
                ConsoleKeyInfo resultstr = _oldDelegate.EndInvoke(ReadResult);
                switch (resultstr.Key)
                {
                case ConsoleKey.UpArrow:
                    return(Direction.Up);

                case ConsoleKey.DownArrow:
                    return(Direction.Down);

                case ConsoleKey.LeftArrow:
                    return(Direction.Left);

                case ConsoleKey.RightArrow:
                    return(Direction.Right);

                default:
                    return(defaultDirection);
                }
            }

            return(defaultDirection);
        }