public static Project LoadXuk(string file) { string fullpath = Path.GetFullPath(file); Project project = new Project(); var uri = new Uri(fullpath); var action = new OpenXukAction(project, uri); action.Execute(); return(project); }
private void Application_Startup(object sender, StartupEventArgs e) { string errMsg; if (!ParseCommandLineArguments(e.Args, out errMsg)) { MessageBox.Show( String.Format("{0}\nUsage: FlowDocumentXmlEditor [-xuk:<xuk_uri>]", errMsg)); this.Shutdown(-1); return; } mProject = new Project(); //MainWindow mw1 = new MainWindow(); mw2 = new MainWindow(mProject, mProjectUri); if (mProjectUri != null) { OpenXukAction action = new OpenXukAction(mProject, mProjectUri); bool wasCancelled; ProgressWindow.ExecuteProgressAction(action, out wasCancelled); if (wasCancelled) { Shutdown(-1); return; } } if (mProject.NumberOfPresentations > 0) { Presentation pres = mProject.GetPresentation(0); TextChannel textCh = null; foreach (Channel ch in pres.ChannelsManager.ListOfChannels) { if (ch is TextChannel) { textCh = (TextChannel)ch; break; } } //UrakawaHtmlFlowDocument doc1 = new UrakawaHtmlFlowDocument(pres.getRootNode(), textCh); //mw1.EditedDocument = doc1; GenericExtractionVisitor.USE_TEXT_BOX_UIELEMENT = false; UrakawaHtmlFlowDocument doc2 = new UrakawaHtmlFlowDocument(pres.RootNode, textCh); mw2.EditedDocument = doc2; } //mw1.Show(); mw2.Show(); }
/// <summary> /// Open a project from a XUK file. /// </summary> public void Open(string path) { m_ErrorsInOpeningProject = false; m_ListOfErrorMessages.Clear(); mProject = new urakawa.Project(); //sdk2 //mProject.setDataModelFactory ( mDataModelFactory ); mProject.dataIsMissing += new EventHandler <urakawa.events.media.data.DataIsMissingEventArgs>(OnDataIsMissing); //long memoryBefore = System.GC.GetTotalMemory(true); //sdk2 //mProject.openXUK ( new Uri ( path ) ); //System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); //stopWatch.Start(); OpenXukAction action = new OpenXukAction(mProject, new Uri(path)); action.ShortDescription = "DUMMY"; action.LongDescription = "DUMMY"; action.DoWork(); //stopWatch.Stop(); //Console.WriteLine("Time taken for xuk-in in milliseconds " + stopWatch.ElapsedMilliseconds); //Presentation = mProject.Presentations.Get(0); //long memoryAfter = System.GC.GetTotalMemory(true); //long memoryDiff = memoryBefore - memoryAfter; //Console.WriteLine("opening project memory differenc is " + (memoryDiff / 1024)); mPath = path; GetLock(mPath); Presentation.Initialize(this); // Hack to ignore the empty commands saved by the default undo/redo manager Presentation.UndoRedoManager.FlushCommands(); ((ObiRootNode)mProject.Presentations.Get(0).RootNode).LocateBookMarkAndAssociatedNode(); SetupBackupFilesForNewSession(path); if (ProjectOpened != null) { ProjectOpened(this, null); } if (m_ListOfErrorMessages.Count > 0) { m_ErrorsInOpeningProject = true; Dialogs.ReportDialog reportDialog = new Obi.Dialogs.ReportDialog(Localizer.Message("Warning"), Localizer.Message("Error_Message"), m_ListOfErrorMessages); reportDialog.ShowDialog(); } ShouldDisableDiskSpaceCheck(); }
}//btnLoad //Start Import button to strat the conversion process private void btnStartImport_Click(object sender, EventArgs e) { var converter = new XukImport.DaisyToXuk(m_ImportFile, m_SaveDir); Channel channelText = null; Channel channelAudio = null; List <Channel> listCh = converter.Project.Presentations.Get(0).ChannelsManager.ManagedObjects.ContentsAs_ListCopy; foreach (Channel ch in listCh) { if (ch is TextChannel) { channelText = ch; } else if (ch is AudioChannel) { channelAudio = ch; } } RenameChannelCommand.mProject = converter.Project; RenameChannelCommand cmd1 = null; if (channelText != null) { cmd1 = converter.Project.Presentations.Get(0).CommandFactory.Create <RenameChannelCommand>(); cmd1.Init(channelText, "The new TEXT Channel Name"); } RenameChannelCommand cmd2 = null; if (channelAudio != null) { cmd2 = converter.Project.Presentations.Get(0).CommandFactory.Create <RenameChannelCommand>(); cmd2.Init(channelAudio, "The new AUDIO Channel Name"); } RenameChannelCommand cmd3 = null; if (channelText != null) { cmd3 = converter.Project.Presentations.Get(0).CommandFactory.Create <RenameChannelCommand>(); cmd3.Init(channelText, "NEW TEXT Channel Name"); } /* * DeleteChannelCommand cmd2 = null; * if (channelAudio != null) * { * cmd2 = new DeleteChannelCommand(channelAudio); * } * */ converter.Project.Presentations.Get(0).UndoRedoManager.StartTransaction("rename transaction", null); if (cmd1 != null) { converter.Project.Presentations.Get(0).UndoRedoManager.Execute(cmd1); } if (cmd2 != null) { converter.Project.Presentations.Get(0).UndoRedoManager.Execute(cmd2); } converter.Project.Presentations.Get(0).UndoRedoManager.EndTransaction(); if (cmd3 != null) { converter.Project.Presentations.Get(0).UndoRedoManager.Execute(cmd3); } converter.Project.Presentations.Get(0).UndoRedoManager.Undo(); Uri uriComp = new Uri(m_SaveDir + ".COMPRESSED.xuk"); converter.Project.SetPrettyFormat(false); { SaveXukAction actionSave = new SaveXukAction(converter.Project, converter.Project, uriComp); bool saveWasCancelled; Progress.ExecuteProgressAction(actionSave, out saveWasCancelled); if (saveWasCancelled) { return; } } Uri uriPretty = new Uri(m_SaveDir + ".PRETTY.xuk"); converter.Project.SetPrettyFormat(true); { SaveXukAction actionSave = new SaveXukAction(converter.Project, converter.Project, uriPretty); bool saveWasCancelled; Progress.ExecuteProgressAction(actionSave, out saveWasCancelled); if (saveWasCancelled) { return; } } ///// //// Make sure we don't create concurrent access to WAV files while opening the same XUK file in several projects. converter.Project.Presentations.Get(0).DataProviderManager.CompareByteStreamsDuringValueEqual = false; ///// Project projectPretty = new Project(); { OpenXukAction actionOpen = new OpenXukAction(projectPretty, uriPretty); bool openWasCancelled; Progress.ExecuteProgressAction(actionOpen, out openWasCancelled); if (openWasCancelled) { return; } } projectPretty.Presentations.Get(0).DataProviderManager.CompareByteStreamsDuringValueEqual = false; System.Diagnostics.Debug.Assert(converter.Project.ValueEquals(projectPretty)); Project projectComp = new Project(); { OpenXukAction actionOpen = new OpenXukAction(projectComp, uriComp); bool openWasCancelled; Progress.ExecuteProgressAction(actionOpen, out openWasCancelled); if (openWasCancelled) { return; } } projectComp.Presentations.Get(0).DataProviderManager.CompareByteStreamsDuringValueEqual = false; System.Diagnostics.Debug.Assert(converter.Project.ValueEquals(projectComp)); //// Make sure we don't create concurrent access to WAV files while opening the same XUK file in several projects. System.Diagnostics.Debug.Assert(projectComp.ValueEquals(projectPretty)); converter.Project.Presentations.Get(0).UndoRedoManager.Redo(); System.Diagnostics.Debug.Assert(!converter.Project.ValueEquals(projectPretty)); //TODO: there is a bug in the Urakawa SDK due to the static sharing of the XukString ! // In other words, the Factories will not refresh their QNames in the following call to SetPrettyFormat(), // because converter.Project was already set to PRETTY a while ago (see code above). Problem: // the "projectComp" instance created above has set the Factory QNames to COMPRESSED // and due to the static sharing of XukStrings, converter.Project is affected. As a result, the PRETTY2 file // is nicely indented but with compressed q-names. Uri uriPretty2 = new Uri(m_SaveDir + ".PRETTY2.xuk"); converter.Project.SetPrettyFormat(true); { SaveXukAction actionSave = new SaveXukAction(converter.Project, converter.Project, uriPretty2); bool saveWasCancelled; Progress.ExecuteProgressAction(actionSave, out saveWasCancelled); if (saveWasCancelled) { return; } } }//btnStartImport
private void btnLoad_Click_1(object sender, EventArgs e) { txtBookName.Clear(); var open = new OpenFileDialog(); //open.InitialDirectory = @"C:\"; open.Filter = "XML Files (*.xml)|*.xml|OPF Files (*.opf)|*.opf|All files(*.*)|*.*"; open.FilterIndex = 1; open.RestoreDirectory = true; if (open.ShowDialog(this) == DialogResult.OK) { txtBookName.Text = open.FileName; string pathDTBook = txtBookName.Text; DTBooktoXukConversion converter = new DTBooktoXukConversion(pathDTBook); Channel channelText = null; Channel channelAudio = null; List <Channel> listCh = converter.Project.GetPresentation(0).ChannelsManager.ListOfChannels; foreach (Channel ch in listCh) { if (ch is TextChannel) { channelText = ch; } else if (ch is AudioChannel) { channelAudio = ch; } } RenameChannelCommand.mProject = converter.Project; RenameChannelCommand cmd1 = null; if (channelText != null) { cmd1 = converter.Project.GetPresentation(0).CommandFactory.Create <RenameChannelCommand>(); cmd1.Init(channelText, "The new TEXT Channel Name"); } RenameChannelCommand cmd2 = null; if (channelAudio != null) { cmd2 = converter.Project.GetPresentation(0).CommandFactory.Create <RenameChannelCommand>(); cmd2.Init(channelAudio, "The new AUDIO Channel Name"); } RenameChannelCommand cmd3 = null; if (channelText != null) { cmd3 = converter.Project.GetPresentation(0).CommandFactory.Create <RenameChannelCommand>(); cmd3.Init(channelText, "NEW TEXT Channel Name"); } /* * DeleteChannelCommand cmd2 = null; * if (channelAudio != null) * { * cmd2 = new DeleteChannelCommand(channelAudio); * } * */ converter.Project.GetPresentation(0).UndoRedoManager.StartTransaction("rename transaction", null); if (cmd1 != null) { converter.Project.GetPresentation(0).UndoRedoManager.Execute(cmd1); } if (cmd2 != null) { converter.Project.GetPresentation(0).UndoRedoManager.Execute(cmd2); } converter.Project.GetPresentation(0).UndoRedoManager.EndTransaction(); if (cmd3 != null) { converter.Project.GetPresentation(0).UndoRedoManager.Execute(cmd3); } converter.Project.GetPresentation(0).UndoRedoManager.Undo(); //// //// Uri uriComp = new Uri(txtBookName.Text + ".COMPRESSED.xuk"); converter.Project.SetPrettyFormat(false); { SaveXukAction actionSave = new SaveXukAction(converter.Project, converter.Project, uriComp); bool saveWasCancelled; Progress.ExecuteProgressAction(actionSave, out saveWasCancelled); if (saveWasCancelled) { return; } } ///// Uri uriPretty = new Uri(txtBookName.Text + ".PRETTY.xuk"); converter.Project.SetPrettyFormat(true); { SaveXukAction actionSave = new SaveXukAction(converter.Project, converter.Project, uriPretty); bool saveWasCancelled; Progress.ExecuteProgressAction(actionSave, out saveWasCancelled); if (saveWasCancelled) { return; } } ///// //// Make sure we don't create concurrent access to WAV files while opening the same XUK file in several projects. converter.Project.GetPresentation(0).DataProviderManager.CompareByteStreamsDuringValueEqual = false; ///// Project projectPretty = new Project(); { OpenXukAction actionOpen = new OpenXukAction(projectPretty, uriPretty); bool openWasCancelled; Progress.ExecuteProgressAction(actionOpen, out openWasCancelled); if (openWasCancelled) { return; } } projectPretty.GetPresentation(0).DataProviderManager.CompareByteStreamsDuringValueEqual = false; System.Diagnostics.Debug.Assert(converter.Project.ValueEquals(projectPretty)); ///// ///// Project projectComp = new Project(); { OpenXukAction actionOpen = new OpenXukAction(projectComp, uriComp); bool openWasCancelled; Progress.ExecuteProgressAction(actionOpen, out openWasCancelled); if (openWasCancelled) { return; } } projectComp.GetPresentation(0).DataProviderManager.CompareByteStreamsDuringValueEqual = false; System.Diagnostics.Debug.Assert(converter.Project.ValueEquals(projectComp)); //// Make sure we don't create concurrent access to WAV files while opening the same XUK file in several projects. System.Diagnostics.Debug.Assert(projectComp.ValueEquals(projectPretty)); converter.Project.GetPresentation(0).UndoRedoManager.Redo(); System.Diagnostics.Debug.Assert(!converter.Project.ValueEquals(projectPretty)); Uri uriPretty2 = new Uri(txtBookName.Text + ".PRETTY2.xuk"); converter.Project.SetPrettyFormat(true); { SaveXukAction actionSave = new SaveXukAction(converter.Project, converter.Project, uriPretty2); bool saveWasCancelled; Progress.ExecuteProgressAction(actionSave, out saveWasCancelled); if (saveWasCancelled) { return; } } } }
public void MergeProject() { m_SectionsToMerge.Clear(); try { //1 Uri uri = new Uri(m_SourceProjectPath, UriKind.Absolute); bool pretty = m_session.Presentation.Project.PrettyFormat; Project subproject = new Project(); OpenXukAction action = new OpenXukAction(subproject, uri); action.ShortDescription = "..."; action.LongDescription = "..."; action.Execute(); subproject.PrettyFormat = pretty; Presentation subpresentation = subproject.Presentations.Get(0); // compare audio formats if (m_session.Presentation.MediaDataManager.DefaultPCMFormat.Data.BitDepth != subpresentation.MediaDataManager.DefaultPCMFormat.Data.BitDepth || m_session.Presentation.MediaDataManager.DefaultPCMFormat.Data.BlockAlign != subpresentation.MediaDataManager.DefaultPCMFormat.Data.BlockAlign || m_session.Presentation.MediaDataManager.DefaultPCMFormat.Data.SampleRate != subpresentation.MediaDataManager.DefaultPCMFormat.Data.SampleRate) { throw new System.Exception("Audio format of project does not match"); } TreeNode subroot = subpresentation.RootNode; int sectionCount = ((ObiRootNode)subroot).SectionChildCount; if (sectionCount == 0) { return; } int progressValue = 0; reportProgress(progressValue, ""); SectionNode section = ((ObiRootNode)subroot).SectionChild(0); while (section != null) { //2 if (RequestCancellation) { return; } TreeNode importedLevel = section.Export(m_session.Presentation); ObiRootNode parent = (ObiRootNode)m_session.Presentation.RootNode; //parent.AppendChild((SectionNode) importedLevel); m_SectionsToMerge.Add((SectionNode)importedLevel); progressValue += 90 / sectionCount; reportProgress(progressValue, string.Format(Localizer.Message("MergeProject_SectionProgress"), section.Label)); //System.Windows.Forms.MessageBox.Show(section.GetText().ToString()); section = section.NextSibling; } //-2 } //-1 //catch (Exception ex) //{//1 //messageBoxAlert("PROBLEM:\n " + xukPath, null); //m_session.messageBoxText("MERGE PROBLEM", xukPath, ex.Message); //throw ex; //System.Windows.Forms.MessageBox.Show(ex.ToString()); //}//-1 finally { } reportProgress(100, ""); }