예제 #1
0
 public void AttachmentCustomItem_Click(Microsoft.Office.Core.CommandBarButton button, ref bool CancelDefault)
 {
     NuxeoAttachList attachList = new NuxeoAttachList();
     try
     {
         attachList.init(this.attachment);
         attachList.ShowDialog();
         attachList.Close();
     }
     catch (Exception e)
     {
         FormError bob = new FormError(e.ToString(), "Erreur lors de l'initialisation du plugin."
             + System.Environment.NewLine + "Veuillez redémarrez le programme, vérifiez vos paramètres de connection et réessayez ou contactez l'administrateur si le problème persiste.");
         bob.ShowDialog();
         System.Diagnostics.Trace.TraceError("Problème Initialisation NuxeoDocList :" + e);
         using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
         {
             file.WriteLine(e + "\n\t\n\t");
             file.Close();
         }
     }
 }
예제 #2
0
        private void buildTree(TreeNode treeNode)
        {
            try
            {
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                parameters[SessionParameter.BindingType] = BindingType.AtomPub;
                XmlNode rootNode = Config1.xmlRootNode();

                parameters[SessionParameter.AtomPubUrl] = rootNode.ChildNodes.Item(0).InnerText + "atom/cmis";
                parameters[SessionParameter.User] = rootNode.ChildNodes.Item(1).InnerText;
                parameters[SessionParameter.Password] = rootNode.ChildNodes.Item(2).InnerText;

                SessionFactory factory = SessionFactory.NewInstance();
                ISession session = factory.GetRepositories(parameters)[0].CreateSession();
                IItemEnumerable<IQueryResult> qr = session.Query("SELECT * from cmis:folder where cmis:parentId = '" + treeNode.Name + "'", false);

                foreach (IQueryResult hit in qr)
                {
                    //Recuperation du dossier
                    Object obj = session.GetObject(hit["cmis:objectId"].FirstValue.ToString());
                    Folder folder = (Folder)obj;
                    if (folder.AllowableActions.Actions.Contains("canCreateDocument"))
                    {
                        TreeNode tn = treeNode.Nodes.Add(hit["cmis:objectId"].FirstValue.ToString(), hit["cmis:name"].FirstValue.ToString());
                        AddVirtualNode(tn);
                    }
                }
            }
            catch (Exception e)
            {
                FormError bob = new FormError(e.ToString(), "Le plugin a rencontré un problème lors de la création de l'arborescence." + System.Environment.NewLine + "Veuillez redémarrez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Connection serveur fail :" + e);
            }
        }
예제 #3
0
        private void SaveXML()
        {
            CspParameters cspParams = new CspParameters();
            cspParams.KeyContainerName = "XML_ENC_RSA_KEY_" + Environment.UserName + Environment.MachineName;

            // Create a new RSA key and save it in the container. This key will encrypt
            // a symmetric key, which will then be encryped in the XML document.

            RSACryptoServiceProvider rsaKey = null;
            try
            {
                rsaKey = new RSACryptoServiceProvider(cspParams);
                //Test si dossier & fichier.xml exists
                testXML();

                //Chargement du fichier.xml
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.PreserveWhitespace = false;
                xmlDoc.Load(fichierXML);

                //Dechiffrage du fichier
                Cryptography.Decrypt(xmlDoc, rsaKey, "rsaKey");

                //Selection de la node Root
                XmlNodeList nodes = xmlDoc.ChildNodes;
                XmlNode rootNode;
                if (nodes.Item(0).Name == "Root")
                {
                    rootNode = nodes.Item(0);
                }
                else
                {
                    rootNode = nodes.Item(1);
                }

                String url = _textBoxServeur.Text.Trim();
                if (url.Substring(url.Length - 1, 1) != "/")
                    url = _textBoxServeur.Text + "/";

                rootNode.ChildNodes.Item(0).InnerText = url;
                rootNode.ChildNodes.Item(1).InnerText = _textBoxUser.Text;
                rootNode.ChildNodes.Item(2).InnerText = _textBoxPass.Text;

                //Rechiffre le fichier
                Cryptography.Encrypt(xmlDoc, "Root", "EncryptedElement1", rsaKey, "rsaKey");

                xmlDoc.Save(fichierXML);
            }
            catch (Exception e)
            {
                FormError bob = new FormError(e.ToString(), "Le plugin a rencontré une erreur lors du cryptage du fichier xml." + System.Environment.NewLine + "Veuillez réassyez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Sauvegarde ou cryptage problème :" + e);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }
            }
            finally
            {
                // Supprime la cle RSA
                rsaKey.Clear();
            }
        }
