Example #1
0
 /// <summary>
 /// Function to Continue the Translation process
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void btn_OK_Click(object sender, EventArgs e)
 {
     try
     {
         Translate();
     }
     catch (Exception ex)
     {
         AddinLogger.Error(ex);
         MessageBox.Show(ex.Message);
     }
 }
Example #2
0
        /*Function to check whether selected document is open or not*/
        public String CheckFileOPen(String listSubDocs)
        {
            AddinLogger.Info("Check if file opened : " + listSubDocs);
            String resultSubDoc = "notopen";

            try
            {
                Package pack;
                pack = Package.Open(listSubDocs, FileMode.Open, FileAccess.ReadWrite);
                pack.Close();
            }
            catch (Exception e)
            {
                AddinLogger.Error(e);
                resultSubDoc = "open";
            }
            return(resultSubDoc);
        }
Example #3
0
 /*Function  which starts DAISY Translation*/
 private void DoConvert()
 {
     try
     {
         converter.RemoveMessageListeners();
         converter.AddProgressMessageListener(new AbstractConverter.MessageListener(ProgressMessageInterceptor));
         converter.AddFeedbackMessageListener(new AbstractConverter.MessageListener(FeedbackMessageInterceptor));
         converter.AddFeedbackValidationListener(new AbstractConverter.MessageListener(FeedbackValidationInterceptor));
         converter.DirectTransform = this.isDirect;
         this.computeSize          = true;
         converter.ComputeSize(this.inputFile, this.table);
         this.step        = Convert.ToSingle(this.progressBar1.Maximum - this.progressBar1.Value) / this.size;
         this.computeSize = false;
         converter.Transform(this.inputFile, this.outputFile, this.table, this.listMathMl, true, output_Pipeline);
         WorkComplete(null);
     }
     catch (Exception e)
     {
         AddinLogger.Error(e);
         MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         WorkComplete(e);
     }
 }
