public ContactsApi(IDatabaseSession session)
        {
            this.Id = Guid.NewGuid();
            this.session = session;

            Debug.WriteLine("ContactsApi {0} created and got session {1}", this.Id, this.session.Id);
        }
Ejemplo n.º 2
0
        public Population(IDatabaseSession session)
        {
            this.session = session;

            new Setup(session).Apply();

            this.Person1 = new PersonBuilder(this.session)
                           .WithUserName("*****@*****.**")
                           .WithFirstName("person1 first name")
                           .WithLastName("person1 last name")
                           .WithUserEmail("*****@*****.**")
                           .WithUserEmailConfirmed(true)
                           .WithUserPasswordHash("ADhrQUXHNLCelscP3NfZxpld7jRMOHkfxd8WRb9HtvgqS4vHKRzQCiIlZuj3qZ98kQ==")
                           .Build();

            this.Person2 = new PersonBuilder(this.session)
                           .WithUserName("*****@*****.**")
                           .WithFirstName("person2 first name")
                           .WithLastName("person2 last name")
                           .WithUserEmail("*****@*****.**")
                           .WithUserEmailConfirmed(true)
                           .WithUserPasswordHash("ADhrQUXHNLCelscP3NfZxpld7jRMOHkfxd8WRb9HtvgqS4vHKRzQCiIlZuj3qZ98kQ==")
                           .Build();

            new UserGroups(this.session).Administrators.AddMember(this.Person1);

            this.session.Derive(true);
            this.session.Commit();
        }
Ejemplo n.º 3
0
        public NHibernateUnitOfWork(ISession session)
        {
            _session     = session;
            _transaction = _session.BeginTransaction();

            _databaseSession = new NHibernateDatabaseSession(_session);
        }
Ejemplo n.º 4
0
 public void ValidateMappingsAgainstDatabase(IDatabaseSession session)
 {
     foreach (var currentMapping in this._mappings)
     {
         currentMapping.Value.ValidateAgainstDatabase(session, this._converter);
     }
 }
Ejemplo n.º 5
0
        public async ValueTask Delete(NodeID nid, IDatabaseSession db, Func <NodeID, IDatabaseSession, ValueTask> next)
        {
            var result = next(nid, db);

            await deleteFromParentFolder(nid, db);

            await result;
        }
