本文整理汇总了C#中Windows.Storage.Streams.DataWriter.WriteInt32方法的典型用法代码示例。如果您正苦于以下问题:C# DataWriter.WriteInt32方法的具体用法?C# DataWriter.WriteInt32怎么用?C# DataWriter.WriteInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.Streams.DataWriter
的用法示例。
在下文中一共展示了DataWriter.WriteInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAsync
public async Task SendAsync(string text)
{
try
{
// DataWriter to send message to client
var writer = new DataWriter(_socket.OutputStream);
//Encrypt message
byte[] data = Cryptographic.Encrypt(text, "123");
//Write Lenght message in buffer
writer.WriteInt32(data.Length);
//Write message in buffer
writer.WriteBytes(data);
//Send buffer
await writer.StoreAsync();
//Clear buffer
await writer.FlushAsync();
}
catch (Exception e)
{
InvokeOnError(e.Message);
}
}
示例2: SendSongOverSocket
//send song data over the socket
//this uses an app specific socket protocol: send title, artist, then song data
public async Task<bool> SendSongOverSocket(StreamSocket socket, string fileName, string songTitle, string songFileSize)
{
try
{
// Create DataWriter for writing to peer.
_dataWriter = new DataWriter(socket.OutputStream);
//send song title
await SendStringOverSocket(songTitle);
//send song file size
await SendStringOverSocket(songFileSize);
// read song from Isolated Storage and send it
using (var fileStream = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication()))
{
byte[] buffer = new byte[1024];
int bytesRead;
int readCount = 0;
_length = fileStream.Length;
//Initialize the User Interface elements
InitializeUI(fileName);
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
readCount += bytesRead;
//UpdateUI
UpdateProgressBar(readCount);
//size of the packet
_dataWriter.WriteInt32(bytesRead);
//packet data sent
_dataWriter.WriteBytes(buffer);
try
{
await _dataWriter.StoreAsync();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
return true;
}
catch
{
return false;
}
}
示例3: SaveTo
public static async void SaveTo ( ObservableCollection<RecentData> datas )
{
StorageFile sf = await ApplicationData.Current.LocalFolder.CreateFileAsync ( "data.dat",
Windows.Storage.CreationCollisionOption.ReplaceExisting );
FileRandomAccessStream stream = await sf.OpenAsync ( FileAccessMode.ReadWrite ) as FileRandomAccessStream;
DataWriter dw = new DataWriter ( stream );
dw.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
dw.ByteOrder = ByteOrder.LittleEndian;
dw.WriteInt32 ( datas.Count );
foreach ( RecentData data in datas )
{
dw.WriteUInt32 ( ( uint ) dw.MeasureString ( data.Source ) );
dw.WriteString ( data.Source );
dw.WriteInt32 ( data.SourceIndex );
dw.WriteInt32 ( data.TargetIndex );
}
await dw.StoreAsync ();
await dw.FlushAsync ();
stream.Dispose ();
}
示例4: Write
public void Write(DataWriter writer)
{
writer.WriteInt32((int)t);
writer.WriteDateTime(time);
writer.WriteInt64(cc);
writer.WriteInt64(asdf);
writer.WriteInt64(peak);
writer.WriteUInt64(max0);
writer.WriteUInt64(max1);
writer.WriteUInt64(ave0);
writer.WriteUInt64(ave1);
writer.WriteUInt64(ave);
writer.WriteUInt64(beat);
writer.WriteUInt64(noAudio);
writer.WriteUInt64(audio);
}
示例5: TransferImage
private async void TransferImage(StreamSocket socket)
{
var writer = new DataWriter(socket.OutputStream);
UpdateStatus("Übertrage Bild...");
// Anzahl der zu übertragenden Bytes übertragen
writer.WriteInt32(App.ImageBytesToTransfer.Length);
await writer.StoreAsync();
// Image-Bytes übertragen
writer.WriteBytes(App.ImageBytesToTransfer);
await writer.StoreAsync();
await writer.FlushAsync();
// Ressourcen freigeben
writer.Dispose();
UpdateStatus("Übertragung abgeschlossen");
}
示例6: Should_detect_corrupt_block_length
public async Task Should_detect_corrupt_block_length()
{
using (var input = new InMemoryRandomAccessStream())
{
await CopyData(input, "IO.HashedBlockStream.bin");
input.Seek(36);
var writer = new DataWriter(input)
{
ByteOrder = ByteOrder.LittleEndian,
};
writer.WriteInt32(-100);
await writer.StoreAsync();
input.Seek(0);
await Assert.ThrowsAsync<InvalidDataException>(
() => HashedBlockFileFormat.Read(input));
}
}
示例7: TransferPicture
private async void TransferPicture(StreamSocket socket)
{
// DataWriter erzeugen, um Byte-Umwandlung erledigen zu lassen...
var writer = new DataWriter(socket.OutputStream);
// Anzahl der zu übertragenden Bytes übertragen
writer.WriteInt32(App.PhotoBytesToShare.Length);
await writer.StoreAsync();
// Image-Bytes übertragen
writer.WriteBytes(App.PhotoBytesToShare);
await writer.StoreAsync();
await writer.FlushAsync();
UpdateStatus("Übertragung abgeschlossen.");
// Ressourcen freigeben
writer.Dispose();
socket.Dispose();
// Beenden der Annahme von Client-Verbindungen
_listener.Dispose();
}
示例8: TransferPicture_Click
private async void TransferPicture_Click(object sender, RoutedEventArgs e)
{
var selectedPeer = PeersList.SelectedItem as PeerInformation;
if (selectedPeer == null)
{
MessageBox.Show("Bitte Emfängergerät wählen");
return;
}
try
{
Status.Text = "Verbinde mit Peer...";
var peerSocket = await PeerFinder.ConnectAsync(selectedPeer);
var writer = new DataWriter(peerSocket.OutputStream);
Status.Text = "Verbunden. Übertrage Bild...";
// Anzahl der zu übertragenden Bytes übertragen
writer.WriteInt32(App.ImageBytesToTransfer.Length);
await writer.StoreAsync();
// Image-Bytes übertragen
writer.WriteBytes(App.ImageBytesToTransfer);
await writer.StoreAsync();
await writer.FlushAsync();
// Ressourcen freigeben
writer.Dispose();
peerSocket.Dispose();
Status.Text = "Übertragung abgeschlossen";
}
catch (Exception ex)
{
MessageBox.Show("Fehler: " + ex.Message);
Status.Text = "Bereit.";
}
}
示例9: beginexecblock
async void beginexecblock()
{
RenderContext mtext = new RenderContext();
maincontext = mtext;
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await folder.GetFileAsync("DXInteropLib\\VertexShader.cso");
var stream = (await file.OpenAsync(FileAccessMode.Read));
Windows.Storage.Streams.DataReader mreader = new Windows.Storage.Streams.DataReader(stream.GetInputStreamAt(0));
byte[] dgram = new byte[file.Size];
await mreader.LoadAsync((uint)dgram.Length);
mreader.ReadBytes(dgram);
file = await folder.GetFileAsync("DXInteropLib\\PixelShader.cso");
stream = await file.OpenAsync(FileAccessMode.Read);
mreader = new Windows.Storage.Streams.DataReader(stream.GetInputStreamAt(0));
byte[] mgram = new byte[file.Size];
await mreader.LoadAsync((uint)file.Size);
mreader.ReadBytes(mgram);
defaultshader = mtext.CreateShader(dgram, mgram);
mtext.InitializeLayout(dgram);
defaultshader.Apply();
mtext.OnRenderFrame += onrenderframe;
IStorageFile[] files = (await folder.GetFilesAsync()).ToArray();
bool founddata = false;
foreach (IStorageFile et in files)
{
if (et.FileName.Contains("rawimage.dat"))
{
stream = await et.OpenAsync(FileAccessMode.Read);
founddata = true;
}
}
int width;
int height;
byte[] rawdata;
if (!founddata)
{
file = await folder.GetFileAsync("TestProgram\\test.jpg");
stream = await file.OpenAsync(FileAccessMode.Read);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
var pixeldata = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Rgba8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.IgnoreExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.DoNotColorManage);
width = (int)decoder.PixelWidth;
height = (int)decoder.PixelHeight;
rawdata = pixeldata.DetachPixelData();
file = await folder.CreateFileAsync("rawimage.dat");
stream = (await file.OpenAsync(FileAccessMode.ReadWrite));
var realstream = stream.GetOutputStreamAt(0);
DataWriter mwriter = new DataWriter(realstream);
mwriter.WriteInt32(width);
mwriter.WriteInt32(height);
mwriter.WriteBytes(rawdata);
await mwriter.StoreAsync();
await realstream.FlushAsync();
}
else
{
DataReader treader = new DataReader(stream.GetInputStreamAt(0));
await treader.LoadAsync((uint)stream.Size);
rawdata = new byte[stream.Size-(sizeof(int)*2)];
width = treader.ReadInt32();
height = treader.ReadInt32();
treader.ReadBytes(rawdata);
}
Texture2D mtex = maincontext.createTexture2D(rawdata, width, height);
mtex.Draw();
#region Cube
List<VertexPositionNormalTexture> triangle = new List<VertexPositionNormalTexture>();
float z = 0;
triangle.Add(new VertexPositionNormalTexture(new Vector3(0,0,z),new Vector3(1,1,1),new Vector2(0,0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1,1,z),new Vector3(1,1,1),new Vector2(1,1)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(0,1,z),new Vector3(1,1,1),new Vector2(0,1)));
//Triangle 2
triangle.Add(new VertexPositionNormalTexture(new Vector3(0, 0, z), new Vector3(1, 1, 1), new Vector2(0, 0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1,0,z),new Vector3(1,1,1),new Vector2(1,0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 1, z), new Vector3(1, 1, 1), new Vector2(1, 1)));
// Triangle 3
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 0, z),new Vector3(1,1,1),new Vector2(0,0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 1, z+1), new Vector3(1, 1, 1), new Vector2(1, 1)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 0, z + 1), new Vector3(1, 1, 1), new Vector2(0, 1)));
//Triangle 4
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 0, z), new Vector3(1, 1, 1), new Vector2(0, 0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 1, z), new Vector3(1, 1, 1), new Vector2(1, 0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(1, 1, z + 1), new Vector3(1, 1, 1), new Vector2(1, 1)));
//Triangle 5
triangle.Add(new VertexPositionNormalTexture(new Vector3(0, 0, z), new Vector3(1, 1, 1), new Vector2(0, 0)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(0, 1, z + 1), new Vector3(1, 1, 1), new Vector2(1, 1)));
triangle.Add(new VertexPositionNormalTexture(new Vector3(0, 0, z + 1), new Vector3(1, 1, 1), new Vector2(0, 1)));
//Triangle 6
//.........这里部分代码省略.........
示例10: SendUsersList
/// <summary>
/// Broadcast clients number changed
/// </summary>
/// <param name="clientSocket"></param>
/// <param name="userName"></param>
/// <param name="changedUser"></param>
/// <param name="state"></param>
public async void SendUsersList(StreamSocket clientSocket, string userName, string changedUser, string state)
{
var data = new Data
{
Command = Command.Broadcast,
To = userName,
Message = string.Format("{0}|{1}|{2}|{3}",
string.Join(",", clients.Select(u => u.UserName).Where(name => name != userName)), changedUser, state,
serverName)
};
var dataWriter = new DataWriter(clientSocket.OutputStream);
var bytes = data.ToByte();
dataWriter.WriteInt32(bytes.Length);
dataWriter.WriteBytes(bytes);
await dataWriter.StoreAsync();
}
示例11: saveState
/// <summary>
/// Saves the current progress state for the current dictionary
/// </summary>
public void saveState()
{
if (string.IsNullOrEmpty(mCrammerDict.StateFile))
throw new Exception("No state file available");
try
{
using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
{
using (DataWriter dataWriter = new DataWriter(memoryStream))
{
dataWriter.WriteInt32(mTotalWords);
dataWriter.WriteInt32(mKnownWords);
dataWriter.WriteInt32(mStart);
dataWriter.WriteInt32(mCurrentWord);
dataWriter.WriteBoolean(mNewWordsInUse);
dataWriter.WriteInt32(mInSystem);
dataWriter.WriteBoolean(mSwapSequence);
dataWriter.WriteBoolean(mReachedEnd);
mNewWordsChamber.saveState(dataWriter);
mFirstChamber.saveState(dataWriter);
mSecondChamber.saveState(dataWriter);
mThirdChamber.saveState(dataWriter);
mFourthChamber.saveState(dataWriter);
mFifthChamber.saveState(dataWriter);
mCompletedChamber.saveState(dataWriter);
IBuffer stateBuffer = dataWriter.DetachBuffer();
string stateString = BinaryBufferConverter.getStringFromBuffer(stateBuffer);
mCrammerDict.setStateFile(stateString);
}
}
}
catch (Exception)
{
// Assume mismatch with chamber-size config and contents of .STA file.
// Delete it so that the dictionary will load successfully next time.
mCrammerDict.removeStateFile();
}
mRestoredState = true;
}
示例12: Send
public async void Send(byte[] fileBytes)
{
try
{
if (Speakers != null && Speakers.Count > 0 && fileBytes != null)
{
//iterate through the speakers and send out the media file to each speaker
foreach (Speaker speaker in Speakers)
{
StreamSocket socket = speaker.Socket;
if (socket != null)
{
IOutputStream outStream = socket.OutputStream;
using (DataWriter dataWriter = new DataWriter(outStream))
{
//write header bytes to indicate to the subscriber
//information about the file to be sent
dataWriter.WriteInt16((short)MessageType.Media);
dataWriter.WriteInt32(fileBytes.Length);
await dataWriter.StoreAsync();
//start from 0 and increase by packet size
int partNumber = 0;
int sourceIndex = 0;
int bytesToWrite = fileBytes.Length;
while (bytesToWrite > 0)
{
dataWriter.WriteInt32(partNumber);
int packetSize = bytesToWrite;
if (packetSize > MAX_PACKET_SIZE)
{
packetSize = MAX_PACKET_SIZE;
}
byte[] fragmentedPixels = new byte[packetSize];
Array.Copy(fileBytes, sourceIndex, fragmentedPixels, 0, packetSize);
dataWriter.WriteBytes(fragmentedPixels);
Debug.WriteLine("sent byte packet length " + packetSize);
await dataWriter.StoreAsync();
sourceIndex += packetSize;
bytesToWrite -= packetSize;
partNumber++;
Debug.WriteLine("sent total bytes " + (fileBytes.Length - bytesToWrite));
}
//Finally DetachStream
dataWriter.DetachStream();
}
}
}
//check the speakers have all received the file
foreach (Speaker speaker in Speakers)
{
StreamSocket socket = speaker.Socket;
if (socket != null)
{
//wait for the 'I got it' message
DataReader reader = new DataReader(socket.InputStream);
uint x = await reader.LoadAsync(sizeof(short));
MessageType t = (MessageType)reader.ReadInt16();
if (MessageType.Ready == t)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
Speakers.Remove(speaker);
speaker.Status = "Ready";
Speakers.Add(speaker);
});
}
reader.DetachStream();
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
示例13: BeepBeep
public async Task<IRandomAccessStream> BeepBeep(int Amplitude, int Frequency, int Duration)
{
double A = ((Amplitude * (System.Math.Pow(2, 15))) / 1000) - 1;
double DeltaFT = 2 * Math.PI * Frequency / 44100.0;
int Samples = 441 * Duration / 10;
int Bytes = Samples * 4;
int[] Hdr = { 0X46464952, 36 + Bytes, 0X45564157, 0X20746D66, 16, 0X20001, 44100, 176400, 0X100004, 0X61746164, Bytes };
InMemoryRandomAccessStream ims = new InMemoryRandomAccessStream();
IOutputStream outStream = ims.GetOutputStreamAt(0);
DataWriter dw = new DataWriter(outStream);
dw.ByteOrder = ByteOrder.LittleEndian;
for (int I = 0; I < Hdr.Length; I++)
{
dw.WriteInt32(Hdr[I]);
}
for (int T = 0; T < Samples; T++)
{
short Sample = System.Convert.ToInt16(A * Math.Sin(DeltaFT * T));
dw.WriteInt16(Sample);
dw.WriteInt16(Sample);
}
await dw.StoreAsync();
await outStream.FlushAsync();
return ims;
}
示例14: SendMessage
// Отправка сообщения
async private void SendMessage(StreamSocket socket, string message)
{
var writer = new DataWriter(socket.OutputStream);
var len = writer.MeasureString(message); // Gets the UTF-8 string length.
writer.WriteInt32((int)len);
writer.WriteString(message);
var ret = await writer.StoreAsync();
writer.DetachStream();
}
示例15: SaveModelAsync
/// <summary>
/// Save the model (family and their notes) to the app's isolated storage
/// </summary>
/// <remarks>
/// The data format for notes data:
///
/// Serialized model data (the people and the sticky notes)
/// For each sticky note
/// {
/// int32 number of inkstrokes for the note
/// }
/// All ink stroke data (for all notes) combined into one container
/// </remarks>
/// <returns></returns>
public async Task SaveModelAsync()
{
// Persist the model
StorageFile notesDataFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(NOTES_MODEL_FILE, CreationCollisionOption.ReplaceExisting);
using (Stream notesDataStream = await notesDataFile.OpenStreamForWriteAsync())
{
// Serialize the model which contains the people and the stickyNote collection
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Model));
serializer.WriteObject(notesDataStream, Model);
}
/* For each sticky note, save the number of inkstrokes it contains.
The function on the InkStrokeContainer that persists its contents is not designed
to save persist containers to the one stream. We also don't want to manage one
backing file per note. So combine the ink strokes into one container and persist that.
We'll seperate out the ink strokes to the right ink control by keeping track of how
many ink strokes belongs to each note */
InkStrokeContainer CombinedStrokes = new InkStrokeContainer();
StorageFile inkFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(NOTES_INK_FILE, CreationCollisionOption.ReplaceExisting);
using (var randomAccessStream = await inkFile.OpenAsync(FileAccessMode.ReadWrite))
{
using (IOutputStream inkStream = randomAccessStream.GetOutputStreamAt(0)) // DataWriter requires an IOutputStream
{
bool combinedStrokesHasContent = false; // whether we had any ink to save across all of the notes
DataWriter writer = new DataWriter(inkStream);
foreach (StickyNote Note in Model.StickyNotes)
{
// Save # strokes for this note
if (Note.Ink != null && Note.Ink.GetStrokes().Count > 0)
{
IReadOnlyList<InkStroke> InkStrokesInNote = Note.Ink.GetStrokes();
writer.WriteInt32(InkStrokesInNote.Count);
// capture the ink strokes into the combined container which will be saved at the end of the notes data file
foreach (InkStroke s in InkStrokesInNote)
{
CombinedStrokes.AddStroke(s.Clone());
}
combinedStrokesHasContent = true;
}
else
{
writer.WriteInt32(0); // not all notes have ink
}
}
await writer.StoreAsync(); // flush the data in the writer to the inkStream
// Persist the ink data
if (combinedStrokesHasContent )
{
await CombinedStrokes.SaveAsync(inkStream);
}
}
}
}