public EditionWindow(Info infoToEdit)
 {
     InitializeComponent();
     this.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, this.OnCloseWindow));
     this.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, this.OnMaximizeWindow, this.OnCanResizeWindow));
     this.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, this.OnMinimizeWindow, this.OnCanMinimizeWindow));
     this.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, this.OnRestoreWindow, this.OnCanResizeWindow));
     this.DataContext = infoToEdit;
 }
Exemplo n.º 2
0
    public ClaimDetail getClaimInfo(long id)
    {
        var defaultErrors = new List <int>()
        {
            -1, 2, 0
        };
        var info       = new ClaimDetail();
        var memberCode = (string)userInfo.MemberCode;

        var values = createBaseContent();

        values.Add("MemberCode", memberCode);
        values.Add("SlotPromoSettingsId", id.ToString());

        var content = new FormUrlEncodedContent(values);

        var slotClient = new HttpClient();
        HttpResponseMessage wcfResponse = slotClient.PostAsync(opsettings.Values.Get("DailySlotPromoService") + "/GetMemberStakeAndBonus", content).Result;
        HttpContent         stream      = wcfResponse.Content;
        var data = stream.ReadAsStringAsync();

        PromoClaimRequest response = (PromoClaimRequest)JsonConvert.DeserializeObject(data.Result, typeof(PromoClaimRequest));

        Models.Info stakeInfo = response.info;
        info.svc_error_code = stakeInfo.ErrorCode;
        info.svc_error      = stakeInfo.Message;
        var errorString = (stakeInfo.ErrorCode == -1) ? "Minus1" : Convert.ToString(stakeInfo.ErrorCode);

        if (defaultErrors.Contains(info.svc_error_code))
        {
            errorString = "ErrorDefault";
        }
        else
        {
        }
        info.message = commonCulture.ElementValues.getResourceXPathString(
            "StakeAndBonus/Error" + errorString,
            commonVariables.PromotionsXML);

        switch (stakeInfo.ErrorCode)
        {
        case -1:
        case -2:
        case 1:
        case 10:
            info.message = commonCulture.ElementValues.getResourceXPathString(
                "StakeAndBonus/ErrorDefault",
                commonVariables.PromotionsXML);
            break;

        default:
            info.message = commonCulture.ElementValues.getResourceXPathString(
                "StakeAndBonus/Error" + Convert.ToString(response.info.ErrorCode),
                commonVariables.PromotionsXML);
            if (string.IsNullOrEmpty(info.message))
            {
                info.message = commonCulture.ElementValues.getResourceXPathString(
                    "StakeAndBonus/ErrorDefault",
                    commonVariables.PromotionsXML);
            }
            break;
        }

        info.total_stake     = response.TotalStake;
        info.bonus_amount    = response.ClaimAmount;
        info.rollover_amount = response.RolloverAmount;
        info.total_win_lost  = response.TotalStake;

        if (response.SlotPromoSetup != null)
        {
            info.rollover   = response.SlotPromoSetup.Rollover;
            info.min_amount = response.SlotPromoSetup.Stake;
        }


        return(info);
    }
