本文整理汇总了C#中SerializationWriter.UpdateHeader方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationWriter.UpdateHeader方法的具体用法?C# SerializationWriter.UpdateHeader怎么用?C# SerializationWriter.UpdateHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SerializationWriter
的用法示例。
在下文中一共展示了SerializationWriter.UpdateHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveService
/// <summary>
/// Saves the service
/// </summary>
/// <param name="serviceName">Service name.</param>
/// <param name="service">Service.</param>
/// <param name="path">Path.</param>
/// <returns>The filename of the persisted service.</returns>
private static String SaveService(string serviceName, IService service, string path)
{
var serviceFileName = path + Constants.ServiceSaveString + serviceName;
using (var serviceFile = File.Create(serviceFileName, Constants.BufferSize, FileOptions.SequentialScan))
{
var serviceWriter = new SerializationWriter(serviceFile);
serviceWriter.Write(serviceName);
serviceWriter.Write(service.PluginName);
service.Save(serviceWriter);
serviceWriter.UpdateHeader();
serviceWriter.Flush();
serviceFile.Flush();
}
return Path.GetFileName(serviceFileName);
}
示例2: SaveBunch
/// <summary>
/// Saves the graph element bunch.
/// </summary>
/// <returns> The path to the graph element bunch </returns>
/// <param name='range'> Range. </param>
/// <param name='graphElements'> Graph elements. </param>
/// <param name='pathToSavePoint'> Path to save point basis. </param>
private static String SaveBunch(Tuple<Int32, Int32> range, BigList<AGraphElement> graphElements,
String pathToSavePoint)
{
var partitionFileName = pathToSavePoint + Constants.GraphElementsSaveString + range.Item1 + "_to_" + range.Item2;
using (var partitionFile = File.Create(partitionFileName, Constants.BufferSize, FileOptions.SequentialScan))
{
var partitionWriter = new SerializationWriter(partitionFile);
partitionWriter.Write(range.Item1);
partitionWriter.Write(range.Item2);
for (var i = range.Item1; i < range.Item2; i++)
{
AGraphElement aGraphElement = graphElements.GetElement(i);
//there can be nulls
if (aGraphElement == null)
{
partitionWriter.Write(SerializedNull); // 2 for null
continue;
}
//code if it is an vertex or an edge
if (aGraphElement is VertexModel)
{
WriteVertex((VertexModel) aGraphElement, partitionWriter);
}
else
{
WriteEdge((EdgeModel) aGraphElement, partitionWriter);
}
}
partitionWriter.UpdateHeader();
partitionWriter.Flush();
partitionFile.Flush();
}
return Path.GetFileName(partitionFileName);
}
示例3: SaveIndex
/// <summary>
/// Saves the index.
/// </summary>
/// <returns> The filename of the persisted index. </returns>
/// <param name='indexName'> Index name. </param>
/// <param name='index'> Index. </param>
/// <param name='path'> Path. </param>
private static String SaveIndex(string indexName, IIndex index, string path)
{
var indexFileName = path + Constants.IndexSaveString + indexName;
using (var indexFile = File.Create(indexFileName, Constants.BufferSize, FileOptions.SequentialScan))
{
var indexWriter = new SerializationWriter(indexFile);
indexWriter.Write(indexName);
indexWriter.Write(index.PluginName);
index.Save(indexWriter);
indexWriter.UpdateHeader();
indexWriter.Flush();
indexFile.Flush();
}
return Path.GetFileName(indexFileName);
}
示例4: Save
//.........这里部分代码省略.........
/// <param name='savePartitions'> The number of save partitions for the graph elements. </param>
/// <param name="currentId">The current graph elemement identifier.</param>
internal static void Save(Fallen8 fallen8, BigList<AGraphElement> graphElements, String path, UInt32 savePartitions, Int32 currentId)
{
// Create the new, empty data file.
if (File.Exists(path))
{
//the newer save gets an timestamp
path = path + Constants.VersionSeparator + DateTime.Now.ToBinary().ToString(CultureInfo.InvariantCulture);
}
using (var file = File.Create(path, Constants.BufferSize, FileOptions.SequentialScan))
{
var writer = new SerializationWriter(file, true);
writer.Write(currentId);
//create some futures to save as much as possible in parallel
const TaskCreationOptions options = TaskCreationOptions.LongRunning;
var f = new TaskFactory(CancellationToken.None, options, TaskContinuationOptions.None,
TaskScheduler.Default);
#region graph elements
var graphElementCount = Convert.ToUInt32(currentId);
Task<string>[] graphElementSaver;
if (graphElementCount > 0)
{
graphElementCount++; //Hack
var graphElementPartitions = CreatePartitions(graphElementCount, savePartitions);
graphElementSaver = new Task<string>[graphElementPartitions.Count];
for (var i = 0; i < graphElementPartitions.Count; i++)
{
var partition = graphElementPartitions[i];
graphElementSaver[i] = f.StartNew(() => SaveBunch(partition, graphElements, path));
}
}
else
{
graphElementSaver = new Task<string>[0];
}
#endregion
#region indices
var indexSaver = new Task<string>[fallen8.IndexFactory.Indices.Count];
var counter = 0;
foreach (var aIndex in fallen8.IndexFactory.Indices)
{
var indexName = aIndex.Key;
var index = aIndex.Value;
indexSaver[counter] = f.StartNew(() => SaveIndex(indexName, index, path));
counter++;
}
#endregion
#region services
var serviceSaver = new Task<string>[fallen8.ServiceFactory.Services.Count];
counter = 0;
foreach (var aService in fallen8.ServiceFactory.Services)
{
var serviceName = aService.Key;
var service = aService.Value;
serviceSaver[counter] = f.StartNew(() => SaveService(serviceName, service, path));
counter++;
}
#endregion
writer.Write(graphElementSaver.Length);
foreach (var aFileStreamName in graphElementSaver)
{
writer.Write(aFileStreamName.Result);
}
writer.Write(indexSaver.Length);
foreach (var aIndexFileName in indexSaver)
{
writer.Write(aIndexFileName.Result);
}
writer.Write(serviceSaver.Length);
foreach (var aServiceFileName in serviceSaver)
{
writer.Write(aServiceFileName.Result);
}
writer.UpdateHeader();
writer.Flush();
file.Flush();
}
}