Example #1
0
        public SelectManyInputNode(string name, string varName, List <T> options,
                                   IMetaMessage <MetaInlineKeyboardMarkup> metaMessage = null,
                                   string checkedSymbol = defaultChecked, string uncheckedSymbol = defaultUnchecked, Func <T, string> btnCallbackFunc = null,
                                   byte pageSize        = 6, FlipperArrowsType flipperArrows     = FlipperArrowsType.Double, bool needBack = true, bool useGlobalCallbacks = false)
            : base(name, options,
                   (session, element) => (session.Vars.GetVar <List <T> >(varName)?.Contains(element) ?? false ? // если элемент есть,
                                          checkedSymbol : uncheckedSymbol) + element.ToString(session),          // то добавляем checkedSymbol, иначе uncheckedSymbol
                   btnCallbackFunc, metaMessage ?? new MetaDoubleKeyboardedMessage(name),
                   pageSize, needBack, flipperArrows, useGlobalCallbacks)
        {
            VarName  = varName ?? throw new ArgumentNullException(nameof(varName));
            Children = new List <ITreeNode>(1);
            if (collection.Count == 0)
            {
                throw new ArgumentException(nameof(options));
            }

            Dictionary <string, T> callbackToValue = new Dictionary <string, T>(collection.Count);

            foreach (T element in collection)
            {
                callbackToValue.Add(callbackFunc(element), element);
            }

            Converter = (string text, out T variable) => callbackToValue.TryGetValue(text, out variable);
        }
 public CollectionNode(string name, byte pageSize, IMetaMessage metaMessage, List <T> elements = null, bool needBack = false)
     : base(name, metaMessage, needBack)
 {
     this.pageSize      = pageSize;
     NeedNextButton     = true;
     NeedPreviousButton = true;
     collection         = elements ?? new List <T>();
 }
Example #3
0
 public FlipperNode(string name, List <T> elements, Func <ISession, T, string> btnNameFunc = null, Func <T, string> btnCallbackFunc = null,
                    IMetaMessage <MetaInlineKeyboardMarkup> metaMessage = null, byte pageSize           = 6, bool needBack = true,
                    FlipperArrowsType flipperArrows = FlipperArrowsType.Double, bool useGlobalCallbacks = true)
     : base(name, pageSize, metaMessage ?? new MetaDoubleKeyboardedMessage(name), elements, needBack)
 {
     nameFunc        = btnNameFunc ?? ((session, element) => element.ToString(session));
     callbackFunc    = btnCallbackFunc ?? ((element) => element.ToString());
     arrowsType      = flipperArrows;
     GlobalCallbacks = useGlobalCallbacks;
 }
Example #4
0
 public ChildrenFlipperNode(string name, IMetaMessage <MetaInlineKeyboardMarkup> metaMessage = null, byte pageSize = 6,
                            bool needBack = true, FlipperArrowsType flipperArrows = FlipperArrowsType.Double, bool useGlobalCallbacks = true)
     : base(name, null,
            (session, child) => session.Translate(child.Name),
            (child) => ButtonIdManager.GetInlineButtonId(child),
            metaMessage ?? new MetaDoubleKeyboardedMessage(name),
            pageSize, needBack, flipperArrows, useGlobalCallbacks)
 {
     Children = collection;
 }
 public UsualInputNode(string name, string varName, TryConvert <T> converter,
                       IMetaMessage metaMessage = null, bool required = true, bool needBack = true, bool useCallbacks = false)
     : base(name, metaMessage, needBack)
 {
     VarName  = varName ?? throw new ArgumentNullException(nameof(varName));
     Children = new List <ITreeNode>(1);
     Required = required;
     //Memoization = needSave;
     Converter      = converter ?? throw new ArgumentNullException(nameof(converter));
     usingCallbacks = useCallbacks;
 }
Example #6
0
 public BlockNode(string name, IMetaMessage metaMessage = null, byte pageSize = 2,
                  bool needBack = true, bool needPrevious = false) : base(name, pageSize, metaMessage, null, needBack)
 {
     Children = collection;
     message.AddNextButton();
     NeedPreviousButton = needPrevious;
     if (NeedPreviousButton)
     {
         message.InsertPreviousButton();
     }
 }
