コード例 #1
0
        public void TestDeSerializeClassHierarchyAndBind()
        {
            Type streamTask1Type = typeof(StreamTask1);
            Type helloTaskType   = typeof(HelloTask);

            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(HelloTask).Assembly.GetName().Name });
            IClassNode      StreamTask1ClassNode = (IClassNode)ns.GetNode(streamTask1Type.AssemblyQualifiedName);
            IClassNode      HelloTaskClassNode   = (IClassNode)ns.GetNode(helloTaskType.AssemblyQualifiedName);

            ProtocolBufferClassHierarchy.Serialize("task.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("task.bin");
            IClassNode      StreamTask1ClassNode2 = (IClassNode)ch.GetNode(streamTask1Type.AssemblyQualifiedName);
            IClassNode      HelloTaskClassNode2   = (IClassNode)ch.GetNode(helloTaskType.AssemblyQualifiedName);

            Assert.Equal(StreamTask1ClassNode.GetName(), StreamTask1ClassNode2.GetName());
            Assert.Equal(HelloTaskClassNode.GetName(), HelloTaskClassNode2.GetName());

            // have to use original class hierarchy for the merge. ClassHierarchy from ProtoBuffer doesn't support merge.
            IConfigurationBuilder cb = TangFactory.GetTang()
                                       .NewConfigurationBuilder(ns);

            cb.AddConfiguration(TaskConfiguration.ConfigurationModule
                                .Set(TaskConfiguration.Identifier, "Hello_From_Streaming1")
                                .Set(TaskConfiguration.Task, GenericType <StreamTask1> .Class)
                                .Build());

            IConfiguration taskConfiguration = cb.Build();
            StreamTask1    st = TangFactory.GetTang().NewInjector(taskConfiguration).GetInstance <StreamTask1>();

            Assert.NotNull(st);
        }
コード例 #2
0
        public void TestDeSerializeClassHierarchy()
        {
            Type timerType            = typeof(Timer);
            Type SecondType           = typeof(Timer.Seconds);
            Type simpleCOnstuctorType = typeof(SimpleConstructors);

            IClassHierarchy ns             = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(Timer).Assembly.GetName().Name });
            IClassNode      timerClassNode = (IClassNode)ns.GetNode(timerType.AssemblyQualifiedName);
            INode           secondNode     = (INode)ns.GetNode(SecondType.AssemblyQualifiedName);
            IClassNode      SimpleConstructorsClassNode = (IClassNode)ns.GetNode(simpleCOnstuctorType.AssemblyQualifiedName);

            ProtocolBufferClassHierarchy.Serialize("node.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("node.bin");

            IClassNode timerClassNode2 = (IClassNode)ch.GetNode(timerType.AssemblyQualifiedName);
            INode      secondNode2     = ch.GetNode(SecondType.AssemblyQualifiedName);
            IClassNode SimpleConstructorsClassNode2 = (IClassNode)ch.GetNode(simpleCOnstuctorType.AssemblyQualifiedName);

            Assert.Equal(timerClassNode.GetFullName(), timerClassNode2.GetFullName());
            Assert.Equal(secondNode.GetFullName(), secondNode2.GetFullName());
            Assert.Equal(SimpleConstructorsClassNode.GetFullName(), SimpleConstructorsClassNode2.GetFullName());

            Assert.True(SimpleConstructorsClassNode2.GetChildren().Count == 0);
            IList <IConstructorDef> def = SimpleConstructorsClassNode2.GetInjectableConstructors();

            Assert.Equal(3, def.Count);
        }
