Example #1
0
        public void setRoot(EntryElement root)
        {
            RootPath = "\\";
            Root = root;
            CurrentRoot = Root;
            Parent = null;

        }
Example #2
0
 public Entry(string root)
 {
     count = -1;
     RootPath = root;
     Meta = new Hashtable();
     LinearList = new Hashtable();
     HistoryQueue = new Queue<History>();            
     ServerHistroy = new ArrayList();
     ClientHistory = new ArrayList();
     ConfilicHistory = new ArrayList();
     Root = new EntryElement(this, EntryType.Folder, root);
     CurrentRoot = Root;
     Parent = null;
     Limit = limit;
     
 }
Example #3
0
        /// <summary>
        /// EntryElement의 자식도느 추가
        /// </summary>
        /// <param name="entry">전체 Entry</param>
        /// <param name="e">추가 할 EntryElement</param>
        public History addChild(Entry entry, EntryElement e)
        {
            if (!contains(e))
            {
                int count = 1;
                string[] fileNameToken = e.FILENAME.Split('.');
                string resultFileName = e.FILENAME;
                if (fileNameToken.Length > 1)
                {
                    while (NamedChildren.Contains(resultFileName))
                    {
                        
                        resultFileName = makeFileName(fileNameToken[0], fileNameToken[1], count++);
                    }
                }
                else
                {
                    while (NamedChildren.Contains(resultFileName))
                    {
                        resultFileName = makeFileName(fileNameToken[0], "", count++);
                    }
                }

                if (count > 1)
                {
                    System.IO.File.Move(entry.RootPath + e.File.FullPathStr + "\\" + e.FILENAME, entry.RootPath + e.File.FullPathStr + "\\" + resultFileName);
                    e.File.FileName = resultFileName;
                }

                HistoryFileType ht;
                e.File.Parent = File.FileId;
                Children.Add(e);
                NamedChildren.Add(e.FILENAME, e);

                if (e.Type == EntryType.File)
                    ht = HistoryFileType.File;
                else
                    ht = HistoryFileType.Folder;

                string date = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

                Date = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

                return new History
                {
                    Type = HistoryType.Create,
                    FType = ht,
                    Data = e.File,
                    Sync = false,
                    Date = date
                };
            }
            return null;
        }
Example #4
0
 public void setRoot(string root)
 {
     RootPath = root;
     Root = new EntryElement(this, EntryType.Folder, root);
     CurrentRoot = Root;
     Parent = null;
 }
Example #5
0
        public void deleteFileFromMeta(EntryElement target)
        {

        }
Example #6
0
 public void searchEntry(EntryElement root)
 {            
     EntryElement[] entrylist = root.Children.ToArray(typeof(EntryElement)) as EntryElement[];
     foreach (EntryElement e in entrylist)
     {
         e.Index = count++;
         if (e.Type == EntryType.Folder)
         {
             String[] filelist = Directory.GetFiles(RootPath + e.File.FullPathStr);
             String[] folderlist = Directory.GetDirectories(RootPath + e.File.FullPathStr);
             makeEntryList(e, filelist, folderlist);
             searchEntry(e);
         }
     }
 }
Example #7
0
        public static void deleteEntryHelper(Queue<History> historyQueue, Entry entry, EntryElement e)
        {
            EntryElement[] folderList = e.getDirectories();
            EntryElement[] fileList = e.getFiles();

            foreach (EntryElement d in folderList)
            {
                deleteEntry(historyQueue, entry, d);
                historyQueue.Enqueue(e.removeChild(d));
            }

            
            string date = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
            foreach (EntryElement f in fileList)
            {                
                string[] ext = f.FILENAME.Split('.');
                if (ext.Length > 1)
                    entry.addMetaData(ext.Last(), e.File);
                entry.addMetaData(date, e.File);
                historyQueue.Enqueue(e.removeChild(f));
            }
        }
