Example #1
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 #2
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 #3
0
        public static void mergeEntryHelper(Queue<History> svrQueue, Queue<History> cltQueue, Entry svr, Entry clt, RequestManager rm)
        {
            //병합은 삭제 없이 생성만 수행

            //1. 업로드 : FID가 없는 엔트리에 대해 업로드 수행 후 FID 설정
            //폴더는 이름이 있는지 없는지 확인 있다면 FID 있지 확인 후 FID 설정
            clt.Root.File.FileId = svr.Root.FID;
            uploadEntryElement(clt, svr.Root, clt.Root, rm);
            string[] Keys = new string[clt.Meta.Count];
            clt.Meta.Keys.CopyTo(Keys, 0);
            foreach (string key in Keys)
            {
                ArrayList al = (ArrayList)clt.Meta[key];
                foreach (FileData val in al)
                {
                    EntryElement t = EntryElement.getChild(clt.Root, val.ID);
                    rm.insertMeta(rm.userID, rm.aKey, t.File, key);
                }
            }

            //2. 다운로드 : 파일 비교 후 클라이언트 측 엔트리에 존재하지 않는 파일 모두 다운로드
            //파일아이디로 엔트리 검색 후 null인 노드에 대해 다운로드한다
            downloadEntryElement(clt, svr.Root, clt.Root, rm);
        }
Example #4
0
        /// <summary>
        /// 두 Entry를 병합, 서버와 클라이언트간 동기화를 위해 사용. 병합 후 히스토리 생성
        /// </summary>
        /// <param name="prv"></param>
        /// <param name="cur"></param>
        public static void mergeEntry(Entry svr, Entry clt, RequestManager rm)
        {
            //Client용 queue
            curQueue.Clear();

            //Server용 queue
            svrQueue.Clear();

            //병합 시작
            mergeEntryHelper(svrQueue, curQueue, svr, clt, rm);
        }
        public bool syncEnd(string uId, string key)
        {
            RequestManager rq = new RequestManager();
            string req = string.Format("userId={0}&clientKey={1}", uId, key);
            HttpWebResponse test = rq.SendPOSTRequest("http://210.118.74.120:8080/cu/api/syncEnd", req, null, null, true);
            string result = rq.GetResponseContent(test);
            dynamic jsonStr = JsonConvert.DeserializeObject(result);
            string r = jsonStr["result"];
            if (r.Equals("true"))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
 public string testLogin(string uId, string pwd)
 {
     RequestManager rq = new RequestManager();
     userID = uId;
     string req = string.Format("userId={0}&password={1}", userID, pwd);            
     HttpWebResponse test = rq.SendPOSTRequest("http://210.118.74.120:8080/cu/api/login", req, null, null, true);
     string result = rq.GetResponseContent(test);
     dynamic jsonStr = JsonConvert.DeserializeObject(result);            
     aKey = jsonStr["clientKey"];
     return aKey;
 }