Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of Dates that are the next fire times of a
        /// <see cref="ITrigger" />.
        /// The input trigger will be cloned before any work is done, so you need
        /// not worry about its state being altered by this method.
        /// </summary>
        /// <param name="trigg">The trigger upon which to do the work</param>
        /// <param name="cal">The calendar to apply to the trigger's schedule</param>
        /// <param name="numTimes">The number of next fire times to produce</param>
        /// <returns>List of java.util.Date objects</returns>
        public static IList<DateTimeOffset> ComputeFireTimes(IOperableTrigger trigg, ICalendar cal, int numTimes)
        {
            List<DateTimeOffset> lst = new List<DateTimeOffset>();

            IOperableTrigger t = (IOperableTrigger) trigg.Clone();

            if (t.GetNextFireTimeUtc() == null || !t.GetNextFireTimeUtc().HasValue)
            {
                t.ComputeFirstFireTimeUtc(cal);
            }

            for (int i = 0; i < numTimes; i++)
            {
                DateTimeOffset? d = t.GetNextFireTimeUtc();
                if (d.HasValue)
                {
                    lst.Add(d.Value);
                    t.Triggered(cal);
                }
                else
                {
                    break;
                }
            }

            return lst.AsReadOnly();
        }
Exemplo n.º 2
0
		/// <summary>
		/// Start this instance.
		/// <para xml:lang="es">
		/// Inicia la instancia del objeto Calendar.
		/// </para>
		/// </summary>
		public override void Start()
		{
			base.Start();

			// Create an Stack
			IStack stack = Platform.Current.Create<IStack>();

			// Creates an Label with text and a specific size and adds it to the stack.
			lblLabel = Platform.Current.Create<ILabel>();
			lblLabel.Text = "Select 1 day";
			lblLabel.Height = 30;
			stack.Children.Add(lblLabel);

			// Creates an Calendar with text specific and adds it to the stack.
			calendar = Platform.Current.Create<ICalendar>();
			calendar.Name = "calendar";
			calendar.Bold = true;
			stack.Children.Add(calendar);

			// Creates the Button cmdChange with text specific, with the event also click and adds it to the stack.
			IButton cmdChange = Platform.Current.Create<IButton>();
			cmdChange.Text = "Change";
			cmdChange.Click += CmdChange_Click;
			stack.Children.Add(cmdChange);

			// Creates the Button cmdClose with text specific, with the event also click and adds it to the stack.
			IButton cmdClose = Platform.Current.Create<IButton>();
			cmdClose.Text = "Close";
			cmdClose.Click += CmdClose_Click;
			stack.Children.Add(cmdClose);

			// Establishes the content and title of the page
			Platform.Current.Page.Title = "Test label";
			Platform.Current.Page.Content = stack;
		}
Exemplo n.º 3
0
        public static TriggerDetailDto Create(ITrigger trigger, ICalendar calendar)
        {
            var simpleTrigger = trigger as ISimpleTrigger;
            if (simpleTrigger != null)
            {
                return new SimpleTriggerDetailDto(simpleTrigger, calendar);
            }
            var cronTrigger = trigger as ICronTrigger;
            if (cronTrigger != null)
            {
                return new CronTriggerDetailDto(cronTrigger, calendar);
            }
            var calendarIntervalTrigger = trigger as ICalendarIntervalTrigger;
            if (calendarIntervalTrigger != null)
            {
                return new CalendarIntervalTriggerDetailDto(calendarIntervalTrigger, calendar);
            }
            var dailyTimeIntervalTrigger = trigger as IDailyTimeIntervalTrigger;
            if (dailyTimeIntervalTrigger != null)
            {
                return new DailyTimeIntervalTriggerDetailDto(dailyTimeIntervalTrigger, calendar);
            }

            return new TriggerDetailDto(trigger, calendar);
        }
 /// <summary>
 /// Create a <see cref="CronCalendar" /> with the given cron expression and 
 /// <see cref="BaseCalendar" />. 
 /// </summary>
 /// <param name="baseCalendar">
 /// the base calendar for this calendar instance 
 /// see BaseCalendar for more information on base
 /// calendar functionality
 /// </param>
 /// <param name="expression">a String representation of the desired cron expression</param>
 /// <param name="timeZone"></param>
 public CronCalendar(ICalendar baseCalendar,
                     string expression,
                     TimeZone timeZone)
     : base(baseCalendar, timeZone)
 {
     cronExpression = new CronExpression(expression);
 }
Exemplo n.º 5
0
		public override void Start()
		{
			base.Start();

			IStack stack = Platform.Current.Create<IStack>();

			lblLabel = Platform.Current.Create<ILabel>();
			lblLabel.Text = "Select 1 day";
			lblLabel.Height = 30;
			stack.Children.Add(lblLabel);

			calendar = Platform.Current.Create<ICalendar>();
			calendar.Name = "calendar";
			//calendar.BackgroundColor = new Color(1,0,0,255);
			calendar.Bold = true;
			stack.Children.Add(calendar);

			IButton cmdChange = Platform.Current.Create<IButton>();
			cmdChange.Text = "Change";
			cmdChange.Click += CmdChange_Click;
			stack.Children.Add(cmdChange);

			IButton cmdClose = Platform.Current.Create<IButton>();
			cmdClose.Text = "Close";
			cmdClose.Click += CmdClose_Click;
			stack.Children.Add(cmdClose);

			Platform.Current.Page.Title = "Test label";
			Platform.Current.Page.Content = stack;
		}
