本文整理汇总了C#中ITransactionalStorage.Batch方法的典型用法代码示例。如果您正苦于以下问题:C# ITransactionalStorage.Batch方法的具体用法?C# ITransactionalStorage.Batch怎么用?C# ITransactionalStorage.Batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITransactionalStorage
的用法示例。
在下文中一共展示了ITransactionalStorage.Batch方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: when_there_are_multiple_map_results_for_multiple_indexes
private static void when_there_are_multiple_map_results_for_multiple_indexes(ITransactionalStorage transactionalStorage)
{
transactionalStorage.Initialize(new DummyUuidGenerator());
transactionalStorage.Batch(accessor =>
{
accessor.Indexing.AddIndex("a",true);
accessor.Indexing.AddIndex("b", true);
accessor.Indexing.AddIndex("c", true);
accessor.MappedResults.PutMappedResult("a", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("a", "a"));
accessor.MappedResults.PutMappedResult("a", "a/2", "a", new RavenJObject(), MapReduceIndex.ComputeHash("a", "a"));
accessor.MappedResults.PutMappedResult("b", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("b", "a"));
accessor.MappedResults.PutMappedResult("b", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("b", "a"));
accessor.MappedResults.PutMappedResult("c", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("c", "a"));
accessor.MappedResults.PutMappedResult("c", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("c", "a"));
});
transactionalStorage.Batch(actionsAccessor =>
{
Assert.True(actionsAccessor.Staleness.IsReduceStale("a"));
Assert.True(actionsAccessor.Staleness.IsReduceStale("b"));
Assert.True(actionsAccessor.Staleness.IsReduceStale("c"));
});
}
示例2: StorageStream
protected StorageStream(ITransactionalStorage transactionalStorage, string fileName,
StorageStreamAccess storageStreamAccess,
RavenJObject metadata, IndexStorage indexStorage, StorageOperationsTask operations)
{
TransactionalStorage = transactionalStorage;
StorageStreamAccess = storageStreamAccess;
Name = fileName;
switch (storageStreamAccess)
{
case StorageStreamAccess.Read:
TransactionalStorage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
if (fileHeader.TotalSize == null)
{
throw new FileNotFoundException("File is not uploaded yet");
}
Metadata = fileHeader.Metadata;
Seek(0, SeekOrigin.Begin);
break;
case StorageStreamAccess.CreateAndWrite:
TransactionalStorage.Batch(accessor =>
{
operations.IndicateFileToDelete(fileName);
accessor.PutFile(fileName, null, metadata);
indexStorage.Index(fileName, metadata);
});
Metadata = metadata;
break;
default:
throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
}
}
示例3: ReadIndexesFromCatalog
private void ReadIndexesFromCatalog(IEnumerable<AbstractViewGenerator> compiledGenerators, ITransactionalStorage transactionalStorage)
{
foreach (var generator in compiledGenerators)
{
var copy = generator;
var displayNameAtt = TypeDescriptor.GetAttributes(copy)
.OfType<DisplayNameAttribute>()
.FirstOrDefault();
var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name;
transactionalStorage.Batch(actions =>
{
if (actions.Indexing.GetIndexesStats().Any(x => x.Name == name))
return;
actions.Indexing.AddIndex(name, copy.ReduceDefinition != null);
});
var indexDefinition = new IndexDefinition
{
Name = name,
Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName,
// need to supply this so the index storage will create map/reduce index
Reduce = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName,
Indexes = generator.Indexes,
Stores = generator.Stores,
IsCompiled = true
};
indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy);
indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition);
}
}
示例4: IndexDefinitionStorage
public IndexDefinitionStorage(
ITransactionalStorage transactionalStorage,
string path,
IEnumerable<AbstractViewGenerator> compiledGenerators,
AbstractDynamicCompilationExtension[] extensions)
{
this.extensions = extensions;// this is used later in the ctor, so it must appears first
this.path = Path.Combine(path, IndexDefDir);
if (Directory.Exists(this.path) == false)
Directory.CreateDirectory(this.path);
this.extensions = extensions;
foreach (var index in Directory.GetFiles(this.path, "*.index"))
{
try
{
AddAndCompileIndex(
MonoHttpUtility.UrlDecode(Path.GetFileNameWithoutExtension(index)),
JsonConvert.DeserializeObject<IndexDefinition>(File.ReadAllText(index), new JsonEnumConverter())
);
}
catch (Exception e)
{
logger.Warn("Could not compile index " + index + ", skipping bad index", e);
}
}
//compiled view generators always overwrite dynamic views
foreach (var generator in compiledGenerators)
{
var copy = generator;
var displayNameAtt = TypeDescriptor.GetAttributes(copy)
.OfType<DisplayNameAttribute>()
.FirstOrDefault();
var name = displayNameAtt != null ? displayNameAtt.DisplayName : copy.GetType().Name;
transactionalStorage.Batch(actions =>
{
if (actions.Indexing.GetIndexesStats().Any(x => x.Name == name))
return;
actions.Indexing.AddIndex(name);
});
var indexDefinition = new IndexDefinition
{
Map = "Compiled map function: " + generator.GetType().AssemblyQualifiedName,
// need to supply this so the index storage will create map/reduce index
Reduce = generator.ReduceDefinition == null ? null : "Compiled reduce function: " + generator.GetType().AssemblyQualifiedName,
Indexes = generator.Indexes,
Stores = generator.Stores,
IsCompiled = true
};
indexCache.AddOrUpdate(name, copy, (s, viewGenerator) => copy);
indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) => indexDefinition);
}
}
示例5: GetOrDefault
public static SynchronizationConfig GetOrDefault(ITransactionalStorage storage)
{
SynchronizationConfig result = null;
storage.Batch(accessor => result = GetOrDefault(accessor));
return result ?? new SynchronizationConfig();
}
示例6: TimeoutExceeded
public bool TimeoutExceeded(string fileName, ITransactionalStorage storage)
{
var result = false;
storage.Batch(accessor => result = TimeoutExceeded(fileName, accessor));
return result;
}
示例7: StorageStream
protected StorageStream(RavenFileSystem fileSystem, ITransactionalStorage storage, string fileName, RavenJObject metadata, StorageStreamAccess storageStreamAccess)
{
this.fileSystem = fileSystem;
this.storage = storage;
StorageStreamAccess = storageStreamAccess;
Name = fileName;
switch (storageStreamAccess)
{
case StorageStreamAccess.Read:
storage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
if (fileHeader.TotalSize == null)
{
throw new FileNotFoundException("File is not uploaded yet");
}
Metadata = fileHeader.Metadata;
Seek(0, SeekOrigin.Begin);
break;
case StorageStreamAccess.CreateAndWrite:
if (this.fileSystem == null)
throw new ArgumentNullException("fileSystem");
storage.Batch(accessor =>
{
using (fileSystem.DisableAllTriggersForCurrentThread())
{
fileSystem.Files.IndicateFileToDelete(fileName, null);
}
var putResult = accessor.PutFile(fileName, null, metadata);
fileSystem.Search.Index(fileName, metadata, putResult.Etag);
});
Metadata = metadata;
break;
default:
throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
}
}
示例8: SynchronizationWorkItem
protected SynchronizationWorkItem(string fileName, string sourceServerUrl, ITransactionalStorage storage)
{
Storage = storage;
FileName = fileName;
FileAndPagesInformation fileAndPages = null;
Storage.Batch(accessor => fileAndPages = accessor.GetFile(fileName, 0, 0));
FileMetadata = fileAndPages.Metadata;
FileSystemInfo = new FileSystemInfo
{
Id = Storage.Id,
Url = sourceServerUrl
};
conflictDetector = new ConflictDetector();
conflictResolver = new ConflictResolver(null, null);
}
示例9: when_there_are_updates_to_map_reduce_results
private static void when_there_are_updates_to_map_reduce_results(ITransactionalStorage transactionalStorage)
{
var dummyUuidGenerator = new DummyUuidGenerator();
transactionalStorage.Initialize(dummyUuidGenerator);
Guid a = Guid.Empty;
Guid b = Guid.Empty;
Guid c = Guid.Empty;
transactionalStorage.Batch(accessor =>
{
accessor.Indexing.AddIndex("a", true);
accessor.Indexing.AddIndex("b", true);
accessor.Indexing.AddIndex("c", true);
accessor.MappedResults.PutMappedResult("a", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("a", "a"));
a = dummyUuidGenerator.CreateSequentialUuid();
accessor.MappedResults.PutMappedResult("a", "a/2", "a", new RavenJObject(), MapReduceIndex.ComputeHash("a", "a"));
accessor.MappedResults.PutMappedResult("b", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("b", "a"));
b = dummyUuidGenerator.CreateSequentialUuid();
accessor.MappedResults.PutMappedResult("b", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("b", "a"));
accessor.MappedResults.PutMappedResult("c", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("c", "a"));
c = dummyUuidGenerator.CreateSequentialUuid();
accessor.MappedResults.PutMappedResult("c", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("c", "a"));
});
transactionalStorage.Batch(actionsAccessor =>
{
Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("a", a).Count());
Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("b", b).Count());
Assert.Equal(1, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("c", c).Count());
});
}
示例10: when_there_are_multiple_map_results_and_we_ask_for_results
private static void when_there_are_multiple_map_results_and_we_ask_for_results(ITransactionalStorage transactionalStorage)
{
transactionalStorage.Initialize(new DummyUuidGenerator());
transactionalStorage.Batch(accessor =>
{
accessor.Indexing.AddIndex("a", true);
accessor.Indexing.AddIndex("b", true);
accessor.Indexing.AddIndex("c", true);
accessor.MappedResults.PutMappedResult("a", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("a", "a"));
accessor.MappedResults.PutMappedResult("a", "a/2", "a", new RavenJObject(), MapReduceIndex.ComputeHash("a", "a"));
accessor.MappedResults.PutMappedResult("b", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("b", "a"));
accessor.MappedResults.PutMappedResult("b", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("b", "a"));
accessor.MappedResults.PutMappedResult("c", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("c", "a"));
accessor.MappedResults.PutMappedResult("c", "a/1", "a", new RavenJObject(), MapReduceIndex.ComputeHash("c", "a"));
});
transactionalStorage.Batch(actionsAccessor =>
{
Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("a", Guid.Empty).Count());
Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("b", Guid.Empty).Count());
Assert.Equal(2, actionsAccessor.MappedResults.GetMappedResultsReduceKeysAfter("c", Guid.Empty).Count());
});
}