예제 #4
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            String url = "";
            //Test si le plugin peut etablir une connexion avec le serveur
            try
            {
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                parameters[SessionParameter.BindingType] = BindingType.AtomPub;

                url = _textBoxServeur.Text.Trim();
                if (url.Substring(url.Length - 1, 1) != "/")
                    url = _textBoxServeur.Text + "/";

                parameters[SessionParameter.AtomPubUrl] = url + "atom/cmis";
                parameters[SessionParameter.User] = _textBoxUser.Text;
                parameters[SessionParameter.Password] = _textBoxPass.Text;

                SessionFactory factory = SessionFactory.NewInstance();
                System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
                ISession session = factory.GetRepositories(parameters)[0].CreateSession();

                MessageBox.Show("Connection Réussi.", "Connection", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ex)
            {
                FormError bob = new FormError(ex.ToString(), "Le plugin n'est pas parvenu à se connecter au serveur nuxeo suivant : " + Config1.xmlRootNode().ChildNodes.Item(0).InnerText
                        + System.Environment.NewLine + "Veuillez vérifier vos paramètres de connection.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Connection serveur fail :" + ex);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }
            }
        }
예제 #5
0
        /*Request Upload */
        public void EnvoiPJ(string fileName, string fsFilename, string docRef)
        {
            // Restlet uploadAttached to upload file in nuxeo document
            StringBuilder url = new StringBuilder(nuxeo + "restAPI/default/");
            url.Append(docRef);
            url.Append("/");
            url.Append(fileName);
            url.Append("/uploadAttached");
            HttpWebRequest request = WebRequest.Create(url.ToString()) as HttpWebRequest;

            request.Credentials = new NetworkCredential(login, mdp);
            request.Method = "POST";
            request.ContentType = "application/outlook";
            request.Headers.Add("filename", fileName);

            byte[] buff = null;
            FileStream fs = new FileStream(fsFilename, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            long numBytes = new FileInfo(fsFilename).Length;
            buff = br.ReadBytes((int)numBytes);
            br.Close();

            try
            {
                using (Stream postStream = request.GetRequestStream())
                {
                    postStream.Write(buff, 0, buff.Length);
                }
                // Get response
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    // Get the response stream
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string resultXml = reader.ReadToEnd();

                    // Console application output
                    System.Diagnostics.Trace.TraceError("Retour REST API uploadFile :" + resultXml);
                }
                File.Delete(fsFilename);
            }
            catch (Exception e)
            {
                FormError bob = new FormError(e.ToString(), "Le plugin a rencontré un problème lors de l'upload de(s) pièce(s) jointe(s)."
                + System.Environment.NewLine + "Veuillez réessayez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Upload pieces jointes fail :" + e);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }
            }
        }