Exemplo n.º 3
0
    public claim createClaim(long promoId, string gameClub)
    {
        var promoClaim = new claim();


        var riskId     = userInfo.RiskId ?? "N";
        var memberCode = (string)userInfo.MemberCode;

        var values = createBaseContent();

        values.Add("MemberCode", memberCode);
        values.Add("SlotPromoSettingsId", promoId.ToString());
        values.Add("ProductCodeToCredit", gameClub);
        values.Add("CreatedBy", memberCode);

        var content = new FormUrlEncodedContent(values);

        var slotClient = new HttpClient();
        HttpResponseMessage wcfResponse = slotClient.PostAsync(opsettings.Values.Get("DailySlotPromoService") + "/AddSlotPromoClaim", content).Result;
        HttpContent         stream      = wcfResponse.Content;
        var data = stream.ReadAsStringAsync();

        PromoClaimedResult response = (PromoClaimedResult)JsonConvert.DeserializeObject(data.Result, typeof(PromoClaimedResult));

        Models.Info claimInfo = response.info;
        promoClaim.status = claimInfo.ErrorCode;

        switch (response.info.ErrorCode)
        {
        case -1:
        case -2:
        case 1:
        case 10:
        case 100:
            promoClaim.hidden_message = promoClaim.message = commonCulture.ElementValues.getResourceXPathString(
                "PromoClaim/ErrorDefault",
                commonVariables.PromotionsXML);
            break;

        case 0:
            promoClaim.hidden_message = promoClaim.message = commonCulture.ElementValues.getResourceXPathString(
                "PromoClaim/Success",
                commonVariables.PromotionsXML);
            break;

        default:
            promoClaim.hidden_message = promoClaim.message = commonCulture.ElementValues.getResourceXPathString(
                "PromoClaim/Error" + Convert.ToString(response.info.ErrorCode),
                commonVariables.PromotionsXML);
            if (string.IsNullOrEmpty(promoClaim.message))
            {
                promoClaim.message = commonCulture.ElementValues.getResourceXPathString(
                    "PromoClaim/ErrorDefault",
                    commonVariables.PromotionsXML);
                promoClaim.hidden_message = string.Format("{0}: {1}", claimInfo.ErrorCode, claimInfo.Message);
            }
            break;
        }

        return(promoClaim);
    }
        public async Task<CountResponse> Count()
        {
            // Get the list of representative service partition clients.
            IList<ServicePartitionClient<CommunicationClient>> partitionClients = 
                await this.GetServicePartitionClientsAsync();

            // For each partition client, keep track of partition information and the number of words
            ConcurrentDictionary<Int64RangePartitionInformation, long> totals = new ConcurrentDictionary<Int64RangePartitionInformation, long>();
            IList<Task> tasks = new List<Task>(partitionClients.Count);
            foreach (ServicePartitionClient<CommunicationClient> partitionClient in partitionClients)
            {
                // partitionClient internally resolves the address and retries on transient errors based on the configured retry policy.
                tasks.Add(
                    partitionClient.InvokeWithRetryAsync(
                        client =>
                        {
                            Uri serviceAddress = new Uri(client.BaseAddress, "Count");

                            HttpWebRequest request = WebRequest.CreateHttp(serviceAddress);
                            request.Method = "GET";
                            request.Timeout = (int)client.OperationTimeout.TotalMilliseconds;
                            request.ReadWriteTimeout = (int)client.ReadWriteTimeout.TotalMilliseconds;

                            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                            {
                                totals[client.ResolvedServicePartition.Info as Int64RangePartitionInformation] = Int64.Parse(reader.ReadToEnd().Trim());
                            }

                            return Task.FromResult(true);
                        }));
            }

            try
            {
                await Task.WhenAll(tasks);
            }
            catch (Exception ex)
            {
                // Sample code: print exception
                ServiceEventSource.Current.OperationFailed(ex.Message, "Count - run web request");
            }

            var retVal = new CountResponse();

            retVal.Total = totals.Aggregate<KeyValuePair<Int64RangePartitionInformation, long>, long>(0, (total, next) => next.Value + total);
            foreach (KeyValuePair<Int64RangePartitionInformation, long> partitionData in totals.OrderBy(partitionData => partitionData.Key.LowKey))
            {
                var info = new Info();

                info.Id = partitionData.Key.Id;
                info.LowKey = partitionData.Key.LowKey;
                info.HighKey = partitionData.Key.HighKey;
                info.Hits = partitionData.Value;

                retVal.Infos.Add(info);
            }

            return retVal;
        }
        private async Task DoParseStations()
        {
            HttpClient client = new HttpClient();
            HttpResponseMessage response = await client.GetAsync("http://proezd.by/js/localdata.js");

            String data = await response.Content.ReadAsStringAsync();

            Int32 start = data.IndexOf('[');
            Int32 length = data.LastIndexOf(']') - start + 1;

            data = data.Substring(start, length);

            Int32 handledStationCount = 0;

            List<String> stations = JsonConvert.DeserializeObject<List<String>>(data);

            IHubContext progressHubContext = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();

            using (DataContext dataContext = new DataContext())
            {
                foreach (String stationName in stations)
                {
                    String url = String.Format("http://proezd.by/stop?poisk_up={0}", stationName);

                    String stationHtml = await (await client.GetAsync(url)).Content.ReadAsStringAsync();

                    HtmlDocument html = new HtmlDocument();
                    html.LoadHtml(stationHtml);
                    HtmlNode document = html.DocumentNode;

                    HtmlNode listNode = document.QuerySelector(".spisok_na_vivod_33");

                    dataContext.SaveChanges();

                    foreach (HtmlNode infoNode in listNode.QuerySelectorAll(".vivod_33 a"))
                    {
                        String hrefAttr = infoNode.GetAttributeValue("href", String.Empty);
                        String name = infoNode.InnerText;

                        String description = infoNode
                            .QuerySelector(".opisianie_oostanovok").InnerText
                            .Replace("(", String.Empty)
                            .Replace(")", String.Empty);

                        String stationCodeStr = hrefAttr.Replace("?id=", String.Empty);
                        Int32 code = 0;
                        if (!Int32.TryParse(stationCodeStr, out code))
                        {
                            continue;
                        }

                        Station station = new Station()
                        {
                            Code = code,
                            Name = name,
                        };

                        dataContext.Stations.Add(station);
                        dataContext.SaveChanges();
                    }

                    handledStationCount++;

                    Info info = new Info()
                    {
                        Progress =
                            ((handledStationCount == stations.Count) ? 1 : ((Single)handledStationCount / stations.Count)) *
                                100,
                        Operation = stationName
                    };

                    progressHubContext.Clients.All.onProgress(info);
                }
            }
        }
        private async Task DoParseTime()
        {
            Int32 handledRouteCount = 0;
            IHubContext progressHubContext = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();

            using (HttpClient client = new HttpClient())
            using (DataContext dataContext = new DataContext())
            {
                // Get all transports
                List<Transport> transports = dataContext.Transports.ToList();
                List<Station> stations = dataContext.Stations.ToList<Station>();

                // Get href attributes for bus
                List<String> hrefs = new List<String>();

                foreach (Transport transport in transports)
                {
                    foreach (Station station in stations)
                    {
                        String timeUrl = String.Format(ProezdByUrlDictionary.BusUpSheduleUrl, station.Code, transport.Name);
                        String pageContent = await client.GetStringAsync(timeUrl);

                        List<TimeStopTransport> dateTimes = GetTime(pageContent);

                        if (dateTimes.Count > 0)
                        {
                            Schedule scheduleWorkDays = new Schedule
                            {
                                TransportID = transport.ID,
                                StationID = station.ID,
                                IsWeekend = false
                            };

                            Schedule scheduleWeekend = new Schedule
                            {
                                TransportID = transport.ID,
                                StationID = station.ID,
                                IsWeekend = true
                            };

                            dataContext.Schedules.Add(scheduleWorkDays);
                            dataContext.Schedules.Add(scheduleWeekend);
                            dataContext.SaveChanges();

                            foreach (TimeStopTransport item in dateTimes)
                            {
                                ScheduleItem scheduleItem = new ScheduleItem
                                {
                                    ScheduleID = item.IsWeekend ? scheduleWeekend.ID : scheduleWorkDays.ID,
                                    Time = new DateTime(2013, 5, 5, item.Hour, item.Minute, 0)
                                };
                                dataContext.ScheduleItems.Add(scheduleItem);
                                dataContext.SaveChanges();
                            }
                        }
                    }

                    #region Handle progress

                    handledRouteCount++;

                    Info info = new Info()
                    {
                        Progress =
                            ((handledRouteCount == transports.Count)
                                 ? 1
                                 : ((Single)handledRouteCount / transports.Count)) *
                            100,
                        Operation = transport.Name
                    };

                    progressHubContext.Clients.All.onProgress(info);

                    #endregion
                }
            }
        }
        private async Task DoParseDirections()
        {
            Int32 handledRouteCount = 0;
            IHubContext progressHubContext = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();

            using (HttpClient client = new HttpClient())
            using (DataContext dataContext = new DataContext())
            {
                // Get all transports
                List<Transport> transports = dataContext.Transports.ToList();
                List<Station> stations = dataContext.Stations.ToList<Station>();

                // Get href attributes for bus
                List<String> hrefs = new List<String>();
                String pageContent = await client.GetStringAsync(ProezdByUrlDictionary.BusRoutesList);
                hrefs.AddRange(ExtractDirectionStationsPageUrl(pageContent));

                pageContent = await client.GetStringAsync(ProezdByUrlDictionary.TrolleybusRoutesList);
                hrefs.AddRange(ExtractDirectionStationsPageUrl(pageContent));

                foreach (Transport transport in transports)
                {
                    // Get transport type
                    TransportType transportType = dataContext.TransportTypes.First(x => x.ID.Equals(transport.TypeID));

                    switch (transportType.Name)
                    {
                        case ("Автобусы"):
                            {
                                #region Up direction

                                String upDirectionUrl = String.Format(ProezdByUrlDictionary.BusUpDirectionUrl, transport.Name);
                                if (hrefs.Contains(upDirectionUrl))
                                {
                                    pageContent = await client.GetStringAsync(upDirectionUrl);
                                    List<Int32> directionStationsCodes = ExtractDirectionStationsCodes(pageContent);

                                    // Create direction
                                    Direction direction = new Direction
                                    {
                                        Name = transport.Name,
                                        TransportID = transport.ID,
                                        StartID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.First())).ID,
                                        EndID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.Last())).ID
                                    };
                                    dataContext.Directions.Add(direction);
                                    dataContext.SaveChanges();

                                    // Create direction stations
                                    for (Int32 i = 0; i < directionStationsCodes.Count; i++)
                                    {
                                        dataContext.DirectionStations.Add(new DirectionStation
                                        {
                                            DirectionID = direction.ID,
                                            StationID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes[i])).ID,
                                            Order = i
                                        });
                                    }
                                    dataContext.SaveChanges();
                                }

                                #endregion

                                #region Down direction

                                String downDirectionUrl = String.Format(ProezdByUrlDictionary.BusDownDirectionUrl, transport.Name);
                                if (hrefs.Contains(downDirectionUrl))
                                {
                                    pageContent = await client.GetStringAsync(downDirectionUrl);
                                    List<Int32> directionStationsCodes = ExtractDirectionStationsCodes(pageContent);

                                    // Create direction
                                    Direction direction = new Direction
                                    {
                                        Name = transport.Name,
                                        TransportID = transport.ID,
                                        StartID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.First())).ID,
                                        EndID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.Last())).ID
                                    };
                                    dataContext.Directions.Add(direction);
                                    dataContext.SaveChanges();

                                    // Create direction stations
                                    for (Int32 i = 0; i < directionStationsCodes.Count; i++)
                                    {
                                        dataContext.DirectionStations.Add(new DirectionStation
                                        {
                                            DirectionID = direction.ID,
                                            StationID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes[i])).ID,
                                            Order = i
                                        });
                                    }
                                    dataContext.SaveChanges();
                                }

                                #endregion
                            } break;

                        case ("Троллейбусы"):
                            {
                                #region Up direction

                                String upDirectionUrl = String.Format(ProezdByUrlDictionary.TrolleybusUpDirectionUrl, transport.Name);
                                if (hrefs.Contains(upDirectionUrl))
                                {
                                    pageContent = await client.GetStringAsync(upDirectionUrl);
                                    List<Int32> directionStationsCodes = ExtractDirectionStationsCodes(pageContent);

                                    Direction direction = new Direction
                                    {
                                        Name = transport.Name,
                                        TransportID = transport.ID,
                                        StartID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.First())).ID,
                                        EndID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.Last())).ID
                                    };
                                    dataContext.Directions.Add(direction);
                                    dataContext.SaveChanges();

                                    // Create direction stations
                                    for (Int32 i = 0; i < directionStationsCodes.Count; i++)
                                    {
                                        dataContext.DirectionStations.Add(new DirectionStation
                                        {
                                            DirectionID = direction.ID,
                                            StationID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes[i])).ID,
                                            Order = i
                                        });
                                    }
                                    dataContext.SaveChanges();
                                }

                                #endregion

                                #region Down direction

                                String downDirectionUrl = String.Format(ProezdByUrlDictionary.TrolleybusDownDirectionUrl, transport.Name);
                                if (hrefs.Contains(downDirectionUrl))
                                {
                                    pageContent = await client.GetStringAsync(downDirectionUrl);
                                    List<Int32> directionStationsCodes = ExtractDirectionStationsCodes(pageContent);

                                    Direction direction = new Direction
                                    {
                                        Name = transport.Name,
                                        TransportID = transport.ID,
                                        StartID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.First())).ID,
                                        EndID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes.Last())).ID
                                    };
                                    dataContext.Directions.Add(direction);
                                    dataContext.SaveChanges();

                                    // Create direction stations
                                    for (Int32 i = 0; i < directionStationsCodes.Count; i++)
                                    {
                                        dataContext.DirectionStations.Add(new DirectionStation
                                        {
                                            DirectionID = direction.ID,
                                            StationID = stations.AsParallel().First(x => x.Code.Equals(directionStationsCodes[i])).ID,
                                            Order = i
                                        });
                                    }
                                    dataContext.SaveChanges();
                                }

                                #endregion
                            } break;
                    }

                    #region Handle progress

                    handledRouteCount++;

                    Info info = new Info()
                    {
                        Progress =
                            ((handledRouteCount == transports.Count)
                                 ? 1
                                 : ((Single)handledRouteCount / transports.Count)) *
                            100,
                        Operation = transport.Name
                    };

                    progressHubContext.Clients.All.onProgress(info);

                    #endregion
                }
            }
        }
        private async Task DoParseRoutes(String routesListUrl, String transportTypeName, String hrefBegin)
        {
            Int32 handledRouteCount = 0;
            IHubContext progressHubContext = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();

            using (HttpClient client = new HttpClient())
            using (DataContext dataContext = new DataContext())
            {
                Guid busTypeId = dataContext.TransportTypes.First(x => x.Name.Equals(transportTypeName)).ID;
                String pageContent = await client.GetStringAsync(routesListUrl);

                HtmlDocument htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(pageContent);

                HtmlNode document = htmlDocument.DocumentNode;
                List<HtmlNode> busRouteLinks = document.QuerySelectorAll(".naprovlenie_odin_variant a").ToList();
                List<String> busRouteLinksHref = busRouteLinks.Select(busRoute => busRoute.GetAttributeValue("href", String.Empty)).ToList();

                // Extract route number
                List<String> routes = busRouteLinksHref.Select(x =>
                {
                    String temString = x.Remove(0, hrefBegin.Length);
                    temString = temString.Split('&')[0];

                    return temString;
                }).Distinct().ToList();

                foreach (String route in routes)
                {
                    Transport transport = new Transport
                    {
                        Name = route,
                        TypeID = busTypeId
                    };
                    dataContext.Transports.Add(transport);
                    dataContext.SaveChanges();

                    handledRouteCount++;

                    Info info = new Info()
                    {
                        Progress =
                            ((handledRouteCount == routes.Count) ? 1 : ((Single)handledRouteCount / routes.Count)) *
                                100,
                        Operation = route
                    };

                    progressHubContext.Clients.All.onProgress(info);
                }
            }
        }