예제 #1
0
        /// <summary>
        /// Request to write data
        /// </summary>
        /// <param name="profileName">profile name</param>
        /// <param name="password">password</param>
        /// <param name="keys">key array</param>
        /// <param name="data">data</param>
        public void WriteProfileValues(string profileName, byte[] password, string[] keys, byte[][] data)
        {
            if (IsSupportPenProfile())
            {
                if (string.IsNullOrEmpty(profileName))
                {
                    throw new ArgumentNullException("profileName");
                }
                if (password == null)
                {
                    throw new ArgumentNullException("password");
                }
                if (keys == null)
                {
                    throw new ArgumentNullException("keys");
                }
                if (data == null)
                {
                    throw new ArgumentNullException("data");
                }
                if (keys.Length != data.Length)
                {
                    throw new ArgumentOutOfRangeException("keys, data", "The number of keys and data does not match");
                }

                byte[] profileNameBytes = Encoding.UTF8.GetBytes(profileName);
                //byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
                if (profileNameBytes.Length > PenProfile.LIMIT_BYTE_LENGTH_PROFILE_NAME)
                {
                    throw new ArgumentOutOfRangeException("profileName", $"profileName byte length must be {PenProfile.LIMIT_BYTE_LENGTH_PROFILE_NAME} or less");
                }
                else if (password.Length != PenProfile.LIMIT_BYTE_LENGTH_PASSWORD)
                {
                    throw new ArgumentOutOfRangeException("password", $"password byte length must be {PenProfile.LIMIT_BYTE_LENGTH_PASSWORD}");
                }

                byte[][] keysBytes = new byte[keys.Length][];
                for (int i = 0; i < keys.Length; ++i)
                {
                    keysBytes[i] = Encoding.UTF8.GetBytes(keys[i]);
                    if (keysBytes[i].Length > PenProfile.LIMIT_BYTE_LENGTH_KEY)
                    {
                        throw new ArgumentOutOfRangeException("keys", $"key byte length must be {PenProfile.LIMIT_BYTE_LENGTH_KEY} or less");
                    }
                }

                Request(() => mClientV1.ReqWriteProfileValue(profileNameBytes, password, keysBytes, data), () => mClientV2.ReqWriteProfileValue(profileNameBytes, password, keysBytes, data));
            }
            else
            {
                throw new NotSupportedException($"CreateProfile is not supported at this pen firmware version");
            }
        }