Example #7
0
 public Node(string name, IMetaMessage metaMessage)
 {
     Id = nextID++; // получать из БД
     if (string.IsNullOrWhiteSpace(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     this.Name = name;
     Children  = new List <ITreeNode>();
     message   = metaMessage ?? new MetaMessage(name, ". ");
 }
Example #8
0
        /// <summary>
        /// Converts from the hexadecimal bytes of a meta event into a <see cref="TrackMetaEventInfo"/>.
        /// </summary>
        /// <param name="trackChunk">A <see cref="List"/> of hexadecimal bytes that represent the track chunk.</param>
        /// <param name="deltaTime">The time between the previous event and the current event.</param>
        /// <returns>A <see cref="TrackMetaEventInfo"/> containing <see cref="IMessage"/> information and the number of bytes the meta event was.</returns>
        private TrackMetaEventInfo ProcessMetaEvent(List <byte> trackChunk, int deltaTime)
        {
            int eventSize = trackChunk[2];

            byte[] data = trackChunk.GetRange(3, eventSize).ToArray();

            MetaMessage message = new MetaMessage
            {
                MetaType = trackChunk[1],
                Data     = data
            };

            IMetaMessage metaMessage = MessageUtility.ToIMetaMessage(message, deltaTime);

            return(new TrackMetaEventInfo
            {
                eventSize = eventSize,
                trackOrMetaEvent = metaMessage
            });
        }
        public SelectSingleInputNode(string name, string varName, List <T> options,
                                     IMetaMessage <MetaInlineKeyboardMarkup> metaMessage = null, byte pageSize        = 6,
                                     Func <ISession, T, string> btnNameFunc = null, Func <T, string> btnCallbackFunc  = null, bool required           = true,
                                     FlipperArrowsType flipperArrows        = FlipperArrowsType.Double, bool needBack = true, bool useGlobalCallbacks = false)
            : base(name, options, btnNameFunc, btnCallbackFunc, metaMessage ?? new MetaDoubleKeyboardedMessage(name),
                   pageSize, needBack, flipperArrows, useGlobalCallbacks)
        {
            VarName  = varName ?? throw new ArgumentNullException(nameof(varName));
            Children = new List <ITreeNode>(1);
            Required = required;
            if (collection.Count == 0)
            {
                throw new ArgumentException(nameof(options));
            }

            Dictionary <string, T> callbackToValue = new Dictionary <string, T>(collection.Count);

            foreach (T element in collection)
            {
                callbackToValue.Add(callbackFunc(element), element);
            }

            Converter = (string text, out T variable) => callbackToValue.TryGetValue(text, out variable);
        }
Example #10
0
 public TimeInputNode(string name, string varName,
                      IMetaMessage metaMessage = null, bool required = true, bool needBack = true, bool useCallbacks = false)
     : base(name, varName, new TryConvert <TimeSpan>((string text, out TimeSpan variable) =>
 public TextInputNode(string name, string varName, TryConvert <string> converter,
                      IMetaMessage metaMessage = null, bool required = true, bool needBack = true, bool useCallbacks = false)
     : base(name, varName, converter, metaMessage, required, needBack, useCallbacks)
 {
 }
 public void Send(IMetaMessage message)
 {
     Send(message.Raw);
 }
Example #13
0
 public SimpleNode(string name, IMetaMessage metaMessage = null, bool needBack = true) : base(name, metaMessage, needBack)
 {
 }
Example #14
0
 public NormalNode(string name, IMetaMessage metaMessage, bool needBack) : base(name, metaMessage)
 {
     needBackButton = needBack;
 }
Example #15
0
        public MetaValuedContainerInputNode(string name, string varName, List <MetaValued <T> > options, IMetaMessage <MetaInlineKeyboardMarkup> metaMessage = null,
                                            Action <ISession, MetaValuedContainer <T> > endAction = null, Func <ISession, MetaValued <T>, string> btnNameFunc = null, Func <MetaValued <T>, string> btnCallbackFunc = null,
                                            byte pageSize = 6, FlipperArrowsType flipperArrows = FlipperArrowsType.Double, bool needBack = true, bool useGlobalCallbacks = false)
            : base(name, options, btnNameFunc, btnCallbackFunc ?? ((element) => DefaultStrings.DoNothing), metaMessage ?? new MetaDoubleKeyboardedMessage(name),
                   pageSize, needBack, flipperArrows, useGlobalCallbacks)
        {
            VarName  = varName ?? throw new ArgumentNullException(nameof(varName));
            Children = new List <ITreeNode>(1);
            if (collection.Count == 0)
            {
                throw new ArgumentException(nameof(options));
            }

            Dictionary <string, MetaValued <T> > callbackToValue = new Dictionary <string, MetaValued <T> >(collection.Count);

            foreach (MetaValued <T> element in collection)
            {
                callbackToValue.Add(element.ToString(), element);
            }

            Converter   = (string text, out MetaValued <T> variable) => callbackToValue.TryGetValue(text, out variable);
            finalisator = endAction;
        }