public static bool InputFieldTwoWay <T>(CompositeDisposable cd, IEngine engine, InputField mid, IWriteable <T> dst, Func <string, T> dstConverter, IReadable <T> src, Func <T, string> srcConverter) { if (!mid) { return(NotBinded()); } engine.Reader(cd, new object[] { src }, () => { if (Equals(dstConverter(mid.text), src.Read())) { return; } mid.text = srcConverter(src.Read()); }); UnityAction <string> action = text => { if (srcConverter(src.Read()) == text) { return; } dst.Write(dstConverter(text)); }; mid.onValueChanged.AddListener(action); cd.Add(new DisposableAction(() => mid.onValueChanged.RemoveListener(action))); return(true); }
/// <summary> /// 计算 md5,可以通过 u32p 传入初始参数,以定制自定义的 md5 算法. /// </summary> /// <param name="input">输入.</param> /// <param name="size">输入的长度(字节数).</param> /// <param name="buffer">缓冲区,必须是 64 字节或以上.</param> /// <param name="pio">可以通过 pio 传入初始参数,以定制自定义的 md5 算法,同时以此输出结果,结果一定是 16 个字节的,请传入一个 16 字节或以上的指针.</param> public unsafe static void __MD5(IReadable input, ulong size, byte[] buffer, void *pio) { // 分组相关常量: 分组大小(位数)的宽度,分组大小(位数),分组余数掩码 const int GROUP_SIZE_WIDTH = 6; const int GROUP_SIZE = 0x00000001 << GROUP_SIZE_WIDTH; const int GROUP_SIZE_MASK = GROUP_SIZE - 1; const int DATA_SIZE_SIZE = sizeof(ulong); // 完整分组数目 ulong groupCount = size >> GROUP_SIZE_WIDTH; // 不足一组的字节数 int remain = (int)(size) & GROUP_SIZE_MASK; // 用于以 UInt32 操作数据的指针 fixed(byte *pInput = buffer) { uint *M = (uint *)pInput; uint *u32p = (uint *)pio; // 当设置好这四个链接变量后,就开始进入算法的四轮循环运算。循环的次数是信息中512位信息分组的数目。 // 将上面四个链接变量复制到另外四个变量中:A到a,B到b,C到c,D到d。 for (ulong index = 0; index < groupCount; ++index) { input.Read(buffer, 0, GROUP_SIZE); ProcessGroup(M, u32p); } int i = input.Read(buffer, 0, remain); buffer[i++] = 0x80; if (i > (GROUP_SIZE - DATA_SIZE_SIZE)) { while (i < GROUP_SIZE) { buffer[i++] = 0x00; } ProcessGroup(M, u32p); i = 0; } while (i < (GROUP_SIZE - DATA_SIZE_SIZE)) { buffer[i++] = 0x00; } *((ulong *)(pInput + i)) = ((ulong)size) << 3; ProcessGroup(M, u32p); //uint* pUintResult = (uint*)pResult; //pUintResult[0] = a; //pUintResult[1] = b; //pUintResult[2] = c; //pUintResult[3] = d; } }
public static byte[] ReadByteArray(this IReadable input, int length) { var v = new byte[length]; input.Read(v, 0, length); return(v); }
public static double GpReadDouble(this IReadable data) { var bytes = new byte[8]; data.Read(bytes, 0, bytes.Length); return(Platform.Platform.ToDouble(bytes)); }
public static bool Tabs <T>(CompositeDisposable cd, IEngine engine, Map map, string[] tabs, string[] toggles, IWriteable <T> dst, Func <string, T> dstConverter, IReadable <T> src, Func <T, string> srcConverter) { engine.Reader(cd, Dep.On(src), () => { string selected = srcConverter(src.Read()); for (int i = 0, n = tabs.Length; i < n; ++i) { // TODO Fade animation map.Get(tabs[i]).SetActive(tabs[i] == selected); } }); for (int i = 0, n = toggles.Length; i < n; ++i) { string tab = tabs[i]; string toggle = toggles[i]; ToggleIsOn(cd, engine, map.GetComponent <Toggle>(toggles[i]), src, t => srcConverter(t) == tab ); ToggleChange(cd, engine, map.GetComponent <Toggle>(toggles[i]), b => { if (b) { dst.Write(dstConverter(tab)); } } ); } return(true); }
private static float[] LoadSamples(RiffChunk chunk, IReadable reader) { var samplesLeft = (int)(chunk.Size / 2); var samples = new float[samplesLeft]; var samplesPos = 0; var sampleBuffer = new byte[2048]; var testBuffer = new short[sampleBuffer.Length / 2]; while (samplesLeft > 0) { var samplesToRead = (int)Math.Min(samplesLeft, sampleBuffer.Length / 2); reader.Read(sampleBuffer, 0, samplesToRead * 2); for (var i = 0; i < samplesToRead; i++) { testBuffer[i] = Platform.ToInt16((sampleBuffer[(i * 2) + 1] << 8) | sampleBuffer[(i * 2)]); samples[samplesPos + i] = testBuffer[i] / 32767f; } samplesLeft -= samplesToRead; samplesPos += samplesToRead; } return(samples); }
public override IEnumerator GetRoutine() { var particle = particleProvider.Read().GetInstance(); particle.Play(); yield break; }
public T Read() { string text = Reader.Read(); T readedObject = new JsonDeserializer().Deserialize <T>(text); return(readedObject); }
public override IEnumerator GetRoutine() { var audioSource = audioSourceProvider.Read().GetInstance(); audioBundle.AssignTo(audioSource); audioSource.Play(); yield break; }
protected void HandlePacket(ClientGamePacket packet) { IReadable message = MessageManager.GetMessage(packet.Opcode); if (message == null) { log.Warn($"Received unknown packet {packet.Opcode:X}"); return; } MessageHandlerDelegate handlerInfo = MessageManager.GetMessageHandler(packet.Opcode); if (handlerInfo == null) { log.Warn($"Received unhandled packet {packet.Opcode}(0x{packet.Opcode:X})."); return; } if (packet.Opcode != GameMessageOpcode.ClientEncrypted && packet.Opcode != GameMessageOpcode.ClientPacked && packet.Opcode != GameMessageOpcode.ClientPackedWorld && packet.Opcode != GameMessageOpcode.ClientEntityCommand) { log.Trace($"Received packet {packet.Opcode}(0x{packet.Opcode:X})."); } // FIXME workaround for now. possible performance impact. // ClientPing does not currently work and the session times out after 300s -> this keeps the session alive if -any- client packet is received Heartbeat.OnHeartbeat(); using (var stream = new MemoryStream(packet.Data)) using (var reader = new GamePacketReader(stream)) { message.Read(reader); if (reader.BytesRemaining > 0) { log.Warn($"Failed to read entire contents of packet {packet.Opcode}"); } try { handlerInfo.Invoke(this, message); } catch (InvalidPacketValueException exception) { log.Error(exception); RequestedDisconnect = true; } catch (Exception exception) { log.Error(exception); } } }
public void Read() { try { var value = readableSource.Read(); } catch (Exception ex) { Console.WriteLine(ex); } }
public Tree Read(int a_size) { i_size = a_size; if (i_size > 0) { if (i_orderOnRead) { Tree tree = null; for (int i = 0; i < i_size; i++) { tree = Tree.Add(tree, (Tree)i_template.Read(i_bytes)); } return(tree); } while ((1 << i_levels) < (i_size + 1)) { i_levels++; } return(LinkUp(null, i_levels)); } return(null); }
public static void Read([NotNull] this IReadable readableMemory, [NotNull] IWritableMemory targetMemory) { if (readableMemory == null) { throw new ArgumentNullException(nameof(readableMemory)); } if (targetMemory == null) { throw new ArgumentNullException(nameof(targetMemory)); } readableMemory.Read(targetMemory.GetPointer(), 0, targetMemory.Size); }
public static void Run() { ReadableFactory readableFactory = new ReadableFactory(); // Book IReadable book = readableFactory.GetReadable(ReadableType.Book); book.Read("The beach", "Alex Garland", 124); // Magazine IReadable magazine = readableFactory.GetReadable(ReadableType.Magazine); magazine.Read("Men's Health", null, 48); }
public static bool Enabled(CompositeDisposable cd, IEngine engine, GameObject dst, IReadable <bool> src) { if (!dst) { return(NotBinded()); } engine.Reader(cd, new object[] { src }, () => dst.SetActive(src.Read()) ); return(true); }
private void HandlePacket(ClientGamePacket packet) { IReadable message = MessageManager.GetMessage(packet.Opcode); if (message == null) { log.Warn($"Received unknown packet {packet.Opcode:X}"); return; } MessageHandlerDelegate handlerInfo = MessageManager.GetMessageHandler(packet.Opcode); if (handlerInfo == null) { log.Warn($"Received unhandled packet {packet.Opcode}(0x{packet.Opcode:X})."); return; } if (packet.Opcode != GameMessageOpcode.ClientEncrypted && packet.Opcode != GameMessageOpcode.ClientPacked && packet.Opcode != GameMessageOpcode.ClientEntityCommand) { log.Trace($"Received packet {packet.Opcode}(0x{packet.Opcode:X})."); } using (var stream = new MemoryStream(packet.Data)) using (var reader = new GamePacketReader(stream)) { message.Read(reader); if (reader.BytesRemaining > 0) { log.Warn($"Failed to read entire contents of packet {packet.Opcode}"); } try { handlerInfo.Invoke(this, message); } catch (InvalidPacketValueException exception) { log.Error(exception); OnDisconnect(); } catch (Exception exception) { log.Error(exception); } } }
public static bool Interactable <T>(CompositeDisposable cd, IEngine engine, Selectable dst, IReadable <T> src, Func <T, bool> converter) { if (!dst) { return(NotBinded()); } engine.Reader(cd, new object[] { src }, () => dst.interactable = converter(src.Read()) ); return(true); }
private static void HandleUpdate(Session session, UpdateType updateType, byte[] payload, UpdateParameters parameters) { IReadable updatePacket = PacketManager.CreateUpdateMessage(updateType); if (updatePacket == null) { return; } using (var stream = new MemoryStream(payload)) using (var reader = new BinaryReader(stream)) updatePacket.Read(reader); PacketManager.InvokeUpdatePacketHandler(session, updateType, updatePacket, parameters); }
public static bool Label <T>(CompositeDisposable cd, IEngine engine, Text dst, IReadable <T> src, Func <T, string> converter) { if (!dst) { return(NotBinded()); } engine.Reader(cd, new object[] { src }, () => dst.text = converter(src.Read()) ); return(true); }
private void ProcessPacket(ClientPacket packet) { using var stream = new PacketCryptoStream(packet.Header.Seed, packet.Data); using var reader = new BinaryReader(stream); byte group = reader.ReadByte(); byte index = reader.ReadByte(); MessageOpcode opcode = (MessageOpcode)((group << 8) | index); IReadable message = MessageManager.Instance.GetMessage(opcode); if (message == null) { log.Warn($"Received unknown message {opcode}(0x{opcode:X})!"); return; } (MessageHandlerAttribute attribute, MessageHandlerDelegate @delegate) = MessageManager.Instance.GetMessageInformation(opcode); if (attribute == null) { log.Warn($"Received unhandled message {opcode}(0x{opcode:X})!"); return; } if (state != attribute.State) { log.Warn($"Received message {opcode}(0x{opcode:X}) while in an invalid state!"); return; } log.Trace($"Received message {opcode}(0x{opcode:X})."); message.Read(reader); if (reader.BaseStream.Remaining() > 0) { log.Warn($"Failed to read entire contents of message {opcode}(0x{opcode:X})!"); } try { @delegate.Invoke(this, message); } catch (Exception exception) { log.Error(exception); } }
public override bool Execute(CountInput input) { string inputFileName = input.InputFileName; string outputFileName = input.OutputFileName; IReadable reader = DependencyResolver.Container.GetInstance <IReadable>( new ExplicitArguments() .Set(inputFileName)); ISortable sorter = DependencyResolver.Container.GetInstance <ISortable>(); IPrintable printer = DependencyResolver.Container.GetInstance <IPrintable>( new ExplicitArguments() .Set(outputFileName) .Set(sorter.Sort(reader.Read()))); printer.Print(); return(true); }
private void HandlePacket(ClientStsPacket packet) { IReadable message = MessageManager.Instance.GetMessage(packet.Uri); if (message == null) { log.Info($"Received unknown packet {packet.Uri}"); return; } MessageHandlerInfo handlerInfo = MessageManager.Instance.GetMessageHandler(packet.Uri); if (handlerInfo == null) { log.Info($"Received unhandled packet {packet.Uri}"); return; } /*if (State != handlerInfo.State) * { * log.Info($"Received packet with invalid session state {packet.Uri}"); * return; * }*/ if (packet.Headers.TryGetValue("s", out string sequenceString)) { uint.TryParse(sequenceString, out sequence); } log.Trace($"Received packet {packet.Uri}."); if (packet.Body != "") { var doc = new XmlDocument(); doc.LoadXml(packet.Body); message.Read(doc); } handlerInfo.Delegate.Invoke(this, message); }
public static bool List <T>(CompositeDisposable cd, IEngine engine, Transform dst, Map prefab, IReadable <IList <T> > src, Action <CompositeDisposable, Map, T> itemBinder) { if (!dst || !prefab) { return(NotBinded()); } var createdGameObjects = new List <GameObject>(); var createdCd = new CompositeDisposable(); cd.Add(createdCd); engine.Reader(cd, new object[] { src }, () => { createdCd.Dispose(); for (int i = 0, n = createdGameObjects.Count; i < n; ++i) { UnityEngine.Object.Destroy(createdGameObjects[i]); } var items = src.Read(); for (int i = 0, n = items.Count; i < n; ++i) { var itemMap = UnityEngine.Object.Instantiate(prefab.gameObject, dst).GetComponent <Map>(); itemMap.gameObject.SetActive(true); var itemCd = new CompositeDisposable(); createdCd.Add(itemCd); itemBinder(itemCd, itemMap, items[i]); createdGameObjects.Add(itemMap.gameObject); } } ); return(true); }
private void ProcessRawPacket(byte[] payload) { using (var stream = new MemoryStream(payload)) using (var reader = new BinaryReader(stream)) { ClientRawOpcode opcode = (ClientRawOpcode)reader.ReadPackedUInt32(); IReadable packet = PacketManager.CreateRawMessage(opcode); if (packet == null) { return; } log.Trace($"Received raw packet {opcode}(0x{opcode:X})."); packet.Read(reader); if (stream.Remaining() > 0) { log.Warn($"Failed to read entire contents of packet {opcode}(0x{opcode:X})."); } PacketManager.InvokeRawMessageHandler(this, opcode, packet); } }
public static string Read8BitChars(this IReadable input, int length) { byte[] b = new byte[length]; input.Read(b, 0, b.Length); return(Platform.Platform.ToString(b, "utf-8")); }
public override int Read(byte[] buffer, int offset, int count) { return(_readable.Read(buffer, offset, count)); }
public void Print(IReadable readable) { Console.WriteLine(readable.Read()); }
static void Main(string[] args) { try { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddUserSecrets <Program>(); configurationBuilder.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json")); IConfigurationRoot configuration = configurationBuilder.Build(); DbContextOptionsBuilder <MedicContext> builder = new DbContextOptionsBuilder <MedicContext>(); builder.UseSqlServer(configuration[Constants.ConnectionString]); builder.EnableSensitiveDataLogging(); using MedicContext context = new MedicContext(builder.Options); IMedicContextSeeder medicContextSeeder = new MedicContextSeeder(context); medicContextSeeder.Seed(); AMapperConfiguration mapConfiguration = new AMapperConfiguration(); IMappable mapper = new AMapper(mapConfiguration.CreateConfiguration()); string cpDirectory, clprDirectory; bool doesCpDirectoryExist = true, doesCLPRDirectoryExist = true; while (true) { consoleWriter.Notify("Enter directory for CP files"); cpDirectory = consoleReader.Read(); consoleWriter.Notify("Enter directory for CLPR files"); clprDirectory = consoleReader.Read(); if (!string.IsNullOrWhiteSpace(cpDirectory)) { doesCpDirectoryExist = Directory.Exists(cpDirectory); } if (!string.IsNullOrWhiteSpace(clprDirectory)) { doesCLPRDirectoryExist = Directory.Exists(clprDirectory); } if (doesCpDirectoryExist && doesCLPRDirectoryExist) { break; } else { if (!doesCpDirectoryExist) { consoleWriter.Notify("CP directory does not exist."); } if (!doesCLPRDirectoryExist) { consoleWriter.Notify("CLPR directory does not exist."); } } doesCpDirectoryExist = true; doesCLPRDirectoryExist = true; } if (!string.IsNullOrWhiteSpace(cpDirectory)) { ReadCpFiles(mapper, builder, cpDirectory); } if (!string.IsNullOrWhiteSpace(clprDirectory)) { ReadCLPRFiles(mapper, builder, clprDirectory); } } catch (Exception ex) { Console.WriteLine(ex.Message); } consoleWriter.Notify("Press any key to exit."); Console.ReadKey(); }
public static void Read(this IReadable readable, string filename, FileMode mode = FileMode.OpenOrCreate) { using (FileStream fs = File.Open(filename, mode, FileAccess.Read)) { readable.Read(fs); } }
public static void Read(this IReadable readable, Stream stream) { using (StreamReader sr = new StreamReader(stream)) { readable.Read(sr); } }