public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{\"keyboard\":[");
            for (int i = 0; i < _rows.Count; i++)
            {
                sb.Append("[");
                sb.Append(string.Join(",", _rows[i].Split(',').Select(s =>
                {
                    string key = string.Format("{0}_{1}", s, _id);
                    if (!_registeredValues.Contains(key))
                    {
                        _registeredValues.Add(key);
                    }
                    return(string.Format("\"{0}\"", key));
                })));
                sb.Append("]");
                if (i < _rows.Count - 1)
                {
                    sb.Append(",");
                }
            }
            sb.Append("],");
            sb.Append(string.Format("\"resize_keyboard\":{0},", Resize.ToString().ToLower()));
            sb.Append(string.Format("\"one_time_keyboard\":{0}", OneTime.ToString().ToLower()));
            sb.Append("}");
            return(HttpUtility.UrlEncode(sb.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Using a filter-supplied context type, block so that the one time code is only executed once regardless of how many
        /// threads are pushing through the pipe at the same time.
        /// </summary>
        /// <typeparam name="T">The payload type, should be an interface</typeparam>
        /// <param name="context">The pipe context</param>
        /// <param name="setupMethod">The setup method, called once regardless of the thread count</param>
        /// <param name="payloadFactory">The factory method for the payload context, optional if an interface is specified</param>
        /// <returns></returns>
        public static async Task OneTimeSetup <T>(this PipeContext context, Func <T, Task> setupMethod, PayloadFactory <T> payloadFactory = null)
            where T : class
        {
            OneTime <T> newContext      = null;
            var         existingContext = context.GetOrAddPayload <OneTimeSetupContext <T> >(() =>
            {
                var payload = payloadFactory?.Invoke() ?? TypeMetadataCache <T> .InitializeFromObject(new {});

                newContext = new OneTime <T>(payload);

                return(newContext);
            });

            if (newContext == existingContext)
            {
                try
                {
                    await setupMethod(newContext.Payload).ConfigureAwait(false);

                    newContext.SetReady();
                }
                catch (Exception exception)
                {
                    newContext.SetFaulted(exception);

                    throw;
                }
            }
            else
            {
                await existingContext.Ready.ConfigureAwait(false);
            }
        }
        public void TestHeavyEquipmentRentalOneDay()
        {
            RentalCalculator rc = new RentalCalculator();
            OneTime          ot = new OneTime();
            Premium          pr = new Premium();
            int   days          = 1;
            float shouldBe      = ot.getFees() + pr.getFees(1);

            Assert.AreEqual(rc.getRentalPrice(EquipmentType.Heavy, days), shouldBe);
        }
        public void TestRegularEquipmentRentalTwoDays()
        {
            RentalCalculator rc = new RentalCalculator();
            OneTime          ot = new OneTime();
            Premium          pr = new Premium();
            int   days          = 2;
            float shouldBe      = ot.getFees() + pr.getFees(days);

            Assert.AreEqual(rc.getRentalPrice(EquipmentType.Regular, days), shouldBe);
        }
Exemplo n.º 5
0
 public void Post(OneTime value)
 {
     using (var conn = new SqlConnection(this.connString))
     {
         string sQuery = "INSERT INTO OneTime (LockID, Time, Date, PersonID, KeyID)"
                         + " VALUES(@LockID, @Time, @Date, @PersonID, @KeyID)";
         conn.Open();
         conn.Execute(sQuery, value);
     }
 }
Exemplo n.º 6
0
            public void RecordTransaction()
            {
                cli.Title("Which type of transaction would you like to put on record?");

                string[] tmpOpt = { "One-time purchase", "Regular expense" };
                cli.ListOptions(tmpOpt);

                int input;

                while (true)
                {
                    try
                    {
                        input = Convert.ToInt32(cli.Input());

                        if (input != 1 && input != 2)
                        {
                            throw new ArgumentException();
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (FormatException)
                    {
                        cli.Alert("You must enter a valid format!");
                        continue;
                    }
                    catch (ArgumentException)
                    {
                        cli.Alert("You must enter a valid option!");
                        continue;
                    }
                }

                switch (input)
                {
                case 1:
                    OneTime tmp = new OneTime();
                    oneTime.Add(tmp);
                    break;

                case 2:
                    Scheduled tmp1 = new Scheduled();
                    scheduled.Add(tmp1);
                    break;
                }
            }
Exemplo n.º 7
0
        /// <summary>
        /// Using a filter-supplied context type, block so that the one time code is only executed once regardless of how many
        /// threads are pushing through the pipe at the same time.
        /// </summary>
        /// <typeparam name="T">The payload type, should be an interface</typeparam>
        /// <param name="context">The pipe context</param>
        /// <param name="setupMethod">The setup method, called once regardless of the thread count</param>
        /// <param name="payloadFactory">The factory method for the payload context, optional if an interface is specified</param>
        /// <returns></returns>
        public static async Task OneTimeSetup <T>(this PipeContext context, Func <T, Task> setupMethod, PayloadFactory <T> payloadFactory)
            where T : class
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (setupMethod == null)
            {
                throw new ArgumentNullException(nameof(setupMethod));
            }
            if (payloadFactory == null)
            {
                throw new ArgumentNullException(nameof(payloadFactory));
            }

            OneTime <T> newContext      = null;
            var         existingContext = context.GetOrAddPayload <OneTimeSetupContext <T> >(() =>
            {
                var payload = payloadFactory();

                newContext = new OneTime <T>(payload);

                return(newContext);
            });

            if (newContext == existingContext)
            {
                try
                {
                    await setupMethod(newContext.Payload).ConfigureAwait(false);

                    newContext.SetReady();
                }
                catch (Exception exception)
                {
                    newContext.SetFaulted(exception);

                    throw;
                }
            }
            else
            {
                await existingContext.Ready.ConfigureAwait(false);
            }
        }
        public float getRentalPrice(EquipmentType equipmentType, int days)
        {
            float   total   = 0;
            OneTime oneTime = new OneTime();
            Premium premium = new Premium();
            Regular regular = new Regular();

            log.Debug("getRentalPrice: Equipment Type: " + equipmentType + "|Days:" + days);
            switch (equipmentType)
            {
            case EquipmentType.Heavy:
                total = oneTime.getFees() + premium.getFees(days);
                break;

            case EquipmentType.Regular:
                int daysOverTwo = days - 2;
                total = oneTime.getFees();
                if (daysOverTwo <= 0)
                {
                    total += premium.getFees(days);
                }
                else
                {
                    total += premium.getFees(2) + regular.getFees(daysOverTwo);
                }
                break;

            case EquipmentType.Specialized:
                int daysOverThree = days - 3;
                if (daysOverThree <= 0)
                {
                    total = premium.getFees(days);
                }
                else
                {
                    total = premium.getFees(3) + regular.getFees(daysOverThree);
                }
                break;

            default:
                break;
            }
            log.Info("getRentalPrice: Total:" + total);
            return(total);
        }
Exemplo n.º 9
0
            public void EditTransaction()
            {
                if (util.GetExpenseType("modify") == typeof(OneTime))
                {
                    util.ListTransactions(typeof(OneTime));

                    string name = cli.Input("Which transaction would you like to modify?").ToLower();

                    foreach (OneTime i in oneTime)
                    {
                        if (i.Name.ToLower() == name)
                        {
                            OneTime obj = oneTime[oneTime.IndexOf(i)]; //just so i can refund it
                            profile.Refund(obj);
                            obj = new OneTime();
                            oneTime[oneTime.IndexOf(i)] = obj;
                            break;
                        }
                    }
                }
                else
                {
                    util.ListTransactions(typeof(Scheduled));

                    string name = cli.Input("Which transaction would you like to modify?").ToLower();

                    foreach (Scheduled i in scheduled)
                    {
                        if (i.Name.ToLower() == name)
                        {
                            Scheduled obj = scheduled[scheduled.IndexOf(i)];
                            profile.Refund(obj);
                            obj = new Scheduled();
                            scheduled[scheduled.IndexOf(i)] = obj; //what if i just do this instead? EDIT: oh wow this actually works
                            break;
                        }
                    }
                }
            }
Exemplo n.º 10
0
            public static OneTime FromString(string strText)
            {
                string strTime = "";
                string strDetect = "";
                StringUtil.ParseTwoPart(strText,
                    "|",
                    out strTime,
                    out strDetect);
                OneTime result = new OneTime();
                result.Time = strTime;
                result.Detect = DomUtil.IsBooleanTrue(strDetect);

                return result;
            }
Exemplo n.º 11
0
 public void Post([FromBody] OneTime value)
 {
     oneTimeRepository.Post(value);
 }
Exemplo n.º 12
0
            public void Load()
            {
                if (!File.Exists(".save"))
                {
                    util.Introduction();
                }
                else
                {
                    using (StreamReader sr = new StreamReader(".save"))
                    {
                        Phase1(sr); //I'm not sure if 'ref' is needed to progress the StreamReader's iteration
                                    //or not, just making sure
                                    //Edit: nope
                        Phase2(sr);
                        Phase3(sr);
                    }

                    util.List();
                }

                void Phase1(StreamReader sr)
                {
                    profile.Card     = Convert.ToInt32(sr.ReadLine());
                    profile.Cash     = Convert.ToInt32(sr.ReadLine());
                    profile.Currency = sr.ReadLine();
                }

                void Phase2(StreamReader sr)
                {
                    while (true)
                    {
                        string streamInput = sr.ReadLine();
                        if (streamInput != "#--#")
                        {
                            OneTime tmp = new OneTime(true);
                            tmp.Name         = streamInput;
                            tmp.Value        = Convert.ToInt32(sr.ReadLine());
                            tmp.PurchaseDate = Convert.ToDateTime(sr.ReadLine());
                            tmp.Method       = (PaymentMethod)Convert.ToInt32(sr.ReadLine());
                            oneTime.Add(tmp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                void Phase3(StreamReader sr)
                {
                    while (!sr.EndOfStream) //edit if more things will be saved in the future
                    {
                        Scheduled tmp = new Scheduled(true);
                        tmp.Name            = sr.ReadLine();
                        tmp.Value           = Convert.ToInt32(sr.ReadLine());
                        tmp.PurchaseDate    = Convert.ToDateTime(sr.ReadLine());
                        tmp.Interval.Num    = Convert.ToInt32(sr.ReadLine());
                        tmp.Interval.Format = Convert.ToChar(sr.ReadLine());
                        tmp.Method          = (PaymentMethod)Convert.ToInt32(sr.ReadLine());

                        scheduled.Add(tmp);
                    }
                }
            }