private void FileDoc(string strDocId, string strDocClass, string strDocTitle, string strFolderPath)
        {
            // Create a Create verb, populate it to create a new RCR
            CEWSI.CreateAction createVerb = new CEWSI.CreateAction();
            createVerb.autoUniqueContainmentName          = true;
            createVerb.autoUniqueContainmentNameSpecified = true;
            createVerb.classId = "DynamicReferentialContainmentRelationship";

            CEWSI.ChangeRequestType objChange = new CEWSI.ChangeRequestType();
            objChange.Action                       = new CEWSI.ActionType[1];
            objChange.Action[0]                    = (CEWSI.ActionType)createVerb;
            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = MainForm.Library;
            objChange.id = "1";

            // Create the properties of the new RCR
            CEWSI.ObjectReference objHeadRef = new CEWSI.ObjectReference();
            objHeadRef.classId     = strDocClass;
            objHeadRef.objectId    = strDocId;
            objHeadRef.objectStore = MainForm.Library;
            CEWSI.SingletonObject propHead = new CEWSI.SingletonObject();
            propHead.propertyId = "Head";
            propHead.Value      = (CEWSI.ObjectEntryType)objHeadRef;

            CEWSI.ObjectReference objTailRef = new CEWSI.ObjectReference();
            objTailRef.classId     = "Folder";
            objTailRef.objectId    = strFolderPath;
            objTailRef.objectStore = MainForm.Library;
            CEWSI.SingletonObject propTail = new CEWSI.SingletonObject();
            propTail.propertyId = "Tail";
            propTail.Value      = (CEWSI.ObjectEntryType)objTailRef;

            CEWSI.SingletonString propContainmentName = new CEWSI.SingletonString();
            propContainmentName.propertyId = "ContainmentName";
            propContainmentName.Value      = strDocTitle;

            CEWSI.ModifiablePropertyType[] objProps = new CEWSI.ModifiablePropertyType[3];
            objProps[0] = propTail;
            objProps[1] = propHead;
            objProps[2] = propContainmentName;
            objChange.ActionProperties = objProps;

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

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = false;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while filing a document: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }

            MessageBox.Show("Successfully filed a document!");
            return;
        }
Exemple #2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // OK, what are we supposed to retrieve
            System.Data.DataRow dtRow;
            int i = dgrdContainees.CurrentRowIndex;

            dtRow = g_dtblResults.Rows[i];
            string strId          = (string)dtRow["Id"];
            string strContentSize = (string)dtRow["ContentSize"];

            MessageBox.Show("Retrieving content for document [" + strId + "]  size= " + strContentSize + " bytes.");

            // Retrieve the document
            CEWSI.ObjectRequestType   objContentRequest = new CEWSI.ObjectRequestType();
            CEWSI.ObjectSpecification objContentSpec    = new CEWSI.ObjectSpecification();
            objContentSpec.classId                = "Document";
            objContentSpec.objectId               = strId;
            objContentSpec.objectStore            = MainForm.Library;
            objContentRequest.SourceSpecification = objContentSpec;
            objContentRequest.id = "1";

            // Ask for the content properties...
            CEWSI.FilterElementType[] incContentProps;
            if (UseGetContent)
            {
                incContentProps = new CEWSI.FilterElementType[1];
            }
            else
            {
                incContentProps = new CEWSI.FilterElementType[2];
            }
            incContentProps[0]       = new CEWSI.FilterElementType();
            incContentProps[0].Value = "ContentElements";
            if (!UseGetContent)
            {
                incContentProps[1]                  = new CEWSI.FilterElementType();
                incContentProps[1].Value            = "Content";
                incContentProps[1].maxSize          = 1000000;
                incContentProps[1].maxSizeSpecified = true;
            }

            objContentRequest.PropertyFilter = new CEWSI.PropertyFilterType();
            objContentRequest.PropertyFilter.IncludeProperties     = incContentProps;
            objContentRequest.PropertyFilter.maxRecursion          = 1;
            objContentRequest.PropertyFilter.maxRecursionSpecified = true;

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

            // 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 containees: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }


            // Did we get some content?
            if (objResponses.Length < 1)
            {
                MessageBox.Show("No content found");
                return;
            }
            if (objResponses[0].GetType() == typeof(CEWSI.ErrorStackResponse))
            {
                CEWSI.ErrorStackResponse errStackResponse = (CEWSI.ErrorStackResponse)objResponses[0];
                CEWSI.ErrorStackType     objStack         = errStackResponse.ErrorStack;
                CEWSI.ErrorRecordType    objErr           = objStack.ErrorRecord[0];
                MessageBox.Show("Error [" + objErr.Description + "] occurred. " +
                                " Err source is [" + objErr.Source + "]");
                return;
            }

            // Extract the document object from the response
            CEWSI.ObjectValue objDoc = null;
            if (objResponses[0].GetType() == typeof(CEWSI.SingleObjectResponse))
            {
                CEWSI.SingleObjectResponse objResponse = (CEWSI.SingleObjectResponse)objResponses[0];
                objDoc = objResponse.Object;
            }
            else if (objResponses[0].GetType() == typeof(CEWSI.ObjectSetResponse))
            {
                CEWSI.ObjectSetResponse objSetResponse = (CEWSI.ObjectSetResponse)objResponses[0];
                CEWSI.ObjectSetType     objSet         = objSetResponse.ObjectSet;
                objDoc = objSet.Object[0];
            }
            else
            {
                MessageBox.Show("Unknown data type returned in ObjectReponse: [" + objResponses[0].GetType().ToString() + "]");
                return;
            }

            // OK, we got some content.  Get the bits from the response packet
            // First find the ContentElements property

            /*
             * if( objDoc.Property == null )
             * {
             *      MessageBox.Show("Received a document with no properties!");
             *      return;
             * }
             */

            // Extract the content for each content element
            foreach (CEWSI.PropertyType objProp in objDoc.Property)
            {
                if (objProp.propertyId.ToLower().CompareTo("contentelements") == 0)
                {
                    CEWSI.DependentObjectType[] contTrans = (CEWSI.DependentObjectType[])((CEWSI.ListOfObject)objProp).Value;
                    if (contTrans == null)
                    {
                        MessageBox.Show("The selected document has no content");
                        break;
                    }
                    for (int nItem = 0; nItem < contTrans.Length; nItem++)
                    {
                        Byte[] byteContent = null;

                        if (UseGetContent)
                        {
                            CEWSI.ContentRequestType crt = new CEWSI.ContentRequestType();
                            crt.cacheAllowed          = true;
                            crt.cacheAllowedSpecified = true;
                            crt.id                   = "1";
                            crt.maxBytes             = 100 * 1024;
                            crt.maxBytesSpecified    = true;
                            crt.startOffset          = 0;
                            crt.startOffsetSpecified = true;
                            crt.continueFrom         = null;

                            CEWSI.ElementSpecificationType est = new CEWSI.ElementSpecificationType();
                            est.itemIndex                      = nItem;
                            est.itemIndexSpecified             = true;
                            est.elementSequenceNumber          = 0;
                            est.elementSequenceNumberSpecified = false;

                            crt.ElementSpecification = est;

                            CEWSI.ObjectSpecification objSpec = new CEWSI.ObjectSpecification();
                            objSpec.classId     = "Document";
                            objSpec.objectId    = strId;
                            objSpec.objectStore = MainForm.Library;

                            crt.SourceSpecification = objSpec;

                            CEWSI.ContentRequestType[] contReqArray = new CEWSI.ContentRequestType[1];
                            contReqArray[0] = crt;

                            CEWSI.FNCEWS40PortTypeClient binding2 = WSIUtil.ConfigureBinding(MainForm.User,
                                                                                             MainForm.Domain, MainForm.Password, MainForm.URL);

                            // Send off the request
                            CEWSI.GetContentRequest gcr = new CEWSI.GetContentRequest();
                            gcr.ContentRequest        = contReqArray;
                            gcr.validateOnly          = false;
                            gcr.validateOnlySpecified = true;
                            CEWSI.ContentResponseType[] contResponses = null;
                            try
                            {
                                contResponses = binding2.GetContent(WSIUtil.GetLocalization(), gcr);
                            }
                            catch (System.Net.WebException ex)
                            {
                                MessageBox.Show("An exception occurred while fetching content for a content element: [" + ex.Message + "]");
                                return;
                            }
                            catch (Exception allEx)
                            {
                                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                                return;
                            }

                            CEWSI.ContentResponseType crt2 = contResponses[0];
                            if (crt2 is CEWSI.ContentErrorResponse)
                            {
                                CEWSI.ContentErrorResponse cer      = (CEWSI.ContentErrorResponse)crt2;
                                CEWSI.ErrorStackType       objStack = cer.ErrorStack;
                                CEWSI.ErrorRecordType      objErr   = objStack.ErrorRecord[0];
                                MessageBox.Show("Error [" + objErr.Description + "] occurred. " +
                                                " Err source is [" + objErr.Source + "]");
                                return;
                            }
                            else if (crt2 is CEWSI.ContentElementResponse)
                            {
                                CEWSI.ContentElementResponse elem = (CEWSI.ContentElementResponse)crt2;
                                CEWSI.InlineContent          ic   = (CEWSI.InlineContent)elem.Content;

                                byteContent = ic.Binary;
                            }
                            else
                            {
                                MessageBox.Show("Unknown data type returned in content response: [" + crt.GetType().ToString() + "]");
                                return;
                            }
                        }       // end if (UseGetContent)
                        else
                        {
                            CEWSI.DependentObjectType contTran = (CEWSI.DependentObjectType)contTrans[nItem];
                            CEWSI.PropertyType[]      props    = (CEWSI.PropertyType[])contTran.Property;
                            if (props != null)
                            {
                                CEWSI.ContentData   contData = (CEWSI.ContentData)props[0];
                                CEWSI.InlineContent ic       = (CEWSI.InlineContent)contData.Value;

                                byteContent = ic.Binary;
                            }
                        }

                        // Write the retrieved content out to a file
                        System.DateTime now         = System.DateTime.Now;
                        string          strFileName = "C:\\Temp\\ContentElement0";                // + nItem.ToString();
                        strFileName = strFileName + "_" + now.Month.ToString();
                        strFileName = strFileName + "_" + now.Day.ToString();
                        strFileName = strFileName + "_" + now.Year.ToString();
                        strFileName = strFileName + "_" + now.Hour.ToString();
                        strFileName = strFileName + "_" + now.Minute.ToString();
                        strFileName = strFileName + "_" + now.Millisecond.ToString();
                        MessageBox.Show("Saving content of size " + byteContent.Length.ToString() + " to file: " + strFileName);
                        saveContentToFile(strFileName, byteContent);
                    }
                }
            }
        }
        private void btnCreate_Click_1(object sender, System.EventArgs e)
        {
            long   lngPropCount       = 1;
            long   lngActionCount     = 1;
            string strContentLocation = "";
            string strRetrievalName   = "";
            ulong  ulContentSize      = 0;

            // If content was specified, do some sanity checks and prepare...
            if (chkContent.Checked)
            {
                // Extract the location, retrieval name, and MIME type
                if (txtContentLocation.Text == "")
                {
                    MessageBox.Show("Looks like you forgot to specify a content location - aborting");
                    return;
                }
                if (txtMimeType.Text == "")
                {
                    MessageBox.Show("Looks like you forgot to specify a MIME type - aborting");
                    return;
                }
                strContentLocation = txtContentLocation.Text.Replace('/', '\\');
                int nStart = strContentLocation.LastIndexOf('\\');
                strRetrievalName = (nStart > 1) ? strContentLocation.Substring(nStart + 1, (strContentLocation.Length - nStart - 1)) : strContentLocation;

                // Verify that the file exists and get its size
                ulContentSize = getFileContentSize(strContentLocation);
                if (ulContentSize == 0)
                {
                    MessageBox.Show("The specified content file either does not exist, or is of zero length");
                    return;
                }
                lngPropCount += 1;
            }

            // Sanity checks if content by reference was specified...
            if (chkContentReference.Checked)
            {
                if (txtContentURL.Text == "")
                {
                    MessageBox.Show("Looks like you forgot to specify a content URL - aborting");
                    return;
                }
                if (txtMimeType.Text == "")
                {
                    MessageBox.Show("Looks like you forgot to specify a MIME type - aborting");
                    return;
                }
                lngPropCount += 1;
            }

            // Get the WS binding object
            //  (this will be used to set WS-Security parameters)
            CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(MainForm.User,
                                                                               MainForm.Domain, MainForm.Password, MainForm.URL);

            // We first need to create a Create verb, populate it
            CEWSI.CreateAction createVerb = new CEWSI.CreateAction();
            createVerb.classId = txtDocClass.Text;

            // If the user wants to check the document in, then we'll add a separate
            //  Checkin verb as well
            CEWSI.CheckinAction checkinVerb = new CEWSI.CheckinAction();
            if (chkCheckIn.Checked)
            {
                checkinVerb.checkinMinorVersion          = true;
                checkinVerb.checkinMinorVersionSpecified = true;
                lngActionCount += 1;
            }

            CEWSI.ChangeRequestType objChange = new CEWSI.ChangeRequestType();
            objChange.Action    = new CEWSI.ActionType[lngActionCount];
            objChange.Action[0] = (CEWSI.ActionType)createVerb;
            if (chkCheckIn.Checked)
            {
                objChange.Action[1] = (CEWSI.ActionType)checkinVerb;
            }

            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = MainForm.Library;
            objChange.id = "1";

            // Build a list of properties to set in the new document
            CEWSI.ModifiablePropertyType[] objInputProps = new CEWSI.ModifiablePropertyType[lngPropCount];
            CEWSI.SingletonString          objString     = new CEWSI.SingletonString();
            objString.Value      = txtTitle.Text;
            objString.propertyId = "DocumentTitle";
            objInputProps[0]     = objString;

            if (chkContent.Checked || chkContentReference.Checked)
            {
                // Create content properties array
                //   ContentTransfer elements will take three properties:
                //		* RetrievalName
                //		* Content
                //		* ContentType
                //   ContentReference elements will take two properties:
                //		* ContentLocation
                //		* ContentType
                CEWSI.PropertyType[] ctProps = null;
                if (chkContent.Checked)
                {
                    ctProps = new CEWSI.PropertyType[3];
                }
                else
                {
                    ctProps = new CEWSI.PropertyType[2];
                }

                // Set the ContentType property
                CEWSI.SingletonString typeProp = new CEWSI.SingletonString();
                typeProp.propertyId = "ContentType";
                typeProp.Value      = txtMimeType.Text;
                ctProps[0]          = typeProp;

                // Create the dependent object type object
                CEWSI.DependentObjectType ct = new CEWSI.DependentObjectType();
                ct.dependentAction          = CEWSI.DependentObjectTypeDependentAction.Insert;
                ct.dependentActionSpecified = true;

                // ContentTransfer case
                if (chkContent.Checked)
                {
                    // create RetrievalName name property
                    CEWSI.SingletonString nameProp = new CEWSI.SingletonString();
                    nameProp.propertyId = "RetrievalName";
                    nameProp.Value      = strRetrievalName;
                    ctProps[1]          = nameProp;

                    // create content data object
                    CEWSI.ContentData contData = new CEWSI.ContentData();
                    contData.propertyId = "Content";

                    CEWSI.InlineContent ic = new CEWSI.InlineContent();
                    ic.Binary = getSouceFileContent(strContentLocation);

                    contData.Value = ic;
                    ctProps[2]     = contData;

                    // Dependent object is of type ContentTransfer
                    ct.classId = "ContentTransfer";
                }

                // ContentReference case
                else
                {
                    // Create the ContentLocation property
                    CEWSI.SingletonString locationProp = new CEWSI.SingletonString();
                    locationProp.propertyId = "ContentLocation";
                    locationProp.Value      = txtContentURL.Text;
                    ctProps[1] = locationProp;

                    // Dependent object is of type ContentReference
                    ct.classId = "ContentReference";
                }

                //	create content object list
                ct.Property = ctProps;
                CEWSI.DependentObjectType[] contentObjects = new CEWSI.DependentObjectType[1];
                contentObjects[0] = ct;

                //	Create the content element list and set it into the document's properties
                CEWSI.ListOfObject objContentList = new CEWSI.ListOfObject();
                objContentList.propertyId = "ContentElements";
                objContentList.Value      = contentObjects;
                objInputProps[1]          = objContentList;
            }
            objChange.ActionProperties = objInputProps;

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = true;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while creating a document: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }


            // Created a document!  Sanity check the results
            string strObjectId = "";
            bool   bFound      = false;

            if (objResponseArray == null || objResponseArray.Length < 1)
            {
                MessageBox.Show("The change request was executed, but a valid object was not returned");
                return;
            }
            CEWSI.ChangeResponseType objResponse = objResponseArray[0];
            foreach (CEWSI.PropertyType objProp in objResponse.Property)
            {
                if (objProp.propertyId.CompareTo("Id") == 0)
                {
                    strObjectId = IdmObjectType.getPropertyValue(objProp);
                    bFound      = true;
                    break;
                }
            }
            if (!bFound)
            {
                MessageBox.Show("The document was created, but the results do not contain a document ID!");
                return;
            }

            if (chkFile.Checked)
            {
                MessageBox.Show("Successfully created a document!  ID = [" + strObjectId + "].  Now filing.");
                FileDoc(strObjectId, txtDocClass.Text, txtTitle.Text, txtFolderName.Text);
            }
            else
            {
                MessageBox.Show("Successfully created a document!  ID = [" + strObjectId + "]");
            }
            return;
        }
