Exemple #1
0
 public SuccessEventArgs(ImageInformation imageInformation, LoadingResult loadingResult)
 {
     ImageInformation = imageInformation;
     ImageSize        = ImageInformation == null ?
                        new ImageSize() : new ImageSize(imageInformation.OriginalWidth, imageInformation.OriginalHeight);
     LoadingResult = loadingResult;
 }
Exemple #2
0
 private async void Succeeded(ImageInformation info, LoadingResult result)
 {
     if (State != TransferStates.CANCELED)
     {
         await InsertInGallery(info.FilePath);
     }
 }
        private void SetLoadingResult(LoadingResult loadingResult)
        {
            var localizer = StaticContainer.Container.Resolve <ILocalizerService>();

            switch (loadingResult)
            {
            case LoadingResult.Success:
                SaveIndicatorMessage =
                    localizer.GetLocalizedString(ApplicationGlobalNames.StatusMessages.SAVED_SUCCESSFULLY) + ": " +
                    PathToFolderToSave;
                break;

            case LoadingResult.SuccessWithIssues:
                SaveIndicatorMessage =
                    $"{localizer.GetLocalizedString(ApplicationGlobalNames.StatusMessages.SAVED_WITH_ISSUES)}:{PathToFolderToSave}";
                break;

            case LoadingResult.Fail:
                SaveIndicatorMessage =
                    $"{localizer.GetLocalizedString(ApplicationGlobalNames.StatusMessages.FAIL)}";
                break;

            case LoadingResult.InProgress:
                SaveIndicatorMessage =
                    localizer.GetLocalizedString(ApplicationGlobalNames.StatusMessages.IN_PROGRESS) + ": " +
                    PathToFolderToSave;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(loadingResult), loadingResult, null);
            }

            IsSavedSuccessfully = loadingResult == LoadingResult.Success ||
                                  loadingResult == LoadingResult.SuccessWithIssues;
        }
Exemple #4
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;
            AssemblyLoadResult result2 = null;

            if (this._resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                result2       = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = result2.status;
            }
            else
            {
                bool flag;
                result2 = new AssemblyLoadResult {
                    a = this.LoadAssemblyFromResourceReference(resourceReference, out flag)
                };
                if (result2.a == null)
                {
                    result2.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }
                this._resourceReferenceToAssemblyCache.Add(resourceReference, result2);
            }
            bindingStatus = result2.status;
            if (result2.a == null)
            {
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            try
            {
                string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId);
                if (str == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                result = LoadingResult.NoError;
                return(str);
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
 private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     result = LoadingResult.AssemblyNotFound;
     bindingStatus = AssemblyBindingStatus.NotFound;
     AssemblyLoadResult result2 = null;
     if (this._resourceReferenceToAssemblyCache.Contains(resourceReference))
     {
         result2 = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
         bindingStatus = result2.status;
     }
     else
     {
         bool flag;
         result2 = new AssemblyLoadResult {
             a = this.LoadAssemblyFromResourceReference(resourceReference, out flag)
         };
         if (result2.a == null)
         {
             result2.status = AssemblyBindingStatus.NotFound;
         }
         else
         {
             result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
         }
         this._resourceReferenceToAssemblyCache.Add(resourceReference, result2);
     }
     bindingStatus = result2.status;
     if (result2.a == null)
     {
         result = LoadingResult.AssemblyNotFound;
         return null;
     }
     try
     {
         string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId);
         if (str == null)
         {
             result = LoadingResult.StringNotFound;
             return null;
         }
         result = LoadingResult.NoError;
         return str;
     }
     catch (InvalidOperationException)
     {
         result = LoadingResult.ResourceNotFound;
     }
     catch (MissingManifestResourceException)
     {
         result = LoadingResult.ResourceNotFound;
     }
     catch (Exception)
     {
         throw;
     }
     return null;
 }
Exemple #6
0
        public bool LoadTranslation(string language)
        {
            LoadingResult result = Load(language);

            if (result == LoadingResult.Failure)
            {
                result = Load("en");
            }

            return(result == LoadingResult.Success);
        }
        private void bwRefresh_DoWork(object sender, DoWorkEventArgs e)
        {
            LoadingParameters parameters = (LoadingParameters)e.Argument;

            LoadingResult result = new LoadingResult()
            {
                AppointHistory = AppointHistory.LoadList(parameters.Database, parameters.AppointId),
                AppointLog     = AppointLog.LoadList(parameters.Database, parameters.AppointId)
            };

            e.Result = result;
        }
        /// <summary>Loads the translation data for the specified language.</summary>
        /// <param name="language">The language to load the translation for.</param>
        /// <returns><c>true</c> when the translation data was loaded; otherwise, <c>false</c>.</returns>
        public bool LoadTranslation(string language)
        {
            if (string.IsNullOrEmpty(language))
            {
                return(false);
            }

            LoadingResult result = Load(language);

            if (result == LoadingResult.Failure)
            {
                result = Load("en");
            }

            return(result == LoadingResult.Success);
        }
