public VersionDetail UpdateVersionDetail(VersionDetail detail) { if (detail != null) { dbContext.Versions.Attach(detail.Version); if (detail.Id == Guid.Empty) { detail.Id = Guid.NewGuid(); dbContext.Details.Add(detail); } else { if (dbContext.Details.Any(d => d.Id == detail.Id)) { dbContext.Entry(detail).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } else { return(null); } } dbContext.SaveChanges(); return(detail); } return(null); }
private void button7_Click(object sender, EventArgs e) { VersionDetail vd = new VersionDetail { IsValid = "0", VersionType = "1", oldversion = "", version = "", description = "新版本", createTime = "", Name = "新升级包", BG = "0", sg = "0", v = "0", f = "0", SortId = 999 }; VDIList.Add(vd); string s = dataGridView1.CurrentRow.Cells[0].Value.ToString();//获取当前行[0]字段的值 HMIList.Where(m => m.VersionName == s).FirstOrDefault().VersionDetail = VDIList; dataGridView1.DataSource = HMIList.ToList(); }
public VersionDetail IncrementVersion(IVersionRequest request) { var versions = GetVersions(request); var versionList = versions.OrderBy(x => new Version(x.Version.Major, x.Version.Minor)).Reverse(); VersionSimple version = null; if (versionList.Count() == 0) { version.CreateIncrement(request); } else { version = versionList.First().Version; version.CalculateIncrement(request); } var versionDetail = new VersionDetail { Version = version, CreatedDate = DateTime.Now, Product = new Product { Id = request.ProductId } }; var created = _repository.Add(versionDetail); return(created); }
public void GenerateTestDataSet() { string path = Path.Combine(Path.GetTempPath(), s_TxtFileName); using (var txtFile = File.CreateText(path)) { foreach (TestCaseData testCase in TestCasesFromReferenceImplementation) { for (int index = 0; index < 3; index++) { if (index == 1) { VersionDetail vc = (VersionDetail)testCase.Arguments[index]; txtFile.WriteLine(vc.ToString()); } else { IEnumerable <bool> ienumBool = (IEnumerable <bool>)testCase.Arguments[index]; txtFile.WriteLine(ienumBool.To01String()); } } } txtFile.Close(); } }
private void TestOneCase(IEnumerable<bool> dataCodewords, VersionDetail vc, IEnumerable<bool> expected) { BitList dcList = new BitList(); dcList.Add(dataCodewords); IEnumerable<bool> actualResult = ECGenerator.FillECCodewords(dcList, vc); BitVectorTestExtensions.CompareIEnumerable(actualResult, expected, "string"); }
private TestCaseData GenerateRandomTestCaseData(int version, MaskPatternType patternType) { int matrixSize = VersionDetail.Width(version); ByteMatrix matrix = new ByteMatrix(matrixSize, matrixSize); EmbedAlignmentPattern(matrix, version, patternType); return(new TestCaseData(version, patternType, matrix.ToBitMatrix()).SetName(string.Format(s_TestNameFormat, matrixSize, version))); }
private TestCaseData GenerateRandomTestCaseData(int version, int totalCodewords, Random randomizer) { int matrixSize = VersionDetail.Width(version); ByteMatrix matrix = new ByteMatrix(matrixSize, matrixSize); BitVector codewords = GenerateDataCodewords(totalCodewords, randomizer); EmbedAlignmentPattern(matrix, version, codewords); return(new TestCaseData(version, matrix.ToBitMatrix(), codewords).SetName(string.Format(s_TestNameFormat, matrixSize, version))); }
private void TestOneCase(IEnumerable <bool> dataCodewords, VersionDetail vc, IEnumerable <bool> expected) { BitList dcList = new BitList(); dcList.Add(dataCodewords); IEnumerable <bool> actualResult = ECGenerator.FillECCodewords(dcList, vc); BitVectorTestExtensions.CompareIEnumerable(actualResult, expected, "string"); }
/// <summary> /// Minecraftを起動します。 /// </summary> /// <param name="detail">起動するバージョンの詳細</param> /// <param name="credentials">アカウントのトークン</param> /// <param name="java">Javaの場所</param> /// <param name="classpath">追加するクラスパスのリスト</param> /// <param name="waitForExit">終了を待つかどうか</param> /// <param name="onOutput">標準出力に書き込まれた時のイベントハンドラ</param> public static void Launch(this VersionDetail detail, Credentials credentials, string java, IEnumerable <string> classpath, bool waitForExit = true, DataReceivedEventHandler onOutput = null) { var arguments = new[] { "-Djava.library.path=natives", "-cp " + string.Join(";", classpath), detail.MainClass, detail.MinecraftArguments .Replace("${version_name}", detail.Id) .Replace("${game_directory}", "game") .Replace("${assets_root}", "assets") .Replace("${assets_index_name}", detail.AssetsId) .Replace("${auth_access_token}", credentials.AccessToken) .Replace("${auth_uuid}", credentials.SelectedProfile.Id) .Replace("${auth_player_name}", credentials.SelectedProfile.Name) .Replace("${user_type}", "mojang") .Replace("${version_type}", detail.Type.ToString().ToLower()) .Replace("${user_properties}", "{}") }; var process = new Process { StartInfo = new ProcessStartInfo { FileName = java, Arguments = string.Join(" ", arguments), CreateNoWindow = true, UseShellExecute = false, } }; if (onOutput != null) { process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.OutputDataReceived += onOutput; process.ErrorDataReceived += onOutput; } process.Start(); if (onOutput != null) { process.BeginOutputReadLine(); process.BeginErrorReadLine(); } if (waitForExit) { process.WaitForExit(); } }
public void ShowVersion() { List <VersionDetail> VersionDetailList = new List <VersionDetail>(); String[] s = ClientViewMode.VersionDetail.Split(','); foreach (string s1 in s) { VersionDetail versionDetail = new VersionDetail(); versionDetail.VersionDetailItem = s1; VersionDetailList.Add(versionDetail); } VersionList.ItemsSource = VersionDetailList; }
public void DeleteVersionDetail(Guid detailId) { if (detailId != Guid.Empty) { var detail = new VersionDetail() { Id = detailId }; dbContext.Details.Attach(detail); dbContext.Details.Remove(detail); dbContext.SaveChanges(); } }
/// <summary> /// バージョンの詳細からクライアントをダウンロードします。 /// </summary> /// <param name="detail">クライアントをダウンロードするバージョンの詳細</param> /// <param name="versionsDirectory">バージョンディレクトリの場所</param> /// <returns>ダウンロードしたクライアントの場所</returns> public static string DownloadClient(this VersionDetail detail, string versionsDirectory) { var location = detail.Downloads[DownloadType.Client]; var directory = $"{versionsDirectory}/{detail.Id}"; var file = $"{directory}/{detail.Id}.jar"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (!File.Exists(file)) { DownloadFile(location.Url, file); } return(file); }
/// <summary> /// サーバからアセットのリストを取得します。 /// </summary> /// <param name="detail">アセットを取得するバージョンの詳細</param> /// <param name="assetsDirectory">アセットディレクトリの場所(リストを保存する場合)</param> /// <returns>アセットのリスト</returns> public static AssetIndex GetAssetIndex(this VersionDetail detail, string assetsDirectory = null) { var json = Get(detail.AssetIndex.Url); if (assetsDirectory != null) { var directory = assetsDirectory + "/indexes"; var file = $"{directory}/{detail.AssetsId}.json"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllText(file, json); } return(json.ToObject <AssetIndex>()); }
public VersionDetail Add(VersionDetail versionDetail) { var connectionString = @"MyData.db"; // Open database (or create if doesn't exist) using (var client = new LiteDatabase(connectionString)) { var collection = client.GetCollection <VersionDetail>("version_detail"); // Create unique index in Name field collection.EnsureIndex(x => x.Id, true); // Insert new customer document (Id will be auto-incremented) var versionDetailId = collection.Insert(versionDetail); return(collection.FindById(versionDetailId)); } }
public void AddItemToVersion() { var versionDetail = new VersionRequest() { ProductId = 1, Major = 8, Minor = 2 }; var addResult = new VersionDetail { Id = 1, Version = new VersionSimple { Major = 8, Minor = 2, Build = 101, Revision = 0 }, CreatedDate = DateTime.Now }; var repository = new Mock <IVersionDetailRepository>(); repository.Setup(x => x.GetByProductId(versionDetail.ProductId)) .Returns(VersionDetails .Where(x => x.Product.Id == versionDetail.ProductId && x.Version.Major == versionDetail.Major)); repository.Setup(x => x.Add(It.IsAny <VersionDetail>())) .Returns(addResult); var service = new VersionService(repository.Object); var version = service.IncrementVersion(versionDetail); var expectedVersion = new VersionSimple(8, 2, 101, 0); version.Version.Major.Should().Be(expectedVersion.Major); version.Version.Minor.Should().Be(expectedVersion.Minor); version.Version.Build.Should().Be(expectedVersion.Build); version.Version.Revision.Should().Be(expectedVersion.Revision); }
public static VersionDetailDto ConvertToDetailDto(VersionDetail detail) { if (detail != null) { return(new VersionDetailDto() { Id = detail.Id, Applicant = detail.Applicant, CommitIds = detail.CommitIds, DetailNote = detail.DetailNote, Iteration = detail.Iteration, TaskTitle = detail.TaskTitle, Type = detail.Type, VersionId = detail.Version.Id }); } return(null); }
public Tuple <string, long, float, string, string>[] GetTorrentSeedDetail(string sContentUniqueId, string sContentHashCode) { JobDetail oJob = quartzScheduler.GetJobDetail(sContentUniqueId, ContentMonitorConstants.ContentMonitorGroupName); List <Tuple <string, long, float, string, string> > listTorrentSeed = new List <Tuple <string, long, float, string, string> >(); if (oJob != null) { try { string sContentDetailJson = (string)oJob.JobDataMap[ContentMonitorJobDataMapConstants.ContentDetail]; if (sContentDetailJson != null) { ContentDetail oContent = JsonConvert.DeserializeObject <ContentDetail>(sContentDetailJson); if (oContent.Versions.Count > 0) { VersionDetail oVer = oContent.Versions.Find(x => { return(x.Hash == sContentHashCode); }); if (oVer != null) { foreach (TorrentSeedDetail oTSD in oVer.TorrentSeeds) { listTorrentSeed.Add( new Tuple <string, long, float, string, string>( oTSD.IP, oTSD.TotalSize, (float)Math.Round(oTSD.PartDone, 3), oTSD.StatusCode.ToString(), oTSD.Error)); } } } } } catch (Exception oEx) { throw new ApplicationException(string.Format(AppResource.ContentDetailReadFailed, oEx.Message), oEx); } } return(listTorrentSeed.ToArray()); }
private static VersionControlStruct FillVCStruct(int versionNum, ErrorCorrectionLevel level) { if (versionNum < 1 || versionNum > 40) { throw new InvalidOperationException($"Unexpected version number: {versionNum}"); } VersionControlStruct vcStruct = new VersionControlStruct(); int version = versionNum; QRCodeVersion versionData = VersionTable.GetVersionByNum(versionNum); int numTotalBytes = versionData.TotalCodewords; ErrorCorrectionBlocks ecBlocks = versionData.GetECBlocksByLevel(level); int numDataBytes = numTotalBytes - ecBlocks.NumErrorCorrectionCodewards; int numECBlocks = ecBlocks.NumBlocks; VersionDetail vcDetail = new VersionDetail(version, numTotalBytes, numDataBytes, numECBlocks); vcStruct.VersionDetail = vcDetail; return(vcStruct); }
private static VersionControlStruct FillVCStruct(int versionNum, ErrorCorrectionLevel level, string encodingName) { if(versionNum < 1 || versionNum > 40) { throw new InvalidOperationException(string.Format("Unexpected version number: {0}", versionNum)); } VersionControlStruct vcStruct = new VersionControlStruct(); int version = versionNum; QRCodeVersion versionData = VersionTable.GetVersionByNum(versionNum); int numTotalBytes = versionData.TotalCodewords; ErrorCorrectionBlocks ecBlocks = versionData.GetECBlocksByLevel(level); int numDataBytes = numTotalBytes - ecBlocks.NumErrorCorrectionCodewards; int numECBlocks = ecBlocks.NumBlocks; VersionDetail vcDetail = new VersionDetail(version, numTotalBytes, numDataBytes, numECBlocks); vcStruct.VersionDetail = vcDetail; return vcStruct; }
private static string ProcessContentMonitor(List <string> listVersion, JobExecutionContext context) { JobDataMap oJobDataMap = context.JobDetail.JobDataMap; string[] listSeedWebIP = AppConfig.ContentDeployJob.OfficalSeedWebIPList; ContentDetail oContentDetail = new ContentDetail(); // Construct the hierarchy per the Version list & registered Seed Web IP list first oContentDetail.Name = context.JobDetail.Name; oContentDetail.DateCreated = GetContentCreateDate(context.JobDetail.Name); foreach (string sVer in listVersion) { VersionDetail oVerDetail = new VersionDetail(); ContentGenRecipes oContentRecipes = GetContentRecipes(oContentDetail.Name, sVer); if (oContentRecipes != null) { oVerDetail.Name = oContentRecipes.ContentFileName; oVerDetail.DateCreated = oContentRecipes.CreateDateTime; } else { oVerDetail.Name = ""; oVerDetail.DateCreated = DateTime.MaxValue; } oVerDetail.Hash = sVer; oVerDetail.DeployToTracker = QueryTrackerTorrentDeploymentStatus(sVer); oContentDetail.Versions.Add(oVerDetail); foreach (string sIP in listSeedWebIP) { TorrentSeedDetail oDetail = new TorrentSeedDetail(); // Create the TorrentSeedDetail first with the unknown status // And replace the unkown status with the real status parsed from JSON later oDetail.IP = sIP; oDetail.Hash = oVerDetail.Hash.ToUpper(); oDetail.Name = ""; oDetail.TotalSize = 0; oDetail.PartDone = 0f; oDetail.StatusCode = TorrentStatus.Unknown; oDetail.DatePublished = DateTime.MaxValue; oDetail.Error = AppResource.SeedWebConnectionFailed; oVerDetail.TorrentSeeds.Add(oDetail); } } // Enumerate all the registered seed web IP for walking through all the seed monitors foreach (string sIP in listSeedWebIP) { JobDetail oSeedJob = context.Scheduler.GetJobDetail( sIP, SeedMonitorConstants.SeedMonitorGroupName); // Check to see if the seed monitor job exists if (oSeedJob != null) { string sTorrentDetails = (string)oSeedJob.JobDataMap[SeedMonitorJobDataMapConstants.TorrentDetails]; // Check to see if the seed monitor has torrent detail JSON ready if (sTorrentDetails != null) { List <TorrentDetail> listTorrentDetail = JsonConvert.DeserializeObject <List <TorrentDetail> >(sTorrentDetails); List <string> listTorrentInSeed = new List <string>(); // Enumerate all the TorrentDetail to update to the pre-created TorrentSeedDetail foreach (TorrentDetail oTorrentDetail in listTorrentDetail) { TorrentSeedDetail oDetail = new TorrentSeedDetail(); oDetail.IP = sIP; oDetail.Hash = oTorrentDetail.UniqueID.ToUpper(); oDetail.Name = oTorrentDetail.Name; oDetail.TotalSize = oTorrentDetail.TotalSize; oDetail.PartDone = oTorrentDetail.PartDone; oDetail.StatusCode = oTorrentDetail.StatusCode; oDetail.DatePublished = oTorrentDetail.DateAdded; oDetail.Error = oTorrentDetail.Error; // Use the TorrentSeedDetail object to update the corresponding list // in the VersionDetails list so the JSON just needs to be parsed just once UpdateTorrentSeedDetail(oContentDetail, oDetail); // Add the torrent hash for later use of checking the exclusion of the torrents listTorrentInSeed.Add(oDetail.Hash); } // Update TorrentSeedDetail not found in the seed's torrent list to "content not deployed" error foreach (VersionDetail oVersion in oContentDetail.Versions.FindAll (x => { return(!listTorrentInSeed.Contains(x.Hash)); })) { TorrentSeedDetail oTorrentSeed = oVersion.TorrentSeeds.Find(x => { return(x.IP == sIP); }); if (oTorrentSeed != null) { oTorrentSeed.Error = AppResource.ContentNotDeployToSeed; } } } } } // Serialize the content detail to JSON and return return(JsonConvert.SerializeObject(oContentDetail)); }
/// <summary> /// Generate error correction blocks. Then out put with codewords BitList /// ISO/IEC 18004/2006 P45, 46. Chapter 6.6 Constructing final message codewords sequence. /// </summary> /// <param name="dataCodewords">Datacodewords from DataEncodation.DataEncode</param> /// <param name="numTotalBytes">Total number of bytes</param> /// <param name="numDataBytes">Number of data bytes</param> /// <param name="numECBlocks">Number of Error Correction blocks</param> /// <returns>codewords BitList contain datacodewords and ECCodewords</returns> internal static BitList FillECCodewords(BitList dataCodewords, VersionDetail vd) { List <byte> dataCodewordsByte = dataCodewords.List; int ecBlockGroup2 = vd.ECBlockGroup2; int ecBlockGroup1 = vd.ECBlockGroup1; int numDataBytesGroup1 = vd.NumDataBytesGroup1; int numDataBytesGroup2 = vd.NumDataBytesGroup2; int ecBytesPerBlock = vd.NumECBytesPerBlock; int dataBytesOffset = 0; byte[][] dByteJArray = new byte[vd.NumECBlocks][]; byte[][] ecByteJArray = new byte[vd.NumECBlocks][]; GaloisField256 gf256 = GaloisField256.QRCodeGaloisField; GeneratorPolynomial generator = new GeneratorPolynomial(gf256); for (int blockID = 0; blockID < vd.NumECBlocks; blockID++) { if (blockID < ecBlockGroup1) { dByteJArray[blockID] = new byte[numDataBytesGroup1]; for (int index = 0; index < numDataBytesGroup1; index++) { dByteJArray[blockID][index] = dataCodewordsByte[dataBytesOffset + index]; } dataBytesOffset += numDataBytesGroup1; } else { dByteJArray[blockID] = new byte[numDataBytesGroup2]; for (int index = 0; index < numDataBytesGroup2; index++) { dByteJArray[blockID][index] = dataCodewordsByte[dataBytesOffset + index]; } dataBytesOffset += numDataBytesGroup2; } ecByteJArray[blockID] = ReedSolomonEncoder.Encode(dByteJArray[blockID], ecBytesPerBlock, generator); } if (vd.NumDataBytes != dataBytesOffset) { throw new ArgumentException("Data bytes does not match offset"); } BitList codewords = new BitList(); int maxDataLength = ecBlockGroup1 == vd.NumECBlocks ? numDataBytesGroup1 : numDataBytesGroup2; for (int dataID = 0; dataID < maxDataLength; dataID++) { for (int blockID = 0; blockID < vd.NumECBlocks; blockID++) { if (!(dataID == numDataBytesGroup1 && blockID < ecBlockGroup1)) { codewords.Add((int)dByteJArray[blockID][dataID], 8); } } } for (int ECID = 0; ECID < ecBytesPerBlock; ECID++) { for (int blockID = 0; blockID < vd.NumECBlocks; blockID++) { codewords.Add((int)ecByteJArray[blockID][ECID], 8); } } if (vd.NumTotalBytes != codewords.Count >> 3) { throw new ArgumentException(string.Format("total bytes: {0}, actual bits: {1}", vd.NumTotalBytes, codewords.Count)); } return(codewords); }
/// <summary> /// バージョンの詳細からライブラリをダウンロードします。 /// </summary> /// <param name="detail">ライブラリをダウンロードするバージョンの詳細</param> /// <param name="librariesDirectory">ライブラリディレクトリの場所</param> /// <param name="onProgressChanged">進捗状況が変化したときのイベントハンドラ</param> /// <returns>クラスパスなどを含むダウンロードの結果</returns> public static LibrariesDownloadResult DownloadLibraries(this VersionDetail detail, string librariesDirectory, MinecraftProgressEventHandler onProgressChanged = null) { var classpath = new List <string>(); var extracts = new Dictionary <string, ExtractRule>(); var libraries = detail.Libraries; for (var i = 0; i < libraries.Length; i++) { var library = libraries[i]; onProgressChanged?.Invoke( new MinecraftProgressEventArgs( libraries.Length, i + 1, library.Name ) ); var location = library.Downloads.Artifact; if (location != null) { classpath.Add(location.DownloadLibrary(librariesDirectory)); } var rules = library.NativeRules; if (rules != null) { if (rules.ContainsWhere(r => r.Action == NativeRuleAction.Disallow) && rules.Where(r => r.Action == NativeRuleAction.Disallow) .ContainsWhere(r => r.OS.Type == NativeOSType.Windows)) { continue; } if (!rules.ContainsWhere(r => r.Action == NativeRuleAction.Disallow) && !rules.Where(r => r.Action == NativeRuleAction.Allow) .ContainsWhere(r => r.OS.Type == NativeOSType.Windows)) { continue; } } if (library.Natives == null || !library.Natives.ContainsKey(NativeOSType.Windows)) { continue; } var arch = Environment.Is64BitOperatingSystem ? "64" : "32"; var nativeName = library.Natives[NativeOSType.Windows].Replace("${arch}", arch); var classifier = library.Downloads.Classifiers[nativeName]; extracts.Add(classifier.DownloadLibrary(librariesDirectory), library.ExtractRule); } return(new LibrariesDownloadResult { Classpath = classpath, Extracts = extracts }); }
/// <summary> /// Generate error correction blocks. Then out put with codewords BitList /// ISO/IEC 18004/2006 P45, 46. Chapter 6.6 Constructing final message codewords sequence. /// </summary> /// <param name="dataCodewords">Datacodewords from DataEncodation.DataEncode</param> /// <param name="vd">The vd.</param> /// <returns>codewords BitList contain datacodewords and ECCodewords</returns> /// <remarks></remarks> internal static BitList FillECCodewords(BitList dataCodewords, VersionDetail vd) { List<byte> dataCodewordsByte = dataCodewords.List; int ecBlockGroup2 = vd.ECBlockGroup2; int ecBlockGroup1 = vd.ECBlockGroup1; int numDataBytesGroup1 = vd.NumDataBytesGroup1; int numDataBytesGroup2 = vd.NumDataBytesGroup2; int ecBytesPerBlock = vd.NumECBytesPerBlock; int dataBytesOffset = 0; var dByteJArray = new byte[vd.NumECBlocks][]; var ecByteJArray = new byte[vd.NumECBlocks][]; GaloisField256 gf256 = GaloisField256.QRCodeGaloisField; var generator = new GeneratorPolynomial(gf256); for (int blockID = 0; blockID < vd.NumECBlocks; blockID++) { if (blockID < ecBlockGroup1) { dByteJArray[blockID] = new byte[numDataBytesGroup1]; for (int index = 0; index < numDataBytesGroup1; index++) { dByteJArray[blockID][index] = dataCodewordsByte[dataBytesOffset + index]; } dataBytesOffset += numDataBytesGroup1; } else { dByteJArray[blockID] = new byte[numDataBytesGroup2]; for (int index = 0; index < numDataBytesGroup2; index++) { dByteJArray[blockID][index] = dataCodewordsByte[dataBytesOffset + index]; } dataBytesOffset += numDataBytesGroup2; } ecByteJArray[blockID] = ReedSolomonEncoder.Encode(dByteJArray[blockID], ecBytesPerBlock, generator); } if (vd.NumDataBytes != dataBytesOffset) throw new ArgumentException("Data bytes does not match offset"); var codewords = new BitList(); int maxDataLength = ecBlockGroup1 == vd.NumECBlocks ? numDataBytesGroup1 : numDataBytesGroup2; for (int dataID = 0; dataID < maxDataLength; dataID++) { for (int blockID = 0; blockID < vd.NumECBlocks; blockID++) { if (!(dataID == numDataBytesGroup1 && blockID < ecBlockGroup1)) codewords.Add(dByteJArray[blockID][dataID], 8); } } for (int ECID = 0; ECID < ecBytesPerBlock; ECID++) { for (int blockID = 0; blockID < vd.NumECBlocks; blockID++) { codewords.Add(ecByteJArray[blockID][ECID], 8); } } if (vd.NumTotalBytes != codewords.Count >> 3) throw new ArgumentException(string.Format("total bytes: {0}, actual bits: {1}", vd.NumTotalBytes, codewords.Count)); return codewords; }
public void Test_against_TXT_Dataset(IEnumerable <bool> dataCodewords, VersionDetail vc, IEnumerable <bool> expected) { TestOneCase(dataCodewords, vc, expected); }
public void Test_against_reference_implementation(IEnumerable <bool> dataCodewords, VersionDetail vc, IEnumerable <bool> expected) { TestOneCase(dataCodewords, vc, expected); }
private void Go() { int isconn = 0; //定义会话,每一个请求都将封装成一个会话 List <Fiddler.Session> oAllSessions = new List <Fiddler.Session>(); Fiddler.FiddlerApplication.BeforeRequest += delegate(Fiddler.Session oS) { oS.bBufferResponse = true; Monitor.Enter(oAllSessions); if (oS.fullUrl.IndexOf("hicloud.com") > -1) { if (oS.fullUrl.IndexOf("servicesupport/updateserver/getConfig") > -1) { hwconfig = oS.GetRequestBodyAsString(); //AddTXT(hwconfig); } if (oS.fullUrl.IndexOf("http://update.hicloud.com") > -1 && oS.fullUrl.IndexOf("TDS/data/files") > -1 && oS.fullUrl.IndexOf(".zip") > -1) { oS.bBufferResponse = false; AddTXT("正在下载..."); //Fiddler.FiddlerApplication.Shutdown(); //return; } if ((oS.fullUrl.IndexOf("hicloud.com") > -1 && oS.fullUrl.IndexOf("Check.action") > -1) || (oS.fullUrl.IndexOf("http://update.hicloud.com:8180/TDS/data/files") > -1 && oS.fullUrl.IndexOf(".zip") == -1)) { IOHelper.CreateFile("Log.txt"); //if (isconn == 1) //{ // oS.utilSetRequestBody(oS.GetRequestBodyAsString().Replace("B321", "B168")); //} IOHelper.WriteLine("Log.txt", "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][请求] " /*+ oS.fullUrl*/ + "\n\r" + oS.GetRequestBodyAsString()); } } oAllSessions.Add(oS); Monitor.Exit(oAllSessions); oS["X-AutoAuth"] = "(default)"; }; Fiddler.FiddlerApplication.BeforeResponse += delegate(Fiddler.Session oS) { if (isconn == 0) { isconn++; AddTXT("成功链接代理"); } string resstr = ""; oS.utilDecodeResponse(); if ((oS.fullUrl.IndexOf("hicloud.com") > -1 && oS.fullUrl.IndexOf("Check.action") > -1) || (oS.fullUrl.IndexOf("http://update.hicloud.com:8180/TDS/data/files") > -1 && oS.fullUrl.IndexOf(".zip") == -1)) { //if (iscm < 1 && string.IsNullOrEmpty(hwconfig)) //{ // AddTXT("串码获取失败,请重新获取更新(多点获取版本" + (3 - iscm).ToString() + "次,别问)~"); // iscm++; // return; //} //else //{ // iscm = 3; //} resstr = oS.GetResponseBodyAsString(); IOHelper.CreateFile("Log.txt"); IOHelper.WriteLine("Log.txt", "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][返回] " /* + oS.fullUrl */ + "\n\r" + resstr); } if (oS.fullUrl.IndexOf("http://query.hicloud.com:80/sp_ard_common/v2/Check.action") > -1 || oS.fullUrl.IndexOf("http://query.hicloud.com/sp_ard_common/v2/Check.action") > -1 || oS.fullUrl.IndexOf("http://query.hicloud.com/sp_ard_common/UrlCommand/CheckNewVersion.aspx") > -1) { string ipc = oS.clientIP.Replace("::ffff:", ""); if (!IsLAN(ipc) && roles == 2) { AddTXT("您无外网远程推送权限~"); return; //myqqinfo.role } //http://update.hicloud.com:8180/TDS/data/files/p3/s15/G962/g77/v48270/f2/full/update.zip AddTXT("0%"); if (oS.fullUrl.IndexOf("http://query.hicloud.com:80/sp_ard_common/v2/Check.action") > -1) { ctype = 1; if (isconn == 0) { AddTXT("正在使用WIFI代理获取升级版本"); } } else if (oS.fullUrl.IndexOf("http://query.hicloud.com/sp_ard_common/UrlCommand/CheckNewVersion.aspx") > -1) { ctype = 2; if (isconn == 0) { AddTXT("正在使用华为手机助手获取升级版本(新)"); } } else if (oS.fullUrl.IndexOf("http://query.hicloud.com/sp_ard_common/v2/Check.action") > -1) { ctype = 3; if (isconn == 0) { AddTXT("正在使用华为手机助手获取升级版本"); } } else { AddTXT("路径异常"); } if (isconn == 1) { isconn++; } try { string reqstr = oS.GetRequestBodyAsString(); Mate8RequestBody rules = new Mate8RequestBody(); if (ctype == 2) { IOHelper.CreateFile("Log.txt"); IOHelper.WriteLine("Log.txt", "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][请求XML] " /*+ oS.fullUrl*/ + "\n\r" + reqstr); rules = PublicClass.GetRulesByXml(reqstr); } else //if (1 == 1) { rules = JsonConvert.DeserializeObject <Mate8RequestBody>(reqstr); } AddTXT("5%"); if (rules.rules == null) { AddTXT("无法获取您的版本,请关闭软件并重新打开"); return; } var DeviceName = rules.rules.DeviceName; var C_version = rules.rules.C_version; var FirmWare = rules.rules.FirmWare; if (rules.rules.OS == "Android 7.0") { AddTXT("本软件不支持" + rules.rules.OS + "系统使用,请下载最新包使用三键刷机!"); return; } if (Vtype == "1" && (rules.rules.PackageType != "patch" || rules.rules.PackageType != "increment")) { return; } //if (Vtype == "2" && rules.rules.PackageType != "patch") //{ return; } if (ctype == 3) { if (Vtype == "3" && rules.rules.PackageType != "full_back") { return; } } else { if (Vtype == "3" && rules.rules.PackageType != "full") { return; } if (Vtype == "3") { AddTXT("不建议使用WIFI代理降级"); } } if (Vtype == "4" && rules.rules.PackageType != "full") { AddTXT("完整包请在手机上使用[系统更新-高级-下载最新完整包]"); return; } var FirmWareEMUI = ""; int isjk = 0; try { AddTXT("6%"); FirmWareEMUI = rules.rules.FirmWare.Split('_')[0]; if (FirmWareEMUI.IndexOf("EMUI") > -1) { DeviceName = FirmWareEMUI + "_" + DeviceName; isjk++; } } catch { AddTXT("7%"); } if (isconn == 2) { AddTXT("您的手机型号为:" + DeviceName); } isconn++; AddTXT("10%"); AddTXT("正在自动适配版本库"); // HMISelect = LHMISelect.Where(m => m.PhoneModel.Replace(" ", "") == DeviceName.Replace(" ", "")).FirstOrDefault();//自动选择版本库 var HMISelect = LHMISelect.Where(m => DeviceName.Replace(" ", "").StartsWith(m.PhoneModel.Replace(" ", ""))).FirstOrDefault(); if (HMISelect == null) { AddTXT("15%"); var HMIAll = LHMI.Where(m => DeviceName.Replace(" ", "").StartsWith(m.PhoneModel.Replace(" ", ""))).FirstOrDefault(); if (HMIAll == null) { AddTXT("16%"); AddTXT("找不到对应的型号,请联系管理员"); AddTXT("100%"); return; } else { AddTXT("17%"); if (checkBox3.Checked) { this.BeginInvoke((MethodInvoker) delegate { listBox2.SelectedItem = HMIAll.VersionName; }); Thread.Sleep(100); var NewLHMISelect = LHMISelect.Where(m => DeviceName.Replace(" ", "").StartsWith(m.PhoneModel.Replace(" ", ""))).FirstOrDefault();//自动选择版本库 AddTXT("自动切换正确的版本库"); HMISelect = NewLHMISelect; AddTXT("切换成功"); } else if (!checkBox3.Checked) { AddTXT("请勾选自动切换版本"); } } } //Mate8Model Mate8Model = Mate8List.Mate8Model.Where(m => m.ModelName == DeviceName).FirstOrDefault(); //MyVersion = Mate8Model; AddTXT("18%"); string mobilemodel = ""; if (HMISelect.MobileModel != null) { AddTXT("19%"); MobileModel mm = HMISelect.MobileModel.Where(x => (DeviceName.Replace(" ", "") + ((isjk > 0) ? "" : C_version.Replace(" ", ""))).EndsWith(x.PhoneModel)).FirstOrDefault(); if (mm != null) { AddTXT("20%"); mobilemodel = mm.PhoneModel; } } AddTXT("21%"); var VD = HMISelect.VersionDetail; AddTXT("22%"); VersionDetail VDSelect = null; if (Vtype == "3" || Vtype == "4") { AddTXT("25%"); //if (FullIsGo == 0) //{ //FullIsGo++; VDSelect = VD.Where(m => m.Name.Replace(" ", "") == SelectedVersionName.Replace(" ", "")).FirstOrDefault(); //} //else //{ //AddTXT("74%"); //} AddTXT("26%"); } else { AddTXT("27%"); List <string> li = new List <string>(); //手动选择 if (checkBox1.Checked) { AddTXT("28%"); li = listBox1.SelectedItems.Cast <string>().ToList(); } if (li.Count > 0) { AddTXT("29%"); VDSelect = VD.Where(m => li.Contains(m.Name.Replace(" ", "")) && (mobilemodel + ((isjk > 0) ? "_" : "") + m.oldversion.Replace(" ", "")).Replace("__", "_") == rules.rules.FirmWare.Replace(" ", "")).FirstOrDefault(); AddTXT("30%"); } else { AddTXT("31%"); VDSelect = VD.Where(m => (mobilemodel + ((isjk > 0) ? "_" : "") + m.oldversion.Replace(" ", "")).Replace("__", "_") == rules.rules.FirmWare.Replace(" ", "")).FirstOrDefault(); AddTXT("32%"); } AddTXT("33%"); } AddTXT("40%"); if (VDSelect != null) { //try //{ // if (int.Parse(listBox1.SelectedItem.ToString().Remove(0, 1)) <= int.Parse(mus.version.Remove(0, 1))) // { // AddTXT("100%"); // AddTXT("您的版本为:" + rules.rules.FirmWare + ",请重新选择版本,本软件暂时不提供降级服务!"); // return; // } //} //catch (Exception ee) //{ // AddTXT("100%"); // AddTXT("出错了,原因如下:" + ee.Message); // return; //} AddTXT("50%"); AddTXT("您手机的版本为:" + rules.rules.FirmWare); AddTXT("您找到的版本为:" + mobilemodel + VDSelect.version); AddTXT("51%"); List <VersionInfo> lvif = new List <VersionInfo>(); AddTXT("52%"); AddTXT("开始加载升级数据"); VersionInfo vif = new VersionInfo { name = "[官方]" + mobilemodel + VDSelect.version, version = mobilemodel + VDSelect.version, versionID = VDSelect.v, description = VDSelect.description, createTime = VDSelect.createTime, url = "http://update.hicloud.com:8180/TDS/data/files/p3/s15/G" + VDSelect.BG + "/g" + VDSelect.sg + "/v" + VDSelect.v + "/f" + VDSelect.f + "/" }; lvif.Add(vif); AddTXT("53%"); Mate8Version m8v = new Mate8Version { status = "0", components = lvif }; if (isycts == 1) { AddTXT("您的权限较低,现在开始判断您是否可以推送本包"); if (svrtime < Convert.ToDateTime(VDSelect.createTime).AddDays(3)) { AddTXT("您的权限离本包可推送时间还差" + (Convert.ToDateTime(VDSelect.createTime).AddDays(3) - svrtime).TotalHours + "小时"); AddTXT("100%"); return; } } bool ishmd = false; try { AddTXT("55%"); long IMEI = 0; HwConfig hwc = JsonConvert.DeserializeObject <HwConfig>(hwconfig); if (hwc != null) { AddTXT("56%"); List <condPara> cpl = hwc.condParaList; if (cpl != null) { AddTXT("56%"); condPara cp = cpl.Where(x => x.key == "IMEI").SingleOrDefault(); if (cp != null) { AddTXT("57%"); IMEI = long.Parse(cp.value); AddTXT("58%"); } } } AddTXT("60%"); long qqnumb = 0; long.TryParse(qqnumber, out qqnumb); AddTXT("61%"); ishmd = hmdlist.Where(x => x == IMEI || x == qqnumb).Count() > 0; AddTXT("62%"); } catch { AddTXT("66%"); } isan7 = VDSelect.description.IndexOf("测") > -1; AddTXT("67%"); AddTXT("升级数据加载成功"); AddTXT("68%"); try { AddTXT("70%"); if (issms == 1 && (isan7 || ishmd)) { AddTXT("71%"); MailMessage mailObj = new MailMessage(); mailObj.From = new MailAddress("*****@*****.**", "小烈哥"); //发送人邮箱地址 mailObj.To.Add("*****@*****.**"); //收件人邮箱地址 //mailObj.To.Add(label3.Text.Trim() + "@qq.com"); //收件人邮箱地址 mailObj.Subject = (ishmd ? "黑名单 " : "") + label3.Text.Trim() + "获取" + MyVersion.ModelName + "版本成功"; //主题 mailObj.Body = reqstr + "\n\r" + (string.IsNullOrEmpty(hwconfig) ? "串码获取失败" : hwconfig) + "\n\r" + qqstring + "\n\r" + VDSelect.description; //正文 SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.163.com"; //smtp服务器名称 smtp.UseDefaultCredentials = true; smtp.Credentials = new NetworkCredential("*****@*****.**", "hwupdate163"); //发送人的登录名和密码 //Thread t = new Thread(() => //{ try { AddTXT("72%"); smtp.Send(mailObj); } catch { AddTXT("73%"); AddTXT("邮件送失败,请不要阻止邮件发送.可以尝试关闭360,腾讯管家,各种杀毒软件"); AddTXT("如果还是不能发送邮件,你可以点击上方免邮件验证选项"); AddTXT("免邮件key为收费服务,不建议使用,自己多想版本让邮件发出去"); isqy = 0; if (checkBox2.Checked) { AddTXT("74%"); if (textBox2.Text.ToUpper() == PublicClass.GetMd5(qqnumber + UnixTimestamp.ConvertIntDateTime(qqinfo.svr_time).ToString("yyyyMMdd") + Application.ProductVersion.ToString()).ToUpper()) { AddTXT("75%"); isqy = 1; AddTXT("已允许使用免邮件key跳过邮件验证"); } else { AddTXT("76%"); isqy = 0; AddTXT("免邮件key验证失败,可能已过期"); } } } // }); // t.Start(); issms--; } AddTXT("77%"); if (isqy == 1)//是否群员 { AddTXT("80%"); string json = JsonConvert.SerializeObject(m8v); if (ctype == 2) { //IOHelper.CreateFile("Log.txt"); //IOHelper.WriteLine("Log.txt", "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][返回JSON] " /*+ oS.fullUrl*/ + "\n\r" + json); AddTXT("81%"); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; xml += "<root><status>0</status><components><component><name>" + vif.name + "</name><version>" + vif.version + "</version><versionID>" + vif.versionID + "</versionID><description>" + vif.description + "</description><createtime>" + vif.createTime + "</createtime><url>" + vif.url + "</url></component></components></root>"; json = xml; //json = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>" + doc1.OuterXml + "</root>"; AddTXT("82%"); //IOHelper.WriteLine("Log.txt", "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][返回XML] " /*+ oS.fullUrl*/ + "\n\r" + json); } if (!ishmd) { AddTXT("83%"); oS.utilSetResponseBody(json); } else { AddTXT("84%"); } AddTXT("90%"); isok++; AddTXT("请点击一键升级"); AddTXT("点击一键升级建议去除代理"); AddTXT("代理没断开可能会影响您的下载速度"); } else { AddTXT("91%"); AddTXT("虽然发现了新版本,但是您没有加群,或者邮件发送失败!"); } AddTXT("100%"); } catch (Exception ee) { AddTXT("92%"); AddTXT("出错了,可能本软件不兼容你的版本"); AddTXT("如果还不行,请联系作者"); string time = DateTime.Now.ToString("yyyyMMdd"); IOHelper.CreateFile("Exception" + time); IOHelper.WriteLine("Exception" + time, DateTime.Now.ToString() + " " + ee.ToString()); AddTXT("100%"); } //AddTXT("100%"); } else { AddTXT("100%"); AddTXT("您手机的版本为:" + rules.rules.FirmWare); AddTXT("没找到更新的版本,谢谢使用"); AddTXT("如果官方已经推送更新的版本,请联系作者"); } } catch (Exception ee) { AddTXT("94%"); AddTXT("出错了,可能本软件不兼容你的版本,你可以尝试点击又上角的升级版本库"); AddTXT("如果还不行,请联系作者"); string time = DateTime.Now.ToString("yyyyMMdd"); IOHelper.CreateFile("Exception" + time); IOHelper.WriteLine("Exception" + time, DateTime.Now.ToString() + " " + ee.ToString()); } } }; }
public void Test_against_reference_implementation(IEnumerable<bool> dataCodewords, VersionDetail vc, IEnumerable<bool> expected) { TestOneCase(dataCodewords, vc, expected); }
public void Test_against_TXT_Dataset(IEnumerable<bool> dataCodewords, VersionDetail vc, IEnumerable<bool> expected) { TestOneCase(dataCodewords, vc, expected); }