Esempio n. 1
0
        public static async Task <ReturnedSaveFuncInfo> PingHostAsync()
        {
            Ping pinger = null;
            var  res    = new ReturnedSaveFuncInfo();

            try
            {
                pinger = new Ping();
                await pinger.SendPingAsync("www.google.com");
            }
            catch (PingException)
            {
                res.AddReturnedValue(ReturnedState.Error, "لطفا اتصال سیستم به اینترنت را بررسی نمایید");
            }
            finally
            {
                pinger?.Dispose();
            }

            return(res);
        }
 public ReturnedSaveFuncInfo AddReturnedValue(ReturnedSaveFuncInfo returnedSaveFuncInfo)
 {
     try
     {
         if (returnedSaveFuncInfo?.ErrorList?.Count > 0)
         {
             ErrorList.AddRange(returnedSaveFuncInfo.ErrorList);
         }
         if (returnedSaveFuncInfo?.WarningList?.Count > 0)
         {
             WarningList.AddRange(returnedSaveFuncInfo.WarningList);
         }
         if (returnedSaveFuncInfo?.InformationList?.Count > 0)
         {
             InformationList.AddRange(returnedSaveFuncInfo.InformationList);
         }
     }
     catch (Exception ex)
     {
         WebErrorLog.ErrorInstence.StartErrorLog(ex);
     }
     return(returnedSaveFuncInfo);
 }
Esempio n. 3
0
        public static async Task <ReturnedSaveFuncInfo> FileTryReplceadeAsync(string FullFilePath, byte[] data, short tryCount = 10)
        {
            var ret = new ReturnedSaveFuncInfo();

            try
            {
                if (File.Exists(FullFilePath))
                {
                    File.Delete(FullFilePath);
                }
                File.WriteAllBytes(FullFilePath, data);
                return(ret);
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                ret.AddReturnedValue(ex);
            }

            try
            {
                File.WriteAllBytes(FullFilePath, data);
                return(new ReturnedSaveFuncInfo());
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                ret.AddReturnedValue(ex);
            }
            if (tryCount > 0 && ret.HasError)
            {
                await Task.Delay(5 * 1000);

                return(await FileTryReplceadeAsync(FullFilePath, data, --tryCount));
            }
            return(ret);
        }
        public ReturnedSaveFuncInfo AddReturnedValue(ReturnedSaveFuncInfo[] returnedSaveFuncInfo)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var ret = returnedSaveFuncInfo?.ToList();
                if (ret == null || ret.Count() <= 0)
                {
                    return(res);
                }
                foreach (var info in ret)
                {
                    res.AddReturnedValue(info);
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }