Example #1
0
        private static void InvokeCallBackItem(object state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }
            ScheduledItem item = null;

            item = state as ScheduledItem;
            if ((item != null) && item.CanInvoke)
            {
                try
                {
                    item.InvokeCallBack();
                }
                catch
                {
                }
                finally
                {
                    if (item.Expression.Once)
                    {
                        lock (_removeItems.SyncRoot)
                        {
                            _removeItems.Enqueue(item);
                        }
                    }
                }
            }
        }
            public IDisposable Schedule(TimeSpan dueTime, Action action)
            {
                if (action == null)
                    throw new ArgumentNullException("action");

                var dt = Time + Scheduler.Normalize(dueTime);

                var si = new ScheduledItem(action, dt);

                var queue = GetQueue();

                if (queue == null)
                {
                    queue = new SchedulerQueue(4);
                    queue.Enqueue(si);

                    CurrentThreadScheduler.SetQueue(queue);
                    try
                    {
                        Trampoline.Run(queue);
                    }
                    finally
                    {
                        CurrentThreadScheduler.SetQueue(null);
                    }
                }
                else
                {
                    queue.Enqueue(si);
                }

                return si.Cancellation;
            }
Example #3
0
            public IDisposable Schedule(TimeSpan dueTime, Action action)
            {
                if (action == null)
                {
                    throw new ArgumentNullException("action");
                }
                TimeSpan       dueTime2      = Time + Normalize(dueTime);
                ScheduledItem  scheduledItem = new ScheduledItem(action, dueTime2);
                SchedulerQueue queue         = GetQueue();

                if (queue == null)
                {
                    queue = new SchedulerQueue(4);
                    queue.Enqueue(scheduledItem);
                    SetQueue(queue);
                    try
                    {
                        Trampoline.Run(queue);
                    }
                    finally
                    {
                        SetQueue(null);
                    }
                }
                else
                {
                    queue.Enqueue(scheduledItem);
                }
                return(scheduledItem.Cancellation);
            }
            public IDisposable Schedule(TimeSpan dueTime, Action action)
            {
                if (action == null)
                {
                    throw new ArgumentNullException("action");
                }

                var dt = Time + Scheduler.Normalize(dueTime);

                var si = new ScheduledItem(action, dt);

                var queue = GetQueue();

                if (queue == null)
                {
                    queue = new SchedulerQueue(4);
                    queue.Enqueue(si);

                    CurrentThreadScheduler.SetQueue(queue);

                    try {
                        Trampoline.Run(queue);
                    } finally {
                        CurrentThreadScheduler.SetQueue(null);
                    }
                }
                else
                {
                    queue.Enqueue(si);
                }

                return(si.Cancellation);
            }
Example #5
0
 private static void InvokeCallBack()
 {
     if (_scheduleItems.Count > 0)
     {
         lock (_scheduleItems.SyncRoot)
         {
             if (_scheduleItems.Count > 0)
             {
                 DateTime now = DateTime.Now;
                 for (int i = 0; i < _scheduleItems.Count; i++)
                 {
                     try
                     {
                         ScheduledItem state = _scheduleItems[i] as ScheduledItem;
                         if (state != null)
                         {
                             state.SetCheckTime(now);
                             WorkThread.QueueItem(new WaitCallback(Schedule.InvokeCallBackItem), state);
                         }
                     }
                     catch
                     {
                     }
                 }
             }
         }
     }
 }
Example #6
0
 /// <summary>
 /// Returns a scheduled item by Id, or null if the item does not exist.
 /// </summary>
 public ScheduledItem GetScheduledItemByName(string inScheduledItemName, out bool isRunNow)
 {
     try
     {
         bool          isRunNowPriv  = false;
         ScheduledItem scheduledItem =
             DoSimpleQueryForObjectDelegate <ScheduledItem>(
                 TABLE_NAME, "Name", inScheduledItemName, MAP_SCHEDULED_ITEM_COLUMNS + ";IsRunNow",
                 delegate(IDataReader reader, int rowNum)
         {
             ScheduledItem item = MapScheduledItem(reader);
             isRunNowPriv       = DbUtils.ToBool(reader.GetString(reader.FieldCount - 1));
             return(item);
         });
         isRunNow = isRunNowPriv;
         if (scheduledItem != null)
         {
             PostMapSchedule(scheduledItem);
         }
         return(scheduledItem);
     }
     catch (Spring.Dao.IncorrectResultSizeDataAccessException)
     {
         isRunNow = false;
         return(null); // Not found
     }
 }
