Exemplo n.º 1
0
        /// <summary>
        /// Registers a Capsule to handle callbacks
        /// </summary>
        /// <param name="capsule">Capsule to register</param>
        public void RegisterCapsule(ICapsule capsule)
        {
            // Use Methodname as Key
            string nKey = string.Empty;

            if (capsule.Type == CapsuleType.Invocation)
            {
                // InvocationCapsule
                nKey = ((InvocationCapsule)capsule).InternalDelegate.Method.Name;
            }
            else if (capsule.Type == CapsuleType.Submission)
            {
                // SubmissionCapsule
                nKey = ((SubmissionCapsule)capsule).InternalDelegate.Method.Name;
            }
            // Register Capsule
            if (mRegisteredCapsules.ContainsKey(nKey))
            {
                // Key already contained -> overwrite old Capsule
                mRegisteredCapsules[nKey] = capsule;
            }
            else
            {
                // Add new Capsule
                mRegisteredCapsules.Add(nKey, capsule);
            }
        }
Exemplo n.º 2
0
        public void MarchingMinionsTest()
        {
            ICapsule notes = BigCapsule.GetMarchingMinions(0,
                                                           Note.GetNote(Note.Pitch.A4, 4, 85),
                                                           Note.GetNote(Note.Pitch.B4, 8, 100));

            Assert.AreEqual(36, notes.GetTicksToComplete(), "Ticks to complete");
            IMinion onNote1 = notes.GetReadiedMinion(0);

            Assert.AreEqual(24, onNote1.TicksToComplete());
            Assert.IsFalse(notes.CanDispose());
            IMinion offNote1 = notes.GetReadiedMinion(24);

            Assert.AreEqual(0, offNote1.TicksToComplete());
            Assert.IsFalse(notes.CanDispose());
            Assert.AreEqual(12, notes.GetTicksToComplete(), "Ticks to complete");
            IMinion onNote2 = notes.GetReadiedMinion(24);

            Assert.AreEqual(12, onNote2.TicksToComplete());
            Assert.IsFalse(notes.CanDispose());
            IMinion offNote2 = notes.GetReadiedMinion(36);

            Assert.AreEqual(0, offNote2.TicksToComplete());
            Assert.IsTrue(notes.CanDispose());
        }
Exemplo n.º 3
0
 /// <summary>
 /// <para>Analyses the current Request.</para>
 /// <para>Raises the OnInvoke event of the desired capsule on Callback.</para>
 /// </summary>
 /// <param name="e"></param>
 protected override void OnLoad(EventArgs e)
 {
     // Get identifying AjaxRequestToken
     if (IsCallback)
     {
         string nRequest = this.Page.Request.Params["AjaxXmlHttp"];
         // Check if requested Capsule exists
         if (mRegisteredCapsules.ContainsKey(nRequest))
         {
             // Callback identified and corresponding Capsule found -> Hit event and run back to Client
             ICapsule nCap = mRegisteredCapsules[nRequest];
             if (nCap.Type == CapsuleType.Invocation)
             {
                 // InvocationCapsule
                 string nParam = this.Page.Request.Params["AjaxParam"];
                 ((InvocationCapsule)nCap).RaiseInvocation(this.Page.Response, nParam);
             }
             else if (nCap.Type == CapsuleType.Submission)
             {
                 // SubmissionCapsule
                 ((SubmissionCapsule)nCap).RaiseInvocation(this.Page.Response, this.Page.Request.Params);
             }
         }
     }
 }
Exemplo n.º 4
0
		private void Tock (Object state)
		{
			List<IMinion> toDo = new List<IMinion> ();
			lock (this.capsules) {
				long t = tick++;
				if (capsules.Count == 0)
					return;
				ICapsule c = capsules.GetFirst ();
				IMinion m = c.GetReadiedMinion (t);
				while (m != null) {
					Console.WriteLine ("{0}\t Playing: {1}", t, m);
					capsules.Remove (c);
					if (t == 24) {
						Console.WriteLine ("----- Popped: {0} {1}", c.GetTicksToStart (), capsules);

					}
					if (!c.CanDispose ()) {
						// Sorted to the new start tick
						capsules.Add (c);
					}

					if (t == 24) {
						Console.WriteLine ("------ Reorg: {0} {1}", c.GetTicksToStart (), capsules);

					}
					toDo.Add (m);
					if (capsules.Count == 0)
						break;
					c = capsules.GetFirst ();
					m = c.GetReadiedMinion (t);
				}
			}
			//taskMaster.Invoke (toDo);
		}
