public static CustomContent Create(string data, bool rewindable) { byte[] bytes = Encoding.UTF8.GetBytes(data); Stream stream = new CustomStream(bytes, rewindable); return(new CustomContent(stream, bytes.Length)); }
static void PlayKMCSound(String CustomSound, ref Boolean CustomSoundBool, Stream DefaultSound) { FileStream CustomStream = null; String CustomLnk = String.Format("{0}\\CustomSounds\\{1}.wav", Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.FullName, CustomSound); if (Properties.Settings.Default.AudioEvents) { if (File.Exists(CustomLnk)) { CustomSoundBool = true; CustomStream = new FileStream(CustomLnk, FileMode.Open); } else { CustomSoundBool = false; } Stream str = DefaultSound; System.Media.SoundPlayer player = new System.Media.SoundPlayer(CustomSoundBool ? CustomStream : str); player.Play(); str.Dispose(); if (File.Exists(CustomLnk)) { CustomStream.Dispose(); } } }
public static CustomContent Create(string data, bool rewindable) { byte[] bytes = Encoding.UTF8.GetBytes(data); Stream stream = new CustomStream(bytes, rewindable); return new CustomContent(stream, bytes.Length); }
private async void Check_OnClick(object sender, RoutedEventArgs e) { IsChecking = true; if (StreamUrl.ToLower().Contains(".mp3") || StreamUrl.ToLower().Contains(".wma") || StreamUrl.ToLower().Contains(".flac") || StreamUrl.ToLower().Contains(".wav")) { CurrentTrack = new CustomStream { StreamUrl = StreamUrl }; if (await CurrentTrack.CheckTrack()) { CanAddTrack = true; } else { System.Media.SystemSounds.Hand.Play(); CanAddTrack = false; } } else { System.Media.SystemSounds.Hand.Play(); CanAddTrack = false; } IsChecking = false; }
public async Task ReadUntilEndAsyncTests() { using var stream = new CustomStream(); var buffer = new byte[5]; await stream.ReadUntilCountOrEndAsync(buffer, 0, 5); Assert.Equal(new byte[] { 0, 1, 2, 0, 0 }, buffer); }
/// <summary> /// Modifies the stream for IronPython engine /// </summary> /// <param name="stream">Stream object to use</param> public static void PySetStreams(System.IO.Stream stream = null) { if (stream == null) { stream = new CustomStream(null); } ipy.SetStreams(stream); }
public void ReadUntilEndTests() { using var stream = new CustomStream(); var buffer = new byte[5]; stream.ReadUntilCountOrEnd(buffer, 0, 5); Assert.Equal(new byte[] { 0, 1, 2, 0, 0 }, buffer); }
/// <summary> /// Initializes the IronPython engine /// </summary> /// <param name="stream">IO stream to use</param> public static void PyInit(CustomStream stream = null) { if (stream == null) { stream = new CustomStream(null); } cstream = stream; ipy = new IPyEngine(cstream); ipy.LoadLibs("./core"); }
public override void Load(byte[] data) { using (CustomStream ms = new CustomStream(data)) { id = ms.ReadInt(); name = ms.ReadString(); p1 = ms.ReadInt(); p2 = ms.ReadFloat(); p3 = ms.ReadBoolean(); } }
/// <summary> /// Initializes a new instance of the <see cref="ObstacleDetector"/> class. /// </summary> /// <param name="vision"> /// The IDepthSteram vision stream /// </param> /// <param name="autoStart"> /// Whether or not the detector should start automatically /// </param> public ObstacleDetector(IImageStream vision, bool autoStart = true) { this.vision = vision; this.watchThread = new Thread(this.Watch); CStream = CustomStream.GetEdgeViewInstance(); if (autoStart) { Start(); } }
public async Task ReadToEndAsyncTests(bool canSeek) { using var stream = new MemoryStream(); Enumerable.Range(0, 5).ForEach(i => stream.WriteByte((byte)i)); stream.Seek(0, SeekOrigin.Begin); using var byteByByteStream = new CustomStream(stream, canSeek); var result = await byteByByteStream.ReadToEndAsync(); Assert.Equal(new byte[] { 0, 1, 2, 3, 4 }, result); }
public async Task TryReadAllAsyncTests(bool canSeek) { using var stream = new MemoryStream(); Enumerable.Range(0, 5).ForEach(i => stream.WriteByte((byte)i)); stream.Seek(0, SeekOrigin.Begin); using var byteByByteStream = new CustomStream(stream, canSeek); var buffer = new byte[5]; await byteByByteStream.TryReadAllAsync(buffer, 0, 5); Assert.Equal(new byte[] { 0, 1, 2, 3, 4 }, buffer); }
public override byte[] Save() { using (CustomStream ms = new CustomStream()) { ms.WriteInt(13 + 4 + name.Length); ms.WriteInt(id); ms.WriteString(name); ms.WriteInt(p1); ms.WriteFloat(p2); ms.WriteBoolean(p3); return(ms.ToArray()); } }
public void Should_20_not_allow_reread_after_write() { var msR = new MemoryStream(new byte[] { 1, 2, 3, 4 }); var msW = new MemoryStream(); var cs = new CustomStream(null, (_, b, p, c) => msW.Write(b, p, c), (_, b, p, c) => msR.Read(b, p, c)); var sut = new ReStream(cs); var buf = new byte[1024]; var a = sut.Read(buf, 1, 3); sut.Write(10, 20, 30, 40); sut.ResetReader(); }
List <T> ConvertByte2EntityList <T>(byte[] buffer) where T : BaseEntity { List <T> dataList = new List <T>(); using (CustomStream cs = new CustomStream(buffer)) { int count = cs.ReadInt(); for (int i = 0; i < count; i++) { int size = cs.ReadInt(); byte[] data = new byte[size]; cs.Read(data, 0, size); dataList.Add(BaseEntity.Instantiation(typeof(T), data) as T); } return(dataList); } }
private async void Check_OnClick(object sender, RoutedEventArgs e) { IsChecking = true; CurrentTrack = new CustomStream { StreamUrl = StreamUrl }; if (await CurrentTrack.CheckTrack()) { CanAddTrack = true; } else { System.Media.SystemSounds.Hand.Play(); CanAddTrack = false; } IsChecking = false; }
public void Should_20_read_buf_during_connecting_after_write() { var msR = new MemoryStream(new byte[] { 1, 2, 3 }); var msW = new MemoryStream(); var cs = new CustomStream(null, (_, b, p, c) => msW.Write(b, p, c), (_, b, p, c) => msR.Read(b, p, c)); var sut = new ReStream(cs); var buf = new byte[1024]; var a = sut.Read(buf, 1, 2); // 1 byte left in a buffer!! Assert.AreEqual(2, a); Assert.AreEqual(0, buf[0]); Assert.AreEqual(1, buf[1]); Assert.AreEqual(2, buf[2]); Assert.AreEqual(0, buf[3]); Assert.AreEqual(0, buf[4]); sut.Write(10, 20, 30, 40); msR = new MemoryStream(new byte[] { 4 }); a = sut.Read(buf, 3, 2); // read the last byte from buffer, not from the end of stream Assert.AreEqual(1, a); // just use current remained buffer first, then continue to read from underlying Assert.AreEqual(0, buf[0]); Assert.AreEqual(1, buf[1]); Assert.AreEqual(2, buf[2]); Assert.AreEqual(3, buf[3]); Assert.AreEqual(0, buf[4]); Assert.AreEqual(0, buf[5]); a = sut.Read(buf, 4, 2); // read the last byte from buffer, not from the end of stream Assert.AreEqual(1, a); // remained underlying Assert.AreEqual(0, buf[0]); Assert.AreEqual(1, buf[1]); Assert.AreEqual(2, buf[2]); Assert.AreEqual(3, buf[3]); Assert.AreEqual(4, buf[4]); Assert.AreEqual(0, buf[5]); }
public void LoadTxtSaveToData <T>(string loadPath, string savePath) where T : BaseEntity { string s1 = LoadTextFile(loadPath);//Application.streamingAssetsPath + @"\Table01.txt" List <T> dataList = ConvertString2EntityList <T>(s1); using (CustomStream cs = new CustomStream()) { cs.WriteInt(dataList.Count); for (int i = 0; i < dataList.Count; i++) { byte[] beBuffer = dataList[i].Save(); for (int j = 0; j < beBuffer.Length; j++) { cs.WriteByte(beBuffer[j]); } } byte[] buffer = cs.ToArray(); SaveToData(buffer, savePath); } }
private void ProcessFile(string filename, BinaryWriter outFile, Extractor item) { m_stderr.WriteLine("Processing " + filename); try { item.Open(isys_docfilters.IGR_BODY_AND_META | isys_docfilters.IGR_FORMAT_IMAGE); CustomStream outStream = new CustomStream(new MemoryStream()); Hyland.DocumentFilters.Canvas canvas = m_filters.MakeOutputCanvas(outStream, isys_docfilters.IGR_DEVICE_IMAGE_TIF, ""); try { for (int pageIndex = 0; pageIndex < item.GetPageCount(); pageIndex++) { Hyland.DocumentFilters.Page page = item.GetPage(pageIndex); try { canvas.RenderPage(page); } finally { page.Close(); } } } finally { canvas.Close(); // Write in-memory stream contents to existing open file (e.g. stdout) long BytesWritten = outStream.writeTo(outFile); m_stderr.WriteLine(BytesWritten + " bytes written to outFile"); } } catch (Exception e) { m_stderr.WriteLine("Error Processing " + filename); m_stderr.WriteLine(" - " + e.ToString()); } finally { item.Close(); } }
public Settings() { //initialize default values Data._GazeDelay = 2000; //initialize IImageStreams //initialize streams Data._streams = new List <IImageStream>(5); Data._streams.Add(VideoStream.Instance); Data._streams.Add(DepthStream.Instance); Data._streams.Add(InfraredStream.Instance); Data._streams.Add(CustomStream.GetEdgeViewInstance()); Data._streams.Add(CustomStream.GetHoughLineInstance()); //set initial background stream Data._BackgroundStream = Data.streams[0]; InitializeComponent(); GazeDelaySlider.Value = Data.GazeDelay / 1000; GazeDelayValue.Content = Data.GazeDelay / 1000; if (!Data.XboxConnected) { controller.IsEnabled = false; } if (!Data.EyeTribeConnected) { eyenav.IsEnabled = false; } for (int i = Data.streams.Count - 1; i >= 0; i--) { stringNames.Insert(0, Data.streams[i].GetName()); } //configure delay slider GazeDelaySlider.Minimum = 0.1; GazeDelaySlider.Maximum = 5; }