Example #7
0
        /// <inheritdoc cref="IScheduler"/>
        public IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action)
        {
            var scheduledItem = new ScheduledItem <uint, TState>(this, state, action, CurrentFrame);

            _queue.Enqueue(scheduledItem);
            return(Disposable.Create(scheduledItem.Cancel));
        }
        protected string ScheduleEditImageUrl(object dataItem)
        {
            ScheduledItem scheduledItem = ((KeyValuePair <string, ScheduledItem>)dataItem).Value;

            return(PermissionsHelper.CanEditFlowById(scheduledItem.FlowId) ? "../Images/UI/application_form_edit.png" :
                   "../Images/UI/application_form_magnify.png");
        }
Example #9
0
 protected virtual void UpdateScheduleRunInfo(ScheduledItem scheduledItem, Activity activity)
 {
     if (scheduledItem != null)
     {
         int count = 3;
         do
         {
             try
             {
                 if (scheduledItem.FrequencyType == ScheduledFrequencyType.OnceThenDelete)
                 {
                     ScheduleManager.Delete(scheduledItem.Id);
                 }
                 else
                 {
                     scheduledItem.LastExecutedOn        = DateTime.Now;
                     scheduledItem.LastExecuteActivityId = activity.Id;
                     scheduledItem.NextRunOn             =
                         ScheduledItem.CalcNextRunTime(scheduledItem.NextRunOn, scheduledItem.FrequencyType,
                                                       scheduledItem.Frequency, true, scheduledItem.StartOn,
                                                       scheduledItem.EndOn, scheduledItem.IsActive);
                     scheduledItem = ScheduleManager.Update(scheduledItem, false);
                 }
                 count = 0;
             }
             catch (Exception e)
             {
                 LOG.Error("Error in UpdateScheduleRunInfo().", e);
             }
         }while (--count > 0);
     }
 }
            public IDisposable Schedule(TimeSpan dueTime, Action action)
            {
                if (action == null)
                {
                    throw new ArgumentNullException("action");
                }
                TimeSpan       dueTime2       = Scheduler.CurrentThreadScheduler.Time + Scheduler.Normalize(dueTime);
                ScheduledItem  scheduledItem  = new ScheduledItem(action, dueTime2);
                SchedulerQueue schedulerQueue = Scheduler.CurrentThreadScheduler.GetQueue();

                if (schedulerQueue == null)
                {
                    schedulerQueue = new SchedulerQueue(4);
                    schedulerQueue.Enqueue(scheduledItem);
                    Scheduler.CurrentThreadScheduler.SetQueue(schedulerQueue);
                    try
                    {
                        Scheduler.CurrentThreadScheduler.Trampoline.Run(schedulerQueue);
                    }
                    finally
                    {
                        Scheduler.CurrentThreadScheduler.SetQueue(null);
                    }
                }
                else
                {
                    schedulerQueue.Enqueue(scheduledItem);
                }
                return(scheduledItem.Cancellation);
            }
Example #11
0
        protected virtual string GetResultFileName(ScheduledItem scheduledItem)
        {
            string fileName = string.Format("{0}.zip", Guid.NewGuid().ToString());

            fileName = FileUtils.ReplaceInvalidFilenameChars(fileName, '_');
            return(fileName);
        }
Example #12
0
        public void ScheduleJob <T>(T jobInfo, DateTime schedule, Recurrence r = null, string jobRoute = null) where T : class
        {
            var si = new ScheduledItem(_notUnique, JsonConvert.SerializeObject(jobInfo, _settings), typeof(T),
                                       jobRoute, schedule, r);

            _jobs.Add(si);
        }
Example #13
0
            public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action)
            {
                var s = new ScheduledItem <TimeSpan, TState>(this, state, action, dueTime);

                _queue.Add(s);
                return(Disposable.Create(() => _queue.Remove(s)));
            }
