Ejemplo n.º 1
0
        private void btnXPath_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                editor.AnnotationClearAll();

                if (txtXPath.Text.Length > 0)
                {
                    string xml = editor.GetAllText();
                    Dictionary <int, string> lines = SaxonXForm.XPath(xml, txtXPath.Text);

                    if (lines != null && lines.Count > 0)
                    {
                        editor.Annotate(lines);
                    }
                    else
                    {
                        lblWarning.Text = "No matches found.";
                        Utils.TimerWarning(lblWarning);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An unexpected error occurred. " + ex.Message, "XPath Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Ejemplo n.º 2
0
        internal static void WDMainFormShow()
        {
            try
            {
                if (WDMainForm == null)
                {
                    WDMainForm = new WDMainForm();

                    NppTbData _nppTbData = new NppTbData();
                    _nppTbData.hClient       = WDMainForm.Handle;
                    _nppTbData.pszName       = "ERP Helper - Workday";
                    _nppTbData.dlgID         = idWDForm;
                    _nppTbData.uMask         = NppTbMsg.DWS_DF_CONT_RIGHT;
                    _nppTbData.pszModuleName = PluginName;
                    IntPtr _ptrNppTbData = Marshal.AllocHGlobal(Marshal.SizeOf(_nppTbData));
                    Marshal.StructureToPtr(_nppTbData, _ptrNppTbData, false);

                    Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMREGASDCKDLG, 0, _ptrNppTbData);

                    // Load Saxon
                    new Thread(() =>
                    {
                        try
                        {
                            Thread.CurrentThread.IsBackground = true;
                            SaxonXForm.TransformXml(Properties.Resources.Sample_GetWorkers, Properties.Resources.Sample_Stylesheet);
                        }
                        catch
                        {
                            // ignore exception
                        }
                    }).Start();
                }
                else
                {
                    Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_DMMSHOW, 0, WDMainForm.Handle);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error initializing the plugin. " + ex.Message, "Main", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        private void btnTransform_Click(object sender, EventArgs e)
        {
            string xmlFileName = "";
            string xmlData     = "";
            string xslData     = "";
            string working     = "Working...";

            // Check each file to the right of the XML file.
            bool foundXML   = false;
            bool foundXSLT  = false;
            bool foundXForm = false;
            bool onXSLT     = false;

            try
            {
                Cursor = Cursors.WaitCursor;
                // Get the current doctype
                LangType docType = LangType.L_TEXT;
                Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTLANGTYPE, 0, ref docType);
                bool isDocTypeXML = docType == LangType.L_XML;

                // Return if doctype is not XML
                if (!isDocTypeXML)
                {
                    lblWarning.Text = "Please select an XML file to transform.";
                    Utils.TimerWarning(lblWarning);
                    return;
                }

                // Get XML text
                xmlFileName = notepad.GetCurrentFilePath();
                xmlData     = editor.GetAllText();

                // Identify the current document as XSLT.
                if (xmlData.IndexOf("</xsl:stylesheet>") > 0)
                {
                    onXSLT = true;
                }


                // **************************************************
                // Find the XSLT document
                // **************************************************
                // Count of opened files
                int fileCnt = (int)Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, 0, 0);

                // If viewing XSLT, select the XML file before it.
                if (onXSLT)
                {
                    using (ClikeStringArray cStrArray = new ClikeStringArray(fileCnt, Win32.MAX_PATH))
                    {
                        if (Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, cStrArray.NativePointer, fileCnt) != IntPtr.Zero)
                        {
                            string prevFile = "";
                            foreach (string file in cStrArray.ManagedStringsUnicode)
                            {
                                if (file == xmlFileName)
                                {
                                    Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SWITCHTOFILE, 0, prevFile);
                                    xmlFileName = notepad.GetCurrentFilePath();
                                    xmlData     = editor.GetAllText();
                                    break;
                                }
                                prevFile = file;
                            }
                        }
                    }
                }

                using (ClikeStringArray cStrArray = new ClikeStringArray(fileCnt, Win32.MAX_PATH))
                {
                    if (Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETNBOPENFILES, cStrArray.NativePointer, fileCnt) != IntPtr.Zero)
                    {
                        foreach (string file in cStrArray.ManagedStringsUnicode)
                        {
                            if (foundXML)
                            {
                                // Check for an XML document
                                Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SWITCHTOFILE, 0, file);
                                Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_GETCURRENTLANGTYPE, 0, ref docType);
                                isDocTypeXML = docType == LangType.L_XML;
                                if (isDocTypeXML && !foundXSLT)
                                {
                                    foundXSLT = true;
                                    xslData   = editor.GetAllText();
                                }
                                if (foundXSLT)
                                {
                                    if (file.ToLower().IndexOf(".xform") > 0)
                                    {
                                        Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SWITCHTOFILE, 0, file);
                                        foundXForm = true;
                                        break;
                                    }
                                }
                            }
                            if (file == xmlFileName)
                            {
                                foundXML = true;
                            }
                        }
                    }
                    if (foundXML && foundXSLT)
                    {
                        if (!foundXForm)
                        {
                            notepad.FileNew();
                            Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SAVECURRENTFILEAS, 0, Path.GetTempFileName() + ".xform");
                            foundXForm = true;
                        }
                        editor.SetText(working);
                        working = "";
                        Application.DoEvents();
                        var data = SaxonXForm.TransformXml(xmlData, xslData);
                        editor.SetXML(data + Environment.NewLine);
                    }
                    else
                    {
                        MessageBox.Show("The XML and XSLT documents could not be identified.", "ERP Helper", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                MessageBox.Show(message, "ERP Helper", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (foundXForm)
                {
                    if (working.Length == 0)
                    {
                        try
                        {
                            editor.SetText(working + Environment.NewLine);
                        }
                        catch
                        {
                            // ignore exception
                        }
                    }
                }
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }