Exemple #1
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);
                    }
                }
            }
        }
Exemple #2
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;
        }