Ejemplo n.º 1
0
        public override async System.Threading.Tasks.Task<WindDataLib.CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {
            var response = await httpclient.GetAsync(string.Format("https://www.coopvoce.it/jsp/jahia/templates/coop_voce_templates/iphone/json//login.jsp?username={0}&password={1}", username, password));
            var obj = JsonConvert.DeserializeObject<WindDataLib.Scoop.JsonTrafficSummary>(await response.Content.ReadAsStringAsync());

            if (obj.Common.Ack != "OK")
                throw new WrongLoginDataException("Username o password errati");

            cr.Username = username;
            cr.Password = password;
            cr.Type = type;
            foreach (var number in obj.MSISNDs)
            {
                var res = await httpclient.GetAsync(string.Format("https://www.coopvoce.it/p/selfCareAndroid;jsessionid={0}?service=Subscriber/Wallet&MSISDN={1}&APP_ID=CoopVoce&TOKEN=7d83b77c1441879bc3949ed443552252", obj.Common.Jsessionid, number.Msisdn));
                var objt = JsonConvert.DeserializeObject<WindDataLib.Scoop.WalletData>(await res.Content.ReadAsStringAsync());

                if (objt.Common.Ack != "OK")
                    continue;

                double credit = objt.Wallets.First(x => x.Tipo.ToLower().Contains("main")).Valore;

                var nm = new NumberInfo { Number = number.Msisdn.ToString(), Credit = (float)credit };

                res = await httpclient.GetAsync(string.Format("https://www.coopvoce.it//p/selfCareAndroid;jsessionid={0}?service=Promotions/GetPromos&MSISDN={1}&APP_ID=CoopVoce&TOKEN=7d83b77c1441879bc3949ed443552252", obj.Common.Jsessionid, number.Msisdn));
                var objp = JsonConvert.DeserializeObject<WindDataLib.Scoop.OfferData>(await res.Content.ReadAsStringAsync());

                var counters = objp.CurrentPromos.Where(x => x.Counters != null).SelectMany(x => x.Counters);
                foreach (var counter in counters)
                {
                    if (counter.CounterType == "Time") //minuti
                    {
                        nm.Minutes += counter.CounterResidual / 60;
                        nm.MinutesTotal = counter.CounterMaxValue / 60;
                    }
                    else if (counter.CounterType == "Packets")
                    {
                        nm.GigabytesTotal = 100;
                        nm.Gigabytes = (int)(100 * counter.CounterResidual / counter.CounterMaxValue);
                    }
                    else if (counter.CounterType == "Events")
                    {
                        nm.SMS += counter.CounterResidual;
                        nm.SMSTotal = counter.CounterMaxValue;
                    }

                }
                nm.LastUpdate = DateTime.Now;
                if (counters.Any(x => x.NextResetDate != null))
                    nm.ExpirationDate = counters.Where(x => x.NextResetDate != null).Min(x => DateTime.ParseExact(x.NextResetDate, new[] { "dd-MM-yyyy HH:mm", "dd-MM-yyyy" }, CultureInfo.GetCultureInfo("it-IT"), DateTimeStyles.None));
                else if (objp.CurrentPromos.Any(x => x.Counters != null))
                    nm.ExpirationDate = DateTime.ParseExact(objp.CurrentPromos.First(x => x.Counters != null).ExpirationDate, new[] { "dd-MM-yyyy HH:mm", "dd-MM-yyyy" }, CultureInfo.GetCultureInfo("it-IT"), DateTimeStyles.None);
                else
                    nm.ExpirationDate = DateTime.MaxValue;
                cr.NumberInfos.Add(nm);
            }

            return cr;
        }
