コード例 #1
0
ファイル: Library.cs プロジェクト: t0p47/Mendeley
        private void getFirstTimeFolders()
        {
            NameValueCollection formData = HttpUtility.ParseQueryString(String.Empty);

            formData.Add("type", "windows");
            string postData = formData.ToString();

            string foldersResponse = RESTful.PostRequest(EndPoints.URL_SYNC_FOLDERS, postData);

            var folders = JsonConvert.DeserializeObject <List <FolderResponse> >(foldersResponse);

            foreach (FolderResponse responseFolder in folders)
            {
                /*Console.WriteLine("Folder response: id: "+responseFolder.id+", name: "
                 + responseFolder.name+", parent_id: "+responseFolder.parent_id);*/

                Folder folder = new Folder(responseFolder.id, responseFolder.name, responseFolder.parent_id);
                foldersList.Add(folder);
            }

            func.recreateAllFolders(foldersList);
            foldersList = func.getAllFolders();
            loadFolder();


            //Console.WriteLine("All folders: " + foldersResponse);
        }
コード例 #2
0
ファイル: Library.cs プロジェクト: t0p47/Mendeley
        private void getFirstTimeArticles()
        {
            NameValueCollection formData = HttpUtility.ParseQueryString(String.Empty);

            formData.Add("type", "windows");
            string postData = formData.ToString();

            string articlesResponse = RESTful.PostRequest(EndPoints.URL_SYNC_ARTICLES, postData);

            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            var articles = JsonConvert.DeserializeObject <List <JournalArticleResponse> >(articlesResponse, settings);

            foreach (JournalArticleResponse responseArticle in articles)
            {
                /*Console.WriteLine("Article id: "+responseArticle.id+", title: "+responseArticle.title
                 +", pages: "+responseArticle.pages);*/

                int volume  = responseArticle.volume == 0 ? -1 : responseArticle.volume;
                int issue   = responseArticle.issue == 0 ? -1 : responseArticle.issue;
                int year    = responseArticle.year == 0 ? -1 : responseArticle.year;
                int pages   = responseArticle.pages == 0 ? -1 : responseArticle.pages;
                int ArXivID = responseArticle.ArXivID == 0 ? -1 : responseArticle.ArXivID;
                int DOI     = responseArticle.DOI == 0 ? -1 : responseArticle.DOI;
                int PMID    = responseArticle.PMID == 0 ? -1 : responseArticle.PMID;

                JournalArticle article = new JournalArticle(responseArticle.id, responseArticle.title,
                                                            responseArticle.authors, responseArticle.@abstract, responseArticle.journal_id,
                                                            volume, issue, year, pages, ArXivID, DOI, PMID, responseArticle.folder,
                                                            responseArticle.filepath, responseArticle.created_at, responseArticle.updated_at, responseArticle.favorite);

                articlesList.Add(article);
            }

            func.recreateAllArticles(articlesList);
            articlesList = func.getRootFolderArticles();

            initDataGrid();

            //Console.WriteLine("All articles: "+articlesResponse);
        }
