Ejemplo n.º 1
0
        protected override void _activate(MacroTriggerWithArguments triggerWithArguments)
        {
            object[] argumentObjects = triggerWithArguments.ArgumentObjects;
            Timer    timer           = argumentObjects[0] as Timer;

            if (timer == null)
            {
                return;
            }
            int timeValue = (int)argumentObjects[1];

            if (timeValue < 0)
            {
                return;
            }
            PropertyChangedTwoValuesDelegate <Timer, int> timerSecondsChangedHandler = (i, ov, nv) => {
                if (nv == timeValue)
                {
                    triggerWithArguments.Fire();
                }
            };

            timer.SecondsChanged += timerSecondsChangedHandler;
            ActivationData activationData = new ActivationData(timer, timerSecondsChangedHandler);

            triggerWithArguments.Activated(activationData);
        }
Ejemplo n.º 2
0
        public static bool setProperty <TItem, TProperty>
            (this TItem item, ref TProperty member, TProperty newValue,
            PropertyChangedTwoValuesDelegate <TItem, TProperty> propertyChangedDelegate,
            BeforeChangePropertyDelegate <TProperty> beforeChangePropertyDelegate = null,
            AfterChangePropertyDelegate <TProperty> afterChangePropertyDelegate   = null,
            PropertyValidatorDelegate <TProperty> validator = null,
            [CallerMemberName] string propertyName          = "")
            where TItem : INotifyPropertyChanged
        {
            validator?.Invoke(newValue);
            if (Equals(member, newValue))
            {
                return(false);
            }
            TProperty oldValue = member;

            beforeChangePropertyDelegate?.Invoke(oldValue, newValue);
            member = newValue;
            afterChangePropertyDelegate?.Invoke(oldValue, newValue);
            propertyChangedDelegate?.Invoke(item, oldValue, newValue);
            item.RaisePropertyChanged(propertyName);
            return(true);
        }
Ejemplo n.º 3
0
 public ActivationData(Timer timer, PropertyChangedTwoValuesDelegate <Timer, int> timerSecondsChangedHandler)
 {
     Timer = timer;
     TimerSecondsChangedHandler = timerSecondsChangedHandler;
 }
Ejemplo n.º 4
0
        private void baseColumnCreator(CustomDataGridView <ExternalSignal> table, ItemListFormBaseManager <ExternalSignal> .ColumnDescriptorBuilderGetterDelegate builderGetterMethod)
        {
            CustomDataGridViewColumnDescriptorBuilder <ExternalSignal> builder;

            // Column: ID, name
            idColumnCreator(table, builderGetterMethod);
            nameColumnCreator(table, builderGetterMethod);

            // Column: category
            builder = builderGetterMethod();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Category");
            builder.Width(150);
            builder.DividerWidth(DEFAULT_DIVIDER_WIDTH);
            builder.UpdaterMethod((signal, cell) => {
                cell.Value           = (signal.Category != null) ? string.Format("(#{0}) {1}", signal.Category.ID, signal.Category.Name) : "(not associated)";
                cell.Style.BackColor = (signal.Category != null) ? signal.Category.Color : table.DefaultCellStyle.BackColor;
            });
            builder.ExternalUpdateEventSubscriberMethod((signal, updateInvoker) =>
            {
                PropertyChangedTwoValuesDelegate <IModel, int> signalCategoryIdChangedHandler      = (_category, oldCategory, newCategory) => updateInvoker();
                PropertyChangedTwoValuesDelegate <IModel, string> signalCategoryNameChangedHandler = (_category, oldName, newName) => updateInvoker();
                PropertyChangedTwoValuesDelegate <ExternalSignalCategory, Color> signalCategoryColorChangedHandler = (_category, oldColor, newColor) => updateInvoker();
                if (signal.Category != null)
                {
                    signal.Category.IdChanged    += signalCategoryIdChangedHandler;
                    signal.Category.NameChanged  += signalCategoryNameChangedHandler;
                    signal.Category.ColorChanged += signalCategoryColorChangedHandler;
                }
                signal.CategoryChanged += (_signal, oldCategory, newCategory) => {
                    if (oldCategory != null)
                    {
                        oldCategory.IdChanged    -= signalCategoryIdChangedHandler;
                        oldCategory.NameChanged  -= signalCategoryNameChangedHandler;
                        oldCategory.ColorChanged -= signalCategoryColorChangedHandler;
                    }
                    if (newCategory != null)
                    {
                        newCategory.IdChanged    += signalCategoryIdChangedHandler;
                        newCategory.NameChanged  += signalCategoryNameChangedHandler;
                        newCategory.ColorChanged += signalCategoryColorChangedHandler;
                    }
                };
            });
            builder.AddChangeEvent(nameof(ExternalSignal.Category));

            // Column: red tally
            builder = builderGetterMethod();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("T(R)");
            builder.Width(50);
            builder.UpdaterMethod((signal, cell) => { cell.Style.BackColor = (signal.RedTally.State ? Color.Red : Color.LightGray); });
            builder.AddMultilevelChangeEvent(nameof(ExternalSignal.RedTally), nameof(IBidirectionalSignalTally.State));

            // Column: yellow tally
            builder = builderGetterMethod();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("T(Y)");
            builder.Width(50);
            builder.UpdaterMethod((signal, cell) => { cell.Style.BackColor = (signal.YellowTally.State ? Color.Gold : Color.LightGray); });
            builder.AddMultilevelChangeEvent(nameof(ExternalSignal.YellowTally), nameof(IBidirectionalSignalTally.State));

            // Column: green tally
            builder = builderGetterMethod();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("T(G)");
            builder.Width(50);
            builder.DividerWidth(DEFAULT_DIVIDER_WIDTH);
            builder.UpdaterMethod((signal, cell) => { cell.Style.BackColor = (signal.GreenTally.State ? Color.ForestGreen : Color.LightGray); });
            builder.AddMultilevelChangeEvent(nameof(ExternalSignal.GreenTally), nameof(IBidirectionalSignalTally.State));

            // Column: edit, delete
            editButtonColumnCreator(table, builderGetterMethod);
            deleteButtonColumnCreator(table, builderGetterMethod);
        }