Example #14
0
        public ScheduledItem CreateRunOnceLocalServiceSchedule(string scheduleName, string serviceName, DateTime nextRuntime,
                                                               ByIndexOrNameDictionary <string> parameters)
        {
            if (string.IsNullOrEmpty(scheduleName))
            {
                throw new ArgumentException("scheduleName is null");
            }
            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentException("serviceName is null");
            }
            DataService dataService = _serviceDao.GetDataServiceByName(serviceName);

            if (dataService == null)
            {
                throw new ArgumentException(string.Format("The service \"{0}\" could not be found", serviceName));
            }
            ScheduledItem scheduledItem = new ScheduledItem();

            scheduledItem.SourceId      = dataService.Id;
            scheduledItem.SourceType    = ScheduledItemSourceType.LocalService;
            scheduledItem.FlowId        = dataService.FlowId;
            scheduledItem.TargetType    = ScheduledItemTargetType.None;
            scheduledItem.Name          = scheduleName;
            scheduledItem.Frequency     = 1;
            scheduledItem.FrequencyType = ScheduledFrequencyType.OnceThenDelete;
            scheduledItem.IsActive      = true;
            scheduledItem.StartOn       = nextRuntime;
            scheduledItem.NextRunOn     = nextRuntime;
            scheduledItem.EndOn         = nextRuntime + TimeSpan.FromDays(365);
            scheduledItem.SourceArgs    = parameters;
            scheduledItem.ModifiedById  = _accountManager.RuntimeAccount.Id;
            Save(scheduledItem);
            return(scheduledItem);
        }
Example #15
0
        public void SetScheduleRuntime(string scheduleName, DateTime nextRuntime, ByIndexOrNameDictionary <string> parameters)
        {
            bool          runNow;
            ScheduledItem item = GetScheduledItemByName(scheduleName, out runNow);

            if (item == null)
            {
                throw new ArgumentException(string.Format("Could not locate a schedule with the name \"{0}\"", scheduleName));
            }
            if (!item.IsActive)
            {
                throw new ArgumentException(string.Format("The schedule \"{0}\" is inactive and could not be scheduled.  Please active the schedule and try again.",
                                                          scheduleName));
            }
            if ((item.StartOn > nextRuntime) || (item.EndOn < nextRuntime))
            {
                throw new ArgumentException(string.Format("The schedule \"{0}\" could not be scheduled to run at {1} since it has an execution range of {2} to {3}",
                                                          scheduleName, nextRuntime.ToString(), item.StartOn.ToString(),
                                                          item.EndOn.ToString()));
            }

            item.NextRunOn  = nextRuntime;
            item.SourceArgs = parameters;

            Save(item);
        }
Example #16
0
    public IDisposable SchedulePeriodic(float dueTime, Action action)
    {
        var item = new ScheduledItem(Now + dueTime, action, dueTime);

        m_timerQueue.Enqueue(item);
        return(item.Cancellation);
    }
Example #17
0
        protected string ScheduleToolTipEditName(object dataItem)
        {
            ScheduledItem scheduledItem = ((KeyValuePair <string, ScheduledItem>)dataItem).Value;
            string        tooltip       = FlowEditPrefixTextById(scheduledItem.FlowId) + " '" +
                                          ScheduleDisplayName(dataItem) + "'";

            return(tooltip);
        }
        public ScheduledItem RunNow(string scheduleId, NodeVisit visit)
        {
            ValidateByRole(visit, SystemRoleType.Program);
            ScheduledItem item = _scheduleDao.GetScheduledItem(scheduleId);

            if (item == null)
            {
                throw new ArgumentException(string.Format("Cannot load a schedule with id \"{0}\"", scheduleId));
            }
            return(RunNow(item, visit));
        }
Example #19
0
        public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action)
        {
            var si = new ScheduledItem <TimeSpan, TState>(Scheduler.Immediate, state, action, dueTime);

            lock (EntryGate)
            {
                _sQueue.Enqueue(si);
            }
            manEv.Set();
            return(si);
        }
Example #20
0
 public ScheduledItem[] MakeScheduledItemsForDM (String dm_id, int[] items) {
     ScheduledItem[] scheduledItems = new ScheduledItem[items.Length];
     for (int i=0;i<items.Length;i++)
     {
         ScheduledItem scheduledItem = new ScheduledItem();   
         scheduledItem.Time = i * 60; //makes items at exactly every 60s now -Lisa 12/20/11
         scheduledItem.DM_ID = dm_id;
         scheduledItem.ID = items[i].ToString();
         scheduledItems.SetValue(scheduledItem, i);
     }
     return scheduledItems;
 }