Exemple #4
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);
        }
Exemple #5
0
        private void btnContainees_Click(object sender, System.EventArgs e)
        {
            FolderNode folder;

            // Reset the data grid
            dgrdContainees.DataSource = null;
            dgrdContainees.Show();
            btnGetContent.Enabled = false;

            // Get the ID of the folder we are to search for containees
            if (treeFolders.SelectedNode == null)
            {
                MessageBox.Show("You must first select a folder node");
                return;
            }
            folder = (FolderNode)treeFolders.SelectedNode.Tag;
            string strFolderId = folder.Id;

            // Properties to exclude in the query results
            string[] strExclude = new string[2];
            strExclude[0] = "DateCreated";
            strExclude[1] = "DateLastModified";

            // Get the folder's Containees list object
            CEWSI.ObjectRequestType   objContaineesRequest = new CEWSI.ObjectRequestType();
            CEWSI.ObjectSpecification objContaineesSpec    = new CEWSI.ObjectSpecification();
            objContaineesSpec.classId                = "Folder";
            objContaineesSpec.objectId               = strFolderId;
            objContaineesSpec.objectStore            = MainForm.Library;
            objContaineesSpec.propertyId             = "Containees";
            objContaineesRequest.SourceSpecification = objContaineesSpec;
            objContaineesRequest.id = "1";

            // Make sure to ask for the Head property of the RCR
            objContaineesRequest.PropertyFilter = new CEWSI.PropertyFilterType();
            CEWSI.FilterElementType filterHead        = new CEWSI.FilterElementType();
            CEWSI.FilterElementType filterCName       = new CEWSI.FilterElementType();
            CEWSI.FilterElementType filterId          = new CEWSI.FilterElementType();
            CEWSI.FilterElementType filterCreator     = new CEWSI.FilterElementType();
            CEWSI.FilterElementType filterContentSize = new CEWSI.FilterElementType();
            CEWSI.FilterElementType filterTitle       = new CEWSI.FilterElementType();

            filterHead.Value        = "Head";
            filterCName.Value       = "ContainmentName";
            filterId.Value          = "Id";
            filterCreator.Value     = "Creator";
            filterContentSize.Value = "ContentSize";
            filterTitle.Value       = "DocumentTitle";

            objContaineesRequest.PropertyFilter.IncludeProperties     = new CEWSI.FilterElementType[6];
            objContaineesRequest.PropertyFilter.IncludeProperties[0]  = filterHead;
            objContaineesRequest.PropertyFilter.IncludeProperties[1]  = filterCName;
            objContaineesRequest.PropertyFilter.IncludeProperties[2]  = filterId;
            objContaineesRequest.PropertyFilter.IncludeProperties[3]  = filterCreator;
            objContaineesRequest.PropertyFilter.IncludeProperties[4]  = filterContentSize;
            objContaineesRequest.PropertyFilter.IncludeProperties[5]  = filterTitle;
            objContaineesRequest.PropertyFilter.ExcludeProperties     = strExclude;
            objContaineesRequest.PropertyFilter.maxRecursion          = 1;
            objContaineesRequest.PropertyFilter.maxRecursionSpecified = true;
            // Test continuation  objContaineesRequest.maxElements = 2;
            //                    objContaineesRequest.maxElementsSpecified = true;

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

            // 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 containees: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }


            // Get the containees
            if (objResponses.Length < 1)
            {
                MessageBox.Show("No containees found");
                return;
            }

            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;
            }

            CEWSI.ObjectSetResponse objSetResponse = (CEWSI.ObjectSetResponse)objResponses[0];
            CEWSI.ObjectSetType     objResults     = objSetResponse.ObjectSet;
            if (objResults.Object == null || objResults.Object.Length < 1)
            {
                MessageBox.Show("No containees found");
                return;
            }

            // Query was successful; display a list of result rows
            // First create a data table that has our columns in it
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;

            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");

            dtCol              = new System.Data.DataColumn("RCRId");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            dtCol              = new System.Data.DataColumn("ContainmentName");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            dtCol              = new System.Data.DataColumn("Id");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            dtCol              = new System.Data.DataColumn("ClassID");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            dtCol              = new System.Data.DataColumn("Title");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            dtCol              = new System.Data.DataColumn("Creator");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            dtCol              = new System.Data.DataColumn("ContentSize");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // For each containee, make an entry in our data table
            CEWSI.ObjectValue objHead = null;
            foreach (CEWSI.ObjectValue objContainee in (CEWSI.ObjectValue[])objResults.Object)
            {
                dtRow = dtblResults.NewRow();
                foreach (CEWSI.PropertyType objProp in objContainee.Property)
                {
                    if (objProp.propertyId == "ContainmentName")
                    {
                        dtRow["ContainmentName"] = IdmObjectType.getPropertyValue(objProp);
                    }

                    if (objProp.propertyId == "Id")
                    {
                        dtRow["RCRId"] = IdmObjectType.getPropertyValue(objProp);
                    }

                    if (objProp.propertyId == "Head")
                    {
                        objHead = (CEWSI.ObjectValue)((CEWSI.SingletonObject)objProp).Value;

                        dtRow["ClassId"] = objHead.classId.ToString();

                        foreach (CEWSI.PropertyType objHeadProp in objHead.Property)
                        {
                            if (objHeadProp.propertyId == "Id")
                            {
                                dtRow["Id"] = IdmObjectType.getPropertyValue(objHeadProp);
                            }
                            if (objHeadProp.propertyId == "Creator")
                            {
                                dtRow["Creator"] = IdmObjectType.getPropertyValue(objHeadProp);
                            }
                            if (objHeadProp.propertyId == "ContentSize")
                            {
                                dtRow["ContentSize"] = IdmObjectType.getPropertyValue(objHeadProp);
                            }
                            if (objHeadProp.propertyId == "DocumentTitle")
                            {
                                dtRow["Title"] = IdmObjectType.getPropertyValue(objHeadProp);
                            }
                        }
                    }
                }
                dtblResults.Rows.Add(dtRow);
                btnGetContent.Enabled = true;
            }
            dgrdContainees.DataSource = dtblResults;
            dgrdContainees.Show();
            g_dtblResults = dtblResults;
        }
        private void btnCreateSubclass_Click(object sender, System.EventArgs e)
        {
            String strParentClassName;
            String strParentClassId;
            int    iRow;

            CEWSI.PropertyType    prop;
            CEWSI.ObjectReference objRef;

            // First find the selected parent class, and extract the name and ID for it
            iRow = dgrdResults.CurrentRowIndex;
            if (iRow < 0)
            {
                MessageBox.Show("Please select a class first");
                return;
            }
            prop = g_Classes[iRow].Property[4];
            if (prop == null)
            {
                MessageBox.Show("Cannot find the This property");
                return;
            }
            if (prop.GetType() == typeof(CEWSI.SingletonObject))
            {
                CEWSI.SingletonObject objSO = (CEWSI.SingletonObject)prop;
                objRef = (CEWSI.ObjectReference)((CEWSI.SingletonObject)prop).Value;
                try
                {
                    objRef             = (CEWSI.ObjectReference)objSO.Value;
                    strParentClassName = objRef.classId;
                    strParentClassId   = objRef.objectId;
                }
                catch (System.Exception)
                {
                    MessageBox.Show("Cannot extract the class and Id of the selected item");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Expected to find an object valued property");
                return;
            }

            // Create a Create verb, populate it
            CEWSI.CreateAction createVerb = new CEWSI.CreateAction();
            createVerb.classId = strParentClassName;

            CEWSI.ChangeRequestType objChange = new CEWSI.ChangeRequestType();
            objChange.Action = new CEWSI.ActionType[1];
            objChange.TargetSpecification             = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId     = strParentClassName;
            objChange.TargetSpecification.objectId    = strParentClassId;
            objChange.TargetSpecification.objectStore = MainForm.Library;
            objChange.id = "1";

            // Build a list of properties to set in the new property template
            // The following meta-properties will be set:
            //   SymbolicName		String
            //   DisplayNames		ListOfObject
            CEWSI.ModifiablePropertyType[] objInputProps = new CEWSI.ModifiablePropertyType[2];

            // Symbolic name
            CEWSI.SingletonString objSymName = new CEWSI.SingletonString();
            objSymName.Value      = txtSymbolicName.Text;
            objSymName.propertyId = "SymbolicName";
            objInputProps[0]      = objSymName;

            // Set up the DisplayNames property
            //  DisplayNames is a dependent object that has the following properties:
            //    LocaleName		String
            //    LocalizedText		String
            CEWSI.ListOfObject objNameList = new CEWSI.ListOfObject();
            objNameList.propertyId = "DisplayNames";
            CEWSI.DependentObjectType[] theNames = new CEWSI.DependentObjectType[1];
            CEWSI.DependentObjectType   dispName = new CEWSI.DependentObjectType();
            theNames[0]       = dispName;
            objNameList.Value = theNames;

            dispName.dependentAction          = CEWSI.DependentObjectTypeDependentAction.Insert;
            dispName.dependentActionSpecified = true;
            dispName.classId = "LocalizedString";

            CEWSI.PropertyType[]  nameProps = new CEWSI.PropertyType[2];
            CEWSI.SingletonString objLocale = new CEWSI.SingletonString();
            objLocale.propertyId = "LocaleName";
            objLocale.Value      = "en-us";
            nameProps[0]         = objLocale;

            CEWSI.SingletonString objText = new CEWSI.SingletonString();
            objText.propertyId = "LocalizedText";
            objText.Value      = txtSymbolicName.Text;
            nameProps[1]       = objText;
            dispName.Property  = nameProps;

            objInputProps[1]           = objNameList;
            objChange.ActionProperties = objInputProps;
            objChange.Action[0]        = (CEWSI.ActionType)createVerb;

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

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = true;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while creating a new class: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }


            // Created a class!  Sanity check the results
            string strObjectId = "";
            bool   bFound      = false;

            if (objResponseArray == null || objResponseArray.Length < 1)
            {
                MessageBox.Show("The change request was executed, but a valid object was not returned");
                return;
            }
            CEWSI.ChangeResponseType objResponse = objResponseArray[0];
            foreach (CEWSI.PropertyType objProp in objResponse.Property)
            {
                if (objProp.propertyId.CompareTo("Id") == 0)
                {
                    strObjectId = IdmObjectType.getPropertyValue(objProp);
                    bFound      = true;
                    break;
                }
            }
            if (!bFound)
            {
                MessageBox.Show("The class was created, but the results do not contain an ID!");
                return;
            }
            MessageBox.Show("Successfully created a new class!  ID = [" + strObjectId + "]");
            return;
        }
        private void btnCreate_Click(object sender, System.EventArgs e)
        {
            // We first need to create a Create verb, populate it
            CEWSI.CreateAction createVerb = new CEWSI.CreateAction();

            CEWSI.ChangeRequestType objChange = new CEWSI.ChangeRequestType();
            objChange.Action = new CEWSI.ActionType[1];
            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = MainForm.Library;
            objChange.id = "1";

            // Build a list of properties to set in the new property template
            // The following meta-properties will be set:
            //   SymbolicName		String
            //   IsNameProperty		Boolean
            //   Cardinality		Integer
            //   IsPersistent		Boolean
            //   DisplayNames		ListOfObject
            CEWSI.ModifiablePropertyType[] objInputProps = new CEWSI.ModifiablePropertyType[5];

            // Symbolic name
            CEWSI.SingletonString objSymName = new CEWSI.SingletonString();
            objSymName.Value      = txtSymName.Text;
            objSymName.propertyId = "SymbolicName";
            objInputProps[0]      = objSymName;

            // Hardcode the IsNameProperty for now
            CEWSI.SingletonBoolean objIsName = new CEWSI.SingletonBoolean();
            objIsName.Value          = false;
            objIsName.ValueSpecified = true;
            objIsName.propertyId     = "IsNameProperty";
            objInputProps[1]         = objIsName;

            // Hardcode the Cardinality for now
            CEWSI.SingletonInteger32 objCardinality = new CEWSI.SingletonInteger32();
            objCardinality.Value          = 0;
            objCardinality.ValueSpecified = true;
            objCardinality.propertyId     = "Cardinality";
            objInputProps[2] = objCardinality;

            // Hardcode the IsPersistent property for now
            CEWSI.SingletonBoolean objIsPersistent = new CEWSI.SingletonBoolean();
            objIsPersistent.Value          = true;
            objIsPersistent.ValueSpecified = true;
            objIsPersistent.propertyId     = "IsPersistent";
            objInputProps[3] = objIsPersistent;

            // Set up the DisplayNames property
            //  DisplayNames is a dependent object that has the following properties:
            //    LocaleName		String
            //    LocalizedText		String
            CEWSI.ListOfObject objNameList = new CEWSI.ListOfObject();
            objNameList.propertyId = "DisplayNames";
            CEWSI.DependentObjectType[] theNames = new CEWSI.DependentObjectType[1];
            CEWSI.DependentObjectType   dispName = new CEWSI.DependentObjectType();
            theNames[0]       = dispName;
            objNameList.Value = theNames;

            dispName.dependentAction          = CEWSI.DependentObjectTypeDependentAction.Insert;
            dispName.dependentActionSpecified = true;
            dispName.classId = "LocalizedString";

            CEWSI.PropertyType[]  nameProps = new CEWSI.PropertyType[2];
            CEWSI.SingletonString objLocale = new CEWSI.SingletonString();
            objLocale.propertyId = "LocaleName";
            objLocale.Value      = "en-us";
            nameProps[0]         = objLocale;

            CEWSI.SingletonString objText = new CEWSI.SingletonString();
            objText.propertyId = "LocalizedText";
            objText.Value      = txtSymName.Text;
            nameProps[1]       = objText;
            dispName.Property  = nameProps;

            objInputProps[4] = objNameList;

            // Set the class of the new template according to the data type
            switch (cmbDataType.Text)
            {
            case "String":
                createVerb.classId = "PropertyTemplateString";
                break;

            case "Boolean":
                createVerb.classId = "PropertyTemplateBoolean";
                break;

            case "Float":
                createVerb.classId = "PropertyTemplateFloat64";
                break;

            case "Integer":
                createVerb.classId = "PropertyTemplateInteger32";
                break;

            case "ID":
                createVerb.classId = "PropertyTemplateId";
                break;

            case "Object":
                createVerb.classId = "PropertyTemplateObject";
                break;

            case "Binary":
                createVerb.classId = "PropertyTemplateBinary";
                break;

            case "DateTime":
                createVerb.classId = "PropertyTemplateDateTime";
                break;

            default:
                MessageBox.Show("Invalid property type selected!");
                return;
            }
            objChange.ActionProperties = objInputProps;
            objChange.Action[0]        = (CEWSI.ActionType)createVerb;

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

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = true;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while creating a property template: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }


            // Created a template!  Sanity check the results
            string strObjectId = "";
            bool   bFound      = false;

            if (objResponseArray == null || objResponseArray.Length < 1)
            {
                MessageBox.Show("The change request was executed, but a valid object was not returned");
                return;
            }
            CEWSI.ChangeResponseType objResponse = objResponseArray[0];
            foreach (CEWSI.PropertyType objProp in objResponse.Property)
            {
                if (objProp.propertyId.CompareTo("Id") == 0)
                {
                    strObjectId = IdmObjectType.getPropertyValue(objProp);
                    bFound      = true;
                    break;
                }
            }
            if (!bFound)
            {
                MessageBox.Show("The property template was created, but the results do not contain an ID!");
                return;
            }
            MessageBox.Show("Successfully created a property template!  ID = [" + strObjectId + "]");
            return;
        }
        private void btnQuery_Click(object sender, System.EventArgs e)
        {
            CEWSI.ObjectSetType objResponse = null;

            // Perform the requested query
            try
            {
                // Set up a connection to the web service.
                // Fill in the security headers...
                CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(MainForm.User,
                                                                                   MainForm.Domain, MainForm.Password, MainForm.URL);

                // Create a search object
                // Set up the scope for the query
                // Set up the SQL for the search
                CEWSI.RepositorySearch objSearch      = new CEWSI.RepositorySearch();
                CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
                objSearchScope.objectStore = MainForm.Library;
                objSearch.SearchScope      = objSearchScope;
                objSearch.SearchSQL        = "SELECT ";
                if (txtSelect.Text == "")
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + "*";
                }
                else
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + txtSelect.Text;
                }
                objSearch.SearchSQL = objSearch.SearchSQL + " FROM " + txtFrom.Text;
                if (txtWhere.Text != "")
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " WHERE " + txtWhere.Text;
                }
                if (txtMaxRows.Text != "")
                {
                    Int32 iRows = System.Int32.Parse(txtMaxRows.Text);
                    objSearch.maxElements          = iRows;
                    objSearch.maxElementsSpecified = true;
                }

                // Execute the search
                objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while querying: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }

            // Sanity check the results data
            long lColumnCount = 0;
            long lRowCount    = 0;
            long i;

            if (objResponse == null || objResponse.Object == null)
            {
                MessageBox.Show("The query completed successfully but the results were null!");
                return;
            }
            if (objResponse.Object.Length < 1)
            {
                MessageBox.Show("No results were found for this query - exiting.");
                return;
            }
            lColumnCount = objResponse.Object[0].Property.Length;
            if (lColumnCount < 1)
            {
                MessageBox.Show("The query succeeded, but the results contain no properties - exiting");
                return;
            }

            /*
             * if( lColumnCount > 12 )
             * {
             *      MessageBox.Show("The result set has more than 12 columns.  Only the first 12 columns will be displayed");
             *      lColumnCount = 12;
             * }
             */

            // Query was successful; display a list of result rows
            // First create a data table that has one column for each property in the
            //  returned data
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;
            CEWSI.PropertyType     prop;

            CEWSI.ObjectValue[] objObjects = objResponse.Object;
            lRowCount = objObjects.Length;
            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");
            for (i = 0; i < lColumnCount; i++)
            {
                dtCol              = new System.Data.DataColumn(objObjects[0].Property[i].propertyId);
                dtCol.DataType     = System.Type.GetType("System.String");
                dtCol.DefaultValue = "";
                dtblResults.Columns.Add(dtCol);
            }

            // Populate the rows
            for (i = 0; i < lRowCount; i++)
            {
                dtRow = dtblResults.NewRow();
                for (long iCol = 0; iCol < lColumnCount; iCol++)
                {
                    prop = objObjects[i].Property[iCol];
                    dtRow[prop.propertyId] = IdmObjectType.getPropertyValue(prop);
                }
                dtblResults.Rows.Add(dtRow);
            }
            dgrdResults.DataSource = dtblResults;
            dgrdResults.Show();
            return;
        }
        private void btnQuery_Click(object sender, System.EventArgs e)
        {
            CEWSI.ObjectSetType objResponse = null;

            // Perform the requested query
            try
            {
                // Set up a connection to the web service.
                // Fill in the security headers...
                CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(MainForm.User,
                                                                                   MainForm.Domain, MainForm.Password, MainForm.URL);

                // Create a search object
                // Set up the scope for the query
                // Set up the SQL for the search
                CEWSI.RepositorySearch objSearch      = new CEWSI.RepositorySearch();
                CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
                objSearchScope.objectStore = MainForm.Library;
                objSearch.SearchScope      = objSearchScope;
                objSearch.SearchSQL        = "SELECT SymbolicName, Id, IsHidden, IsSystemOwned, This FROM ClassDefinition ";
                objSearch.SearchSQL        = objSearch.SearchSQL + " WHERE AllowsSubclasses=TRUE";

                if (txtName.Text != "")
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " AND SymbolicName LIKE '" + txtName.Text + "%'";
                }
                if (!chkIncludeSystem.Checked)
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " AND IsSystemOwned=FALSE";
                }
                if (!chkIncludeHidden.Checked)
                {
                    objSearch.SearchSQL = objSearch.SearchSQL + " AND IsHidden=FALSE";
                }

                // Execute the search
                objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while querying: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }

            // Sanity check the results data
            long lColumnCount = 0;
            long lRowCount    = 0;
            long i;

            if (objResponse == null || objResponse.Object == null)
            {
                MessageBox.Show("The query completed successfully but the results were null!");
                return;
            }
            if (objResponse.Object.Length < 1)
            {
                MessageBox.Show("No results were found for this query.");
                return;
            }
            lColumnCount = objResponse.Object[0].Property.Length;
            if (lColumnCount < 5)
            {
                MessageBox.Show("The query succeeded, but the results are missing requested data");
                return;
            }

            // Query was successful; display a list of result rows
            // First create a data table that has one column for each property
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;
            CEWSI.PropertyType     prop;

            g_Classes = objResponse.Object;
            lRowCount = g_Classes.Length;
            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");

            // Name
            dtCol              = new System.Data.DataColumn("Name");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // Class
            dtCol              = new System.Data.DataColumn("Class");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // IsSystem
            dtCol              = new System.Data.DataColumn("IsSystem");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // IsHidden
            dtCol              = new System.Data.DataColumn("IsHidden");
            dtCol.DataType     = System.Type.GetType("System.String");
            dtCol.DefaultValue = "";
            dtblResults.Columns.Add(dtCol);

            // Populate the rows
            CEWSI.ObjectReference objRef;
            for (i = 0; i < lRowCount; i++)
            {
                dtRow             = dtblResults.NewRow();
                prop              = g_Classes[i].Property[0];
                dtRow["Name"]     = IdmObjectType.getPropertyValue(prop);
                prop              = g_Classes[i].Property[4];
                objRef            = (CEWSI.ObjectReference)((CEWSI.SingletonObject)prop).Value;
                dtRow["Class"]    = objRef.classId;
                prop              = g_Classes[i].Property[3];
                dtRow["IsSystem"] = IdmObjectType.getPropertyValue(prop);
                prop              = g_Classes[i].Property[2];
                dtRow["IsHidden"] = IdmObjectType.getPropertyValue(prop);

                dtblResults.Rows.Add(dtRow);
            }
            dgrdResults.PreferredColumnWidth = 140;
            dgrdResults.DataSource           = dtblResults;
            dgrdResults.Show();
            btnCreateSubclass.Enabled = true;
            return;
        }
