public override void ReadExternal(IMemento memento, ExternalizeContext context) { base.ReadExternal(memento, context); if (memento.Contains("Outgoings")) { foreach (var ex in memento.ReadExternalizables("Outgoings")) { var edge = ex as IConnection; if (edge != null) { _Outgoings.Add(edge); } } } if (memento.Contains("Incomings")) { foreach (var ex in memento.ReadExternalizables("Incomings")) { var edge = ex as IConnection; if (edge != null) { _Incomings.Add(edge); } } } }
public virtual void ReadExternal(IMemento memento, ExternalizeContext context) { _isVisible = memento.ReadBool("IsVisible"); _layout = memento.ReadExternalizable("Layout") as ILayout; if (_layout != null) { _layout.Owner = this; } if (memento.Contains("LayoutConstraints")) { var constraints = memento.ReadSerializable("LayoutConstraints") as Dictionary <IMemento, object>; if (constraints.Count > 0) { foreach (var pair in constraints) { var child = context.GetExternalizable("Children", pair.Key) as IFigure; LayoutConstraints[child] = pair.Value; } } } if (memento.Contains("PersistentData")) { var data = memento.ReadSerializable("PersistentData") as Dictionary <string, object>; if (data.Count > 0) { foreach (var pair in data) { PersistentData[pair.Key] = pair.Value; } } } if (memento.Contains("Children")) { var children = memento.ReadExternalizables("Children"); foreach (var child in children) { var childFig = child as IFigure; if (childFig != null) { Children.Add(childFig); } } } }
public void ReadExternal(IMemento memento, ExternalizeContext context) { _inLoading = true; var modelSerializer = context.ExtendedData[EditorConsts.ModelSerializerKey] as IModelSerializer; var site = context.ExtendedData[EditorConsts.EditorSiteKey] as IEditorSite; if (modelSerializer == null || site == null) { throw new ArgumentException("context.ExtendedData is invalid"); } var model = modelSerializer.Load(memento.ReadSerializable("ModelHint")); var fig = memento.ReadExternalizable("Figure") as IFigure; var ctrl = site.ControllerFactory.CreateController(model); /// Controllerは作り直す Model = model; _Figure = fig; _Controller = ctrl; using (Figure.DirtManager.BeginDirty()) { ctrl.ConfigureEditor(this); if (memento.Contains("Children")) { foreach (var child in memento.ReadExternalizables("Children")) { var childEditor = child as Editor; if (childEditor != null) { AddChildEditor(childEditor); } } } RelocateAllHandles(); RelocateFocus(); //Refresh(); //Enable(); } _inLoading = false; }
public void LoadFrom(IMemento memento, ExternalizeContext context) { var type = _target.GetType(); foreach (var prop in _properties) { var externalAttr = TypeService.Instance.GetExternalAttribute(prop); if (externalAttr == null) { continue; } var propName = prop.Name; var value = memento.ReadSerializable(propName); if (value == null) { continue; } var valueType = value.GetType(); var propType = prop.PropertyType; if (GenericTypeUtil.IsGenericIDictionary(propType)) { var elemTypes = GenericTypeUtil.GetGenericArgumentOfGenericIDictionary(valueType); var dictKeyType = elemTypes[0]; var dictValueType = elemTypes[1]; var setItemMethod = propType.GetMethod("set_Item"); if (typeof(IMemento).IsAssignableFrom(dictKeyType)) { if (typeof(IMemento).IsAssignableFrom(dictValueType)) { var dict = memento.ReadSerializable(propName) as IDictionary <IMemento, IMemento>; foreach (var pair in dict) { var keyEx = context.GetExternalizable(propName, pair.Key); var valEx = context.GetExternalizable(propName, pair.Value); if (keyEx != null && valEx != null) { setItemMethod.Invoke(value, new[] { keyEx, valEx }); } } } else { var dict = memento.ReadSerializable(propName) as IDictionary <IMemento, object>; foreach (var pair in dict) { var keyEx = context.GetExternalizable(propName, pair.Key); if (keyEx != null) { setItemMethod.Invoke(value, new[] { keyEx, pair.Value }); } } } } else { if (typeof(IMemento).IsAssignableFrom(dictValueType)) { var dict = memento.ReadSerializable(propName) as IDictionary <object, IMemento>; foreach (var pair in dict) { var valEx = context.GetExternalizable(propName, pair.Value); if (valEx != null) { setItemMethod.Invoke(value, new[] { pair.Key, valEx }); } } } else { var dict = memento.ReadSerializable(propName) as IDictionary <object, IMemento>; foreach (var pair in dict) { setItemMethod.Invoke(value, new[] { pair.Key, pair.Value, }); } } } } else if (GenericTypeUtil.IsGenericICollection(propType)) { var elemType = GenericTypeUtil.GetGenericArgumentOfGenericICollection(valueType); if (typeof(IMemento).IsAssignableFrom(elemType)) { var add = externalAttr.Add; var addMethod = add != null?type.GetMethod(add) : propType.GetMethod("Add"); var list = prop.GetValue(_target, null); var externalizables = memento.ReadExternalizables(propName); foreach (var ex in externalizables) { addMethod.Invoke(list, new[] { ex }); } } else { var add = externalAttr.Add; var addMethod = add != null?type.GetMethod(add) : propType.GetMethod("Add"); var list = prop.GetValue(_target, null); var deserialized = memento.ReadSerializable(propName) as IEnumerable; foreach (var ex in deserialized) { addMethod.Invoke(list, new[] { ex }); } } } else if (GenericTypeUtil.IsGenericIEnumerable(propType) && externalAttr.Add != null) { var elemType = GenericTypeUtil.GetGenericArgumentOfGenericIEnumerable(valueType); if (typeof(IMemento).IsAssignableFrom(elemType)) { var add = externalAttr.Add; var addMethod = type.GetMethod(add); var externalizables = memento.ReadExternalizables(propName); foreach (var ex in externalizables) { addMethod.Invoke(_target, new[] { ex }); } } else { var add = externalAttr.Add; var addMethod = type.GetMethod(add); var deserialized = memento.ReadSerializable(propName) as IEnumerable; foreach (var ex in deserialized) { addMethod.Invoke(_target, new[] { ex }); } } } else { if (valueType.IsPrimitive) { prop.SetValue(_target, memento.ReadSerializable(propName), null); } else { if (typeof(IMemento).IsAssignableFrom(valueType)) { prop.SetValue(_target, memento.ReadExternalizable(propName), null); } else { prop.SetValue(_target, memento.ReadSerializable(propName), null); } } } } var externalizableAttr = TypeService.Instance.GetExternalizableAttribute(_type); if (externalizableAttr.Loaded != null) { var loaded = _type.GetMethod(externalizableAttr.Loaded); loaded.Invoke(_target, new object[] { memento, context }); } }