public void ObjectReaderWriterUpdateTest()
        {
            ObjectReaderWriter rw     = new ObjectReaderWriter(".\\{0}"._Format(MethodBase.GetCurrentMethod().Name));
            string             random = "RandomString_".RandomLetters(5);
            Parent             one    = new Parent {
                Name = "{0}:: Parent Name one"._Format(random)
            };

            rw.Write(typeof(Parent), one);

            Thread.Sleep(1500);             // does a non blocking write of properties

            Parent[] parents = rw.QueryProperty <Parent>("Name", val =>
            {
                return(((string)val).StartsWith(random));
            });

            Expect.AreEqual(1, parents.Length);

            Parent check  = parents.First();
            string uuid   = check.Uuid;
            Parent parent = rw.Query <Parent>(p => p.Uuid.Equals(uuid)).FirstOrDefault();

            Expect.IsNotNull(parent);
            parent.Name = "Updated";
            rw.Write(typeof(Parent), parent);

            check = rw.Query <Parent>(p => p.Uuid.Equals(uuid)).FirstOrDefault();
            Expect.AreEqual("Updated", check.Name);

            rw.Delete(one);
        }
        public void ObjectReaderWriterQueryPropertyTest()
        {
            ObjectReaderWriter rw     = new ObjectReaderWriter(".\\{0}"._Format(MethodBase.GetCurrentMethod().Name));
            string             random = "RandomString_".RandomLetters(5);
            Parent             one    = new Parent {
                Name = "{0}:: Parent Name one"._Format(random)
            };
            Parent two = new Parent {
                Name = "{0}:: Parent Name two"._Format(random)
            };
            Parent three = new Parent {
                Name = "not this one"
            };

            rw.Write(typeof(Parent), one);
            rw.Write(typeof(Parent), two);
            Thread.Sleep(1500);             // does a non blocking write of properties
            Parent[] parents = rw.QueryProperty <Parent>("Name", val =>
            {
                return(((string)val).StartsWith(random));
            });

            Expect.AreEqual(2, parents.Length);
            parents.Each(p =>
            {
                OutLine(p.Name);
            });

            rw.Delete(one);
            rw.Delete(two);
            rw.Delete(three);
        }
Esempio n. 3
0
        private async Task ServerAsync(CancellationToken cancellationToken)
        {
            using (Logger.BeginScope($"{nameof(ServerAsync)}"))
            {
                Logger.LogInformation($"Begin pipe server.\r\n{PipeNameLogString}");
                while (true)
                {
                    using (var stream = new NamedPipeServerStream(PipeName, PipeDirection.InOut, NumberOfServerInstances))
                    {
                        Logger.LogDebug($"Wait for connection.");
                        await stream.WaitForConnectionAsync(cancellationToken);

                        Logger.LogDebug($"Connected to pipe client.");

                        var request = ObjectReaderWriter.ReadObject <TIn>(stream);

                        var response = Func(request);

                        ObjectReaderWriter.WriteObject(stream, response);

                        Logger.LogInformation($"End connection.\r\n{PipeNameLogString}");
                    }
                }
            }
        }
        public void ObjectReaderWriterQueryTest()
        {
            ObjectReaderWriter rw     = new ObjectReaderWriter(".\\TESTOBJECTREADERWRITER");
            string             random = "RandomString_".RandomLetters(8);
            Parent             one    = new Parent {
                Name = "{0}:: Parent One"._Format(random)
            };
            Parent two = new Parent {
                Name = "{0}::Parent Two"._Format(random)
            };
            Parent three = new Parent {
                Name = "not this one"
            };

            rw.Write(typeof(Parent), one);
            rw.Write(typeof(Parent), two);
            rw.Write(typeof(Parent), three);

            Parent[] parents = rw.Query <Parent>(p => p.Name.StartsWith(random));
            Expect.AreEqual(2, parents.Length);
            parents.Each(p =>
            {
                OutLine(p.Name);
            });
            rw.Delete(one);
            rw.Delete(two);
            rw.Delete(three);
        }
Esempio n. 5
0
        private TIn GetResponse(NamedPipeClientStream stream, TOut request)
        {
            ObjectReaderWriter.WriteObject(stream, request);

            var response = ObjectReaderWriter.ReadObject <TIn>(stream);

            Logger.LogInformation($"End connection.\r\n{ConnectionLogString}");

            return(response);
        }