private void LoadMetadata()
 {
     _container.MetadataChildItemAdded += ContainerOnMetadataChildItemAdded;
     try
     {
         using (new UpdateRegion(_container))
         {
             if (_databases != null && _databases.Count != 0)
             {
                 LoadForDatabases();
             }
             else
             {
                 LoadEntireContainer();
             }
         }
     }
     catch (Exception e)
     {
         LoadingFailed?.Invoke(this, e.Message);
     }
     finally
     {
         _container.MetadataChildItemAdded -= ContainerOnMetadataChildItemAdded;
         LoadingFinished?.Invoke(this, EventArgs.Empty);
     }
 }
示例#2
0
 /// <summary>
 /// Raises event 'LoadingFailed'
 /// </summary>
 protected virtual void OnLoadingFailed()
 {
     if (LoadingFailed != null)
     {
         LoadingFailed.Invoke(this, System.EventArgs.Empty);
     }
 }
 private void OnFail(Exception ex)
 {
     this.IsLoading = false;
     _image.Source  = null;
     if (LoadingFailed != null)
     {
         LoadingFailed.Invoke(this, ex);
     }
 }
示例#4
0
文件: Image.cs 项目: yunmiha/TizenFX
        /// <summary>
        /// Sets the file that is used as the image's source with async.
        /// </summary>
        /// <param name="file">The path to the file that is used as an image source.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>(true = success, false = error)</returns>
        /// <since_tizen> preview </since_tizen>
        public async Task <bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(() =>
            {
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetCanceled();
                }
            });

            SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");

            loadReady.On += (s, e) =>
            {
                LoadingCompleted?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(true);
                }
            };

            SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");

            loadError.On += (s, e) =>
            {
                LoadingFailed?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(false);
                }
            };

            using (loadReady)
                using (loadError)
                {
                    bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);
                    if (!ret)
                    {
                        throw new InvalidOperationException("Failed to set file to Image");
                    }
                    // it should be return on main thread, because SmartEvent should be disposed on main thread
                    return(await tcs.Task.ConfigureAwait(true));
                }
        }
示例#5
0
文件: Image.cs 项目: yourina/TizenFX
        /// <summary>
        /// Sets the file that is used as the image's source with async.
        /// </summary>
        /// <param name="file">The path to the file that is used as an image source.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>(true = success, false = error)</returns>
        /// <since_tizen> preview </since_tizen>
        public Task <bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(() =>
            {
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetCanceled();
                }
            });

            SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");

            loadReady.On += (s, e) =>
            {
                loadReady.Dispose();
                LoadingCompleted?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(true);
                }
            };

            SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");

            loadError.On += (s, e) =>
            {
                loadError.Dispose();
                LoadingFailed?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(false);
                }
            };

            bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);

            if (!ret)
            {
                throw new InvalidOperationException("Failed to set file to Image");
            }

            return(tcs.Task);
        }
示例#6
0
        public static ICore CreateCore(ISynchronizeInvoke syncInvoke)
        {
            try
            {
                RaisePartLoadingEvent("Initializing Core");
                Core.PartLoading += RaisePartLoadingEvent;

                return(new Core(syncInvoke));
            }
            catch (Exception e)
            {
                LoadingFailed?.Invoke(e);
                throw;
            }
        }
示例#7
0
 void IImageSourcePartEvents.LoadingFailed(Exception exception)
 {
     IsLoading = false;
     LoadingFailed?.Invoke(exception);
 }
示例#8
0
文件: ImageStub.cs 项目: hevey/maui
 void IImageSourcePartEvents.LoadingFailed(Exception exception) =>
 LoadingFailed?.Invoke(exception);
示例#9
0
文件: Image.cs 项目: yourina/TizenFX
        /// <summary>
        /// Sets the stream that is used as the image's source with async.
        /// </summary>
        /// <param name="stream">The stream that is used as an image source.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>(true = success, false = error)</returns>
        /// <since_tizen> preview </since_tizen>
        public async Task <bool> LoadAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            Interop.Elementary.elm_image_async_open_set(RealHandle, true);
            Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);

            var tcs = new TaskCompletionSource <bool>();

            cancellationToken.Register(() =>
            {
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetCanceled();
                }
            });

            SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");

            loadReady.On += (s, e) =>
            {
                loadReady.Dispose();
                LoadingCompleted?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(true);
                }
            };

            SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");

            loadError.On += (s, e) =>
            {
                loadError.Dispose();
                LoadingFailed?.Invoke(this, EventArgs.Empty);
                if (tcs != null && !tcs.Task.IsCompleted)
                {
                    tcs.SetResult(false);
                }
            };

            using (MemoryStream memstream = new MemoryStream())
            {
                await stream.CopyToAsync(memstream);

                unsafe
                {
                    byte[] dataArr = memstream.ToArray();
                    fixed(byte *data = &dataArr[0])
                    {
                        bool ret = Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);

                        if (!ret)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(await tcs.Task);
        }