本文整理汇总了C#中System.IO.MemoryStream.WriteSpace方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.WriteSpace方法的具体用法?C# MemoryStream.WriteSpace怎么用?C# MemoryStream.WriteSpace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.WriteSpace方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
/// <summary>
/// Removes the serialized objects at the given cache keys from the cache.
/// </summary>
/// <param name="cacheKeys">The cache keys.</param>
public void Remove(IEnumerable<string> cacheKeys)
{
// Sanitize
if (cacheKeys == null)
{
throw new ArgumentNullException("cacheKeys");
}
if (!cacheKeys.Any())
{
throw new ArgumentException("must have at least one element", "cacheKeys");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("del");
foreach (var cacheKey in cacheKeys)
{
memoryStream.WriteSpace();
memoryStream.Write(cacheKey);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeys);
// Send
_client.Send(command);
}
示例2: RemoveTagged
/// <summary>
/// Removes all serialized objects associated with the given tag names and optionally with keys matching the given pattern.
/// WARNING: THIS IS A VERY EXPENSIVE OPERATION FOR LARGE TAG CACHES. USE WITH CAUTION.
/// </summary>
/// <param name="tagNames">The tag names.</param>
/// <param name="pattern">The search pattern (RegEx). Optional. If not specified, the default of "*" is used to indicate match all.</param>
public void RemoveTagged(IEnumerable<string> tagNames, string pattern = "*")
{
// Sanitize
if (tagNames == null)
{
throw new ArgumentNullException("tagNames");
}
if (!tagNames.Any())
{
throw new ArgumentException("must have at least one element", "tagNames");
}
if (string.IsNullOrWhiteSpace(pattern))
{
throw new ArgumentException("cannot be null, empty, or white space", "pattern");
}
byte[] command;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("del-tag");
memoryStream.WriteSpace();
memoryStream.Write(pattern);
foreach (var tagName in tagNames)
{
memoryStream.WriteSpace();
memoryStream.Write(tagName);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeys);
// Send
_client.Send(command);
}
示例3: GetTagged
/// <summary>
/// Gets all serialized objects associated with the given tag name.
/// </summary>
/// <param name="tagNames">The tag names.</param>
/// <returns>A list of the serialized objects.</returns>
public List<byte[]> GetTagged(IEnumerable<string> tagNames)
{
// Sanitize
if (tagNames == null)
{
throw new ArgumentNullException("tagNames");
}
if (!tagNames.Any())
{
throw new ArgumentException("must have at least one element", "tagNames");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("get-tag");
foreach (var tagName in tagNames)
{
memoryStream.WriteSpace();
memoryStream.Write(tagName);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeys);
// Send and receive
command = _client.SendReceive(command);
// Parse string
var commandResult = DacheProtocolHelper.CommunicationEncoding.GetString(command);
// Verify that we got something
if (commandResult == null)
{
return null;
}
// Parse command from bytes
var commandResultParts = commandResult.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return ParseCacheObjects(commandResultParts);
}
示例4: GetCacheKeysTagged
/// <summary>
/// Gets all cache keys associated with the given tag names and optionally matching the given pattern.
/// WARNING: THIS IS A VERY EXPENSIVE OPERATION FOR LARGE TAG CACHES. USE WITH CAUTION.
/// </summary>
/// <param name="tagNames">The tag names.</param>
/// <param name="pattern">The search pattern (RegEx). Optional. If not specified, the default of "*" is used to indicate match all.</param>
/// <returns>The list of cache keys matching the provided pattern.</returns>
public List<byte[]> GetCacheKeysTagged(IEnumerable<string> tagNames, string pattern = "*")
{
if (tagNames == null)
{
throw new ArgumentNullException("tagNames");
}
if (!tagNames.Any())
{
throw new ArgumentException("must have at least one element", "tagNames");
}
if (string.IsNullOrWhiteSpace(pattern))
{
throw new ArgumentException("cannot be null, empty, or white space", "pattern");
}
byte[] command;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("keys-tag");
memoryStream.WriteSpace();
memoryStream.Write(pattern);
foreach (var tagName in tagNames)
{
memoryStream.WriteSpace();
memoryStream.Write(tagName);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.Literal);
// Send and receive
var rawResult = _client.SendReceive(command);
// Verify that we got something
if (rawResult == null)
{
return null;
}
// Parse string
var decodedResult = DacheProtocolHelper.CommunicationEncoding.GetString(rawResult);
if (string.IsNullOrWhiteSpace(decodedResult))
{
return null;
}
// Parse command from bytes
var commandResultParts = decodedResult.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return ParseCacheObjects(commandResultParts);
}
示例5: AddOrUpdateTaggedInterned
/// <summary>
/// Adds or updates the interned serialized objects in the cache at the given cache keys.
/// NOTE: interned objects use significantly less memory when placed in the cache multiple times however cannot expire or be evicted.
/// You must remove them manually when appropriate or else you may face a memory leak.
/// </summary>
/// <param name="cacheKeysAndSerializedObjects">The cache keys and associated serialized objects.</param>
/// <param name="tagName">The tag name.</param>
public void AddOrUpdateTaggedInterned(IEnumerable<KeyValuePair<string, byte[]>> cacheKeysAndSerializedObjects, string tagName)
{
// Sanitize
if (cacheKeysAndSerializedObjects == null)
{
throw new ArgumentNullException("cacheKeysAndSerializedObjects");
}
if (!cacheKeysAndSerializedObjects.Any())
{
throw new ArgumentException("must have at least one element", "cacheKeysAndSerializedObjects");
}
if (string.IsNullOrWhiteSpace(tagName))
{
throw new ArgumentException("cannot be null, empty, or white space", "tagName");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("set-tag-intern {0}", tagName);
foreach (var cacheKeyAndSerializedObjectKvp in cacheKeysAndSerializedObjects)
{
memoryStream.WriteSpace();
memoryStream.Write(cacheKeyAndSerializedObjectKvp.Key);
memoryStream.WriteSpace();
memoryStream.WriteBase64(cacheKeyAndSerializedObjectKvp.Value);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeysAndObjects);
// Send
_client.Send(command);
}
示例6: AddOrUpdate
/// <summary>
/// Adds or updates the serialized objects in the cache at the given cache keys.
/// </summary>
/// <param name="cacheKeysAndSerializedObjects">The cache keys and associated serialized objects.</param>
/// <param name="slidingExpiration">The sliding expiration.</param>
public void AddOrUpdate(IEnumerable<KeyValuePair<string, byte[]>> cacheKeysAndSerializedObjects, TimeSpan slidingExpiration)
{
// Sanitize
if (cacheKeysAndSerializedObjects == null)
{
throw new ArgumentNullException("cacheKeysAndSerializedObjects");
}
if (!cacheKeysAndSerializedObjects.Any())
{
throw new ArgumentException("must have at least one element", "cacheKeysAndSerializedObjects");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("set {0}", (int)slidingExpiration.TotalSeconds);
foreach (var cacheKeyAndSerializedObjectKvp in cacheKeysAndSerializedObjects)
{
memoryStream.WriteSpace();
memoryStream.Write(cacheKeyAndSerializedObjectKvp.Key);
memoryStream.WriteSpace();
memoryStream.WriteBase64(cacheKeyAndSerializedObjectKvp.Value);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeysAndObjects);
// Send
_client.Send(command);
}
示例7: ProcessCommand
private byte[] ProcessCommand(string command, DacheProtocolHelper.MessageType messageType)
{
// Sanitize
if (command == null)
{
return null;
}
if (string.IsNullOrWhiteSpace(command))
{
return null;
}
string[] commandParts = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (commandParts.Length == 0)
{
return null;
}
List<byte[]> results;
byte[] commandResult = null;
switch (messageType)
{
case DacheProtocolHelper.MessageType.Literal:
{
if (string.Equals(commandParts[0], "keys", StringComparison.OrdinalIgnoreCase))
{
// Sanitize the command
if (commandParts.Length != 2)
{
return null;
}
var pattern = commandParts[1];
results = GetCacheKeys(pattern);
// Structure the results for sending
using (var memoryStream = new MemoryStream())
{
for (int i = 0; i < results.Count; i++)
{
if (i != 0)
{
memoryStream.WriteSpace();
}
memoryStream.WriteBase64(results[i]);
}
commandResult = memoryStream.ToArray();
}
}
else if (string.Equals(commandParts[0], "clear", StringComparison.OrdinalIgnoreCase))
{
Clear();
}
break;
}
case DacheProtocolHelper.MessageType.RepeatingCacheKeys:
{
// Determine command
if (string.Equals(commandParts[0], "get", StringComparison.OrdinalIgnoreCase))
{
// Sanitize the command
if (commandParts.Length < 2)
{
return null;
}
var cacheKeys = commandParts.Skip(1);
results = Get(cacheKeys);
// Structure the results for sending
using (var memoryStream = new MemoryStream())
{
for (int i = 0; i < results.Count; i++)
{
if (i != 0)
{
memoryStream.WriteSpace();
}
memoryStream.WriteBase64(results[i]);
}
commandResult = memoryStream.ToArray();
}
}
if (string.Equals(commandParts[0], "get-tag", StringComparison.OrdinalIgnoreCase))
{
// Sanitize the command
if (commandParts.Length < 2)
{
return null;
}
var tagNames = commandParts.Skip(1);
results = GetTagged(tagNames);
// Structure the results for sending
using (var memoryStream = new MemoryStream())
{
for (int i = 0; i < results.Count; i++)
{
if (i != 0)
{
//.........这里部分代码省略.........