コード例 #1
0
        // Return if document is valid to be opened with ms word
        public static bool isDocumentValidToOpenWithMSWord(MSOpenKMCore.ws.document doc)
        {
            bool valid = false;

            String[] WORD_EXTENSIONS = new String[15] {
                "doc", "dot", "xml", "html",
                "htm", "mht", "mhtml", "rtf",
                "txt", "scd", "olk", "pab",
                "wri", "wpd", "wpd"
            };

            String docExtension = getDocumentExtension(doc);

            foreach (String extension in WORD_EXTENSIONS)
            {
                if (docExtension.Equals(extension))
                {
                    valid = true;
                    break;
                }
            }

            // Special case, document could start with doc*
            if (!valid)
            {
                if (docExtension.StartsWith("doc"))
                {
                    valid = true;
                }
            }

            return(valid);
        }
コード例 #2
0
        // Return if document is valid to be opened with ms excel
        public static bool isDocumentValidToOpenWithMSExcel(MSOpenKMCore.ws.document doc)
        {
            bool valid = false;

            String[] EXCEL_EXTENSIONS = new String[16] {
                "xls", "xlt", "htm", "html", "mht", "mhtml", "xml",
                "xla", "xlm", "xlc", "xlw", "odc", "uxdc", "prn",
                "txt", "csv"
            };

            String docExtension = getDocumentExtension(doc);

            foreach (String extension in EXCEL_EXTENSIONS)
            {
                if (docExtension.Equals(extension))
                {
                    valid = true;
                    break;
                }
            }

            // Special case, document could start with xl*
            if (!valid)
            {
                if (docExtension.StartsWith("xl"))
                {
                    valid = true;
                }
            }

            return(valid);
        }