Example #8
0
 public static EntryElement findParent(EntryElement root, EntryElement e)
 {
     if (root.FID == e.File.Parent)
         return root;
     else
     {
         EntryElement[] directories = root.getDirectories();
         EntryElement parent = null;
         foreach (EntryElement d in directories)
         {
             parent = findParent(d, e);
             if (parent != null)
                 break;
         }
         return parent;
     }           
 }
Example #9
0
        public static EntryElement findParentByID(EntryElement root, EntryElement e)
        {
            EntryElement[] files = root.getFiles();
            EntryElement[] dirs = root.getDirectories();

            foreach (EntryElement f in files)
            {
                if (root.File.ID == f.File.ID)
                    return root;
            }

            EntryElement result = null;

            foreach (EntryElement d in dirs)
            {
                if (root.FILENAME != d.FILENAME)
                {
                    result = findParentByID(d, e);
                    if (result != null)
                        break;
                }else{
                    return root;
                }
            }
            return result;
        }
Example #10
0
 /// <summary>
 /// 입력된 EntryElement의 리스트에 포함된 EntryElement를 자식노드에 추가
 /// </summary>
 /// <param name="entryList"></param>
 public void addChildren(Entry entry, EntryElement[] entryList)
 {
     foreach (EntryElement e in entryList)
     {
         addChild(entry, e);
     }
 }
Example #11
0
        /// <summary>
        /// File과 Directory를 입력받아 자식노드에 추가
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="fileList"></param>
        /// <param name="folderList"></param>
        public void addChildren(Entry entry, string[] fileList, string[] folderList)
        {
            foreach (string file in fileList)
            {
                EntryElement newElement = new EntryElement(entry, EntryType.File, file);                
                addChild(entry, newElement);              

                string date = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
                entry.addMetaData(date, newElement.File);
                string[] ext = file.Split('.');
                if (ext.Length > 1)
                    entry.addMetaData(ext.Last(), newElement.File);
            }
            foreach (string folder in folderList)
            {
                EntryElement newElement = new EntryElement(entry, EntryType.Folder, folder);                
                addChild(entry, newElement);
            }
        }
Example #12
0
        public EntryElement getChild(EntryElement e)
        {
            EntryElement[] children;

            if (e.Type == EntryType.File)
            {
                children = getFiles();
                foreach (EntryElement c in children)
                {
                    if (c.FID == e.FID || c.ID == e.ID)
                        return c;
                }
                return null;
            }
            else
            {
                children = getDirectories();
                foreach (EntryElement c in children)
                {
                    if (e.FILENAME.Equals(c.FILENAME))
                        return c;
                }
                return null;
            }
        }
Example #13
0
        /// <summary>
        /// EntryElement의 자식노드에 해당 EntryElement가 포함되어 있는지 확인
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public bool contains(EntryElement e)
        {
            EntryElement[] children;

            if (e.Type == EntryType.File)
            {
                children = getFiles();
                foreach (EntryElement c in children)
                {
                    if ((c.FID == e.FID) || (!c.ID.Equals("-1")&&c.ID == e.ID))
                        return true;
                }
            }
            else
            {
                children = getDirectories();
                foreach (EntryElement c in children)
                {
                    if (e.FILENAME.Equals(c.FILENAME))
                        return true;
                }
            }
            
            return false;
            /*if (NamedChildren.Contains(e.FILENAME) && ((EntryElement)NamedChildren[e.FILENAME]).ID == e.ID)
                return true;
            else
                return false;*/
        }
Example #14
0
        /// <summary>
        /// EntryElement의 자식노드 제거
        /// </summary>
        /// <param name="e"></param>
        public History removeChild(EntryElement e)
        {
            if (contains(e))
            {
                HistoryFileType ht;

                Children.Remove(e);
                NamedChildren.Remove(e.FILENAME);

                if (e.Type == EntryType.File)
                    ht = HistoryFileType.File;
                else
                    ht = HistoryFileType.Folder;

                Date = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

                return new History
                {
                    Type = HistoryType.Delete,
                    FType = ht,
                    Data = e.File,
                    Sync = false,
                    Date = Date
                };
            }
            return null;
        }