Exemple #9
0
        public static bool IsLocalOrCachedResult(this LoadingResult result)
        {
            switch (result)
            {
            case LoadingResult.ApplicationBundle:
            case LoadingResult.CompiledResource:
            case LoadingResult.Disk:
            case LoadingResult.DiskCache:
            case LoadingResult.MemoryCache:
            case LoadingResult.Stream:
                return(true);

            default:
                return(false);
            }
        }
        private void bwRefresh_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            LoadingResult  result         = (LoadingResult)e.Result;
            AppointHistory appointHistory = result.AppointHistory;

            bsAppointHistory.DataSource = appointHistory;
            lblVehicle.Text             = appointHistory.Vehicle;
            lblDriverName.Text          = appointHistory.Driver;
            lblDriverPhone.Text         = appointHistory.DriverPhone;
            lblCargo.Text   = appointHistory.Cargo;
            lblWhereTo.Text = appointHistory.WhereTo;

            bsLog.DataSource = result.AppointLog;

            timerLoading.Stop();
            pbarLoading.Height = 0;
        }
Exemple #11
0
        public Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token)
        {
            var t = Task.Run(() =>
            {
                Stream stream        = null;
                LoadingResult result = LoadingResult.Disk;
                try
                {
                    stream = UIImage.FromBundle(identifier).AsPNG().AsStream();
                }
                catch
                {
                    result = LoadingResult.Failed;
                }

                var tuple = new Tuple <Stream, LoadingResult, ImageInformation>(stream, result, new ImageInformation());
                return(tuple);
            });

            return(t);
        }
 public static WithLoadingResult <T> Encapsulate <T>(T item, LoadingResult result)
 {
     return(new WithLoadingResult <T>(item, result));
 }
Exemple #13
0
 public SuccessEventArgs(ImageSize imageSize, LoadingResult loadingResult)
 {
     ImageSize     = imageSize;
     LoadingResult = loadingResult;
 }
        public async Task RunAsync()
        {
            try
            {
                if (IsCompleted || IsCancelled || ImageService.ExitTasksEarly)
                {
                    throw new OperationCanceledException();
                }

                ThrowIfCancellationRequested();
                LoadingResult loadingResult = LoadingResult.Failed;

                // LOAD IMAGE
                if (!(await TryLoadFromMemoryCacheAsync().ConfigureAwait(false)))
                {
                    Logger.Debug(string.Format("Generating/retrieving image: {0}", Key));
                    var resolver  = DataResolverFactory.GetResolver(Parameters.Path, Parameters.Source, Parameters, Configuration);
                    var imageData = await resolver.Resolve(Parameters.Path, Parameters, CancellationTokenSource.Token).ConfigureAwait(false);

                    loadingResult = imageData.Item2;

                    using (imageData.Item1)
                    {
                        ImageInformation = imageData.Item3;
                        ThrowIfCancellationRequested();

                        // Preload
                        if (Parameters.Preload && Parameters.CacheType.HasValue && Parameters.CacheType.Value == CacheType.Disk)
                        {
                            if (Parameters.Source != ImageSource.Url)
                            {
                                throw new InvalidOperationException("DownloadOnly: Only Url ImageSource is supported.");
                            }

                            if (loadingResult == LoadingResult.Internet)
                            {
                                Logger?.Debug(string.Format("DownloadOnly success: {0}", Key));
                            }

                            Parameters?.OnSuccess?.Invoke(ImageInformation, loadingResult);
                            return;
                        }

                        ThrowIfCancellationRequested();

                        var image = await GenerateImageAsync(Parameters.Path, Parameters.Source, imageData.Item1, imageData.Item3, TransformPlaceholders, false).ConfigureAwait(false);

                        try
                        {
                            BeforeLoading(image, false);

                            if (image != default(TImageContainer) && CanUseMemoryCache)
                            {
                                MemoryCache.Add(Key, imageData.Item3, image);
                            }

                            ThrowIfCancellationRequested();

                            bool isFadeAnimationEnabled = Parameters.FadeAnimationEnabled ?? Configuration.FadeAnimationEnabled;
                            await SetTargetAsync(image, isFadeAnimationEnabled).ConfigureAwait(false);
                        }
                        finally
                        {
                            AfterLoading(image, false);
                        }
                    }
                }

                Parameters?.OnSuccess?.Invoke(ImageInformation, loadingResult);
            }
            catch (Exception ex)
            {
                if (_clearCacheOnOutOfMemory && ex is OutOfMemoryException)
                {
                    MemoryCache.Clear();
                }

                if (ex is OperationCanceledException)
                {
                    if (Configuration.VerboseLoadingCancelledLogging)
                    {
                        Logger.Debug(string.Format("Image loading cancelled: {0}", Key));
                    }
                }
                else
                {
                    Logger.Error(string.Format("Image loading failed: {0}", Key), ex);
                    Parameters?.OnError?.Invoke(ex);

                    try
                    {
                        // Error placeholder if enabled
                        if (!Parameters.Preload && !string.IsNullOrWhiteSpace(Parameters.ErrorPlaceholderPath))
                        {
                            await ShowPlaceholder(Parameters.ErrorPlaceholderPath, KeyForErrorPlaceholder,
                                                  Parameters.ErrorPlaceholderSource, false).ConfigureAwait(false);
                        }
                    }
                    catch (Exception ex2)
                    {
                        if (!(ex2 is OperationCanceledException))
                        {
                            Logger.Error(string.Format("Image loading failed: {0}", Key), ex);
                        }
                    }
                }
            }
            finally
            {
                using (Parameters)
                {
                    Parameters?.OnFinish?.Invoke(this);
                    ImageService.RemovePendingTask(this);
                }

                IsCompleted = true;
            }
        }
 public DataResolverResult(Stream stream, LoadingResult loadingResult, ImageInformation imageInformation)
 {
     Stream           = stream;
     LoadingResult    = loadingResult;
     ImageInformation = imageInformation;
 }