Exemple #10
0
        public static EcmQueryResult QueryDocument(DocumentModel doc, string query, int maxRow = 100)
        {
            EcmQueryResult ret = new EcmQueryResult();

            CEWSI.ObjectSetType objResponse = null;

            // Perform the requested query
            try
            {
                if (doc.IsUseCert == 1)
                {
                    Addcert(doc.EcmUrl);
                }
                // Set up a connection to the web service.
                // Fill in the security headers...
                CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

                // Create a search object
                // Set up the scope for the query
                // Set up the SQL for the search
                CEWSI.RepositorySearch objSearch      = new CEWSI.RepositorySearch();
                CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
                objSearchScope.objectStore     = doc.ObjectStore;
                objSearch.SearchScope          = objSearchScope;
                objSearch.SearchSQL            = query;
                objSearch.maxElements          = maxRow;
                objSearch.maxElementsSpecified = true;

                // Execute the search
                objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
            }
            catch (System.Net.WebException ex)
            {
                ret.ErrorCode = -1;
                ret.ErrorMsg  = "An exception occurred while querying: [" + ex.Message + "]\n" + ex.ToString();
                return(ret);
            }
            catch (Exception allEx)
            {
                ret.ErrorCode = -1;
                ret.ErrorMsg  = "An exception occurred: [" + allEx.Message + "]\n" + allEx.ToString();
                return(ret);
            }

            // Sanity check the results data
            long lColumnCount = 0;
            long lRowCount    = 0;
            long i;

            if (objResponse == null || objResponse.Object == null)
            {
                ret.ErrorCode = 1;
                ret.ErrorMsg  = "The query completed successfully but the results were null";
                return(ret);
            }
            if (objResponse.Object.Length < 1)
            {
                ret.ErrorCode = 1;
                ret.ErrorMsg  = "No results were found for this query - exiting";
                return(ret);
            }
            lColumnCount = objResponse.Object[0].Property.Length;
            if (lColumnCount < 1)
            {
                ret.ErrorCode = 1;
                ret.ErrorMsg  = "The query succeeded, but the results contain no properties - exiting";
                return(ret);
            }

            /*
             *          if( lColumnCount > 12 )
             *          {
             *                  MessageBox.Show("The result set has more than 12 columns.  Only the first 12 columns will be displayed");
             *                  lColumnCount = 12;
             *          }
             */

            // Query was successful; display a list of result rows
            // First create a data table that has one column for each property in the
            //  returned data
            System.Data.DataColumn dtCol;
            System.Data.DataRow    dtRow;
            CEWSI.PropertyType     prop;

            CEWSI.ObjectValue[] objObjects = objResponse.Object;
            lRowCount = objObjects.Length;
            System.Data.DataTable dtblResults = new System.Data.DataTable("Results");
            for (i = 0; i < lColumnCount; i++)
            {
                dtCol              = new System.Data.DataColumn(objObjects[0].Property[i].propertyId);
                dtCol.DataType     = System.Type.GetType("System.String");
                dtCol.DefaultValue = "";
                dtblResults.Columns.Add(dtCol);
            }

            // Populate the rows
            for (i = 0; i < lRowCount; i++)
            {
                dtRow = dtblResults.NewRow();
                for (long iCol = 0; iCol < lColumnCount; iCol++)
                {
                    prop = objObjects[i].Property[iCol];
                    dtRow[prop.propertyId] = IdmObjectType.getPropertyValue(prop);
                }
                dtblResults.Rows.Add(dtRow);
            }
            ret.Result    = dtblResults;
            ret.ErrorCode = 1;
            ret.ErrorMsg  = "Success";
            return(ret);
        }