Exemplo n.º 6
0
		public Time (ulong timestamp, ICalendar calendar)
		{
			if (calendar == null)
				throw new ArgumentNullException ("calendar");

			this.Calendar = calendar;
			this.Calendar.DecodeTimestamp (timestamp, this);
		}
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="calendar"></param>
        public override void SetCalendar(ICalendar calendar) {
            var cal = (HolidayCalendar)calendar;
            if (cal == null)
                return;

            this.Dates = new BindableCollection<DateTime>(cal.ExcludedDates);
            this.NotifyOfPropertyChange(() => this.Dates);
        }
 public ExpenseReportController(IExpenseReportBuilder expenseReportBuilder, IUserSession session,
     IWorkflowFacilitator workflowFacilitator, Bus bus, ICalendar calendar)
 {
     _expenseReportBuilder = expenseReportBuilder;
     _session = session;
     _workflowFacilitator = workflowFacilitator;
     _bus = bus;
     _calendar = calendar;
 }
Exemplo n.º 9
0
 protected CalendarDetailDto(ICalendar calendar)
 {
     CalendarType = calendar.GetType().AssemblyQualifiedNameWithoutVersion();
     Description = calendar.Description;
     if (calendar.CalendarBase != null)
     {
         CalendarBase = Create(calendar.CalendarBase);
     }
 }
 public override IEnumerable<PushedEvent> Push(ICalendar calendar)
 {
     Log.Info(String.Format("Pushing calendar [{0}] to outlook", calendar.Id));
     var result = new List<PushedEvent>();
     foreach (var evt in calendar.Events)
     {
     }
     return result;
 }
 public CalendarSynchronizationWorker(
     ICalendar sourceCalendar,
     ICalendar destinationCalendar,
     ISynchronizationConfiguration synchronizationConfiguration,
     AutoResetEvent saveSynchronizationConfigurationsEvent)
     : this(
         sourceCalendar, destinationCalendar, synchronizationConfiguration, saveSynchronizationConfigurationsEvent,
         new CalendarEventSynchronizer())
 { }
Exemplo n.º 12
0
        public AddEvent(GoogleCalendar.Data.Event monEvt, EventControler controler, ICalendar parent)
        {
            this.InitializeComponent();

            this.Title.Text = IConstantes.TITLE_ADD_EVT;
            this.Button_Cancel.Content = IConstantes.BUTTON_CANCEL;
            this.Button_Add.Content = IConstantes.BUTTON_ADD;

            this.DataContext = new VIEWMODEL.Event.EventModelView(monEvt, controler,parent);
        }
Exemplo n.º 13
0
        public ModifEvent(GoogleCalendar.Data.Event monEvt,EventControler controler, ICalendar parent)
        {
            this.InitializeComponent();

            this.Title.Text = IConstantes.TITLE_UPDATE_EVT;
            this.Button_Cancel.Content = IConstantes.BUTTON_CANCEL;
            this.Button_Add.Content = IConstantes.BUTTON_UPDATE;
            this.Button_Delete.Content = IConstantes.BUTTON_DELETE;

            this.DataContext = new EventModelView(monEvt, controler, parent);
        }
 public override async Task<IEnumerable<PushedEvent>> PushAsync(ICalendar calendar)
 {
     Log.Info(String.Format("Pushing calendar to google [{0}]", calendar.Id));
     if (LastCalendar != null)
     {
         var eventsToRemove = LastCalendar.Events.Where(e => !calendar.Events.Any(elc => elc.Id == e.Id));
         RemoveEvents(eventsToRemove);
     }
     LastCalendar = calendar;
     var res = await PushEvents(calendar.Events);
     return res;
 }
