public static InjectionPlan Serialize(Implementations.InjectionPlan.InjectionPlan ip)
 {
     if (ip is Implementations.InjectionPlan.Constructor)
     {
         Implementations.InjectionPlan.Constructor     cons = (Implementations.InjectionPlan.Constructor)ip;
         Implementations.InjectionPlan.InjectionPlan[] args = cons.GetArgs();
         InjectionPlan[] protoArgs = new InjectionPlan[args.Length];
         for (int i = 0; i < args.Length; i++)
         {
             protoArgs[i] = Serialize(args[i]);
         }
         return(NewConstructor(ip.GetNode().GetFullName(), protoArgs.ToList <InjectionPlan>()));
     }
     if (ip is Implementations.InjectionPlan.Subplan)
     {
         Implementations.InjectionPlan.Subplan         sp   = (Implementations.InjectionPlan.Subplan)ip;
         Implementations.InjectionPlan.InjectionPlan[] args = sp.GetPlans();
         InjectionPlan[] subPlans = new InjectionPlan[args.Length];
         for (int i = 0; i < args.Length; i++)
         {
             subPlans[i] = Serialize(args[i]);
         }
         return(NewSubplan(ip.GetNode().GetFullName(), sp.GetSelectedIndex(), subPlans.ToList <InjectionPlan>()));
     }
     if (ip is CsInstance)
     {
         CsInstance ji = (CsInstance)ip;
         return(NewInstance(ip.GetNode().GetFullName(), ji.GetInstanceAsString()));
     }
     Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(
                                                                "Encountered unknown type of InjectionPlan: " + ip), LOGGER);
     return(null);
 }
        public static Implementations.InjectionPlan.InjectionPlan Deserialize(IClassHierarchy ch, InjectionPlan ip)
        {
            string fullName = ip.name;

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

                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());
                    }
                }

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

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

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

                Implementations.InjectionPlan.InjectionPlan[] subPlans = new Implementations.InjectionPlan.InjectionPlan[protoBufPlans.Length];
                for (int i = 0; i < protoBufPlans.Length; i++)
                {
                    subPlans[i] = (Implementations.InjectionPlan.InjectionPlan)Deserialize(ch, protoBufPlans[i]);
                }
                INode n = ch.GetNode(fullName);
                return(new Implementations.InjectionPlan.Subplan(n, subPlans));
            }
            Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Encountered unknown type of InjectionPlan: " + ip), LOGGER);
            return(null);
        }
        public static void Serialize(string fileName, Implementations.InjectionPlan.InjectionPlan ip)
        {
            InjectionPlan plan = Serialize(ip);

            using (var file = File.Create(fileName))
            {
                Serializer.Serialize <InjectionPlan>(file, plan);
            }
        }
Exemplo n.º 4
0
        public static Implementations.InjectionPlan.InjectionPlan Deserialize(IClassHierarchy ch, InjectionPlan ip) 
        {
            string fullName = ip.name;
            if (ip.constructor != null) 
            {
                Constructor cons = ip.constructor;
                IClassNode cn = (IClassNode)ch.GetNode(fullName);

                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());
                    }
                }

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

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

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

                Implementations.InjectionPlan.InjectionPlan[] subPlans = new Implementations.InjectionPlan.InjectionPlan[protoBufPlans.Length];
                for (int i = 0; i < protoBufPlans.Length; i++) 
                {
                    subPlans[i] = (Implementations.InjectionPlan.InjectionPlan)Deserialize(ch, protoBufPlans[i]);
                }
                INode n = ch.GetNode(fullName);
                return new Implementations.InjectionPlan.Subplan(n, subPlans);
            } 
            Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Encountered unknown type of InjectionPlan: " + ip), LOGGER);
            return null;
        }