Exemple #11
0
        //     public static EcmQueryResult QueryFolder(DocumentModel doc, string query, int maxRow = 100)
        //     {
        //         EcmQueryResult ret = new EcmQueryResult();
        //         CEWSI.ObjectSetType objResponse = null;

        //         // Perform the requested query
        //         try
        //         {
        //             if (doc.IsUseCert == 1)
        //                 Addcert(doc.EcmUrl);
        //             // Set up a connection to the web service.
        //             // Fill in the security headers...
        //             CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

        //             // Create a search object
        //             // Set up the scope for the query
        //             // Set up the SQL for the search
        //             CEWSI.RepositorySearch objSearch = new CEWSI.RepositorySearch();
        //             CEWSI.ObjectStoreScope objSearchScope = new CEWSI.ObjectStoreScope();
        //             objSearchScope.objectStore = doc.ObjectStore;
        //             objSearch.SearchScope = objSearchScope;
        //             objSearch.SearchSQL = query;
        //             objSearch.maxElements = maxRow;
        //             objSearch.maxElementsSpecified = true;

        //             // Execute the search
        //             objResponse = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objSearch);
        //         }
        //         catch (System.Net.WebException ex)
        //         {
        //             ret.ErrorCode = -1;
        //             ret.ErrorMsg = "An exception occurred while querying: [" + ex.Message + "]\n" + ex.ToString();
        //             return ret;
        //         }
        //         catch (Exception allEx)
        //         {
        //             ret.ErrorCode = -1;
        //             ret.ErrorMsg = "An exception occurred: [" + allEx.Message + "]\n" + allEx.ToString();
        //             return ret;
        //         }

        //         // Sanity check the results data
        //         long lColumnCount = 0;
        //         long lRowCount = 0;
        //         long i;
        //         if (objResponse == null || objResponse.Object == null)
        //         {
        //             ret.ErrorCode = 1;
        //             ret.ErrorMsg = "The query completed successfully but the results were null";
        //             return ret;
        //         }
        //         if (objResponse.Object.Length < 1)
        //         {
        //             ret.ErrorCode = 1;
        //             ret.ErrorMsg = "No results were found for this query - exiting";
        //             return ret;
        //         }
        //         lColumnCount = objResponse.Object[0].Property.Length;
        //         if (lColumnCount < 1)
        //         {
        //             ret.ErrorCode = 1;
        //             ret.ErrorMsg = "The query succeeded, but the results contain no properties - exiting";
        //             return ret;
        //         }
        //         /*
        //if( lColumnCount > 12 )
        //{
        //	MessageBox.Show("The result set has more than 12 columns.  Only the first 12 columns will be displayed");
        //	lColumnCount = 12;
        //}
        //*/

        //         // Query was successful; display a list of result rows
        //         // First create a data table that has one column for each property in the
        //         //  returned data
        //         System.Data.DataColumn dtCol;
        //         System.Data.DataRow dtRow;
        //         CEWSI.PropertyType prop;

        //         CEWSI.ObjectValue[] objObjects = objResponse.Object;
        //         lRowCount = objObjects.Length;
        //         System.Data.DataTable dtblResults = new System.Data.DataTable("Results");
        //         for (i = 0; i < lColumnCount; i++)
        //         {
        //             dtCol = new System.Data.DataColumn(objObjects[0].Property[i].propertyId);
        //             dtCol.DataType = System.Type.GetType("System.String");
        //             dtCol.DefaultValue = "";
        //             dtblResults.Columns.Add(dtCol);
        //         }

        //         // Populate the rows
        //         for (i = 0; i < lRowCount; i++)
        //         {
        //             dtRow = dtblResults.NewRow();
        //             for (long iCol = 0; iCol < lColumnCount; iCol++)
        //             {
        //                 prop = objObjects[i].Property[iCol];
        //                 dtRow[prop.propertyId] = IdmObjectType.getPropertyValue(prop);
        //             }
        //             dtblResults.Rows.Add(dtRow);
        //         }
        //         ret.Result = dtblResults;
        //         ret.ErrorCode = 1;
        //         ret.ErrorMsg = "Success";
        //         return ret;
        //     }


        //     public static EcmQueryResult QueryFolder1(DocumentModel doc, string folderPath)
        //     {
        //         byte[] ret = null;

        //         Addcert(doc.EcmUrl);
        //         CEWSI.FNCEWS40PortTypeClient wseService = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

        //         // Add default locale info to SOAP header
        //         Localization objDefaultLocale = new Localization();
        //         objDefaultLocale.Locale = "en-US";

        //         // Set a reference to the document to retrieve
        //         ObjectSpecification objDocumentSpec = new ObjectSpecification();
        //         objDocumentSpec.classId = "Document";
        //         objDocumentSpec.path = folderPath;
        //         //objDocumentSpec.objectId = docId;
        //         objDocumentSpec.objectStore = doc.ObjectStore;

        //         // Create property filter object and set its attributes
        //         PropertyFilterType objPropFilter = new PropertyFilterType();
        //         objPropFilter.maxRecursion = 4;
        //         objPropFilter.maxRecursionSpecified = true;

        //         // Create filter element array to hold IncludeProperties specifications
        //         objPropFilter.IncludeProperties = new FilterElementType[4];

        //         // Create filter element for ContentElements property
        //         objPropFilter.IncludeProperties[1] = new FilterElementType();
        //         objPropFilter.IncludeProperties[1].Value = "ContentElements";

        //         // Create an object request for a GetObjects operation
        //         ObjectRequestType[] objObjectRequestTypeArray = new ObjectRequestType[1];
        //         objObjectRequestTypeArray[0] = new ObjectRequestType();
        //         objObjectRequestTypeArray[0].SourceSpecification = objDocumentSpec;
        //         objObjectRequestTypeArray[0].PropertyFilter = objPropFilter;

        //         // Call GetObjects operation to get document object and its properties
        //         ObjectResponseType[] objObjectResponseTypeArray;
        //         try
        //         {
        //             objObjectResponseTypeArray = wseService.GetObjects(objDefaultLocale, objObjectRequestTypeArray);
        //         }
        //         catch (System.Net.WebException ex)
        //         {
        //             Console.WriteLine("An exception occurred while requesting a document: [" + ex.Message + "]");
        //             return null;
        //         }

        //         // Get document object from the GetObjects response
        //         ObjectValue objDocument = null;
        //         if (objObjectResponseTypeArray[0] is SingleObjectResponse)
        //         {
        //             objDocument = ((SingleObjectResponse)objObjectResponseTypeArray[0]).Object;
        //         }

        //         // Get the ContentElements property of the Document object
        //         ListOfObject prpContentElements = null;
        //         foreach (PropertyType prpProperty in objDocument.Property)
        //         {
        //             if (prpProperty.propertyId == "ContentElements")
        //             {
        //                 prpContentElements = (ListOfObject)prpProperty;
        //                 break;
        //             }
        //         }

        //         // Get number of content elements
        //         int intElementCount = (prpContentElements.Value == null) ? 0 : prpContentElements.Value.Length;
        //         if (intElementCount == 0)
        //         {
        //             Console.WriteLine("The selected document has no content elements");
        //             Console.WriteLine("Press Enter to end");
        //             //Console.ReadLine();
        //             return null;
        //         }

        //         // Get the content from each content element of the document
        //         for (int intElem = 0; intElem < intElementCount; intElem++)
        //         {
        //             // Get a ContentTransfer object from the ContentElements property collection
        //             DependentObjectType objContentTransfer = prpContentElements.Value[intElem];

        //             // Construct element specification for GetContent request
        //             ElementSpecificationType objElemSpecType = new ElementSpecificationType();
        //             objElemSpecType.itemIndex = intElem;
        //             objElemSpecType.itemIndexSpecified = true;
        //             objElemSpecType.elementSequenceNumber = 0;
        //             objElemSpecType.elementSequenceNumberSpecified = false;

        //             // Construct the GetContent request
        //             ContentRequestType objContentReqType = new ContentRequestType();
        //             objContentReqType.cacheAllowed = true;
        //             objContentReqType.cacheAllowedSpecified = true;
        //             objContentReqType.id = "1";
        //             //objContentReqType.maxBytes = 100 * 1024;
        //             //objContentReqType.maxBytesSpecified = true;
        //             objContentReqType.maxBytesSpecified = false;
        //             objContentReqType.startOffset = 0;
        //             objContentReqType.startOffsetSpecified = true;
        //             objContentReqType.continueFrom = null;
        //             objContentReqType.ElementSpecification = objElemSpecType;
        //             objContentReqType.SourceSpecification = objDocumentSpec;
        //             ContentRequestType[] objContentReqTypeArray = new ContentRequestType[1];
        //             objContentReqTypeArray[0] = objContentReqType;
        //             GetContentRequest objGetContentReq = new GetContentRequest();
        //             objGetContentReq.ContentRequest = objContentReqTypeArray;
        //             objGetContentReq.validateOnly = false;
        //             objGetContentReq.validateOnlySpecified = true;

        //             // Call the GetContent operation
        //             ContentResponseType[] objContentRespTypeArray = null;
        //             try
        //             {
        //                 objContentRespTypeArray = wseService.GetContent(objDefaultLocale, objGetContentReq);
        //             }
        //             catch (System.Net.WebException ex)
        //             {
        //                 Console.WriteLine("An exception occurred while fetching content from a content element: [" + ex.Message + "]");
        //                 Console.WriteLine("Press Enter to end");
        //                 //Console.ReadLine();
        //                 return null;
        //             }
        //             catch (Exception allEx)
        //             {
        //                 Console.WriteLine("An exception occurred: [" + allEx.Message + "]");
        //                 Console.WriteLine("Press Enter to end");
        //                 //Console.ReadLine();
        //                 return null;
        //             }

        //             // Process GetContent response
        //             ContentResponseType objContentRespType = objContentRespTypeArray[0];
        //             if (objContentRespType is ContentErrorResponse)
        //             {
        //                 ContentErrorResponse objContentErrorResp = (ContentErrorResponse)objContentRespType;
        //                 ErrorStackType objErrorStackType = objContentErrorResp.ErrorStack;
        //                 ErrorRecordType objErrorRecordType = objErrorStackType.ErrorRecord[0];
        //                 Console.WriteLine("Error [" + objErrorRecordType.Description + "] occurred. " + " Err source is [" + objErrorRecordType.Source + "]");
        //                 //Console.WriteLine("Press Enter to end");
        //                 //Console.ReadLine();
        //                 return null;
        //             }
        //             else if (objContentRespType is ContentElementResponse)
        //             {
        //                 ContentElementResponse objContentElemResp = (ContentElementResponse)objContentRespType;
        //                 InlineContent objInlineContent = (InlineContent)objContentElemResp.Content;
        //                 ret = objInlineContent.Binary;
        //                 // Write content to file
        //                 //Stream outputStream = File.OpenWrite(strDocContentPath);
        //                 //outputStream.Write(objInlineContent.Binary, 0, objInlineContent.Binary.Length);
        //                 //outputStream.Close();
        //                 Console.WriteLine("Document content has been written");
        //                 //Console.WriteLine("Press Enter to end");
        //                 //Console.ReadLine();
        //             }
        //             else
        //             {
        //                 Console.WriteLine("Unknown data type returned in content response: [" + objContentRespType.GetType().ToString() + "]");
        //                 //Console.WriteLine("Press Enter to end");
        //                 //Console.ReadLine();
        //                 return null;
        //             }

        //         }
        //         return new EcmQueryResult();
        //     }

        public static byte[] GetContenFile(DocumentModel doc, string docId)
        {
            byte[] ret = null;

            Addcert(doc.EcmUrl);
            CEWSI.FNCEWS40PortTypeClient wseService = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

            // Add default locale info to SOAP header
            Localization objDefaultLocale = new Localization();

            objDefaultLocale.Locale = "en-US";

            // Set a reference to the document to retrieve
            ObjectSpecification objDocumentSpec = new ObjectSpecification();

            objDocumentSpec.classId     = "Document";
            objDocumentSpec.objectId    = docId;
            objDocumentSpec.objectStore = doc.ObjectStore;

            // Create property filter object and set its attributes
            PropertyFilterType objPropFilter = new PropertyFilterType();

            objPropFilter.maxRecursion          = 4;
            objPropFilter.maxRecursionSpecified = true;

            // Create filter element array to hold IncludeProperties specifications
            objPropFilter.IncludeProperties = new FilterElementType[4];

            // Create filter element for ContentElements property
            objPropFilter.IncludeProperties[1]       = new FilterElementType();
            objPropFilter.IncludeProperties[1].Value = "ContentElements";

            // Create an object request for a GetObjects operation
            ObjectRequestType[] objObjectRequestTypeArray = new ObjectRequestType[1];
            objObjectRequestTypeArray[0] = new ObjectRequestType();
            objObjectRequestTypeArray[0].SourceSpecification = objDocumentSpec;
            objObjectRequestTypeArray[0].PropertyFilter      = objPropFilter;

            // Call GetObjects operation to get document object and its properties
            ObjectResponseType[] objObjectResponseTypeArray;
            try
            {
                objObjectResponseTypeArray = wseService.GetObjects(objDefaultLocale, objObjectRequestTypeArray);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine("An exception occurred while requesting a document: [" + ex.Message + "]");
                return(null);
            }

            // Get document object from the GetObjects response
            ObjectValue objDocument = null;

            if (objObjectResponseTypeArray[0] is SingleObjectResponse)
            {
                objDocument = ((SingleObjectResponse)objObjectResponseTypeArray[0]).Object;
            }

            // Get the ContentElements property of the Document object
            ListOfObject prpContentElements = null;

            foreach (PropertyType prpProperty in objDocument.Property)
            {
                if (prpProperty.propertyId == "ContentElements")
                {
                    prpContentElements = (ListOfObject)prpProperty;
                    break;
                }
            }

            // Get number of content elements
            int intElementCount = (prpContentElements.Value == null) ? 0 : prpContentElements.Value.Length;

            if (intElementCount == 0)
            {
                Console.WriteLine("The selected document has no content elements");
                Console.WriteLine("Press Enter to end");
                //Console.ReadLine();
                return(null);
            }

            // Get the content from each content element of the document
            for (int intElem = 0; intElem < intElementCount; intElem++)
            {
                // Get a ContentTransfer object from the ContentElements property collection
                DependentObjectType objContentTransfer = prpContentElements.Value[intElem];

                // Construct element specification for GetContent request
                ElementSpecificationType objElemSpecType = new ElementSpecificationType();
                objElemSpecType.itemIndex                      = intElem;
                objElemSpecType.itemIndexSpecified             = true;
                objElemSpecType.elementSequenceNumber          = 0;
                objElemSpecType.elementSequenceNumberSpecified = false;

                // Construct the GetContent request
                ContentRequestType objContentReqType = new ContentRequestType();
                objContentReqType.cacheAllowed          = true;
                objContentReqType.cacheAllowedSpecified = true;
                objContentReqType.id = "1";
                //objContentReqType.maxBytes = 100 * 1024;
                //objContentReqType.maxBytesSpecified = true;
                objContentReqType.maxBytesSpecified    = false;
                objContentReqType.startOffset          = 0;
                objContentReqType.startOffsetSpecified = true;
                objContentReqType.continueFrom         = null;
                objContentReqType.ElementSpecification = objElemSpecType;
                objContentReqType.SourceSpecification  = objDocumentSpec;
                ContentRequestType[] objContentReqTypeArray = new ContentRequestType[1];
                objContentReqTypeArray[0] = objContentReqType;
                GetContentRequest objGetContentReq = new GetContentRequest();
                objGetContentReq.ContentRequest        = objContentReqTypeArray;
                objGetContentReq.validateOnly          = false;
                objGetContentReq.validateOnlySpecified = true;

                // Call the GetContent operation
                ContentResponseType[] objContentRespTypeArray = null;
                try
                {
                    objContentRespTypeArray = wseService.GetContent(objDefaultLocale, objGetContentReq);
                }
                catch (System.Net.WebException ex)
                {
                    Console.WriteLine("An exception occurred while fetching content from a content element: [" + ex.Message + "]");
                    Console.WriteLine("Press Enter to end");
                    //Console.ReadLine();
                    return(null);
                }
                catch (Exception allEx)
                {
                    Console.WriteLine("An exception occurred: [" + allEx.Message + "]");
                    Console.WriteLine("Press Enter to end");
                    //Console.ReadLine();
                    return(null);
                }

                // Process GetContent response
                ContentResponseType objContentRespType = objContentRespTypeArray[0];
                if (objContentRespType is ContentErrorResponse)
                {
                    ContentErrorResponse objContentErrorResp = (ContentErrorResponse)objContentRespType;
                    ErrorStackType       objErrorStackType   = objContentErrorResp.ErrorStack;
                    ErrorRecordType      objErrorRecordType  = objErrorStackType.ErrorRecord[0];
                    Console.WriteLine("Error [" + objErrorRecordType.Description + "] occurred. " + " Err source is [" + objErrorRecordType.Source + "]");
                    //Console.WriteLine("Press Enter to end");
                    //Console.ReadLine();
                    return(null);
                }
                else if (objContentRespType is ContentElementResponse)
                {
                    ContentElementResponse objContentElemResp = (ContentElementResponse)objContentRespType;
                    InlineContent          objInlineContent   = (InlineContent)objContentElemResp.Content;
                    ret = objInlineContent.Binary;
                    // Write content to file
                    //Stream outputStream = File.OpenWrite(strDocContentPath);
                    //outputStream.Write(objInlineContent.Binary, 0, objInlineContent.Binary.Length);
                    //outputStream.Close();
                    Console.WriteLine("Document content has been written");
                    //Console.WriteLine("Press Enter to end");
                    //Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Unknown data type returned in content response: [" + objContentRespType.GetType().ToString() + "]");
                    //Console.WriteLine("Press Enter to end");
                    //Console.ReadLine();
                    return(null);
                }
            }
            return(ret);
        }