Exemplo n.º 15
0
 protected TriggerDetailDto(ITrigger trigger, ICalendar calendar)
 {
     Description = trigger.Description;
     TriggerType = trigger.GetType().AssemblyQualifiedNameWithoutVersion();
     Name = trigger.Key.Name;
     Group = trigger.Key.Group;
     CalendarName = trigger.CalendarName;
     Priority = trigger.Priority;
     StartTimeUtc = trigger.StartTimeUtc;
     EndTimeUtc = trigger.EndTimeUtc;
     NextFireTimes = TriggerUtils.ComputeFireTimes((IOperableTrigger) trigger, calendar, 10);
 }
 public CalendarSynchronizationWorker(
     ICalendar sourceCalendar, 
     ICalendar destinationCalendar,
     ISynchronizationConfiguration synchronizationConfiguration,
     AutoResetEvent saveSynchronizationConfigurationsEvent,
     ICalendarEventSynchronizer calendarEventSynchronizer)
 {
     _sourceCalendar = sourceCalendar;
     _destinationCalendar = destinationCalendar;
     _synchronizationConfiguration = synchronizationConfiguration;
     _saveSynchronizationConfigurationsEvent = saveSynchronizationConfigurationsEvent;
     _calendarEventSynchronizer = calendarEventSynchronizer;
 }
 public static PublicItemCollection GetForCalendar(ICalendar calendar)
 {
     var sharingOptions = new PublicItemCollection();
     sharingOptions.Items.Add(new PublicItemWrapper(new ASC.Web.Core.Calendars.SharingOptions.PublicItem()
            {
                Id = calendar.OwnerId,
                IsGroup = false
            },
           calendar.Id.ToString(), calendar.OwnerId));
     foreach (var item in calendar.SharingOptions.PublicItems)            
         sharingOptions.Items.Add(new PublicItemWrapper(item, calendar.Id.ToString(), calendar.OwnerId));
     
     return sharingOptions;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TriggerFiredBundle"/> class.
 /// </summary>
 /// <param name="job">The job.</param>
 /// <param name="trigger">The trigger.</param>
 /// <param name="cal">The calendar.</param>
 /// <param name="jobIsRecovering">if set to <c>true</c> [job is recovering].</param>
 /// <param name="fireTimeUtc">The fire time.</param>
 /// <param name="scheduledFireTimeUtc">The scheduled fire time.</param>
 /// <param name="prevFireTimeUtc">The previous fire time.</param>
 /// <param name="nextFireTimeUtc">The next fire time.</param>
 public TriggerFiredBundle(IJobDetail job, IOperableTrigger trigger, ICalendar cal, bool jobIsRecovering,
     DateTimeOffset? fireTimeUtc,
     DateTimeOffset? scheduledFireTimeUtc,
     DateTimeOffset? prevFireTimeUtc,
     DateTimeOffset? nextFireTimeUtc)
 {
     this.job = job;
     this.trigger = trigger;
     this.cal = cal;
     this.jobIsRecovering = jobIsRecovering;
     this.fireTimeUtc = fireTimeUtc;
     this.scheduledFireTimeUtc = scheduledFireTimeUtc;
     this.prevFireTimeUtc = prevFireTimeUtc;
     this.nextFireTimeUtc = nextFireTimeUtc;
 }
Exemplo n.º 19
0
 static void Initialize(ICalendar calendar, IXpandJobTrigger trigger) {
     if (calendar is AnnualCalendar) {
         InitializeAnnual(calendar as AnnualCalendar, trigger.Calendar as IAnnualCalendar);
     } else if (calendar is HolidayCalendar) {
         InitializeHoliday(calendar as HolidayCalendar, trigger.Calendar as IHolidayCalendar);
     } else if (calendar is WeeklyCalendar) {
         InitializeWeekly(calendar as WeeklyCalendar, trigger.Calendar as IWeeklyCalendar);
     } else if (calendar is MonthlyCalendar) {
         InitializeMonthly(calendar as MonthlyCalendar, trigger.Calendar as IMonthlyCalendar);
     } else if (calendar is DailyCalendar) {
         InitializeDaily(calendar as DailyCalendar, trigger.Calendar as IDailyCalendar);
     } else if (calendar is CronCalendar) {
         InitializeCron(calendar as CronCalendar, trigger.Calendar as ICronCalendar);
     }
 }
Exemplo n.º 20
0
		public static ICalendar GetCalendar (CalendarType type)
		{
			// Initialize the calendars here

			if (Gregorian == null)
				Gregorian = new GregorianCalendar ();

			// List the calendars here

			switch (type) {
			case CalendarType.Gregorian:
				return Gregorian;
			default:
				return null;
			}
		}
Exemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of UptimeManagement
        /// </summary>
        public UptimeManagement(IDeviceConfiguration device, ICalendarFactory calendarFactory)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (calendarFactory == null)
            {
                throw new ArgumentNullException(nameof(calendarFactory));
            }

            this.m_Device = device;
            this.m_Calendar = calendarFactory.GetCalendar(m_Device.UptimeCalendarType.ToCalendarCalendarType(),
                m_Device.CalendarProviderSettingsDirectory,
                m_Device.UptimeCalendarName);
        }
Exemplo n.º 22
0
        public static DbCalendar CreateFromICalendar(ICalendar calendar)
        {
            DbCalendar dbCalendar = new DbCalendar();

            byte[] serializedCalendar = null;
            if (calendar != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(ms, calendar);
                    serializedCalendar = ms.ToArray();
                }
            }

            dbCalendar.Calendar = serializedCalendar;

            return dbCalendar;
        }
