/// <summary>
        /// Initialize method
        /// </summary>
        /// <param name="key"></param>
        /// <param name="uniqueId"></param>
        //public void Initialize(string uniqueId, string key)
        //{
        //    OnBoolChange(false, 0, PasswordManagementConstants.BoolEvaluatedChange);

        //    try
        //    {
        //        if(string.IsNullOrEmpty(uniqueId) || string.IsNullOrEmpty(key))
        //        {
        //            Debug.Console(1, "PasswordManager.Initialize({0}, {1}) null or empty parameters", uniqueId, key);
        //            return;
        //        }

        //        JsonToSimplMaster master = J2SGlobal.GetMasterByFile(uniqueId);
        //        if(master == null)
        //        {
        //            Debug.Console(1, "PassowrdManager.Initialize failed:\rCould not find JSON file with uniqueID {0}", uniqueId);
        //            return;
        //        }

        //        var global = master.JsonObject.ToObject<RootObject>().global;
        //        var passwords = global.passwords;
        //        if(passwords == null)
        //        {
        //            Debug.Console(1, "PasswordManager.Initialize failed:\rCould not find password object");
        //            return;
        //        }

        //        foreach(var password in passwords)
        //        {
        //            if (password != null)
        //            {
        //                var index = passwords.IndexOf(password);

        //                password.path = string.Format("global.passwords[{0}]", index);
        //                Debug.Console(1, "PasswordManager.Initialize: {0}, {1}, {2}, {3}, {4}, {5}", password.key, password.name, password.simplEnabled, password.simplType, password.password, password.path);
        //                //AddPassword(password);

        //                OnStringChange(password.path, (ushort)index, PasswordManagementConstants.FullPathToPassword);
        //                OnStringChange(password.key, (ushort)index, PasswordManagementConstants.PasswordKey);
        //            }
        //        }

        //        OnUshrtChange(Convert.ToUInt16(Passwords.Count), 0, PasswordManagementConstants.PasswordListCount);
        //    }
        //    catch(Exception e)
        //    {
        //        var msg = string.Format("PasswordManager.Initialize({0}, {1}) failed:\r{2}", uniqueId, key, e.Message);
        //        CrestronConsole.PrintLine(msg);
        //        ErrorLog.Error(msg);
        //    }
        //    finally
        //    {
        //        OnBoolChange(true, 0, PasswordManagementConstants.BoolEvaluatedChange);
        //    }
        //}

        /// <summary>
        ///	Adds password to the list
        /// </summary>
        /// <param name="password"></param>
        //private void AddPassword(PasswordConfig password)
        //{
        //    if (password == null)
        //        return;

        //    var item = Passwords.FirstOrDefault(i => i.key.Equals(password.key));
        //    if (item != null)
        //        Passwords.Remove(item);
        //    Passwords.Add(password);

        //    Passwords.Sort((x, y) => string.Compare(x.key, y.key));
        //}

        /// <summary>
        /// Removes password from the list
        /// </summary>
        /// <param name="password"></param>
        //private void RemovePassword(PasswordConfig password)
        //{
        //    if (password == null)
        //        return;

        //    var item = Passwords.FirstOrDefault(i => i.key.Equals(password.key));
        //    if (item != null)
        //        Passwords.Remove(item);
        //}

        /// <summary>
        /// Updates password stored in the dictonary
        /// </summary>
        /// <param name="uniqueId"></param>
        /// <param name="key"></param>
        /// <param name="password"></param>
        public void UpdatePassword(ushort key, string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                return;
            }

            var pw = TempPasswords[key];

            if (pw == null)
            {
                pw = new PasswordConfig();
            }
            pw.password = password;

            if (UpdateTimer == null)
            {
                // (o) => SavePasswords removes the need to create a callback method that takes in an object
                UpdateTimer = new CTimer((o) => StorePassword(), UpdateTimerElapsedMs);
            }
            else
            {
                UpdateTimer.Reset();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves password by key
        /// </summary>
        /// <param name="key"></param>
        //public void GetPasswordByKey(string key)
        //{
        //    if (string.IsNullOrEmpty(key))
        //    {
        //        Debug.Console(1, "PassowrdClient.GetPasswordByKey failed:\rKey {0} is null or empty", key);
        //        return;
        //    }

        //    PasswordConfig password = PasswordManager.Passwords.FirstOrDefault(p => p.key.Equals(key));
        //    if (password == null)
        //    {
        //        OnUshrtChange(0, 0, PasswordManagementConstants.SelectedPasswordLength);
        //        return;
        //    }

        //    Client = password;
        //    OnUshrtChange((ushort)Client.password.Length, 0, PasswordManagementConstants.SelectedPasswordLength);
        //    OnStringChange(Client.key, 0, PasswordManagementConstants.PasswordKeySelected);
        //}

        /// <summary>
        /// Retrieve password by index
        /// </summary>
        /// <param name="index"></param>
        public void GetPasswordByIndex(ushort key)
        {
            PasswordConfig pw = PasswordManager.Passwords[key];

            if (pw == null)
            {
                OnUshrtChange(0, 0, PasswordManagementConstants.SelectedPasswordLength);
                return;
            }

            Client = pw;
            OnUshrtChange((ushort)Client.password.Length, 0, PasswordManagementConstants.SelectedPasswordLength);
            OnUshrtChange(key, 0, PasswordManagementConstants.PasswordKeySelected);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize method
        /// </summary>
        /// <param name="key"></param>
        public void Initialize(string key)
        {
            OnBoolChange(false, 0, PasswordManagementConstants.BoolEvaluatedChange);

            Client             = new PasswordConfig();
            PasswordToValidate = "";

            // there has to be a better way to get the index of the current index of password
            ushort i = 0;

            foreach (var password in PasswordManager.Passwords)
            {
                i++;
                OnUshrtChange((ushort)password.Key, (ushort)password.Key, PasswordManagementConstants.PasswordKey);
            }

            OnBoolChange(true, 0, PasswordManagementConstants.BoolEvaluatedChange);
        }