/// <summary> /// Serializes the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="context">The context.</param> public virtual void Serialize(ModelBase model, TSerializationContext context) { Argument.IsNotNull("model", model); Argument.IsNotNull("context", context); using (var finalContext = GetContext(model, context, SerializationContextMode.Serialization)) { var serializerModifiers = SerializationManager.GetSerializerModifiers(finalContext.ModelType); Log.Debug("Using '{0}' serializer modifiers to deserialize type '{1}'", serializerModifiers.Length, finalContext.ModelType.GetSafeFullName()); var serializingEventArgs = new SerializationEventArgs(finalContext); Serializing.SafeInvoke(this, serializingEventArgs); foreach (var serializerModifier in serializerModifiers) { serializerModifier.OnSerializing(finalContext, model); } BeforeSerialization(finalContext); var members = GetSerializableMembers(model); SerializeMembers(finalContext, members); AfterSerialization(finalContext); foreach (var serializerModifier in serializerModifiers) { serializerModifier.OnSerialized(finalContext, model); } Serialized.SafeInvoke(this, serializingEventArgs); } }
/// <summary> /// Serializes the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="context">The context.</param> protected virtual void Serialize(object model, ISerializationContext <TSerializationContext> context) { Argument.IsNotNull("model", model); Argument.IsNotNull("context", context); var serializerModifiers = SerializationManager.GetSerializerModifiers(context.ModelType); Log.Debug("Using '{0}' serializer modifiers to deserialize type '{1}'", serializerModifiers.Length, context.ModelTypeName); var serializingEventArgs = new SerializationEventArgs(context); Serializing.SafeInvoke(this, serializingEventArgs); foreach (var serializerModifier in serializerModifiers) { serializerModifier.OnSerializing(context, model); } BeforeSerialization(context); var members = GetSerializableMembers(context, model); SerializeMembers(context, members); AfterSerialization(context); foreach (var serializerModifier in serializerModifiers) { serializerModifier.OnSerialized(context, model); } Serialized.SafeInvoke(this, serializingEventArgs); }
public void OnEventErrorMessage(RemoteHostInfo remoteHost, EventErrArgs args) { Logger.Debug($"Invoked OnEventErrorMessage for {remoteHost.Host} via {remoteHost.Protocol} file {args.ErrorMessage}"); string message = Serializing.GetString(args.ErrorMessage); OnSend(this, new EventDataArg <string>(remoteHost, message)); }
public void OnCall(RemoteHostInfo remoteHost, EventCallArgs args) { Logger.Debug($"Invoked OnCall for {remoteHost.Host} via {remoteHost.Protocol} file {args.CallInfo}"); string message = Serializing.GetString(args.CallInfo); OnSend(this, new EventDataArg <string>(remoteHost, message)); }
public static void SavePlants() { Console.WriteLine(); Console.WriteLine("Saving plants..."); Console.WriteLine(); Serializing.WriteToBinaryFile("save/" + new Random().Next(0, 1000), Scan.plants); }
public override void Load(ContentManager content) { powerUps = Serializing.LoadPowerUps(); powerUpImg = new ImageController(Screen, "GameStuff/PowerUps", 120, false); powerUpImg.FrameRectangle = new Rectangle(0, 0, 50, 50); powerUpImg.OriginDefault = new Vector2(25, 25); //powerUpImg.FramesPerRow = 5; powerUpImg.ScaleDefault = 0; AddController(powerUpImg); generateTimeToNext(); }
/// <summary> /// Ретрансформация данных в xml /// </summary> /// <param name="filePath">Файл, содержащий трансформированные xml в json данные</param> /// <returns>Список сотрудников</returns> public List <Employee> Detransform(string filePath) { string tempFileName = Path.GetTempFileName(); string json = File.ReadAllText(filePath); XmlDocument doc = JsonConvert.DeserializeXmlNode(json); doc.Save(tempFileName); List <Employee> workers = Serializing.XmlDeserialize(tempFileName); File.Delete(tempFileName); return(workers); }
private void ClickOpen(object objSrc, EventArgs args) { if (!_isSaved) { if (MiscFunctions.SavingPictureMessageBox() == DialogResult.Yes) { ClickSave(objSrc, args); } } var ofd = new OpenFileDialog { Filter = @"Xml files (*.xml)|*.xml|All files (*.*)|*.*", DefaultExt = "xml", AddExtension = true }; if (ofd.ShowDialog() == DialogResult.OK) { drawPan.Refresh(); drawPan.Invalidate(); _lines.Clear(); try { _lines = Serializing.Deserialize(ofd.FileName); MiscFunctions.DrawLinesList(_lines, drawPan.CreateGraphics()); shapesToolStripMenuItem.DropDownItems.Clear(); foreach (var line in _lines) { var lineItem = new ToolStripMenuItem { Size = new Size(129, 26), Text = line.Name, }; lineItem.Click += ShapesMenuItemClick; shapesToolStripMenuItem.DropDownItems.Add(lineItem); //listBox.Items.Add($"Added new line ({line.Name}), color: {Color.FromArgb(line.R, line.G, line.B).Name}"); } SwitchMovingObject(_lines.Count > 0 ? _lines.Count : 0); } catch (InvalidOperationException exc) { MessageBox.Show( $@"File '{ofd.FileName}' is invalid\n\nException: {exc.Message}", @"Invalid file was loaded", MessageBoxButtons.OK, MessageBoxIcon.Error ); } } _isSaved = true; }
/// <summary> /// Трансформация xml данных в json /// </summary> /// <param name="workers">Список сотрудников</param> /// <param name="filePath">Файл, в который будут записаны трансформированные xml данные</param> public void Transform(List <Employee> workers, string filePath) { string tempFileName = Path.GetTempFileName(); Serializing.XmlSerialize(workers, tempFileName); XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(tempFileName)); File.Delete(tempFileName); string jsonText = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(filePath, jsonText); }
public Game() { Serializing.GenereateModels(); Content.RootDirectory = "Content"; IsMouseVisible = !true; graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = Constants.WindowWidth; graphics.PreferredBackBufferHeight = Constants.WindowHeight; graphics.IsFullScreen = Constants.FullScreen; ConvertUnits.SetDisplayUnitToSimUnitRatio(64f); Components.Add(new ScreenManager(this)); }
public IActionResult Index() { var brands = _service.GetCatalogBrands() .Select(b => new BrandDTO { Id = b.Id, Brand = b.Brand }).ToList(); var serializer = new Serializing(); var data = serializer.SerializeBinary(brands); return(Ok(data)); }
private void ClickSave(object objSrc, EventArgs args) { var sfd = new SaveFileDialog { Filter = @"Xml files (*.xml)|*.xml|All files (*.*)|*.*", DefaultExt = "xml", FileName = "Lines", AddExtension = true }; if (sfd.ShowDialog() == DialogResult.OK) { Serializing.Serialize(sfd.FileName, _lines); _isSaved = true; } }
// GET api/<controller> public HttpResponseMessage Get() { var brands = _service.GetCatalogBrands() .Select(b => new BrandDTO { Id = b.Id, Brand = b.Brand }).ToList(); var serializer = new Serializing(); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(serializer.SerializeBinary(brands)) }; return(response); }
private void LoadCharacters(ContentManager content) { //Loads the characters from the xml files characterModels = Serializing.LoadCharacters(); characterThumbs = new List <ImageController>(); characterImages = new List <ImageController>(); int i = 0; int row = 0, col = 0; //Create textures for thumb and image for every character model foreach (CharacterStats character in characterModels) { ImageController thumb = new ImageController(Screen, character.thumbnail, 3, true); thumb.OriginDefault = new Vector2(Constants.ThumbWith - 10, Constants.ThumbHeight - 10) / 2; thumb.IsVisible = false; thumb.ScaleDefault = 0.1f; ImageModel thumbModel = thumb.SetPosition(col * Constants.ThumbWith + 200, row * Constants.ThumbHeight + 210); thumbModel.SetBoundBox(World, Constants.ThumbWith - 20, Constants.ThumbHeight - 20, new Vector2(10, 0), Category.Cat5, Category.Cat4, true); thumbModel.BoundBox.IsSensor = true; thumbModel.BoundBox.Enabled = false; thumbModel.BoundBox.UserData = i; AddController(thumb); characterThumbs.Add(thumb); //Check if new row if (i == 4) { row++; col = 0; } else { col++; } i++; //Creates the images for every texture var img = new ImageController(Screen, character.image, 4, true); AddController(img); characterImages.Add(img); } }
public static void LoadPlants() { Console.WriteLine(); Console.WriteLine("Loading plants..."); Console.WriteLine(); var directory = new DirectoryInfo("save"); var myFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First(); var loadedPlants = Serializing.ReadFromBinaryFile <List <Plant> >(myFile.FullName); Scan.plants.AddRange(loadedPlants); Console.WriteLine(loadedPlants.Count + " plants loaded from : " + myFile.FullName); }
/// <summary> /// Ретрансформация данных в json /// </summary> /// <param name="filePath">Файл, содержащий трансформированные json в xml данные</param> /// <returns>Список сотрудников</returns> public List <Employee> Detransform(string filePath) { try { XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(filePath)); string jsonText = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.None, true); jsonText = jsonText.Replace("{\"Workers\":", ""); jsonText = jsonText.Remove(jsonText.Length - 1); string tempFileName = Path.GetTempFileName(); File.WriteAllText(tempFileName, jsonText); List <Employee> workers = Serializing.JsonDeserialize(tempFileName); File.Delete(tempFileName); return(workers); } catch (Exception ex) { throw ex; } }
/// <summary> /// Трансформация json данных в xml /// </summary> /// <param name="workers">Список сотрудников</param> /// <param name="filePath">Файл, в который будут записаны трансформированные json данные</param> public void Transform(List <Employee> workers, string filePath) { try { string tempFileName = Path.GetTempFileName(); Serializing.JsonSerialize(workers, tempFileName); string json = File.ReadAllText(tempFileName); File.Delete(tempFileName); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { DateParseHandling = DateParseHandling.None }; XmlDocument doc = JsonConvert.DeserializeXmlNode("{\"Workers\":" + json + "}", "WorkersList"); doc.Save(filePath); } catch (Exception ex) { throw ex; } }
/// <summary> /// Runs when options menu is clicked on /// </summary> /// <param name="index">entry Index</param> private void optionsMenuClick(int index) { if (index == 1) { if (Screen.GameOptions.UseLifes) { Screen.GameOptions.Lifes = Screen.GameOptions.Lifes == 9 ? 1 : Screen.GameOptions.Lifes + 1; } else { Screen.GameOptions.Minutes = Screen.GameOptions.Minutes == 9 ? 1 : Screen.GameOptions.Minutes + 1; } } else if (index == 0) { Screen.GameOptions.UseLifes = !Screen.GameOptions.UseLifes; } Serializing.SaveGameOptions(Screen.GameOptions); menuView.SetEntries(World, Screen.GameOptions.CreateMenu(optionsMenuClick).ToArray()); menuView.AddEntries(World, new MenuEntry("Close Menu", closeMenuBox), new MenuEntry("Exit Game", exitGame)); }
private void LoadMaps(ContentManager content) { //Loads all the map models from json textfiles mapModels = Serializing.LoadMaps(); mapThumbs = new List <ImageController>(); int row = 0, column = 0, i = 0; foreach (var map in mapModels) { ImageController thumb = new ImageController(Screen, map.thumbImage, 3, true); thumb.IsVisible = false; thumb.ScaleDefault = 0.1f; thumb.OriginDefault = new Vector2(300, 230) / 2; ImageModel img = thumb.SetPosition(300 * column + 200, row * 230 + 180); img.SetBoundBox(World, 280, 210, Vector2.Zero, Category.Cat5, Category.Cat4, true); img.BoundBox.IsSensor = true; img.BoundBox.Enabled = false; img.BoundBox.UserData = i; AddController(thumb); mapThumbs.Add(thumb); if (column == 3) { row++; column = 0; } else { column++; } i++; } }
public void WriteBool(bool Value) { Serializing.WriteBool(Value, ref buffer, ref OffSet); }
private void OnSerializing(SerializeEventArgs e) { Serializing?.Invoke(this, e); }
protected virtual void OnSerializing(SerializeEventArgs e) { Serializing?.Invoke(this, e); }
public float ReadFloat() { return(Serializing.ReadFloat(ref buffer, ref OffSet)); }
/// <summary> /// Triggers the Serializing event. /// </summary> /// <param name="ea">The event arguments.</param> public virtual void OnSerializing(SerializingEventArgs ea) { Serializing?.Invoke(this, ea); }
public void WriteDouble(double Value) { Serializing.WriteDouble(Value, ref buffer, ref OffSet); }
public bool ReadBool() { return(Serializing.ReadBool(ref buffer, ref OffSet)); }
/// <summary> /// 触发序列化开始前事件 /// </summary> public void OnBeforeSerialize() { Body.DetachEvent(); Serializing?.Invoke(this, EventArgs.Empty); }
public void WriteFloat(float Value) { Serializing.WriteFloat(Value, ref buffer, ref OffSet); }
public double ReadDouble() { return(Serializing.ReadDouble(ref buffer, ref OffSet)); }