Ejemplo n.º 1
0
        public void Chaining_Dictionary()
        {
            var dict = new System.Collections.Generic.Dictionary <int, int> {
                [1] = 2, [3] = 4
            };
            var sortedDict = new System.Collections.Generic.SortedDictionary <int, int> {
                [1] = 2, [3] = 4
            };

            System.Collections.Generic.KeyValuePair <int, int> dictKvp = default(System.Collections.Generic.KeyValuePair <int, int>);
            foreach (var kv in dict)
            {
                dictKvp = kv;
                break;
            }

            System.Collections.Generic.KeyValuePair <int, int> sortedDictKvp = default(System.Collections.Generic.KeyValuePair <int, int>);
            foreach (var kv in sortedDict)
            {
                sortedDictKvp = kv;
                break;
            }

            Assert.AreEqual(dictKvp, dict.First());
            Assert.AreEqual(dictKvp, dict.First(x => true));
            Assert.AreEqual(dictKvp, dict.FirstOrDefault());
            Assert.AreEqual(dictKvp, dict.FirstOrDefault(x => true));
            Assert.AreEqual(sortedDictKvp, sortedDict.First());
            Assert.AreEqual(sortedDictKvp, sortedDict.First(x => true));
            Assert.AreEqual(sortedDictKvp, sortedDict.FirstOrDefault());
            Assert.AreEqual(sortedDictKvp, sortedDict.FirstOrDefault(x => true));
        }
Ejemplo n.º 2
0
        public void Errors_Dictionary()
        {
            var dict = new System.Collections.Generic.Dictionary <int, int> {
                [1] = 2, [3] = 4
            };
            var sortedDict = new System.Collections.Generic.SortedDictionary <int, int> {
                [1] = 2, [3] = 4
            };

            try { dict.First(null); Assert.Fail(); }catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
            try { dict.FirstOrDefault(null); Assert.Fail(); } catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
            try { sortedDict.First(null); Assert.Fail(); } catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
            try { sortedDict.FirstOrDefault(null); Assert.Fail(); } catch (ArgumentNullException exc) { Assert.AreEqual("predicate", exc.ParamName); }
        }
Ejemplo n.º 3
0
        private async void metroComboAvailableDicts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (metroComboAvailableDicts.SelectedIndex != 0)
            {
                strSelectedID        = dictionaryList.FirstOrDefault(x => x.Value == metroComboAvailableDicts.Text).Key;
                metroLblSelDict.Text = String.Format("Selected:\n\tDictionary Id: {0}\n\tDictionary Name: {1}",
                                                     strSelectedID, metroComboAvailableDicts.Text);

                MakeLoadPanelVisible(metroPanelHome);
                rtxtDictInfo.Text = await Task.Run(() => service.DictionaryInfo(strSelectedID));

                MakeLoadPanelHide(metroPanelHome);
            }
            else
            {
                metroLblSelDict.Text = "Selected: All";
            }
        }
Ejemplo n.º 4
0
        private ActionResult Processing_PayPal(int claim, PaymentMode payment)
        {
            if (payment == null)
            {
                throw new System.ArgumentNullException("payment");
            }
            PaymentBeforeProcessingResult beforePaymentResult = BookingProvider.BeforePaymentProcessing(UrlLanguage.CurrentLanguage, payment.paymentparam);

            if (beforePaymentResult == null)
            {
                throw new System.Exception("cannot get payment details");
            }
            if (!beforePaymentResult.success)
            {
                throw new System.Exception("payment details fail");
            }
            System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>();
            PaymentDetailsType paymentDetail = new PaymentDetailsType();

            paymentDetail.AllowedPaymentMethod = new AllowedPaymentMethodType?(AllowedPaymentMethodType.ANYFUNDINGSOURCE);
            CurrencyCodeType       currency    = (CurrencyCodeType)EnumUtils.GetValue(payment.payrest.currency, typeof(CurrencyCodeType));
            PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();

            paymentItem.Name                 = string.Format(PaymentStrings.ResourceManager.Get("PaymentForOrderFormat"), claim);
            paymentItem.Amount               = new BasicAmountType(new CurrencyCodeType?(currency), payment.payrest.total.ToString("#.00", System.Globalization.NumberFormatInfo.InvariantInfo));
            paymentItem.Quantity             = new int?(1);
            paymentItem.ItemCategory         = new ItemCategoryType?(ItemCategoryType.PHYSICAL);
            paymentItem.Description          = string.Format("Booking #{0}", claim);
            paymentDetail.PaymentDetailsItem = new System.Collections.Generic.List <PaymentDetailsItemType>
            {
                paymentItem
            };
            paymentDetail.PaymentAction = new PaymentActionCodeType?(PaymentActionCodeType.SALE);
            paymentDetail.OrderTotal    = new BasicAmountType(paymentItem.Amount.currencyID, paymentItem.Amount.value);
            paymentDetails.Add(paymentDetail);
            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();

            ecDetails.ReturnURL = new Uri(base.Request.BaseServerAddress(), base.Url.Action("processingresult", new
            {
                id      = "paypal",
                success = true
            })).ToString();
            ecDetails.CancelURL = new Uri(base.Request.BaseServerAddress(), base.Url.Action("processingresult", new
            {
                id      = "paypal",
                success = false
            })).ToString();
            ecDetails.NoShipping     = "1";
            ecDetails.AllowNote      = "0";
            ecDetails.SolutionType   = new SolutionTypeType?(SolutionTypeType.SOLE);
            ecDetails.SurveyEnable   = "0";
            ecDetails.PaymentDetails = paymentDetails;
            ecDetails.InvoiceID      = beforePaymentResult.invoiceNumber;
            SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();

            request.Version = "104.0";
            request.SetExpressCheckoutRequestDetails = ecDetails;
            SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();

            wrapper.SetExpressCheckoutRequest = request;
            System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig();
            PayPalAPIInterfaceServiceService service       = new PayPalAPIInterfaceServiceService(config);
            SetExpressCheckoutResponseType   setECResponse = service.SetExpressCheckout(wrapper);

            System.Collections.Generic.KeyValuePair <string, string> sandboxConfig = config.FirstOrDefault((System.Collections.Generic.KeyValuePair <string, string> m) => m.Key == "mode");
            string sandboxServer = (sandboxConfig.Key != null && sandboxConfig.Value == "sandbox") ? ".sandbox" : "";

            return(base.View("PaymentSystems\\PayPal", new ProcessingContext
            {
                Reservation = BookingProvider.GetReservationState(UrlLanguage.CurrentLanguage, claim),
                PaymentMode = payment,
                BeforePaymentResult = beforePaymentResult,
                RedirectUrl = string.Format("https://www{0}.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", sandboxServer, base.Server.UrlEncode(setECResponse.Token))
            }));

            //  return new RedirectResult(string.Format("https://www{0}.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", sandboxServer, base.Server.UrlEncode(setECResponse.Token)));
        }
