Example #1
0
        private int ExpandNode(System.Windows.Forms.TreeNode objParent, FolderNode fNode)
        {
            int numSubfolders = 0;

            // Don't waste time expanding the same node twice...
            if (fNode.Expanded)
            {
                return(0);
            }

            // Properties to exclude in the query results
            string strFolderId = fNode.Id;

            string[] strExclude = new string[5];
            strExclude[0] = "DateCreated";
            strExclude[1] = "DateLastModified";

            // Comment out stuff that gets us in trouble when recursion is enabled
            strExclude[2] = "ObjectStore";
            strExclude[3] = "ClassDescription";
            strExclude[4] = "Parent";

            // Get the folder's Subfolders list object
            CEWSI.ObjectRequestType   objSubFoldersRequest = new CEWSI.ObjectRequestType();
            CEWSI.ObjectSpecification objSubFoldersSpec    = new CEWSI.ObjectSpecification();
            objSubFoldersSpec.classId                = "Folder";
            objSubFoldersSpec.objectId               = strFolderId;
            objSubFoldersSpec.objectStore            = MainForm.Library;
            objSubFoldersSpec.propertyId             = "SubFolders";
            objSubFoldersRequest.SourceSpecification = objSubFoldersSpec;
            objSubFoldersRequest.id             = "1";
            objSubFoldersRequest.PropertyFilter = new CEWSI.PropertyFilterType();
            objSubFoldersRequest.PropertyFilter.ExcludeProperties = strExclude;
            //objSubFoldersRequest.PropertyFilter.maxRecursion = 3;
            //objSubFoldersRequest.PropertyFilter.maxRecursionSpecified = true;
            //objSubFoldersRequest.maxElements = 2;
            //objSubFoldersRequest.maxElementsSpecified = true;

            // Get the folder itself
            //CEWSI.ObjectRequestType objFolderRequest = new CEWSI.ObjectRequestType();
            //CEWSI.ObjectSpecification objFolderSpec = new CEWSI.ObjectSpecification();
            //objFolderSpec.classId = "Folder";
            //objFolderSpec.objectId = strFolderId;
            //objFolderSpec.objectStore = MainForm.Library;
            //objFolderRequest.SourceSpecification = objFolderSpec;
            //objFolderRequest.id = "3";
            //objFolderRequest.PropertyFilter = new CEWSI.PropertyFilterType();
            //objFolderRequest.PropertyFilter.ExcludeProperties = strExclude;

            // Create the request array
            CEWSI.ObjectRequestType[] objRequestArray = new CEWSI.ObjectRequestType[1];
            objRequestArray[0] = objSubFoldersRequest;

            // Fill in the security headers...
            CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(MainForm.User,
                                                                               MainForm.Domain, MainForm.Password, MainForm.URL);

            // Send off the request
            CEWSI.ObjectResponseType[] objResponses = null;
            try
            {
                objResponses = objBinding.GetObjects(WSIUtil.GetLocalization(), objRequestArray);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while querying for a folder: [" + ex.Message + "]");
                return(0);
            }

            // Get the nodes below the parent
            if (objResponses.Length > 0 && objResponses[0].id == "1")
            {
                if (objResponses[0].GetType() == typeof(CEWSI.ErrorStackResponse))
                {
                    CEWSI.ErrorStackResponse objErrResponse = (CEWSI.ErrorStackResponse)objResponses[0];
                    CEWSI.ErrorStackType     objStack       = objErrResponse.ErrorStack;
                    CEWSI.ErrorRecordType    objErr         = objStack.ErrorRecord[0];
                    MessageBox.Show("Error [" + objErr.Description + "] occurred. " +
                                    " Err source is [" + objErr.Source + "]");
                    return(0);
                }

                CEWSI.ObjectSetResponse objSetResponse = (CEWSI.ObjectSetResponse)objResponses[0];
                CEWSI.ObjectSetType     objSet         = objSetResponse.ObjectSet;
                if (objSet.Object != null && objSet.Object.Length > 0)
                {
                    foreach (CEWSI.ObjectValue objValue in (CEWSI.ObjectValue[])objSet.Object)
                    {
                        numSubfolders += 1;
                        System.Windows.Forms.TreeNode objNode = new System.Windows.Forms.TreeNode();
                        FolderNode newNode = new FolderNode();
                        foreach (CEWSI.PropertyType objProp in objValue.Property)
                        {
                            if (objProp.propertyId == "FolderName")
                            {
                                string strName = ((CEWSI.SingletonString)objProp).Value;
                                objNode.Text = strName;
                                newNode.Name = strName;
                            }
                            if (objProp.propertyId == "Id")
                            {
                                string strId = ((CEWSI.SingletonId)objProp).Value;
                                newNode.Id = strId;
                            }
                        }
                        objNode.Tag = (object)newNode;
                        objParent.Nodes.Add(objNode);
                    }
                }
            }
            objParent.Expand();
            fNode.Expanded = true;
            return(numSubfolders);
        }