public string md5hash(RepositoryItem item) { if (item.IsFolder) { return "d41d8cd98f00b204e9800998ecf8427e";//default folder etag for zero bytes inode generated from s3. } return md5hash (item.LocalAbsolutePath); }
public void Copy(RepositoryItem item) { string path = item.ResultItem.LocalAbsolutePath; if (Exists (item.ResultItem)) Delete (item.ResultItem); if (item.IsFolder) { if(!Directory.Exists(path)){ var dir = new DirectoryInfo(item.LocalAbsolutePath); CopyDir (dir, path); } }else{ CopyFile(item.LocalAbsolutePath, path); } }
public bool Exists(RepositoryItem item) { return Exists(item.LocalAbsolutePath); }
public RepositoryItem GetFomDatabase(RepositoryItem item) { string sql = string.Format("SELECT * FROM REPOSITORYITEM WHERE RepositoryItemKey = '{0}'", item.Key.Replace("'", "''")); return Select(sql).Last(); }
public bool Exists(RepositoryItem item) { string sql = string.Format("SELECT count(*) FROM REPOSITORYITEM WHERE RepositoryItemKey = '{0}'", item.Key.Replace("'", "''")); int i = int.Parse(database.ExecuteScalar (sql)); return i > 0; }
public override void ActualizeUpdatedAt(RepositoryItem item) { string sql = string.Format("UPDATE REPOSITORYITEM SET UpdatedAt = '{0}' WHERE RepositoryItemID = '{1}' ", item.UpdatedAt, item.Id); database.ExecuteNonQuery (sql); }
public override void Update(RepositoryItem i) { database.ExecuteNonQuery(string.Format("UPDATE REPOSITORYITEM SET RepositoryItemKey='{1}', RepositoryId='{2}', IsFolder='{3}', ResultItemId = '{4}', eTag = '{5}', eTagLocal = '{6}', Moved = '{7}', UpdatedAt = '{8}' WHERE RepositoryItemID ='{0}'", i.Id, i.Key.Replace("'", "''"), i.Repository.Id, i.IsFolder, ((i.ResultItem == null) ? "" : i.ResultItemId.ToString()), i.ETag, i.LocalETag, i.Moved, i.UpdatedAt)); }
//TODO DONT NEED public void Remove(RepositoryItem item) { //string sql = string.Format("UPDATE REPOSITORYITEM SET DELETED = '{0}' WHERE NAME = '{1}' AND RELATIVEPATH = '{2}' AND REPOPATH = '{3}'", bool.TrueString, item.Name, item.RelativePath, item.Repository.Path); //database.ExecuteNonQuery (sql); }
public bool IsFolder(RepositoryItem item) { if (Exists(item)) { int ID = GetId (item); return GetById (ID).IsFolder; } return true; }
public string RemoteETAG(RepositoryItem item) { GetObjectResponse meta = GetMetadata (item.Key); if(meta == null){ Logger.LogInfo("ERROR ON READING METADATA", "ETAG from " + item.Key + " cannot be calculated. Metadata not found!"); return ""; } return meta.ETag.Replace("\"", ""); }
public void Move(RepositoryItem item) { if(item.IsFolder){ GenericCopy (item.Key, item.ResultItem.Key); MoveEntry(connection.Connect ().ListObjects (RuntimeSettings.DefaultBucketName, item.Key), item); }else{ GenericCopy (item.Key, item.ResultItem.Key); } Delete (item); }
public bool Exists(RepositoryItem item) { return Exists(item.Key); }
public void CreateFolder(RepositoryItem item) { if (!Exists(item)){ CreatePath (item.LocalAbsolutePath); BlockWatcher (item.LocalAbsolutePath); Directory.CreateDirectory (item.LocalAbsolutePath); UnblockWatcher (item.LocalAbsolutePath); } }
public void Move(RepositoryItem item) { string path = item.ResultItem.LocalAbsolutePath; if (Exists (item.ResultItem)) Delete (item.ResultItem); if (item.IsFolder) { MoveDir(item.LocalAbsolutePath, path); }else{ MoveFile(item.LocalAbsolutePath, path); } }
//TODO understand and refactor public bool IsSync(RepositoryItem item) { //if(item.IsFolder) // return true; //if(item.ETag == string.Empty) // throw new Exception ("Remote Hash not exists"); //item.LocalMD5Hash = CalculateMD5Hash(item); //return item.RemoteMD5Hash == item.LocalMD5Hash; return true; }
public abstract void MarkAsUnmoved(RepositoryItem item);
public abstract void UpdateETAG(RepositoryItem i);
public void Upload(RepositoryItem item) { if(item.IsFolder){ GenericCreateFolder (item.Key); //UploadEntry(connection.Connect ().ListObjects (RuntimeSettings.DefaultBucketName, item.Key), item); }else{ GenericUpload (item.Key, item.LocalAbsolutePath); } }
public override void MarkAsUnmoved(RepositoryItem item) { item.Moved = true; string sql; if(item.IsFolder) sql = string.Format("UPDATE REPOSITORYITEM SET Moved = '{0}' WHERE RepositoryItemID = '{1}' AND RepositoryItemKey LIKE '{2}%' ", bool.FalseString, item.Id, item.Key.Replace("'", "''")); else sql = string.Format("UPDATE REPOSITORYITEM SET Moved = '{0}' WHERE RepositoryItemID = '{1}' ", bool.FalseString, item.Id); database.ExecuteNonQuery (sql); }
private void MoveEntry(IEnumerable<ListEntry> entries, RepositoryItem father) { foreach(ListEntry entry in entries ){ string key = Key(entry); if(key != string.Empty && key != father.Key ){ RepositoryItem item = CreateObjectInstance (entry); item.BuildResultItem (Path.Combine(father.ResultItem.Key, item.Name)); if(item.Key != father.Key){ Move (item); } } } }
public List<RepositoryItem> Select(string sql) { List<RepositoryItem> items = new List<RepositoryItem>(); DataTable dt = database.GetDataTable(sql); foreach(DataRow dr in dt.Rows){ RepositoryItem item = new RepositoryItem (LocalRepository.CreateInstance(int.Parse(dr[2].ToString()))); item.Id = int.Parse(dr[0].ToString()); item.Key = dr[1].ToString(); if(dr[2].ToString().Length > 0) item.IsFolder = bool.Parse (dr[3].ToString()); if(dr[4].ToString().Length > 0) item.ResultItemId = int.Parse (dr[4].ToString()); item.ETag = dr[5].ToString(); item.LocalETag = dr[6].ToString(); item.Moved = bool.Parse (dr[7].ToString()); if(dr[8].ToString().Length > 0) item.UpdatedAt = dr[8].ToString(); items.Add (item); } return items; }
private void UploadEntry(IEnumerable<ListEntry> entries, RepositoryItem father) { foreach(ListEntry entry in entries ){ if(Key(entry) != string.Empty){ RepositoryItem item = CreateObjectInstance (entry); if(item.Key != father.Key){ Upload (item); } } } }
public override void UpdateETAG(RepositoryItem item) { string sql = string.Format("UPDATE REPOSITORYITEM SET eTag = '{0}', eTagLocal = '{1}' WHERE RepositoryItemID = '{2}' ", item.ETag, item.LocalETag, item.Id); database.ExecuteNonQuery (sql); }
public void Delete(RepositoryItem item) { GenericDelete (item.Key, item.IsFolder); }
public override void Create(RepositoryItem item) { item.Id = (int)database.ExecuteNonQuery(string.Format("INSERT INTO REPOSITORYITEM (RepositoryItemKey, RepositoryId, IsFolder, ResultItemId, eTag, eTagLocal, Moved, UpdatedAt) VALUES ('{0}', '{1}','{2}','{3}','{4}','{5}', '{6}', '{7}')", item.Key.Replace("'", "''"), item.Repository.Id, item.IsFolder, ((item.ResultItem == null) ? "" : item.ResultItemId.ToString()), item.ETag, item.LocalETag, item.Moved, item.UpdatedAt), true); }
public void Download(RepositoryItem item, bool recursive = false) { physicalController.CreatePath(item.LocalFolderPath); if (item.IsFolder) { physicalController.CreateFolder(item); if (recursive) DownloadEntry(connection.Connect ().ListObjects (RuntimeSettings.DefaultBucketName, item.Key), item); } else { GenericDownload (item.Key, item.LocalAbsolutePath); } }
public bool ExistsUnmoved(RepositoryItem item) { return ExistsUnmoved(item.Key, item.Repository); }
public abstract void ActualizeUpdatedAt(RepositoryItem resultItem);
public int GetId(RepositoryItem item) { if (Exists (item)){ //if (item.Id != 0) // return item.Id; //else return Select(string.Format("SELECT * FROM REPOSITORYITEM WHERE RepositoryItemKey = '{0}' AND RepositoryId = '{1}'", item.Key.Replace("'", "''"), item.Repository.Id)).Last().Id; } return 0; }
public abstract void Create(RepositoryItem e);