コード例 #3
0
        public static InjectionPlan Deserialize(IClassHierarchy ch, InjectionPlanProto.InjectionPlan ip)
        {
            string fullName = ip.name;

            if (ip.constructor != null)
            {
                InjectionPlanProto.Constructor cons = ip.constructor;
                IClassNode cn = (IClassNode)ch.GetNode(fullName);

                InjectionPlanProto.InjectionPlan[] protoBufArgs = cons.args.ToArray();

                IClassNode[] cnArgs = new IClassNode[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++)
                {
                    INode no = ch.GetNode(protoBufArgs[i].name);
                    if (no is IClassNode)
                    {
                        cnArgs[i] = (IClassNode)no;
                    }
                    else if (no is INamedParameterNode)
                    {
                        INamedParameterNode np = (INamedParameterNode)no;
                        cnArgs[i] = (IClassNode)ch.GetNode(np.GetFullArgName());
                    }
                }

                InjectionPlan[] ipArgs = new InjectionPlan[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++)
                {
                    ipArgs[i] = (InjectionPlan)Deserialize(ch, protoBufArgs[i]);
                }

                IConstructorDef constructor = cn.GetConstructorDef(cnArgs);
                return(new Constructor(cn, constructor, ipArgs));
            }
            if (ip.instance != null)
            {
                InjectionPlanProto.Instance ins = ip.instance;
                object instance = Parse(ip.name, ins.value);
                return(new CsInstance(ch.GetNode(ip.name), instance));
            }
            if (ip.subplan != null)
            {
                InjectionPlanProto.Subplan         subplan       = ip.subplan;
                InjectionPlanProto.InjectionPlan[] protoBufPlans = subplan.plans.ToArray();

                InjectionPlan[] subPlans = new InjectionPlan[protoBufPlans.Length];
                for (int i = 0; i < protoBufPlans.Length; i++)
                {
                    subPlans[i] = (InjectionPlan)Deserialize(ch, protoBufPlans[i]);
                }
                INode n = ch.GetNode(fullName);
                return(new Subplan(n, subPlans));
            }
            Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Encountered unknown type of InjectionPlan: " + ip), LOGGER);
            return(null);
        }
コード例 #4
0
        public void RegisterLegacyConstructor(string s, IList <string> args)
        {
            IClassNode         cn     = (IClassNode)this.ClassHierarchy.GetNode(s);
            IList <IClassNode> cnArgs = new List <IClassNode>();

            for (int i = 0; i < args.Count; i++)
            {
                cnArgs.Add((IClassNode)ClassHierarchy.GetNode(args[i]));
            }
            RegisterLegacyConstructor(cn, cnArgs);
        }
コード例 #5
0
        public void TestGenericClass()
        {
            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(Timer).Assembly.GetName().Name });

            Type t = typeof(Timer);
            IClassNode EventClassNode = (IClassNode)ns.GetNode(t.AssemblyQualifiedName);
            ProtocolBufferClassHierarchy.Serialize("event.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("event.bin");
            IClassNode EventClassNode1 = (IClassNode)ns.GetNode(t.AssemblyQualifiedName);
            Assert.AreEqual(EventClassNode.GetName(), EventClassNode1.GetName());
        }
コード例 #6
0
        /// <summary>
        /// This program generates class hierarchy bin file for the list of dlls, plus a defalut list
        /// The default list include: ITask, StreamTask1, HelloTask and ShellTask, please remove if not needed
        /// </summary>
        /// <param name="args"> additional dlls needed to build class hierarchy </param>
        public static void Main(string[] args)
        {
            const string DllSubfix = ".dll";
            const string ClassHierarchyBinFileName = "task.bin";

            List <string> taskDlls = new List <string>();

            foreach (string arg in args)
            {
                string assemblyName = arg;
                if (!arg.EndsWith(DllSubfix, StringComparison.OrdinalIgnoreCase))
                {
                    assemblyName += DllSubfix;
                }
                if (!File.Exists(assemblyName))
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "invalid argument: assembly {0} cannot be found", assemblyName));
                }
                taskDlls.Add(arg);
            }

            taskDlls.Add(GetAssemblyName(typeof(ITask)));
            taskDlls.Add(GetAssemblyName(typeof(HelloTask)));
            taskDlls.Add(GetAssemblyName(typeof(ShellTask)));
            taskDlls.Add(GetAssemblyName(typeof(StreamTask1)));

            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(taskDlls.ToArray());

            // the following is verification only
            // to verify that a class indeeded has been added to the class hierarchy, check the class name
            IClassNode streamTaskClassNode = (IClassNode)ns.GetNode(typeof(StreamTask1).AssemblyQualifiedName);
            IClassNode helloTaskClassNode  = (IClassNode)ns.GetNode(typeof(HelloTask).AssemblyQualifiedName);
            IClassNode shellTaskClassNode  = (IClassNode)ns.GetNode(typeof(ShellTask).AssemblyQualifiedName);

            ProtocolBufferClassHierarchy.Serialize(ClassHierarchyBinFileName, ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize(ClassHierarchyBinFileName);

            IClassNode retrievedStreamTaskClassNode = (IClassNode)ch.GetNode(typeof(StreamTask1).AssemblyQualifiedName);
            IClassNode retrievedHelloTaskClassNode  = (IClassNode)ch.GetNode(typeof(HelloTask).AssemblyQualifiedName);
            IClassNode retrievedShellTaskClassNode  = (IClassNode)ch.GetNode(typeof(ShellTask).AssemblyQualifiedName);

            if (!streamTaskClassNode.GetFullName().Equals(retrievedStreamTaskClassNode.GetFullName()) ||
                !helloTaskClassNode.GetFullName().Equals(retrievedHelloTaskClassNode.GetFullName()) ||
                !shellTaskClassNode.GetFullName().Equals(retrievedShellTaskClassNode.GetFullName()))
            {
                Console.WriteLine("Node deseriliazed is not equal");
            }
            else
            {
                Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Class hierarchy written to [{0}].", Directory.GetCurrentDirectory()));
            }
        }
