コード例 #1
0
        internal static string SearchFFU(string ProductType, string ProductCode, string OperatorCode, out string FoundProductType)
        {
            if (ProductType == "")
            {
                ProductType = null;
            }
            if (ProductCode == "")
            {
                ProductCode = null;
            }
            if (OperatorCode == "")
            {
                OperatorCode = null;
            }

            if (ProductCode != null)
            {
                ProductCode  = ProductCode.ToUpper();
                ProductType  = null;
                OperatorCode = null;
            }
            if (ProductType != null)
            {
                ProductType = ProductType.ToUpper();
                if (ProductType.StartsWith("RM") && !ProductType.StartsWith("RM-"))
                {
                    ProductType = "RM-" + ProductType.Substring(2);
                }
            }
            if (OperatorCode != null)
            {
                OperatorCode = OperatorCode.ToUpper();
            }

            DiscoveryQueryParameters DiscoveryQueryParams = new DiscoveryQueryParameters
            {
                manufacturerName            = "Microsoft",
                manufacturerProductLine     = "Lumia",
                packageType                 = "Firmware",
                packageClass                = "Public",
                manufacturerHardwareModel   = ProductType,
                manufacturerHardwareVariant = ProductCode,
                operatorName                = OperatorCode
            };
            DiscoveryParameters DiscoveryParams = new DiscoveryParameters
            {
                query = DiscoveryQueryParams
            };

            DataContractJsonSerializer Serializer1 = new DataContractJsonSerializer(typeof(DiscoveryParameters));
            MemoryStream JsonStream1 = new MemoryStream();

            Serializer1.WriteObject(JsonStream1, DiscoveryParams);
            JsonStream1.Seek(0L, SeekOrigin.Begin);
            string JsonContent = new StreamReader(JsonStream1).ReadToEnd();

            Uri RequestUri = new Uri("https://api.swrepository.com/rest-api/discovery/1/package");

            HttpClient HttpClient = new HttpClient();

            HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("SoftwareRepository");
            HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            Task <HttpResponseMessage> HttpPostTask = HttpClient.PostAsync(RequestUri, new StringContent(JsonContent, Encoding.UTF8, "application/json"));

            HttpPostTask.Wait();
            HttpResponseMessage Response = HttpPostTask.Result;

            string JsonResultString = "";

            if (Response.StatusCode == HttpStatusCode.OK)
            {
                Task <string> ReadResponseTask = Response.Content.ReadAsStringAsync();
                ReadResponseTask.Wait();
                JsonResultString = ReadResponseTask.Result;
            }

            SoftwarePackage Package = null;

            using (MemoryStream JsonStream2 = new MemoryStream(Encoding.UTF8.GetBytes(JsonResultString)))
            {
                DataContractJsonSerializer Serializer2      = new DataContractJsonSerializer(typeof(SoftwarePackages));
                SoftwarePackages           SoftwarePackages = (SoftwarePackages)Serializer2.ReadObject(JsonStream2);
                if (SoftwarePackages != null)
                {
                    Package = SoftwarePackages.softwarePackages.FirstOrDefault <SoftwarePackage>();
                }
            }

            if (Package == null)
            {
                throw new WPinternalsException("FFU not found");
            }

            FoundProductType = Package.manufacturerHardwareModel[0];

            SoftwareFile FileInfo = Package.files.Where(f => f.fileName.EndsWith(".ffu", StringComparison.OrdinalIgnoreCase)).First();

            Uri           FileInfoUri     = new Uri("https://api.swrepository.com/rest-api/discovery/fileurl/1/" + Package.id + "/" + FileInfo.fileName);
            Task <string> GetFileInfoTask = HttpClient.GetStringAsync(FileInfoUri);

            GetFileInfoTask.Wait();
            string FileInfoString = GetFileInfoTask.Result;

            string        FfuUrl  = "";
            FileUrlResult FileUrl = null;

            using (MemoryStream JsonStream3 = new MemoryStream(Encoding.UTF8.GetBytes(FileInfoString)))
            {
                DataContractJsonSerializer Serializer3 = new DataContractJsonSerializer(typeof(FileUrlResult));
                FileUrl = (FileUrlResult)Serializer3.ReadObject(JsonStream3);
                if (FileUrl != null)
                {
                    FfuUrl = FileUrl.url;
                }
            }

            HttpClient.Dispose();

            return(FfuUrl);
        }
