public static Type FindDataSourceAndCheckPermissions( this IDomainModel DomainModel, IPermissionManager Permissions, IPrincipal principal, string domainName) { if (string.IsNullOrEmpty(domainName)) { throw new ArgumentException("Domain object name not provided."); } var domainObjectType = DomainModel.Find(domainName); if (domainObjectType == null) { throw new ArgumentException("Couldn't find domain object: {0}".With(domainName)); } if (!typeof(IDataSource).IsAssignableFrom(domainObjectType)) { throw new ArgumentException(@"Specified type ({0}) is not a data source. Please check your arguments.".With(domainName)); } if (!Permissions.CanAccess(domainObjectType.FullName, principal)) { throw new SecurityException("You don't have permission to access: {0}.".With(domainName)); } return(domainObjectType); }
private bool HandleEvent(Type eventType, IEvent @event) { Contract.Requires(eventType, "eventType"); Contract.Requires(@event, "@event"); List <HandlerInfo> handlers; if (!_handlersByEventType.TryGetValue(eventType, out handlers)) { return(false); } IDomainModel targetDomainModel = _store.GetDomainModel(@event.Domain); if (targetDomainModel == null) { return(false); } foreach (var info in handlers) { if ((info.DomainModelName == null || String.Compare(info.DomainModelName, targetDomainModel.Name, StringComparison.OrdinalIgnoreCase) == 0)) { var commands = info.Handler(targetDomainModel, @event); Session.Current.Execute(commands.ToArray()); } } return(handlers.Count > 0); }
// 1 -> 2 -> 4 -> 6 -> 7 // -> 5 // -> 3 -> 7 // -> 3 -> 7 protected void CreateGraph(IDomainModel domain, Action settings = null) { var graph = domain.Resolve <IHyperGraph>(); var ids = new Identity[8]; var mid = domain.Store.GetSchemaEntity <XExtendsBaseClass>(); using (var session = domain.Store.BeginSession()) { for (int i = 1; i <= 7; i++) { ids[i] = Id(i); graph.CreateEntity(ids[i], mid); } var cx = 8; var rid = domain.Store.GetSchemaRelationship <XReferencesX>(); graph.CreateRelationship(Id(cx++), rid, ids[1], ids[2]); graph.CreateRelationship(Id(cx++), rid, ids[1], ids[3]); graph.CreateRelationship(Id(cx++), rid, ids[2], ids[4]); graph.CreateRelationship(Id(cx++), rid, ids[2], ids[5]); graph.CreateRelationship(Id(cx++), rid, ids[2], ids[3]); graph.CreateRelationship(Id(cx++), rid, ids[4], ids[6]); graph.CreateRelationship(Id(cx++), rid, ids[6], ids[7]); graph.CreateRelationship(Id(cx++), rid, ids[3], ids[7]); session.AcceptChanges(); } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Unload a domain or an extension. /// </summary> /// <param name="models"> /// The models to act on. /// </param> /// <param name="scope"> /// domain or extension to unload. /// </param> ///------------------------------------------------------------------------------------------------- public static void Unload(this IModelList <IDomainModel> models, IDomainModel scope) { Contract.Requires(scope, "scope"); var store = models.Store as IDomainManager; store.UnloadDomainOrExtension(scope); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Deserialize a domain in xml /// </summary> /// <param name="stream"> /// The stream. /// </param> /// <param name="domain"> /// The domain. /// </param> /// <param name="settings"> /// Options for controlling the operation. /// </param> ///------------------------------------------------------------------------------------------------- public static void Deserialize(Stream stream, IDomainModel domain, XmlDeserializationSettings settings = null) { Contract.Requires(domain, "domain"); var ser = new XmlDeserializer(domain, settings); ser.Deserialize(stream); }
protected override void Initialize(ISchemaElement metadata, IDomainModel domainModel) { base.Initialize(metadata, domainModel); var observable = metadata.Schema.Behavior == DomainBehavior.Observable; _customers = observable ? (ICollection <Customer>) new ObservableModelElementCollection <Customer>(this, "CustomerReferencesProducts", true) : (ICollection <Customer>) new ModelElementCollection <Customer>(this, "CustomerReferencesProducts", true); }
private GraphPath(GraphPath parent, Identity node, EdgeInfo fromEdge) { DomainModel = parent.DomainModel; _parent = parent; EndElement = node; LastTraversedRelationship = fromEdge; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="AddRelationshipCommand" /> class. /// </summary> ///------------------------------------------------------------------------------------------------- public AddRelationshipCommand(ISchemaRelationship relationshipSchema, IModelElement start, Identity endId, Identity id = null, long?version = null) : base(start.DomainModel, version) { Contract.Requires(start, "start"); Contract.Requires(endId, "endId"); Contract.Requires(endId, "endId"); Contract.Requires(relationshipSchema, "relationshipSchema"); Start = start; EndId = endId; _domainModel = start.DomainModel; Id = id ?? DomainModel.IdGenerator.NextValue(relationshipSchema); if (String.Compare(Id.DomainModelName, start.DomainModel.Name, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidIdException("The id must be an id of the specified domain model."); } if (relationshipSchema.IsEmbedded && start.Id == endId) { throw new CircularReferenceException("An element can not contain itself."); } SchemaRelationship = relationshipSchema; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Méthode permettant de déplacer l'appel du constructeur dans les classes d'héritage. /// </summary> /// <exception cref="SessionRequiredException"> /// Thrown when a Session Required error condition occurs. /// </exception> /// <param name="domainModel"> /// . /// </param> /// <param name="schemaElement"> /// . /// </param> /// <param name="commandFactory"> /// . /// </param> /// <param name="id"> /// (Optional) /// </param> ///------------------------------------------------------------------------------------------------- protected virtual void Super(IDomainModel domainModel, ISchemaElement schemaElement, Func <IDomainModel, Identity, ISchemaElement, IDomainCommand> commandFactory, Identity id = null) { Contract.Requires(domainModel, "domainModel"); Contract.Requires(commandFactory, "commandFactory"); if (Session.Current == null) { throw new SessionRequiredException(); } if (schemaElement == null) { schemaElement = EnsuresSchemaExists(domainModel, GetType().FullName); } if (id == null) { id = domainModel.IdGenerator.NextValue(schemaElement); } _id = id; Initialize(schemaElement, domainModel); PersistElement(commandFactory); }
internal GraphPath(IDomainModel domain, Identity node) { DebugContract.Requires(node, "node"); DomainModel = domain; EndElement = node; }
protected void Configure(IDomainModel domainModel) { DebugContract.Requires(domainModel); if (_domainModel != null) { return; } _trace = domainModel.Resolve <IHyperstoreTrace>(false) ?? new EmptyHyperstoreTrace(); _domainModel = domainModel; var kv = _services.Resolve <IKeyValueStore>() ?? new Hyperstore.Modeling.MemoryStore.TransactionalMemoryStore(domainModel); _storage = kv; if (kv is IDomainService) { ((IDomainService)kv).SetDomain(domainModel); } _indexManager = new Hyperstore.Modeling.HyperGraph.Index.MemoryIndexManager(this); // TODO lier avec TransactionalMemoryStore _loader = _services.Resolve <IGraphAdapter>(); if (_loader is IDomainService) { ((IDomainService)_loader).SetDomain(domainModel); } _lazyLoader = _loader as ISupportsLazyLoading; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Constructeur. Si la clé est à null, une clé est générée automatiquement. Si le metadata est /// Empty, un nouvel metadata est créé automatiquement. /// </summary> /// <exception cref="SessionRequiredException"> /// Thrown when a Session Required error condition occurs. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when one or more arguments have unsupported or illegal values. /// </exception> /// <exception cref="TypeMismatchException"> /// Thrown when a Type Mismatch error condition occurs. /// </exception> /// <param name="schemaName"> /// Name of the schema. /// </param> /// <param name="domainModel"> /// (Optional) Domain model auquel appartient l'élément. /// </param> ///------------------------------------------------------------------------------------------------- protected ModelEntity(string schemaName, IDomainModel domainModel = null) { Contract.RequiresNotEmpty(schemaName, "schemaName"); if (Session.Current == null) { throw new SessionRequiredException(); } if (domainModel == null) { domainModel = Session.Current.DefaultDomainModel; if (domainModel == null) { throw new ArgumentException("domainModel"); } } var metadata = EnsuresSchemaExists(domainModel, schemaName) as ISchemaEntity; Super(domainModel, metadata, (dm, melId, mid) => new AddEntityCommand(this)); if (((IModelEntity)this).SchemaEntity == null) { throw new TypeMismatchException(ExceptionMessages.SchemaMismatch); } }
public JsonWriter(SerializationOptions options, IDomainModel domain) { this._options = options; _stream = new StringWriter(); _firstScope = true; _domain = domain; }
private async Task InitializeCollaborativeMode(IDomainModel domain) { // Configure a bidirectionnel communication for this domain store.EventBus.RegisterDomainPolicies(domain, new Modeling.Messaging.ChannelPolicy(EventPropagationStrategy.All), new Modeling.Messaging.ChannelPolicy(EventPropagationStrategy.All)); // Open a peer to peer channel await store.EventBus.OpenAsync(new Hyperstore.Modeling.Messaging.PeerToPeerPChannel(new Uri("net.p2p://localhost/Library"))); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Méthode appelée dans le processus de création que celle ci soit faite par new ou par /// sérialisation. /// </summary> /// <param name="schemaElement"> /// The metadata. /// </param> /// <param name="domainModel"> /// The domain model. /// </param> ///------------------------------------------------------------------------------------------------- protected override void Initialize(ISchemaElement schemaElement, IDomainModel domainModel) { base.Initialize(schemaElement, domainModel); _superClassHandler = new ReferenceHandler(this, domainModel.Store.PrimitivesSchema.SchemaElementReferencesSuperElementSchema); _properties = new ModelElementCollection <ISchemaProperty>(this, domainModel.Store.PrimitivesSchema.SchemaElementHasPropertiesSchema); _propertiesByName = PlatformServices.Current.CreateConcurrentDictionary <string, ISchemaProperty>(); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Initialisation du service avec le domaine associé. Cette méthode est appelée quand le service /// est instancié par le domaine. /// </summary> /// <param name="domainModel"> /// The domain model. /// </param> ///------------------------------------------------------------------------------------------------- public void SetDomain(IDomainModel domainModel) { DebugContract.Requires(domainModel, "domainModel"); _domainModel = domainModel; //// Création d'un dispatcher //this._eventDispatcher = new EventDispatcher(domainModel.Store, domainModel, false); }
public ActionResult GradeTrackerError(IDomainModel errorModel, IViewModel viewModel) { var errorViewModel = new GradeTrackerErrorViewModel((ErrorDomainModel)errorModel); errorViewModel.ViewModel = viewModel; return(View("GradeTrackerError", errorViewModel)); }
protected override void Initialize(ISchemaElement metadata, IDomainModel domainModel) { base.Initialize(metadata, domainModel); var observable = metadata.Schema.Behavior == DomainBehavior.Observable; _products = observable ? (ICollection <Product>) new ObservableModelElementCollection <Product>(this, "CustomerReferencesProducts") : (ICollection <Product>) new ModelElementCollection <Product>(this, "CustomerReferencesProducts"); _products2 = observable ? new ObservableModelElementList <Product>(this, "CustomerReferencesProducts") : new ModelElementList <Product>(this, "CustomerReferencesProducts"); ((ModelElementList <Product>)_products2).WhereClause = item => item.Name.EndsWith("0"); }
public static bool IsAliasOf(this IDomainModel instance, string alias) { var attrType = instance.GetType(); var attr = (DocumentTypeAliasAttribute)attrType.GetCustomAttributes(typeof(DocumentTypeAliasAttribute), false).FirstOrDefault(); bool isAlias = attr != null?attr.Name.Equals(alias, StringComparison.CurrentCultureIgnoreCase) : false; return(isAlias); }
public QueueEvent( IDomainModel domainModel, IPermissionManager permissions, IDataContext dataContext) { this.DomainModel = domainModel; this.Permissions = permissions; this.DataContext = dataContext; }
private HyperstoreSerializer(IDomainModel domain, SerializationSettings settings) { Contract.Requires(domain, "domain"); _domain = domain; _options = settings.Options; _schema = settings.Schema; _serializer = settings.Serializer; _writer = HasOption(SerializationOptions.Json) ? (ISerializerWriter) new JsonWriter(_options, domain) : new XmlWriter(_options, domain); }
public static string GetAliasName(this IDomainModel instance) { var attrType = instance.GetType(); var attr = (DocumentTypeAliasAttribute)attrType.GetCustomAttributes(typeof(DocumentTypeAliasAttribute), false).FirstOrDefault(); string alias = attr?.Name; return(alias); }
public CachingCrudCommands( IDomainModel domainModel, CrudCommands crudCommands, IServiceLocator locator) { this.DomainModel = domainModel; this.CrudComands = crudCommands; this.Locator = locator; }
public CachingCrudCommands( IDomainModel domainModel, CrudCommands crudCommands, IServiceProvider locator) { this.DomainModel = domainModel; this.CrudComands = crudCommands; this.Locator = locator; }
public static void CheckIdentifiable(IDomainModel domainModel, string name) { var type = CheckDomainObject(domainModel, name); if (!typeof(IIdentifiable).IsAssignableFrom(type)) { Utility.ThrowError("{0} doesn't have URI".With(name), HttpStatusCode.BadRequest); } }
public QueueAggregateEvent( IDomainModel domainModel, IPermissionManager permissions) { Contract.Requires(domainModel != null); Contract.Requires(permissions != null); this.DomainModel = domainModel; this.Permissions = permissions; }
public static Either <Type> CheckDomainEvent(IDomainModel domainModel, string name) { var type = CheckDomainObject(domainModel, name); if (type.IsSuccess && !typeof(IDomainEvent).IsAssignableFrom(type.Result)) { return(name + " is not a domain event"); } return(type); }
public AnalyzeOlapCube( IDomainModel domainModel, IPermissionManager permissions) { Contract.Requires(domainModel != null); Contract.Requires(permissions != null); this.DomainModel = domainModel; this.Permissions = permissions; }
public static Either <Type> CheckDomainObject(IDomainModel domainModel, string name) { var type = domainModel.Find(name); if (type == null) { return("Can't find domain object: " + name); } return(type); }
public static Either <Type> CheckIdentifiable(IDomainModel domainModel, string name) { var type = CheckDomainObject(domainModel, name); if (type.IsSuccess && !typeof(IIdentifiable).IsAssignableFrom(type.Result)) { return(name + " doesn't have URI"); } return(type); }
public EvaluateQuery( IDomainModel domainModel, IPermissionManager permissions) { Contract.Requires(domainModel != null); Contract.Requires(permissions != null); this.DomainModel = domainModel; this.Permissions = permissions; }
public CrudCommands( IServiceProvider locator, ICommandConverter converter, IDomainModel domainModel, IWireSerialization serialization) { this.Locator = locator; this.Converter = converter; this.DomainModel = domainModel; this.Serialization = serialization; }
public CachingDomainCommands( IDomainModel domainModel, DomainCommands domainCommands, IServiceLocator locator, IWireSerialization serialization) { this.DomainModel = domainModel; this.DomainCommands = domainCommands; this.Locator = locator; this.Serialization = serialization; }
public DomainCommands( IServiceLocator locator, ICommandConverter converter, IProcessingEngine processing, IDomainModel domainModel, IWireSerialization serialization) { this.Locator = locator; this.Converter = converter; this.Processing = processing; this.DomainModel = domainModel; this.Serialization = serialization; }
/// <summary> /// Constructor /// </summary> /// <param name="treeModel"></param> /// <param name="typeSystem"></param> public DomainModelContext(IDomainModel treeModel, TypeSystem.TypeSystem typeSystem) { _treeModel = treeModel; _typeSystem = typeSystem; _typeDomainFactory = new TypeDomainFactory(_typeSystem); }
private void PopulateLibraryDomain(IDomainModel domain) { // All changes must be include in a session using (var session = store.BeginSession()) { // Forcing the id is optional by necessary for the synchronization sample Library = new Library(id:domain.CreateId("0")); // Force an unique id Library.Name = "The shop around the corner"; session.AcceptChanges(); } // Add some books Parallel.For(0, 10, i => { using (var session = store.BeginSession()) { var book = new Book(id: domain.CreateId("B" + i.ToString())); book.Copies = i + 1; book.Author = "Author " + i.ToString(); book.Title = "Book " + i.ToString(); Library.Books.Add(book); session.AcceptChanges(); } }); // And some members Parallel.For(0, 10, i => { using (var session = store.BeginSession()) { var member = new Member(id: domain.CreateId("M" + i.ToString())); member.Name = "Member " + i.ToString(); Library.Members.Add(member); session.AcceptChanges(); } }); }
/// <summary> /// Merge the template text with an <see cref="IDomainModel"/> and /// other optional context values. /// </summary> /// <param name="model">An <see cref="IDomainModel"/> instance</param> /// <param name="context">A <see cref="System.Collections.Hashtable"/> containing context values</param> /// <returns></returns> public string Merge(IDomainModel model, Hashtable context) { Hashtable velocitycontext = new Hashtable(); context = context == null ? new Hashtable() : context; velocitycontext["model"] = model; velocitycontext["context"] = context; velocitycontext["ctx"] = context; velocitycontext["emptyline"] = " "; return Services.NVelocityService.MergeTemplate( new System.IO.StreamReader(GetTemplateStream()), velocitycontext ); }
/// <summary> /// Check if an <see cref="IDomainModel"/> is valid for this transformer. /// <param name="domainModel">The input <see cref="IDomainModel"/></param> /// </summary> public abstract bool CanTransform(IDomainModel domainModel);
/// <summary> /// Execute a transformation. /// </summary> /// <param name="domainModel">The input <see cref="IDomainModel"/></param> /// <param name="productionContext">The input <see cref="ProductionContext"/></param> /// <returns></returns> public TransformationResult Transform(IDomainModel domainModel, ProductionContext productionContext) { if (TransformationInfo == null) throw new FactoryException("TransformationInfo must be set before invoking Transform method"); Model = domainModel; AddParameter(Model.ModelTypeName, Model.Name); ProductionContext = productionContext; TransformationResult = new TransformationResult(); ProductionContext.SetCurrentTransformationResult(TransformationResult); OnTransform(); return TransformationResult; }
/// <summary> /// Store an <see cref="IDomainModel"/> instance, which is the result of a /// transformation during the production being executed. /// </summary> /// <param name="key">The model key</param> /// <param name="model">The <see cref="IDomainModel"/> instance to store</param> public void SetModel(string key, IDomainModel model) { Models[key] = model; }