Ejemplo n.º 6
0
        public async ValueTask Upsert(Node node, IDatabaseSession db, Func <Node, IDatabaseSession, ValueTask> next)
        {
            var result = next(node, db);

            await updateParentFolder(node, db);

            await result;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Validates the Query SQL statement against database engine for its syntax and structural correctness.
        /// Validates only statement in <see cref="SqlStatement"/>. If derived class contains more than this one
        /// SQL statement - override this implementation and add all statement validations to it.
        /// </summary>
        /// <param name="databaseSession">The database session object.</param>
        /// <exception cref="DatabaseStatementSyntaxException">Throws when <see cref="SqlStatement"/> is incorrect.</exception>
        public virtual void Validate(IDatabaseSession databaseSession)
        {
            string result = databaseSession.QueryFirstOrDefault <string>("SELECT dbo.CheckSql(@tsql, @parameterTypes)", new { tsql = this.SqlStatement, parameterTypes = MsSqlValidationHelpers.GetParameterTypes(this.Parameters) });

            if (result != "OK")
            {
                throw new DatabaseStatementSyntaxException(result, this.SqlStatement);
            }
        }
Ejemplo n.º 8
0
        protected NHQueryableRepository(IDatabaseSession databaseSession)
        {
            if (databaseSession == null)
            {
                throw new ArgumentNullException(nameof(databaseSession));
            }

            Session = databaseSession.Session;
        }
        public SqlServerDurableIncoming(IDatabaseSession session, DatabaseSettings settings, JasperOptions options)
        {
            _session  = session;
            _settings = settings;
            _findAtLargeEnvelopesSql =
                $"select top {options.Retries.RecoveryBatchSize} body from {settings.SchemaName}.{IncomingTable} where owner_id = {TransportConstants.AnyNode} and status = '{TransportConstants.Incoming}'";

            _cancellation = options.Cancellation;
        }
Ejemplo n.º 10
0
        public SqlServerDurableIncoming(IDatabaseSession session, DatabaseSettings databaseSettings, AdvancedSettings settings)
        {
            _session                 = session;
            _databaseSettings        = databaseSettings;
            _findAtLargeEnvelopesSql =
                $"select top {settings.RecoveryBatchSize} body, attempts from {databaseSettings.SchemaName}.{IncomingTable} where owner_id = {TransportConstants.AnyNode} and status = '{EnvelopeStatus.Incoming}'";

            _cancellation = settings.Cancellation;
        }
Ejemplo n.º 11
0
        public async ValueTask Delete(NodeID nodeId, IDatabaseSession db, Func <NodeID, IDatabaseSession, ValueTask> next)
        {
            var store = db.GetPartition(nodeId).Value;
            await store.DeleteNodeAsync(nodeId);

            if (next != null)
            {
                throw new Exception("Next should be null for the that last merge writer middleware.");
            }
        }
Ejemplo n.º 12
0
        public async ValueTask Upsert(Node node, IDatabaseSession db, Func <Node, IDatabaseSession, ValueTask> next)
        {
            var store = db.GetPartition(node).Value;
            await store.UpsertNode(node);

            if (next != null)
            {
                throw new Exception("Next should be null for the that last writer middleware.");
            }
        }
Ejemplo n.º 13
0
        private async ValueTask updateParentFolder(Node node, IDatabaseSession db)
        {
            var parentPath = ParentPath(new Uri(node.Id.Iri));

            // avoid recursive loops
            if (parentPath.Equals(node.Id))
            {
                return;
            }

            await AddToParentsChildrenCollection(parentPath, node.Id, FileTypes.FromNode(node), db);
        }
Ejemplo n.º 14
0
        private async ValueTask deleteFromParentFolder(NodeID nid, IDatabaseSession db)
        {
            var parentPath = ParentPath(new Uri(nid.Iri));

            // avoid recursive loops
            if (parentPath.Equals(nid))
            {
                return;
            }
            var parent = await db.Read(parentPath);

            await RemoveFromParentsChildrenCollection(parent, nid, db);
        }
        public CreatedResponse Run(IDatabaseSession dbSession)
        {
            var clientId      = entity.Id;
            var recordChanges = entity as IRecordChangeInfo;

            var newRecord = dbSession.Insert <T>(this.BuildSql(), entity);

            return(new CreatedResponse
            {
                ClientId = clientId,
                ServerId = newRecord.Id,
                RowVersion = newRecord.RowVersion
            });
        }
Ejemplo n.º 16
0
        public virtual void Dispose()
        {
            if (this.session != null)
            {
                this.session.Rollback();
                this.session = null;
            }

            if (this.session2 != null)
            {
                this.session2.Rollback();
                this.session2 = null;
            }
        }
Ejemplo n.º 17
0
        public virtual void Dispose()
        {
            if (this.session != null)
            {
                this.session.Rollback();
                this.session = null;
            }

            if (this.session2 != null)
            {
                this.session2.Rollback();
                this.session2 = null;
            }
        }
Ejemplo n.º 18
0
        protected DurableOutgoing(IDatabaseSession session, DatabaseSettings settings, JasperOptions options)
        {
            _session = session;
            _findUniqueDestinations =
                $"select distinct destination from {settings.SchemaName}.{OutgoingTable}";

            _deleteOutgoingSql =
                $"delete from {settings.SchemaName}.{OutgoingTable} where owner_id = :owner and destination = @destination";

            _cancellation = options.Cancellation;

            _findOutgoingEnvelopesSql =
                determineOutgoingEnvelopeSql(settings, options);
        }
Ejemplo n.º 19
0
 public SchoolClassController(ISchoolClassService scoolClassService,
     IMappingEngine mappingEngine,
     IDropdownQueries dropdownQueries,
     ISchoolClassTeacherService schoolClassTeacherService,
     ISchoolClassStudentService schoolClassStudentService,
     ISchoolClassSubjectService schoolClassSubjectService, IDatabaseSession databaseSession)
 {
     _scoolClassService = scoolClassService;
     _mappingEngine = mappingEngine;
     _dropdownQueries = dropdownQueries;
     _schoolClassTeacherService = schoolClassTeacherService;
     _schoolClassStudentService = schoolClassStudentService;
     _schoolClassSubjectService = schoolClassSubjectService;
     _databaseSession = databaseSession;
 }
Ejemplo n.º 20
0
        private static void AddRec(IDatabaseSession sess)
        {
            var rec = new CommandQueueRec
            {
                Id             = Guid.NewGuid(),
                TimeQueued     = DateTime.UtcNow,
                CommandType    = "Test",
                TemplateName   = "TemplateName",
                TemplateFields = "fields"
            };

            var cmdQueueMap = new CommandQueueMap(sess);

            cmdQueueMap.Insert(rec);
        }
Ejemplo n.º 21
0
        public DeletedResponse Run(IDatabaseSession dbSession)
        {
            IDictionary <string, object> parameters;
            var changeInfo = entity as IRecordChangeInfo;
            var deleteSql  = this.BuildSql();

            parameters = this.GetParameters(changeInfo?.RowVersion);

            dbSession.DeleteSingle(deleteSql, parameters, this.entity);

            return(new DeletedResponse()
            {
                Success = true
            });
        }
Ejemplo n.º 22
0
        public UpdatedResponse Run(IDatabaseSession dbSession)
        {
            IDictionary <string, object> parameters;
            var changeInfo = this.entity as IRecordChangeInfo;
            var updateSql  = this.BuildSql();

            parameters = this.GetParameters(changeInfo?.RowVersion);

            var record = dbSession.UpdateSingle(updateSql, parameters, this.entity);

            return(new UpdatedResponse()
            {
                ServerId = this.entity.Id,
                RowVersion = record.RowVersion
            });
        }
Ejemplo n.º 23
0
 public PmsWorkArea(
     IDatabaseSession databaseSession,
     IAddressRepository addresses,
     ICollaboratorRepository collaborators,
     ICommercialGuestRepository commercialGuests,
     IIndividualGuestRepository individualGuests,
     IMaintenanceJobRepository maintenanceJobs,
     IPassportRepository passports,
     IRoomRepository rooms) : base(databaseSession)
 {
     Addresses        = addresses;
     Collaborators    = collaborators;
     CommercialGuests = commercialGuests;
     IndividualGuests = individualGuests;
     MaintenanceJobs  = maintenanceJobs;
     Passports        = passports;
     Rooms            = rooms;
 }
Ejemplo n.º 24
0
        public static IAsyncEnumerable <object> RemoteRun(byte[] assemblyStream, IDatabaseSession queryDatabaseSession)
        {
            var result = ExecuteAndUnload(Assembly.GetExecutingAssembly().Location, assemblyStream,
                                          "remoteRun",
                                          out var alcWeakRef,
                                          assembly =>
            {
                //using (token.Scope())
                {
                    IAsyncEnumerable <object> results = null;
                    var subTypes = assembly.DefinedTypes.Where(dt => dt.IsAssignableTo(typeof(EkatiQuery))).ToList();
                    if (subTypes.Any())
                    {
                        var pipeline = subTypes.Select(info =>
                        {
                            if (Activator.CreateInstance(info.AsType()) is Standard stdQuery)
                            {
                                return(stdQuery.Query(queryDatabaseSession).Prepend($"Running: {info.FullName}"));
                            }

                            if (Activator.CreateInstance(info.AsType()) is Single singleQuery)
                            {
                                var qr = new[]
                                {
                                    $"Running: {info.FullName}",
                                    singleQuery.Query(queryDatabaseSession)
                                }.ToAsyncEnumerable();
                                return(qr);
                            }

                            return(new[] { "No query detected" }.ToAsyncEnumerable());
                        }).ToAsyncEnumerable().SelectMany(x => x);
                        return(pipeline);
                    }

                    return(results);
                }
            });


            return(result);
        }
Ejemplo n.º 25
0
        public DurableNodes(IDatabaseSession session, DatabaseSettings settings,
                            CancellationToken cancellation)
        {
            _session        = session;
            _cancellation   = cancellation;
            _fetchOwnersSql = $@"
select distinct owner_id from {settings.SchemaName}.{IncomingTable} where owner_id != 0 and owner_id != @owner
union
select distinct owner_id from {settings.SchemaName}.{OutgoingTable} where owner_id != 0 and owner_id != @owner";

            _reassignDormantNodeSql = $@"
update {settings.SchemaName}.{IncomingTable}
  set owner_id = 0
where
  owner_id = @owner;

update {settings.SchemaName}.{OutgoingTable}
  set owner_id = 0
where
  owner_id = @owner;
";
        }
Ejemplo n.º 26
0
 public static async Task AddDoc(this IDatabaseSession data, string iri, params KeyValue[] withProps)
 {
     var nowTicks = DateTime.Now.Ticks;
     await data.Upsert(new Node
     {
         Id = new NodeID {
             Iri = iri
         },
         Attributes = new Map
         {
             Items =
                 withProps.Concat(new KeyValue[]
             {
                 ("hi", "there", nowTicks),
                 ("hii", 18.7d, nowTicks),
                 ("hiii", 7, nowTicks),
                 ("hiiii", "there4", nowTicks),
                 ("someMap", new KeyValue[]
                 {
                     ("m1", 11.3f, nowTicks),
                     ("m2", 8, nowTicks),
                     ("m3", new Primitive[]
                     {
                         3.123f,
                         3,
                         3L,
                         (Map) new KeyValue[]
                         {
                             ("n1", "v3", nowTicks),
                             ("n2", "v4", nowTicks),
                             ("n3", new Primitive[]
                             {
                                 4.123f,
                                 4,
                                 4L,
                             }, nowTicks)
                         }, nowTicks
Ejemplo n.º 27
0
        public override async IAsyncEnumerable <object> Query(IDatabaseSession db)
        {
            var traversed = 0;
            var parResult = System.Threading.Tasks.Parallel.For(0, 10, async(i) =>
            {
                var item = db.Read(Utils.Id("ekati:/etc/assembly"));

                if (item.IsCompletedSuccessfully)
                {
                    var res = item.Result;
                    var it  = res.Attributes.Items.FirstOrDefault(i => i.Key.TryGet <NodeID>(out var nid) && nid.Iri == "ekati:attr/children");
                    if (it != null)
                    {
                        if (it.Value.TryGet <Map>(out var kids) && kids != null)
                        {
                            foreach (var k in kids.Items)
                            {
                                if (k.Key.TryGet <NodeID>(out var doc))
                                {
                                    var sub = await db.Read(doc);
                                    traversed++;
                                }
                            }
                        }
                    }
                    traversed++;
                }
                else
                {
                    await item;
                    traversed++;
                }
            });

            yield return(new { traversed, parResult });
        }
Ejemplo n.º 28
0
 public FakeRepository(IDatabaseSession databaseSession)
 {
     _databaseSession = databaseSession;
 }
Ejemplo n.º 29
0
 public SchoolClassStudentService(IDatabaseSession databaseSession)
 {
     _databaseSession = databaseSession;
 }
Ejemplo n.º 30
0
 public IDatabaseSession GetSession2()
 {
     return this.session2 ?? (this.session2 = this.GetPopulation2().CreateSession());
 }
Ejemplo n.º 31
0
 public TeacherService(IDatabaseSession databaseSession)
 {
     _databaseSession = databaseSession;
 }
Ejemplo n.º 32
0
 public SchoolClassTeacherService(IDatabaseSession databaseSession)
 {
     _databaseSession = databaseSession;
 }
Ejemplo n.º 33
0
        protected void Init(bool setup)
        {
            if (setup)
            {
                var stringReader = new StringReader(Fixture.DefaultXml);
                var reader = new XmlTextReader(stringReader);
                Config.Default.Load(reader);
            }
            else
            {
                Config.Default.Init();
            }

            this.databaseSession = Config.Default.CreateSession();

            SecurityCache.Invalidate();
        }
Ejemplo n.º 34
0
 public virtual void TearDown()
 {
     this.databaseSession.Rollback();
     this.databaseSession = null;
 }
Ejemplo n.º 35
0
 public BrightStarDataProvider(GrpcFileStore fileStore)
 {
     _databaseSession = fileStore.Session();
 }
Ejemplo n.º 36
0
 public override void ValidateAgainstDatabase(IDatabaseSession session, ITypeToColumnTypeConverter converter)
 {
     this.ValidateAgainstTableMetaData(session.GetTableMetaData(this.TableName), converter);
 }
Ejemplo n.º 37
0
 public SchoolClassSubjectService(IDatabaseSession databaseSession)
 {
     _databaseSession = databaseSession;
 }
Ejemplo n.º 38
0
 public SqlServerDurableOutgoing(IDatabaseSession session, DatabaseSettings settings, AdvancedSettings options) : base(session, settings, options)
 {
     _session      = session;
     _settings     = settings;
     _cancellation = options.Cancellation;
 }
Ejemplo n.º 39
0
 public ProductRepository(IDatabaseSession session) : base(session)
 {
 }
Ejemplo n.º 40
0
 public ContactRepository(IDatabaseSessionFactory databaseSessionFactory)
 {
     _dbSession = databaseSessionFactory.CreateSession(CONNECTION_STRING);
 }
Ejemplo n.º 41
0
 public ClientRepository(IDatabaseSession session) : base(session)
 {
 }
Ejemplo n.º 42
0
 public async ValueTask <Node> Read(NodeID nodeId, IDatabaseSession db, Func <NodeID, IDatabaseSession, ValueTask <Node> > next)
 {
     return(await db.GetPartition(nodeId).Value.LoadNodeAsync(nodeId));
 }