Example #15
0
        public static void createEntry(Queue<History> historyQueue, Hashtable metadata, Entry entry, EntryElement p, EntryElement e)
        {
            EntryElement newElement = new EntryElement
            {
                Index = e.Index,
                Type = e.Type,
                File = e.File,
                Children = e.Children,
                NamedChildren = e.NamedChildren,
                Metadata = e.Metadata
            };

            

            historyQueue.Enqueue(p.addChild(entry, newElement));

            if (e.Type == EntryType.Folder)
            {
                EntryElement[] childrenList = e.getChildren();

                foreach (EntryElement c in childrenList)
                {
                    createEntry(historyQueue, metadata, entry, newElement, c);
                }
            }
        }
Example #16
0
        public static void parseEntryJSON(EntryElement root)
        {
            if (root.Children.Count == 0) return;
            ArrayList ChildrenObject = new ArrayList();
            JObject[] entrylist = root.Children.ToArray(typeof(JObject)) as JObject[];
            root.Children.Clear();
            foreach (JObject e in entrylist)
            {
                EntryElement ee = JsonConvert.DeserializeObject<EntryElement>(e.ToString());
                ChildrenObject.Add(ee);
                parseEntryJSON(ee);
            }
            root.Children = ChildrenObject;

            string[] keys = new string[root.NamedChildren.Count];
            root.NamedChildren.Keys.CopyTo(keys, 0);

            foreach (string k in keys)
            {
                JObject jo = (JObject)root.NamedChildren[k];
                EntryElement ee = JsonConvert.DeserializeObject<EntryElement>(jo.ToString());
                root.NamedChildren.Remove(k);
                root.NamedChildren.Add(k, ee);
                parseEntryJSON(ee);
            }
            
        }
Example #17
0
 public static void deleteEntry(Queue<History> historyQueue, Entry entry, EntryElement e)
 {
     EntryElement parent = EntryElement.getParent(entry, e);
     if (parent != null)
     {
         if (e.Type == EntryType.Folder)
         {
             deleteEntryHelper(historyQueue, entry, e);
         }
         historyQueue.Enqueue(parent.removeChild(e));
     }
 }
Example #18
0
        public static EntryElement findTarget(EntryElement root, EntryElement target)
        {
            if (root.FID == target.File.FileId)
                return root;
            else
            {
                if (root.Type == EntryType.Folder)
                {
                    EntryElement[] nextfile = root.getChildren();

                    foreach (EntryElement n in nextfile)
                    {
                        EntryElement e = findTarget(n, target);
                        if (e != null)
                            return e;
                    }
                }
                
                return null;
            }
        }
Example #19
0
 public static Entry buildEntryFromFileList(Entry entry, EntryElement[] fileList)
 {
     if (fileList.Length > 0)
     {
         Entry newEntry = new Entry();
         newEntry.setRoot(fileList[0]);
         entry.Root.File.FileId = newEntry.Root.File.FileId;
         for (int i = 1; i < fileList.Length; i++)
         {
             EntryElement parent = EntryElement.findParent(newEntry.Root, fileList[i]);
             parent.addChild(entry, fileList[i]);
         }
         return newEntry;
     }
     return null;            
 }
