コード例 #1
0
        // populate the folders as tree nodes
        private CustomTreeNode createNodes(Folder folder) {

            // first create the root node
            CustomTreeNode node = new CustomTreeNode();
            node.Name = folder.name;
            node.Text = folder.name;
            node.fieldType = folder.type;
            node.fieldId = folder.id;

            // check for the child folders and call this method again
            // it will be a self loop method
            FolderDao folderDao = new FolderDao();
            List<Folder> childFolders = folderDao.getChildFolders(node.fieldId);
            if (childFolders.Count > 0)
            {
                foreach (var childFolder in childFolders)
                {
                    CustomTreeNode childNode = createNodes(childFolder);
                    node.Nodes.Add(childNode);
                }
            }
            return node;
        }       
コード例 #2
0
        // This method fetches only the first level folders , and further calls the child folders of the
        // first level folders
        public void getAllFolders(String token, String workspaceId,int level)
        {

            // used class objects defined below
           
            List<Folder> firstLevelFolders = new List<Folder>();
          

            String url = Resource.endpoint + "wittyparrot/api/folders/workspaceId/" + workspaceId + "/level/" + level + "";
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            //var strJSONContent = "{\"workspaceId\":\"" + workspaceId + "\" ,\"level\":\"" + level + "\"}";

            var request = new RestRequest();
            request.Method = Method.GET;
            request.AddHeader("Authorization", "Bearer " + token);
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);

            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            String content = response.Content;
            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            // This method pulls the first level folder
            firstLevelFolders = JsonConvert.DeserializeObject<List<Folder>>(content);
            if (firstLevelFolders != null && firstLevelFolders.Count > 0)
            {
                // save the folders into db

                FolderDao folderDao = new FolderDao();
                folderDao.saveAllFolders(firstLevelFolders);

                foreach (var folder in firstLevelFolders)
                {

                    if (folder.hasChildren == false)
                    {
                        // in this scenario child folders wont be present 
                        // query for the wits in the folder
                        // Implimenting thread to improve the performance
                        
                        Thread thread = new Thread(() => getFolderWitsThread(folder));
                        thread.Start();

                    }
                    else if (folder.hasChildren == true)
                    {
                        // in this scenario child folders will be there                 
                        getChildFolders(token, folder.id,1);


                        // Implimenting thread to improve the performance
                        Thread thread = new Thread(() => getFolderWitsThread(folder));
                        thread.Start();
                    }
                }

            }         
        }
コード例 #3
0
        // Create Folder heirarchy using customtreeview control 
        private void prepareTreeNodeHeirarchy(String selectedWSid)
        {
            FolderDao folderDao = new FolderDao();
            List<Folder> folders = folderDao.getFolders(selectedWSid);

            if (folders.Count > 0) {

                myCustomTreeView.Nodes.Clear();   
                foreach (var folder in folders)
                {
                    CustomTreeNode node = createNodes(folder);
                    myCustomTreeView.Nodes.Add(node);
                }
            }          
        }
コード例 #4
0
        // This method will fetch all the child folders of the parent folder
        public void getChildFolders(String token, String folderId,int level)
        {
            String url = Resource.endpoint + "wittyparrot/api/folders/" + folderId + "/hierarchy/level/" + level ;
            var client = new RestClient();
            client.BaseUrl = new Uri(url);

            var request = new RestRequest();
            request.Method = Method.GET;
            request.Parameters.Clear();
            request.AddParameter("Authorization", "Bearer " + token, ParameterType.HttpHeader);
            request.RequestFormat = DataFormat.Json;

            // execute the request
            IRestResponse response = client.Execute(request);
            String content = response.Content;

            if (response.ErrorException != null)
            {
                var statusMessage = RestUtils.getErrorMessage(response.StatusCode);
                MessageBox.Show(statusMessage == "" ? response.StatusDescription : statusMessage);
                var myException = new ApplicationException(response.StatusDescription, response.ErrorException);
                throw myException;
            }

            
            Folder parentfolder = JsonConvert.DeserializeObject<Folder>(content);
            List<Folder> childFolders = parentfolder.children;
            if (childFolders != null && childFolders.Count > 0)
            {
                foreach (var folder in childFolders)
                {
                    // save the folders into db

                    FolderDao folderDao = new FolderDao();
                    folderDao.saveFolder(folder);

                    WitsDao witsDao = new WitsDao();
                    RestClientWits restWits = new RestClientWits();


                    List<Wits> wits = restWits.getFolderWits(folder.id);
                    if (wits != null && wits.Count > 0)
                    {
                        witsDao.saveAllWits(wits);
                    }


                  
                    if (folder.hasChildren != null && folder.hasChildren == true)
                    {
                        // This is a self loop code where it check if a folder is having child folders
                        // loop itself get all the child folders and the wits of that folder
                        getChildFolders(token, folder.id, level);
                    }

                }
            }


        }