コード例 #7
0
        public static InjectionPlan Deserialize(IClassHierarchy ch, InjectionPlanProto.InjectionPlan ip)
        {
            string fullName = ip.name;

            if (ip.constructor != null)
            {
                InjectionPlanProto.Constructor cons = ip.constructor;
                IClassNode cn = (IClassNode)ch.GetNode(fullName);

                InjectionPlanProto.InjectionPlan[] protoBufArgs = cons.args.ToArray();

                INode[] cnArgs = new INode[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++)
                {
                    cnArgs[i] = (INode)ch.GetNode(protoBufArgs[i].name);
                }

                InjectionPlan[] ipArgs = new InjectionPlan[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++)
                {
                    ipArgs[i] = (InjectionPlan)Deserialize(ch, protoBufArgs[i]);
                }

                IConstructorDef constructor = cn.GetConstructorDef(cnArgs);
                return(new Constructor(cn, constructor, ipArgs));
            }
            else if (ip.instance != null)
            {
                InjectionPlanProto.Instance ins = ip.instance;
                object instance = Parse(ip.name, ins.value);
                return(new CsInstance(ch.GetNode(ip.name), instance));
            }
            else if (ip.subplan != null)
            {
                InjectionPlanProto.Subplan         subplan       = ip.subplan;
                InjectionPlanProto.InjectionPlan[] protoBufPlans = subplan.plans.ToArray();

                InjectionPlan[] subPlans = new InjectionPlan[protoBufPlans.Length];
                for (int i = 0; i < protoBufPlans.Length; i++)
                {
                    subPlans[i] = (InjectionPlan)Deserialize(ch, protoBufPlans[i]);
                }
                INode n = ch.GetNode(fullName);
                return(new Subplan(n, subPlans));
            }
            else
            {
                throw new IllegalStateException("Encountered unknown type of injection plan: " + ip);
            }
        }
コード例 #8
0
        public static InjectionPlan Deserialize(IClassHierarchy ch, InjectionPlanProto.InjectionPlan ip)
        {
            string fullName = ip.name;
            if (ip.constructor != null)
            {
                InjectionPlanProto.Constructor cons = ip.constructor;
                IClassNode cn = (IClassNode) ch.GetNode(fullName);

                InjectionPlanProto.InjectionPlan[] protoBufArgs = cons.args.ToArray();

                INode[] cnArgs = new INode[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++)
                {
                    cnArgs[i] = (INode) ch.GetNode(protoBufArgs[i].name);
                }

                InjectionPlan[] ipArgs = new InjectionPlan[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++)
                {
                    ipArgs[i] = (InjectionPlan) Deserialize(ch, protoBufArgs[i]);
                }

                IConstructorDef constructor = cn.GetConstructorDef(cnArgs);
                return new Constructor(cn, constructor, ipArgs);
            }
            else if (ip.instance != null)
            {
                InjectionPlanProto.Instance ins = ip.instance;
                object instance = Parse(ip.name, ins.value);
                return new CsInstance(ch.GetNode(ip.name), instance);
            }
            else if (ip.subplan != null)
            {
                InjectionPlanProto.Subplan subplan = ip.subplan;
                InjectionPlanProto.InjectionPlan[] protoBufPlans = subplan.plans.ToArray();

                InjectionPlan[] subPlans = new InjectionPlan[protoBufPlans.Length];
                for (int i = 0; i < protoBufPlans.Length; i++)
                {
                    subPlans[i] = (InjectionPlan) Deserialize(ch, protoBufPlans[i]);
                }
                INode n = ch.GetNode(fullName);
                return new Subplan(n, subPlans);
            }
            else
            {
                throw new IllegalStateException("Encountered unknown type of injection plan: " + ip);
            }
        }
