public void RetryAll(ISourceDataStore sourceDataProvider, Action<IItemData> retrySingleItemAction, Action<IItemData> retryTreeAction)
        {
            Assert.ArgumentNotNull(sourceDataProvider, "sourceDataProvider");
            Assert.ArgumentNotNull(retrySingleItemAction, "retrySingleItemAction");
            Assert.ArgumentNotNull(retryTreeAction, "retryTreeAction");

            if (_itemFailures.Count > 0)
            {
                List<Failure> originalItemFailures;
                List<Failure> originalTreeFailures;

                do
                {
                    sourceDataProvider.ResetTemplateEngine();

                    // save existing failures collection
                    originalItemFailures = new List<Failure>(_itemFailures);

                    // clear the failures collection - we'll re-add any that fail again by evaluating originalFailures
                    _itemFailures.Clear();

                    foreach (var failure in originalItemFailures)
                    {
                        // retry loading a single item failure
                        var item = failure.Reference;
                        if (item != null)
                        {
                            try
                            {
                                retrySingleItemAction(item);
                            }
                            catch (Exception reason)
                            {
                                _itemFailures.Add(new Failure(failure.Reference, reason));
                            }

                            continue;
                        }

                        // retry loading a reference failure (note the continues in the above ensure execution never arrives here for items)
                        retryTreeAction(failure.Reference);
                    }
                }
                while (_itemFailures.Count > 0 && _itemFailures.Count < originalItemFailures.Count); // continue retrying until all possible failures have been fixed

                do
                {
                    sourceDataProvider.ResetTemplateEngine();

                    // save existing failures collection
                    originalTreeFailures = new List<Failure>(_treeFailures);

                    // clear the failures collection - we'll re-add any that fail again by evaluating originalFailures
                    _treeFailures.Clear();

                    foreach (var failure in originalTreeFailures)
                    {

                        // retry loading a tree failure
                        retryTreeAction(failure.Reference);
                    }
                }
                while (_treeFailures.Count > 0 && _treeFailures.Count < originalTreeFailures.Count); // continue retrying until all possible failures have been fixed
            }

            if (_itemFailures.Count > 0 || _treeFailures.Count > 0)
            {
                var exceptions = new List<DeserializationException>();

                foreach (var failure in _itemFailures)
                {
                    exceptions.Add(new DeserializationException(failure.Reference.GetDisplayIdentifier(), failure.Reference, failure.Reason));
                }

                foreach (var failure in _treeFailures)
                {
                    exceptions.Add(new DeserializationException(string.Format("This tree failed to load: {0} (the error may not be on this item, see the details below)", failure.Reference.GetDisplayIdentifier()), failure.Reference, failure.Reason));
                }

                throw new DeserializationAggregateException("Some directories could not be loaded.") { InnerExceptions = exceptions.ToArray() };
            }
        }
        public virtual void RetryAll(ISourceDataStore sourceDataStore, Action <IItemData> retrySingleItemAction, Action <IItemData> retryTreeAction)
        {
            Assert.ArgumentNotNull(sourceDataStore, "sourceDataProvider");
            Assert.ArgumentNotNull(retrySingleItemAction, "retrySingleItemAction");
            Assert.ArgumentNotNull(retryTreeAction, "retryTreeAction");

            if (_itemFailures.Count > 0)
            {
                List <Failure> originalItemFailures;

                do
                {
                    sourceDataStore.ResetTemplateEngine();

                    // save existing failures collection
                    originalItemFailures = new List <Failure>(_itemFailures);

                    // clear the failures collection - we'll re-add any that fail again by evaluating originalFailures
                    _itemFailures.Clear();

                    foreach (var failure in originalItemFailures)
                    {
                        // retry loading a single item failure
                        var item = failure.Item;
                        if (item != null)
                        {
                            try
                            {
                                retrySingleItemAction(item);
                            }
                            catch (Exception reason)
                            {
                                _itemFailures.Add(CreateFailure(failure.Item, reason));
                            }

                            continue;
                        }

                        // retry loading a reference failure (note the continues in the above ensure execution never arrives here for items)
                        retryTreeAction(failure.Item);
                    }
                } while (_itemFailures.Count > 0 && _itemFailures.Count < originalItemFailures.Count);
                // continue retrying until all possible failures have been fixed
            }

            if (_treeFailures.Count > 0)
            {
                List <Failure> originalTreeFailures;

                do
                {
                    sourceDataStore.ResetTemplateEngine();

                    // save existing failures collection
                    originalTreeFailures = new List <Failure>(_treeFailures);

                    // clear the failures collection - we'll re-add any that fail again by evaluating originalFailures
                    _treeFailures.Clear();

                    foreach (var failure in originalTreeFailures)
                    {
                        try
                        {
                            // retry loading a tree failure
                            retryTreeAction(failure.Item);
                        }
                        catch (Exception reason)
                        {
                            _treeFailures.Add(CreateFailure(failure.Item, reason));
                        }
                    }
                }while (_treeFailures.Count > 0 && _treeFailures.Count < originalTreeFailures.Count);                // continue retrying until all possible failures have been fixed
            }

            if (_itemFailures.Count > 0 || _treeFailures.Count > 0)
            {
                if (_itemFailures.All(fail => !fail.IsHardFailure) && _treeFailures.All(fail => !fail.IsHardFailure))
                {
                    throw new DeserializationSoftFailureAggregateException("Non-fatal warnings occurred during loading.")
                          {
                              InnerExceptions = _itemFailures.Select(fail => fail.Reason).Concat(_treeFailures.Select(fail => fail.Reason)).ToArray()
                          };
                }

                var exceptions = new List <DeserializationException>();

                foreach (var failure in _itemFailures)
                {
                    exceptions.Add(new DeserializationException(failure.Item.GetDisplayIdentifier(), failure.Item, failure.Reason));
                }

                foreach (var failure in _treeFailures)
                {
                    exceptions.Add(new DeserializationException($"Tree failed to load: {failure.Item.GetDisplayIdentifier()} (the error may be on a child of this item, see the details below)", failure.Item, failure.Reason));
                }

                throw new DeserializationAggregateException("Some directories could not be loaded.")
                      {
                          InnerExceptions = exceptions.ToArray()
                      };
            }
        }