Exemple #16
0
 public static WithLoadingResult <T> Encapsulate <T>(T item, LoadingResult result, ImageInformation imageInformation) where T : class
 {
     return(new WithLoadingResult <T>(item, result, imageInformation));
 }
Exemple #17
0
 public SuccessEventArgs(ImageInformation imageInformation, LoadingResult loadingResult)
 {
     ImageInformation = imageInformation;
     LoadingResult = loadingResult;
 }
Exemple #18
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;

            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult    = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            else
            {
                resourceReference.assemblyLocation = loadResult.a.Location;
            }

            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                else
                {
                    result = LoadingResult.NoError;
                    return(val);
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }

            return(null);
        }
Exemple #19
0
        public async Task RunAsync()
        {
            LoadingResult loadingResult = LoadingResult.Failed;
            bool          success       = false;

            try
            {
                if (IsCompleted || IsCancelled || ImageService.ExitTasksEarly)
                {
                    throw new OperationCanceledException();
                }

                ThrowIfCancellationRequested();

                // LOAD IMAGE
                if (!(await TryLoadFromMemoryCacheAsync().ConfigureAwait(false)))
                {
                    Logger.Debug(string.Format("Generating/retrieving image: {0}", Key));
                    var resolver = Parameters.CustomDataResolver ?? DataResolverFactory.GetResolver(Parameters.Path, Parameters.Source, Parameters, Configuration);
                    resolver = new WrappedDataResolver(resolver);
                    var imageData = await resolver.Resolve(Parameters.Path, Parameters, CancellationTokenSource.Token).ConfigureAwait(false);

                    loadingResult = imageData.Item2;

                    using (imageData.Item1)
                    {
                        ImageInformation = imageData.Item3;
                        ImageInformation.SetKey(Key, Parameters.CustomCacheKey);
                        ImageInformation.SetPath(Parameters.Path);
                        ThrowIfCancellationRequested();

                        // Preload
                        if (Parameters.Preload && Parameters.CacheType.HasValue && Parameters.CacheType.Value == CacheType.Disk)
                        {
                            if (loadingResult == LoadingResult.Internet)
                            {
                                Logger?.Debug(string.Format("DownloadOnly success: {0}", Key));
                            }

                            success = true;

                            return;
                        }

                        ThrowIfCancellationRequested();

                        var image = await GenerateImageAsync(Parameters.Path, Parameters.Source, imageData.Item1, imageData.Item3, true, false).ConfigureAwait(false);

                        ThrowIfCancellationRequested();

                        try
                        {
                            BeforeLoading(image, false);

                            if (image != default(TImageContainer) && CanUseMemoryCache)
                            {
                                MemoryCache.Add(Key, imageData.Item3, image);
                            }

                            ThrowIfCancellationRequested();

                            bool isFadeAnimationEnabled = Parameters.FadeAnimationEnabled ?? Configuration.FadeAnimationEnabled;
                            await SetTargetAsync(image, isFadeAnimationEnabled).ConfigureAwait(false);
                        }
                        finally
                        {
                            AfterLoading(image, false);
                        }
                    }
                }

                success = true;
            }
            catch (Exception ex)
            {
                if (ex is OperationCanceledException || ex is ObjectDisposedException)
                {
                    if (Configuration.VerboseLoadingCancelledLogging)
                    {
                        Logger.Debug(string.Format("Image loading cancelled: {0}", Key));
                    }
                }
                else
                {
                    if (_clearCacheOnOutOfMemory && ex is OutOfMemoryException)
                    {
                        MemoryCache.Clear();
                    }

                    Logger.Error(string.Format("Image loading failed: {0}", Key), ex);

                    if (Configuration.ExecuteCallbacksOnUIThread && Parameters?.OnError != null)
                    {
                        await MainThreadDispatcher.PostAsync(() =>
                        {
                            Parameters?.OnError?.Invoke(ex);
                        }).ConfigureAwait(false);
                    }
                    else
                    {
                        Parameters?.OnError?.Invoke(ex);
                    }

                    try
                    {
                        // Error placeholder if enabled
                        if (!Parameters.Preload && !string.IsNullOrWhiteSpace(Parameters.ErrorPlaceholderPath))
                        {
                            await ShowPlaceholder(Parameters.ErrorPlaceholderPath, KeyForErrorPlaceholder,
                                                  Parameters.ErrorPlaceholderSource, false).ConfigureAwait(false);
                        }
                    }
                    catch (Exception ex2)
                    {
                        if (!(ex2 is OperationCanceledException))
                        {
                            Logger.Error(string.Format("Image loading failed: {0}", Key), ex);
                        }
                    }
                }
            }
            finally
            {
                try
                {
                    if (CancellationTokenSource?.IsCancellationRequested == false)
                    {
                        CancellationTokenSource.Cancel();
                    }
                }
                catch (Exception)
                {
                }

                IsCompleted = true;

                using (Parameters)
                {
                    if (Configuration.ExecuteCallbacksOnUIThread && Parameters?.OnFinish != null)
                    {
                        await MainThreadDispatcher.PostAsync(() =>
                        {
                            if (success)
                            {
                                Parameters?.OnSuccess?.Invoke(ImageInformation, loadingResult);
                            }
                            Parameters?.OnFinish?.Invoke(this);
                        }).ConfigureAwait(false);
                    }
                    else
                    {
                        if (success)
                        {
                            Parameters?.OnSuccess?.Invoke(ImageInformation, loadingResult);
                        }
                        Parameters?.OnFinish?.Invoke(this);
                    }

                    ImageService.RemovePendingTask(this);
                }
            }
        }
