Exemplo n.º 1
0
        private void SetRequestType(ContentRequestType type)
        {
            switch (type)
            {
            case ContentRequestType.File:
                ContentRequester = new FileScrapper();
                break;

            case ContentRequestType.Website:
                ContentRequester = new WebsiteScrapper();
                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get the content from a target
 /// ex a file path
 /// or a website uri
 /// </summary>
 /// <param name="path"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public string GetContent(string path, ContentRequestType type)
 {
     SetRequestType(type);
     return(ContentRequester.GetContent(path));
 }
Exemplo n.º 3
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);
        }