예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }