Ejemplo n.º 1
0
        public void Merge(CreditInfo newData)
        {
            if (newData == null)
                return;

            if (NumberInfos == null)
                NumberInfos = new ObservableCollection<NumberInfo>();

            foreach (var item in newData.NumberInfos)
            {
                var it = NumberInfos.Where(n => n.Number == item.Number);

                if (!it.Any())
                    NumberInfos.Add(item);

                var nmb = it.Single();

                nmb.ExpirationDate = item.ExpirationDate;
                nmb.Minutes = item.Minutes;
                nmb.Gigabytes = item.Gigabytes;
                nmb.SMS = item.SMS;
                nmb.Credit = item.Credit;
                nmb.LastUpdate = item.LastUpdate;
            }

            //Remove what is not in the new data.
            foreach (var item in NumberInfos.Where(x => !newData.NumberInfos.Select(y => y.Number).Contains(x.Number)))
                NumberInfos.Remove(item);
        }
Ejemplo n.º 2
0
        public async override System.Threading.Tasks.Task<WindDataLib.CreditInfo> Get(string username, string password, string type, Guid dev_id)
        {

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

            httpclient.BaseAddress = new Uri("https://rest.fastweb.it/myfp-restAPI/restAPI/");
            httpclient.DefaultRequestHeaders.TryAddWithoutValidation("deviceIMEI", (new Random()).Next(int.MinValue, int.MaxValue).ToString());
            var loginResponse = await (await httpclient.PostAsJsonAsync("identity/credential/pass", new { password = password, username = username, generateToken = false })).Content.ReadAsAsync<FastwebLoginResponse>();
            if (loginResponse.errorCode != 0)
                throw new WrongLoginDataException(loginResponse.errorMessage);

            var accountSims = await (await httpclient.GetAsync("account/service/usim?accountNumber=" + loginResponse.authenticationDetails.accountNumber)).Content.ReadAsAsync<UsimList>();

            if (accountSims.errorCode != 0)
                throw new WrongLoginDataException(loginResponse.errorMessage);

            foreach (var item in accountSims.ListOfMobileNumber)
            {
                var data = await (await httpclient.GetAsync("account/service/usim/usage?accountNumber=" + HttpUtility.UrlEncode(loginResponse.authenticationDetails.accountNumber) + "&msisdn=" + HttpUtility.UrlEncode(item.msisdn) + "&queryPeriod=30")).Content.ReadAsAsync<FCreditData>();
                if (data.errorCode != 0)
                    throw new WrongLoginDataException(data.errorMessage);

                cr.NumberInfos.Add(new NumberInfo
                {
                    Number = item.msisdn,
                    ExpirationDate = data.usageServiceInfo.SelectMany(x => x.listOfPlafond).Min(x => DateTime.ParseExact(x.endDateValidity, "dd/MM/yyyy", CultureInfo.GetCultureInfo("it-IT"))),
                    LastUpdate = DateTime.Now,
                    Credit = float.Parse(data.totalConsumption.balance),
                    SMS = data.usageServiceInfo.First(x => x.serviceType.Contains("SMS")).listOfPlafond.Sum(x => int.Parse(x.residual.Split(' ')[0])),
                    SMSTotal = data.usageServiceInfo.First(x => x.serviceType.Contains("SMS")).listOfPlafond.Sum(x => int.Parse(x.total.Split(' ')[0])),
                    Gigabytes = (int)(100.0f / data.usageServiceInfo.First(x => x.serviceType.Contains("DATA")).listOfPlafond.Sum(x => (int)float.Parse(x.total.Split(' ')[0])) * data.usageServiceInfo.First(x => x.serviceType.Contains("DATA")).listOfPlafond.Sum(x => (int)float.Parse(x.residual.Split(' ')[0]))),
                    Minutes = data.usageServiceInfo.First(x => x.serviceType.Contains("VOICE")).listOfPlafond.Where(w => w.description.Contains("Fuel") == false).Sum(x => int.Parse(x.residual.Split(' ')[0])),
                    MinutesTotal = data.usageServiceInfo.First(x => x.serviceType.Contains("VOICE")).listOfPlafond.Where(w => w.description.Contains("Fuel") == false).Sum(x => int.Parse(x.total.Split(' ')[0])),
                    GigabytesTotal = 100,

                });
            }

            return cr;
        }
Ejemplo n.º 3
0
        public void Merge(CreditInfo newData)
        {
            if (newData == null)
            {
                return;
            }

            if (NumberInfos == null)
            {
                NumberInfos = new ObservableCollection <NumberInfo>();
            }

            foreach (var item in newData.NumberInfos)
            {
                var it = NumberInfos.Where(n => n.Number == item.Number);

                if (!it.Any())
                {
                    NumberInfos.Add(item);
                }

                var nmb = it.Single();

                nmb.ExpirationDate = item.ExpirationDate;
                nmb.Minutes        = item.Minutes;
                nmb.Gigabytes      = item.Gigabytes;
                nmb.SMS            = item.SMS;
                nmb.Credit         = item.Credit;
                nmb.LastUpdate     = item.LastUpdate;
            }

            //Remove what is not in the new data.
            foreach (var item in NumberInfos.Where(x => !newData.NumberInfos.Select(y => y.Number).Contains(x.Number)))
            {
                NumberInfos.Remove(item);
            }
        }
Ejemplo n.º 4
0
 public static void SaveCreditState(CreditInfo info)
 {
     using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (IsolatedStorageFileStream stream = file.OpenFile("creditData", FileMode.Create))
         {
             string s = JsonConvert.SerializeObject(info);
             byte[] buffer = ProtectedData.Protect(Encoding.UTF8.GetBytes(s), null);
             stream.Write(buffer, 0, buffer.Length);
         }
     }
 }
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;
        }