コード例 #3
0
 // get the document Extension
 public static String getDocumentExtension(MSOpenKMCore.ws.document doc)
 {
     try
     {
         return(doc.path.Substring(doc.path.LastIndexOf(".") + 1));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #4
0
 // Evaluates enabled buttons by permisions
 private void evaluateEnabledButtonByPermissions(MSOpenKMCore.ws.folder fld, MSOpenKMCore.ws.document doc)
 {
     if (Util.hasWritePermission(fld, doc) && !doc.locked && !doc.checkedOut)
     {
         edit.Enabled = true;
     }
     else
     {
         edit.Enabled = false;
     }
 }
コード例 #5
0
 // Return if a user document has write permissions
 public static bool hasWritePermission(MSOpenKMCore.ws.folder fatherFld, MSOpenKMCore.ws.document doc)
 {
     try
     {
         // Must have permission to write in folders and in document
         return(((fatherFld.permissions & OKMPermissions.WRITE) == OKMPermissions.WRITE) &
                ((doc.permissions & OKMPermissions.WRITE) == OKMPermissions.WRITE));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #6
0
        // mouse click
        private void nodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                // Init values
                rootNode   = null;
                actualNode = null;

                // OpenKM authentication
                token = authService.login(configXML.getUser(), configXML.getPassword());

                MSOpenKMCore.ws.folder folderNode = (MSOpenKMCore.ws.folder)e.Node.Tag;
                actualNode = e.Node;

                // Gets folder childs
                getChilds();
                actualNode.ExpandAll();

                // Gets document childs
                getDocumentChilds();

                // Evaluates buttons enabled
                if (dataGridView.RowCount > 0 && dataGridView.SelectedRows.Count > 0)
                {
                    MSOpenKMCore.ws.folder   fld = (MSOpenKMCore.ws.folder)actualNode.Tag;
                    MSOpenKMCore.ws.document doc = (MSOpenKMCore.ws.document)dataGridView.Rows[dataGridView.SelectedRows[0].Index].Tag;
                    evaluateEnabledButtonByPermissions(fld, doc);
                }
                else
                {
                    enableDefaultButtons();
                }

                // Logout OpenKM
                authService.logout(token);
                token = "";
            } catch (Exception ex)
            {
                if (!token.Equals(""))
                {
                    String errorMsg = "ExplorerForm - (nodeMouseClick)\n" + ex.Message + "\n\n" + ex.StackTrace;
                    MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
            }
        }
コード例 #7
0
        // Return if document is valid to be opened with ms excel
        public static bool isDocumentValidToOpenWithMSPowerPoint(MSOpenKMCore.ws.document doc)
        {
            bool valid = false;

            String[] POWERPOINT_EXTENSIONS = new String[9] {
                "htm", "html", "mht", "mhtml", "txt", "rtf", "doc", "wpd", "wps"
            };

            String docExtension = getDocumentExtension(doc);

            foreach (String extension in POWERPOINT_EXTENSIONS)
            {
                if (docExtension.Equals(extension))
                {
                    valid = true;
                    break;
                }
            }

            // Special case, document could start with pps* ppt* pot*
            if (!valid)
            {
                if (docExtension.StartsWith("pps"))
                {
                    valid = true;
                }
            }
            if (!valid)
            {
                if (docExtension.StartsWith("ppt"))
                {
                    valid = true;
                }
            }
            if (!valid)
            {
                if (docExtension.StartsWith("pot"))
                {
                    valid = true;
                }
            }

            return(valid);
        }
コード例 #8
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;
            }
        }
コード例 #9
0
 // mouse click
 private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         // Evaluates buttons enabled
         if (dataGridView.RowCount > 0 && dataGridView.SelectedRows.Count > 0)
         {
             MSOpenKMCore.ws.folder   fld = (MSOpenKMCore.ws.folder)actualNode.Tag;
             MSOpenKMCore.ws.document doc = (MSOpenKMCore.ws.document)dataGridView.Rows[dataGridView.SelectedRows[0].Index].Tag;
             evaluateEnabledButtonByPermissions(fld, doc);
         }
         else
         {
             enableDefaultButtons();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #10
0
        // returns file name that not exist in disk
        public String getFilenameWithoutCollision(MSOpenKMCore.ws.document doc)
        {
            try
            {
                String fileName     = getConfigPath() + @"\" + Util.getDocumentName(doc); // Default path name
                String docNamePart1 = fileName.Substring(0, fileName.LastIndexOf("."));
                String docNamePart2 = fileName.Substring(fileName.LastIndexOf("."));

                int count = 1;
                while (File.Exists(fileName))
                {
                    fileName = docNamePart1 + "_" + count + docNamePart2;
                    count++;
                }

                return(fileName);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #11
0
        // Return if document is valid to be opened with ms visio
        public static bool isDocumentValidToOpenWithMSVisio(MSOpenKMCore.ws.document doc)
        {
            bool valid = false;

            String[] VISIO_EXTENSIONS = new String[9] {
                "vsd", "vxd", "vss", "vsx", "vst", "vtx", "vsw", "svg", "svgz"
            };

            String docExtension = getDocumentExtension(doc);

            foreach (String extension in VISIO_EXTENSIONS)
            {
                if (docExtension.Equals(extension))
                {
                    valid = true;
                    break;
                }
            }

            // Special case, document could start with vs* v?x
            if (!valid)
            {
                if (docExtension.StartsWith("vs"))
                {
                    valid = true;
                }
            }
            if (!valid)
            {
                if (docExtension.StartsWith("v") && docExtension.Length == 3 && docExtension.EndsWith("x"))
                {
                    valid = true;
                }
            }

            return(valid);
        }
コード例 #12
0
        public void ImportMail(Outlook.Explorers explorers, ConfigXML configXML)
        {
            ComponentResourceManager resources = new ComponentResourceManager(typeof(OpenKMAddIn));

            int mailCount = 0;
            int mailAttach = 0;

            for (int y = 1; y <= explorers.Count; y++)
            {
                Outlook.Explorer openWindow = explorers.Item(y);
                String token = "";
                OKMAuth authService = new OKMAuth(configXML.getHost());
                OKMFolder folderService = new OKMFolder(configXML.getHost());
                OKMRepository repositoryService = new OKMRepository(configXML.getHost());
                OKMMail mailService = new OKMMail(configXML.getHost());
                OKMDocument documentService = new OKMDocument(configXML.getHost());

                try
                {
                    if (configXML.getUser().Equals("") || configXML.getPassword().Equals("") ||
                        configXML.getHost().Equals(""))
                    {
                        throw new Exception(resources.GetString("error_configuration_empty"));
                    }

                    token = authService.login(configXML.getUser(), configXML.getPassword());

                    for (int i = 1; i<=openWindow.Selection.Count; i++) {
                        Object selObject = openWindow.Selection.Item(i);
                        if (selObject is Outlook.MailItem)
                        {
                            mailCount++;
                            Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
                            DateTime receivedTime = mailItem.ReceivedTime;
                            String user = configXML.getUser();
                            String basePath = "/okm:mail/" + user + "/";
                            String year = "" + receivedTime.Year;
                            String month = "" + receivedTime.Month;
                            String day = "" + receivedTime.Day;

                            // Only creating folders when it's needed
                            if (repositoryService.hasNode(token, basePath + year))
                            {
                                if (repositoryService.hasNode(token, basePath + year + "/" + month))
                                {
                                    if (!repositoryService.hasNode(token, basePath + year + "/" + month + "/" + day))
                                    {
                                        folder dayFolder = new folder();
                                        dayFolder.path = basePath + year + "/" + month + "/" + day;
                                        folderService.create(token, dayFolder);
                                    }
                                }
                                else
                                {
                                    folder monthFolder = new folder();
                                    folder dayFolder = new folder();
                                    monthFolder.path = basePath + year + "/" + month;
                                    dayFolder.path = basePath + year + "/" + month + "/" + day;
                                    folderService.create(token, monthFolder);
                                    folderService.create(token, dayFolder);
                                }
                            }
                            else
                            {
                                folder yearFolder = new folder();
                                folder monthFolder = new folder();
                                folder dayFolder = new folder();
                                yearFolder.path = basePath + year;
                                monthFolder.path = basePath + year + "/" + month;
                                dayFolder.path = basePath + year + "/" + month + "/" + day;
                                folderService.create(token, yearFolder);
                                folderService.create(token, monthFolder);
                                folderService.create(token, dayFolder);
                            }

                            // Adding mail values
                            mail newMail = new mail();
                            newMail.path = basePath + year + "/" + month + "/" + day + "/" + mailItem.Subject;
                            newMail.subject = mailItem.Subject;

                            newMail.from = mailItem.GetType().InvokeMember("SenderEmailAddress", System.Reflection.BindingFlags.GetProperty, null, mailItem, null).ToString();
                            //newMail.from = mailItem.SenderEmailAddress; // SenderEmailAddress was introduced in outlook 2002
                            newMail.sentDate = mailItem.SentOn;
                            newMail.sentDateSpecified = true;
                            newMail.receivedDate = mailItem.ReceivedTime;
                            newMail.receivedDateSpecified = true;

                            // Setting mail context and type

                            BodyFormat format = (BodyFormat) mailItem.GetType().InvokeMember("BodyFormat", System.Reflection.BindingFlags.GetProperty, null, mailItem, null);
                            if (format.Equals(BodyFormat.olFormatPlain))
                            {
                                newMail.mimeType = "text/plain";
                                newMail.content = mailItem.Body;
                            }
                            else
                            {
                                newMail.mimeType = "text/html";
                                newMail.content = mailItem.HTMLBody;
                            }

                            // Initialize count recipient address variables
                            int count = 0;
                            int countTo = 0;
                            int countCC = 0;
                            int countBCC = 0;
                            int actualCountTo = 0;
                            int actualCountCC = 0;
                            int actualCountBCC = 0;

                            // Count each mail addresss type to / cc / bcc
                            for (int x=1; x<=mailItem.Recipients.Count; x++) {
                                Outlook.Recipient recipient = mailItem.Recipients.Item(x);
                                switch (recipient.Type)
                                {
                                    case 1:
                                        countTo++;
                                        break;

                                    case 2:
                                        countCC++;
                                        break;

                                    case 3:
                                        countBCC++;
                                        break;

                                    default:
                                        countTo++;
                                        break;
                                }
                                count++;
                            }

                            // Initialize variables
                            String[] mailTo = new String[(countTo > 0) ? countTo : 1];
                            String[] mailCC = new String[(countCC > 0) ? countCC : 1];
                            String[] mailBCC = new String[(countBCC > 0) ? countBCC : 1];

                            // All string[] must have at least one value, it¡s mandatory in webservices
                            if (countTo == 0)
                            {
                                mailTo[0] = "";
                            }
                            if (countCC == 0)
                            {
                                mailCC[0] = "";
                            }
                            if (countBCC == 0)
                            {
                                mailBCC[0] = "";
                            }

                            // Depending mail type each mail is assignede to it own type String[]
                            for (int x=1; x<=mailItem.Recipients.Count; x++) {
                                Outlook.Recipient recipient = mailItem.Recipients.Item(x);
                                switch (recipient.Type)
                                {
                                    case 1:
                                        mailTo[actualCountTo] = recipient.Address;
                                        actualCountTo++;
                                        break;

                                    case 2:
                                        mailCC[actualCountCC] = recipient.Address;
                                        actualCountCC++;
                                        break;

                                    case 3:
                                        mailBCC[actualCountBCC] = recipient.Address;
                                        actualCountBCC++;
                                        break;

                                    default:
                                        mailTo[actualCountTo] = recipient.Address;
                                        actualCountTo++;
                                        break;
                                }

                            }

                            // Assign mail recipients by type
                            newMail.bcc = mailBCC;
                            newMail.cc = mailCC;
                            newMail.to = mailTo;

                            // Creating mail
                            newMail = mailService.create(token, newMail);

                            // Setting attachments
                            if (mailItem.Attachments.Count > 0)
                            {
                                for (int x=1; x<=mailItem.Attachments.Count; x++) {
                                    Outlook.Attachment attachment = mailItem.Attachments.Item(x);

                                    mailAttach++;
                                    document doc = new document();
                                    doc.path = newMail.path + "/" + attachment.FileName;

                                    // save as tempfile for reading
                                    String filename = Environment.GetEnvironmentVariable("TEMP") + "\\" + DateTime.Now.ToString("yymmddHHMMss-") + attachment.FileName;
                                    // save the attachment
                                    attachment.SaveAsFile(filename);

                                    // Uploading document
                                    documentService.create(token, doc, ReadFile(filename));

                                    // Delete a file by using File class static method...
                                    if (File.Exists(filename))
                                    {
                                        // Use a try block to catch IOExceptions, to
                                        // handle the case of the file already being
                                        // opened by another process.
                                        try
                                        {
                                            File.Delete(filename);
                                        }
                                        catch (System.IO.IOException ex)
                                        {
                                            MessageBox.Show(String.Format(resources.GetString("error_deleting_tmp_file"), filename, ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }

                                    // Releasing com object
                                    Marshal.ReleaseComObject(attachment);
                                }
                            }

                            // Releasing com object
                            Marshal.ReleaseComObject(mailItem);
                        }

                        // Releasing com object
                        Marshal.ReleaseComObject(selObject);
                    }

                    if (!token.Equals(""))
                    {
                        authService.logout(token);  // Always we logout
                        token = "";                 // Reseting token value
                    }

                    if (mailCount > 0)
                    {
                        MessageBox.Show(String.Format(resources.GetString("email_successful_imported"), mailCount, mailAttach));
                    }
                    else
                    {
                        MessageBox.Show(resources.GetString("error_mail_not_selected"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    if (!token.Equals(""))
                    {
                        authService.logout(token); // Always we logout
                    }
                }

            }
        }
コード例 #13
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();
            }
        }
コード例 #14
0
        // Starting up drawing folder tree
        public void startUp()
        {
            try
            {
                // Refreshing config file
                configXML.ReadConfig();

                // Init services
                initServices();

                // Default buttons enabled
                enableDefaultButtons();

                // OpenKM authentication
                token = authService.login(configXML.getUser(), configXML.getPassword());

                // Suppress repainting the TreeView until all the objects have been created.
                tree.BeginUpdate();

                // Clear the TreeView each time the method is called.
                tree.Nodes.Clear();

                // Draws the root folder
                getRootFolder();

                // Draws the root folder childs
                getChilds();

                // Draws document childs
                getDocumentChilds();

                // Expand all nodes
                tree.ExpandAll();

                // Begin repainting the TreeView.
                tree.EndUpdate();

                // Evaluates buttons enabled
                if (dataGridView.RowCount > 0 && dataGridView.SelectedRows.Count > 0)
                {
                    MSOpenKMCore.ws.folder   fld = (MSOpenKMCore.ws.folder)actualNode.Tag;
                    MSOpenKMCore.ws.document doc = (MSOpenKMCore.ws.document)dataGridView.Rows[dataGridView.SelectedRows[0].Index].Tag;
                    evaluateEnabledButtonByPermissions(fld, doc);
                }
                else
                {
                    enableDefaultButtons();
                }

                // Logout OpenKM
                authService.logout(token);
                token = "";
            }
            catch (Exception ex)
            {
                String errorMsg = "ExplorerForm - (startUp)\n" + ex.Message;
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                if (!token.Equals(""))
                {
                    // Logout OpenKM
                    authService.logout(token);
                    token = "";
                }
            }
        }