示例#1
0
 public static T ParseJSON <T>(string content)
 {
     try
     {
         return(!string.IsNullOrEmpty(content)?JsonConvert.DeserializeObject <T>(content, _settings):default(T));
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
     }
     return(default(T));
 }
 static ShootingGame()
 {
     UnhandledException += (s, e) =>
     {
         X1LogHelper.Exception(e.Exception);
         if (Debugger.IsAttached)
         {
             Debugger.Break();
         }
         e.Handled = true;
     };
 }
示例#3
0
 public void CopyFile(string source, string dest)
 {
     Delete(dest);
     try
     {
         File.Copy(source, dest);
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
     }
 }
 public virtual bool Add(T entity)
 {
     try
     {
         CheckDateTime(entity);
         Connection.Insert(entity);
         return(true);
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
         return(false);
     }
 }
示例#5
0
 static string _CreateDirectory(string path)
 {
     try
     {
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
     }
     return(path);
 }
示例#6
0
        public async Task <List <string> > ListFiles(string remotePath, bool includingFolder = false, bool includingFiles = true)
        {
            var list = new List <string>();

            try
            {
                using (var s3Client = AWSS3Client)
                {
                    remotePath = ConvertToRemotePath(remotePath);
                    try
                    {
                        var response = await s3Client.ListObjectsAsync(ZibaobaoBucket, remotePath);

                        {
                            foreach (var s3Object in response.S3Objects)
                            {
                                var name = s3Object.Key;
                                if (!includingFolder && name.EndsWith("/"))
                                {
                                    continue;
                                }
                                if (!includingFiles && !name.EndsWith("/"))
                                {
                                    continue;
                                }
                                if (name.StartsWith(remotePath))
                                {
                                    var localPath = name.Substring(remotePath.Length).Trim('/');
                                    if (!string.IsNullOrEmpty(localPath))
                                    {
                                        list.Add(localPath);
                                    }
                                }
                            }
                        }
                    }
                    catch (AmazonS3Exception e)
                    {
                        X1LogHelper.Exception(e);
                    }
                }
            }
            catch (Exception ex)
            {
                X1LogHelper.Exception(ex);
            }
            return(list);
        }
示例#7
0
 public static string GetImageUrl(string id, string baseUrl = HttpResourceBase + "images")
 {
     try
     {
         if (String.IsNullOrEmpty(id))
         {
             return(null);
         }
         return(baseUrl + "/" + id);
     }
     catch (Exception e)
     {
         X1LogHelper.Exception(e);
     }
     return(null);
 }
示例#8
0
 public bool ResetData()
 {
     try
     {
         _Delete(Path.Combine(_dataPath, "cache"));
         _Delete(Path.Combine(_dataPath, "temp"));
         _Delete(Path.Combine(_dataPath, "entity"));
         _Delete(PersistentDataHelper.Instance.GetDataBasePath(true, PersistentDataHelper.DataDB));
         return(true);
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
         return(false);
     }
 }
 public void RemoveConnection(bool isGlobal, string dbName)
 {
     lock (_connectionLock)
     {
         try
         {
             string connectionKey = GetDataBasePath(isGlobal, dbName);
             if (_connections.ContainsKey(connectionKey))
             {
                 _connections.Remove(connectionKey);
             }
         }
         catch (Exception e)
         {
             X1LogHelper.Exception(e);
             throw;
         }
     }
 }
示例#10
0
 public bool Create(string path)
 {
     try
     {
         CreateDirectory(Path.GetDirectoryName(path));
     }
     catch (Exception)
     {
     }
     try
     {
         using (File.Create(path)) { }
         return(true);
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
     }
     return(false);
 }
 public SQLiteConnectionWithLock GetConnection(bool isGlobal, string dbName)
 {
     lock (_connectionLock)
     {
         try
         {
             string connectionKey = GetDataBasePath(isGlobal, dbName);
             SQLiteConnectionWithLock connection;
             if (!_connections.TryGetValue(connectionKey, out connection))
             {
                 connection = new SecureSqLiteConnectionWithLock(
                     new SQLiteConnectionString(connectionKey, true, connectionKey), SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.Create);
                 _connections[connectionKey] = connection;
             }
             return(connection);
         }
         catch (TypeInitializationException e)
         {
             X1LogHelper.Exception(e);
             X1LogHelper.Error("Please try to rebuild entire service package when this happens");
             throw;
         }
     }
 }
示例#12
0
 public bool SaveContent(string path, Stream data)
 {
     try
     {
         using (var stream = new FileStream(path, FileMode.Create))
         {
             try
             {
                 data.Position = 0;
             }
             catch (Exception ex)
             {
                 X1LogHelper.Error(ex.Message);
             }
             data.CopyTo(stream);
             return(true);
         }
     }
     catch (Exception ex)
     {
         X1LogHelper.Exception(ex);
     }
     return(false);
 }