Example #20
0
        public static void downloadEntryElement(Entry cltEntry, EntryElement svr, EntryElement clt, RequestManager rm)
        {
            EntryElement[] children = svr.getChildren();
            foreach (EntryElement c in children)
            {
                EntryElement targetElement = Entry.findTarget(clt, c);
                if (targetElement == null)
                {
                    string fullPath = cltEntry.RootPath + c.File.FullPathStr + "\\" + c.FILENAME;
                    if (c.Type == EntryType.File)
                    {                        
                        rm.downloadFile(rm.userID, rm.aKey, cltEntry, c);
                        EntryElement newElement = new EntryElement(cltEntry, EntryType.File, fullPath);
                        newElement.File.FileId = c.FID;
                        EntryElement parent = Entry.findTarget(clt, svr);
                        parent.addChild(cltEntry, newElement);
                    }
                    else
                    {
                        //폴더 생성
                        System.IO.Directory.CreateDirectory(fullPath);
                        EntryElement newElement = new EntryElement(cltEntry, EntryType.Folder, fullPath);
                        newElement.File.FileId = c.FID;
                        EntryElement parent = Entry.findTarget(clt, svr);
                        parent.addChild(cltEntry, newElement);
                        //생성 된 폴더에 대해 재귀
                        downloadEntryElement(cltEntry, c, clt, rm);
                    }
                }
                else
                {
                    //다운받지 않아도 존재하는 파일. 이부분에서 변경 날짜 확인 후 충돌리스트로
                    //만약 폴더라면 재귀
                    if (!c.FILENAME.Equals(targetElement.FILENAME))
                    {

                    }
                    else
                    {
                        if (c.Type == EntryType.Folder)
                        {
                            downloadEntryElement(cltEntry, c, clt, rm);
                        }
                    }
                }
            }
        }
Example #21
0
        public void makeEntryList(EntryElement root, String[] filelist, String[] folderlist)
        {
            
            foreach (String s in filelist)
            {
                String parentpath = s;
                String[] token = s.Split('\\');
                string[] rtoken = RootPath.Split('\\');
                string rpath = "";
                for (int i = rtoken.Length; i < token.Length; i++)
                {
                    rpath = rpath + "\\" + token[i];
                }
                if (token != null)
                {
                    if (!root.NamedChildren.ContainsKey(token.Last()))
                    {
                        EntryElement newElement = new EntryElement(EntryType.File, new FileData { FileName = token.Last(), FullPathStr = rpath });

                        if (root.File.FileId != -1)
                        {
                            if (!LinearList.ContainsKey(root.File.FileId))
                                LinearList.Add(root.File.FileId, root);
                        }

                        root.Children.Add(newElement);
                        root.NamedChildren.Add(token.Last(), newElement);
                    }
                }
                
            }
            foreach (String s in folderlist)
            {
                String parentpath = s;
                String[] token = s.Split('\\');
                string[] rtoken = RootPath.Split('\\');
                string rpath = "";
                for (int i = rtoken.Length; i < token.Length; i++)
                {
                    rpath = rpath + "\\" + token[i];
                }
                if (token != null)
                {
                    if (!root.NamedChildren.ContainsKey(token.Last()))
                    {
                        EntryElement newElement = new EntryElement(EntryType.Folder, new FileData { FileName = token.Last(), FullPathStr = rpath });

                        if (root.File.FileId != -1)
                        {
                            if (!LinearList.ContainsKey(root.File.FileId))
                                LinearList.Add(root.File.FileId, root);
                        }

                        root.Children.Add(newElement);
                        root.NamedChildren.Add(token.Last(), newElement);
                    }
                }
                
            }
        }
Example #22
0
 public static void uploadEntryElement(Entry cltEntry, EntryElement svr, EntryElement clt, RequestManager rm)
 {
     EntryElement[] cltList = clt.getChildren();
     foreach (EntryElement e in cltList)
     {   
         if (e.FID < 0)
         {
             //동기화 되지 않은 폴더 및 파일 -> 업로드한다                    
             e.File.Parent = clt.FID;
             if (e.Type == EntryType.Folder)
             {
                 int fid = rm.generateFolder(rm.userID, rm.aKey, e.File);
                 e.File.FileId = fid;
                 uploadEntryElement(cltEntry, svr, e, rm);                        
             }
             else
             {
                 int fid = rm.uploadFile(rm.userID, rm.aKey, cltEntry, e.File);
                 e.File.FileId = fid;
             }
         }
         else
         {
             //동기화된 파일 -> 충돌 확인
             EntryElement targetElement = Entry.findTarget(svr, e);
             if (targetElement == null)
             {
                 if (e.Type == EntryType.Folder)
                 {
                     e.File.Parent = clt.FID;
                     int fid = rm.generateFolder(rm.userID, rm.aKey, e.File);
                     e.File.FileId = fid;
                     
                     uploadEntryElement(cltEntry, svr, e, rm);
                 }
                 else
                 {
                     int fid = rm.uploadFile(rm.userID, rm.aKey, cltEntry, e.File);
                     e.File.FileId = fid;
                 }
             }
             else
             {
                 if (!e.FILENAME.Equals(targetElement.FILENAME))
                 {
                     //rm.renameFile(rm.userID, rm.aKey, e);
                 }
                 else
                 {
                     if (e.Type == EntryType.Folder)
                         uploadEntryElement(cltEntry, svr, e, rm);
                 }
             }
         }
     }
 }
