private void ImportDatapool( IWriteSession session, IProjectContext projectContext, IList <JsonDpItem> dpItems, INamespace @namespace) { CheckForDuplicates("datapool items", dpItems.Select(i => i.Name).ToList()); foreach (var dp in dpItems) { var type = TryGetDpItemType(projectContext, dp.Type); if (type == null) { _importProblems.Add($"Invalid type '{dp.Type}' for a datapool item with name '{dp.Name}'"); continue; } var dpItemName = !string.IsNullOrWhiteSpace(dp.Name) ? dp.Name : null; var dpItem = _datapoolService.CreateDatapoolItem(session, projectContext, @namespace, type, dpItemName); var value = ConvertValue(dp.Value, type.BaseType); value.Match( val => SetDpItemValue(session, dpItem, val), errors => _importProblems.Add($"Invalid value '{dp.Value}' for a datapool item with name '{dp.Name}'")); } }
public IAnnotationData SetAnnotation(IWriteSession session, IProjectContext projectContext, IModelElement element, string annotation) { var pluginData = GetPluginData(projectContext); if (pluginData == null) { pluginData = new AnnotationPluginData(); _pluginDataService.SetPluginData(session, projectContext, PLUGIN_ID, pluginData); } var annotationData = GetAnnotationData(projectContext, element); if (annotationData == null) { annotationData = new AnnotationData { Element = element, Annotation = annotation }; pluginData.Annotations.Add(annotationData); session.Save(pluginData); } else { annotationData.Annotation = annotation; } session.Save(annotationData); return(annotationData); }
private void AddModelNamespace(IWriteSession session, IProjectContext projectContext, INamespace @namespace) { var rootNamespace = projectContext.Project.RootNamespace; rootNamespace.Namespaces.Add(@namespace); session.Save(rootNamespace); session.SaveHierarchy(@namespace); }
public void Delete( IWriteSession session, IProjectContext projectContext, IReadOnlyCollection <IModelElement> deletedElements) { foreach (var element in deletedElements) { _annotationService.Value.DeleteAnnotation(session, projectContext, element); } }
public void DeleteAnnotation(IWriteSession session, IProjectContext projectContext, IModelElement element) { var annotationData = GetAnnotationData(projectContext, element); if (annotationData == null) { return; } _modelElementService.DeleteElements(session, projectContext, annotationData); }
private void ImportEvents( IWriteSession session, IProjectContext projectContext, IList <JsonEvent> events, INamespace @namespace) { var existingEvents = projectContext.Project.GetAllEvents().ToList(); CheckForDuplicates("events", events.Select(e => e.Name).ToList()); foreach (var evt in events) { var eventName = !string.IsNullOrWhiteSpace(evt.Name) ? evt.Name : null; var @event = _eventService.CreateEvent(session, projectContext, @namespace, eventName); var eventGroup = projectContext.Project.EventGroups.Items.FirstOrDefault(i => i.Name == evt.EventGroup) ?? projectContext.Project.EventGroups.Items.FirstOrDefault(); if ([email protected](eventGroup)) { _eventService.SetEventGroup(session, @event, eventGroup); } if (@namespace.Events.Items.GroupBy(e => e.EventId).Any(id => id.Count() > 1)) { _eventService.SetEventId(session, @event, existingEvents.FindFreeEventId()); } if (evt.Parameters != null) { CheckForDuplicates("event parameters", evt.Parameters.Select(p => p.Name).ToList()); foreach (var param in evt.Parameters) { var paramType = projectContext.TypeManager.FindType(param.Type); if (paramType == null) { _importProblems.Add($"Invalid parameter type '{param.Type}' for a parameter with name " + $"'{param.Name}' in event '{evt.Name}'"); continue; } var parameter = _eventService.AddParameter(session, projectContext, @event, paramType); if (!string.IsNullOrWhiteSpace(param.Name)) { SetParameterName(session, @event, parameter, param.Name); } } } existingEvents.Add(@event); } }
public void Write(DocumentTableRow document, IWriteSession session) { var analyzedTerms = _analyzer.AnalyzeDocument(document); foreach (var term in analyzedTerms) { _treeBuilder.Add(term.Field, term.Value, term); } session.Write(document); Log.DebugFormat("analyzed doc ID {0}", document.TableId); }
public DocumentUpsertTransaction( string directory, Compression compression, DocumentStream documents, IWriteSessionFactory writeSessionFactory = null, IDocumentWriteCommand documentWriteCommand = null) : this(directory, documents) { var factory = writeSessionFactory ?? new WriteSessionFactory(directory); WriteSession = factory.OpenWriteSession(compression); DocumentWriteCommand = documentWriteCommand ?? new DocumentWriteCommand(); }
public ExtensionContext(IWriteSession session, IAnchor anchor, IStorageEngine engine) { Session = session; Anchor = anchor; Engine = engine; }
public UpsertTransaction( string directory, IAnalyzer analyzer, Compression compression, DocumentStream documents, IWriteSessionFactory storeWriterFactory = null) { long version = Util.GetNextChronologicalFileId(); Log.InfoFormat("begin writing {0}", version); FileStream lockFile; if (!Util.TryAquireWriteLock(directory, out lockFile)) { var compoundFileName = Path.Combine(directory, version + ".rdb"); _compoundFile = new FileStream( compoundFileName, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite, 4096 ); } else { var ixFileName = Util.GetIndexFileNamesInChronologicalOrder(directory).FirstOrDefault(); long dataFileVersion; if (ixFileName == null) { dataFileVersion = version; } else { dataFileVersion = long.Parse(Path.GetFileNameWithoutExtension(ixFileName)); } var compoundFileName = Path.Combine(directory, dataFileVersion + ".rdb"); _compoundFile = new FileStream( compoundFileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite, 4096 ); _lockFile = lockFile; } _directory = directory; _analyzer = analyzer; _documents = documents; _ix = new BatchInfo { VersionId = version, Compression = compression, PrimaryKeyFieldName = documents.PrimaryKeyFieldName }; var posFileName = Path.Combine( _directory, string.Format("{0}.{1}", _ix.VersionId, "pos")); var factory = storeWriterFactory ?? new WriteSessionFactory(directory, _ix); _writeSession = factory.OpenWriteSession(_compoundFile); _postingsWriter = new PostingsWriter( new FileStream( posFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.DeleteOnClose )); }
public DocumentUpsertCommand(IWriteSession writeSession, IAnalyzer analyzer, TrieBuilder treeBuilder) { _writeSession = writeSession; _analyzer = analyzer; _treeBuilder = treeBuilder; }
public void Write(DocumentTableRow document, IWriteSession session) { session.Write(document); Log.DebugFormat("stored doc ID {0}", document.TableId); }
private void SetParameterName(IWriteSession session, IEvent @event, IEventParameter parameter, string name) { parameter.Name = name; session.SaveHierarchy(@event); }
private void SetDpItemValue(IWriteSession session, IDpItem dpItem, ModelValue value) { dpItem.Value = value; session.SaveHierarchy(dpItem); }