Exemple #12
0
        public static EcmResult CreateFolder(DocumentModel doc, string folderName, string parentFolder, string folderClass)
        {
            EcmResult ret = new EcmResult();

            if (doc.IsUseCert == 1)
            {
                Addcert(doc.EcmUrl);
            }

            CEWSI.ChangeRequestType objChange  = new CEWSI.ChangeRequestType();
            CEWSI.CreateAction      createVerb = new CEWSI.CreateAction();
            createVerb.classId                     = folderClass;
            objChange.Action                       = new CEWSI.ActionType[1];
            objChange.Action[0]                    = (CEWSI.ActionType)createVerb;
            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = doc.ObjectStore;
            objChange.id = "1";

            CEWSI.ModifiablePropertyType[] objInputProps = new CEWSI.ModifiablePropertyType[2];
            objChange.ActionProperties = objInputProps;

            // Build a list of properties to set in the new folder (just the folder name and parent for now)
            //    -Folder name property
            CEWSI.SingletonString objString = new CEWSI.SingletonString();
            objString.Value      = folderName;
            objString.propertyId = "FolderName";
            objInputProps[0]     = objString;

            //    -Parent property
            CEWSI.ObjectSpecification objSpec   = new CEWSI.ObjectSpecification();
            CEWSI.SingletonObject     objObject = new CEWSI.SingletonObject();
            objSpec.classId      = "Folder";
            objSpec.path         = parentFolder;
            objSpec.objectStore  = doc.ObjectStore;
            objObject.propertyId = "Parent";
            objObject.Value      = (CEWSI.ObjectEntryType)objSpec;
            objInputProps[1]     = objObject;

            // Fill in the security headers...
            CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = true;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                ret.ErrorCode = -1;
                ret.ErrorMsg  = ex.ToString();
                return(ret);
            }
            catch (Exception allEx)
            {
                ret.ErrorCode = -1;
                ret.ErrorMsg  = allEx.ToString();
                return(ret);
            }

            // Created a folder!  Sanity check the results
            string strObjectId = "";
            bool   bFound      = false;

            if (objResponseArray == null || objResponseArray.Length < 1)
            {
                ret.ErrorCode = 0;
                ret.ErrorMsg  = "The change request was executed, but a valid object was not returned";
                return(ret);
            }
            CEWSI.ChangeResponseType objResponse = objResponseArray[0];
            foreach (CEWSI.PropertyType objProp in objResponse.Property)
            {
                if (objProp.propertyId.CompareTo("Id") == 0)
                {
                    strObjectId = IdmObjectType.getPropertyValue(objProp);
                    bFound      = true;
                    break;
                }
            }
            if (!bFound)
            {
                ret.ErrorCode = 0;
                ret.ErrorMsg  = "The folder was created, but the results do not contain a folder ID";
                return(ret);
            }
            ret.ErrorCode = 1;
            ret.ErrorMsg  = "Successfully created a folder";
            ret.DocId     = strObjectId;
            return(ret);
        }