Exemplo n.º 23
0
        public static CalendarDetailDto Create(ICalendar calendar)
        {
            var annualCalendar = calendar as AnnualCalendar;
            if (annualCalendar != null)
            {
                return new AnnualCalendarDto(annualCalendar);
            }

            var cronCalendar = calendar as CronCalendar;
            if (cronCalendar != null)
            {
                return new CronCalendarDto(cronCalendar);
            }

            var dailyCalendar = calendar as DailyCalendar;
            if (dailyCalendar != null)
            {
                return new DailyCalendarDto(dailyCalendar);
            }

            var holidayCalendar = calendar as HolidayCalendar;
            if (holidayCalendar != null)
            {
                return new HolidayCalendarDto(holidayCalendar);
            }

            var monthlyCalendar = calendar as MonthlyCalendar;
            if (monthlyCalendar != null)
            {
                return new MonthlyCalendarDto(monthlyCalendar);
            }

            var weeklyCalendar = calendar as WeeklyCalendar;
            if (weeklyCalendar != null)
            {
                return new WeeklyCalendarDto(weeklyCalendar);
            }

            return new CalendarDetailDto(calendar);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Compute the <see cref="DateTimeOffset" /> that is 1 second after the Nth firing of 
        /// the given <see cref="ITrigger" />, taking the triger's associated 
        /// <see cref="ICalendar" /> into consideration.
        /// </summary>
        /// <remarks>
        /// The input trigger will be cloned before any work is done, so you need
        /// not worry about its state being altered by this method.
        /// </remarks>
        /// <param name="trigger">The trigger upon which to do the work</param>
        /// <param name="calendar">The calendar to apply to the trigger's schedule</param>
        /// <param name="numberOfTimes">The number of next fire times to produce</param>
        /// <returns>the computed Date, or null if the trigger (as configured) will not fire that many times</returns>
        public static DateTimeOffset? ComputeEndTimeToAllowParticularNumberOfFirings(IOperableTrigger trigger, ICalendar calendar, int numberOfTimes)
        {
            IOperableTrigger t = (IOperableTrigger) trigger.Clone();

            if (t.GetNextFireTimeUtc() == null)
            {
                t.ComputeFirstFireTimeUtc(calendar);
            }

            int c = 0;
            DateTimeOffset? endTime = null;

            for (int i = 0; i < numberOfTimes; i++)
            {
                DateTimeOffset? d = t.GetNextFireTimeUtc();
                if (d != null)
                {
                    c++;
                    t.Triggered(calendar);
                    if (c == numberOfTimes)
                    {
                        endTime = d;
                    }
                }
                else
                {
                    break;
                }
            }

            if (endTime == null)
            {
                return null;
            }

            endTime = endTime.Value.AddSeconds(1);

            return endTime;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="calendar"></param>
        /// <param name="misfireThreshold"></param>
        /// <see cref="AbstractTrigger.UpdateWithNewCalendar"/>
        public override void UpdateWithNewCalendar(ICalendar calendar, TimeSpan misfireThreshold)
        {
            nextFireTimeUtc = GetFireTimeAfter(previousFireTimeUtc);

            if (nextFireTimeUtc == null || calendar == null)
            {
                return;
            }

            DateTimeOffset now = SystemTime.UtcNow();

            while (nextFireTimeUtc != null && !calendar.IsTimeIncluded(nextFireTimeUtc.Value))
            {
                nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);

                if (nextFireTimeUtc == null)
                {
                    break;
                }

                //avoid infinite loop
                if (nextFireTimeUtc.Value.Year > YearToGiveupSchedulingAt)
                {
                    nextFireTimeUtc = null;
                }

                if (nextFireTimeUtc != null && nextFireTimeUtc < now)
                {
                    TimeSpan diff = now - nextFireTimeUtc.Value;
                    if (diff >= misfireThreshold)
                    {
                        nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);
                    }
                }
            }
        }
        /// <summary>
        /// This method should not be used by the Quartz client.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Called by the scheduler at the time a <see cref="ITrigger" /> is first
        /// added to the scheduler, in order to have the <see cref="ITrigger" />
        /// compute its first fire time, based on any associated calendar.
        /// </para>
        ///
        /// <para>
        /// After this method has been called, <see cref="ITrigger.GetNextFireTimeUtc" />
        /// should return a valid answer.
        /// </para>
        /// </remarks>
        /// <returns>
        /// The first time at which the <see cref="ITrigger" /> will be fired
        /// by the scheduler, which is also the same value <see cref="ITrigger.GetNextFireTimeUtc" />
        /// will return (until after the first firing of the <see cref="ITrigger" />).
        /// </returns>
        public override DateTimeOffset?ComputeFirstFireTimeUtc(ICalendar calendar)
        {
            nextFireTimeUtc = GetFireTimeAfter(StartTimeUtc.AddSeconds(-1));

            // Check calendar for date-time exclusion
            while (nextFireTimeUtc != null && calendar != null &&
                   !calendar.IsTimeIncluded(nextFireTimeUtc.Value))
            {
                nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);

                if (nextFireTimeUtc == null)
                {
                    break;
                }

                //avoid infinite loop
                if (nextFireTimeUtc.Value.Year > YearToGiveupSchedulingAt)
                {
                    return(null);
                }
            }

            return(nextFireTimeUtc);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Generate calendar days by calendar week template.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="dateTime">The date time.</param>
        /// <param name="weeksCount">Number of weeks to generate.</param>
        /// <returns>
        /// Calendar days.
        /// </returns>
        /// <exception cref="Exception">Unable to find day of week in week template</exception>
        public static IEnumerable <ICalendarDay> GenerateWeeks(this ICalendar <ICalendarDay> calendar, DateTime dateTime,
                                                               int weeksCount)
        {
            int daysOffInPeriod = 0;
            var days            = new List <ICalendarDay>();
            int dayCount        = calendar.WeekTemplate.Count;

            for (var i = 0; i < weeksCount + Math.Ceiling((decimal)daysOffInPeriod / 7); i++)
            {
                for (var j = 0; j < dayCount; j++)
                {
                    ICalendarDay day;
                    DateTime     calendarDate = dateTime.AddDays(j + dayCount * i);
                    ICalendarDay dayOff       = calendar.DayOffs
                                                .FirstOrDefault(d => d.CalendarDateTime.Date == calendarDate.Date);
                    if (dayOff != null)
                    {
                        day = (ICalendarDay)dayOff.Clone();
                        daysOffInPeriod++;
                    }
                    else
                    {
                        var dayOfWeek = calendar.WeekTemplate
                                        .FirstOrDefault(d => d.DayOfWeek == calendarDate.DayOfWeek);
                        if (dayOfWeek == default(ICalendarDay))
                        {
                            throw new Exception("Unable to find day of week in week template");
                        }
                        day = (ICalendarDay)dayOfWeek.Clone();
                        day.CalendarDateTime = calendarDate;
                    }
                    days.Add(day);
                }
            }
            return(days);
        }
