public ProcessedTokensDocument(TokensDocument previousStepSnapshot, DocumentVersion <IProcessedTokensLine> processedTokensLinesVersion, ISearchableReadOnlyList <IProcessedTokensLine> processedTokensLines) { TextSourceInfo = previousStepSnapshot.TextSourceInfo; PreviousStepSnapshot = previousStepSnapshot; CurrentVersion = processedTokensLinesVersion; Lines = processedTokensLines; }
public Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { UIApplication uiapp = revit.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; string path = doc.PathName; BasicFileInfo info = BasicFileInfo.Extract( path); DocumentVersion v = info.GetDocumentVersion(); int n = v.NumberOfSaves; Util.InfoMsg(string.Format( "Document '{0}' has GUID {1} and {2} save{3}.", path, v.VersionGUID, n, Util.PluralSuffix(n))); return(Result.Succeeded); }
public CompilationDocument(TextSourceInfo textSourceInfo, IEnumerable <ITextLine> initialTextLines, TypeCobolOptions compilerOptions, IProcessedTokensDocumentProvider processedTokensDocumentProvider, [CanBeNull] MultilineScanState scanState, List <RemarksDirective.TextNameVariation> copyTextNameVariations) { TextSourceInfo = textSourceInfo; CompilerOptions = compilerOptions; CopyTextNamesVariations = copyTextNameVariations ?? new List <RemarksDirective.TextNameVariation>(); MissingCopies = new List <CopyDirective>(); this.processedTokensDocumentProvider = processedTokensDocumentProvider; // Initialize the compilation document lines compilationDocumentLines = ImmutableList <CodeElementsLine> .Empty.ToBuilder(); // ... with the initial list of text lines received as a parameter if (initialTextLines != null) { // Insert Cobol text lines in the internal tree structure compilationDocumentLines.AddRange(initialTextLines.Select(textLine => CreateNewDocumentLine(textLine, textSourceInfo.ColumnsLayout))); } // Initialize document views versions currentTextLinesVersion = new DocumentVersion <ICobolTextLine>(this); currentTokensLinesVersion = new DocumentVersion <ITokensLine>(this); // Initialize performance stats PerfStatsForText = new PerfStatsForCompilationStep(CompilationStep.Text); PerfStatsForScanner = new PerfStatsForCompilationStep(CompilationStep.Scanner); PerfStatsForPreprocessor = new PerfStatsForParsingStep(CompilationStep.Preprocessor); initialScanStateForCopy = scanState; }
public TokensDocument(TextSourceInfo textSourceInfo, DocumentVersion <ICobolTextLine> textLinesVersion, DocumentVersion <ITokensLine> tokensLinesVersion, ISearchableReadOnlyList <ITokensLine> tokensLines) { TextSourceInfo = textSourceInfo; SourceLinesVersion = textLinesVersion; CurrentVersion = tokensLinesVersion; Lines = tokensLines; }
public async Task <IHttpActionResult> PutDocumentVersion(int id, DocumentVersion documentVersion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != documentVersion.Id) { return(BadRequest()); } db.Entry(documentVersion).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DocumentVersionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public CodeElementsDocument(ProcessedTokensDocument previousStepSnapshot, DocumentVersion <ICodeElementsLine> codeElementsLinesVersion, ISearchableReadOnlyList <ICodeElementsLine> codeElementsLines) { TextSourceInfo = previousStepSnapshot.TextSourceInfo; PreviousStepSnapshot = previousStepSnapshot; CurrentVersion = codeElementsLinesVersion; Lines = codeElementsLines; }
// --- Initialization --- /// <summary> /// Initializes a new compilation document from a list of text lines. /// This method does not scan the inserted text lines to produce tokens. /// You must explicitely call UpdateTokensLines() to start an initial scan of the document. /// </summary> public CompilationDocument(TextSourceInfo textSourceInfo, IEnumerable<ITextLine> initialTextLines, TypeCobolOptions compilerOptions, IProcessedTokensDocumentProvider processedTokensDocumentProvider) { TextSourceInfo = textSourceInfo; CompilerOptions = compilerOptions; this.processedTokensDocumentProvider = processedTokensDocumentProvider; // Initialize the compilation document lines compilationDocumentLines = ImmutableList<CodeElementsLine>.Empty.ToBuilder(); // ... with the initial list of text lines received as a parameter if (initialTextLines != null) { // Insert Cobol text lines in the internal tree structure compilationDocumentLines.AddRange(initialTextLines.Select(textLine => CreateNewDocumentLine(textLine, textSourceInfo.ColumnsLayout))); } // Initialize document views versions currentTextLinesVersion = new DocumentVersion<ICobolTextLine>(this); currentTokensLinesVersion = new DocumentVersion<ITokensLine>(this); // Initialize performance stats PerfStatsForText = new PerfStatsForCompilationStep(CompilationStep.Text); PerfStatsForScanner = new PerfStatsForCompilationStep(CompilationStep.Scanner); PerfStatsForPreprocessor = new PerfStatsForCompilationStep(CompilationStep.Preprocessor); }
internal static void DocumentReceived(Document source) { try { var document = source; document.Crc32 = document.ContentStream.CalculateCrc32(); document.Size = document.ContentStream.Length; var message = document.Message; var root = ClientState.Current.DataService.SelectBy <Document>(new { Crc32 = document.Crc32 }); if (root == null) { document.StreamName = Guid.NewGuid().GetHash(12) + "_" + Path.GetExtension(document.Filename); // Save document to storage engine ClientState.Current.Storage.Write( ".", document.StreamName, document.ContentStream); // New document, save stream and add to search/mailbox ClientState.Current.DataService.Save(document); ClientState.Current.Search.Store(document); } else { // Replace document reference with root to create new version for document = root; } // Create new version var version = new DocumentVersion { DocumentId = document.DocumentId.Value, SourceChannelId = document.SourceChannelId, TargetChannelId = document.TargetChannelId, StreamName = document.StreamName, Filename = document.Filename, DateReceived = document.DateReceived, DateSent = document.DateSent }; if (message != null) { version.From = message.From; version.To = message.To; version.MessageId = message.MessageId; } ClientState.Current.DataService.Save(version); } finally { source.ContentStream.Dispose(); source.ContentStream = null; } }
public static List <VersionChange> GetComparisonToCurrent(this DocumentVersion currentVersion) { var document = currentVersion.Document.Unproxy(); var previousVersion = DeserializeVersion(currentVersion, document); return(GetVersionChanges(document, previousVersion)); }
public void DetermineVersion <TClass>(TClass instance) where TClass : class, IDocument { var type = typeof(TClass); var documentVersion = instance.Version.ToString(); var latestVersion = _migrationLocator.GetLatestVersion(type); var currentVersion = _runtimeVersionLocator.GetLocateOrNull(type) ?? latestVersion; if (documentVersion == currentVersion) { return; } if (documentVersion == latestVersion) { return; } if (DocumentVersion.Default() == documentVersion) { SetVersion(instance, currentVersion, latestVersion); return; } throw new VersionViolationException(currentVersion.ToString(), documentVersion, latestVersion); }
public VersionViolationException( DocumentVersion currentVersion, DocumentVersion documentVersion, DocumentVersion latestVersion) : base(string.Format(ErrorTexts.DuplicateVersion, currentVersion, documentVersion, latestVersion)) { }
private void NextVersionButton_Click(object sender, RoutedEventArgs e) { _goingToAnotherVersion = true; _followingVersion = _document.Versions[_document.Versions.IndexOf(_version) + 1]; Close(); }
public async Task Handle() { // parameters: bucket,folder logger.Info("S3UpdatePlugin.Handle"); var s3VersionId = GetCurrentDocumentVersion(_domain); var document = await _repository.FindById(_domain); if (document == null || document.Version != s3VersionId) { await DownloadFilesForDomain(_domain); var model = new DocumentVersion { DocumentKey = _domain, Version = s3VersionId }; // if there was an existing document, update it's version if (document != null) { await _repository.Update(model); } else { await _repository.Add(model); } // TODO: Notification? } }
private static T DeserializeVersion <T>(DocumentVersion version, T doc) where T : Document { // use null handling ignore so that properties that didn't exist in previous versions are defaulted return(JsonConvert.DeserializeObject(version.Data, doc.GetType(), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }) as T); }
public void If_implicit_version_to_string_Then_cast_should_work() { var version = new DocumentVersion("1.0.2"); string versionString = version; versionString.Should().Be("1.0.2"); }
/// <summary> /// Retrieve the project identification information /// to store in the external database and return it /// as a dictionary in a JSON formatted string. /// </summary> string GetProjectDataJson( //string project_id, Document doc) { string path = doc.PathName.Replace('\\', '/'); BasicFileInfo file_info = BasicFileInfo.Extract(path); DocumentVersion doc_version = file_info.GetDocumentVersion(); ModelPath model_path = doc.GetWorksharingCentralModelPath(); string central_server_path = null != model_path ? model_path.CentralServerPath : string.Empty; // Hand-written JSON formatting. string s = string.Format( //"\"_id\": \"{0}\"," "\"projectinfo_uid\": \"{0}\"," + "\"versionguid\": \"{1}\"," + "\"numberofsaves\": {2}," + "\"title\": \"{3}\"," + "\"centralserverpath\": \"{4}\"," + "\"path\": \"{5}\"," + "\"computername\": \"{6}\"," + "\"jid\": \"{7}\"", //project_id, doc.ProjectInformation.UniqueId, doc_version.VersionGUID, doc_version.NumberOfSaves, doc.Title, central_server_path, path, System.Environment.MachineName, Util.GetProjectIdentifier(doc)); return("{" + s + "}"); #region Use JavaScriptSerializer #if USE_JavaScriptSerializer // Use JavaScriptSerializer to format JSON data. ProjectData project_data = new ProjectData() { projectinfo_uid = doc.ProjectInformation.UniqueId, versionguid = doc_version.VersionGUID.ToString(), numberofsaves = doc_version.NumberOfSaves, title = doc.Title, centralserverpath = central_server_path, path = path, computername = System.Environment.MachineName }; return(new JavaScriptSerializer().Serialize( project_data)); #endif // USE_JavaScriptSerializer #endregion // Use JavaScriptSerializer }
public DocumentVersion DetermineLastVersion(DocumentVersion version, List <IMigration> migrations, int currentMigration) { if (migrations.Last() != migrations[currentMigration]) { return(migrations[currentMigration + 1].Version); } return(version); }
public IEnumerable <TMigrationType> GetMigrationsGtEq(Type type, DocumentVersion version) { var migrations = GetMigrations(type); return (migrations .Where(m => m.Version >= version) .ToList()); }
private void DeletingTheVersion(DocumentVersion version) { _document.Versions.Remove(version); _storage.Documents.Save(); VersionsListBox.ItemsSource = null; VersionsListBox.ItemsSource = _document.Versions; }
public ActionResult ViewChanges(DocumentVersion documentVersion) { if (documentVersion == null) { return(RedirectToAction("Index")); } return(PartialView(documentVersion)); }
public async Task <DocumentVersion> AddNewDocumentVersion(DocumentVersion documentVersion) { return(await Task.Run(() => { documentVersion.Id = documentVersions.Count + 1; documentVersions.Add(documentVersion); return documentVersion; })); }
private void MigrateUp(Type type, BsonDocument document, DocumentVersion version, DocumentVersion toVersion) { var migrations = _migrationLocator.GetMigrationsFromTo(type, version, toVersion).ToList(); foreach (var migration in migrations) { migration.Up(document); _documentVersionService.SetVersion(document, migration.Version); } }
public void DocumentVersionService_GetDocumentVersion_GetsTheVersionWithTheRequestedId() { var documentVersion = new DocumentVersion(); _documentVersionRepository.Add(documentVersion); var version = _documentVersionsAdminService.GetDocumentVersion(documentVersion.Id); version.Should().Be(documentVersion); }
private void MigrateUp(Type type, DocumentVersion version, BsonDocument document) { var migrations = _migrationLocator.GetMigrationsGt(type, version).ToList(); foreach (var migration in migrations) { migration.Up(document); SetVersion(document, migration.Version); } }
public TemporarySemanticDocument(CodeElementsDocument previousSnapShot, DocumentVersion <ICodeElementsLine> codeElementsLinesVersion, ISearchableReadOnlyList <ICodeElementsLine> codeElementsLines, SourceFile root, [NotNull] List <Diagnostic> diagnostics, Dictionary <CodeElement, Node> nodeCodeElementLinkers) { PreviousStepSnapshot = previousSnapShot; Root = root; Diagnostics = diagnostics; NodeCodeElementLinkers = nodeCodeElementLinkers; TextSourceInfo = previousSnapShot.TextSourceInfo; CurrentVersion = codeElementsLinesVersion; Lines = codeElementsLines; }
public void DocumentVersionService_GetDocumentVersion_GetsTheVersionWithTheRequestedId() { var documentVersion = new DocumentVersion(); Session.Transact(session => session.Save(documentVersion)); DocumentVersion version = _documentVersionsAdminService.GetDocumentVersion(documentVersion.Id); version.Should().Be(documentVersion); }
public IEnumerable <TMigrationType> GetMigrationsFromTo(Type type, DocumentVersion version, DocumentVersion otherVersion) { var migrations = GetMigrations(type); return (migrations .Where(m => m.Version > version) .Where(m => m.Version <= otherVersion) .ToList()); }
private static DocumentVersion DetermineDocumentVersion( DocumentVersion version, List <IMigration> migrations, int m) { if (migrations.Last() != migrations[m]) { return(migrations[m + 1].Version); } return(version); }
public DocumentVersion GetLatestVersion(Type type) { var migrations = GetMigrations(type); if (migrations == null || !migrations.Any()) { return(DocumentVersion.Default()); } return(migrations.Max(m => m.Version)); }
public async Task <DocumentVersion> UpdateDocumentVersion(DocumentVersion documentVersion) { return(await Task.Run(() => { var result = documentVersions.SingleOrDefault(dv => dv.Id == documentVersion.Id); var index = documentVersions.IndexOf(result); documentVersions.Remove(result); documentVersions.Insert(index, documentVersion); return documentVersion; })); }
public async Task <IHttpActionResult> GetDocumentVersion(int id) { DocumentVersion documentVersion = await db.DocumentVersions.FindAsync(id); if (documentVersion == null) { return(NotFound()); } return(Ok(documentVersion)); }
/// <summary> /// Update the text lines of the document after a text change event. /// NOT thread-safe : this method can only be called from the owner thread. /// </summary> public void UpdateTextLines(TextChangedEvent textChangedEvent) { // This method can only be called by the document owner thread if (documentOwnerThread == null) { documentOwnerThread = Thread.CurrentThread; } else { VerifyAccess(); } // Make sure we don't update the document while taking a snapshot DocumentChangedEvent<ICobolTextLine> documentChangedEvent = null; lock (lockObjectForDocumentLines) { // Start perf measurement PerfStatsForText.OnStartRefresh(); // Apply text changes to the compilation document IList<DocumentChange<ICobolTextLine>> documentChanges = new List<DocumentChange<ICobolTextLine>>(textChangedEvent.TextChanges.Count); foreach (TextChange textChange in textChangedEvent.TextChanges) { DocumentChange<ICobolTextLine> appliedChange = null; CodeElementsLine newLine = null; switch (textChange.Type) { case TextChangeType.DocumentCleared: compilationDocumentLines.Clear(); appliedChange = new DocumentChange<ICobolTextLine>(DocumentChangeType.DocumentCleared, 0, null); // Ignore all previous document changes : they are meaningless now that the document was completely cleared documentChanges.Clear(); break; case TextChangeType.LineInserted: newLine = CreateNewDocumentLine(textChange.NewLine, TextSourceInfo.ColumnsLayout); compilationDocumentLines.Insert(textChange.LineIndex, newLine); appliedChange = new DocumentChange<ICobolTextLine>(DocumentChangeType.LineInserted, textChange.LineIndex, newLine); // Recompute the line indexes of all the changes prevously applied foreach (DocumentChange<ICobolTextLine> documentChangeToAdjust in documentChanges) { if(documentChangeToAdjust.LineIndex >= textChange.LineIndex) { documentChangeToAdjust.LineIndex = documentChangeToAdjust.LineIndex + 1; } } break; case TextChangeType.LineUpdated: newLine = CreateNewDocumentLine(textChange.NewLine, TextSourceInfo.ColumnsLayout); compilationDocumentLines[textChange.LineIndex] = newLine; // Check to see if this change can be merged with a previous one bool changeAlreadyApplied = false; foreach (DocumentChange<ICobolTextLine> documentChangeToAdjust in documentChanges) { if (documentChangeToAdjust.LineIndex == textChange.LineIndex) { changeAlreadyApplied = true; break; } } if (!changeAlreadyApplied) { appliedChange = new DocumentChange<ICobolTextLine>(DocumentChangeType.LineUpdated, textChange.LineIndex, newLine); } // Line indexes are not impacted break; case TextChangeType.LineRemoved: compilationDocumentLines.RemoveAt(textChange.LineIndex); appliedChange = new DocumentChange<ICobolTextLine>(DocumentChangeType.LineRemoved, textChange.LineIndex, null); // Recompute the line indexes of all the changes prevously applied IList<DocumentChange<ICobolTextLine>> documentChangesToRemove = null; foreach (DocumentChange<ICobolTextLine> documentChangeToAdjust in documentChanges) { if (documentChangeToAdjust.LineIndex > textChange.LineIndex) { documentChangeToAdjust.LineIndex = documentChangeToAdjust.LineIndex - 1; } else if(documentChangeToAdjust.LineIndex == textChange.LineIndex) { if(documentChangesToRemove == null) { documentChangesToRemove = new List<DocumentChange<ICobolTextLine>>(1); } documentChangesToRemove.Add(documentChangeToAdjust); } } // Ignore all previous changes applied to a line now removed if(documentChangesToRemove != null) { foreach (DocumentChange<ICobolTextLine> documentChangeToRemove in documentChangesToRemove) { documentChanges.Remove(documentChangeToRemove); } } break; } if (appliedChange != null) { documentChanges.Add(appliedChange); } } // Create a new version of the document to track these changes currentTextLinesVersion.changes = documentChanges; currentTextLinesVersion.next = new DocumentVersion<ICobolTextLine>(currentTextLinesVersion); // Prepare an event to signal document change to all listeners documentChangedEvent = new DocumentChangedEvent<ICobolTextLine>(currentTextLinesVersion, currentTextLinesVersion.next); currentTextLinesVersion = currentTextLinesVersion.next; // Stop perf measurement PerfStatsForText.OnStopRefresh(); } // Send events to all listeners EventHandler<DocumentChangedEvent<ICobolTextLine>> textLinesChanged = TextLinesChanged; // avoid race condition if (textLinesChanged != null) { textLinesChanged(this, documentChangedEvent); } }
/// <summary> /// Update the tokens lines of the document if the text lines changed since the last time this method was called. /// NOT thread-safe : this method can only be called from the owner thread. /// </summary> public void UpdateTokensLines() { // This method can only be called by the document owner thread if (documentOwnerThread == null) { documentOwnerThread = Thread.CurrentThread; } else { VerifyAccess(); } // Check if an update is necessary and compute changes to apply since last version bool scanAllDocumentLines = false; IList<DocumentChange<ICobolTextLine>> textLineChanges = null; if(textLinesVersionForCurrentTokensLines == null) { scanAllDocumentLines = true; } else if(currentTextLinesVersion == textLinesVersionForCurrentTokensLines) { // Text lines did not change since last update => nothing to do return; } else { textLineChanges = textLinesVersionForCurrentTokensLines.GetReducedAndOrderedChangesInNewerVersion(currentTextLinesVersion); } // Make sure we don't update the document while taking a snapshot DocumentChangedEvent<ITokensLine> documentChangedEvent = null; lock (lockObjectForDocumentLines) { // Start perf measurement PerfStatsForScanner.OnStartRefresh(); // Apply text changes to the compilation document if (scanAllDocumentLines) { ScannerStep.ScanDocument(TextSourceInfo, compilationDocumentLines, CompilerOptions); } else { IList<DocumentChange<ITokensLine>> documentChanges = ScannerStep.ScanTextLinesChanges(TextSourceInfo, compilationDocumentLines, textLineChanges, PrepareDocumentLineForUpdate, CompilerOptions); // Create a new version of the document to track these changes currentTokensLinesVersion.changes = documentChanges; currentTokensLinesVersion.next = new DocumentVersion<ITokensLine>(currentTokensLinesVersion); // Prepare an event to signal document change to all listeners documentChangedEvent = new DocumentChangedEvent<ITokensLine>(currentTokensLinesVersion, currentTokensLinesVersion.next); currentTokensLinesVersion = currentTokensLinesVersion.next; } // Register that the tokens lines were synchronized with the current text lines version textLinesVersionForCurrentTokensLines = currentTextLinesVersion; // Stop perf measurement PerfStatsForScanner.OnStopRefresh(); } // Send events to all listeners EventHandler<DocumentChangedEvent<ITokensLine>> tokensLinesChanged = TokensLinesChanged; // avoid race condition if (documentChangedEvent != null && tokensLinesChanged != null) { tokensLinesChanged(this, documentChangedEvent); } }
public void AddToDocumentVersions(DocumentVersion documentVersion) { base.AddObject("DocumentVersions", documentVersion); }
public static DocumentVersion CreateDocumentVersion(int ID, int documentVersion_Document, int documentVersion_Employee, int majorVersionNumber, int minorVersionNumber, string changes, global::System.DateTime effectiveDate, string documentStatus, byte[] rowVersion) { DocumentVersion documentVersion = new DocumentVersion(); documentVersion.Id = ID; documentVersion.DocumentVersion_Document = documentVersion_Document; documentVersion.DocumentVersion_Employee = documentVersion_Employee; documentVersion.MajorVersionNumber = majorVersionNumber; documentVersion.MinorVersionNumber = minorVersionNumber; documentVersion.Changes = changes; documentVersion.EffectiveDate = effectiveDate; documentVersion.DocumentStatus = documentStatus; documentVersion.RowVersion = rowVersion; return documentVersion; }