Example #21
0
        private void UpdateCPE(String dmId, double ffCpe, double ttCpe, int time)
        {
            if (!_dmCPEs.ContainsKey(dmId))
            {
                _dmCPEs.Add(dmId, new CPEPair(dmId, ffCpe, ttCpe, time));
            }
            else
            {
                _dmCPEs[dmId].FF_CPE          = ffCpe;
                _dmCPEs[dmId].TT_CPE          = ttCpe;
                _dmCPEs[dmId].LastTimeUpdated = time;
            }
            _lastCPEUpdateTime = time;
            AppendToInfoBox(tbInfoBox, String.Format("{0} CPEs updated to: FindFix={1}, TrackTarget={2}\r\n", dmId, ffCpe, ttCpe));
            //if they have a queued item waiting, send it now!

            if (_timelineEvents.Count() > 0 && !_hasFinishedPreTest)
            {
                _readyToSendItems = true; //next time tick, will check for next scheduled item
                return;                   //only adaptively choose if there are no more scheduled items remaining.
            }
            _hasFinishedPreTest = true;
            //Do stuff!
            List <int> usedItemIds    = new List <int>();
            CellRange  nextItemRange  = _itemSelector.GetNextItem(ffCpe, ttCpe);
            T_Item     nextItem       = SelectNextItemByRange(nextItemRange, dmId);
            int        failedAttempts = 0;

            while (nextItem == null && _items.Count > usedItemIds.Count)//0)
            {
                failedAttempts++;
                usedItemIds.Add(nextItemRange.CellNumber);
                //get a similar cell range and try again
                nextItemRange = _itemSelector.GetNextItem(ffCpe, ttCpe, usedItemIds, failedAttempts);
                nextItem      = SelectNextItemByRange(nextItemRange, dmId);
            }
            if (nextItem == null)
            {
                Console.WriteLine("Serious issues where we can't find a good fit");
                nextItem = _items[Math.Min(_items.Count, 5).ToString()];
            }
            //Thread.Sleep(1000); //TEMP
            ScheduledItem si = new ScheduledItem();

            si.DM_ID = dmId;
            si.ID    = nextItem.ID;
            si.Time  = time;
            _timelineEvents.Add(si);
            _readyToSendItems = true;
            //SendItem(nextItem, dmId, time);
            AppendToInfoBox(tbInfoBox, String.Format("{3}: Next Item ({4}) selected for {0}: FindFixDifficulty={1}, TrackTargetDifficulty={2}\r\n", dmId, nextItem.Parameters.FF_Difficulty, nextItem.Parameters.TT_Difficulty, time, nextItem.ID));
        }
        public void Delete(ScheduledItem instance, NodeVisit visit)
        {
            ValidateCanEditFlowById(visit, instance.FlowId);
            string flowName = _flowManager.GetDataFlowNameById(instance.FlowId);

            TransactionTemplate.Execute(delegate
            {
                _scheduleDao.Delete(instance.Id);
                ActivityManager.LogAudit(NodeMethod.None, flowName, instance.Name, visit, "{0} deleted scheduled item: {1}.",
                                         visit.Account.NaasAccount, instance.ToString());
                return(null);
            });
        }
Example #23
0
 public ScheduledItem[] MakeScheduledItemsForDM(String dm_id, int[] items)
 {
     ScheduledItem[] scheduledItems = new ScheduledItem[items.Length];
     for (int i = 0; i < items.Length; i++)
     {
         ScheduledItem scheduledItem = new ScheduledItem();
         scheduledItem.Time  = i * 60; //makes items at exactly every 60s now -Lisa 12/20/11
         scheduledItem.DM_ID = dm_id;
         scheduledItem.ID    = items[i].ToString();
         scheduledItems.SetValue(scheduledItem, i);
     }
     return(scheduledItems);
 }
Example #24
0
        protected virtual void ProcessFileSource(ScheduledItem scheduledItem, Activity activity,
                                                 string transactionId)
        {
            if (!File.Exists(scheduledItem.SourceId))
            {
                throw new FileNotFoundException(string.Format("Could not find source file \"{0}\"",
                                                              scheduledItem.SourceId));
            }

            DocumentManager.AddDocument(transactionId, CommonTransactionStatusCode.Processed,
                                        null, scheduledItem.SourceId);
            LogActivity(activity, "Added document \"{0}\" to transaction.", scheduledItem.SourceId);
        }