Exemplo n.º 28
0
 public DrLarryFine(ICalendar calendar) : base(.05, calendar, MyProfile, "34.199.18.202", "10.10.5.2")
 {
 }
 public BankAccountController(IConsolWrapper consolWrapper, ICalendar calendarWrapper, IBankAccount bankAccount)
 {
     _consolWrapper   = consolWrapper;
     _calendarWrapper = calendarWrapper;
     _bankAccount     = bankAccount;
 }
Exemplo n.º 30
0
 public WorkflowFacilitator(ICalendar calendar)
 {
     _calendar = calendar;
 }
Exemplo n.º 31
0
        /// <summary>
        /// Register jobs and triggers (within a transaction, if possible).
        /// </summary>
        protected virtual void RegisterJobsAndTriggers()
        {
            ITransactionStatus transactionStatus = null;

            if (transactionManager != null)
            {
                transactionStatus = transactionManager.GetTransaction(new DefaultTransactionDefinition());
            }
            try
            {
                if (jobSchedulingDataLocations != null)
                {
                    JobSchedulingDataProcessor dataProcessor = new JobSchedulingDataProcessor(true, true);
                    for (int i = 0; i < this.jobSchedulingDataLocations.Length; i++)
                    {
                        dataProcessor.ProcessFileAndScheduleJobs(
                            jobSchedulingDataLocations[i], GetScheduler(), overwriteExistingJobs);
                    }
                }

                // Register JobDetails.
                if (jobDetails != null)
                {
                    foreach (JobDetail jobDetail in jobDetails)
                    {
                        AddJobToScheduler(jobDetail);
                    }
                }
                else
                {
                    // Create empty list for easier checks when registering triggers.
                    jobDetails = new LinkedList();
                }

                // Register Calendars.
                if (calendars != null)
                {
                    foreach (DictionaryEntry entry in calendars)
                    {
                        string    calendarName = (string)entry.Key;
                        ICalendar calendar     = (ICalendar)entry.Value;
                        GetScheduler().AddCalendar(calendarName, calendar, true, true);
                    }
                }

                // Register Triggers.
                if (triggers != null)
                {
                    foreach (Trigger trigger in triggers)
                    {
                        AddTriggerToScheduler(trigger);
                    }
                }
            }

            catch (Exception ex)
            {
                if (transactionStatus != null)
                {
                    try
                    {
                        transactionManager.Rollback(transactionStatus);
                    }
                    catch (TransactionException)
                    {
                        logger.Error("Job registration exception overridden by rollback exception", ex);
                        throw;
                    }
                }
                if (ex is SchedulerException)
                {
                    throw;
                }
                throw new SchedulerException("Registration of jobs and triggers failed: " + ex.Message);
            }

            if (transactionStatus != null)
            {
                transactionManager.Commit(transactionStatus);
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Serialization constructor.
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected BaseCalendar(SerializationInfo info, StreamingContext context)
        {
            string prefix = "";
            try
            {
                info.GetValue("description", typeof(string));
            }
            catch
            {
                // base class for other
                prefix = "BaseCalendar+";
            }

            baseCalendar = (ICalendar) info.GetValue(prefix + "baseCalendar", typeof(ICalendar));
            description = (string)info.GetValue(prefix + "description", typeof(string));
            timeZone = (TimeZoneInfo)info.GetValue(prefix + "timeZone", typeof(TimeZoneInfo));
        }
Exemplo n.º 33
0
        public InvoicesTransactionReportRecord
            (int id, int clientNumber, string clientName, int customerId, int customerNumber, string customerName,
            Date date, string invoice, string reference, decimal amount, Date processedDate, int batch, decimal?batchTotal, TransactionStatus transactionStatus, decimal balance, IDate receiptDate, ICalendar calendar)
            : base(id, clientNumber, clientName, customerId, customerNumber, customerName, date, invoice, reference, amount, processedDate, batch, batchTotal, transactionStatus, TransactionType.Invoice)
        {
            ArgumentChecker.ThrowIfNull(calendar, "calendar");

            this.balance     = balance;
            this.receiptDate = receiptDate;
            this.calendar    = calendar;
        }
Exemplo n.º 34
0
 public override DateTimeOffset?ComputeFirstFireTimeUtc(ICalendar cal)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseCalendar"/> class.
 /// </summary>
 /// <param name="baseCalendar">The base calendar.</param>
 public BaseCalendar(ICalendar baseCalendar)
 {
     CalendarBase = baseCalendar;
 }
Exemplo n.º 36
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="baseCalendar">The base calendar.</param>
 public MonthlyCalendar(ICalendar baseCalendar) : base(baseCalendar)
 {
     Init();
 }
Exemplo n.º 37
0
 public override void Triggered(ICalendar cal)
 {
     throw new NotImplementedException();
 }
        public NotificationViewModel(IReqDB dbss, IDialogService dialog, ICalendar calendar, IToast toast, INetwork net)
        {
            dbs           = dbss;
            this.dialog   = dialog;
            this.calendar = calendar;

            ReloadCommand.Execute(null);
            SelectMessage = new MvxCommand <Req>(async selectedItem =>
            {
                string ifloc = "Not Needed";
                string ifcal = "Not Needed";

                if (selectedItem.ReqLoc == true)
                {
                    ifloc = "Needed";
                }

                if (selectedItem.ReqCal == true)
                {
                    ifcal = "Needed";
                }

                string mes = selectedItem.ReqFrom + "\n" + "Calendar: " + ifcal + "\n" + "Location: " + ifloc + "\n" + "Other Info:" + selectedItem.ReqExtra;

                List <string> Answer = await dialog.Show(mes, "Status Request", "Send", "Dismiss");
                if (Answer[0] == "true")
                {
                    Message.Remove(selectedItem);
                    await DeleteReq(selectedItem.Id);
                    toast.Show("Status Response Sent");
                    string calend = ""; // Calander Events for Today
                    string wifi   = ""; // Wifi Access point of person

                    // Don't send location or Calendar
                    if ((MyGlobals.SelPer.PLocCheck == false || ifloc == "Not Needed") && (MyGlobals.SelPer.PCalCheck == false || ifcal == "Not Needed"))
                    {
                        calend = "";
                        wifi   = "";
                    }
                    // Don't send Calendar
                    else if (MyGlobals.SelPer.PCalCheck == false || ifcal == "Not Needed")
                    {
                        calend = "";
                        wifi   = net.SSID();
                    }
                    // Don't send Location
                    else if (MyGlobals.SelPer.PLocCheck == false || ifloc == "Not Needed")
                    {
                        calend = calendar.returnEvents();
                        wifi   = "";
                    }
                    // Send both.
                    else
                    {
                        calend = calendar.returnEvents();
                        wifi   = net.SSID();
                    }


                    MyGlobals.answer = new Answ
                    {
                        AnsFrom  = selectedItem.ReqTo,
                        AnsTo    = selectedItem.ReqFrom,
                        AnsLoc   = wifi,
                        AnsCal   = calend,
                        AnsExtra = Answer[1]
                    };
                    ShowViewModel <RedirectViewModel>();
                }

                else if (Answer[0] == "false")
                {
                    Message.Remove(selectedItem);
                    await DeleteReq(selectedItem.Id);
                    toast.Show("Status Request Deleted");
                }
            });
        }
Exemplo n.º 39
0
        protected async Task <List <EventModel> > GetEventsByTime(List <DateTime> startDateList, List <DateTime> startTimeList, List <DateTime> endDateList, List <DateTime> endTimeList, TimeZoneInfo userTimeZone, ICalendar calendarService)
        {
            // todo: check input datetime is utc
            var rawEvents    = new List <EventModel>();
            var resultEvents = new List <EventModel>();

            DateTime?startDate = null;

            if (startDateList.Any())
            {
                startDate = startDateList.Last();
            }

            DateTime?endDate = null;

            if (endDateList.Any())
            {
                endDate = endDateList.Last();
            }

            bool searchByStartTime = startTimeList.Any() && endDate == null && !endTimeList.Any();

            startDate = startDate ?? TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);
            endDate   = endDate ?? startDate ?? TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone);

            var searchStartTimeList = new List <DateTime>();
            var searchEndTimeList   = new List <DateTime>();

            if (startTimeList.Any())
            {
                foreach (var time in startTimeList)
                {
                    searchStartTimeList.Add(TimeZoneInfo.ConvertTimeToUtc(
                                                new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day, time.Hour, time.Minute, time.Second),
                                                userTimeZone));
                }
            }
            else
            {
                searchStartTimeList.Add(TimeZoneInfo.ConvertTimeToUtc(
                                            new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day), userTimeZone));
            }

            if (endTimeList.Any())
            {
                foreach (var time in endTimeList)
                {
                    searchEndTimeList.Add(TimeZoneInfo.ConvertTimeToUtc(
                                              new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, time.Hour, time.Minute, time.Second),
                                              userTimeZone));
                }
            }
            else
            {
                searchEndTimeList.Add(TimeZoneInfo.ConvertTimeToUtc(
                                          new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, 23, 59, 59), userTimeZone));
            }

            DateTime?searchStartTime = null;

            if (searchByStartTime)
            {
                foreach (var startTime in searchStartTimeList)
                {
                    rawEvents = await calendarService.GetEventsByStartTime(startTime);

                    if (rawEvents.Any())
                    {
                        searchStartTime = startTime;
                        break;
                    }
                }
            }
            else
            {
                for (var i = 0; i < searchStartTimeList.Count(); i++)
                {
                    rawEvents = await calendarService.GetEventsByTime(
                        searchStartTimeList[i],
                        searchEndTimeList.Count() > i?searchEndTimeList[i] : searchEndTimeList[0]);

                    if (rawEvents.Any())
                    {
                        searchStartTime = searchStartTimeList[i];
                        break;
                    }
                }
            }

            foreach (var item in rawEvents)
            {
                if (item.StartTime >= searchStartTime && item.IsCancelled != true)
                {
                    resultEvents.Add(item);
                }
            }

            return(resultEvents);
        }
