Exemple #1
0
        public Bet(IBetBonus bonus, IStake stake, IStake entireStake, string id, IEnumerable <int> selectedSystems, IEnumerable <ISelection> selections, string reofferRefId, long sumOfWins, bool?customBet, int?calculationOdds)
        {
            Guard.Argument(stake, nameof(stake)).NotNull();
            Guard.Argument(id, nameof(id)).Require(string.IsNullOrEmpty(id) || TicketHelper.ValidateTicketId(id));
            var systems = selectedSystems == null ? new List <int>() : selectedSystems.ToList();

            Guard.Argument(systems, nameof(systems)).Require(selectedSystems == null ||
                                                             (systems.Any()
                                                              //&& systems.Count < 64
                                                              && systems.Count == systems.Distinct().Count() &&
                                                              systems.All(a => a > 0)));
            var listSelections = selections.ToList();

            Guard.Argument(listSelections, nameof(listSelections)).NotNull();
            if (!listSelections.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(selections));
            }
            Guard.Argument(listSelections, nameof(listSelections)).Require(/*listSelections.Count < 64 && */ listSelections.Count == listSelections.Distinct().Count());

            Guard.Argument(reofferRefId, nameof(reofferRefId)).Require(string.IsNullOrEmpty(reofferRefId) || reofferRefId.Length <= 50);
            Guard.Argument(sumOfWins, nameof(sumOfWins)).NotNegative();
            bool customBetBool = customBet ?? false;

            Guard.Argument(customBet, nameof(customBet)).Require((customBetBool && calculationOdds != null && calculationOdds >= 0) || (!customBetBool && calculationOdds == null));

            Bonus           = bonus;
            Stake           = stake;
            EntireStake     = entireStake;
            Id              = id;
            SelectedSystems = systems;
            Selections      = listSelections;
            ReofferRefId    = reofferRefId;
            SumOfWins       = sumOfWins;
            CustomBet       = customBet;
            CalculationOdds = calculationOdds;

            if (SelectedSystems != null)
            {
                var enumerable = SelectedSystems as IList <int> ?? SelectedSystems.ToList();
                if (SelectedSystems != null && enumerable.Any(a => a > Selections.Count()))
                {
                    throw new ArgumentException("Invalid value in SelectedSystems.");
                }
            }
        }
Exemple #2
0
        public bool IsEquivalentTo(Market market, bool checkTags, bool checkSelections)
        {
            if (market == null)
            {
                return(false);
            }

            if (market.Id != Id)
            {
                return(false);
            }

            if (checkTags)
            {
                if (market.TagsCount != TagsCount)
                {
                    return(false);
                }

                if (market.TagKeys.Any(tag => !HasTag(tag) || GetTagValue(tag) != market.GetTagValue(tag)))
                {
                    return(false);
                }
            }

            if (checkSelections)
            {
                if (Selections.Count() != market.Selections.Count())
                {
                    return(false);
                }

                foreach (var seln in market.Selections)
                {
                    ISelectionState seln_state = this[seln.Id];
                    if (seln_state == null)
                    {
                        return(false);
                    }

                    if (!seln_state.IsEquivalentTo(seln, checkTags))
                    {
                        return(false);
                    }
                }
            }

            var result = IsSuspended == market.IsSuspended &&
                         IsActive == market.IsActive &&
                         IsResulted == market.IsResulted &&
                         IsPending == market.IsPending &&
                         IsVoided == market.IsVoided;


            if (IsRollingMarket)
            {
                result &= Line == ((RollingMarket)market).Line;
            }

            // the only case we really should pay attention
            // is when we have forced the suspension
            // when the market was active
            if (IsForcedSuspended)
            {
                result &= market.IsSuspended;
            }

            return(result);
        }
        void Command_Numeric_RandomNumber(NumericRandomNumberDialog.Result result)
        {
            var variables = GetVariables();
            var minValues = new NEExpression(result.MinValue).EvaluateList <int>(variables, Selections.Count());
            var maxValues = new NEExpression(result.MaxValue).EvaluateList <int>(variables, Selections.Count());

            ReplaceSelections(Selections.AsParallel().Select((range, index) => random.Next(minValues[index], maxValues[index] + 1).ToString()).ToList());
        }
        void Command_Numeric_Cycle(NumericCycleDialog.Result result)
        {
            var variables = GetVariables();
            var minimums  = new NEExpression(result.Minimum).EvaluateList <double>(variables, Selections.Count());
            var maximums  = new NEExpression(result.Maximum).EvaluateList <double>(variables, Selections.Count());

            ReplaceSelections(Selections.AsParallel().AsOrdered().Select((range, index) => Cycle(double.Parse(GetString(range)), minimums[index], maximums[index], result.IncludeBeginning).ToString()).ToList());
        }
        void Command_Numeric_Round(NumericFloorRoundCeilingDialog.Result result)
        {
            var baseValue = new NEExpression(result.BaseValue).EvaluateList <double>(GetVariables(), Selections.Count());
            var interval  = new NEExpression(result.Interval).EvaluateList <double>(GetVariables(), Selections.Count());

            ReplaceSelections(Selections.AsParallel().AsOrdered().Select((range, index) => (Math.Round((double.Parse(GetString(range), NumberStyles.Float) - baseValue[index]) / interval[index], MidpointRounding.AwayFromZero) * interval[index] + baseValue[index]).ToString()).ToList());
        }
        void Command_Numeric_Scale(NumericScaleDialog.Result result)
        {
            var variables = GetVariables();
            var prevMins  = new NEExpression(result.PrevMin).EvaluateList <double>(variables, Selections.Count());
            var prevMaxs  = new NEExpression(result.PrevMax).EvaluateList <double>(variables, Selections.Count());
            var newMins   = new NEExpression(result.NewMin).EvaluateList <double>(variables, Selections.Count());
            var newMaxs   = new NEExpression(result.NewMax).EvaluateList <double>(variables, Selections.Count());

            ReplaceSelections(Selections.AsParallel().AsOrdered().Select((range, index) => ((double.Parse(GetString(range)) - prevMins[index]) * (newMaxs[index] - newMins[index]) / (prevMaxs[index] - prevMins[index]) + newMins[index]).ToString()).ToList());
        }
Exemple #7
0
        void Command_Image_GrabImage(ImageGrabImageDialog.Result result)
        {
            var variables = GetVariables();
            var x         = new NEExpression(result.GrabX).EvaluateList <int>(variables, Selections.Count());
            var y         = new NEExpression(result.GrabY).EvaluateList <int>(variables, Selections.Count());
            var width     = new NEExpression(result.GrabWidth).EvaluateList <int>(variables, Selections.Count());
            var height    = new NEExpression(result.GrabHeight).EvaluateList <int>(variables, Selections.Count());

            var strs = new List <string>();

            for (var ctr = 0; ctr < x.Count; ++ctr)
            {
                using (var image = new System.Drawing.Bitmap(width[ctr], height[ctr], System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    using (var dest = System.Drawing.Graphics.FromImage(image))
                        dest.CopyFromScreen(x[ctr], y[ctr], 0, 0, image.Size);
                    strs.Add(Coder.BitmapToString(image));
                }
            }
            ReplaceSelections(strs);
        }