예제 #6
0
        public string createNuxeoDocument(Outlook.MailItem mailItem, int position, String idFolder)
        {
            try
            {
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                parameters[SessionParameter.BindingType] = BindingType.AtomPub;
                parameters[SessionParameter.AtomPubUrl] = nuxeo + "atom/cmis";
                parameters[SessionParameter.User] = login;
                parameters[SessionParameter.Password] = mdp;

                SessionFactory factory = SessionFactory.NewInstance();
                ISession session = factory.GetRepositories(parameters)[0].CreateSession();
                IObjectId id = session.CreateObjectId(idFolder);
                IFolder folder = session.GetObject(id) as IFolder;

                IDictionary<string, object> properties = new Dictionary<string, object>();

                properties["cmis:objectTypeId"] = "MailMessage";
                properties["cmis:name"] = mailItem.Subject == null ? "Sans Objet" : mailItem.Subject;

                properties["mail:sender"] = mailItem.SenderName;
                properties["mail:messageId"] = mailItem.Subject;
                properties["mail:sending_date"] = mailItem.SentOn;

                List<String> rep = new List<String>();
                for(int i = 1; i <= mailItem.Recipients.Count ; i++)
                {
                    rep.Add(mailItem.Recipients[i].Name);
                }
                properties["mail:recipients"] = rep;

                if (mailItem.CC != null)
                {
                    List<String> to = new List<String>();
                    to.Add(mailItem.CC);
                    properties["mail:cc_recipients"] = to;
                }

                string html = mailItem.HTMLBody;
                //bug nuxeo ? <body bgcolor=black>
                //take code in <body></body>
                Regex rx = new Regex(@"<body[^>]*>(.*?)</body", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                Match m1 = rx.Match(html);
                html = m1.Groups[1].Value;
                //max size of mail:htmlText = 65536
                if (!(html.Length < 60000))
                {
                    FormError bob = new FormError("Le mail est trop long, impossible de l'uploader dans nuxeo.");
                    bob.ShowDialog();
                    return null;
                }

                //For Nuxeo 5.5+
                properties["mail:htmlText"] = html;
                //For Nuxeo 5.4.2
                properties["mail:text"] = html;

                try
                {
                    IDocument doc = folder.CreateDocument(properties, null, null);

                    //Add mail in nuxeo attachment (format .msg)
                    addContentFile(mailItem, doc.Id);

                    int nbAttachments = mailItem.Attachments.Count;

                    if (nbAttachments > 0)
                    {
                        //pattern to find img in htmlmessage
                        string pattern = "<img.+?src=[\"'](.+?)[\"'].+?>";
                        string patternIMG = "image(\\S+?)\\.(jpg|png|gif|jpeg)";
                        int i = 1;

                        //Upload Attachments
                        for (int iCurAttachment = 1; iCurAttachment <= nbAttachments; iCurAttachment++)
                        {
                            //Property ATTACH_FLAGS 0x37140003
                            //If != 4, attachment
                            if (mailItem.Attachments[iCurAttachment].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37140003") != 4)
                            {
                                attachFile(mailItem.Attachments[iCurAttachment], doc.Id);
                                i++;
                            }
                        }

                        //Upload pictures embedded in mail
                        foreach (Match m in Regex.Matches(html, pattern, RegexOptions.IgnoreCase))
                        {
                            //replace url in mailMessage to nuxeo url
                            string nameIMG = Regex.Match(m.Groups[1].Value, patternIMG, RegexOptions.IgnoreCase).Value != "" ? Regex.Match(m.Groups[1].Value, patternIMG, RegexOptions.IgnoreCase).Value : m.Groups[1].Value;
                            html = html.Replace(m.Groups[1].Value, nuxeo + "nxfile/default/" + doc.Id + "/files:files/" + i + "/file/" + nameIMG);

                            for (int iCurAttachment = 1; iCurAttachment <= nbAttachments; iCurAttachment++)
                            {
                                if (mailItem.Attachments[iCurAttachment].FileName.Equals(nameIMG, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    //Upload picture
                                    attachFile(mailItem.Attachments[iCurAttachment], doc.Id);
                                    i++;
                                    break;
                                }
                            }
                        }

                        properties["mail:text"] = html;
                        properties["mail:htmlText"] = html;
                        doc.UpdateProperties(properties);
                    }
                    return doc.Id;
                }
                catch (Exception e)
                {
                    FormError bob = new FormError(e.ToString(), "Le programme s'est connecté à nuxeo mais n'a pas réussi à créer le(s) document(s)." + System.Environment.NewLine + "Veuillez réessayez ou contactez l'administrateur si le problème persiste.");
                    bob.ShowDialog();
                    System.Diagnostics.Trace.TraceError("Probleme createNuxeoDocument() :" + e);
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                    {
                        file.WriteLine(e + "\n\t\n\t");
                        file.Close();
                    }
                }
            }
            catch (Exception e)
            {
                FormError bob = new FormError(e.ToString(), "Le plugin n'est pas parvenu à se connecter au serveur nuxeo suivant : " + Config1.xmlRootNode().ChildNodes.Item(0).InnerText
                        + System.Environment.NewLine + "Veuillez vérifier vos paramètres de connection.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Connection serveur fail :" + e);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }
            }
            return null;
        }
예제 #7
0
 public void OnMyButtonClick(Office.IRibbonControl control)
 {
     NuxeoAttachList nuxeo = new NuxeoAttachList();
     try
     {
         if (control.Context is Outlook.AttachmentSelection)
         {
             Outlook.AttachmentSelection attachSel =
                 control.Context as Outlook.AttachmentSelection;
             foreach (Outlook.Attachment attach in attachSel)
             {
                 nuxeo.init(attach);
                 nuxeo.ShowDialog();
                 nuxeo.Close();
             }
         }
     }
     catch (Exception e)
     {
         FormError bob = new FormError(e.ToString(), "Erreur lors de l'initialisation du plugin."
         + System.Environment.NewLine + "Veuillez redémarrez le programme, vérifiez vos paramètres de connection et réessayez ou contactez l'administrateur si le problème persiste.");
         bob.ShowDialog();
     }
 }
예제 #8
0
 private void AddMenuBar()
 {
     try
     {
         newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, false);
         if (newMenuBar != null)
         {
             newMenuBar.Caption = "Nuxeo";
             newMenuBar.Tag = menuTag;
             buttonConfig = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, 1, true);
             buttonConfig.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
             buttonConfig.Caption = "Configuration";
             buttonConfig.FaceId = 65;
             buttonConfig.Tag = "c123";
             //  buttonConfig.Picture = getImage();
             newMenuBar.Visible = true;
         }
     }
     catch (Exception ex)
     {
         FormError bob = new FormError(ex.ToString(), "Erreur lors de l'ajout de la barre de menu."
     + System.Environment.NewLine + "Veuillez redémarrez le programme, réessayez ou contactez l'administrateur si le problème persiste.");
         bob.ShowDialog();
         System.Diagnostics.Trace.TraceError("Problème Initialisation NuxeoDocList :" + ex);
         using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
         {
             file.WriteLine(ex + "\n\t\n\t");
             file.Close();
         }
     }
 }
