Example #1
0
        public void AddTask(DatabaseTask task, DateTime addedAt)
        {
            var tasksByType         = tableStorage.Tasks.GetIndex(Tables.Tasks.Indices.ByType);
            var tasksByIndex        = tableStorage.Tasks.GetIndex(Tables.Tasks.Indices.ByIndex);
            var tasksByIndexAndType = tableStorage.Tasks.GetIndex(Tables.Tasks.Indices.ByIndexAndType);

            var type       = task.GetType().FullName;
            var index      = task.Index;
            var id         = generator.CreateSequentialUuid(UuidType.Tasks);
            var idAsString = (Slice)id.ToString();

            var taskStructure = new Structure <TaskFields>(tableStorage.Tasks.Schema)
                                .Set(TaskFields.IndexId, index)
                                .Set(TaskFields.TaskId, id.ToByteArray())
                                .Set(TaskFields.AddedAt, addedAt.ToBinary())
                                .Set(TaskFields.Type, type)
                                .Set(TaskFields.SerializedTask, task.AsBytes());

            tableStorage.Tasks.AddStruct(writeBatch.Value, idAsString, taskStructure, 0);

            var indexKey = CreateKey(index);

            tasksByType.MultiAdd(writeBatch.Value, (Slice)CreateKey(type), idAsString);
            tasksByIndex.MultiAdd(writeBatch.Value, (Slice)indexKey, idAsString);
            tasksByIndexAndType.MultiAdd(writeBatch.Value, (Slice)AppendToKey(indexKey, type), idAsString);
        }
Example #2
0
        public void AddTask(DatabaseTask task, DateTime addedAt)
        {
            var tasksByType         = tableStorage.Tasks.GetIndex(Tables.Tasks.Indices.ByType);
            var tasksByIndex        = tableStorage.Tasks.GetIndex(Tables.Tasks.Indices.ByIndex);
            var tasksByIndexAndType = tableStorage.Tasks.GetIndex(Tables.Tasks.Indices.ByIndexAndType);

            var type       = task.GetType().FullName;
            var index      = task.Index;
            var id         = generator.CreateSequentialUuid(UuidType.Tasks);
            var idAsString = id.ToString();

            tableStorage.Tasks.Add(
                writeBatch.Value,
                idAsString,
                new RavenJObject
            {
                { "index", index },
                { "id", id.ToByteArray() },
                { "time", addedAt },
                { "type", type },
                { "task", task.AsBytes() }
            }, 0);

            tasksByType.MultiAdd(writeBatch.Value, CreateKey(type), idAsString);
            tasksByIndex.MultiAdd(writeBatch.Value, CreateKey(index), idAsString);
            tasksByIndexAndType.MultiAdd(writeBatch.Value, CreateKey(index, type), idAsString);
        }
Example #3
0
        public void AddTask(DatabaseTask task, DateTime addedAt)
        {
            int actualBookmarkSize;
            var bookmark = new byte[bookmarkMost];

            using (var update = new Update(session, Tasks, JET_prep.Insert))
            {
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["task"], task.AsBytes());
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["for_index"], task.Index);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["task_type"], task.GetType().FullName, Encoding.ASCII);
                Api.SetColumn(session, Tasks, tableColumnsCache.TasksColumns["added_at"], addedAt.ToBinary());

                update.Save(bookmark, bookmark.Length, out actualBookmarkSize);
            }
            Api.JetGotoBookmark(session, Tasks, bookmark, actualBookmarkSize);
        }