static string processTransform(Transform t, bool makeSubmeshes) { StringBuilder meshString = new StringBuilder(); meshString.Append("#" + t.name + "\n#-------" + "\n"); if (makeSubmeshes) { meshString.Append("g ").Append(t.name).Append("\n"); } MeshFilter mf = t.GetComponent <MeshFilter>(); if (mf) { meshString.Append(ObjSerializer.MeshToString(mf, t)); } for (int i = 0; i < t.childCount; i++) { meshString.Append(processTransform(t.GetChild(i), makeSubmeshes)); } return(meshString.ToString()); }
private void OnFormLoad(object sender, EventArgs e) { _executor = new Executor(); _env = new ProcEnvironInfo(); _defaultCmdPaths = new List <string>(); _defaultCmdPaths.Add(_env.SysDir.System32); _defaultCmdPaths.Add(_env.SysDir.WinDir); _configFile = Path.Combine(_env.WorkingDir, CmdConfigFile); if (FileValidator.IsValid(_configFile)) { _cmdTable = ObjSerializer.Load <DataTable>(Path.Combine(_env.WorkingDir, CmdConfigFile)); } else { _cmdTable = new DataTable("CommandTable"); _cmdTable.Columns.Add("Command"); _cmdTable.Columns.Add("Parameters"); object[] itemArray = new object[_cmdTable.Columns.Count]; itemArray[0] = ExplorerCmd; itemArray[1] = ExplorerParam; DataRow dtRowTmp = _cmdTable.NewRow(); dtRowTmp.ItemArray = itemArray; _cmdTable.Rows.Add(dtRowTmp); } FillSettingTable(); }
public DiffChain Resolve(object local, object remote, ResolveContext context) { if (local == null && remote == null) { return(DiffChain.Empty()); } var result = new DiffChain(); if (local == null) { result.Add(context.CreateDiffFromCurrentPath(remote, DiffPartType.Create)); } else if (remote == null) { result.Add(context.CreateDiffFromCurrentPath(DiffPartType.Remove)); } else { var remoteDict = (IDictionary)remote; var localDict = (IDictionary)local; var remoteEnumerator = remoteDict.GetEnumerator(); var localEnumerator = localDict.GetEnumerator(); Type[] arguments = context.Type.GetGenericArguments(); Type valueType = arguments[1]; // Удаление элементов, по ключам отсутствующем в конечном состоянии while (localEnumerator.MoveNext()) { if (!remoteDict.Contains(localEnumerator.Key)) { result.Add(new ResolveContext(context, ObjSerializer.Serialize(localEnumerator.Key), valueType).CreateDiffFromCurrentPath()); } } // Определение новых элементов и сравнение пересекающихся по ключам while (remoteEnumerator.MoveNext()) { if (localDict.Contains(remoteEnumerator.Key)) { var remoteValue = remoteEnumerator.Value; var localValue = localDict[remoteEnumerator.Key]; result.Add(context.Resolvers.FindResolver(valueType).Resolve(localValue, remoteValue, new ResolveContext(context, ObjSerializer.Serialize(remoteEnumerator.Key), valueType))); } else { result.Add(new ResolveContext(context, ObjSerializer.Serialize(remoteEnumerator.Key), valueType).CreateDiffFromCurrentPath(remoteEnumerator.Value)); } } } result.Lock(); return(result); }
private bool DoLoad <SettingT>(string filePath, out SettingT obj) where SettingT : new() { if (FileValidator.IsValid(filePath, 1)) { try { obj = ObjSerializer.Load <SettingT>(filePath); return(true); } catch { } } obj = new SettingT(); return(false); }
static void Main(string[] args) { if (args.Length > 0 && File.Exists(args[0])) { string batchOptFile = args[0]; BatchOptionBase <ReplaceOption> bo = ObjSerializer.Load <BatchOptionBase <ReplaceOption> >(batchOptFile); BatchTextReplacer batchPro = new BatchTextReplacer(bo); batchPro.Start(); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new TextProcessorForm()); } }
private void OnBatchReplaceOperation(object sender, EventArgs e) { BatchOptionBase <ReplaceOption> bo = ObjSerializer.Load <BatchOptionBase <ReplaceOption> >(BatchConfigFile); _batchOptDlg = new OptionsDlg(); _batchOptDlg.AddOption(bo); if (_batchOptDlg.ShowDialog() != DialogResult.OK) { return; } ObjSerializer.Save(BatchConfigFile, bo); BatchTextReplacer batchPro = new BatchTextReplacer(bo); batchPro.Start(); }
static void DoExport(bool makeSubmeshes) { if (Selection.gameObjects.Length == 0) { Debug.Log("Didn't Export Any Meshes; Nothing was selected!"); return; } string meshName = Selection.gameObjects[0].name; string fileName = EditorUtility.SaveFilePanel("Export .obj file", "", meshName, "obj"); ObjSerializer.Start(); StringBuilder meshString = new StringBuilder(); meshString.Append("#" + meshName + ".obj" + "\n#" + System.DateTime.Now.ToLongDateString() + "\n#" + System.DateTime.Now.ToLongTimeString() + "\n#-------" + "\n\n"); Transform t = Selection.gameObjects[0].transform; Vector3 originalPosition = t.position; t.position = Vector3.zero; if (!makeSubmeshes) { meshString.Append("g ").Append(t.name).Append("\n"); } meshString.Append(processTransform(t, makeSubmeshes)); WriteToFile(meshString.ToString(), fileName); t.position = originalPosition; ObjSerializer.End(); Debug.Log("Exported Mesh: " + fileName); }
public void SerializationTest() { bool testDictionary = false; bool testList = true; if (testDictionary) { string dcFile = "dictionary.xml"; Dictionary <int, string> td1 = new Dictionary <int, string>(); td1.Add(1, "One"); td1.Add(2, "Two"); td1.Add(3, "Three"); ObjSerializer.Save(dcFile, td1); Dictionary <int, string> td2 = ObjSerializer.Load <Dictionary <int, string> >(dcFile); foreach (int key in td1.Keys) { Assert.IsTrue(td1[key] == td2[key]); } } if (testList) { string lstFile = "list.xml"; DBLoginInfo e1 = new DBLoginInfo(); e1.ServerName = "(local)"; List <KVPair <string, DBLoginInfo> > lst1 = new List <KVPair <string, DBLoginInfo> >(); lst1.Add(new KVPair <string, DBLoginInfo>("(local)", e1)); lst1.Sort(); ObjSerializer.Save(lstFile, lst1); List <KVPair <string, DBLoginInfo> > lst2 = ObjSerializer.Load <List <KVPair <string, DBLoginInfo> > >(lstFile); lst2.Sort(); foreach (KVPair <string, DBLoginInfo> item in lst1) { Assert.IsTrue(lst2.Contains(item)); } } }
public void SaveSysConfig <SettingT>(SettingT settings, string objName) { ObjSerializer.Save(GetPath(_sysDirectory, objName), settings); }
public void SaveProfile <SettingT>(SettingT settings, string objName) { ObjSerializer.Save(GetPath(_userDirectory, objName), settings); }
private void OnFormClosing(object sender, FormClosingEventArgs e) { ObjSerializer.Save(_configFile, _cmdTable); }
public void Map(ref object local, DiffPart diff, MapContext context) { if (context.Path.Count == 0) { switch (diff.DiffType) { case DiffPartType.Create: local = diff.Value; break; case DiffPartType.Remove: local = null; break; } } else { if (local == null) { local = TypeHelpers.CreateInitialState(context.Type); } var localDict = (IDictionary)local; var key = ObjSerializer.Deserialize(context.Path.Pop()); if (context.Path.Count == 0) { switch (diff.DiffType) { case DiffPartType.Exclude: if (localDict.Contains(key)) { localDict.Remove(key); } break; case DiffPartType.Include: if (localDict.Contains(key)) { localDict[key] = diff.Value; } else { localDict.Add(key, diff.Value); } break; } } else { if (localDict.Contains(key)) { Type[] arguments = context.Type.GetGenericArguments(); Type valueType = arguments[1]; var value = localDict[key]; context.Resolvers.FindResolver(valueType).Map(ref value, diff, new MapContext(context, valueType)); localDict[key] = value; } else { // Ключ обязан быть в словаре, т.к. движение к изменяемой части не завершено throw new InvalidOperationException("Not found key " + (key ?? String.Empty)); } } } }