コード例 #1
0
 public static InjectionPlanProto.InjectionPlan Serialize(InjectionPlan ip)
 {
     if (ip is Constructor)
     {
         Constructor     cons = (Constructor)ip;
         InjectionPlan[] args = cons.GetArgs();
         InjectionPlanProto.InjectionPlan[] protoArgs = new InjectionPlanProto.InjectionPlan[args.Length];
         for (int i = 0; i < args.Length; i++)
         {
             protoArgs[i] = Serialize(args[i]);
         }
         return(NewConstructor(ip.GetNode().GetFullName(), protoArgs.ToList <InjectionPlanProto.InjectionPlan>()));
     }
     if (ip is Subplan)
     {
         Subplan         sp   = (Subplan)ip;
         InjectionPlan[] args = sp.GetPlans();
         InjectionPlanProto.InjectionPlan[] subPlans = new InjectionPlanProto.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 <InjectionPlanProto.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);
 }
コード例 #2
0
ファイル: Subplan.cs プロジェクト: NurimOnsemiro/reef
        readonly int selectedIndex; // the implementation that is bound

        public Subplan(INode n, int selectedIndex, InjectionPlan[] alternatives)
            : base(n)
        {
            this.alternatives = alternatives;
            if (selectedIndex < -1 || selectedIndex >= alternatives.Length)
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IndexOutOfRangeException(), LOGGER);
            }
            this.selectedIndex = selectedIndex;
            if (selectedIndex != -1)
            {
                // one was bound
                this.numAlternatives = alternatives[selectedIndex].GetNumAlternatives();
            }
            else
            {
                // no one was bound, but anyone could be used
                int numAlternatives = 0;
                foreach (InjectionPlan a in alternatives)
                {
                    numAlternatives += a.GetNumAlternatives();
                }
                this.numAlternatives = numAlternatives;
            }
        }
コード例 #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 static void Serialize(string fileName, InjectionPlan ip)
        {
            InjectionPlanProto.InjectionPlan plan = Serialize(ip);

            using (var file = File.Create(fileName))
            {
                Serializer.Serialize <InjectionPlanProto.InjectionPlan>(file, plan);
            }
        }
コード例 #5
0
ファイル: TestSerilization.cs プロジェクト: DifferentSC/TANG
        public void TestSerirializeInjectionPlanForSimpleConstructor()
        {
            Type simpleConstructorType = typeof(Com.Microsoft.Tang.Examples.SimpleConstructors);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb   = tang.NewConfigurationBuilder(new string[] { file });
            IConfiguration          conf = cb.Build();
            IInjector     injector       = tang.NewInjector(conf);
            InjectionPlan ip             = injector.GetInjectionPlan(simpleConstructorType);

            ProtocolBufferInjectionPlan.Serialize("plan.bin", ip);
        }
コード例 #6
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);
            }
        }
コード例 #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
ファイル: TestSerilization.cs プロジェクト: DifferentSC/TANG
        public void TestSerirializeInjectionPlanForTimer()
        {
            Type timerType      = typeof(Com.Microsoft.Tang.Examples.Timer);
            Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds");

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file });

            cb.BindNamedParameter(namedParameter, "2");
            IConfiguration conf     = cb.Build();
            IInjector      injector = tang.NewInjector(conf);
            InjectionPlan  ip       = injector.GetInjectionPlan(timerType);

            ProtocolBufferInjectionPlan.Serialize("timerplan.bin", ip);
        }
コード例 #9
0
ファイル: TestSerilization.cs プロジェクト: beysims/reef
        public void TestSerirializeInjectionPlanForSimpleConstructor()
        {
            Type simpleConstructorType = typeof(SimpleConstructors);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb   = tang.NewConfigurationBuilder(new string[] { FileNames.Examples });
            IConfiguration          conf = cb.Build();
            IInjector     injector       = tang.NewInjector(conf);
            InjectionPlan ip             = injector.GetInjectionPlan(simpleConstructorType);

            ProtocolBufferInjectionPlan.Serialize("plan.bin", ip);
            var ch          = conf.GetClassHierarchy();
            var ipRecovered = ProtocolBufferInjectionPlan.DeSerialize("plan.bin", ch);

            Assert.IsNotNull(ipRecovered);
        }