Exemple #13
0
        public static bool Deletedoc(DocumentModel doc, string docId, int taskId, string userName)
        {
            EcmResult ret = new EcmResult();

            //string mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            //bool isCheckin = false;
            if (doc.IsUseCert == 1)
            {
                Addcert(doc.EcmUrl);
            }

            CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

            CEWSI.ObjectStoreScope objObjectStoreScope = new CEWSI.ObjectStoreScope();
            objObjectStoreScope.objectStore = doc.ObjectStore;

            // Create RepositorySearch
            CEWSI.RepositorySearch objRepositorySearch = new CEWSI.RepositorySearch();
            objRepositorySearch.repositorySearchMode          = CEWSI.RepositorySearchModeType.Rows;
            objRepositorySearch.repositorySearchModeSpecified = true;
            objRepositorySearch.SearchScope = objObjectStoreScope;

            objRepositorySearch.SearchSQL = "SELECT [DocumentTitle],[Id],[DateLastModified],bpmCodeLarge FROM " + doc.DocumentClass + " WHERE Id='" + docId + "' AND bpmCode='" + taskId.ToString() + "' AND NguoiTao='" + userName + "' ORDER BY [DateLastModified]";


            // Invoke the ExecuteSearch operation
            CEWSI.ObjectSetType objObjectSet = objBinding.ExecuteSearch(WSIUtil.GetLocalization(), objRepositorySearch);

            // Display the Document Titles
            int hitCount = (objObjectSet.Object == null) ? 0 : objObjectSet.Object.Length;

            if (hitCount == 0)
            {
                return(true);
            }

            CEWSI.DeleteAction docUnfile = new CEWSI.DeleteAction();

            // Assign the action to the ChangeRequestType element
            CEWSI.ChangeRequestType[] objChangeRequestTypeArray = new CEWSI.ChangeRequestType[1];
            CEWSI.ChangeRequestType   objChangeRequestType      = new CEWSI.ChangeRequestType();
            objChangeRequestTypeArray[0] = objChangeRequestType;

            // Create ChangeResponseType element array
            CEWSI.ChangeResponseType[] objChangeResponseTypeArray;

            // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it
            CEWSI.ExecuteChangesRequest objExecuteChangesRequest = new CEWSI.ExecuteChangesRequest();
            objExecuteChangesRequest.ChangeRequest    = objChangeRequestTypeArray;
            objExecuteChangesRequest.refresh          = true; // return a refreshed object
            objExecuteChangesRequest.refreshSpecified = true;

            objChangeRequestType.Action    = new CEWSI.ActionType[1];
            objChangeRequestType.Action[0] = (CEWSI.ActionType)docUnfile;

            // Specify the target object (Reservation object) for the actions
            objChangeRequestType.TargetSpecification             = new CEWSI.ObjectReference();
            objChangeRequestType.TargetSpecification.classId     = doc.DocumentClass;
            objChangeRequestType.TargetSpecification.objectId    = docId;
            objChangeRequestType.TargetSpecification.objectStore = doc.ObjectStore;
            objChangeRequestType.id = "1";

            // Assign ChangeRequestType element
            objChangeRequestTypeArray[0] = objChangeRequestType;

            // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it
            objExecuteChangesRequest.ChangeRequest    = objChangeRequestTypeArray;
            objExecuteChangesRequest.refresh          = true; // return a refreshed object
            objExecuteChangesRequest.refreshSpecified = true;

            try
            {
                // Call ExecuteChanges operation to implement the Delete object
                objChangeResponseTypeArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objExecuteChangesRequest);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine("An exception occurred while checking out a document: [" + ex.Message + "]");
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An exception : [" + ex.Message + "]");
                return(false);
            }

            // The new document object will be returned, unless there is an error
            if (objChangeResponseTypeArray == null || objChangeResponseTypeArray.Length < 1)
            {
                Console.WriteLine("A valid object was not returned from the ExecuteChanges operation");
                return(false);
            }

            return(true);
        }
