示例#1
0
        /// <summary>
        /// Close the last project.
        /// Will close no matter what, so check with CanClose before doing anything.
        /// </summary>
        public void Close()
        {
            if (mProject != null)
            {
                // save to backup
                if (Presentation != null && CanSave)
                {
                    SaveToBackup();
                }

                mProject.dataIsMissing -= new EventHandler <urakawa.events.media.data.DataIsMissingEventArgs>(OnDataIsMissing);

                // if the project could not be opened, there is no presentation so this call may fail
                Presentation presentation = null;
                try { presentation = Presentation; }
                catch (Exception) { }
                mProject = null;
                RemoveLock_safe(mPath);
                mPath         = null;
                mChangesCount = 0;
                if (ProjectClosed != null)
                {
                    ProjectClosed(this, new ProjectClosedEventArgs(presentation));
                }
            }
        }
示例#2
0
 /// <summary>
 /// Create a new session for Obi.
 /// </summary>
 public Session()
 {
     mDataModelFactory = new DataModelFactory();
     mProject          = null;
     mPath             = null;
     mChangesCount     = 0;
     mCanDeleteLock    = false;
 }
示例#3
0
        /// <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();
        }
        public void Open(string path)
        {
            mProject = new urakawa.Project();

            //mProject.dataIsMissing += new EventHandler<urakawa.events.media.data.DataIsMissingEventArgs> ( OnDataIsMissing );
            Uri newUri = new Uri(path);

            try
            {
                mProject.OpenXuk(newUri);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            m_Presentation = mProject.Presentations.Get(0);
            //MessageBox.Show ( m_Presentation.RootNode.Children.Count.ToString ()) ;
            m_DaisyExport = new DaisyExport.DAISY3Export(m_Presentation);
        }
示例#5
0
 /// <summary>
 /// Imports a DAISY 3 book in Obi
 /// </summary>
 /// <param name="outputPath"></param>
 /// <param name="title"></param>
 /// <param name="createTitleSection"></param>
 /// <param name="id"></param>
 /// <param name="settings"></param>
 /// <param name="importDTBPath"></param>
 public void ImportProjectFromDTB(string outputPath, string title, bool createTitleSection, string id, Settings settings, string importDTBPath, ref ImportExport.DAISY3_ObiImport import, int audioChannels, int audioSampleRate)
 {
     importDTBPath = System.IO.Path.GetFullPath(importDTBPath);
     CreateNewPresentationInBackend(outputPath, title, createTitleSection, id, settings, true, audioChannels, audioSampleRate);
     import = new Obi.ImportExport.DAISY3_ObiImport(this, settings, importDTBPath, System.IO.Path.GetDirectoryName(outputPath), false,
                                                    audioSampleRate == 44100? AudioLib.SampleRate.Hz44100: audioSampleRate == 22050?  AudioLib.SampleRate.Hz22050: AudioLib.SampleRate.Hz11025,
                                                    audioChannels == 2);
     import.DoWork();
     if (import.RequestCancellation)
     {
         mProject = null;
         return;
     }
     Presentation.CheckAndCreateDefaultMetadataItems(settings.UserProfile);
     import.CorrectExternalAudioMedia();
     Save(Path);
     if (ProjectCreated != null)
     {
         ProjectCreated(this, null);
     }
 }
示例#6
0
        internal void CreateNewPresentationInBackend(string path, string title, bool createTitleSection, string id, Settings settings, bool isStubProjectForImport, int audioChannels, int audioSampleRate)
        {
            mProject = new Project();
#if false //(DEBUG)
            mProject.PrettyFormat = true;
#else
            mProject.PrettyFormat = false;
#endif
            string parentDirectory     = System.IO.Path.GetDirectoryName(path);
            Uri    obiProjectDirectory = new Uri(parentDirectory);

            //Presentation presentation = mProject.AddNewPresentation(obiProjectDirectory, System.IO.Path.GetFileName(path));
            //ObiPresentation newPres = mProject.PresentationFactory.Create(mProject, obiProjectDirectory, System.IO.Path.GetFileName(path));

            ObiPresentation newPres = mProject.PresentationFactory.Create <ObiPresentation>();
            newPres.Project = mProject;
            newPres.RootUri = obiProjectDirectory;

            //TODO: it would be good for Obi to separate Data folder based on project file name,
            //TODO: otherwise collision of Data folder may happen if several project files are in same directory.
            //newPres.DataProviderManager.SetDataFileDirectoryWithPrefix(System.IO.Path.GetFileName(path));

#if DEBUG
            newPres.WarmUpAllFactories();
#endif


            mProject.Presentations.Insert(mProject.Presentations.Count, newPres);


            PCMFormatInfo pcmFormat = new PCMFormatInfo((ushort)audioChannels, (uint)audioSampleRate, (ushort)settings.Audio_BitDepth);
            newPres.MediaDataManager.DefaultPCMFormat       = pcmFormat;
            newPres.MediaDataManager.EnforceSinglePCMFormat = true;

            newPres.ChannelsManager.GetOrCreateTextChannel();
            //m_textChannel = presentation.ChannelFactory.CreateTextChannel();
            //m_textChannel.Name = "The Text Channel";

            newPres.ChannelsManager.GetOrCreateAudioChannel();
            //m_audioChannel = presentation.ChannelFactory.CreateAudioChannel();
            //m_audioChannel.Name = "The Audio Channel";

            ObiRootNode rootNode = newPres.TreeNodeFactory.Create <ObiRootNode>();
            newPres.RootNode = rootNode;

            //sdk2
            //mProject.setDataModelFactory ( mDataModelFactory );
            //mProject.setPresentation ( mDataModelFactory.createPresentation (), 0 );

            mPath = path;
            GetLock(mPath);
            mChangesCount = 0;
            newPres.Initialize(this, title, createTitleSection, id, settings, isStubProjectForImport);

            //sdk2
            //Presentation.setRootUri ( new Uri ( path ) );

            //sdk2
            // create data directory if it is not created
            //string dataDirectory = ((urakawa.media.data.FileDataProviderManager)Presentation.getDataProviderManager ()).getDataFileDirectoryFullPath ();
            //if ( !Directory.Exists (dataDirectory ) )
            //    {
            //    Directory.CreateDirectory ( dataDirectory );
            //    }

            //if (ProjectCreated != null) ProjectCreated ( this, null );

            SetupBackupFilesForNewSession(path);
            ShouldDisableDiskSpaceCheck();
            Save(mPath);
            //ForceSave ();
        }