コード例 #10
0
        private void _btnDupe_Click(object sender, EventArgs e)
        {
            if (_dgvPlans.SelectedRows.Count > 0)
            {
                if (AreYouSure())
                {
                    List <InjectionPlan> dupes = new List <InjectionPlan>();
                    foreach (DataGridViewRow r in _dgvPlans.SelectedRows)
                    {
                        dupes.Add((InjectionPlan)r.DataBoundItem);
                    }

                    foreach (var d in dupes)
                    {
                        var p = new InjectionPlan()
                        {
                            DestinationLine  = d.DestinationLine,
                            Images           = new List <InjectionImage>(),
                            LoopLineInc      = d.LoopLineInc,
                            LoopSize         = d.LoopSize,
                            Name             = d.Name + " copy",
                            PatternHeight    = d.PatternHeight,
                            SongPosition     = d.SongPosition,
                            TotalFrames      = d.TotalFrames,
                            PixelMode        = d.PixelMode,
                            FrameLineInc     = d.FrameLineInc,
                            PatternAllFrames = d.PatternAllFrames
                        };

                        foreach (var i in d.Images)
                        {
                            p.Images.Add(new InjectionImage()
                            {
                                FileName      = i.FileName,
                                Image         = i.Image,
                                PatternHeight = i.PatternHeight
                            });
                        }

                        _project.Plans.Add(p);
                    }

                    RefreshData();
                }
            }
        }
コード例 #11
0
ファイル: TestSerilization.cs プロジェクト: beysims/reef
        public void TestSerirializeInjectionPlanForTimer()
        {
            Type  timerType            = typeof(Timer);
            ITang tang                 = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples });

            cb.BindNamedParameter <Timer.Seconds, Int32>(GenericType <Timer.Seconds> .Class, "2");
            IConfiguration conf     = cb.Build();
            IInjector      injector = tang.NewInjector(conf);
            InjectionPlan  ip       = injector.GetInjectionPlan(timerType);

            ProtocolBufferInjectionPlan.Serialize("timerplan.bin", ip);
            var ch  = conf.GetClassHierarchy();
            var ip1 = ProtocolBufferInjectionPlan.DeSerialize("timerplan.bin", ch);

            Assert.IsNotNull(ip1);
        }
コード例 #12
0
ファイル: Constructor.cs プロジェクト: beomyeol/reef
 public Constructor(IClassNode classNode,
     IConstructorDef constructor, InjectionPlan[] args) : base(classNode)
 {
     this.constructor = constructor;
     this.args = args;
     int curAlternatives = 1;
     bool curAmbiguous = false;
     bool curInjectable = true;
     foreach (InjectionPlan plan in args) 
     {
         curAlternatives *= plan.GetNumAlternatives();
         curAmbiguous |= plan.IsAmbiguous();
         curInjectable &= plan.IsInjectable();
     }
     this.numAlternatives = curAlternatives;
     this.isAmbiguous = curAmbiguous;
     this.isInjectable = curInjectable;
 }
コード例 #13
0
ファイル: Subplan.cs プロジェクト: kyungtaak/TANG
 public Subplan(INode n, int selectedIndex, InjectionPlan[] alternatives)
     : base(n)
 {
     this.alternatives = alternatives;
     if (selectedIndex < -1 || selectedIndex >= alternatives.Length)
     {
         throw new IndexOutOfRangeException();
     }
     this.selectedIndex = selectedIndex;
     if (selectedIndex != -1)
     {
         this.numAlternatives = alternatives[selectedIndex].GetNumAlternatives();
     }
     else
     {
         int numAlternatives = 0;
         foreach (InjectionPlan a in alternatives)
         {
             numAlternatives += a.GetNumAlternatives();
         }
         this.numAlternatives = numAlternatives;
     }
 }
コード例 #14
0
ファイル: Subplan.cs プロジェクト: DifferentSC/incubator-reef
 public Subplan(INode n, InjectionPlan[] alternatives)
     : this(n, -1, alternatives)
 {           
 }
コード例 #15
0
ファイル: Subplan.cs プロジェクト: DifferentSC/incubator-reef
 public InjectionPlan[] GetPlans() 
 {
     InjectionPlan[] copy = new InjectionPlan[alternatives.Length];
     Array.Copy(alternatives, copy, alternatives.Length); // not sure if it does deep copy??
     return copy;
 }