Exemplo n.º 40
0
 public ICalendar InitCalendarService(ICalendar calendarAPI, EventSource source)
 {
     return(new MockCalendarService());
 }
        /// <summary> 
        /// This method should not be used by the Quartz client.
        /// <para>
        /// The implementation should update the <see cref="ITrigger" />'s state
        /// based on the given new version of the associated <see cref="ICalendar" />
        /// (the state should be updated so that it's next fire time is appropriate
        /// given the Calendar's new settings). 
        /// </para>
        /// </summary>
        /// <param name="calendar"> </param>
        /// <param name="misfireThreshold"></param>
        public override void UpdateWithNewCalendar(ICalendar calendar, TimeSpan misfireThreshold)
        {
            nextFireTimeUtc = GetFireTimeAfter(previousFireTimeUtc);

            if (nextFireTimeUtc == null || calendar == null)
            {
                return;
            }

            DateTimeOffset now = SystemTime.UtcNow();
            while (nextFireTimeUtc != null && !calendar.IsTimeIncluded(nextFireTimeUtc.Value))
            {
                nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);

                if (nextFireTimeUtc == null)
                {
                    break;
                }

                //avoid infinite loop
                if (nextFireTimeUtc.Value.Year > YearToGiveupSchedulingAt)
                {
                    nextFireTimeUtc = null;
                }

                if (nextFireTimeUtc != null && nextFireTimeUtc < now)
                {
                    TimeSpan diff = now - nextFireTimeUtc.Value;
                    if (diff >= misfireThreshold)
                    {
                        nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);
                    }
                }
            }
        }