Example #25
0
        protected virtual void ProcessWebServiceSolicitSource(ScheduledItem scheduledItem, Activity activity,
                                                              string transactionId)
        {
            PartnerIdentity partner = _partnerManager.GetById(scheduledItem.SourceId);

            if (partner == null)
            {
                throw new ArgumentException(string.Format("Invalid partner id \"{0}.\"  Could not find partner for scheduled item \"{1}\".",
                                                          scheduledItem.TargetId, scheduledItem.Name));
            }

            string filePath = Path.Combine(SettingsProvider.TempFolderPath, GetResultFileName(scheduledItem));

            string networkTransactionId;
            EndpointVersionType endpointVersion;
            string endpointUrl;
            string networkFlowName = null, networkFlowOperation = scheduledItem.SourceRequest;

            using (INodeEndpointClient client = GetNodeClient(partner, activity, scheduledItem.SourceEndpointUser))
            {
                try
                {
                    if (client.Version == EndpointVersionType.EN11)
                    {
                        networkTransactionId = client.Solicit(null, scheduledItem.SourceRequest, scheduledItem.GetTranformedSourceArgs(),
                                                              new string[] { SettingsProvider.Endpoint11Url });
                    }
                    else
                    {
                        networkTransactionId = client.Solicit(scheduledItem.SourceFlow, scheduledItem.SourceRequest,
                                                              scheduledItem.GetTranformedSourceArgs(),
                                                              new string[] { SettingsProvider.Endpoint20Url });
                        networkFlowName = scheduledItem.SourceFlow;
                    }
                }
                catch (Exception e)
                {
                    LogActivityError(activity, "Error returned from node endpoint: \"{0}\"", ExceptionUtils.GetDeepExceptionMessage(e));
                    throw;
                }
                endpointVersion = client.Version;
                endpointUrl     = client.Url;
            }
            LogActivity(activity, "Performed Solicit of partner \"{0}\" at url \"{1}\" with returned transaction id \"{2}\"",
                        partner.Name, partner.Url, networkTransactionId);
            _transactionManager.SetNetworkIdAndEndpointUserId(transactionId, networkTransactionId, endpointVersion, endpointUrl,
                                                              networkFlowName, networkFlowOperation,
                                                              null, scheduledItem.SourceEndpointUser);
            //_transactionManager.SetNetworkId(transactionId, networkTransactionId, endpointVersion, endpointUrl,
            //                                 networkFlowName, networkFlowOperation);
        }
        void WaitForFire(ScheduledItem actionInstance1)
        {
            for (int i = 0; i < 30 * 2; i++)
            {
                Thread.Sleep(500);
                var res = Entity.GetByName <Resource>(actionInstance1.Id.ToString());   // The Id is the name of the created reosurce
                if (res.Count() > 0)
                {
                    return;
                }
            }

            Assert.Fail("Didn't run");
        }
Example #27
0
        private void SaveAndRun(ScheduledItem item, bool?runNow)
        {
            if (item == null)
            {
                throw new ArgumentException("Null item");
            }
            DateTime now         = DateTime.Now;
            string   id          = null;
            bool     isRunNow    = runNow.HasValue ? runNow.Value : false;
            string   columnNames = "Name;FlowId;StartOn;EndOn;SourceType;SourceId;SourceFlow;SourceOperation;TargetType;" +
                                   "TargetId;TargetFlow;TargetOperation;LastExecuteActivityId;LastExecutedOn;NextRun;" +
                                   "FrequencyType;Frequency;ModifiedBy;ModifiedOn;IsActive;IsRunNow;ExecuteStatus";
            List <object> columnValues =
                CollectionUtils.CreateList <object>(item.Name, item.FlowId, DbUtils.ToDbDate(item.StartOn),
                                                    DbUtils.ToDbDate(item.EndOn),
                                                    item.SourceType.ToString(), item.SourceId, item.SourceFlow ?? string.Empty,
                                                    item.SourceRequest ?? string.Empty, item.TargetType.ToString(), item.TargetId,
                                                    item.TargetFlow ?? string.Empty, item.TargetRequest ?? string.Empty, item.LastExecuteActivityId,
                                                    DbUtils.ToDbDate(item.LastExecutedOn),
                                                    DbUtils.ToDbDate(item.NextRunOn), item.FrequencyType.ToString(),
                                                    item.Frequency, item.ModifiedById, now, DbUtils.ToDbBool(item.IsActive),
                                                    DbUtils.ToDbBool(isRunNow), item.ExecuteStatus.ToString());

            if (AreEndpointUsersEnabled)
            {
                columnNames += ";SourceEndpointUser;TargetEndpointUser";
                columnValues.AddRange(new object[] { item.SourceEndpointUser, item.TargetEndpointUser });
            }
            TransactionTemplate.Execute(delegate
            {
                if (string.IsNullOrEmpty(item.Id))
                {
                    id          = IdProvider.Get();
                    columnNames = "Id;" + columnNames;
                    columnValues.Insert(0, id);
                    DoInsertWithValues(TABLE_NAME, columnNames, columnValues);
                }
                else
                {
                    DoSimpleUpdateOneWithValues(TABLE_NAME, "Id", item.Id, columnNames, columnValues);
                }
                SaveScheduleSourceArgs(id ?? item.Id, item.SourceArgs);
                return(null);
            });
            if (id != null)
            {
                item.Id = id;
            }
            item.ModifiedOn = now;
        }
