/// <summary> /// 获取要解压的文件 /// </summary> /// <param name="verTextName"></param> /// <param name="callBack"></param> public void GetDecompressionTaskList(VerInfo localVer, Action <DecompressionOrDownInfo> callBack) { string sourceUrl = AppConst.SourceResPathUrl + "/" + localVer.verName + ".txt"; VerInfo remoteVer = null; Action <WWW> loadlocaled = www => { if (www != null && string.IsNullOrEmpty(www.error)) { try { remoteVer = JsonUtility.FromJson <VerInfo>(www.text); } catch (Exception) { Debug.LogError("本地没有这个文件:" + sourceUrl); } } else { Debug.LogError("本地没有这个文件:" + sourceUrl); } ComparisonInfo info = VerInfo.ComparisonVer(localVer, remoteVer); DecompressionOrDownInfo dord = new DecompressionOrDownInfo(); dord.remoteVer = remoteVer; dord.localVer = localVer; dord.comparisonInfo = info; if (callBack != null) { callBack(dord); } }; ComUtil.WWWLoad(sourceUrl, loadlocaled); }
void timer_Tick(object sender, EventArgs e) { lock (mutex) { while (results.Count > 0) { ComparisonInfo info = results.First.Value; results.RemoveFirst(); int index = this.dataGridView1.Rows.Add(new object[] { info.filename, info.filehash1, info.filehash2, info.good ? "yes" : "NO" }); this.dataGridView1.Rows[index].Cells[3].Style.ForeColor = Color.White; if (info.good) { this.dataGridView1.Rows[index].Cells[3].Style.BackColor = Color.Green; } else { this.dataGridView1.Rows[index].Cells[3].Style.BackColor = Color.Red; } } if (stop) { this.label_progress.Text = "Stopped."; } else { this.label_progress.Text = "Hashing..."; } } }
public void GetDownList(VerInfo localVer, Action <DecompressionOrDownInfo> callBack) { if (downLoadInfo == null) { DecompressionOrDownInfo downInfo = new DecompressionOrDownInfo(); downInfo.localVer = localVer; downInfo.remoteVer = null; downInfo.comparisonInfo = VerInfo.ComparisonVer(localVer, downInfo.remoteVer); if (callBack != null) { callBack(downInfo); } return; } string remoturl = downLoadInfo.ResUrl + "/" + localVer.verName + ".txt"; VerInfo remoteVer = null; Debug.LogWarning("准备校验远程文件:" + remoturl); Action <WWW> wwwed = www => { if (www != null && string.IsNullOrEmpty(www.error)) { try { remoteVer = JsonUtility.FromJson <VerInfo>(www.text); } catch (System.Exception ex) { Debug.LogError("远程文件解析失败:text=" + www.text); } } else { Debug.LogError("从远程下载文件失败:url=" + remoturl); } ComparisonInfo info = VerInfo.ComparisonVer(localVer, remoteVer); if (localVer != null) { Debug.LogWarning("检查完成 本地版本:" + localVer.ver); } if (remoteVer != null) { Debug.LogWarning("检查完成 远程版本:" + remoteVer.ver); } DecompressionOrDownInfo dord = new DecompressionOrDownInfo(); dord.remoteVer = remoteVer; dord.localVer = localVer; dord.comparisonInfo = info; if (callBack != null) { callBack(dord); } www.Dispose(); }; Debug.LogWarning("从远程下载文件" + remoturl); ComUtil.WWWLoad(remoturl, wwwed); }
//选中文件夹的事件 private void DirTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { locationTextBlock.Visibility = Visibility.Visible; AddTag.Visibility = Visibility.Visible; compareTable.Visibility = Visibility.Visible; ComparisonInfo info = ComparisonService.GetInfoByNode(dirTree.SelectedItem as DirNode); // 放入两个事件的创建时间 info.OldTime = (oldIncident.SelectedItem as IncidentBean).CreateTimeFormat; info.NewTime = (newIncident.SelectedItem as IncidentBean).CreateTimeFormat; comparisonGrid.DataContext = info; }
static Expression GetDetailExpression(ComparisonInfo comparison, DetailInfo detail) { ParameterExpression detailParameter = Expression.Parameter(detail.DetailType, "cd"); var nameEqual = GetPropertyEquals(detailParameter, "Name", Expression.Constant(comparison.NameExpression.Member.Name)); bool isLinkQuery = detail.ValuePropertyName == "LinkedItem"; var valueExpression = GetPropertyComparison(detailParameter, isLinkQuery ? Expression.Property(Expression.Property(detailParameter, "LinkedItem"), "ID") : Expression.Property(detailParameter, detail.ValuePropertyName), comparison, isLinkQuery); Expression nameAndValue = Expression.AndAlso(nameEqual, valueExpression); var nameAndValueExpression = Expression.Lambda(nameAndValue, detailParameter); return(nameAndValueExpression); }
/// <summary> /// 通过节点获取文件夹的比较信息 /// </summary> public static ComparisonInfo GetInfoByNode(DirNode node) { //获取bean RecordBean oldBean = null; if (node.OldId != 0) { oldBean = RecordMapper.GetOneById(node.OldId, node.OldIncidentId); } RecordBean newBean = null; if (node.NewId != 0) { newBean = RecordMapper.GetOneById(node.NewId, node.NewIncidentId); } //设置标签 ComparisonInfo info = new ComparisonInfo() { TagName = string.Concat("标签:", node.Tag.Name ?? "没有标签") }; //设置主要比较的数据 BigInteger oldSize, newSize, oldUsage, newUsage; if (oldBean != null) { info.Title = oldBean.Name; info.Location = oldBean.Location; info.CreateTime = "创建时间:" + oldBean.CerateTime.ToString("yy-MM-dd HH:mm:ss"); info.OldFileCount = Convert.ToInt32(oldBean.FileCount); info.OldDirCount = Convert.ToInt32(oldBean.DirCount); oldSize = oldBean.Size; oldUsage = oldBean.SpaceUsage; } else { oldSize = BigInteger.Zero; oldUsage = BigInteger.Zero; } if (newBean != null) { info.Title = newBean.Name; info.Location = newBean.Location; info.CreateTime = "创建时间:" + newBean.CerateTime.ToString("yy-MM-dd HH:mm:ss"); info.NewFileCount = Convert.ToInt32(newBean.FileCount); info.NewDirCount = Convert.ToInt32(newBean.DirCount); newSize = newBean.Size; newUsage = newBean.SpaceUsage; } else { newSize = BigInteger.Zero; newUsage = BigInteger.Zero; } //单位换算 info.OldSize = ConversionUtil.StorageFormate(oldSize, false); info.NewSize = ConversionUtil.StorageFormate(newSize, false); info.SizeChanged = ConversionUtil.StorageFormate(newSize - oldSize, true); info.OldUsage = ConversionUtil.StorageFormate(oldUsage, false); info.NewUsage = ConversionUtil.StorageFormate(newUsage, false); info.UsageChanged = ConversionUtil.StorageFormate(newUsage - oldUsage, true); //设置状态 switch (node.Type) { case DirNodeType.Unchanged: info.Action = "文件夹未发生变化"; break; case DirNodeType.Added: info.Action = "该文件夹是新增的文件夹"; break; case DirNodeType.Changed: info.Action = "该文件夹发生了变化"; break; case DirNodeType.Deleted: info.Action = "该文件夹已经被删除"; break; } return(info); }
static int Main(string[] args) { string bsmnFile = null; string logFile = null; string scriptFile = null; List <string> skipOptions = null; StreamWriter writer = null; Comparison _comparison = null; try { #region Argument validation / help message if (!(args?.Length > 0)) { Console.WriteLine("No arguments received. Exiting."); return(ERROR_BAD_ARGUMENTS); } else if (args[0].ToLower() == "help" || args[0].ToLower() == "?" || args[0].ToLower() == "/?" || args[0].ToLower() == "/h" || args[0].ToLower() == "/help" || args[0].ToLower() == "-help" || args[0].ToLower() == "-h") { Console.WriteLine(""); Console.WriteLine(" BISM Normalizer Command-Line Utility"); Console.WriteLine(""); Console.WriteLine(" Executes BISM Normalizer in command-line mode, based on content of BSMN file"); Console.WriteLine(""); Console.WriteLine(" USAGE:"); Console.WriteLine(""); Console.WriteLine(" BismNormalizer.exe BsmnFile [/Log:LogFile] [/Script:ScriptFile] [/Skip:{MissingInSource | MissingInTarget | DifferentDefinitions}]"); Console.WriteLine(""); Console.WriteLine(" BsmnFile : Full path to the .bsmn file."); Console.WriteLine(""); Console.WriteLine(" /Log:LogFile : All messages are output to the LogFile."); Console.WriteLine(""); Console.WriteLine(" /Script:ScriptFile : Does not perform actual update to target database; instead, a deployment script is generated and stored to the ScriptFile."); Console.WriteLine(""); Console.WriteLine(" /Skip:{MissingInSource | MissingInTarget | DifferentDefinitions} : Skip all objects that are missing in source/missing in target/with different definitions. Can pass a comma separated list of multiple skip options; e.g. 'MissingInSource,MissingInTarget,DifferentDefinitions'."); Console.WriteLine(""); return(ERROR_SUCCESS); } bsmnFile = args[0]; const string logPrefix = "/log:"; const string scriptPrefix = "/script:"; const string skipPrefix = "/skip:"; for (int i = 1; i < args.Length; i++) { if (args[i].Length >= logPrefix.Length && args[i].Substring(0, logPrefix.Length).ToLower() == logPrefix) { logFile = args[i].Substring(logPrefix.Length, args[i].Length - logPrefix.Length).Replace("\"", ""); } else if (args[i].Length >= scriptPrefix.Length && args[i].Substring(0, scriptPrefix.Length).ToLower() == scriptPrefix) { scriptFile = args[i].Substring(scriptPrefix.Length, args[i].Length - scriptPrefix.Length).Replace("\"", ""); } else if (args[i].Length >= skipPrefix.Length && args[i].Substring(0, skipPrefix.Length).ToLower() == skipPrefix) { skipOptions = new List <string>(args[i].Substring(skipPrefix.Length, args[i].Length - skipPrefix.Length).Split(',')); foreach (string skipOption in skipOptions) { if (!(skipOption == ComparisonObjectStatus.MissingInSource.ToString() || skipOption == ComparisonObjectStatus.MissingInTarget.ToString() || skipOption == ComparisonObjectStatus.DifferentDefinitions.ToString())) { Console.WriteLine($"Argument '{args[i]}' is invalid. Valid skip options are '{ComparisonObjectStatus.MissingInSource.ToString()}', '{ComparisonObjectStatus.MissingInTarget.ToString()}' or '{ComparisonObjectStatus.DifferentDefinitions.ToString()}'"); return(ERROR_BAD_ARGUMENTS); } } } else { Console.WriteLine($"'{args[i]}' is not a valid argument."); return(ERROR_BAD_ARGUMENTS); } } if (logFile != null) { // Attempt to open output file. writer = new StreamWriter(logFile); // Redirect output from the console to the file. Console.SetOut(writer); } #endregion if (!File.Exists(bsmnFile)) { throw new FileNotFoundException($"File not found {bsmnFile}"); } Console.WriteLine($"About to deserialize {bsmnFile}"); ComparisonInfo comparisonInfo = ComparisonInfo.DeserializeBsmnFile(bsmnFile); Console.WriteLine(); if (comparisonInfo.ConnectionInfoSource.UseProject) { Console.WriteLine($"Source Project File: {comparisonInfo.ConnectionInfoSource.ProjectFile}"); } else { Console.WriteLine($"Source Database: {comparisonInfo.ConnectionInfoSource.ServerName};{comparisonInfo.ConnectionInfoSource.DatabaseName}"); } if (comparisonInfo.ConnectionInfoTarget.UseProject) { Console.WriteLine($"Target Project: {comparisonInfo.ConnectionInfoTarget.ProjectName}"); } else { Console.WriteLine($"Target Database: {comparisonInfo.ConnectionInfoTarget.ServerName};{comparisonInfo.ConnectionInfoTarget.DatabaseName}"); } Console.WriteLine(); Console.WriteLine("--Comparing ..."); _comparison = ComparisonFactory.CreateComparison(comparisonInfo); _comparison.ValidationMessage += HandleValidationMessage; _comparison.Connect(); _comparison.CompareTabularModels(); if (skipOptions != null) { foreach (string skipOption in skipOptions) { SetSkipOptions(skipOption, _comparison.ComparisonObjects); } } Console.WriteLine("--Done"); Console.WriteLine(); Console.WriteLine("--Validating ..."); _comparison.ValidateSelection(); Console.WriteLine("--Done"); Console.WriteLine(); if (scriptFile != null) { Console.WriteLine("--Generating script ..."); //Generate script File.WriteAllText(scriptFile, _comparison.ScriptDatabase()); Console.WriteLine($"Generated script '{scriptFile}'"); } else { Console.WriteLine("--Updating ..."); //Update target database/project _comparison.Update(); if (comparisonInfo.ConnectionInfoTarget.UseProject) { Console.WriteLine($"Applied changes to project {comparisonInfo.ConnectionInfoTarget.ProjectName}."); } else { Console.WriteLine($"Deployed changes to database {comparisonInfo.ConnectionInfoTarget.DatabaseName}."); Console.WriteLine("Passwords have not been set for impersonation accounts (setting passwords is not supported in command-line mode). Ensure the passwords are set before processing."); if (comparisonInfo.OptionsInfo.OptionProcessingOption != ProcessingOption.DoNotProcess) { Console.WriteLine("No processing has been done (processing is not supported in command-line mode)."); } } } Console.WriteLine("--Done"); } catch (FileNotFoundException exc) { Console.WriteLine("The following exception occurred:"); Console.WriteLine(exc.ToString()); return(ERROR_FILE_NOT_FOUND); } catch (ArgumentNullException exc) { Console.WriteLine("The following exception occurred. Try re-saving the BSMN file from Visual Studio using latest version of BISM Normalizer to ensure all necessary properties are deserialized and stored in the file."); Console.WriteLine(); Console.WriteLine(exc.ToString()); return(ERROR_NULL_REF_POINTER); } catch (Exception exc) { Console.WriteLine("The following exception occurred:"); Console.WriteLine(exc.ToString()); return(ERROR_GENERIC_NOT_MAPPED); } finally { if (writer != null) { writer.Close(); } if (_comparison != null) { _comparison.Disconnect(); } } return(ERROR_SUCCESS); }