コード例 #2
0
        internal static string SearchENOSW(string ProductType, string PhoneFirmwareRevision)
        {
            if (ProductType == "")
            {
                ProductType = null;
            }

            if (ProductType != null)
            {
                ProductType = ProductType.ToUpper();
                if (ProductType.StartsWith("RM") && !ProductType.StartsWith("RM-"))
                {
                    ProductType = "RM-" + ProductType.Substring(2);
                }
            }

            DiscoveryQueryParameters DiscoveryQueryParams = new DiscoveryQueryParameters
            {
                manufacturerName          = "Microsoft",
                manufacturerProductLine   = "Lumia",
                packageType               = "Test Mode",
                packageClass              = "Public",
                manufacturerHardwareModel = ProductType
            };
            DiscoveryParameters DiscoveryParams = new DiscoveryParameters
            {
                query = DiscoveryQueryParams
            };

            DataContractJsonSerializer Serializer1 = new DataContractJsonSerializer(typeof(DiscoveryParameters));
            MemoryStream JsonStream1 = new MemoryStream();

            Serializer1.WriteObject(JsonStream1, DiscoveryParams);
            JsonStream1.Seek(0L, SeekOrigin.Begin);
            string JsonContent = new StreamReader(JsonStream1).ReadToEnd();

            Uri RequestUri = new Uri("https://api.swrepository.com/rest-api/discovery/1/package");

            HttpClient HttpClient = new HttpClient();

            HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("SoftwareRepository");
            HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            Task <HttpResponseMessage> HttpPostTask = HttpClient.PostAsync(RequestUri, new StringContent(JsonContent, Encoding.UTF8, "application/json"));

            HttpPostTask.Wait();
            HttpResponseMessage Response = HttpPostTask.Result;

            string JsonResultString = "";

            if (Response.StatusCode == HttpStatusCode.OK)
            {
                Task <string> ReadResponseTask = Response.Content.ReadAsStringAsync();
                ReadResponseTask.Wait();
                JsonResultString = ReadResponseTask.Result;
            }

            SoftwarePackage Package = null;

            using (MemoryStream JsonStream2 = new MemoryStream(Encoding.UTF8.GetBytes(JsonResultString)))
            {
                DataContractJsonSerializer Serializer2      = new DataContractJsonSerializer(typeof(SoftwarePackages));
                SoftwarePackages           SoftwarePackages = (SoftwarePackages)Serializer2.ReadObject(JsonStream2);
                if (SoftwarePackages != null)
                {
                    foreach (SoftwarePackage pkg in SoftwarePackages.softwarePackages)
                    {
                        Package = SoftwarePackages.softwarePackages.FirstOrDefault <SoftwarePackage>();
                    }
                }
            }

            if (Package == null)
            {
                throw new WPinternalsException("ENOSW package not found", "No ENOSW package has been found in the remote software repository for the requested model.");
            }

            SoftwareFile FileInfo = Package.files.Where(f => f.fileName.EndsWith(".secwim", StringComparison.OrdinalIgnoreCase)).First();

            SoftwareFile  DPLF       = Package.files.Where(f => f.fileName.EndsWith(".dpl", StringComparison.OrdinalIgnoreCase)).First();
            Uri           DPLUri     = new Uri("https://api.swrepository.com/rest-api/discovery/fileurl/1/" + Package.id + "/" + DPLF.fileName);
            Task <string> GetDPLTask = HttpClient.GetStringAsync(DPLUri);

            GetDPLTask.Wait();
            string DPLString = GetDPLTask.Result;

            string        DPLUrl     = "";
            FileUrlResult FileUrlDPL = null;

            using (MemoryStream JsonStream3 = new MemoryStream(Encoding.UTF8.GetBytes(DPLString)))
            {
                DataContractJsonSerializer Serializer3 = new DataContractJsonSerializer(typeof(FileUrlResult));
                FileUrlDPL = (FileUrlResult)Serializer3.ReadObject(JsonStream3);
                if (FileUrlDPL != null)
                {
                    DPLUrl = FileUrlDPL.url;
                }
            }

            if (DPLUrl == "")
            {
                throw new WPinternalsException("DPL not found", "No DPL has been found in the remote software repository for the requested model.");
            }

            Task <string> GetDPLStrTask = HttpClient.GetStringAsync(DPLUrl);

            GetDPLStrTask.Wait();
            string DPLStrString = GetDPLStrTask.Result;

            DPL.Package   dpl;
            XmlSerializer serializer = new XmlSerializer(typeof(DPL.Package));

            using (StringReader reader = new StringReader(DPLStrString.Replace("ft:", "").Replace("dpl:", "").Replace("typedes:", "")))
            {
                dpl = (DPL.Package)serializer.Deserialize(reader);
            }

            foreach (DPL.File file in dpl.Content.Files.File)
            {
                string name = file.Name;

                DPL.Range range = file.Extensions.MmosWimFile.UseCaseCompatibilities.Compatibility.FirstOrDefault().Range;

                if (IsFirmwareBetween(PhoneFirmwareRevision, range.From, range.To))
                {
                    FileInfo = Package.files.Where(f => f.fileName.EndsWith(name, StringComparison.OrdinalIgnoreCase)).First();
                }
            }

            Uri           FileInfoUri     = new Uri("https://api.swrepository.com/rest-api/discovery/fileurl/1/" + Package.id + "/" + FileInfo.fileName);
            Task <string> GetFileInfoTask = HttpClient.GetStringAsync(FileInfoUri);

            GetFileInfoTask.Wait();
            string FileInfoString = GetFileInfoTask.Result;

            string        ENOSWUrl = "";
            FileUrlResult FileUrl  = null;

            using (MemoryStream JsonStream3 = new MemoryStream(Encoding.UTF8.GetBytes(FileInfoString)))
            {
                DataContractJsonSerializer Serializer3 = new DataContractJsonSerializer(typeof(FileUrlResult));
                FileUrl = (FileUrlResult)Serializer3.ReadObject(JsonStream3);
                if (FileUrl != null)
                {
                    ENOSWUrl = FileUrl.url;
                }
            }

            HttpClient.Dispose();

            return(ENOSWUrl);
        }