// writes a file to the project folder
 private static void WriteCodeFile()
 {
     Com.WriteCodeFile(FilePath, builder =>
     {
         WrappedInt indentCount = 0;
         builder.AppendIndentLine(indentCount, Com.AutoGenTemplate);
         builder.AppendIndentLine(indentCount, Com.NameSpaceTemplate);
         using (new CurlyIndent(builder, indentCount))
         {
             builder.AppendIndentFormatLine(indentCount, "public static class {0}", FileName);
             using (new CurlyIndent(builder, indentCount))
             {
                 foreach (string name in Com.names)
                 {
                     builder.AppendIndentFormatLine(indentCount, "private static string {0} = @\"{1}\";",
                                                    Com.MakeIdentifier(name), Com.EscapeDoubleQuote(name));
                     builder.AppendIndentFormatLine(indentCount,
                                                    "public static int {0} => UnityEngine.LayerMask.NameToLayer(" +
                                                    Com.MakeIdentifier(name) + ");\n", Com.MakeIdentifier("_" + name),
                                                    Com.EscapeDoubleQuote(name));
                 }
             }
         }
     });
 }
Exemplo n.º 2
0
        private static async Task RunClientAsync()
        {
            var pipeClient = new PipeClient <IAdder>("mypipe");

            pipeClient.SetLogger(message => Console.WriteLine(message));

            try
            {
                await pipeClient.ConnectAsync().ConfigureAwait(false);

                WrappedInt result = await pipeClient.InvokeAsync(adder => adder.AddWrappedNumbers(new WrappedInt {
                    Num = 1
                }, new WrappedInt {
                    Num = 3
                })).ConfigureAwait(false);

                Console.WriteLine("Server add result: " + result.Num);

                await pipeClient.WaitForRemotePipeCloseAsync();

                Console.WriteLine("Server closed pipe.");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception in pipe processing: " + exception);
            }
        }
Exemplo n.º 3
0
    public WrappedInt Clone()
    {
        WrappedInt r = new WrappedInt();

        r.Value = Value;
        return(r);
    }
Exemplo n.º 4
0
 public CurlyIndent(StringBuilder b, WrappedInt counter)
 {
     val     = counter;
     builder = b;
     builder.AppendIndentLine(val, "{");
     ++val;
 }
Exemplo n.º 5
0
    public static WrappedInt Wrap(int i)
    {
        WrappedInt des = new WrappedInt();

        des.Value = i;

        return(des);
    }
Exemplo n.º 6
0
        private static async Task RunClientAsync()
        {
            var rawStream = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut, PipeOptions.Asynchronous);
            var pipeClientWithCallback = new PipeClientWithCallback <IAdder, IConcatenator>(rawStream, () => new Concatenator());

            //var pipeClientWithCallback = new PipeClientWithCallback<IAdder, IConcatenator>("testpipe", () => new Concatenator());
            pipeClientWithCallback.SetLogger(message => Console.WriteLine(message));

            try
            {
                await pipeClientWithCallback.ConnectAsync().ConfigureAwait(false);

                WrappedInt result = await pipeClientWithCallback.InvokeAsync(adder => adder.AddWrappedNumbers(new WrappedInt {
                    Num = 1
                }, new WrappedInt {
                    Num = 3
                })).ConfigureAwait(false);

                Console.WriteLine("Server wrapped add result: " + result.Num);

                int asyncResult = await pipeClientWithCallback.InvokeAsync(adder => adder.AddAsync(4, 7)).ConfigureAwait(false);

                Console.WriteLine("Server async add result: " + asyncResult);

                IList <string> listifyResult = await pipeClientWithCallback.InvokeAsync(adder => adder.Listify("item")).ConfigureAwait(false);

                Console.WriteLine("Server listify result: " + listifyResult[0]);

                try
                {
                    await pipeClientWithCallback.InvokeAsync(adder => adder.AlwaysFails()).ConfigureAwait(false);
                }
                catch (PipeInvokeFailedException exception)
                {
                    Console.WriteLine("Handled invoke exception:" + Environment.NewLine + exception);
                }

                try
                {
                    int refValue = 4;
                    await pipeClientWithCallback.InvokeAsync(adder => adder.HasRefParam(ref refValue)).ConfigureAwait(false);
                }
                catch (PipeInvokeFailedException exception)
                {
                    Console.WriteLine("Handled invoke exception:" + Environment.NewLine + exception);
                }

                await pipeClientWithCallback.WaitForRemotePipeCloseAsync();

                Console.WriteLine("Server closed pipe.");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception in pipe processing: " + exception);
            }
        }
