Beispiel #1
0
        protected XResult <T> Deserialise <T>(string entity)

        {
            try
            {
                if (OverrideSerialiser != null)
                {
                    return(OverrideSerialiser.Deserialise <XResult <T> >(entity));
                }
                var e = _entitySerialiser.Deserialise <XResult <T> >(entity);

                if (e == null)
                {
                    return(XResult <T> .GetFailed(entity));
                }

                if (e.Message == null && e.Object == null && !e.IsSuccess)
                {
                    e.Message = entity;
                }

                return(e);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Des problem: " + ex.Message);
            }

            return(XResult <T> .GetFailed(entity));
        }
Beispiel #2
0
        public async Task <XResult <bool> > DownloadByteAsync(string blobName, string fileName)
        {
            var c = _getBlob(blobName);

            var result = await XResiliant.Default.Run(() => OperationWrap <bool>(async() =>
            {
                using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    await c.DownloadToStreamAsync(fs);
                    _logRead(blobName);
                    return(true);
                }
            }));

            if (!result)
            {
                return(XResult <bool> .GetFailed("Could not read blob"));
            }

            if (!File.Exists(fileName))
            {
                return(XResult <bool> .GetFailed("Blob file check not present"));
            }

            var b = File.ReadAllBytes(fileName);

            return(new XResult <bool>(b.Length > 0));
        }
Beispiel #3
0
        async Task <XResult <bool> > _retry()
        {
            await Task.Delay(500);

            if (count == 0)
            {
                count++;
                return(XResult <bool> .GetFailed("Could not do someting"));
            }

            return(new XResult <bool>(true));
        }
Beispiel #4
0
        public async Task <XResult <bool> > RunBool(Func <Task <bool> > func)
        {
            return(await Run(async() =>
            {
                var result = await func();

                if (!result)
                {
                    return XResult <bool> .GetFailed();
                }

                return new XResult <bool>(true);
            }));
        }
Beispiel #5
0
        public async Task <XResult <T> > Run <T>(Func <Task <T> > func)
            where T : class
        {
            var run = await Run(async() =>
            {
                var result = await func();

                if (result == null)
                {
                    return(XResult <T> .GetFailed());
                }

                return(new XResult <T>(result));
            });

            return(run);
        }
Beispiel #6
0
        public async Task <XResult <T> > Run <T>(Func <Task <XResult <T> > > func)
        {
            var counter = 0;

            XResult <T> lastResult = null;

            while (counter <= Retries || Retries == -1)
            {
                try
                {
                    var result = await func();

                    result.Retries = counter;

                    if (ExceptionsOnly)
                    {
                        return(result);
                    }

                    if (!result)
                    {
                        if (AllowedResultCodes.HasFlag(result.ResultCode))
                        {
                            return(result);
                        }

                        lastResult = result;

                        if (counter == Retries)
                        {
                            break;
                        }
                        await Task.Delay(RetryTimeout);

                        counter++;
                        continue;
                    }
                    return(result);
                }
                catch (Exception ex)
                {
                    lastResult = XResult <T> .GetException();

                    lastResult.Exception = ex;

                    if (counter == Retries)
                    {
                        break;
                    }

                    counter++;
                }
            }

            if (lastResult == null)
            {
                lastResult = XResult <T> .GetFailed();

                lastResult.ResultCode = OperationResults.RetryTimeout;
            }

            lastResult.Retries = counter;

            return(lastResult);
        }
Beispiel #7
0
        async Task <XResult <bool> > _retryFail()
        {
            await Task.Delay(500);

            return(XResult <bool> .GetFailed("Could not do someting"));
        }