Example #1
0
        // check out document
        public static MSOpenKMCore.bean.OKMDocument checkoutDocument(document doc, String type, String host, String username, String password)
        {
            String  token       = "";
            OKMAuth authService = null;

            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // Create a new document
                MSOpenKMCore.bean.OKMDocument oKMDocument = Util.copy(doc, type);

                // Creates new document
                FileStream fileStream = new FileStream(oKMDocument.getLocalFilename(), FileMode.CreateNew);

                // Checking out document
                documentService.checkout(token, doc.path);
                byte[] byteDoc = documentService.getContent(token, doc.path, false);

                // Write the data to the file, byte by byte.
                for (int i = 0; i < byteDoc.Length; i++)
                {
                    fileStream.WriteByte(byteDoc[i]);
                }

                fileStream.Close();

                // Logout OpenKM
                authService.logout(token);
                token = "";

                return(oKMDocument);
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (checkoutDocument)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
 // Add new document to document file
 public void add(OKMDocument oKMDocument)
 {
     try
     {
         documentList.Add(oKMDocument);
         CreateDocumentFile();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #3
0
        // copy document object to OKMDocument object
        public static MSOpenKMCore.bean.OKMDocument copy(document doc, String docType)
        {
            try
            {
                MSOpenKMCore.bean.OKMDocument oKMDocument = new MSOpenKMCore.bean.OKMDocument();
                FileUtil fileUtil = new FileUtil();

                oKMDocument.setUUID(doc.uuid);
                oKMDocument.setName(getDocumentName(doc));
                oKMDocument.setLocalFilename(fileUtil.getFilenameWithoutCollision(doc));
                oKMDocument.setPath(doc.path);
                oKMDocument.setType(docType);

                return(oKMDocument);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
0
        // copy document object to OKMDocument object
        public static MSOpenKMCore.bean.OKMDocument copy(document doc, String docType)
        {
            try
            {
                MSOpenKMCore.bean.OKMDocument oKMDocument = new MSOpenKMCore.bean.OKMDocument();
                FileUtil fileUtil = new FileUtil();

                oKMDocument.setUUID(doc.uuid);
                oKMDocument.setName(getDocumentName(doc));
                oKMDocument.setLocalFilename(fileUtil.getFilenameWithoutCollision(doc));
                oKMDocument.setPath(doc.path);
                oKMDocument.setType(docType);

                return oKMDocument;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #5
0
        // Checkin document
        public static void checkin(MSOpenKMCore.bean.OKMDocument oKMDocument, String host, String username, String password)
        {
            String token = "";

            MSOpenKMCore.ws.OKMAuth     authService     = null;
            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new MSOpenKMCore.ws.OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // Checkin document
                //documentService.setContent(token, oKMDocument.getPath(), FileUtil.readFile(oKMDocument.getLocalFilename()));
                //documentService.checkin(token, oKMDocument.getPath(), "");

                // Logout OpenKM
                authService.logout(token);
                token = "";
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (checkin)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
Example #6
0
        // cancel checkout document
        public static void cancelCheckout(MSOpenKMCore.bean.OKMDocument oKMDocument, String host, String username, String password)
        {
            String  token       = "";
            OKMAuth authService = null;

            MSOpenKMCore.ws.OKMDocument documentService = null;

            try
            {
                // Init services
                SSL.init(host);
                authService     = new MSOpenKMCore.ws.OKMAuth(host);
                documentService = new MSOpenKMCore.ws.OKMDocument(host);

                // OpenKM authentication
                token = authService.login(username, password);

                // Cancelling checkout
                documentService.cancelCheckout(token, oKMDocument.getPath());

                // Logout OpenKM
                authService.logout(token);
                token = "";
            }
            catch (Exception e)
            {
                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
                String errorMSG = "DocumentLogic (cancelCheckout)\n" + e.Message + "\n\n" + e.StackTrace;
                throw new OKMException(errorMSG);
            }
        }
Example #7
0
        // edit button
        private void edit_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView.RowCount > 0 && dataGridView.SelectedRows.Count > 0)
                {
                    bool editFile = true;
                    MSOpenKMCore.ws.document doc = (MSOpenKMCore.ws.document)dataGridView.Rows[dataGridView.SelectedRows[0].Index].Tag;

                    // We try to advice user in case selects some document extension that seems not be good to be opened with MS Word
                    if (formType.Equals(OKMDocumentType.TYPE_WORD))
                    {
                        if (!Util.isDocumentValidToOpenWithMSWord(doc))
                        {
                            String msg = String.Format(resources.GetString("word_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }
                    else if (formType.Equals(OKMDocumentType.TYPE_EXCEL))
                    {
                        if (!Util.isDocumentValidToOpenWithMSExcel(doc))
                        {
                            String msg = String.Format(resources.GetString("excel_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }
                    else if (formType.Equals(OKMDocumentType.TYPE_POWER_POINT))
                    {
                        if (!Util.isDocumentValidToOpenWithMSPowerPoint(doc))
                        {
                            String msg = String.Format(resources.GetString("powerpoint_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }
                    else if (formType.Equals(OKMDocumentType.TYPE_VISIO))
                    {
                        if (!Util.isDocumentValidToOpenWithMSVisio(doc))
                        {
                            String msg = String.Format(resources.GetString("visio_document_extension_warning"), Util.getDocumentName(doc));
                            editFile = (MessageBox.Show(msg, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK);
                        }
                    }

                    if (editFile)
                    {
                        MSOpenKMCore.bean.OKMDocument oKMDocument = DocumentLogic.checkoutDocument(doc, formType, configXML.getHost(), configXML.getUser(), configXML.getPassword());
                        if (oKMDocument != null)
                        {
                            documentXML.add(oKMDocument);
                            object missingValue = Type.Missing;
                            object readOnly     = false;
                            object fileName     = oKMDocument.getLocalFilename();

                            if (application is Word.Documents)
                            {
                                ((Word.Documents)application).Open(ref fileName,
                                                                   ref missingValue, ref readOnly, ref missingValue, ref missingValue, ref missingValue,
                                                                   ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue,
                                                                   ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
                            }
                            else if (application is Excel.Workbooks)
                            {
                                ((Excel.Workbooks)application).Open(oKMDocument.getLocalFilename(),
                                                                    missingValue, readOnly, missingValue, missingValue, missingValue,
                                                                    missingValue, missingValue, missingValue, missingValue, missingValue,
                                                                    missingValue, missingValue, missingValue, missingValue);
                            }
                            else if (application is PowerPoint.Presentations)
                            {
                                ((PowerPoint.Presentations)application).Open(oKMDocument.getLocalFilename(), Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,
                                                                             Office.MsoTriState.msoTrue);
                            }
                            else if (application is Visio.Documents)
                            {
                                ((Visio.Documents)application).Open(oKMDocument.getLocalFilename());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                String errorMsg = "ExplorerForm - (edit_Click)\n" + ex.Message + "\n\n" + ex.StackTrace;
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Hide();
            }
        }
        // Read document file
        private void ReadDocumentFile()
        {
            XmlTextReader reader = null;
            OKMDocument doc = null;
            documentList = null;

            try
            {
                reader = new XmlTextReader(fileUtil.getDocumentFilenamePath());
                doc = new OKMDocument();
                documentList = new List<OKMDocument>();

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (reader.Name.ToLower().Equals(XML_TAG_DOCUMENT))
                            {
                                doc = new OKMDocument();
                            }
                            else if (reader.Name.ToLower().Equals(XML_TAG_UUID))
                            {
                                if (reader.Read())
                                {
                                    doc.setUUID(reader.Value);
                                }
                            }
                            else if (reader.Name.ToLower().Equals(XML_TAG_PATH))
                            {
                                if (reader.Read())
                                {
                                    doc.setPath(reader.Value);
                                }
                            }
                            else if (reader.Name.ToLower().Equals(XML_TAG_LOCAL_FILENAME))
                            {
                                if (reader.Read())
                                {
                                    doc.setLocalFilename(reader.Value);
                                }
                            }
                            else if (reader.Name.ToLower().Equals(XML_TAG_NAME))
                            {
                                if (reader.Read())
                                {
                                    doc.setName(reader.Value);
                                }
                            }
                            else if (reader.Name.ToLower().Equals(XML_TAG_TYPE))
                            {
                                if (reader.Read())
                                {
                                    doc.setType(reader.Value);
                                    documentList.Add(doc);
                                }
                            }
                            break;

                        case XmlNodeType.Text:
                            break;

                        case XmlNodeType.EndElement:
                            break;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
        // remove document from document file
        public void remove(OKMDocument oKMDocument)
        {
            try
            {
                OKMDocument documentToRemove = null;

                foreach (OKMDocument oKMDocumentTemp in documentList)
                {
                    if (oKMDocumentTemp.getLocalFilename().Equals(oKMDocument.getLocalFilename()))
                    {
                        documentToRemove = oKMDocumentTemp;
                        break;
                    }
                }

                if (documentToRemove != null)
                {
                    documentList.Remove(documentToRemove);
                }

                CreateDocumentFile();
            }
            catch (Exception e)
            {
                throw e;
            }
        }