コード例 #9
0
ファイル: TestClassHierarchy.cs プロジェクト: cccnam5158/reef
        public void TestNameCantBindSubclassOfArgumentAsDefault()
        {
            ns = TangFactory.GetTang().GetClassHierarchy(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks });
            INode node = ns.GetNode(typeof(GoodNameForGeneric).AssemblyQualifiedName);

            Assert.Equal(node.GetFullName(), typeof(GoodNameForGeneric).AssemblyQualifiedName);
        }
コード例 #10
0
ファイル: TestSerilization.cs プロジェクト: DifferentSC/TANG
        public void TestSerializeClassHierarchy()
        {
            IClassHierarchy ns             = TangFactory.GetTang().GetClassHierarchy(new string[] { @"Com.Microsoft.Tang.Examples" });
            IClassNode      timerClassNode = (IClassNode)ns.GetNode("Com.Microsoft.Tang.Examples.Timer");

            ProtocolBufferClassHierarchy.Serialize("node.bin", ns);
        }
コード例 #11
0
 public void TestDeSerializeClassHierarchyFromJava()
 {
     //the file comes from Java TestClassHierarchyRoundTrip SetUp3 testSimpleConstructors
     IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("simpleConstructorJavaProto.bin");
     IClassNode simpleConstructorNode = (IClassNode)ch.GetNode("org.apache.reef.tang.implementation.SimpleConstructors");
     Assert.AreEqual(simpleConstructorNode.GetChildren().Count, 0);
     Assert.AreEqual(simpleConstructorNode.GetInjectableConstructors().Count, 3);
 }
コード例 #12
0
        public void TestDeSerializeClassHierarchyForTask()
        {
            Type streamTask1Type = typeof(StreamTask1);
            Type helloTaskType   = typeof(HelloTask);

            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(HelloTask).Assembly.GetName().Name });
            IClassNode      StreamTask1ClassNode = (IClassNode)ns.GetNode(streamTask1Type.AssemblyQualifiedName);
            IClassNode      HelloTaskClassNode   = (IClassNode)ns.GetNode(helloTaskType.AssemblyQualifiedName);

            ProtocolBufferClassHierarchy.Serialize("task.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("task.bin");
            IClassNode      StreamTask1ClassNode2 = (IClassNode)ch.GetNode(streamTask1Type.AssemblyQualifiedName);
            IClassNode      HelloTaskClassNode2   = (IClassNode)ch.GetNode(helloTaskType.AssemblyQualifiedName);

            Assert.Equal(StreamTask1ClassNode.GetFullName(), StreamTask1ClassNode2.GetFullName());
            Assert.Equal(HelloTaskClassNode.GetFullName(), HelloTaskClassNode2.GetFullName());
        }
コード例 #13
0
        public void TestGenericArgument()
        {
            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { typeof(ClassWithGenericArgument<>).Assembly.GetName().Name });

            Type t = typeof(ClassWithGenericArgument<>);
            IClassNode classNode = (IClassNode)ns.GetNode(t.AssemblyQualifiedName);
            var cons = classNode.GetAllConstructors();
            foreach (var c in cons)
            {
                var args = c.GetArgs();
                foreach (var a in args)
                {
                    Assert.IsNotNull(a.GetName());
                }
            }
            ProtocolBufferClassHierarchy.Serialize("generic.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("generic.bin");
            IClassNode classNode1 = (IClassNode)ns.GetNode(t.AssemblyQualifiedName);
            Assert.AreEqual(classNode.GetName(), classNode1.GetName());
        }
コード例 #14
0
        public void TestToFromAvroNode()
        {
            Type timerType             = typeof(Timer);
            Type secondType            = typeof(Timer.Seconds);
            Type simpleConstructorType = typeof(SimpleConstructors);

            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(
                new string[] { typeof(Timer).Assembly.GetName().Name, typeof(SimpleConstructors).Assembly.GetName().Name });
            IClassNode timerClassNode = (IClassNode)ns.GetNode(timerType.AssemblyQualifiedName);
            INode      secondNode     = ns.GetNode(secondType.AssemblyQualifiedName);
            IClassNode simpleConstructorsClassNode = (IClassNode)ns.GetNode(simpleConstructorType.AssemblyQualifiedName);

            AvroNode        n   = _serializer.ToAvroNode(ns);
            IClassHierarchy ns2 = _serializer.FromAvroNode(n);

            IClassNode timerClassNode2 = (IClassNode)ns2.GetNode(timerType.AssemblyQualifiedName);
            INode      secondNode2     = ns2.GetNode(secondType.AssemblyQualifiedName);
            IClassNode simpleConstructorsClassNode2 = (IClassNode)ns2.GetNode(simpleConstructorType.AssemblyQualifiedName);

            Assert.Equal(timerClassNode, timerClassNode2);
            Assert.Equal(secondNode, secondNode2);
            Assert.Equal(simpleConstructorsClassNode, simpleConstructorsClassNode2);
        }