Exemplo n.º 42
0
 public override void UpdateAfterMisfire(ICalendar cal)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 43
0
        /// <summary>
        /// Store the given <see cref="ICalendar" />.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="calendar">The <see cref="ICalendar" /> to be stored.</param>
        /// <param name="replaceExisting">If <see langword="true" />, any <see cref="ICalendar" /> existing
        /// in the <see cref="IJobStore" /> with the same name and group
        /// should be over-written.</param>
        /// <param name="updateTriggers">If <see langword="true" />, any <see cref="ITrigger" />s existing
        /// in the <see cref="IJobStore" /> that reference an existing
        /// Calendar with the same name with have their next fire time
        /// re-computed with the new <see cref="ICalendar" />.</param>
        public virtual void StoreCalendar(string name, ICalendar calendar, bool replaceExisting,
            bool updateTriggers)
        {
            CalendarWrapper calendarWrapper = new CalendarWrapper()
                {
                    Name = name,
                    Calendar = calendar
                };

            lock (lockObject)
            {
                if (this.Calendars.FindOneByIdAs<BsonDocument>(name) != null
                    && replaceExisting == false)
                {
                    throw new ObjectAlreadyExistsException(string.Format(CultureInfo.InvariantCulture, "Calendar with name '{0}' already exists.", name));
                }

                this.Calendars.Save(calendarWrapper);

                if (updateTriggers)
                {
                    var triggers = this.Triggers.FindAs<IOperableTrigger>(Query.EQ("CalendarName", name));
                    foreach (IOperableTrigger trigger in triggers)
                    {
                        trigger.UpdateWithNewCalendar(calendar, MisfireThreshold);
                        this.Triggers.Save(trigger);
                    }
                }
            }
        }
Exemplo n.º 44
0
 public override void UpdateWithNewCalendar(ICalendar cal, TimeSpan misfireThreshold)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseCalendar"/> class.
 /// </summary>
 /// <param name="baseCalendar">The base calendar.</param>
 /// <param name="timeZone">The time zone.</param>
 public BaseCalendar(ICalendar baseCalendar, TimeZoneInfo timeZone)
 {
     this.baseCalendar = baseCalendar;
     this.timeZone = timeZone;
 }
