public StorageEnvironment(StorageEnvironmentOptions options) { try { _options = options; _dataPager = options.DataPager; _freeSpaceHandling = new FreeSpaceHandling(); _headerAccessor = new HeaderAccessor(this); var isNew = _headerAccessor.Initialize(); _scratchBufferPool = new ScratchBufferPool(this); _journal = new WriteAheadJournal(this); if (isNew) CreateNewDatabase(); else // existing db, let us load it LoadExistingDatabase(); State.FreeSpaceRoot.Name = Constants.FreeSpaceTreeName; State.Root.Name = Constants.RootTreeName; Writer = new TransactionMergingWriter(this, _cancellationTokenSource.Token); if (_options.ManualFlushing == false) _flushingTask = FlushWritesToDataFileAsync(); } catch (Exception) { Dispose(); throw; } }
/// <summary> /// Class constructor /// </summary> /// <param name="document">Document to perform operations on</param> /// <param name="fullName">Full path name of document</param> public PTWordprocessingDocument(OpenXmlSDK.WordprocessingDocument document, string fullName) : base() { Document = document; FullName = fullName; InnerContent = new WordprocessingDocumentManager(this); Comments = new CommentAccessor(this); Changes = new ChangeAccessor(this); Headers = new HeaderAccessor(this); Footer = new FooterAccessor(this); Setting = new SettingAccessor(this); CustomXml = new CustomXmlAccessor(this); Background = new BackgroundAccessor(this); Style = new StyleAccessor(this); Format = new ContentFormatAccessor(this); Picture = new PictureAccessor(this); Watermark = new WatermarkAccesor(this); Theme = new ThemeAccessor(this); TOC = new TOCAccessor(this); TOF = new TOFAccessor(this); TOA = new TOAAccessor(this); Index = new IndexAccessor(this); CoreProperties = new CorePropertiesAccesor(this); CustomProperties = new CustomPropertiesAccesor(this); }
/// <summary> /// Entry point for PowerShell cmdlets /// </summary> protected override void ProcessRecord() { if (headerPath != null) { header = XDocument.Load(headerPath); } if (header == null) { WriteError(new ErrorRecord(new ArgumentException("No footer was specified."), "OpenXmlPowerTools", ErrorCategory.InvalidArgument, null)); return; } foreach (var document in AllDocuments("Set-OpenXmlHeader")) { try { if (!(document is WmlDocument)) { throw new PowerToolsDocumentException("Not a wordprocessing document."); } OutputDocument(HeaderAccessor.SetHeader((WmlDocument)document, header, kind, Section - 1)); } catch (Exception e) { WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document)); } } }
public StorageEnvironment(StorageEnvironmentOptions options, LoggerSetup loggerSetup) { try { _loggerSetup = loggerSetup; _options = options; _dataPager = options.DataPager; _freeSpaceHandling = new FreeSpaceHandling(); _headerAccessor = new HeaderAccessor(this); var isNew = _headerAccessor.Initialize(); _scratchBufferPool = new ScratchBufferPool(this); _journal = new WriteAheadJournal(this); if (isNew) { CreateNewDatabase(); } else // existing db, let us load it { LoadExistingDatabase(); } if (_options.ManualFlushing == false) { Task.Run(IdleFlushTimer); } } catch (Exception) { Dispose(); throw; } }
public StorageEnvironment(StorageEnvironmentOptions options) { try { _log = LoggingSource.Instance.GetLogger <StorageEnvironment>(options.BasePath); _options = options; _dataPager = options.DataPager; _freeSpaceHandling = new FreeSpaceHandling(); _headerAccessor = new HeaderAccessor(this); _options.DeleteAllTempBuffers(); _decompressionBuffers = new DecompressionBuffersPool(options); var isNew = _headerAccessor.Initialize(); _scratchBufferPool = new ScratchBufferPool(this); if (PlatformDetails.RunningOnPosix && options.BasePath != null && IsStorageSupportingO_Direct(options.BasePath) == false) { options.SafePosixOpenFlags &= ~PerPlatformValues.OpenFlags.O_DIRECT; var message = "Path " + options.BasePath + " not supporting O_DIRECT writes. As a result - data durability is not guarenteed"; _options.InvokeNonDurabaleFileSystemError(this, message, null); } options.PosixOpenFlags = options.SafePosixOpenFlags; _journal = new WriteAheadJournal(this); if (isNew) { CreateNewDatabase(); } else // existing db, let us load it { LoadExistingDatabase(); } if (_options.ManualFlushing == false) { Task.Run(IdleFlushTimer); } } catch (Exception) { Dispose(); throw; } }
public StorageEnvironment(StorageEnvironmentOptions options) { try { _log = LoggingSource.Instance.GetLogger <StorageEnvironment>(options.BasePath.FullPath); _options = options; _dataPager = options.DataPager; _freeSpaceHandling = new FreeSpaceHandling(); _headerAccessor = new HeaderAccessor(this); NumOfConcurrentSyncsPerPhysDrive = options.NumOfConcurrentSyncsPerPhysDrive; TimeToSyncAfterFlashInSec = options.TimeToSyncAfterFlashInSec; Debug.Assert(_dataPager.NumberOfAllocatedPages != 0); var remainingBits = _dataPager.NumberOfAllocatedPages % (8 * sizeof(long)); _validPages = new long[_dataPager.NumberOfAllocatedPages / (8 * sizeof(long)) + (remainingBits == 0 ? 0 : 1)]; _validPages[_validPages.Length - 1] |= unchecked (((long)ulong.MaxValue << (int)remainingBits)); _decompressionBuffers = new DecompressionBuffersPool(options); var isNew = _headerAccessor.Initialize(); _scratchBufferPool = new ScratchBufferPool(this); options.SetPosixOptions(); _journal = new WriteAheadJournal(this); if (isNew) { CreateNewDatabase(); } else // existing db, let us load it { LoadExistingDatabase(); } if (_options.ManualFlushing == false) { Task.Run(IdleFlushTimer); } } catch (Exception) { Dispose(); throw; } }
public override unsafe bool ReadHeader(string filename, FileHeader *header) { if (Disposed) { throw new ObjectDisposedException("PureMemoryStorageEnvironmentOptions"); } IntPtr ptr; if (_headers.TryGetValue(filename, out ptr) == false) { return(false); } *header = *((FileHeader *)ptr); return(header->Hash == HeaderAccessor.CalculateFileHeaderHash(header)); }
public WriteAheadJournal(StorageEnvironment env) { _env = env; _dataPager = _env.Options.DataPager; _currentJournalFileSize = env.Options.InitialLogFileSize; _headerAccessor = env.HeaderAccessor; _updateLogInfo = header => { var journalFilesCount = _files.Count; header->Journal.CurrentJournal = journalFilesCount > 0 ? _journalIndex : -1; header->Journal.JournalFilesCount = journalFilesCount; header->IncrementalBackup.LastCreatedJournal = _journalIndex; }; _compressionPager = _env.Options.CreateScratchPager("compression.buffers"); _journalApplicator = new JournalApplicator(this); }
/// <summary> /// Class constructor /// </summary> /// <param name="filePath">Path of document to load</param> /// <param name="createNew">Whether create a new document or load contents from existing one</param> public PTWordprocessingDocument(string filePath, bool createNew) : base() { try { if (createNew) { Document = OpenXmlSDK.WordprocessingDocument.Create(filePath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document); } else { Document = OpenXmlSDK.WordprocessingDocument.Open(filePath, true); } FullName = filePath; InnerContent = new WordprocessingDocumentManager(this); Comments = new CommentAccessor(this); Changes = new ChangeAccessor(this); Headers = new HeaderAccessor(this); Footer = new FooterAccessor(this); Setting = new SettingAccessor(this); CustomXml = new CustomXmlAccessor(this); Background = new BackgroundAccessor(this); Style = new StyleAccessor(this); Format = new ContentFormatAccessor(this); Picture = new PictureAccessor(this); Watermark = new WatermarkAccesor(this); Theme = new ThemeAccessor(this); TOC = new TOCAccessor(this); TOF = new TOFAccessor(this); TOA = new TOAAccessor(this); Index = new IndexAccessor(this); } catch (OpenXmlSDK.OpenXmlPackageException ope) { throw new Exception("Bad formed OpenXml package", ope); } catch (FileFormatException ffe) { throw new Exception("File contains corrupted data", ffe); } catch (Exception) { throw; } }
public override unsafe bool ReadHeader(string filename, FileHeader *header) { var path = _basePath.Combine(filename); if (File.Exists(path.FullPath) == false) { return(false); } var success = RunningOnPosix ? PosixHelper.TryReadFileHeader(header, path) : Win32Helper.TryReadFileHeader(header, path); if (!success) { return(false); } return(header->Hash == HeaderAccessor.CalculateFileHeaderHash(header)); }
public unsafe StorageEnvironment(StorageEnvironmentOptions options) { try { TemporaryPage = new TemporaryPage(); _options = options; _dataPager = options.DataPager; _freeSpaceHandling = new FreeSpaceHandling(this); _sliceComparer = NativeMethods.memcmp; _headerAccessor = new HeaderAccessor(this); var isNew = _headerAccessor.Initialize(); _scratchBufferPool = new ScratchBufferPool(this); _journal = new WriteAheadJournal(this); if (isNew) { CreateNewDatabase(); } else // existing db, let us load it { LoadExistingDatabase(); } State.FreeSpaceRoot.Name = Constants.FreeSpaceTreeName; State.Root.Name = Constants.RootTreeName; Writer = new TransactionMergingWriter(this); if (_options.ManualFlushing == false) { _flushingTask = FlushWritesToDataFileAsync(); } } catch (Exception) { Dispose(); throw; } }
/// <summary> /// WordprocessingDocument (Constructor) /// </summary> public PTWordprocessingDocument() : base() { memoryStream = new MemoryStream(); Document = OpenXmlSDK.WordprocessingDocument.Create(memoryStream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document); InnerContent = new WordprocessingDocumentManager(this); Comments = new CommentAccessor(this); Changes = new ChangeAccessor(this); Headers = new HeaderAccessor(this); Footer = new FooterAccessor(this); Setting = new SettingAccessor(this); CustomXml = new CustomXmlAccessor(this); Background = new BackgroundAccessor(this); Style = new StyleAccessor(this); Format = new ContentFormatAccessor(this); Picture = new PictureAccessor(this); Watermark = new WatermarkAccesor(this); Theme = new ThemeAccessor(this); TOC = new TOCAccessor(this); TOF = new TOFAccessor(this); }
public StorageEnvironment(StorageEnvironmentOptions options) { try { _options = options; _dataPager = options.DataPager; _freeSpaceHandling = new FreeSpaceHandling(); _headerAccessor = new HeaderAccessor(this); var isNew = _headerAccessor.Initialize(); _scratchBufferPool = new ScratchBufferPool(this); _journal = new WriteAheadJournal(this); if (isNew) { CreateNewDatabase(); } else // existing db, let us load it { LoadExistingDatabase(); } Writer = new TransactionMergingWriter(this, _cancellationTokenSource.Token); if (_options.ManualFlushing == false) { _flushingTask = FlushWritesToDataFileAsync(); } } catch (Exception) { Dispose(); throw; } }
public unsafe bool Update(int currentVersion, StorageEnvironmentOptions options, HeaderAccessor headerAccessor, out int versionAfterUpgrade) { headerAccessor.Modify(header => { Memory.Set(header->Journal.Reserved, 0, JournalInfo.NumberOfReservedBytes); if (options.JournalExists(header->Journal.LastSyncedJournal)) { header->Journal.Flags = JournalInfoFlags.None; } else { header->Journal.Flags = JournalInfoFlags.IgnoreMissingLastSyncJournal; } }); versionAfterUpgrade = 23; return(true); }
public VoronSchemaUpdater(HeaderAccessor headerAccessor, StorageEnvironmentOptions options) { _headerAccessor = headerAccessor; _options = options; }