コード例 #15
0
ファイル: TestSerilization.cs プロジェクト: DifferentSC/TANG
        public void TestDeSerializeClassHierarchy()
        {
            IClassHierarchy ns             = TangFactory.GetTang().GetClassHierarchy(new string[] { @"Com.Microsoft.Tang.Examples" });
            IClassNode      timerClassNode = (IClassNode)ns.GetNode("Com.Microsoft.Tang.Examples.Timer");
            INode           secondNode     = (INode)ns.GetNode("Com.Microsoft.Tang.Examples.Timer+Seconds");
            IClassNode      SimpleConstructorsClassNode = (IClassNode)ns.GetNode("Com.Microsoft.Tang.Examples.SimpleConstructors");

            ProtocolBufferClassHierarchy.Serialize("node.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("node.bin");

            IClassNode timerClassNode2 = (IClassNode)ch.GetNode("Com.Microsoft.Tang.Examples.Timer");
            INode      secondNode2     = ch.GetNode("Com.Microsoft.Tang.Examples.Timer+Seconds");
            IClassNode SimpleConstructorsClassNode2 = (IClassNode)ch.GetNode("Com.Microsoft.Tang.Examples.SimpleConstructors");

            Assert.AreEqual(timerClassNode.GetFullName(), timerClassNode2.GetFullName());
            Assert.AreEqual(secondNode.GetFullName(), secondNode.GetFullName());
            Assert.AreEqual(SimpleConstructorsClassNode.GetFullName(), SimpleConstructorsClassNode2.GetFullName());

            Assert.IsTrue(SimpleConstructorsClassNode2.GetChildren().Count == 0);
            IList <IConstructorDef> def = SimpleConstructorsClassNode2.GetInjectableConstructors();

            Assert.AreEqual(3, def.Count);
        }
コード例 #16
0
ファイル: TestSerilization.cs プロジェクト: DifferentSC/TANG
        public void TestDeSerializeClassHierarchyForActivity()
        {
            string[] s = new string[2];
            s[0] = @"com.microsoft.reef.activity";
            s[1] = @"com.microsoft.reef.activityInterface";

            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(s);
            IClassNode      activityClassNode = (IClassNode)ns.GetNode("com.microsoft.reef.activity.HelloActivity");

            ProtocolBufferClassHierarchy.Serialize("activity.bin", ns);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("activity.bin");

            IClassNode activityClassNode2 = (IClassNode)ch.GetNode("com.microsoft.reef.activity.HelloActivity");

            Assert.AreEqual(activityClassNode.GetFullName(), activityClassNode2.GetFullName());
        }
コード例 #17
0
        public void TestAnonymousTypeWithDictionary()
        {
            List <string> appDlls = new List <string>();

            appDlls.Add(typeof(AnonymousType).Assembly.GetName().Name);
            var c = TangFactory.GetTang().GetClassHierarchy(appDlls.ToArray());

            c.GetNode(typeof(AnonymousType).AssemblyQualifiedName);

            IConfiguration conf     = TangFactory.GetTang().NewConfigurationBuilder(c).Build();
            IInjector      injector = TangFactory.GetTang().NewInjector(conf);
            var            obj      = injector.GetInstance <AnonymousType>();

            Assert.IsNotNull(obj);

            var cd = Directory.GetCurrentDirectory();

            Console.WriteLine(cd);

            ProtocolBufferClassHierarchy.Serialize(ClassHierarchyBinFileName, c);
            IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize(ClassHierarchyBinFileName);

            ch.GetNode(typeof(AnonymousType).AssemblyQualifiedName);
        }
コード例 #18
0
        public void TestAvroClassHierarchyMerge()
        {
            IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(
                new string[] { typeof(Timer).Assembly.GetName().Name });
            IClassNode timerClassNode = (IClassNode)ns.GetNode(typeof(Timer).AssemblyQualifiedName);

            AvroNode        n   = _serializer.ToAvroNode(ns);
            IClassHierarchy ns2 = _serializer.FromAvroNode(n);

            IClassHierarchy ns3 = TangFactory.GetTang().GetClassHierarchy(
                new string[] { typeof(AvroNode).Assembly.GetName().Name });
            IClassNode avroNodeClassNode = (IClassNode)ns3.GetNode(typeof(AvroNode).AssemblyQualifiedName);

            AvroNode        n2  = _serializer.ToAvroNode(ns3);
            IClassHierarchy ns4 = _serializer.FromAvroNode(n2);

            var ns5 = ns2.Merge(ns4);

            IClassNode timerClassNode2    = (IClassNode)ns5.GetNode(typeof(Timer).AssemblyQualifiedName);
            IClassNode avroNodeClassNode2 = (IClassNode)ns5.GetNode(typeof(AvroNode).AssemblyQualifiedName);

            Assert.Equal(timerClassNode, timerClassNode2);
            Assert.Equal(avroNodeClassNode, avroNodeClassNode2);
        }
コード例 #19
0
        public static Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan Deserialize(IClassHierarchy ch, Org.Apache.REEF.Tang.Protobuf.InjectionPlan ip) 
        {
            string fullName = ip.name;
            if (ip.constructor != null) 
            {
                Org.Apache.REEF.Tang.Protobuf.Constructor cons = ip.constructor;
                IClassNode cn = (IClassNode) ch.GetNode(fullName);

                Org.Apache.REEF.Tang.Protobuf.InjectionPlan[] protoBufArgs = cons.args.ToArray();

                IClassNode[] cnArgs = new IClassNode[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++) 
                {
                    INode no = ch.GetNode(protoBufArgs[i].name);
                    if (no is IClassNode)
                    {
                        cnArgs[i] = (IClassNode)no;
                    }
                    else if (no is INamedParameterNode)
                    {
                        INamedParameterNode np = (INamedParameterNode)no;
                        cnArgs[i] = (IClassNode)ch.GetNode(np.GetFullArgName());
                    }
                }

                Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan[] ipArgs = new Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan[protoBufArgs.Length];

                for (int i = 0; i < protoBufArgs.Length; i++) 
                {
                    ipArgs[i] = (Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan)Deserialize(ch, protoBufArgs[i]);
                }

                IConstructorDef constructor = cn.GetConstructorDef(cnArgs);
                return new Org.Apache.REEF.Tang.Implementations.InjectionPlan.Constructor(cn, constructor, ipArgs);
            }
            if (ip.instance != null) 
            {
                Org.Apache.REEF.Tang.Protobuf.Instance ins = ip.instance;
                object instance = Parse(ip.name, ins.value);
                return new CsInstance(ch.GetNode(ip.name), instance);
            } 
            if (ip.subplan != null) 
            {
                Org.Apache.REEF.Tang.Protobuf.Subplan subplan = ip.subplan;
                Org.Apache.REEF.Tang.Protobuf.InjectionPlan[] protoBufPlans = subplan.plans.ToArray();

                Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan[] subPlans = new Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan[protoBufPlans.Length];
                for (int i = 0; i < protoBufPlans.Length; i++) 
                {
                    subPlans[i] = (Org.Apache.REEF.Tang.Implementations.InjectionPlan.InjectionPlan)Deserialize(ch, protoBufPlans[i]);
                }
                INode n = ch.GetNode(fullName);
                return new Org.Apache.REEF.Tang.Implementations.InjectionPlan.Subplan(n, subPlans);
            } 
            Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Encountered unknown type of InjectionPlan: " + ip), LOGGER);
            return null;
        }
コード例 #20
0
ファイル: TestClassHierarchy.cs プロジェクト: cccnam5158/reef
        public void TestString()
        {
            INode n = null;

            try
            {
                n = ns.GetNode("System");
            }
            catch (ApplicationException)
            {
            }
            catch (NameResolutionException)
            {
            }
            Assert.Null(n);

            Assert.NotNull(ns.GetNode(typeof(string).AssemblyQualifiedName));

            string msg = null;

            try
            {
                ns.GetNode("org.apache");
                msg = "Didn't get expected exception";
            }
            catch (ApplicationException)
            {
            }
            catch (NameResolutionException)
            {
            }
            Assert.True(msg == null, msg);
        }
コード例 #21
0
        public void TestString()
        {
            INode n = null;

            try
            {
                n = ns.GetNode("System");
            }
            catch (NameResolutionException e)
            {
            }
            Assert.IsNull(n);

            Assert.IsNotNull(ns.GetNode("System.String"));
            try
            {
                ns.GetNode("com.microsoft");
                Assert.Fail("Didn't get expected exception");
            }
            catch (NameResolutionException e)
            {
            }
        }