Exemplo n.º 46
0
        public static Tuple <Date, double>[] Calibrate(
            string name,
            Date referenceDate,
            IMarketInstrument[] marketInstruments,
            BusinessDayConvention bda,
            IDayCount daycount,
            ICalendar calendar,
            Compound compound,
            Interpolation interpolation,
            YieldCurveTrait trait,
            CurrencyCode currency,
            Date[] knotPoints,
            out double fittingError,
            IMarketCondition baseMarket = null,
            Expression <Func <IMarketCondition, object> >[] expression = null,
            double initialValue = double.NaN,
            double initialGuess = 0.05,
            double xmin         = -3,
            double xmax         = 3.0
            )
        {
            var accuracy = 1.0e-13;

            if (marketInstruments.Any(x => !(x.Instrument is Bond)))
            {
                throw new PricingLibraryException("All instruments must be bond to build a bond curve!");
            }

            var keyTs = knotPoints.Select(x => daycount.CalcDayCountFraction(referenceDate, x)).ToArray();
            var len   = keyTs.Length;

            baseMarket =
                baseMarket
                ??
                new MarketCondition(
                    x => x.ValuationDate.Value        = referenceDate,
                    x => x.DiscountCurve.Value        = null,
                    x => x.FixingCurve.Value          = null,
                    x => x.HistoricalIndexRates.Value = new Dictionary <IndexType, SortedDictionary <Date, double> >()
                    );

            var bondYieldPricer = new BondYieldPricer();
            var bonds           = marketInstruments.Select(x => x.Instrument as Bond);
            var bondCf          = bonds.Select(x => x.GetCashflows(baseMarket, true)).ToList();
            var bondPrices      =
                bonds.Select(
                    (x, i) =>
                    bondYieldPricer.FullPriceFromYield(bondCf[i], x.PaymentDayCount, x.PaymentFreq, x.StartDate, referenceDate,
                                                       marketInstruments[i].TargetValue, x.BondTradeingMarket, x.IrregularPayment)).ToArray();

            var rand = new Random();
            // variables : alpha, b1, b2, b3, b4, b5 ...
            var    numVars     = 1 + 2 + len;
            var    lowerBounds = new double[numVars];
            var    upperBounds = new double[numVars];
            var    initials    = new double[numVars];
            double?finalScore  = double.NaN;

            for (var i = 0; i < numVars; ++i)
            {
                lowerBounds[i] = i == 0 ? 0.0 : xmin;
                upperBounds[i] = i == 0 ? 1.0 : xmax;
                initials[i]    = rand.NextDouble() > 0 ? rand.NextDouble() : -rand.NextDouble();
            }

            var globalSolver = new NLoptSolver(NLoptAlgorithm.GN_DIRECT, (ushort)numVars, accuracy, 100000, NLoptAlgorithm.LN_COBYLA);

            globalSolver.SetLowerBounds(lowerBounds);
            globalSolver.SetUpperBounds(upperBounds);
            globalSolver.SetMinObjective((variables, gradients) =>
            {
                var error =
                    bondCf.Select((cfs, i) => GetModelPrice(referenceDate, cfs, daycount, variables, keyTs) - bondPrices[i]).ToArray();
                return(error.Sum(x => x * x));
            });
            double?globalFinalScore;
            var    globalResult = globalSolver.Optimize(initials, out globalFinalScore);

            var localSolvers = new[] { NLoptAlgorithm.LN_BOBYQA, NLoptAlgorithm.LD_AUGLAG, NLoptAlgorithm.LN_COBYLA };

            for (var k = 0; k < 3; ++k)
            {
                var localSolver = new NLoptSolver(localSolvers[k], (ushort)numVars, accuracy, 100000, NLoptAlgorithm.LN_COBYLA);
                localSolver.SetLowerBounds(lowerBounds);
                localSolver.SetUpperBounds(upperBounds);
                localSolver.SetMinObjective((variables, gradients) =>
                {
                    var error = bondCf.Select((cfs, i) => GetModelPrice(referenceDate, cfs, daycount, variables, keyTs) - bondPrices[i]).ToArray();
                    return(error.Sum(x => x * x));
                });

                var result = localSolver.Optimize(initials, out finalScore);
            }
            fittingError = finalScore.Value;

            var coeffes = new[]
            {
                Tuple.Create(referenceDate, initials[0]),
                Tuple.Create(referenceDate, -1.0 - initials[1] - initials[2] - initials.Skip(3).Sum() * 1 / 3.0),
                Tuple.Create(referenceDate, initials[1]),
                Tuple.Create(referenceDate, initials[2]),
            }
            .Union(knotPoints.Select((x, i) => Tuple.Create(x, initials[i + 3])))
            .ToArray();

            //var errors = bondCf.Select((cfs, i) => GetModelPrice(referenceDate, cfs, daycount, initials, keyTs)).ToArray();

            //for (var i = 0; i < errors.Length; ++i)
            //{

            //	Console.WriteLine("{0},{1},{2}", errors[i], bondPrices[i], errors[i] - bondPrices[i]);
            //}

            return(coeffes);            // Insert 0D point to avoid interpolation jump at the beginning
        }
Exemplo n.º 47
0
 /// <summary>
 /// Add (register) the given <see cref="ICalendar" /> to the Scheduler.
 /// </summary>
 public virtual void AddCalendar(string calName, ICalendar calendar, bool replace,
                                 bool updateTriggers)
 {
     ValidateState();
     resources.JobStore.StoreCalendar(calName, calendar, replace, updateTriggers);
 }
Exemplo n.º 48
0
 /// <summary>
 /// Called when the <see cref="IScheduler" /> has decided to 'fire' the trigger
 /// (Execute the associated <see cref="IJob" />), in order to give the
 /// <see cref="ITrigger" /> a chance to update itself for its next triggering
 /// (if any).
 /// </summary>
 public override void Triggered(ICalendar cal)
 {
     calendar            = cal;
     previousFireTimeUtc = nextFireTimeUtc;
     nextFireTimeUtc     = GetFireTimeAfter(nextFireTimeUtc);
 }