Example #23
0
        public void makeEntryFromData(FileData[] fileList)
        {
            //search root
            EntryElement root = new EntryElement();
            foreach (FileData f in fileList)
            {
                if (f.Parent == 0)
                {
                    root.File = f;
                    break;
                }
            }

        }
Example #24
0
        public static EntryElement findTargetByID(EntryElement root, EntryElement e)
        {
            if (root.Type == EntryType.Folder)
            {
                if (root.FILENAME == e.FILENAME)
                    return root;
                else
                {
                    EntryElement[] nextfile = root.getChildren();

                    foreach (EntryElement n in nextfile)
                    {
                        EntryElement element = findTargetByID(n, e);
                        if (element != null)
                            return element;
                    }
                    return null;
                }
            }
            else
            {
                if (root.File.ID == e.File.ID)
                    return root;
                else
                    return null;
            }            
        }
Example #25
0
        public void deleteFile(EntryElement parent, EntryElement target, string date)
        {
            if (target.Type == EntryType.Folder)
            {
                EntryElement[] children = target.Children.ToArray(typeof(EntryElement)) as EntryElement[];
                foreach (EntryElement e in children)
                {
                    deleteFile(target, e, date);
                }
                HistoryQueue.Enqueue(new History(HistoryType.Delete, target.File, date, false));
                parent.Children.Remove(target);
                parent.NamedChildren.Remove(target.File.FileName);
            }
            else if (target.Type == EntryType.File)
            {
                HistoryQueue.Enqueue(new History(HistoryType.Delete, target.File, date, false));
                parent.Children.Remove(target);
                parent.NamedChildren.Remove(target.File.FileName);
                deleteFileFromMeta(target); 
            }

        }
Example #26
0
 public static void recursiveCompareDelete(Queue<History> historyQueue, Hashtable metadata, Entry prvEntry, EntryElement prv, EntryElement cur)
 {
                 
     //파일 삭제 : Prv에 있는데 Current에 없는것, 과거 리스트를 현재 리스트에 대조하여 현재 리스트에 없는 Element는 삭제된 Element이다.
     EntryElement[] prvList = prv.getChildren();
     foreach (EntryElement e in prvList)
     {
         EntryElement targetElement = Entry.findTargetByID(cur, e);
         if (targetElement == null)
         {
             deleteEntry(historyQueue, prvEntry, e);
         }
         else
         {
             //폴더면 제귀적으로 자식 노드를 구성
             if (targetElement.Type == EntryType.Folder)
                 recursiveCompareDelete(historyQueue, metadata, prvEntry, e, cur);
         }
     }            
 }
