Пример #1
0
        /// <summary>
        /// Writes an array of <see cref="byte"/> starting from a position in the file.
        /// </summary>
        /// <param name="bytes">The <see cref="byte"/> array to write</param>
        /// <param name="type">Write mode from <see cref="WritableType"/>.</param>
        /// <param name="keepExistingData">If false the temporary file starts out empty, otherwise the existing file is first copied to this temporary file.</param>
        /// <param name="position">The cursor's position</param>
        /// <param name="callback">Callback method that receives a <see cref="bool"/> object.</param>
        public void WriteBytes(byte[] bytes, WritableType type, bool keepExistingData, int position, Action <bool> callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            var context = Application.Current;
            var task    = WriteBytesAsync(bytes, position, type, keepExistingData);

            task.ContinueWith((t) =>
            {
                Application.Update(context, () =>
                {
                    if (t.IsFaulted)
                    {
                        callback(false);
                    }
                    else
                    {
                        callback(true);
                    }
                });
            });
        }
Пример #2
0
 /// <summary>
 /// Writes an array of <see cref="byte"/> starting from a position in the file asynchronously.
 /// </summary>
 /// <param name="bytes">The <see cref="byte"/> array to write</param>
 /// <param name="position">The cursor's position</param>
 /// <param name="type">Write mode from <see cref="WritableType"/>.</param>
 /// <param name="keepExistingData">If false the temporary file starts out empty, otherwise the existing file is first copied to this temporary file.</param>
 /// <returns>An awaitable <see cref="Task"/> that represents the asynchronous operation.</returns>
 public async Task WriteBytesAsync(byte[] bytes, int position, WritableType type, bool keepExistingData)
 {
     await CallAsync("writeBytes", bytes, position, keepExistingData, type);
 }