本文整理汇总了C#中MessageWriter类的典型用法代码示例。如果您正苦于以下问题:C# MessageWriter类的具体用法?C# MessageWriter怎么用?C# MessageWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageWriter类属于命名空间,在下文中一共展示了MessageWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WritesMessage
public async Task WritesMessage()
{
MemoryStream outputStream = new MemoryStream();
MessageWriter messageWriter =
new MessageWriter(
outputStream,
this.messageSerializer);
// Write the message and then roll back the stream to be read
// TODO: This will need to be redone!
await messageWriter.WriteMessage(Message.Event("testEvent", null));
outputStream.Seek(0, SeekOrigin.Begin);
string expectedHeaderString =
string.Format(
Constants.ContentLengthFormatString,
ExpectedMessageByteCount);
byte[] buffer = new byte[128];
await outputStream.ReadAsync(buffer, 0, expectedHeaderString.Length);
Assert.Equal(
expectedHeaderString,
Encoding.ASCII.GetString(buffer, 0, expectedHeaderString.Length));
// Read the message
await outputStream.ReadAsync(buffer, 0, ExpectedMessageByteCount);
Assert.Equal(
TestEventString,
Encoding.UTF8.GetString(buffer, 0, ExpectedMessageByteCount));
outputStream.Dispose();
}
开发者ID:juvchan,项目名称:PowerShellEditorServices,代码行数:35,代码来源:MessageReaderWriterTests.cs
示例2: SendAllPlayerColors
public static void SendAllPlayerColors(ClientObject client)
{
Dictionary<string,float[]> sendColors = new Dictionary<string, float[]>();
foreach (ClientObject otherClient in ClientHandler.GetClients())
{
if (otherClient.authenticated && otherClient.playerColor != null)
{
if (otherClient != client)
{
sendColors[otherClient.playerName] = otherClient.playerColor;
}
}
}
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.PLAYER_COLOR;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)PlayerColorMessageType.LIST);
mw.Write<int>(sendColors.Count);
foreach (KeyValuePair<string, float[]> kvp in sendColors)
{
mw.Write<string>(kvp.Key);
mw.Write<float[]>(kvp.Value);
}
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:28,代码来源:PlayerColor.cs
示例3: WriteDescriptionTo
/// <summary>
/// Write the constraint description to a MessageWriter
/// </summary>
/// <param name="writer">The writer on which the description is displayed</param>
public override void WriteDescriptionTo(MessageWriter writer)
{
writer.WritePredicate("String starting with");
writer.WriteExpectedValue(MsgUtils.ClipString(expected, writer.MaxLineLength - 40, 0));
if (this.caseInsensitive)
writer.WriteModifier("ignoring case");
}
开发者ID:haiduc32,项目名称:TestThat,代码行数:11,代码来源:StartsWithConstraint.cs
示例4: WriteCommand
/// <summary>
/// Writes the <see cref="UpgradeBuildingCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="UpgradeBuildingCommand"/>.
/// </param>
public override void WriteCommand(MessageWriter writer)
{
writer.Write(BuildingGameIndex);
writer.Write(Unknown1);
writer.Write(Unknown2);
}
开发者ID:circa94,项目名称:CoCSharp,代码行数:13,代码来源:UpgradeBuildingCommand.cs
示例5: SendScenarioModules
public static void SendScenarioModules(ClientObject client)
{
int numberOfScenarioModules = Directory.GetFiles(Path.Combine(Server.universeDirectory, "Scenarios", client.playerName)).Length;
int currentScenarioModule = 0;
string[] scenarioNames = new string[numberOfScenarioModules];
byte[][] scenarioDataArray = new byte[numberOfScenarioModules][];
foreach (string file in Directory.GetFiles(Path.Combine(Server.universeDirectory, "Scenarios", client.playerName)))
{
//Remove the .txt part for the name
scenarioNames[currentScenarioModule] = Path.GetFileNameWithoutExtension(file);
scenarioDataArray[currentScenarioModule] = File.ReadAllBytes(file);
currentScenarioModule++;
}
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.SCENARIO_DATA;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string[]>(scenarioNames);
foreach (byte[] scenarioData in scenarioDataArray)
{
if (client.compressionEnabled)
{
mw.Write<byte[]>(Compression.CompressIfNeeded(scenarioData));
}
else
{
mw.Write<byte[]>(Compression.AddCompressionHeader(scenarioData, false));
}
}
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:33,代码来源:ScenarioData.cs
示例6: PageUrlValidator
public PageUrlValidator(NameValueCollection queryString, DataManager manager)
{
_queryString = queryString;
_isValid = false;
_manager = manager;
_writer = new MessageWriter();
}
开发者ID:jirikadlec2,项目名称:hydrodata,代码行数:7,代码来源:pageurlvalidator.cs
示例7: WriteDescriptionTo
/// <summary>
/// Write the constraint description to a MessageWriter
/// </summary>
/// <param name="writer">The writer on which the description is displayed</param>
public override void WriteDescriptionTo(MessageWriter writer)
{
writer.WritePredicate("String ending with");
writer.WriteExpectedValue(expected);
if (this.caseInsensitive)
writer.WriteModifier("ignoring case");
}
开发者ID:Unity-Technologies,项目名称:nunitv2,代码行数:11,代码来源:EndsWithConstraint.cs
示例8: Load
public void Load()
{
if (savedVessel != null && savedSubspace != null)
{
if ((UnityEngine.Time.realtimeSinceStartup - lastLoadTime) > 5f)
{
lastLoadTime = UnityEngine.Time.realtimeSinceStartup;
TimeSyncer.fetch.UnlockSubspace();
long serverClock = TimeSyncer.fetch.GetServerClock();
int newSubspace = TimeSyncer.fetch.LockNewSubspace(serverClock, savedSubspace.planetTime, savedSubspace.subspaceSpeed);
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)WarpMessageType.NEW_SUBSPACE);
mw.Write<string>(Settings.fetch.playerName);
mw.Write<int>(newSubspace);
mw.Write<long>(serverClock);
mw.Write<double>(savedSubspace.planetTime);
mw.Write<float>(savedSubspace.subspaceSpeed);
NetworkWorker.fetch.SendWarpMessage(mw.GetMessageBytes());
}
TimeSyncer.fetch.LockSubspace(newSubspace);
VesselWorker.fetch.LoadVessel(savedVessel);
ScreenMessages.PostScreenMessage("Quickloaded!", 3f, ScreenMessageStyle.UPPER_CENTER);
}
}
else
{
ScreenMessages.PostScreenMessage("No current quicksave to load from!", 3f, ScreenMessageStyle.UPPER_CENTER);
}
}
开发者ID:JoshBlake,项目名称:DarkMultiPlayer,代码行数:30,代码来源:QuickSaveLoader.cs
示例9: WriteDescriptionTo
public override void WriteDescriptionTo(MessageWriter writer)
{
foreach (var msg in messages)
{
msg.Invoke(writer);
}
}
开发者ID:brianhartsock,项目名称:powershell-rackspaceapps,代码行数:7,代码来源:SignatureConstraint.cs
示例10: RunNukeKSC
public static void RunNukeKSC(string commandText)
{
lock (Server.universeSizeLock)
{
string[] vesselList = Directory.GetFiles(Path.Combine(Server.universeDirectory, "Vessels"));
int numberOfRemovals = 0;
foreach (string vesselFile in vesselList)
{
string vesselID = Path.GetFileNameWithoutExtension(vesselFile);
bool landedAtKSC = false;
bool landedAtRunway = false;
using (StreamReader sr = new StreamReader(vesselFile))
{
string currentLine = sr.ReadLine();
while (currentLine != null && !landedAtKSC && !landedAtRunway)
{
string trimmedLine = currentLine.Trim();
if (trimmedLine.StartsWith("landedAt = "))
{
string landedAt = trimmedLine.Substring(trimmedLine.IndexOf("=") + 2);
if (landedAt == "KSC")
{
landedAtKSC = true;
}
if (landedAt == "Runway")
{
landedAtRunway = true;
}
}
currentLine = sr.ReadLine();
}
}
if (landedAtKSC | landedAtRunway)
{
DarkLog.Normal("Removing vessel: " + vesselID);
//Delete it from the universe
if (File.Exists(vesselFile))
{
File.Delete(vesselFile);
}
//Send a vessel remove message
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.VESSEL_REMOVE;
using (MessageWriter mw = new MessageWriter())
{
//Send it with a delete time of 0 so it shows up for all players.
mw.Write<int>(0);
mw.Write<double>(0);
mw.Write<string>(vesselID);
mw.Write<bool>(false);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToAll(null, newMessage, false);
numberOfRemovals++;
}
}
DarkLog.Normal("Nuked " + numberOfRemovals + " vessels around the KSC");
}
}
开发者ID:martindevans,项目名称:DarkMultiPlayer,代码行数:59,代码来源:NukeKSC.cs
示例11: WriteCommand
/// <summary>
/// Writes the <see cref="BuyBuildingCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="BuyBuildingCommand"/>.
/// </param>
public override void WriteCommand(MessageWriter writer)
{
writer.Write(X);
writer.Write(Y);
writer.Write(BuildingDataIndex);
writer.Write(Unknown1);
}
开发者ID:circa94,项目名称:CoCSharp,代码行数:14,代码来源:BuyBuildingCommand.cs
示例12: WriteCommand
/// <summary>
/// Writes the <see cref="BuyDecoration"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="BuyDecoration"/>.
/// </param>
public override void WriteCommand(MessageWriter writer)
{
writer.Write(X);
writer.Write(Y);
writer.Write(DecorationDataIndex);
writer.Write(Unknown1);
}
开发者ID:circa94,项目名称:CoCSharp,代码行数:14,代码来源:BuyDecoration.cs
示例13: HandleAsync
public async Task<StreamResponse> HandleAsync(MessageWriter messageWriter, CancellationToken cancellationToken)
{
if (messageWriter == null)
{
throw new ArgumentNullException("messageWriter");
}
if (cancellationToken == null)
{
throw new ArgumentNullException("cancellationToken");
}
this.messageWriter = messageWriter;
log.Trace("HandleAsync: '{0}' JobId: '{1}''", request.Handle, request.JobId);
StreamResponse streamResponse = null;
Job job = GetJobById(request.JobId, ref streamResponse); // if job is null, streamResponse is set to error
if (job != null)
{
if (job.HasStatus)
{
var awaitables = new List<Task>();
foreach (IJobStatus status in job.RetrieveStatus())
{
awaitables.Add(ListenStatusAsync(status));
}
await Task.WhenAll(awaitables);
}
try
{
if (job.IsCompleted)
{
if (job.Result == null)
{
streamResponse = ToStreamResponse(GetResponseData(true, "Error! Job with ID '{0}' is completed but no result is available!\n", request.JobId));
}
else
{
streamResponse = ToStreamResponse(job.Result);
}
}
else
{
job.AttachListener(this);
IJobResult result = await job.ListenAsync();
streamResponse = StreamResponse.Create(result.ExitCode);
}
}
finally
{
jobManager.RemoveJob(request.JobId);
}
}
return streamResponse;
}
开发者ID:kirannadell,项目名称:ironfoundry,代码行数:58,代码来源:StreamRequestHandler.cs
示例14: WriteDescriptionTo
public override void WriteDescriptionTo(MessageWriter writer)
{
if (!(actual is SilverFunction)) {
writer.WriteLine("Expected SilverFunction, but got {0} instead", actual.GetType());
}
else {
writer.WriteLine("Expected {0}, but got {1} instead", actual, Expected);
}
}
开发者ID:shadowphoenix,项目名称:IronSilver,代码行数:9,代码来源:FunctionConstraint.cs
示例15: WriteActualValueTo
public override void WriteActualValueTo(MessageWriter writer)
{
if (this.propertyExists) {
writer.WriteActualValue(this.propValue);
}
else {
writer.WriteActualValue(String.Format("The property {0} was not found on type {1}", name, base.actual.GetType()));
}
}
开发者ID:mbsky,项目名称:dotnetmarcheproject,代码行数:9,代码来源:MyPropertyConstraint.cs
示例16: Write_WritesMessageToStorage
public void Write_WritesMessageToStorage()
{
var message = new Message("This is my message");
var mockStorage = Substitute.For<IPersistentStorage>();
var messageWriter = new MessageWriter(mockStorage);
messageWriter.Write(message);
mockStorage.Received(1).Write(Arg.Any<byte[]>());
}
开发者ID:alexjneves,项目名称:SoftwareEngineeringTechniques,代码行数:11,代码来源:InversionOfControlUsage.cs
示例17: SendConnectionEnd
public static void SendConnectionEnd(ClientObject client, string reason)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.CONNECTION_END;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(reason);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
开发者ID:Opice,项目名称:DarkMultiPlayer,代码行数:11,代码来源:ConnectionEnd.cs
示例18: WriteMessage
/// <summary>
/// Writes the <see cref="OwnHomeDataMessage"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="OwnHomeDataMessage"/>.
/// </param>
public override void WriteMessage(MessageWriter writer)
{
if (OwnAvatarData == null) // quit early just not to mess up the stream
throw new NullReferenceException("OwnAvatarData was null.");
writer.Write((int)LastVisit.TotalSeconds);
writer.Write(Unknown1); // -1
writer.Write((int)DateTimeConverter.ToUnixTimestamp(Timestamp));
OwnAvatarData.Write(writer);
}
开发者ID:circa94,项目名称:CoCSharp,代码行数:17,代码来源:OwnHomeDataMessage.cs
示例19: WriteCommand
/// <summary>
/// Writes the <see cref="MoveVillageObjectCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="MoveVillageObjectCommand"/>.
/// </param>
/// <exception cref="NullReferenceException">MoveData is null.</exception>
public override void WriteCommand(MessageWriter writer)
{
if (MoveData == null)
throw new NullReferenceException("MoveData cannot be null");
writer.Write(MoveData.X);
writer.Write(MoveData.Y);
writer.Write(MoveData.VillageObjectGameIndex);
writer.Write(Unknown1);
}
开发者ID:circa94,项目名称:CoCSharp,代码行数:18,代码来源:MoveVillageObjectCommand.cs
示例20: WriteMessage
/// <summary>
/// Writes the <see cref="NewClientEncryptionMessage"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="NewClientEncryptionMessage"/>.
/// </param>
public override void WriteMessage(MessageWriter writer)
{
writer.Write(Unknown1);
writer.Write(Unknown2);
writer.Write(MajorVersion);
writer.Write(Unknown4);
writer.Write(MinorVersion);
writer.Write(Hash);
writer.Write(Unknown6);
writer.Write(Unknown7);
}
开发者ID:circa94,项目名称:CoCSharp,代码行数:17,代码来源:NewClientEncryptionMessage.cs
注:本文中的MessageWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论