private static IntPtr[] GetPtrs() { if (Multithread) { long[] Arr = Ptrs.ToArray(); IntPtr[] Rst = new IntPtr[Arr.LongLength]; for (long i = 0; i < Rst.LongLength; i++) { Rst[i] = new IntPtr(Arr[i]); } return(Rst); } PipeWriter.Write((byte)PipeCommands.GetPtrs); PipeWriter.Flush(); long Count = PipeReader.ReadInt64(); IntPtr[] RstPtrs = new IntPtr[Count]; for (long i = 0; i < Count; i++) { RstPtrs[i] = new IntPtr(PipeReader.ReadInt64()); } return(RstPtrs); }
private static void EndPipe() { if (Multithread) { return; } PipeWriter.Write((byte)PipeCommands.EndPipe); PipeWriter.Flush(); }
private static bool ContainsMissed(string Line) { if (Multithread) { return(Missed.Contains(Line)); } PipeWriter.Write((byte)PipeCommands.FindMissed); PipeWriter.Write(Line); PipeWriter.Flush(); return(PipeReader.ReadByte() == (byte)PipeCommands.True); }
private static void AddEntry(string Key, string Value) { if (Multithread) { StrRld.Add(Key, Value); return; } PipeWriter.Write((byte)PipeCommands.AddReload); PipeWriter.Write(Key); PipeWriter.Write(Value); PipeWriter.Flush(); }
private static void AddMask(string ReadMask, string WriteMask) { if (Multithread) { MskRld.Add(ReadMask, WriteMask); return; } PipeWriter.Write((byte)PipeCommands.AddMask); PipeWriter.Write(ReadMask); PipeWriter.Write(WriteMask); PipeWriter.Flush(); }
private static string ProcessMask(string Original) { if (Multithread) { string Mask = (from x in MskRld.Keys where MaskMatch(x, Original) select x).FirstOrDefault(); return(MaskReplace(Mask, Original, MskRld[Mask])); } PipeWriter.Write((byte)PipeCommands.RldMask); PipeWriter.Write(Original); PipeWriter.Flush(); return(PipeReader.ReadString()); }
private static string GetEntry(string Key) { if (Multithread) { if (StrRld.ContainsKey(Key)) { return(StrRld[Key]); } string Result = string.Empty; for (DBID = 0; DBID < Databases.Count; DBID++) { if (StrRld.ContainsKey(Key)) { Result = StrRld[Key]; break; } } if (Debugging) { Log("Database Changed to {0}, ID: {1}", true, GetDBNameById(DBID), DBID); } return(Result); } int OID = 0; if (Debugging) { OID = GetDBID(); } PipeWriter.Write((byte)PipeCommands.GetReload); PipeWriter.Write(Key); PipeWriter.Flush(); string Return = PipeReader.ReadString(); if (Debugging) { int NID = GetDBID(); if (OID != NID) { Log("Database Changed to {0}, ID: {1}", true, GetDBNameById(NID), NID); } } return(Return); }
private static void AddMissed(string Line) { if (Multithread) { if (!Missed.Contains(Line)) { Missed.Add(Line); } return; } PipeWriter.Write((byte)PipeCommands.AddMissed); PipeWriter.Write(Line); PipeWriter.Flush(); }
private static int GetCurrentDBIndex() { if (!AllowDuplicates) { return(-1); } if (Multithread) { return(((DuplicableDictionary <string, string>)StrRld).LastKeyIndex); } PipeWriter.Write((byte)PipeCommands.GetDBIndex); PipeWriter.Flush(); return(PipeReader.ReadInt32()); }
private static void FinishDatabase() { if (Multithread) { if (DBID >= Databases.Count) { return; } LastDBID++; DBID = LastDBID; return; } PipeWriter.Write((byte)PipeCommands.AdvDB); PipeWriter.Flush(); }
private static void SetDBID(int ID) { if (Debugging) { Log("Database Changed to {0}, ID: {1}", true, GetDBNameById(ID), ID); } if (Multithread) { DBID = ID; return; } PipeWriter.Write((byte)PipeCommands.SetDBID); PipeWriter.Write(ID); PipeWriter.Flush(); }
private static void AddPtr(IntPtr Ptr) { long Pointer = Ptr.ToInt64(); if (Multithread) { if (!Ptrs.Contains(Pointer)) { Ptrs.Add(Pointer); } return; } PipeWriter.Write((byte)PipeCommands.AddPtr); PipeWriter.Write(Pointer); PipeWriter.Flush(); }
private static async Task TcpReaderAsync(PipeWriter writer, string host, int port) { const int minimumBufferSize = 512; using (TcpClient client = new TcpClient()) { Console.WriteLine("Connecting to server."); await client.ConnectAsync(host, port); Console.WriteLine("Connected."); using (NetworkStream stream = client.GetStream()) { while (true) { try { Memory <byte> memory = writer.GetMemory(minimumBufferSize); int read = await stream.ReadAsync(memory); if (read == 0) { break; } writer.Advance(read); Console.WriteLine($"Read from stream {read} bytes"); } catch { break; } // Make the data available to the PipeReader if (!await writer.Flush()) { break; } } Console.WriteLine("Message was read"); } } writer.Complete(); }
private static bool ValidateMask(string String) { if (Multithread) { string[] Result = (from x in MskRld.Keys where MaskMatch(x, String) select x).ToArray(); if (Result.Length > 0) { return(true); } return(false); } PipeWriter.Write((byte)PipeCommands.ChkMask); PipeWriter.Write(String); PipeWriter.Flush(); return(PipeReader.ReadByte() == (byte)PipeCommands.True); }
// LiveViewUpdated() is called from the canon sdk wrapper when a new image is read from the camera and is ready for processing // LiveViewUpdated() writes the image to the anonymous memory pipe. // An IO error will terminate the application. // Depth Of Field Preview mode is also enabled after the first received image (to avoid a black screen) private void LiveViewUpdated(Stream img) { // Check if first image if (!LiveViewUpdating) { Console.WriteLine("Received first image from camera. Enabling Depth of Field Preview."); // Enable Depth of Field Preview mode for auto focus // Enabling it now seems to work better than right after calling StartLiveView() (for some reason) CameraWrapper.SetSetting(EDSDK.PropID_Evf_DepthOfFieldPreview, 1); LiveViewUpdating = true; } if (PipeClient.IsConnected) { try { // Protocol: int32 [image length] + length amount of image data in bytes int written; int length = (int)img.Length; if (length <= 0) { return; } byte[] buffer = new byte[length]; PipeWriter.Write(length); while ((written = img.Read(buffer, 0, buffer.Length)) != 0) { PipeWriter.Write(buffer, 0, written); } PipeWriter.Flush(); } catch (IOException e) { Console.WriteLine("Pipe error: {0}", e.Message); CloseCamera(); Application.Exit(); } } else { Console.WriteLine("Pipe disconnected during image update, exiting..."); CloseCamera(); Application.Exit(); } }
private static bool ContainsKey(string Line, bool EnforceAtualDatabase = false) { if (Multithread) { if (StrRld.ContainsKey(Line)) { return(true); } if (EnforceAtualDatabase) { return(false); } return((from x in Databases where x.ContainsKey(Line) select x).Count() > 0); } PipeWriter.Write((byte)PipeCommands.FindReload); PipeWriter.Write((byte)(EnforceAtualDatabase ? PipeCommands.True : PipeCommands.False)); PipeWriter.Write(Line); PipeWriter.Flush(); return(PipeReader.ReadByte() == (byte)PipeCommands.True); }
private static async Task FillPipeAsync(PipeWriter writer, string path) { const int minimumBufferSize = 512; // This turns off internal file stream buffering using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize: 1)) { while (true) { try { Memory <byte> memory = writer.GetMemory(minimumBufferSize); int readBytes = await fileStream.ReadAsync(memory); if (readBytes == 0) { break; } writer.Advance(readBytes); // Make the data available to the PipeReader if (!await writer.Flush()) { break; } } catch (Exception ex) { writer.Complete(ex); break; } } } writer.Complete(); }
private static int GetDBID() { PipeWriter.Write((byte)PipeCommands.GetDBID); PipeWriter.Flush(); return(PipeReader.ReadInt32()); }