コード例 #16
0
        public static void Serialize(string fileName, InjectionPlan ip)
        {
            InjectionPlanProto.InjectionPlan plan = Serialize(ip);

            using (var file = File.Create(fileName))
            {
                Serializer.Serialize<InjectionPlanProto.InjectionPlan>(file, plan);
            }
        }
コード例 #17
0
        public static InjectionPlanProto.InjectionPlan Serialize(InjectionPlan ip)
        {
            if (ip is Constructor)
            {
                Constructor cons = (Constructor) ip;
                InjectionPlan[] args = cons.GetArgs();
                InjectionPlanProto.InjectionPlan[] protoArgs = new InjectionPlanProto.InjectionPlan[args.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    protoArgs[i] = Serialize(args[i]);
                }
                return NewConstructor(ip.GetNode().GetFullName(), protoArgs.ToList<InjectionPlanProto.InjectionPlan>());
            }
            else if (ip is Subplan)
            {
                Subplan sp = (Subplan) ip;
                InjectionPlan[] args = sp.GetPlans();
                InjectionPlanProto.InjectionPlan[] subPlans = new InjectionPlanProto.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<InjectionPlanProto.InjectionPlan>());

            }
            else if (ip is CsInstance)
            {
                CsInstance ji = (CsInstance) ip;
                return NewInstance(ip.GetNode().GetFullName(), ji.GetInstanceAsString());
            } else
            {
                throw new IllegalStateException(
                    "Encountered unknown type of InjectionPlan: " + ip);
            }
        }
コード例 #18
0
ファイル: Constructor.cs プロジェクト: beomyeol/reef
 private string ShallowArgString(InjectionPlan arg) 
 {
     if (arg is Constructor || arg is Subplan) 
     {
         return arg.GetType().Name + ": " + arg.GetNode().GetName();
     } 
     else 
     {
         return arg.ToShallowString();
     }
 }
コード例 #19
0
ファイル: InjectorImpl.cs プロジェクト: kyungtaak/TANG
        public object InjectFromPlan(InjectionPlan plan)
        {
            if (!plan.IsFeasible())
            {
                throw new InjectionException("Cannot inject " + plan.GetNode().GetFullName() + ": "
                    + plan.ToCantInjectString());
            }
            if (plan.IsAmbiguous())
            {
                throw new InjectionException("Cannot inject " + plan.GetNode().GetFullName() + " "
                    + plan.ToCantInjectString());
            }

            if (plan is InjectionFuturePlan)
            {
                InjectionFuturePlan fut = (InjectionFuturePlan)plan;
                string key = fut.GetNode().GetFullName();
                try
                {
                    //we will see if we need to introduce T to replace object
                    InjectionFuture ret = new InjectionFuture(this, classHierarchy.ClassForName(fut.GetNode().GetFullName()));
                    pendingFutures.Add(ret);
                    return ret;
                }
                catch (TypeLoadException e)
                {
                    throw new InjectionException("Could not get class for " + key);
                }
            }
            else if(plan.GetNode() is IClassNode && null != GetCachedInstance((IClassNode)plan.GetNode()))
            {
                return GetCachedInstance((IClassNode)plan.GetNode());
            }
            else if (plan is CsInstance)
            {
                // TODO: Must be named parameter node.  Check.
                //      throw new IllegalStateException("Instance from plan not in Injector's set of instances?!?");
                return ((CsInstance) plan).instance;
            }
            else if (plan is Constructor)
            {
                Constructor constructor = (Constructor) plan;
                object[] args = new object[constructor.GetArgs().Length];
                InjectionPlan[] argPlans = constructor.GetArgs();

                for (int i = 0; i < argPlans.Length; i++)
                {
                    args[i] = InjectFromPlan(argPlans[i]);
                }

                try
                {
                    concurrentModificationGuard = true;
                    object ret;
                    try
                    {
                        IConstructorDef def = (IConstructorDef)constructor.GetConstructorDef();
                        ConstructorInfo c = GetConstructor(def);

                        if (aspect != null)
                        {
                            ret = aspect.Inject(def, c, args);
                        }
                        else
                        {
                            ret = c.Invoke(args);
                        }
                    }
                    catch (ArgumentException e)
                    {
                        StringBuilder sb = new StringBuilder("Internal Tang error?  Could not call constructor " + constructor.GetConstructorDef() + " with arguments [");
                        foreach (Object o in args)
                        {
                            sb.Append("\n\t" + o);
                        }
                        sb.Append("]");
                        throw new IllegalStateException(sb.ToString(), e);
                    }
                    if (ret is IExternalConstructor)
                    {
                        ret = ((IExternalConstructor)ret).NewInstance();
                    }
                    instances.Add(constructor.GetNode(), ret);
                    return ret;
                }
                catch (Exception e)
                {
                    throw new InjectionException("Could not invoke constructor: " + plan,  e); //check what exception might be got and refine it
                } finally
                {
                    concurrentModificationGuard = false;
                }
            }
            else if (plan is Subplan)
            {
                Subplan ambiguous = (Subplan) plan;
                return InjectFromPlan(ambiguous.GetDelegatedPlan());
            }
            else if (plan is SetInjectionPlan)
            {
                SetInjectionPlan setPlan = (SetInjectionPlan) plan;
                ISet<object> ret = new MonotonicSet<object>();
                foreach (InjectionPlan subplan in setPlan.GetEntryPlans())
                {
                    ret.Add(InjectFromPlan(subplan));
                }
                return ret;
            } else
            {
                throw new IllegalStateException("Unknown plan type: " + plan);
            }
        }