Exemple #14
0
        private static EcmResult FileDoc(EcmInfo info)
        {
            EcmResult ret = new EcmResult();

            // Create a Create verb, populate it to create a new RCR
            CEWSI.CreateAction createVerb = new CEWSI.CreateAction();
            createVerb.autoUniqueContainmentName          = true;
            createVerb.autoUniqueContainmentNameSpecified = true;
            createVerb.classId = "DynamicReferentialContainmentRelationship";

            CEWSI.ChangeRequestType objChange = new CEWSI.ChangeRequestType();
            objChange.Action                       = new CEWSI.ActionType[1];
            objChange.Action[0]                    = (CEWSI.ActionType)createVerb;
            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = info.ObjectStore;
            objChange.id = "1";

            // Create the properties of the new RCR
            CEWSI.ObjectReference objHeadRef = new CEWSI.ObjectReference();
            objHeadRef.classId     = info.DocClass;
            objHeadRef.objectId    = info.DocId;
            objHeadRef.objectStore = info.ObjectStore;
            CEWSI.SingletonObject propHead = new CEWSI.SingletonObject();
            propHead.propertyId = "Head";
            propHead.Value      = (CEWSI.ObjectEntryType)objHeadRef;

            CEWSI.ObjectReference objTailRef = new CEWSI.ObjectReference();
            objTailRef.classId     = "Folder";
            objTailRef.objectId    = info.FolderPath;
            objTailRef.objectStore = info.ObjectStore;
            CEWSI.SingletonObject propTail = new CEWSI.SingletonObject();
            propTail.propertyId = "Tail";
            propTail.Value      = (CEWSI.ObjectEntryType)objTailRef;

            CEWSI.SingletonString propContainmentName = new CEWSI.SingletonString();
            propContainmentName.propertyId = "ContainmentName";
            propContainmentName.Value      = info.DocTitle;

            CEWSI.ModifiablePropertyType[] objProps = new CEWSI.ModifiablePropertyType[3];
            objProps[0] = propTail;
            objProps[1] = propHead;
            objProps[2] = propContainmentName;
            objChange.ActionProperties = objProps;

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

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = false;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                //Console.WriteLine("An exception occurred while filing a document: [" + ex.Message + "]");
                //Console.ReadLine();
                ret.ErrorCode = -1;
                ret.ErrorMsg  = ex.ToString();
                return(ret);
            }
            //catch (Exception allEx)
            //{
            //    //Console.WriteLine("An exception occurred: [" + allEx.Message + "]");
            //    //Console.ReadLine();
            //    return false;
            //}

            //Console.WriteLine("Successfully filed a document!");
            //Console.ReadLine();
            ret.ErrorCode = 1;
            ret.ErrorMsg  = "Successfully filed a document!";
            return(ret);
        }