Ejemplo n.º 2
0
    public static void ConvertToJpg(NumberInfo context)
    {
        foreach (var oCanvas in new Control[] { new _159_159(), new _336_336() })
        {
            oCanvas.DataContext = context;

            int x = oCanvas.GetType().FullName.Contains("159") ? 159 : oCanvas.GetType().FullName.Contains("691") ? 691 : 336;
            oCanvas.DataContext = context;
            oCanvas.Measure(new Size((double)x, (double)(x == 691 ? 336 : x)));
            oCanvas.UpdateLayout();
            oCanvas.Arrange(new Rect(0.0, 0.0, x, x == 691 ? 336 : x));
            oCanvas.UpdateLayout();

            RenderTargetBitmap oRenderTargetBitmap = new RenderTargetBitmap(x, x == 691 ? 336 : x, 96, 96, PixelFormats.Default);
            oRenderTargetBitmap.Render(oCanvas);
            PngBitmapEncoder oPngBitmapEncoder = new PngBitmapEncoder();
            oPngBitmapEncoder.Frames.Add(BitmapFrame.Create(oRenderTargetBitmap));
            using (FileStream oFileStream = new FileStream(Path.Combine(HostingEnvironment.MapPath("~/Tiles/"), context.Number + "_" + x + ".jpg"), FileMode.Create))
            {
                oPngBitmapEncoder.Save(oFileStream);
            }

        }
    }