Exemplo n.º 5
0
        public IMinion PeekAtNextMinion()
        {
            if (capsules.Count == 0)
            {
                return(null);
            }
            ICapsule c = capsules.GetFirst();

            return(c.PeekAtNextMinion());
        }
Exemplo n.º 6
0
        public static ICapsule GetMarchingMinions(long ticksToStart, params ICapsule[] capsules)
        {
            if (capsules.Length == 0)
            {
                throw new ArgumentException("Can't march with no penguins");
            }
            ICapsule[] newCapsules           = new ICapsule[capsules.Length];
            long       cumulatedTicksToStart = 0;

            for (int i = 0; i < capsules.Length; i++)
            {
                newCapsules [i]        = new BigCapsule(cumulatedTicksToStart, capsules [i]);
                cumulatedTicksToStart += capsules [i].GetTicksToComplete();
            }
            return(new BigCapsule(ticksToStart, newCapsules));
        }
Exemplo n.º 7
0
 public IMinion GetReadiedMinion(long tick)
 {
     lock (this.capsules) {
         if (capsules.Count == 0)
         {
             return(null);
         }
         ICapsule c = capsules.Min();
         IMinion  m = c.GetReadiedMinion(tick - this.ticksToStart);
         if (m != null)
         {
             if (c.CanDispose())
             {
                 capsules.Remove(c);
             }
             this.canDispose |= capsules.Count == 0;
         }
         return(m);
     }
 }
Exemplo n.º 8
0
        public static int Compare(ICapsule a, ICapsule b)
        {
            if (a == b)
            {
                return(0);
            }
            if (a == null)
            {
                return(-1);
            }
            if (b == null)
            {
                return(1);
            }
            int t = a.GetTicksToStart().CompareTo(b.GetTicksToStart());

            if (t != 0)
            {
                return(t);
            }
            return(Equalizer.Compare(a.PeekAtNextMinion(), b.PeekAtNextMinion()));
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            #region Service Provider

            serviceProvider = new ServiceCollection().AddSingleton <ICapsule, CapsuleService>()
                              .AddSingleton <ICore, CoreService>()
                              .AddSingleton <IDragon, DragonService>()
                              .AddSingleton <IHistory, HistoryService>()
                              .AddSingleton <IInfo, InfoService>()
                              .AddSingleton <ILandingPad, LandingPadService>()
                              .AddSingleton <ILaunch, LaunchService>()
                              .AddSingleton <ILaunchPad, LaunchPadService>()
                              .AddSingleton <IMission, MissionService>()
                              .AddSingleton <IPayload, PayloadService>()
                              .AddSingleton <IRocket, RocketService>()
                              .AddSingleton <IRoadster, RoadsterService>()
                              .AddSingleton <IShip, ShipService>()
                              .BuildServiceProvider();

            _capsule    = serviceProvider.GetService <ICapsule>();
            _core       = serviceProvider.GetService <ICore>();
            _dragon     = serviceProvider.GetService <IDragon>();
            _history    = serviceProvider.GetService <IHistory>();
            _info       = serviceProvider.GetService <IInfo>();
            _landingPad = serviceProvider.GetService <ILandingPad>();
            _launch     = serviceProvider.GetService <ILaunch>();
            _launchPad  = serviceProvider.GetService <ILaunchPad>();
            _mission    = serviceProvider.GetService <IMission>();
            _payload    = serviceProvider.GetService <IPayload>();
            _rocket     = serviceProvider.GetService <IRocket>();
            _roadster   = serviceProvider.GetService <IRoadster>();
            _ship       = serviceProvider.GetService <IShip>();

            #endregion
            InitializeApiService();
            Console.ReadLine();
        }
Exemplo n.º 10
0
 public void Setup()
 {
     this.note = Note.GetNote(Note.Pitch.C5, 4, 100);
 }
Exemplo n.º 11
0
		public void Add (ICapsule c)
		{
			capsules.Add (c);
		}