Example #28
0
        public void Reschedule(ScheduledItem item)
        {
            if (!string.IsNullOrWhiteSpace(item.Recurrence))
            {
                Recurrence r             = JsonConvert.DeserializeObject <Recurrence>(item.Recurrence);
                DateTime   nextOccurence = r.GetNextRecurrence();

                var si = new ScheduledItem(item.UniqueName, item.Message, item.Type, item.Route,
                                           nextOccurence, r);
                _jobs.Add(si);
            }

            _jobs.Remove(item);
        }
Example #29
0
        public void ScheduleJobOnlyOnce <T>(string uniqueName, T jobInfo, DateTime schedule, Recurrence r = null, string jobRoute = null) where T : class
        {
            var exists = true;

            exists = (from si in _jobs where si.UniqueName == uniqueName select si).Any();



            if (!exists)
            {
                var si = new ScheduledItem(uniqueName, JsonConvert.SerializeObject(jobInfo, _settings),
                                           typeof(T), jobRoute, schedule, r);
                _jobs.Add(si);
            }
        }
 protected IList <ScheduledItem> FilterSchedulesForUser(NodeVisit visit, IList <ScheduledItem> schedules)
 {
     if (!CollectionUtils.IsNullOrEmpty(schedules))
     {
         for (int i = schedules.Count - 1; i >= 0; --i)
         {
             ScheduledItem schedule = schedules[i];
             if (!CanUserViewFlowById(visit, schedule.FlowId))
             {
                 schedules.RemoveAt(i);
             }
         }
     }
     return(schedules);
 }
Example #31
0
 public ScheduledItem[] MakeScheduledItemsForDM (String dm_id, int[] items) {
     ScheduledItem[] scheduledItems = new ScheduledItem[items.Length];
     for (int i=0;i<items.Length;i++)
     {
         ScheduledItem scheduledItem = new ScheduledItem();
         if (i== 0)
             scheduledItem.Time = random.Next(10);
         else
             scheduledItem.Time = i * 60 + random.Next(-10, 10);
         scheduledItem.DM_ID = dm_id;
         scheduledItem.ID = items[i].ToString();
         scheduledItems.SetValue(scheduledItem, i);
     }
     return scheduledItems;
 }
Example #32
0
		public ConfigureScheduledItems(ScheduledItem item)
			: this()
		{
			_scheduledItem = item;
			_filePath = _scheduledItem.ItemFilePath;
			startTimePicker.Value = _scheduledItem.ScheduledItemStartDate;

			if (_scheduledItem.ItemFilePath.EndsWith(".pro")) {
				_program = ApplicationServices.LoadProgram(_scheduledItem.ItemFilePath);
				programLabel.Text = GetName();
			}
			else {
				sequenceLabel.Text = GetName();
				_program = new Program();
			}
		}
Example #33
0
        private static Task RunAndAwait(Func <bool> completionSource)
        {
            if (completionSource())
            {
                return(Task.CompletedTask);
            }

            ScheduledItem scheduledItem = new ScheduledItem(completionSource);

            lock (SchedulerLock)
            {
                ScheduledItems.Add(scheduledItem);
            }

            return(scheduledItem.TaskCompletionSource.Task);
        }
Example #34
0
 public void Add(ScheduledItem i)
 {
     if (_list.Count == 0)
     {
         _list.Add(i);
         return;
     }
     for (int x = 0; x < _list.Count; x++)
     {
         if (i.Time < _list[x].Time)
         {
             _list.Insert(x, i);
             return;
         }
     }
     _list.Add(i);
 }
Example #35
0
		private void BuildScheduledItem()
		{
			if (_scheduledItem != null) {
				//since you already have a scheduled item and you can control where and when on the calendar control
				//We only need to change the sequence or program here.
				_scheduledItem.ItemFilePath = _filePath;
			}
			else {
				TimeSpan t1 = GetRunLength();
				if (t1.Ticks == 0.0) {
					t1 = new TimeSpan(_runLength);
				}
				ScheduledItem item = new ScheduledItem(Guid.NewGuid(), _filePath, (int) _calendarItem.Date.DayOfWeek,
				                                       _calendarItem.StartDate.TimeOfDay, t1)
				                     	{ScheduledItemStartDate = _calendarItem.StartDate};
				_scheduledItem = item;
			}
		}
        private void BuildScheduledItem()
        {
            if (_scheduledItem != null)
            {
                //since you already have a scheduled item and you can control where and when on the
                //calendar control
                //We only need to change the sequence or program here.
                _scheduledItem.ItemFilePath = _filePath;
            }
            else
            {
                if (_calendarItem.Duration.Ticks > 0)
                {
                    _runLength = _calendarItem.Duration.Ticks;
                }

                //since this is new create the whole enchilada
                ScheduledItem item = new ScheduledItem(Guid.NewGuid(), _filePath, (int)_calendarItem.Date.DayOfWeek, _calendarItem.StartDate.TimeOfDay, new TimeSpan(_runLength)) { ScheduledItemStartDate = _calendarItem.StartDate };

                _scheduledItem = item;
            }
        }
