private void UpdateValuesInLanguageVersion(ItemFile itemFile, Item item) { foreach (Field field in item.Fields) { if (field.Shared) { SortedSet <FieldValue> fields = itemFile.SharedFieldValues; UpdateField(item, fields, field); } else { Domain.Language language = itemFile.Languages.FirstOrDefault(l => l.LanguageName == field.Language.Name); if (language == null) { language = new Domain.Language() { LanguageName = field.Language.Name }; itemFile.Languages.Add(language); } Domain.Version version = language.Versions.FirstOrDefault(v => v.VersionNumber == item.Version.Number); if (version == null) { version = new Domain.Version() { VersionNumber = item.Version.Number }; language.Versions.Add(version); } UpdateField(item, version.FieldValues, field); } } }
private void UpdateItem(SerializationManager serializationManager, DirectoryInfo indexFileDirectory, Item item, bool recurseAllDescendants) { FileInfo itemFileInfo = GetItemFileInfo(indexFileDirectory, item.ID.ToGuid()); // Read item file ItemFile itemFile = serializationManager.ReadItemFile(itemFileInfo); // Update item data serializationManager.UpdateItemFile(itemFile, item); // Write to file itemFileInfo.Directory.Create(); string serialized = JsonConvert.SerializeObject(itemFile, Formatting.Indented); File.WriteAllText(itemFileInfo.FullName, serialized.Replace("\\r\\n", "\n")); if (!recurseAllDescendants || !item.HasChildren) { return; } // Update children foreach (Item child in item.GetChildren()) { UpdateItem(serializationManager, indexFileDirectory, child, recurseAllDescendants); } }
public void ShouldSharedFieldValuesBeSorted() { ItemFile itemFile = new ItemFile(); Guid guid1 = new Guid("f11cd74b-099b-48c6-aaed-44927164e9e7"); itemFile.SharedFieldValues.Add(new FieldValue() { Id = guid1 }); Guid guid2 = new Guid("62e71efe-bcc8-48dc-9868-4dd2fdbfc2dc"); itemFile.SharedFieldValues.Add(new FieldValue() { Id = guid2 }); Guid guid3 = new Guid("6aa71741-aaf7-4fef-97ad-6148e3a5c076"); itemFile.SharedFieldValues.Add(new FieldValue() { Id = guid3 }); itemFile.SharedFieldValues.Select(c => c.Id).ShouldBeEquivalentTo(new[] { guid2, guid3, guid1 }, options => options.WithStrictOrdering()); }
public VssItem GetItemPhysical(string physicalName) { physicalName = physicalName.ToUpper(); if (physicalName == RootProjectFile) { return(rootProject); } var physicalPath = GetDataPath(physicalName); var itemFile = new ItemFile(physicalPath, encoding); var isProject = (itemFile.Header.ItemType == ItemType.Project); var logicalName = GetFullName(itemFile.Header.Name); var itemName = new VssItemName(logicalName, physicalName, isProject); VssItem item; if (isProject) { var parentFile = ((ProjectHeaderRecord)itemFile.Header).ParentFile; var parent = (VssProject)GetItemPhysical(parentFile); var logicalPath = BuildPath(parent, logicalName); item = new VssProject(this, itemName, physicalPath, logicalPath); } else { item = new VssFile(this, itemName, physicalPath); } item.ItemFile = itemFile; return(item); }
private static void DumpLogFile(string filename) { try { var itemFile = new ItemFile(filename, Encoding.Default); itemFile.Header.Header.Dump(Console.Out); itemFile.Header.Dump(Console.Out); var record = itemFile.GetNextRecord(true); while (record != null) { record.Header.Dump(Console.Out); record.Dump(Console.Out); var revision = record as RevisionRecord; if (revision != null) { if (itemFile.Header.ItemType == ItemType.Project) { projectActions.Add(revision.Action); } else { fileActions.Add(revision.Action); } } record = itemFile.GetNextRecord(true); } } catch (Exception e) { Console.WriteLine("ERROR: {0}", e.Message); } }
//處理前端頁面動態刪除檔案 public JsonResult DeleteFile(string fileId) { if (String.IsNullOrEmpty(fileId)) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Result = "Error" })); } try { Guid guid = new Guid(fileId); ItemFile fileDetail = db.ItemFiles.Find(guid); if (fileDetail == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(new { Result = "Error" })); } //刪除實體檔案資料 DeletePsyicalFile(fileDetail); //刪除Database紀錄 db.ItemFiles.Remove(fileDetail); db.SaveChanges(); return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
/// <summary> /// Updates the asociated combo box list /// </summary> /// <param name="asocDir">The asoc directory.</param> private void UpdateCboAsoc(string asocDir) { if (asocDir.ToUpper().Contains(CAT_DANTE.ToUpper())) { AerithScanner scn = new AerithScanner(asocDir, true, true); scn.Find(new MicrosoftAccessFilter()); this.cboAsoc.ItemsSource = scn.Files.Select(x => new ItemFile(x)).OrderBy(y => y.ItemName); if (this.cboAsoc.Items.Count > 0) { string asoc = App.Riviera.GetPath(DaNTePath.ASOC_MDB); if (IOFile.Exists(asoc)) { IOFileInfo file = new IOFileInfo(asoc); ItemFile item = this.cboAsoc.ItemsSource.OfType <ItemFile>().FirstOrDefault(x => x.ItemName == file.Name); if (item != null) { this.cboAsoc.SelectedIndex = this.cboAsoc.ItemsSource.OfType <ItemFile>().ToList().IndexOf(item); } else { this.cboAsoc.SelectedIndex = 0; } } else { this.cboAsoc.SelectedIndex = 0; } } } }
public FileToCompare(ItemFile local, ItemFile remote) { RelativePath = local.RelativePath; LocalFullPath = local.FullPath; S3ObjectKey = remote.FullPath; S3ETag = remote.ETag; }
public override void Write(BinaryWriter writer) { ItemFile.SerialiseItem(chosen, writer); writer.Write(items.Count); for (int i = 0; i < items.Count; ++i) { if (items[i] == null) { items.RemoveAt(0); --i; continue; } ItemFile.SerialiseItem(items[i], writer); } writer.Write(carriedItems.Count); for (int i = 0; i < carriedItems.Count; ++i) { if (carriedItems[i] == null) { carriedItems.RemoveAt(0); --i; continue; } ItemFile.SerialiseItem(carriedItems[i], writer); } }
/// <summary> /// Creates a new json data model, populates it with this item's data, and saves it to disk. /// </summary> public void Save() { ItemFile itemFile = new ItemFile(); itemFile.PopulateFile(this); itemFile.Save(); }
/// <summary> /// Generic serialization function for reading the inventory from disk /// </summary> /// <param name="reader"></param> public void ReadInventory(BinaryReader reader) { int listcount; int version = reader.ReadInt32(); this.Inventory = new List <ItemBase>(); switch (version) { case 0: listcount = reader.ReadInt32(); for (int index = 0; index < listcount; ++index) { ItemBase item = ItemFile.DeserialiseItem(reader); if (item != null) { this.Inventory.Add(item); } else { Debug.LogError("Machine inventory tried to read in a null item! Corrupt save?"); } } break; default: Debug.LogError("Attempted to read Machine inventory version that does not exist!"); break; } }
protected override void DoProcess(CustomSerializationPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.IsNotNull(args.Item, "no item was passed to the pipeline"); FileInfo itemFileInfo = GetItemFileInfo(GetIndexFileInfo(args.Item.Database.Name).Directory, args.Item.ID.ToGuid()); if (!itemFileInfo.Exists) { args.AddMessage( string.Format("File '{0}' could not be found; item loading aborted", itemFileInfo.FullName), PipelineMessageType.Error); args.AbortPipeline(); return; } ItemFile itemFile = args.SerializationManager.ReadItemFile(itemFileInfo); if (this.revert) { args.Item = args.SerializationManager.DeleteAndRecreate(itemFile, args.Item); } args.SerializationManager.LoadItemIntoSitecore(itemFile, args.Item, revert); }
public override void Read(BinaryReader reader, int entityVersion) { VicisMod.VicisModVersion version = (VicisMod.VicisModVersion)entityVersion; switch (version) { case VicisMod.VicisModVersion.Version1: case VicisMod.VicisModVersion.Version2: case VicisMod.VicisModVersion.Version3: break; default: chosen = ItemFile.DeserialiseItem(reader); mbHoloPreviewDirty = true; int numCarried = reader.ReadInt32(); for (int i = 0; i < numCarried; ++i) { carriedItems.Add(ItemFile.DeserialiseItem(reader)); } int numItems = reader.ReadInt32(); for (int i = 0; i < numItems; ++i) { items.Add(ItemFile.DeserialiseItem(reader)); } break; } }
private void LoadDescendants( IndexFileItem parentFileItem, Item parent, SerializationManager serializationManager, DirectoryInfo parentDirectory) { foreach (var child in parentFileItem.Children) { Item item = parent.Database.GetItem(ID.Parse(child.Id)); if (item == null) { ItemFile itemFile = serializationManager .ReadItemFile(GetItemFileInfo(parentDirectory, child.Id)); item = ItemManager.CreateItem( itemFile.Name, parent, ID.Parse(itemFile.TemplateId), ID.Parse(itemFile.Id), SecurityCheck.Disable); } CorePipeline.Run(revert ? "serialization.revertitem" : "serialization.loaditem", new CustomSerializationPipelineArgs() { SerializationManager = serializationManager, Item = item }); LoadDescendants(child, item, serializationManager, parentDirectory); } }
public override void Read(BinaryReader reader, int entityVersion) { Exemplar = ItemFile.DeserialiseItem(reader); if (reader.BaseStream.Position != reader.BaseStream.Length) { ItemTaken = reader.ReadBoolean(); } }
public ItemPage(ItemFile file) { //Console.WriteLine("DEBUG > ObjentryPage > Filepath: " + filepath); handler = new ItemPageHandler(file); DataContext = handler; InitializeComponent(); }
public override void WriteNetworkUpdate(BinaryWriter writer) { writer.Write(_items.Count); foreach (var item in _items) { ItemFile.SerialiseItem(item, writer); } }
public static void Load(string path) { var file = new ItemFile <Definition>(path); Debug.LogFormat("Num car color entries: {0}", file.GetItems <CarColorDef>().Count()); _sColors = file.GetItems <ColorDef>().Select(x => new Color32(x.R, x.G, x.B, 255)).ToArray(); _sCarColors = file.GetItems <CarColorDef>().DistinctBy(ccd => ccd.Name).ToDictionary(x => x.Name, x => new CarColors(x)); }
/// <summary> /// Creates <see cref="ItemFile"/> element. /// </summary> /// <param name="name">Name field value for ItemFile.</param> /// <param name="type">Type field value for ItemFile.</param> /// <param name="val">Value field value for ItemFile.</param> /// <returns>Returns new <see cref="ItemFile"/> element.</returns> public static ItemFile CreateFile(string name, string type, string[] val) { ItemFile attr = new ItemFile(); attr.Name = name; attr.Type = type; attr.Value = val; return(attr); }
//刪除實體檔案方法 private void DeletePsyicalFile(ItemFile fileDetail) { var path = Path.Combine(Server.MapPath("~/upload/wano"), fileDetail.ItemId + fileDetail.Extension); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } }
private void btnReset_Click(object sender, EventArgs e) { this.SuspendLayout(); this.Controls.Clear(); this.ResumeLayout(); this.InitializeComponent(); this.InitializeMore(); eif = null; }
public override void Write(BinaryWriter writer) { writer.Write(mrCurrentPower); ItemFile.SerialiseItem(mTargetLens, writer); ItemFile.SerialiseItem(mStoredLenses, writer); //Concious decision to not store progress/state. //Should be a "fast" machine anyways. //This will ensure no material/energy is lost. }
public override void Read(BinaryReader reader, int entityVersion) { int itemCount = reader.ReadInt32(); for (int index = 0; index < itemCount; index++) { _items.Add(ItemFile.DeserialiseItem(reader)); } }
public override void ReadNetworkUpdate(BinaryReader reader) { int itemCount = reader.ReadInt32(); _items = new List <ItemBase>(); for (int index = 0; index < itemCount; index++) { _items.Add(ItemFile.DeserialiseItem(reader)); } }
public override void Write(BinaryWriter writer) { VicisMod.log(getPrefix(), "Currently holding: " + GetPopupText()); writer.Write(items.Count); for (int i = 0; i < items.Count; ++i) { VicisMod.log(getPrefix(), "Writing to file " + items[i].GetDisplayString()); ItemFile.SerialiseItem(items[i], writer); } }
public override void Write(BinaryWriter writer) { writer.Write(_machinePower.CurrentPower); writer.Write(_inputEnabled); writer.Write(_outputEnabled); writer.Write(_itemInputRules.Count); foreach (var itemInputRule in _itemInputRules) { writer.Write(itemInputRule.MaxInput); ItemFile.SerialiseItem(itemInputRule.Item, writer); } }
public void ShouldUpdateItemFile() { DbField sharedField = new DbField("sharedfield") { Shared = true, Value = "sharedfieldvalue" }; DbField fieldInEnglishV1 = new DbField("env1field") { { "en", 1, "env1fieldvalue" } }; DbField fieldInEnglishV2 = new DbField("env2field") { { "en", 2, "env2fieldvalue" } }; DbField fieldInDutchV1 = new DbField("nlv1field") { { "nl", 1, "nlv1fieldvalue" } }; DbItem it = new DbItem("it") { sharedField, fieldInEnglishV1, fieldInEnglishV2, fieldInDutchV1 }; using (var db = new Db() { it }) { ItemFile itemFile = new ItemFile(); SerializationManager serializationManager = new SerializationManager(); serializationManager.UpdateItemFile(itemFile, db.GetItem(it.ID)); itemFile.Id.ShouldBeEquivalentTo(it.ID.ToGuid()); itemFile.Name.ShouldBeEquivalentTo("it"); itemFile.TemplateId.ShouldBeEquivalentTo(it.TemplateID.ToGuid()); itemFile.BranchId.ShouldBeEquivalentTo(it.BranchId); itemFile.Languages.Count.ShouldBeEquivalentTo(2); itemFile.Languages.First().LanguageName.ShouldBeEquivalentTo("en"); itemFile.Languages.First().Versions.Count.ShouldBeEquivalentTo(2); CustomSerialization.Domain.Version englishVersion1 = itemFile.Languages.First().Versions.First(); englishVersion1.VersionNumber.ShouldBeEquivalentTo(1); englishVersion1.FieldValues.Should().NotBeEmpty(); FieldValue fieldValue = englishVersion1.FieldValues.FirstOrDefault(f => f.Id == fieldInEnglishV1.ID.ToGuid()); fieldValue.Should().NotBeNull(); fieldValue.Value.ShouldBeEquivalentTo("env1fieldvalue"); } }
public void UpdateItemFile(ItemFile itemFile, Item item) { itemFile.Id = item.ID.ToGuid(); itemFile.Name = item.Name; itemFile.TemplateId = item.TemplateID.ToGuid(); itemFile.BranchId = item.BranchId.IsNull ? null as System.Guid? : item.BranchId.ToGuid(); foreach (Item version in item.Versions.GetVersions(true)) { UpdateValuesInLanguageVersion(itemFile, version); } }
public override void Write(BinaryWriter writer) { writer.Write(carriedItems.Count); foreach (ItemBase item in carriedItems) { ItemFile.SerialiseItem(item, writer); } writer.Write(items.Count); foreach (ItemBase item in items) { ItemFile.SerialiseItem(item, writer); } }
public override void Write(BinaryWriter writer) { writer.Write(carriedItems.Count); for (int i = 0; i < carriedItems.Count; ++i) { ItemFile.SerialiseItem(carriedItems[i], writer); } writer.Write(items.Count); for (int i = 0; i < items.Count; ++i) { ItemFile.SerialiseItem(items[i], writer); } }
private void btnLoad_Click(object sender, EventArgs e) { string fname = ""; try { eif = new ItemFile(fname = (string.IsNullOrEmpty(txtFileName.Text) ? EOLib.Constants.ItemFilePath : txtFileName.Text)); lblFileName.Text = "Loaded file: " + fname; grpStepTwo.Enabled = true; btnReset.Enabled = true; } catch(Exception ex) { eif = null; MessageBox.Show("Error loading " + fname + ":\n" + ex.Message, "Error!"); return; } }
private bool _tryLoadItems(string fileName = null) { try { m_items = string.IsNullOrEmpty(fileName) ? new ItemFile() : new ItemFile(fileName); } catch { m_items = null; return false; } return true; }
private static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Usage: BatchMap.exe <srcmap|srcdir> <dstmap|dstdir> <pubdir>"); return; } string srcFilePath = args[0]; string dstFilePath = args[1]; string pubFilePath = args[2]; bool singleFileProcess = false; if (srcFilePath.ToLower().EndsWith(".emf") && !dstFilePath.ToLower().EndsWith(".emf")) { Console.WriteLine("Invalid: single map cannot be processed into output directory. Specify destination emf file."); return; } if (dstFilePath.ToLower().EndsWith(".emf") && !srcFilePath.ToLower().EndsWith(".emf")) { Console.WriteLine("Invalid: map directory cannot be processed into single output map. Specify destination output directory."); return; } if (srcFilePath.ToLower().EndsWith(".emf") && dstFilePath.ToLower().EndsWith(".emf")) { singleFileProcess = true; if (!File.Exists(srcFilePath)) { Console.WriteLine("Invalid input: input file does not exist!"); return; } if (File.Exists(dstFilePath)) { char inp; do { Console.Write("Destination file exists. Overwrite? [y/n] "); string input = Console.ReadLine() ?? ""; inp = input.Length > 0 ? input[0] : ' '; } while (inp != 'y' && inp != 'n' && inp != 'Y' && inp != 'N'); if (inp == 'n' || inp == 'N') { Console.WriteLine("Will not overwrite existing file. Exiting."); return; } } } else { if (!Directory.Exists(srcFilePath) || Directory.GetFiles(srcFilePath, "*.emf").Length == 0) { Console.WriteLine("Invalid input: source directory does not exist or is missing maps!"); return; } if (Directory.Exists(dstFilePath) && Directory.GetFiles(dstFilePath, "*.emf").Length > 0) { char inp; do { Console.WriteLine("Destination directory contains emf files. Overwrite? [y/n] "); string input = Console.ReadLine() ?? ""; inp = input.Length > 0 ? input[0] : ' '; } while (inp != 'y' && inp != 'n' && inp != 'Y' && inp != 'N'); if (inp == 'n' || inp == 'N') { Console.WriteLine("Will not overwrite existing files. Exiting."); return; } } else if (!Directory.Exists(dstFilePath)) { Directory.CreateDirectory(dstFilePath); } } try { EIF = new ItemFile(Path.Combine(pubFilePath, "dat001.eif")); ENF = new NPCFile(Path.Combine(pubFilePath, "dtn001.enf")); } catch { Console.WriteLine("Error loading pub files!"); return; } ProcessFiles(srcFilePath, dstFilePath, singleFileProcess); }