Exemplo n.º 7
0
 public static void Reference(WrappedInt param)
 {
     param.Number = 42;
 }
Exemplo n.º 8
0
        public static void Run()
        {
            QUnit.Module("Nested object tests");

            var sample = new WrappedInt
            {
                Id       = 5,
                Name     = "Zaid",
                HasValue = true,
                Large    = 238472746327434243L
            };

            QUnit.Test("Nested object is encoded correctly", assert =>
            {
                var encoded = Converters.EncodeObject(sample);
                assert.Equal(encoded["Type"], "Cable.Bridge.Tests.NestedObjectTests+WrappedInt");
                assert.Equal(encoded["Value"]["Id"] == null, false);
                assert.Equal(encoded["Value"]["Id"]["Type"], "Int32");
                assert.Equal(encoded["Value"]["Id"]["Value"], "5");
                assert.Equal(encoded["Value"]["Name"] == null, false);
                assert.Equal(encoded["Value"]["Name"]["Type"], "String");
                assert.Equal(encoded["Value"]["Name"]["Value"], "Zaid");
                assert.Equal(encoded["Value"]["HasValue"] == null, false);
                assert.Equal(encoded["Value"]["HasValue"]["Type"], "Boolean");
                assert.Equal(encoded["Value"]["HasValue"]["Value"], true);
                assert.Equal(encoded["Value"]["Large"] == null, false);
                assert.Equal(encoded["Value"]["Large"]["Type"], "Int64");
                assert.Equal(encoded["Value"]["Large"]["Value"], "238472746327434243");
            });

            QUnit.Test("Serialization and deserialization of nested object works", assert =>
            {
                var serialized = Json.Serialize(sample);

                var deserialized = Json.Deserialize(serialized, typeof(WrappedInt)).As <WrappedInt>();

                assert.Equal(sample.Id, deserialized.Id);
                assert.Equal(sample.Name, deserialized.Name);
                assert.Equal(sample.HasValue, deserialized.HasValue);
                assert.Equal(sample.Large == deserialized.Large, true);
            });

            var generic = new WeirdGenericClass <WeirdGenericClass <int> >
            {
                Inner = new WeirdGenericClass <int>
                {
                    Inner  = 20,
                    Nested = new Nested <int>
                    {
                        InnerInner = 5
                    }
                },
                Nested = new Nested <WeirdGenericClass <int> >
                {
                    InnerInner = new WeirdGenericClass <int>
                    {
                        Inner  = 30,
                        Nested = new Nested <int>
                        {
                            InnerInner = 40
                        }
                    }
                }
            };



            QUnit.Test("Weird generic class is converted correctly", assert =>
            {
                var serialized = Json.Serialize(generic);

                var deserialized = Json.Deserialize <WeirdGenericClass <WeirdGenericClass <int> > >(serialized);


                assert.Equal(generic.Inner.Inner, deserialized.Inner.Inner);
                assert.Equal(generic.Inner.Nested.InnerInner, deserialized.Inner.Nested.InnerInner);
                assert.Equal(generic.Nested.InnerInner.Inner, deserialized.Nested.InnerInner.Inner);
                assert.Equal(generic.Nested.InnerInner.Nested.InnerInner, deserialized.Nested.InnerInner.Nested.InnerInner);
            });
        }