Exemple #15
0
        public static EcmResult CreateDoc(DocumentModel doc)
        {
            EcmResult ret = new EcmResult();

            //string mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            bool isCheckin = false;

            if (doc.IsUseCert == 1)
            {
                Addcert(doc.EcmUrl);
            }

            CEWSI.FNCEWS40PortTypeClient objBinding = WSIUtil.ConfigureBinding(doc.EcmUser, doc.EcmDomain, doc.EcmPassword, doc.EcmUrl);

            CEWSI.CreateAction createVerb = new CEWSI.CreateAction();
            createVerb.classId = doc.DocumentClass;

            CEWSI.CheckinAction checkinVerb = new CEWSI.CheckinAction();
            if (isCheckin)
            {
                checkinVerb.checkinMinorVersion          = true;
                checkinVerb.checkinMinorVersionSpecified = true;
            }

            CEWSI.ChangeRequestType objChange = new CEWSI.ChangeRequestType();
            objChange.Action    = new CEWSI.ActionType[2];
            objChange.Action[0] = (CEWSI.ActionType)createVerb;
            objChange.Action[1] = (CEWSI.ActionType)checkinVerb;

            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = doc.ObjectStore;
            objChange.id = "1";

            int propLength = doc.Properties != null && doc.Properties.Count > 0 ? doc.Properties.Count + 1 : 1;

            CEWSI.ModifiablePropertyType[] objInputProps = new CEWSI.ModifiablePropertyType[propLength];

            #region properties have the must
            CEWSI.PropertyType[] ctProps = new CEWSI.PropertyType[3];

            CEWSI.SingletonString typeProp = new CEWSI.SingletonString();
            typeProp.propertyId = "ContentType";
            typeProp.Value      = doc.MimeTypeSource;
            ctProps[0]          = typeProp;

            CEWSI.DependentObjectType ct = new CEWSI.DependentObjectType();
            ct.dependentAction          = CEWSI.DependentObjectTypeDependentAction.Insert;
            ct.dependentActionSpecified = true;

            CEWSI.SingletonString nameProp = new CEWSI.SingletonString();
            nameProp.propertyId = "RetrievalName";
            nameProp.Value      = doc.FileName;
            ctProps[1]          = nameProp;

            CEWSI.ContentData contData = new CEWSI.ContentData();
            contData.propertyId = "Content";

            CEWSI.InlineContent ic = new CEWSI.InlineContent();
            ic.Binary = doc.BinaryFile;

            contData.Value = ic;
            ctProps[2]     = contData;

            ct.classId = "ContentTransfer";

            //	create content object list
            ct.Property = ctProps;
            CEWSI.DependentObjectType[] contentObjects = new CEWSI.DependentObjectType[1];
            contentObjects[0] = ct;

            //	Create the content element list and set it into the document's properties
            CEWSI.ListOfObject objContentList = new CEWSI.ListOfObject();
            objContentList.propertyId = "ContentElements";
            objContentList.Value      = contentObjects;
            objInputProps[0]          = objContentList;
            #endregion

            if (doc.Properties != null && doc.Properties.Count > 0)
            {
                int i = 1;
                foreach (var p in doc.Properties)
                {
                    CEWSI.SingletonString objProp = new CEWSI.SingletonString();
                    objProp.propertyId = p.Key;
                    objProp.Value      = p.Value;
                    objInputProps[i++] = objProp;
                }
            }

            objChange.ActionProperties = objInputProps;

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = true;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                //Console.WriteLine("An exception occurred while creating a document: [" + ex.Message + "]");
                ret.ErrorCode = -1;
                ret.ErrorMsg  = ex.ToString();
                return(ret);
            }
            catch (Exception allEx)
            {
                //Console.WriteLine("An exception occurred: [" + allEx.Message + "]");
                ret.ErrorCode = -1;
                ret.ErrorMsg  = allEx.ToString();
                return(ret);
            }

            // Created a document!  Sanity check the results
            string strObjectId = "";
            bool   bFound      = false;

            if (objResponseArray == null || objResponseArray.Length < 1)
            {
                ret.ErrorCode = 0;
                ret.ErrorMsg  = "The change request was executed, but a valid object was not returned";
                return(ret);
            }
            CEWSI.ChangeResponseType objResponse = objResponseArray[0];
            foreach (CEWSI.PropertyType objProp in objResponse.Property)
            {
                if (objProp.propertyId.CompareTo("Id") == 0)
                {
                    strObjectId = IdmObjectType.getPropertyValue(objProp);
                    bFound      = true;
                    break;
                }
            }
            if (!bFound)
            {
                ret.ErrorCode = 0;
                ret.ErrorMsg  = "The document was created, but the results do not contain a document ID";
                return(ret);
            }

            //Console.WriteLine("Successfully created a document!  ID = [" + strObjectId + "].  Now filing.");

            ret = FileDoc(new EcmInfo
            {
                DocId       = strObjectId,
                DocClass    = doc.DocumentClass,
                DocTitle    = doc.FileName,
                FolderPath  = doc.DestinationFolder,
                ObjectStore = doc.ObjectStore,
                User        = doc.EcmUser,
                Domain      = doc.EcmDomain,
                Password    = doc.EcmPassword,
                Url         = doc.EcmUrl
            });
            ret.DocId    = strObjectId;
            ret.FileName = doc.FileName;
            ret.Mime     = doc.MimeTypeSource;

            return(ret);
        }
        private void btnCreate_Click(object sender, System.EventArgs e)
        {
            // Create the ChangeRequest
            CEWSI.ChangeRequestType objChange  = new CEWSI.ChangeRequestType();
            CEWSI.CreateAction      createVerb = new CEWSI.CreateAction();
            createVerb.classId                     = txtFolderClass.Text;
            objChange.Action                       = new CEWSI.ActionType[1];
            objChange.Action[0]                    = (CEWSI.ActionType)createVerb;
            objChange.TargetSpecification          = new CEWSI.ObjectReference();
            objChange.TargetSpecification.classId  = "ObjectStore";
            objChange.TargetSpecification.objectId = MainForm.Library;
            objChange.id = "1";

            CEWSI.ModifiablePropertyType[] objInputProps = new CEWSI.ModifiablePropertyType[2];
            objChange.ActionProperties = objInputProps;

            // Build a list of properties to set in the new folder (just the folder name and parent for now)
            //    -Folder name property
            CEWSI.SingletonString objString = new CEWSI.SingletonString();
            objString.Value      = txtName.Text;
            objString.propertyId = "FolderName";
            objInputProps[0]     = objString;

            //    -Parent property
            CEWSI.ObjectSpecification objSpec   = new CEWSI.ObjectSpecification();
            CEWSI.SingletonObject     objObject = new CEWSI.SingletonObject();
            objSpec.classId      = "Folder";
            objSpec.path         = txtParent.Text;
            objSpec.objectStore  = MainForm.Library;
            objObject.propertyId = "Parent";
            objObject.Value      = (CEWSI.ObjectEntryType)objSpec;
            objInputProps[1]     = objObject;

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

            // Send off the request
            CEWSI.ChangeResponseType[]  objResponseArray = null;
            CEWSI.ExecuteChangesRequest objRequest       = new CEWSI.ExecuteChangesRequest();
            objRequest.refresh          = true;
            objRequest.refreshSpecified = true;
            objRequest.ChangeRequest    = new CEWSI.ChangeRequestType[1];
            objRequest.ChangeRequest[0] = objChange;
            try
            {
                objResponseArray = objBinding.ExecuteChanges(WSIUtil.GetLocalization(), objRequest);
            }
            catch (System.Net.WebException ex)
            {
                MessageBox.Show("An exception occurred while creating a folder: [" + ex.Message + "]");
                return;
            }
            catch (Exception allEx)
            {
                MessageBox.Show("An exception occurred: [" + allEx.Message + "]");
                return;
            }

            // Created a folder!  Sanity check the results
            string strObjectId = "";
            bool   bFound      = false;

            if (objResponseArray == null || objResponseArray.Length < 1)
            {
                MessageBox.Show("The change request was executed, but a valid object was not returned");
                return;
            }
            CEWSI.ChangeResponseType objResponse = objResponseArray[0];
            foreach (CEWSI.PropertyType objProp in objResponse.Property)
            {
                if (objProp.propertyId.CompareTo("Id") == 0)
                {
                    strObjectId = IdmObjectType.getPropertyValue(objProp);
                    bFound      = true;
                    break;
                }
            }
            if (!bFound)
            {
                MessageBox.Show("The folder was created, but the results do not contain a folder ID!");
                return;
            }
            MessageBox.Show("Successfully created a folder!  ID = [" + strObjectId + "]");
            return;
        }