예제 #9
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            try
            {
                test();
                menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                RemoveMenubar();
                AddMenuBar();

                _Explorer = (Outlook.ExplorerClass)this.Application.ActiveExplorer();
                _CommandBars = _Explorer.CommandBars;
                _CommandBars.OnUpdate += new Microsoft.Office.Core._CommandBarsEvents_OnUpdateEventHandler(_CommandBars_OnUpdate);
                buttonConfig.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonConfig_Click);

                //MessageBox.Show("The Outlook add-in has been deployed successfully.");
            }
            catch (Exception ex)
            {
                FormError bob = new FormError(e.ToString(), "Erreur lors du deploiement du plugin."
            + System.Environment.NewLine + "Veuillez redémarrez le programme, réessayez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Problème deploiement plugin :" + ex);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(ex + "\n\t\n\t");
                    file.Close();
                }
            }
        }
예제 #10
0
        private void RemoveMenubar()
        {
            // If the menu already exists, remove it.
            try
            {
                Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
                    this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.
                    FindControl(Office.MsoControlType.msoControlPopup,
                    System.Type.Missing, menuTag, true, true);
                if (foundMenu != null)
                {
                    foundMenu.Delete(true);
                }
            }
            catch (Exception ex)
            {

                FormError bob = new FormError(ex.ToString(), "Erreur lors de la suppression de la barre de menu."
            + System.Environment.NewLine + "Veuillez redémarrez le programme, réessayez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Problème Initialisation NuxeoDocList :" + ex);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(ex + "\n\t\n\t");
                    file.Close();
                }
            }
        }
        public bool addContentFile(Outlook.Attachment attachment, string docRef)
        {
            // Extraction et copie en local du message Outlook au format MSG
            string filename = attachment.FileName;
            string fsFilename = repTemp + AddSlashes(filename);
            attachment.SaveAsFile(fsFilename);

            // Lancement de la commande REST d'ajout du fichier principal au document courant
            StringBuilder url = new StringBuilder(nuxeo + "restAPI/default/");
            url.Append(docRef);
            url.Append("/");
            url.Append(filename);
            url.Append("/uploadFile");
            HttpWebRequest request = WebRequest.Create(url.ToString()) as HttpWebRequest;

            request.Credentials = new NetworkCredential(login, mdp);
            request.Method = "POST";
            request.ContentType = "application/msoutlook";

            byte[] buff = null;
            FileStream fs = new FileStream(fsFilename, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            long numBytes = new FileInfo(fsFilename).Length;
            buff = br.ReadBytes((int)numBytes);
            br.Close();

            try
            {
                using (Stream postStream = request.GetRequestStream())
                {
                    postStream.Write(buff, 0, buff.Length);
                }
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());
                    string resultXml = reader.ReadToEnd();
                }

                File.Delete(fsFilename);
                return true;
            }
            catch (Exception e)
            {

                FormError bob = new FormError(e.ToString(), "Le plugin a rencontré un problème lors de l'upload du message."
                + System.Environment.NewLine + "Veuillez réessayez ou contactez l'administrateur si le problème persiste.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Upload fail :" + e);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }

                return false;
            }
        }
        public String createNuxeoDocument(Outlook.Attachment attachment, String idFolder)
        {
            try
            {
                IDictionary<string, string> parameters = new Dictionary<string, string>();
                parameters[SessionParameter.BindingType] = BindingType.AtomPub;
                parameters[SessionParameter.AtomPubUrl] = nuxeo + "atom/cmis";
                parameters[SessionParameter.User] = login;
                parameters[SessionParameter.Password] = mdp;

                SessionFactory factory = SessionFactory.NewInstance();
                ISession session = factory.GetRepositories(parameters)[0].CreateSession();
                IObjectId id = session.CreateObjectId(idFolder);
                IFolder folder = session.GetObject(id) as IFolder;

                IDictionary<string, object> properties = new Dictionary<string, object>();
                properties["cmis:objectTypeId"] = "File";
                properties["cmis:name"] = attachment.FileName;

                try
                {
                    IDocument doc = folder.CreateDocument(properties, null, null);
                    return doc.VersionSeriesId;
                }
                catch (Exception e)
                {
                    FormError bob = new FormError(e.ToString(), "Le programme s'est connecté à nuxeo mais n'a pas réussi à créer le(s) document(s)." + System.Environment.NewLine + "Veuillez réessayez ou contactez l'administrateur si le problème persiste.");
                    bob.ShowDialog();
                    System.Diagnostics.Trace.TraceError("Probleme createNuxeoDocument() :" + e);
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                    {
                        file.WriteLine(e + "\n\t\n\t");
                        file.Close();
                    }
                }
            }
            catch (Exception e)
            {
                FormError bob = new FormError(e.ToString(), "Le plugin n'est pas parvenu à se connecter au serveur nuxeo suivant : " + Config1.xmlRootNode().ChildNodes.Item(0).InnerText
                        + System.Environment.NewLine + "Veuillez vérifier vos paramètres de connection.");
                bob.ShowDialog();
                System.Diagnostics.Trace.TraceError("Connection serveur fail :" + e);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true))
                {
                    file.WriteLine(e + "\n\t\n\t");
                    file.Close();
                }
            }
            return null;
        }