Example #27
0
        public void onFileChanged(object source, FileSystemEventArgs e)
        {
            if (HistoryQueue.Count >= Limit) HistoryQueue.Dequeue();
            string[] rpath = RootPath.Split('\\');
            string[] bpath = e.FullPath.Split('\\');
            string[] path = null;

            EntryElement targetFolder = Root;
            string resultPath = "";

            if (rpath.Length - bpath.Length > 1)
            {
                path = new string[rpath.Length - bpath.Length-1];
                for (int i = rpath.Length; i < bpath.Length-1; i++)
                {
                    path[i] = bpath[i];
                    resultPath = resultPath + "\\" + bpath[i];
                }
                for (int i = 0; i < path.Length; i++)
                {
                    targetFolder = (EntryElement)targetFolder.NamedChildren[path[i]];
                }
            }
            
            FileData newFIle = new FileData
            {
                FileName = e.Name,
                FullPathStr = resultPath,
                Parent = targetFolder.File.FileId
            };
            
            EntryElement newEntryElement;
            string fullPath = RootPath + resultPath + "\\" + newFIle.FileName;
            if ((File.GetAttributes(resultPath) & FileAttributes.Directory) == FileAttributes.Directory)
            {
                newEntryElement = new EntryElement
                {
                    File = newFIle,
                    Type = EntryType.Folder
                };
            }
            else
            {
                newEntryElement = new EntryElement
                {
                    File = newFIle,
                    Type = EntryType.File
                };
            }

            string date = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);

            if (e.ChangeType == WatcherChangeTypes.Created)
            {                
                HistoryQueue.Enqueue(new History(HistoryType.Create, newFIle, date, false));                
            }
            else if (e.ChangeType == WatcherChangeTypes.Deleted)
            {                
                deleteFile(targetFolder, (EntryElement)(targetFolder.NamedChildren[e.Name]), date);                
            }
            else if (e.ChangeType == WatcherChangeTypes.Changed)
            {
                HistoryQueue.Enqueue(new History(HistoryType.Change, newFIle, date, false));
            }            
        }
Example #28
0
        public static void recursiveCompareCreate(Queue<History> historyQueue, Hashtable metadata, Entry prvEntry, EntryElement prv, EntryElement cur)
        {
            //파일 생성 : Prv에 없는데 Current에 있는것, 현재 리스트를 과거 리스트에 대조하여 과거 리스트에 없는 Element는 새로 생성된 Element이다.
            EntryElement[] curList = cur.getChildren();
            foreach (EntryElement e in curList)
            {
                EntryElement targetElement = Entry.findTargetByID(prv, e);
                if (targetElement == null)
                {
                    createEntry(historyQueue, metadata, prvEntry, prv, e);
                }
                else
                {
                    //폴더나 파일명이 서로 다르다면
                    if (!e.FILENAME.Equals(targetElement.FILENAME))
                    {
                        historyQueue.Enqueue(targetElement.changeFilename(e.FILENAME));
                    }

                    e.FID = targetElement.FID;
                    //폴더면 제귀적으로 자식 노드를 구성, 파일이면 메타데이터 추가
                    if (targetElement.Type == EntryType.Folder)
                    {                        
                        recursiveCompareCreate(historyQueue, metadata, prvEntry, targetElement, e);
                    }
                    else
                    {
                        e.Metadata = targetElement.Metadata;
                        string[] keys = e.Metadata.ToArray(typeof(string)) as string[];
                        foreach (string key in keys)
                        {
                            if (metadata.Contains(key))
                            {
                                ((ArrayList)metadata[key]).Add(e.File);
                            }
                            else
                            {
                                ArrayList newList = new ArrayList();
                                newList.Add(e.File);
                                metadata.Add(key, newList);
                            }
                        }
                    }

                    
                }
            }
        }
Example #29
0
        public static EntryElement getChild(EntryElement target,string fileID)
        {
            EntryElement result = target.getChild(fileID);

            if (result == null)
            {
                EntryElement[] directories = target.getDirectories();
                foreach (EntryElement e in directories)
                {
                    result = getChild(e, fileID);
                    if (result != null)
                        break;
                }
            }
         
            return result;
        }
Example #30
0
        public void buildEntryHelper(EntryElement r)
        {
            String[] fileList = Directory.GetFiles(RootPath + r.PATH + "\\" + r.FILENAME);
            String[] folderList = Directory.GetDirectories(RootPath + r.PATH + "\\" + r.FILENAME);

            r.addChildren(this, fileList, folderList);
            foreach (EntryElement e in r.getDirectories())
            {
                buildEntryHelper(e);
            }
        }