| 73 |
{ |
{ |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
public StorageResponse TryFetchMetadata(UUID assetID, out Metadata metadata) |
public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) |
| 77 |
{ |
{ |
| 78 |
metadata = null; |
metadata = null; |
| 79 |
StorageResponse ret; |
BackendResponse ret; |
| 80 |
|
|
| 81 |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
| 82 |
{ |
{ |
| 101 |
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); |
metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); |
| 102 |
metadata.Temporary = reader.GetBoolean(3); |
metadata.Temporary = reader.GetBoolean(3); |
| 103 |
|
|
| 104 |
ret = StorageResponse.Success; |
ret = BackendResponse.Success; |
| 105 |
} |
} |
| 106 |
else |
else |
| 107 |
{ |
{ |
| 108 |
ret = StorageResponse.NotFound; |
ret = BackendResponse.NotFound; |
| 109 |
} |
} |
| 110 |
} |
} |
| 111 |
catch (MySqlException ex) |
catch (MySqlException ex) |
| 112 |
{ |
{ |
| 113 |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
| 114 |
ret = StorageResponse.Failure; |
ret = BackendResponse.Failure; |
| 115 |
} |
} |
| 116 |
} |
} |
| 117 |
|
|
| 119 |
return ret; |
return ret; |
| 120 |
} |
} |
| 121 |
|
|
| 122 |
public StorageResponse TryFetchData(UUID assetID, out byte[] assetData) |
public BackendResponse TryFetchData(UUID assetID, out byte[] assetData) |
| 123 |
{ |
{ |
| 124 |
assetData = null; |
assetData = null; |
| 125 |
StorageResponse ret; |
BackendResponse ret; |
| 126 |
|
|
| 127 |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
| 128 |
{ |
{ |
| 139 |
if (reader.Read()) |
if (reader.Read()) |
| 140 |
{ |
{ |
| 141 |
assetData = (byte[])reader.GetValue(0); |
assetData = (byte[])reader.GetValue(0); |
| 142 |
ret = StorageResponse.Success; |
ret = BackendResponse.Success; |
| 143 |
} |
} |
| 144 |
else |
else |
| 145 |
{ |
{ |
| 146 |
ret = StorageResponse.NotFound; |
ret = BackendResponse.NotFound; |
| 147 |
} |
} |
| 148 |
} |
} |
| 149 |
catch (MySqlException ex) |
catch (MySqlException ex) |
| 150 |
{ |
{ |
| 151 |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
| 152 |
ret = StorageResponse.Failure; |
ret = BackendResponse.Failure; |
| 153 |
} |
} |
| 154 |
} |
} |
| 155 |
|
|
| 157 |
return ret; |
return ret; |
| 158 |
} |
} |
| 159 |
|
|
| 160 |
public StorageResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData) |
public BackendResponse TryFetchDataMetadata(UUID assetID, out Metadata metadata, out byte[] assetData) |
| 161 |
{ |
{ |
| 162 |
metadata = null; |
metadata = null; |
| 163 |
assetData = null; |
assetData = null; |
| 164 |
StorageResponse ret; |
BackendResponse ret; |
| 165 |
|
|
| 166 |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
| 167 |
{ |
{ |
| 188 |
|
|
| 189 |
assetData = (byte[])reader.GetValue(4); |
assetData = (byte[])reader.GetValue(4); |
| 190 |
|
|
| 191 |
ret = StorageResponse.Success; |
ret = BackendResponse.Success; |
| 192 |
} |
} |
| 193 |
else |
else |
| 194 |
{ |
{ |
| 195 |
ret = StorageResponse.NotFound; |
ret = BackendResponse.NotFound; |
| 196 |
} |
} |
| 197 |
} |
} |
| 198 |
catch (MySqlException ex) |
catch (MySqlException ex) |
| 199 |
{ |
{ |
| 200 |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
| 201 |
ret = StorageResponse.Failure; |
ret = BackendResponse.Failure; |
| 202 |
} |
} |
| 203 |
} |
} |
| 204 |
|
|
| 207 |
return ret; |
return ret; |
| 208 |
} |
} |
| 209 |
|
|
| 210 |
public StorageResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) |
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) |
| 211 |
{ |
{ |
| 212 |
assetID = metadata.ID = UUID.Random(); |
assetID = metadata.ID = UUID.Random(); |
| 213 |
return TryCreateAsset(metadata, assetData); |
return TryCreateAsset(metadata, assetData); |
| 214 |
} |
} |
| 215 |
|
|
| 216 |
public StorageResponse TryCreateAsset(Metadata metadata, byte[] assetData) |
public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) |
| 217 |
{ |
{ |
| 218 |
StorageResponse ret; |
BackendResponse ret; |
| 219 |
|
|
| 220 |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
using (MySqlConnection dbConnection = new MySqlConnection(DBConnString.GetConnectionString(server.ConfigFile))) |
| 221 |
{ |
{ |
| 238 |
int rowsAffected = command.ExecuteNonQuery(); |
int rowsAffected = command.ExecuteNonQuery(); |
| 239 |
if (rowsAffected == 1) |
if (rowsAffected == 1) |
| 240 |
{ |
{ |
| 241 |
ret = StorageResponse.Success; |
ret = BackendResponse.Success; |
| 242 |
} |
} |
| 243 |
else if (rowsAffected == 2) |
else if (rowsAffected == 2) |
| 244 |
{ |
{ |
| 245 |
Logger.Log.Info("Replaced asset " + metadata.ID.ToString()); |
Logger.Log.Info("Replaced asset " + metadata.ID.ToString()); |
| 246 |
ret = StorageResponse.Success; |
ret = BackendResponse.Success; |
| 247 |
} |
} |
| 248 |
else |
else |
| 249 |
{ |
{ |
| 250 |
Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); |
Logger.Log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); |
| 251 |
ret = StorageResponse.Failure; |
ret = BackendResponse.Failure; |
| 252 |
} |
} |
| 253 |
} |
} |
| 254 |
catch (MySqlException ex) |
catch (MySqlException ex) |
| 255 |
{ |
{ |
| 256 |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
Logger.Log.Error("Connection to MySQL backend failed: " + ex.Message); |
| 257 |
ret = StorageResponse.Failure; |
ret = BackendResponse.Failure; |
| 258 |
} |
} |
| 259 |
} |
} |
| 260 |
|
|