Exemple #20
0
 private void SendFinishedLoadingSignal(LoadingResult status, IEnumerable <DreamEntry> entries)
 {
     FinishedLoading?.Invoke(this, new FinishedLoadingEventArgs(status, entries));
 }
Exemple #21
0
 public SuccessEventArgs(ImageInformation imageInformation, LoadingResult loadingResult) : base(imageInformation, loadingResult)
 {
 }
			public SuccessEventArgs(ImageSize imageSize, LoadingResult loadingResult)
			{
				ImageSize = imageSize;
				LoadingResult = loadingResult;
			}
            public SuccessEventArgs(ImageInformation imageInformation, LoadingResult loadingResult)
			{
                ImageInformation = imageInformation;
                LoadingResult = loadingResult;
			}
 public DataResolverResult(TImageContainer imageContainer, LoadingResult loadingResult, ImageInformation imageInformation)
 {
     ImageContainer   = imageContainer;
     LoadingResult    = loadingResult;
     ImageInformation = imageInformation;
 }
 internal void VerifyResource(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     GetStringHelper(resourceReference, out result, out bindingStatus);
 }
Exemple #26
0
 internal void VerifyResource(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
 {
     GetStringHelper(resourceReference, out result, out bindingStatus);
 }
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;
            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return null;
            }


            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return null;
                }
                else
                {
                    result = LoadingResult.NoError;
                    return val;
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }
            return null;
        }
 public FinishedLoadingEventArgs(LoadingResult result, [NotNull] IEnumerable <DreamEntry> loadedDreamEntries)
 {
     Result             = result;
     LoadedDreamEntries = loadedDreamEntries;
 }
 public DataResolverResult(IDecodedImage <object> decoded, LoadingResult loadingResult, ImageInformation imageInformation)
 {
     Decoded          = decoded;
     LoadingResult    = loadingResult;
     ImageInformation = imageInformation;
 }