//테스트를 위한 히스토리 리턴 함수(지우기) public History[] pyo(string metaData) { string meta = metaData; // History[] h = new History[5]; for (int i = 0; i < 5; i++) { h[i] = new History() { Type = HistoryType.Create, Data = new ContentManager.FileData() { FileName = i + "", FullPathStr = i + "", Metadata = new ArrayList { i+"Hello", i+"Hi"} }, OldPath = "경로", Sync = true }; } return h; }
public void makeFolder(string root, Entry entry, History h) { string rpath = makePath(entry, h); string fullPath = root + rpath + "\\" + h.Data.FileName; ; string[] path = makePathToken(entry, h); EntryElement newEntryElement; EntryElement targetFolder = entry.Root; if (path != null) { for (int i = 0; i < path.Length; i++) { targetFolder = (EntryElement)targetFolder.NamedChildren[path[i]]; } } if (!targetFolder.NamedChildren.ContainsKey(h.Data.FileName)) { h.Data.FullPathStr = rpath + "\\" + h.Data.FileName; newEntryElement = new EntryElement { File = h.Data, Type = EntryType.Folder }; targetFolder.Children.Add(newEntryElement); targetFolder.NamedChildren.Add(h.Data.FileName, newEntryElement); System.IO.Directory.CreateDirectory(fullPath); } else { if (h.Data.FileId != ((EntryElement)targetFolder.NamedChildren[h.Data.FileName]).File.FileId) { string prvFileName = h.Data.FileName; h.Data.FileName = h.Data.FileName + "_"; h.Data.FullPathStr = rpath + "\\" + h.Data.FileName; fullPath = root + rpath + "\\" + h.Data.FileName ; System.IO.Directory.CreateDirectory(fullPath); newEntryElement = new EntryElement { File = h.Data, Type = EntryType.Folder }; targetFolder.Children.Add(newEntryElement); targetFolder.NamedChildren.Add(h.Data.FileName, newEntryElement); string date = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); entry.HistoryQueue.Enqueue(new History(HistoryType.Rename, h.Data, rpath + "\\" + prvFileName,date, false)); } } }
public void fileDownload(string uId, string Key, int fileId, string root, Entry entry, History h) { string req = string.Format("fileId={0}&userId={1}&clientKey={2}", fileId, uId, Key); HttpWebResponse reqResult = SendPOSTRequest("http://210.118.74.120:8080/cu/api/download", req, null, null, true); string rpath = makePath(entry, h); string fullPath = root + rpath + "\\" + h.Data.FileName; string[] path = makePathToken(entry, h); EntryElement targetFolder = entry.Root; EntryElement newEntryElement; if (path != null) { for (int i = 0; i < path.Length; i++) { targetFolder = (EntryElement)targetFolder.NamedChildren[path[i]]; } } if (!targetFolder.NamedChildren.ContainsKey(h.Data.FileName)) { h.Data.FullPathStr = rpath; GetResponseContentToFile(reqResult, fullPath); newEntryElement = new EntryElement { File = h.Data, Type = EntryType.File }; targetFolder.Children.Add(newEntryElement); targetFolder.NamedChildren.Add(h.Data.FileName, newEntryElement); } else { if (h.Data.FileId != ((EntryElement)targetFolder.NamedChildren[h.Data.FileName]).File.FileId) { string prvFileName = h.Data.FileName; h.Data.FileName = h.Data.FileName + "_"; h.Data.FullPathStr = rpath + "\\" + h.Data.FileName; fullPath = root + rpath + "\\" + h.Data.FileName; GetResponseContentToFile(reqResult, fullPath); newEntryElement = new EntryElement { File = h.Data, Type = EntryType.File }; targetFolder.Children.Add(newEntryElement); targetFolder.NamedChildren.Add(h.Data.FileName, newEntryElement); string date = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); entry.HistoryQueue.Enqueue(new History(HistoryType.Rename, h.Data, rpath + "\\" + prvFileName, date, false)); } } }
public string makePath(Entry entry, History h) { /*int current = h.Data.Parent; string result = ""; while (((FileData)LinearList[current]).Parent != 0) { FileData cFile = (FileData)LinearList[current]; result = "\\" + cFile.FileName + result; current = cFile.Parent; } return result;*/ EntryElement[] pathToken = findParent(entry.Root, h); string result = ""; if (pathToken != null) { for (int i = pathToken.Length - 1; i >= 0; i--) { result = "\\" + pathToken[i].File.FileName; } } return result; }
public string[] makePathToken(Entry entry, History h) { Queue<string> p = new Queue<string>(); EntryElement[] pathToken = findParent(entry.Root, h); if (pathToken != null) { for (int i = pathToken.Length - 1; i >= 0; i--) { p.Enqueue(pathToken[i].File.FileName); } string[] result = p.ToArray(); return result; } else return null; }
public EntryElement[] findParent(EntryElement root, History h) { if (root == null) { return null; } EntryElement[] entrylist = root.Children.ToArray(typeof(EntryElement)) as EntryElement[]; if (entrylist != null) { foreach (EntryElement e in entrylist) { if (e.File.FileId == h.Data.Parent) return new EntryElement[] { e }; else { if (h.FType == HistoryFileType.Folder) { EntryElement[] el = findParent(e, h); if (el != null) { ArrayList nn = new ArrayList(el); nn.Add(e); return nn.ToArray(typeof(EntryElement)) as EntryElement[]; } } } } } return null; }
public EntryElement findParentFolder(EntryElement root, History h) { if (root == null) { return null; } EntryElement[] entrylist = root.Children.ToArray(typeof(EntryElement)) as EntryElement[]; foreach (EntryElement e in entrylist) { if (e.File.FileId == h.Data.Parent) return e; else { if (h.FType == HistoryFileType.Folder) { EntryElement result = findParentFolder(e, h); if (result != null) return result; } } } return null; }
public void deleteFIle(Entry entry, History h) { EntryElement targetFolder = findParentFolder(entry.Root, h); if (targetFolder == null) targetFolder = entry.Root; EntryElement targetFile = (EntryElement)targetFolder.NamedChildren[h.Data.FileName]; deleteTarget(entry, targetFolder, targetFile); if (h.FType == HistoryFileType.File) { File.Delete(entry.RootPath + h.Data.FullPathStr + "\\" + h.Data.FileName); } else { Directory.Delete(entry.RootPath + h.Data.FullPathStr + "\\" + h.Data.FileName, true); } }
public void moveFile(Entry entry, History h) { string[] result = makePathToken(entry, h); h.Data.FullPathStr = entry.RootPath; EntryElement targetFolder = entry.Root; }
public void insertFullPath(Entry entry, History h) { h.Data.FullPathStr = makePath(entry, h); }
public void syncFromHistory(string uId, string Key, History[] historyList, string rootPath, Entry entry) { try { foreach (History h in historyList) { entry.HistoryQueue.Enqueue(h); if (h.Type == HistoryType.Create) { if (h.FType == HistoryFileType.Folder) { makeFolder(entry.RootPath, entry, h); } else { fileDownload(uId, Key, h.Data.FileId, entry.RootPath, entry, h); } } else if (h.Type == HistoryType.Delete) { deleteFIle(entry, h); } else if (h.Type == HistoryType.Rename) { EntryElement parent = findParentFolder(entry.Root, h); string path = makePath(entry, h); if (parent != null) { EntryElement[] cl = parent.Children.ToArray(typeof(EntryElement)) as EntryElement[]; foreach (EntryElement ee in cl) { if (ee.File.FileId == h.Data.FileId) { if (h.FType == HistoryFileType.Folder) { Directory.Move(entry.RootPath + path + "\\" + ee.File.FileName, entry.RootPath + path + "\\" + h.Data.FileName); } else { File.Move(entry.RootPath + path + "\\" + ee.File.FileName, entry.RootPath + path + "\\" + h.Data.FileName); } } } } } else if (h.Type == HistoryType.Etc) { /*EntryElement parent = findParentFolder(entry.Root, h); EntryElement target = findTarget(entry.Root, h); string path = makePath(entry, h); if (parent != null) { EntryElement[] cl = parent.Children.ToArray(typeof(EntryElement)) as EntryElement[]; foreach (EntryElement ee in cl) { if (ee.File.FileId == h.Data.FileId) { if (h.FType == HistoryFileType.Folder) { Directory.Move(entry.RootPath + path + "\\" + ee.File.FileName, entry.RootPath + path + "\\" + h.Data.FileName); } else { File.Move(entry.RootPath + path + "\\" + ee.File.FileName, entry.RootPath + path + "\\" + h.Data.FileName); } } } }*/ } else { } } } catch (Exception e) { } }
public void checkHistory(Entry entry, History[] historyList) { ArrayList sum = new ArrayList(); compareDate cd = new compareDate(); foreach (History h in historyList) { sum.Add(h); } foreach (History h in entry.HistoryQueue) { if(h.Sync == false) sum.Add(h); } sum.Sort(cd); History[] sumList = sum.ToArray(typeof(History)) as History[]; for (int i = 0; i < sumList.Length; i++ ) { if (sumList[i].Type == HistoryType.Delete) { if (historyList.Contains(sumList[i])) { ArrayList check = new ArrayList(); for (int j = i + 1; j < sumList.Length; j++) { if (sumList[j].Data.FileId == sumList[i].Data.FileId) { if (sumList[j].Type == HistoryType.Delete) { for (int k = 0; k < check.Count; k++) { ((History)check[k]).Sync = true; } check.Clear(); break; } else { check.Add(sumList[j]); } } } if (check.Count > 0) { entry.ConfilicHistory.Add(check); } else { entry.ServerHistroy.Add(sumList[i]); } } } else { } } }