Ejemplo n.º 3
0
        public override async Task<CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {
            inf.Username = username;
            inf.Password = password;
            inf.Type = type;
            devUDID = dev_id.ToString();
            httpclient.DefaultRequestHeaders.Clear();
            await RegisterInstallation();
            await StartSession();

            httpclient.DefaultRequestHeaders.Add("X-Bwb-SessionId", SessionID);
            using (var res = await httpclient.PostAsJsonAsync("https://my190.vodafone.it/api/v1/session/login", new { username = username, password = password }))
            {
                LoginResult result = await res.Content.ReadAsAsync<LoginResult>();
                if (result.description != "RESPONSE_OK")
                {
                    throw new WrongLoginDataException(result.message);
                }

                foreach (var sim in result.result.sims)
                {
                    var counters = await httpclient.GetAsync(string.Format("https://my190.vodafone.it/api/v1/sim/{0}/counters", sim.msisdn));
                    var balance = httpclient.GetAsync(string.Format("https://my190.vodafone.it/api/v1/sim/{0}/balance", sim.msisdn));

                    Counters cnts = await counters.Content.ReadAsAsync<Counters>();

                    var ninfo = new NumberInfo { Number = sim.msisdn, LastUpdate = DateTime.Now };


                    var v = new List<Value>();
                    if (cnts.result != null)
                        foreach (var counter in cnts.result.counters.Where(x =>
                            !x.id.StartsWith("3616-S")/*Soglia*/
                            && !x.id.StartsWith("502-S") /*Soglia internet*/
                            && !x.id.StartsWith("6298-S")/*Dettagli chiamate*/
                            && !x.id.StartsWith("1477-P") /*You and me*/
                            && !x.id.StartsWith("796-T")/*Hystogram*/ &&
                            !x.id.StartsWith("412-T")/*Nata cos*/))
                        {

                            var rs = await httpclient.GetAsync(string.Format("https://my190.vodafone.it/api/v1/sim/{0}/counter/{1}", sim.msisdn, counter.id));
                            var str = await rs.Content.ReadAsAsync<CounterValueObj>();

                            if (str.result != null && str.result.counter.threshold != null && str.result.counter.threshold.values != null)
                            {
                                foreach (var value in str.result.counter.threshold.values)
                                {
                                    switch (value.label.ToLower())
                                    {
                                        case "chiamate":
                                            ninfo.Minutes += (int)value.threshold - (int)value.value;
                                            ninfo.MinutesTotal += (int)value.threshold;
                                            ninfo.ExpirationDate = DateTime.ParseExact(value.period_end, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                            break;
                                        case "messaggi":
                                            ninfo.SMS += Math.Min((int)value.threshold - (int)value.value, 999);
                                            ninfo.SMSTotal += Math.Min((int)value.threshold, 999);
                                            ninfo.ExpirationDate = DateTime.ParseExact(value.period_end, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                            break;
                                        case "internet":
                                            ninfo.Gigabytes = (int)(100.0f / value.threshold * (value.threshold - value.value));
                                            ninfo.GigabytesTotal = 100;
                                            ninfo.ExpirationDate = DateTime.ParseExact(value.period_end, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                                            break;

                                        default:
                                            break;
                                    }
                                }
                            }
                        }


                    Task.WaitAll(_tasks.ToArray());
                    Balance blnc = await (await balance).Content.ReadAsAsync<Balance>();
                    ninfo.Credit = blnc.result != null && blnc.result.balance.HasValue ? blnc.result.balance.Value : -1.0f;
                    inf.NumberInfos.Add(ninfo);
                }
            }


            return inf;

        }
Ejemplo n.º 4
0
        public async override System.Threading.Tasks.Task<WindDataLib.CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {
            httpclient.DefaultRequestHeaders.Clear();
            httpclient.DefaultRequestHeaders.Add("User-Widget", "iPhone");
            httpclient.DefaultRequestHeaders.Add("Widget-Version", "2.0");
            httpclient.DefaultRequestHeaders.Add("User-Name", username);
            httpclient.DefaultRequestHeaders.Add("Password", password);
            httpclient.DefaultRequestHeaders.Add("Client-Device-Id", username);
            httpclient.DefaultRequestHeaders.Add("Referer", "file:///Applications/Install/55D00839-D0A9-4CAB-B0F9-94DC75ECD835/Install/");
            var respone = await httpclient.GetAsync("https://camp.tim.it/widgetCamp/login.do");
            var res = await respone.Content.ReadAsStreamAsync();
            var strres = await respone.Content.ReadAsStringAsync();
            WindAuth.Models.LoffTim.Login.RESPONSE r;
            XmlSerializer xs = new XmlSerializer(typeof(WindAuth.Models.LoffTim.Login.RESPONSE));
            r = xs.Deserialize(res) as WindAuth.Models.LoffTim.Login.RESPONSE;

            if (r.RESULT.code != 200)
                throw new WrongLoginDataException("Username o password errati");

            var rdata = await httpclient.GetAsync("https://camp.tim.it/widgetCamp/info.do");

            var sinfo = await (rdata).Content.ReadAsStringAsync();
            var tr = new StringReader(sinfo.Replace('&', 'e'));

            XmlSerializer xst = new XmlSerializer(typeof(WindAuth.Models.LoffTim.Info.RESPONSE));
            var infoObj = xst.Deserialize(tr) as WindAuth.Models.LoffTim.Info.RESPONSE;

            cr.Username = username;
            cr.Password = password;
            cr.Type = type;

            var nm = new NumberInfo { ExpirationDate = DateTime.MaxValue, Number = username, Credit = infoObj.CONTENT.INFO.PROFILE.PREPAID != null ? (float)infoObj.CONTENT.INFO.PROFILE.PREPAID.CREDIT.value : (float)infoObj.CONTENT.INFO.PROFILE.CONTRACT.BALANCE.value };



            if (infoObj.CONTENT.INFO.PROMOTIONS.INTERFACELIST != null)
                foreach (var offer in infoObj.CONTENT.INFO.PROMOTIONS.INTERFACELIST.INTERFACE.Where(x => !x.url.Contains("OD994") && !x.url.Contains("DR600") && !x.url.Contains("TD095") && !x.url.Contains("ODB67") && !x.url.Contains("ODC70")))
                {

                    var data = await (await httpclient.GetAsync(offer.url)).Content.ReadAsStringAsync();
                    var srRead = new StringReader(data.Replace('&', 'e'));
                    var dsr = new XmlSerializer(typeof(WindAuth.Models.LoffTim.InterfaceData.RESPONSE));
                    var fdata = dsr.Deserialize(srRead) as WindAuth.Models.LoffTim.InterfaceData.RESPONSE;
                    if (fdata.CONTENT.PROMODETAIL == null || fdata.CONTENT.PROMODETAIL.DESCRIPTIONS.DESCRIPTION == null)
                        continue;

                    nm.ExpirationDate = new DateTime(Math.Min(nm.ExpirationDate.Ticks, DateTime.ParseExact(fdata.CONTENT.PROMODETAIL.EXPIRATION_DATE.value, "dd/MM/yyyy", CultureInfo.InvariantCulture).Ticks));

                    var promodescs = fdata.CONTENT.PROMODETAIL.PROMO_DESC.value.Split('-').SelectMany(x => x.Split('.')).Where(x => !x.Contains("esauri"));

                    foreach (var match in Regex.Matches(string.Join("-", promodescs), @"\d{1,}\b(\w*)\s(\w+)|\d{1,}(\w*)").Cast<Match>())
                    {
                        if (match.Value.ToUpper().Contains("SMS"))
                        {
                            nm.SMSTotal += int.Parse(Regex.Match(match.Value, @"\d+").Value);
                        }
                        else if (match.Value.ToUpper().Contains("MINUT"))
                        {
                            nm.MinutesTotal += int.Parse(Regex.Match(match.Value, @"\d+").Value);
                        }
                        else if (match.Value.ToUpper().Contains("MB"))
                        {
                            nm.GigabytesTotal = int.Parse(Regex.Match(match.Value, @"\d+").Value);
                        }
                        else if (match.Value.ToUpper().Contains("GB"))
                        {
                            nm.GigabytesTotal = int.Parse(Regex.Match(match.Value, @"\d+").Value) * 1000;
                        }
                    }


                    foreach (var promo in fdata.CONTENT.PROMODETAIL.DESCRIPTIONS.DESCRIPTION.Where(x => !x.value.Contains("effettuato") && !x.value.Contains("inviato")))
                    {
                        var numbers = Regex.Matches(promo.value, @"\d+");

                        if (promo.value.ToLower().Contains("sms"))
                        {
                            nm.SMS += int.Parse(numbers[0].Value);
                            continue;
                        }
                        if (promo.value.ToLower().Contains("minuti"))
                        {
                            nm.Minutes += int.Parse(numbers[0].Value);
                            continue;
                        }
                        if (promo.value.ToLower().Contains("mb"))
                        {
                            var number = Regex.Matches(promo.value, @"\d+.").Cast<Match>().FirstOrDefault(x => x.Value.Contains("."));
                            if (number == null)
                                number = numbers[0];

                            if (nm.GigabytesTotal % 111111 == 0)
                                nm.GigabytesTotal = nm.Gigabytes = 100;
                            else
                                nm.Gigabytes = (int)((100.0f * float.Parse(number.Value)) / nm.GigabytesTotal);
                        }

                        if (nm.SMS % 111111 == 0)
                            nm.SMS = -1;

                        if (nm.Minutes % 111111 == 0)
                            nm.Minutes = -1;
                    }
                }

            if (nm.SMSTotal == 111111)
                nm.SMSTotal = nm.SMS;

            if (nm.MinutesTotal == 111111)
                nm.MinutesTotal = nm.Minutes;

            if (nm.GigabytesTotal == 111111)
                nm.GigabytesTotal = nm.Gigabytes;
            nm.LastUpdate = DateTime.Now;
            cr.NumberInfos.Add(nm);


            await httpclient.GetAsync("https://camp.tim.it/widgetCamp//logout.do"); //Logout at the end.
            return cr;
        }
Ejemplo n.º 5
0
        public async override Task<CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {
            httpclient.BaseAddress = new Uri("https://webservices.tiscali.it/unit/ecare/");
            var query = HttpUtility.ParseQueryString(string.Empty);
            query["entry"] = "login";
            query["mail"] = username;
            query["pwd"] = password;

            var res = await (await httpclient.GetAsync("it_smobile?" + query.ToString())).Content.ReadAsStreamAsync();

            var xDoc = XDocument.Load(res);

            dynamic logData = new ExpandoObject();
            XmlToDynamic.Parse(logData, xDoc.Elements().First());

            if (!(logData.authentication as IDictionary<string, object>).ContainsKey("keys"))
                throw new WrongLoginDataException("Username o password errate");

            query = HttpUtility.ParseQueryString(string.Empty);

            var _idKey = logData.authentication.keys.id;
            var _idCnum = logData.authentication.keys.cnum;

            query["entry"] = "getAllOffers3";
            query["id"] = _idKey;
            query["cnum"] = _idCnum;
            query["name"] = username;
            query["vispi"] = "tiscali";

            res.Dispose();
            res = await (await httpclient.GetAsync("it_smobile?" + query.ToString())).Content.ReadAsStreamAsync();

            xDoc = XDocument.Load(res);

            logData = new ExpandoObject();
            XmlToDynamic.Parse(logData, xDoc.Elements().First());


            res.Dispose();

            var msisdn = ((logData.result.data.offer as IDictionary<string, object>).First().Value as IDictionary<string, object>)["attr_Numeroditelefono"].ToString();

            query = HttpUtility.ParseQueryString(string.Empty);

            query["entry"] = "getSIMOptions";
            query["id"] = _idKey;
            query["cnum"] = _idCnum;
            query["name"] = username;
            query["msisdn"] = msisdn;
            query["total"] = "1";

            res = await (await httpclient.GetAsync("it_smobile?" + query.ToString())).Content.ReadAsStreamAsync();
            xDoc = XDocument.Load(res);
            res.Dispose();
            XmlToDynamic.Parse(logData, xDoc.Elements().First());


            CreditInfo cr = new CreditInfo() { Username = username, Password = password, Type = type };
            cr.NumberInfos = new System.Collections.ObjectModel.ObservableCollection<NumberInfo>();

            var ni = new NumberInfo { Number = msisdn, Credit = float.Parse(logData.result.data.CreditAmount), ExpirationDate = DateTime.ParseExact(logData.result.data.BundleList.Bundle.PeriodEndDate, new[] { "d/M/yyyy", "dd/MM/yyyy" }, CultureInfo.GetCultureInfo("it-IT"), DateTimeStyles.NoCurrentDateDefault), LastUpdate = DateTime.Now };


            foreach (dynamic bundle in logData.result.data.BundleList.Bundle.BundleElement)
            {
                switch ((string)bundle.TrafficType)
                {
                    case "SMS":
                        ni.SMS = int.Parse(bundle.AvailableAmount);
                        ni.SMSTotal = int.Parse(bundle.CatThreshold);
                        break;
                    case "VOCE":
                        ni.Minutes = int.Parse(bundle.AvailableAmount) / 60;
                        ni.MinutesTotal = int.Parse(bundle.CatThreshold) / 60;
                        break;
                    case "DATI":
                        ni.Gigabytes = (int)(100.0 / float.Parse(bundle.CatThreshold) * (float.Parse(bundle.AvailableAmount)));
                        ni.GigabytesTotal = 100;
                        break;
                    default:
                        break;
                }
            }
            cr.NumberInfos.Add(ni);

            return cr;
        }
Ejemplo n.º 6
0
        public override async System.Threading.Tasks.Task<WindDataLib.CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {
            httpclient.DefaultRequestHeaders.Clear();
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", shitAuthorization);
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "text/xml;charset=UTF-8");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("x-h3g-msisdn", "39" + username);
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Date", "Thu, 08 May 2014 20:22:42 GMT");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "NativeHost");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Referer", "file://,/Applications/Install/443D0ECE-0B8F-4D98-AD73-4304A7CAC910/Install/");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("jsessionid", "1");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("resource", "/serviceExposer/soap/selfcare/credential");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("siteid", "11");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Cache-Control", "no-cache");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "*/*");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "identity");
            var cnt = new StringContent(string.Format(H3GStrings.Login, "39" + username, password), Encoding.UTF8, "text/xml");

            cnt.Headers.Clear();
            cnt.Headers.TryAddWithoutValidation("Content-Type", "text/xml;charset=UTF-8");
            cnt.Headers.ContentType = new md(cnt.Headers.ContentType);

            var response = await httpclient.PostAsync(string.Concat(baseUrl, "api/services/credentialService"), cnt).ConfigureAwait(false);

            cnt.Dispose();

            cnt = new StringContent(string.Format(H3GStrings.InfoRapidService, "39" + username), Encoding.UTF8, "text/xml");

            cnt.Headers.Clear();
            cnt.Headers.TryAddWithoutValidation("Content-Type", "text/xml;charset=UTF-8");
            cnt.Headers.ContentType = new md(cnt.Headers.ContentType);

            response = await httpclient.PostAsync(string.Concat(baseUrl, "api/services/infoRapideService"), cnt);
            var xml = await response.Content.ReadAsStringAsync();
            var xmlDoc = XDocument.Parse(xml);

            float credit = 0;
            if (xmlDoc.Descendants().Any(x => x.Name.LocalName == "totalCreditAmount"))
                credit = float.Parse(xmlDoc.Descendants().First(x => x.Name.LocalName == "totalCreditAmount").Value, CultureInfo.GetCultureInfo("en-US"));

            var number = new NumberInfo { Number = username, LastUpdate = DateTime.Now, Credit = credit, SMS = -1, Gigabytes = -1, Minutes = -1, ExpirationDate = DateTime.MaxValue };
            var UnitsNodes = xmlDoc.XPathSelectElements("//data[key='freetUnits']");
            foreach (var node in UnitsNodes.Descendants().Where(a => a.Attributes().Any(x => x.Name.LocalName == "type" && x.Value == "ns1:FreeUnitItems")))
            {
                foreach (var el in node.Elements())
                {

                    var dataElem = el.Elements().First(x => x.Name.LocalName != "key");
                    var initial = float.Parse(dataElem.Elements().First(x => x.Name.LocalName == "initialAmount").Value, CultureInfo.GetCultureInfo("en-US"));
                    var remaining = float.Parse(dataElem.Elements().First(x => x.Name.LocalName == "remainingAmount").Value, CultureInfo.GetCultureInfo("en-US"));
                    DateTime expiration = DateTime.Parse(dataElem.Elements().First(x => x.Name.LocalName == "endDate").Value, CultureInfo.GetCultureInfo("en-US"));
                    number.ExpirationDate = (expiration > number.ExpirationDate ? number.ExpirationDate : expiration);

#if DEBUG
                    Debug.WriteLine("{0}-{1}-{2}", el.Elements().First(x => x.Name.LocalName == "key").Value, remaining, initial);
#endif

                    switch (el.Elements().First(x => x.Name.LocalName == "key").Value)
                    {
                        case "384":
                        case "501":
                        case "498":
                        case "490":
                        case "531":
                        case "535":
                        case "493":
                        case "504":
                        case "364":
                        case "507":
                            number.Gigabytes = Math.Max(number.Gigabytes,0);
                            number.Gigabytes += (int)remaining;
                            number.GigabytesTotal += initial;
                            break;

                        case "194":
                        case "500":
                        case "497":
                        case "489":
                        case "492":
                        case "503":
                        case "363":
                        case "506":
                            number.SMS = Math.Max(number.SMS, 0);
                            number.SMS += (int)remaining;
                            number.SMSTotal += (int)initial;
                            break;
                        case "193":
                        case "499":
                        case "488":
                        case "491":
                        case "502":
                        case "362":
                        case "496":
                        case "505":
                            number.Minutes = Math.Max(number.Minutes, 0);
                            number.Minutes += (int)remaining / 60;
                            number.MinutesTotal += (int)initial / 60;
                            break;

                    }
                }

            }

            if (number.GigabytesTotal == 0)
                number.GigabytesTotal = 1;
            number.Gigabytes = 100 * number.Gigabytes / (int)number.GigabytesTotal;
            number.GigabytesTotal = 100;
            number.Credit = (float)Math.Round((decimal)number.Credit, 2, MidpointRounding.AwayFromZero);

            var cr = new CreditInfo { Username = username, Password = password, Type = type, NumberInfos = new System.Collections.ObjectModel.ObservableCollection<NumberInfo>() };

            cr.NumberInfos.Add(number);
            return cr;
        }