コード例 #20
0
        private void DoTheWork()
        {
            _project.XM             = _ser.DeSerialize(_project.SourceModule);
            _project.XM.TrackerName = "Logicoma Rulez!";
            var sourceChannels = _project.XM.ChannelCount;

            _project.XM.ResizeChannels(_project.Channels, _project.CentreSourceModule);

            // run the stills
            foreach (var s in _project.Stills)
            {
                _project.XM.RunInjectionStill(s);
            }

            // run the plans
            var plans = new List <InjectionPlan>();

            foreach (var p in _project.Plans)
            {
                plans.Add(p);
            }

            plans.Sort(delegate(InjectionPlan x, InjectionPlan y)
            {
                return(y.SongPosition.CompareTo(x.SongPosition));
            });

            InjectionPlan prevPlan = null;

            foreach (var plan in plans)
            {
                var followingDestinationLine = 0;

                if (prevPlan != null && prevPlan.SongPosition - 1 == plan.SongPosition)
                {
                    followingDestinationLine = prevPlan.DestinationLine;
                }

                try
                {
                    _project.XM.RunInjectionPlan(plan, sourceChannels, followingDestinationLine);
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Error with plan {0}: {1}", plan.Name, e.Message));
                }
                prevPlan = plan;
            }

            _project.XM.CleanPatternOrderList();
            _project.XM.RemoveDuplicatePatterns();
            var modData = _ser.Serialize(_project.XM);

            var max = 2097152;

            if (modData.Length > max)
            {
                _lblSize.Text    = "FUUUUUUUUUUUUUUUUUUUUUUUUUUUUUK!";
                _pgbSize.Maximum = max;
                _pgbSize.Value   = max;
            }
            else
            {
                _lblSize.Text    = string.Format("{0:n0} / {1:n0} bytes", modData.Length, max);
                _pgbSize.Maximum = max;
                _pgbSize.Value   = modData.Length;
            }

            _lblSongLength.Text = string.Format("{0} / 256 positions", _project.XM.SongLength);
            _pgbLength.Maximum  = 256;
            _pgbLength.Value    = _project.XM.SongLength;

            File.WriteAllBytes("output.xm", modData);

            /* pattern debug export
             * var patId = 0;
             * foreach (var pat in _project.XM.Patterns)
             * {
             *  File.WriteAllBytes(string.Format("C:\\Debug\\{0}.bin", patId), pat.UnpackedPatternData);
             *  patId++;
             * }
             *
             * var list = "";
             * foreach (var patItemId in _project.XM.PatternOrderList)
             * {
             *  list += patItemId.ToString() + "\n";
             * }
             * File.WriteAllText("C:\\debug\\patorder.txt", list);
             */
        }