コード例 #3
0
ファイル: Library.cs プロジェクト: t0p47/Mendeley
        private void syncArticles()
        {
            string articlesListStr = func.composeJSONFromArticles();

            NameValueCollection formData = HttpUtility.ParseQueryString(String.Empty);

            formData.Add("request", articlesListStr);
            formData.Add("type", "windows");
            string postData = formData.ToString();

            string response = RESTful.PostRequest(EndPoints.URL_SEND_ARTICLES, postData);

            //MessageBox.Show("SyncArticles response: " + response);

            JObject obj = JObject.Parse(response);

            JArray serverCreatedArr   = obj["serverCreated"] as JArray;
            JArray insertedArticleArr = obj["insertedArticles"] as JArray;
            JArray needToSyncArr      = obj["needToSync"] as JArray;
            JArray needToDeleteArr    = obj["needToDelete"] as JArray;

            foreach (JValue needToDeleteObj in needToDeleteArr)
            {
                //MessageBox.Show("NeedToDelete: "+needToDeleteObj.ToString());

                func.deleteGlobalArticle(Convert.ToInt32(needToDeleteObj));

                //func.deleteGlobalArticle(Convert.ToInt32(needToDeleteObj.GetValue("global_id")));
            }

            foreach (JObject insertedArticleObj in insertedArticleArr)
            {
                int local_id  = Convert.ToInt32(insertedArticleObj.GetValue("local_id"));
                int global_id = Convert.ToInt32(insertedArticleObj.GetValue("global_id"));

                func.setGlobalIdToArticle(local_id, global_id);
            }

            foreach (JObject serverCreatedObj in serverCreatedArr)
            {
                func.addGlobalArticle(serverCreatedObj);
            }

            foreach (var needToSyncObj in needToSyncArr)
            {
                if (needToSyncObj.GetType() == typeof(JArray))
                {
                    foreach (JObject needToSyncFinalObj in needToSyncObj)
                    {
                        func.updateLocalArticleByServer(needToSyncFinalObj);
                    }
                }
            }


            //Databases are synched, refresh DataGridView

            /*
             * func.recreateAllArticles(articlesList);
             * articlesList = func.getRootFolderArticles();
             *
             * initDataGrid();
             */

            articlesList = func.getRootFolderArticles();
            initDataGrid();
            tvFolderTitle.Text = "All articles";
            MessageBox.Show("Синхронизация прошла успешно");
        }
コード例 #4
0
ファイル: Library.cs プロジェクト: t0p47/Mendeley
        private void syncFolders()
        {
            string folderListStr = func.composeJSONFromFolders();

            NameValueCollection formData = HttpUtility.ParseQueryString(String.Empty);

            formData.Add("request", folderListStr);
            formData.Add("type", "windows");
            string postData = formData.ToString();

            string response = RESTful.PostRequest(EndPoints.URL_SEND_FOLDERS, postData);


            MessageBox.Show("Folder response: " + response);

            JObject obj = null;

            obj = JObject.Parse(response);

            JArray globalIdNamesArr = obj["global_ids"] as JArray;
            JArray local_dataArr    = obj["local_data"] as JArray;

            //MessageBox.Show("obj: "+obj.ToString());

            foreach (JObject localFolderObj in local_dataArr)
            {
                int global_id = Convert.ToInt32(localFolderObj.GetValue("global_id"));
                int local_id  = Convert.ToInt32(localFolderObj.GetValue("local_id"));
                int is_delete = Convert.ToInt32(localFolderObj.GetValue("is_delete"));

                func.disableIsNewFolder();
                func.disableIsRenameFolder();

                //TODO: Если global_id вернувшейся папки равно 0, то родитель папки был удален и эту папку
                //TODO: тоже нужно удалить
                if (global_id == 0)
                {
                    func.deleteParentFolder(local_id);
                    continue;
                    //TODO:Если global_id вернувшейся папки равен -1, то просто удалить папки
                }
                else if (global_id == -1)
                {
                    func.deleteGlobalFolder(local_id);
                    continue;
                }

                //TODO: Если is_delete вернувшейся папки равно единице, то удаляем её
                if (is_delete == 1)
                {
                    func.deleteGlobalFolder(local_id);
                }
            }

            //Вторая часть

            foreach (JObject globalFolderData in globalIdNamesArr)
            {
                func.checkCreateRenameFolder(globalFolderData);
            }

            /*for (int i = 0; i < globalIdNamesArr.length(); i++)
             * {
             *
             *
             *
             *  JSONObject globalFolderData = globalIdNamesArr.getJSONObject(i);
             *  //int global_id = globalFolderData.getInt("id");
             *
             *  Log.d(TAG, "MainActivity: checkCreateRenameFolder global_id: " + globalFolderData.getInt("id")
             + ", title: " + globalFolderData.getString("name"));
             +
             +  dbh.checkCreateRenameFolder(globalFolderData);
             +
             +  //TODO: Restart Activity when done all synchronization
             + }*/
            /*}
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.Message, ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/

            syncArticles();
            //Upload(EndPoints.URL_SEND_FILE, "params",);
        }