Example #3
0
        public void RetryAll(ISourceDataStore sourceDataProvider, Action <IItemData> retrySingleItemAction, Action <IItemData> retryTreeAction)
        {
            Assert.ArgumentNotNull(sourceDataProvider, "sourceDataProvider");
            Assert.ArgumentNotNull(retrySingleItemAction, "retrySingleItemAction");
            Assert.ArgumentNotNull(retryTreeAction, "retryTreeAction");

            if (_itemFailures.Count > 0)
            {
                List <Failure> originalItemFailures;
                List <Failure> originalTreeFailures;

                do
                {
                    sourceDataProvider.ResetTemplateEngine();

                    // save existing failures collection
                    originalItemFailures = new List <Failure>(_itemFailures);

                    // clear the failures collection - we'll re-add any that fail again by evaluating originalFailures
                    _itemFailures.Clear();

                    foreach (var failure in originalItemFailures)
                    {
                        // retry loading a single item failure
                        var item = failure.Reference;
                        if (item != null)
                        {
                            try
                            {
                                retrySingleItemAction(item);
                            }
                            catch (Exception reason)
                            {
                                _itemFailures.Add(new Failure(failure.Reference, reason));
                            }

                            continue;
                        }

                        // retry loading a reference failure (note the continues in the above ensure execution never arrives here for items)
                        retryTreeAction(failure.Reference);
                    }
                }while (_itemFailures.Count > 0 && _itemFailures.Count < originalItemFailures.Count);                // continue retrying until all possible failures have been fixed

                do
                {
                    sourceDataProvider.ResetTemplateEngine();

                    // save existing failures collection
                    originalTreeFailures = new List <Failure>(_treeFailures);

                    // clear the failures collection - we'll re-add any that fail again by evaluating originalFailures
                    _treeFailures.Clear();

                    foreach (var failure in originalTreeFailures)
                    {
                        // retry loading a tree failure
                        retryTreeAction(failure.Reference);
                    }
                }while (_treeFailures.Count > 0 && _treeFailures.Count < originalTreeFailures.Count);                // continue retrying until all possible failures have been fixed
            }

            if (_itemFailures.Count > 0 || _treeFailures.Count > 0)
            {
                var exceptions = new List <DeserializationException>();

                foreach (var failure in _itemFailures)
                {
                    exceptions.Add(new DeserializationException(failure.Reference.GetDisplayIdentifier(), failure.Reference, failure.Reason));
                }

                foreach (var failure in _treeFailures)
                {
                    exceptions.Add(new DeserializationException(string.Format("This tree failed to load: {0} (the error may not be on this item, see the details below)", failure.Reference.GetDisplayIdentifier()), failure.Reference, failure.Reason));
                }

                throw new DeserializationAggregateException("Some directories could not be loaded.")
                      {
                          InnerExceptions = exceptions.ToArray()
                      };
            }
        }