Example #4
0
        //private void UpdatePathTextboxFromFolderBrowserDialog()
        //{
        //    folderBrowserDialog1.ShowNewFolderButton = true;
        //    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
        //    {
        //        mTextBox.Text = folderBrowserDialog1.SelectedPath;
        //    }

        //}

        public override void UpdateScriptParameterValue()
        {
            if ((mTextBox.Text != null && mTextBox.Text.TrimEnd() != ""))
            {
                m_SelectedPath = mTextBox.Text;
                if (m_PathData.isInputOrOutput == PathDataType.InputOrOutput.output)
                {
                    try
                    {
                        if (m_PathData.IsFileOrDirectory == PathDataType.FileOrDirectory.Directory)
                        {
                            CheckForOutputDirectory();
                        }
                        else if (m_PathData.IsFileOrDirectory == PathDataType.FileOrDirectory.File)
                        {
                            File.CreateText(mTextBox.Text).Close();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        AddinLogger.Error(ex);
                        return;
                    }
                }
                // update    parameter
                try
                {
                    m_PathData.Value = mTextBox.Text;
                }
                catch (System.Exception ex)
                {
                    AddinLogger.Error(ex);
                }
            }
            return;            // null value check ends
        }
Example #5
0
        /*Core function for Translation*/
        private void btn_Ok_Click(object sender, EventArgs e)
        {
            CleanOutputDirDlg cleanUpDialog;

            if ((btnID == "DaisyMultiple" || btnID == "DaisyTabMultiple" || btnID == "Button2") && !useAScript)
            {
                if (lBx_SubDocs.Items.Count == 0)
                {
                    MessageBox.Show(manager.GetString("SubdocsError"), "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Browse.Focus();
                }
                else if (tBx_output.Text == "")
                {
                    MessageBox.Show(manager.GetString("ChoseDestinationFile"), manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Output.Focus();
                }
                else if (Directory.Exists(Path.GetDirectoryName(tBx_output.Text)) == false)
                {
                    MessageBox.Show("Directory " + string.Concat(Path.GetDirectoryName(tBx_output.Text), " ", "does not exist"), manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Output.Focus();
                }
                else if (Path.GetFileNameWithoutExtension(tBx_output.Text) == "")
                {
                    MessageBox.Show("Please provide proper filename", manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Output.Focus();
                }
                else if (tBx_Title.Text.TrimEnd() == "")
                {
                    MessageBox.Show("Please enter the Title", manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tBx_Title.Focus();
                }
                else
                {
                    for (int i = 0; i < lBx_SubDocs.Items.Count; i++)
                    {
                        listDocuments.Add(lBx_SubDocs.Items[i].ToString());
                        btn_Delete.Enabled   = true;
                        btn_Populate.Enabled = true;
                    }

                    table.Add("Title", tBx_Title.Text);
                    table.Add("Creator", tBx_Creator.Text);
                    table.Add("Publisher", tBx_Publisher.Text);
                    table.Add("Subject", tBx_Subject.Text);
                    table.Add("MasterSub", "Yes");
                    table.Add("Version", this.versionInfo);


                    if (tBx_Uid.Text != "")
                    {
                        if (uId == tBx_Uid.Text)
                        {
                            table.Add("UID", "AUTO-UID-" + tBx_Uid.Text);
                        }
                        else
                        {
                            table.Add("UID", tBx_Uid.Text);
                        }
                    }
                    else
                    {
                        table.Add("UID", "AUTO-UID-" + GenerateId().ToString());
                    }


                    if (Path.GetExtension(tBx_output.Text) == "")
                    {
                        tBx_output.Text = tBx_output.Text + ".xml";
                    }

                    fileOutputPath = tBx_output.Text;
                    DaisyTranslationSettings daisySt = new DaisyTranslationSettings();
                    String imgoption      = daisySt.GetImageOption;
                    String resampleValue  = daisySt.GetResampleValue;
                    String characterStyle = daisySt.GetCharacterStyle;
                    String pagenumStyle   = daisySt.GetPagenumStyle;
                    if (imgoption != " ")
                    {
                        table.Add("ImageSizeOption", imgoption);
                        table.Add("DPI", resampleValue);
                    }
                    if (characterStyle != " ")
                    {
                        table.Add("CharacterStyles", characterStyle);
                    }
                    if (pagenumStyle != " ")
                    {
                        table.Add("Custom", pagenumStyle);
                    }

                    masterSubFlag = 1;
                    this.Close();
                }
            }

            else
            {
                string scriptOutput = string.Empty;
                for (int i = 0; i < mLayoutPanel.Controls.Count; i++)
                {
                    if (mLayoutPanel.Controls[i] is BaseUserControl)
                    {
                        ((BaseUserControl)mLayoutPanel.Controls[i]).UpdateScriptParameterValue();
                    }
                }
                for (int i = 0; i < oTableLayoutPannel.Controls.Count; i++)
                {
                    if (oTableLayoutPannel.Controls[i] is BaseUserControl)
                    {
                        ((BaseUserControl)oTableLayoutPannel.Controls[i]).UpdateScriptParameterValue();
                    }
                }

                foreach (ScriptParameter p in mParser.ParameterList)
                {
                    if (p.IsParameterRequired && (p.Name == "outputPath" || p.Name == "output"))
                    {
                        PathDataType pathDataType = p.ParameterDataType as PathDataType;
                        if (pathDataType == null)
                        {
                            continue;
                        }

                        if (pathDataType.IsFileOrDirectory == PathDataType.FileOrDirectory.File)
                        {
                            try
                            {
                                FileInfo outputFileInfo = new FileInfo(p.ParameterValue);
                                if (!string.IsNullOrEmpty(pathDataType.FileExtenssion) &&
                                    !pathDataType.FileExtenssion.Equals(outputFileInfo.Extension, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    MessageBox.Show(string.Format("Please select {0} output file", pathDataType.FileExtenssion), "Error",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                                    return;
                                }
                                strBrtextBox = outputFileInfo.DirectoryName;
                                scriptOutput = outputFileInfo.Name;
                            }
                            catch (ArgumentException ex)
                            {
                                AddinLogger.Error(ex);
                                MessageBox.Show("Please select output file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                                return;
                            }
                        }
                        else
                        {
                            strBrtextBox = p.ParameterValue;
                        }
                        break;
                    }
                }

                cleanUpDialog = new CleanOutputDirDlg(strBrtextBox, scriptOutput);

                if (lBx_SubDocs.Items.Count == 0)
                {
                    MessageBox.Show(manager.GetString("SubdocsError"), "SaveAsDAISY", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btn_Browse.Focus();
                }
                else if (tBx_Title.Text.TrimEnd() == "")
                {
                    MessageBox.Show("Please enter the Title", manager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tBx_Title.Focus();
                }
                else if (strBrtextBox.TrimEnd() == "")
                {
                    MessageBox.Show("Please select the Destination folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                }
                else if (cleanUpDialog.Clean(this) == DialogResult.Cancel)
                {
                    mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                }
                else
                {
                    if (strBrtextBox != cleanUpDialog.OutputDir)
                    {
                        strBrtextBox = cleanUpDialog.OutputDir;
                        foreach (ScriptParameter p in mParser.ParameterList)
                        {
                            if (p.IsParameterRequired && (p.Name == "outputPath" || p.Name == "output"))
                            {
                                p.ParameterValue = cleanUpDialog.OutputDir;
                            }
                        }
                    }


                    tBx_output.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveAsDAISY";
                    for (int i = 0; i < lBx_SubDocs.Items.Count; i++)
                    {
                        listDocuments.Add(lBx_SubDocs.Items[i].ToString());
                        btn_Delete.Enabled   = true;
                        btn_Populate.Enabled = true;
                    }

                    table.Add("Title", tBx_Title.Text);
                    table.Add("Creator", tBx_Creator.Text);
                    table.Add("Publisher", tBx_Publisher.Text);
                    table.Add("Subject", tBx_Subject.Text);
                    table.Add("MasterSub", "Yes");
                    table.Add("Version", this.versionInfo);

                    if (tBx_Uid.Text != "")
                    {
                        if (uId == tBx_Uid.Text)
                        {
                            table.Add("UID", "AUTO-UID-" + tBx_Uid.Text);
                        }
                        else
                        {
                            table.Add("UID", tBx_Uid.Text);
                        }
                    }
                    else
                    {
                        table.Add("UID", "AUTO-UID-" + GenerateId().ToString());
                    }

                    if (Path.GetExtension(tBx_output.Text) == "")
                    {
                        tBx_output.Text = Path.Combine(tBx_output.Text, "MultipleNarrator" + ".xml");
                    }

                    fileOutputPath = tBx_output.Text;
                    DaisyTranslationSettings daisySt = new DaisyTranslationSettings();
                    String imgoption      = daisySt.GetImageOption;
                    String resampleValue  = daisySt.GetResampleValue;
                    String characterStyle = daisySt.GetCharacterStyle;
                    String pagenumStyle   = daisySt.GetPagenumStyle;
                    if (imgoption != " ")
                    {
                        table.Add("ImageSizeOption", imgoption);
                        table.Add("DPI", resampleValue);
                    }
                    if (characterStyle != " ")
                    {
                        table.Add("CharacterStyles", characterStyle);
                    }
                    if (pagenumStyle != " ")
                    {
                        table.Add("Custom", pagenumStyle);
                    }

                    masterSubFlag = 1;
                    this.Close();
                }
            }
        }
Example #6
0
        private bool ValidateForFullDaisyTranslate()
        {
            string fileName    = Path.GetFileNameWithoutExtension(mInputPath);
            string otpfileName = fileName + ".xml";

            tBx_Browse.Text = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\SaveAsDAISY\";
            if (tBx_Title.Text.TrimEnd() == "")
            {
                MessageBox.Show(resManager.GetString("Title"), resManager.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                tBx_Title.Focus();
                return(false);
            }

            for (int i = 0; i < mLayoutPanel.Controls.Count; i++)
            {
                if (mLayoutPanel.Controls[i] is BaseUserControl)
                {
                    ((BaseUserControl)mLayoutPanel.Controls[i]).UpdateScriptParameterValue();
                }
            }

            for (int i = 0; i < oTableLayoutPannel.Controls.Count; i++)
            {
                if (oTableLayoutPannel.Controls[i] is BaseUserControl)
                {
                    ((BaseUserControl)oTableLayoutPannel.Controls[i]).UpdateScriptParameterValue();
                }
            }

            foreach (ScriptParameter p in mParser.ParameterList)
            {
                if (p.IsParameterRequired && (p.Name == "outputPath" || p.Name == "output"))
                {
                    PathDataType pathDataType = p.ParameterDataType as PathDataType;
                    if (pathDataType == null)
                    {
                        continue;
                    }

                    if (pathDataType.IsFileOrDirectory == PathDataType.FileOrDirectory.File)
                    {
                        try
                        {
                            FileInfo outputFileInfo = new FileInfo(p.ParameterValue);
                            if (!string.IsNullOrEmpty(pathDataType.FileExtenssion) && !pathDataType.FileExtenssion.Equals(outputFileInfo.Extension, StringComparison.InvariantCultureIgnoreCase))
                            {
                                MessageBox.Show(string.Format("Please select {0} output file", pathDataType.FileExtenssion), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                                return(false);
                            }
                            strBrtextBox = outputFileInfo.DirectoryName;
                        }
                        catch (ArgumentException ex)
                        {
                            AddinLogger.Error(ex);
                            MessageBox.Show("Please select output file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                            return(false);
                        }
                    }
                    else
                    {
                        strBrtextBox = p.ParameterValue;
                    }

                    //TODO:::
                    if (string.IsNullOrEmpty(strBrtextBox.TrimEnd()))
                    {
                        MessageBox.Show("Please select the Destination folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                        return(false);
                    }

                    CleanOutputDirDlg cleanOutputDirDlg = new CleanOutputDirDlg(strBrtextBox, otpfileName);
                    if (cleanOutputDirDlg.Clean(this) == DialogResult.Cancel)
                    {
                        mLayoutPanel.Controls[0].Controls[0].Controls[1].Focus();
                        return(false);
                    }
                    if (strBrtextBox != cleanOutputDirDlg.OutputDir)
                    {
                        strBrtextBox     = cleanOutputDirDlg.OutputDir;
                        p.ParameterValue = cleanOutputDirDlg.OutputDir;
                    }

                    break;
                }
            }



            //if (File.Exists(strBrtextBox + "\\" + otpfileName))
            //{
            //    DialogResult objResult;
            //    objResult = MessageBox.Show(otpfileName + " already exists in the destination folder. Do you want to overwrite?", "Confirm File Replace", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //    if (objResult != DialogResult.Yes)
            //    {
            //        mLayoutPanel.Controls[0].Controls[0].Focus();
            //        return false;
            //    }
            //}

            return(true);
        }