Example #1
0
        public static void HandleException
        (
            Exception unhandledException
        )
        {
            try
            {
                _exceptionClear.ThrowIfUnitialised(nameof(_exceptionClear),
                                                   nameof(HandleException),
                                                   nameof(RegisterPlatformSpecific));
                _exceptionClear();

                _exceptionLogger.LogError(unhandledException);

                _exceptionNotification.ThrowIfUnitialised(nameof(_exceptionNotification),
                                                          nameof(HandleException),
                                                          nameof(RegisterPlatformSpecific));

                _exceptionNotification(unhandledException.GetAggregatedMessage());
            }
            catch (Exception exception)
            {
                _exceptionClear?.Invoke();

                _exceptionLogger.LogError(exception);
            }
        }
Example #2
0
        XDocument PortableSourceReader.ReadSourceXml
        (
            ReaderWriterLockSlim sourceLock
        )
        {
            XDocument sourceXml = null;

            sourceLock.EnterReadLock();

            try
            {
                if (File.Exists(_fileName))
                {
                    /*Debug.Write
                     * (
                     *  string.Format("{0}*****{1}{2}{3}*****{4}",
                     *                Environment.NewLine,
                     *                Environment.NewLine,
                     *                File.ReadAllText(_fileName),
                     *                Environment.NewLine,
                     *                Environment.NewLine)
                     * );*/

                    sourceXml = XDocument.Load(_fileName);
                }
            }
            catch (Exception exception)
            {
                _contextLogger.LogError(exception);
#if (THROW)
                throw;
#endif
            }
            finally
            {
                sourceLock.ExitReadLock();
            };

            return(sourceXml);
        }
Example #3
0
        public static async Task <IReadOnlyDictionary <string, PortableSourceData> > LoadSourceDataAsync
        (
            PortableContextLogger contextLogger
        )
        {
            return(await Task.Run
                   (
                       () =>

            {
                IReadOnlyDictionary <string, PortableSourceData> sourceData
                    = new Dictionary <string, PortableSourceData>();

                PortableSourceReader sourceReader = _sourceReaderFactory(contextLogger);

                XDocument sourceXml = sourceReader.ReadSourceXml(_sourceLock);

                if (sourceXml == null)
                {
                    return sourceData;
                }

                try
                {
                    XElement sourcesElement = sourceXml.Element(SourcesElementName);

                    if (sourcesElement == null)
                    {
                        throw new XmlException(SourcesElementName);
                    }

                    IEnumerable <XElement> sourceElements
                        = from sourceElement
                          in sourcesElement.Elements()
                          where (sourceElement.Name == SourceElementName)
                          select sourceElement;

                    sourceData = sourceElements.ToDictionary
                                 (
                        sourceElement =>
                    {
                        XAttribute idAttribute = sourceElement.Attribute(SourceIdAttributeName);

                        if (idAttribute == null)
                        {
                            throw new XmlException(SourceIdAttributeName);
                        }

                        string sourceKey = idAttribute.Value;

                        return sourceKey;
                    },

                        sourceElement =>
                    {
                        XAttribute enabledAttribute = sourceElement.Attribute(SourceEnabledAttributeName);

                        if (enabledAttribute == null)
                        {
                            throw new XmlException(SourceEnabledAttributeName);
                        }

                        bool isEnabled = bool.Parse(enabledAttribute.Value);

                        var sourceValue = new PortableSourceData(isEnabled);

                        return sourceValue;
                    }
                                 );
                }
                catch (Exception exception)
                {
                    contextLogger.LogError(exception);
#if (THROW)
                    throw;
#endif
                }

                return sourceData;
            }
                   ));
        }