Ejemplo n.º 5
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(values[3].ToString()))
            {
                return(null);
            }

            string dataStr = values[3].ToString().Substring(1, values[3].ToString().Count() - 2).Replace("L", " ");

            PointCollectionConverter pcconverter = new PointCollectionConverter();
            PointCollection          pc          = new PointCollection();

            pc = (PointCollection)pcconverter.ConvertFromString(dataStr);
            List <Point> pointList = pc.ToList();

            double xMin_color = 0;  // 色标最小值
            double xMax_color = 60; // 色标最大值

            // 定义色标颜色值(彩虹色)
            Color[] colors = new Color[7] {
                Colors.Red, Colors.Orange, Colors.Yellow, Colors.Green, Colors.Indigo, Colors.Blue, Colors.Violet
            };

            // 定义色标与数值范围字典表
            System.Collections.Generic.Dictionary <string, string> colorDic = new System.Collections.Generic.Dictionary <string, string>();

            double interval = Math.Ceiling((xMax_color - xMin_color) / 6); //处理最大值与最小值间隔,保证彩虹色都使用

            for (int skip = 0; skip < 7; skip++)
            {
                double xRange     = xMin_color + (interval * skip);
                double xNextRange = xMin_color + (interval * (skip + 1));
                colorDic.Add(string.Format(@"{0}_{1}", xRange, xNextRange), string.Format(@"{0}_{1}", skip, skip + 1));
                if (xNextRange >= xMax_color)
                {
                    break;
                }
            }

            //colorDic 目前参数没有使用,使用的是静态的,待设置功能开发完,更换 2017-3-22 sjm
            LinearGradientBrush lineGradientBrush = new LinearGradientBrush();

            // 垂直线性渐变
            lineGradientBrush.StartPoint = new Point(0.5, 0);
            lineGradientBrush.EndPoint   = new Point(0.5, 1);

            lineGradientBrush.GradientStops.Add(new GradientStop()
            {
                Color = Colors.White, Offset = 0
            });

            char split = '_';

            for (int i = 0; i < pointList.Count; i++)
            {
                double xPoint        = pointList[i].X > xMax_color ? xMax_color : pointList[i].X;
                var    colorDicValue = colorDic.FirstOrDefault(x =>
                                                               double.Parse(x.Key.Split(split)[0]) <= xPoint &&
                                                               double.Parse(x.Key.Split(split)[1]) >= xPoint
                                                               ).Value;
                var colorDicKey = colorDic.FirstOrDefault(q => q.Value == colorDicValue).Key;

                string[] colorStrs = colorDicValue.Split(split);
                string[] keyStrs   = colorDicKey.Split(split);

                Color s_color = colors[int.Parse(colorStrs[0])];
                Color d_color = colors[int.Parse(colorStrs[1])];

                Color vColor = GetGradientColor(s_color, d_color, xPoint, double.Parse(keyStrs[0]), double.Parse(keyStrs[1]));
                lineGradientBrush.GradientStops.Add(new GradientStop(vColor, (double)i / pointList.Count));
            }

            lineGradientBrush.GradientStops.Add(new GradientStop()
            {
                Color = Colors.White, Offset = 1
            });
            return(lineGradientBrush);
        }