Example #37
0
        public void Generate(String outputFilename) {

            //minute, DM, vesselID,"stimuli,stimuli"

            //Example Data for 20 min seaside scenario 2
            //Right now I create this with "replace" in notepad.
            object[][] spreadsheet = 

new object[][] {
new object [] {1,"BAMS",2469,"Move, Reveal"}, new object [] {
1,"BAMS",7738,"Move, Reveal"}, new object [] {
1,"BAMS",2779,"Move, Reveal"}, new object [] {
1,"BAMS",1604,"Move, Reveal"}, new object [] {
1,"BAMS",2228,"Move, Reveal"}, new object [] {
1,"BAMS",6348,"Move, Reveal"}, new object [] {
1,"BAMS",2994,"Move, Reveal"}, new object [] {
1,"FireScout",7648,"Move, Reveal"}, new object [] {
1,"FireScout",1818,"Move, Reveal"}, new object [] {
1,"FireScout",4633,"Move, Reveal"}, new object [] {
1,"FireScout",5069,"Move, Reveal"}, new object [] {
1,"FireScout",3734,"Move, Reveal"}, new object [] {
1,"FireScout",2213,"Move, Reveal"}, new object [] {
1,"FireScout",4475,"Move, Reveal"}, new object [] {
1,"FireScout",4633,"Move, Reveal"}, new object [] {
2,"BAMS",8736,"Move, Reveal"}, new object [] {
2,"BAMS",1961,"Move, Reveal"}, new object [] {
2,"BAMS",5553,"Move, Reveal"}, new object [] {
2,"BAMS",5958,"Move, Reveal"}, new object [] {
2,"FireScout",8893,"Move, Reveal"}, new object [] {
3,"BAMS",2228,"Move"}, new object [] {
3,"FireScout",1848,"Move, Reveal"}, new object [] {
4,"BAMS",1135,"Reveal"}, new object [] {
4,"FireScout",3502,"Move, Reveal"}, new object [] {
5,"FireScout",7648,"Move"}, new object [] {
5,"FireScout",1818,"Move, Reveal"}, new object [] {
6,"BAMS",2377,"Move, Reveal"}, new object [] {
6,"FireScout",3593,"Move, Reveal"}, new object [] {
7,"BAMS",8948,"Move, Reveal"}, new object [] {
7,"BAMS",3106,"Move, Reveal"}, new object [] {
7,"FireScout",3593,"Move"}, new object [] {
7,"FireScout",6074,"Move, Reveal"}, new object [] {
7,"FireScout",6077,"Move, Reveal"}, new object [] {
7,"FireScout",9167,"Move, Reveal"}, new object [] {
7,"FireScout",4318,"Move, Reveal"}, new object [] {
7,"FireScout",7679,"Move, Reveal"}, new object [] {
8,"FireScout",7232,"Move, Reveal"}, new object [] {
9,"BAMS",7112,"Move, Reveal"}, new object [] {
10,"FireScout",3170,"Move, Reveal"}, new object [] {
11,"BAMS",4940,"Move, Reveal"}, new object [] {
11,"BAMS",5304,"Move, Reveal"}, new object [] {
11,"BAMS",5965,"Move, Reveal"}, new object [] {
11,"BAMS",8560,"Move, Reveal"}, new object [] {
11,"FireScout",1606,"Move, Reveal"}, new object [] {
11,"FireScout",7151,"Move, Reveal"}, new object [] {
13,"BAMS",1212,"Move, Reveal"}, new object [] {
13,"BAMS",9809,"Move, Reveal"}, new object [] {
13,"BAMS",4685,"Move, Reveal"}, new object [] {
13,"BAMS",1608,"Move, Reveal"}, new object [] {
13,"BAMS",3537,"Move, Reveal"}, new object [] {
13,"FireScout",4322,"Move, Reveal"}, new object [] {
13,"FireScout",4257,"Move, Reveal"}, new object [] {
13,"FireScout",3170,"Move, Reveal"}, new object [] {
14,"BAMS",1621,"Move, Reveal"}, new object [] {
14,"FireScout",7626,"Move, Reveal"}, new object [] {
15,"FireScout",6081,"Move, Reveal"}, new object [] {
15,"BAMS",3957,"Move, Reveal"}, new object [] {
15,"BAMS",9081,"Move, Reveal"}, new object [] {
15,"BAMS",1966,"Move, Reveal"}, new object [] {
15,"FireScout",8940,"Move, Reveal"}, new object [] {
15,"FireScout",6015,"Move, Reveal"}, new object [] {
18,"BAMS",9081,"Move"}, new object [] {
18,"BAMS",1604,"Move, Reveal"}, new object [] {
18,"BAMS",4306,"Move, Reveal"}, new object [] {
18,"FireScout",2471,"Move, Reveal"}, new object [] {
18,"FireScout",4758,"Move, Reveal"}, new object [] {
18,"FireScout",4257,"Move"}, new object [] {
19,"BAMS",2285,"Move, Reveal"}, new object [] {
19,"BAMS",9228,"Move, Reveal"}, new object [] {
19,"BAMS",6290,"Move, Reveal"}};


            List<ScheduledItem> allScheduledItems = new List<ScheduledItem>();
            List<T_Item>allItems = new List<T_Item>();
            foreach (object[] line in spreadsheet)
            {
                if (line.Length < 4)
                    continue;   //allows you to paste in and ignore empty lines (with no stimuli)
                int minute = (int)line[0];
                int time = minute *60;
                String dm_id = MakeDMID((String)line[1]);
                int obj_id = (int)line[2];
                String actions = (String)line[3];
                if (actions == null)
                    continue;
                ScheduledItem scheduledItem = null;
                T_Item item = null;
                //see if we've already made an "ScheduledItem" that this action belongs to
                foreach (ScheduledItem maybeScheduledItem in allScheduledItems)
                {
                    if (maybeScheduledItem.DM_ID == dm_id && maybeScheduledItem.Time == time)
                    {
                        scheduledItem = maybeScheduledItem;
                        //find corresponding abstract "Item"
                        foreach (T_Item maybeItem in allItems) {
                            if (maybeItem.ID == scheduledItem.ID) {
                                item = maybeItem;
                            }
                        }
                        break;
                    }
                }
                if (scheduledItem == null)
                    //make new "scheduledItem" and "item" (uid)
                {
                    //Dummy item that contains a UID and empty actions list
                    item = new T_Item();
                    uid = uid+1;
                    item.ID = uid.ToString();
                    item.Action = new object[0];
                    item.Parameters = new Parameters();
                    item.Parameters.ThreatType = T_ThreatType.Nonimminent;
                    item.Parameters.Threat = T_Threat.Unambiguous;
                    item.Parameters.Crossing = false;
                    item.Parameters.Groupings = T_Groupings.One;
                    item.Parameters.PlayerResources = T_ResourceAvailability.Available;
                    item.Parameters.TeammateResources = T_ResourceAvailability.Available;
                    item.Parameters.FF_Difficulty =1.0;
                    item.Parameters.TT_Difficulty = 1.0;
                    allItems.Add(item);

                    scheduledItem = new ScheduledItem();
                    scheduledItem.Time = time;
                    scheduledItem.DM_ID = dm_id;
                    scheduledItem.ID = uid.ToString();
                    allScheduledItems.Add(scheduledItem);
                }

                //OK.  We've verified that the scheduled item exists and we have the pointer to the item.
                //Add actions to item.Action:
                List<T_ScriptedItem> listToAddToAction = new List<T_ScriptedItem>();
                if (actions.Contains("Reveal"))
                {
                    T_ScriptedItem reveal = new T_ScriptedItem();
                    reveal.ID = obj_id.ToString();
                    reveal.ActionType = "Reveal";
                    listToAddToAction.Add(reveal);
                }
                if (actions.Contains("Move"))
                {
                    T_ScriptedItem move = new T_ScriptedItem();
                    move.ID = obj_id.ToString();
                    move.ActionType = "Move";
                    listToAddToAction.Add(move);
                }
                List<object> copyOfActions = item.Action.ToList();
                copyOfActions.AddRange(listToAddToAction);
                item.Action = copyOfActions.ToArray();
            }
            T_SeamateItems seamateItems = new T_SeamateItems();
            seamateItems.Timeline = allScheduledItems.ToArray();
            seamateItems.Items = allItems.ToArray();
            System.IO.File.WriteAllText(@"C:\Work\SEAMATE\"+outputFilename+".xml", seamateItems.Serialize()); 
        }