public void BeforePropertyChanged(IDataRecord record, string name, object previousValue, object nextValue) { if (IsUndoRedo) { return; } if (CurrentUndoGroupId == null || record is UndoItem || record is RedoItem) { return; } try { var undoItem = new UndoItem(); undoItem.Time = DateTime.Now; undoItem.Group = CurrentUndoGroupId; undoItem.DataRecordId = record.Identifier; undoItem.Data = InvertJsonExtensions.SerializeObject(record).ToString(); undoItem.RecordType = record.GetType().AssemblyQualifiedName; undoItem.Type = UndoType.Changed; undoItem.Name = CurrentName; UndoItems.Add(undoItem); } catch (Exception ex) { InvertApplication.LogError(ex.Message); } }
public static IDrawer CreateDrawer <TDrawerBase>(this IUFrameContainer container, ViewModel viewModel) where TDrawerBase : IDrawer { if (_drawers != null) { } if (viewModel == null) { InvertApplication.LogError("Data is null."); return(null); } var drawer = container.ResolveRelation <TDrawerBase>(viewModel.GetType(), new object[] { viewModel }); if (drawer == null) { InvertApplication.Log(String.Format("Couldn't Create drawer for {0}.", viewModel.GetType())); } return(drawer); }
protected override void CreateContent() { base.CreateContent(); foreach (var item in GraphItem.DisplayedItems) { var vm = GetDataViewModel(item); if (vm == null) { InvertApplication.LogError(string.Format("Couldn't find view-model for {0}", item.GetType())); continue; } vm.DiagramViewModel = DiagramViewModel; ContentItems.Add(vm); } AddPropertyFields(); }
public Color GetColor(IGraphItem dataObject) { try { var item = dataObject as IDiagramNodeItem; if (item != null) { var node = item.Node as GenericNode; if (node != null) { var color = node.Config.GetColor(node); switch (color) { case NodeColor.Black: return(Color.black); case NodeColor.Blue: return(new Color(0.25f, 0.25f, 0.65f)); case NodeColor.DarkDarkGray: return(new Color(0.25f, 0.25f, 0.25f)); case NodeColor.DarkGray: return(new Color(0.45f, 0.45f, 0.45f)); case NodeColor.Gray: return(new Color(0.65f, 0.65f, 0.65f)); case NodeColor.Green: return(new Color(0.00f, 1f, 0f)); case NodeColor.LightGray: return(new Color(0.75f, 0.75f, 0.75f)); case NodeColor.Orange: return(new Color(0.059f, 0.98f, 0.314f)); case NodeColor.Pink: return(new Color(0.059f, 0.965f, 0.608f)); case NodeColor.Purple: return(new Color(0.02f, 0.318f, 0.659f)); case NodeColor.Red: return(new Color(1f, 0f, 0f)); case NodeColor.Yellow: return(new Color(1f, 0.8f, 0f)); case NodeColor.YellowGreen: return(new Color(0.604f, 0.804f, 0.196f)); } } } } catch (Exception ex) { InvertApplication.LogError(ex.Message); InvertApplication.LogError(string.Format("Node is null on get color {0} : {1}", dataObject.Label, dataObject.Identifier)); } return(Color.white); }
private void AddSection(NodeConfigSectionBase section) { //if (DiagramViewModel != null && DiagramViewModel.CurrentRepository.CurrentFilter.IsAllowed(null, section.SourceType)) return; var section1 = section as NodeConfigSectionBase; if (!IsVisible(section.Visibility)) { return; } if (!string.IsNullOrEmpty(section.Name)) { var header = new GenericItemHeaderViewModel() { Name = section.Name, NodeViewModel = this, NodeConfig = NodeConfig, SectionConfig = section1, }; //if (section.AttributeInfo != null) //{ // header.IsNewLine = inputConfig.AttributeInfo.IsNewRow; //} //else //{ // header.IsNewLine = true; //} header.AddCommand = section1.AllowAdding ? new LambdaCommand("Add Item", () => { OnAdd(section, section1, this); }) : null; ContentItems.Add(header); } if (section1.GenericSelector != null && section1.ReferenceType == null) { foreach (var item in section1.GenericSelector(GraphItem).OfType <IDiagramNodeItem>().OrderBy(p => p.Order)) { if (section.SourceType.IsAssignableFrom(item.GetType())) { var vm = GetDataViewModel(item) as GraphItemViewModel; var itemViewModel = vm as ItemViewModel; if (itemViewModel != null) { itemViewModel.IsEditable = section1.IsEditable; ApplyInputConfiguration(section, item, vm.InputConnector, section.AllowMultipleInputs); ApplyOutputConfiguration(section, item, vm.OutputConnector, section.AllowMutlipleOutputs); } if (vm == null) { InvertApplication.LogError( string.Format( "Couldn't find view-model for {0} in section {1} with child type {2}", item.GetType(), section1.Name, section1.SourceType.Name)); continue; } vm.DiagramViewModel = DiagramViewModel; ContentItems.Add(vm); } else { InvertApplication.LogError(string.Format("Types do not match {0} and {1}", section.SourceType, item.GetType())); } } } else { foreach (var item in GraphItem.PersistedItems) { if (section.SourceType.IsAssignableFrom(item.GetType())) { var vm = GetDataViewModel(item) as ItemViewModel; if (vm == null) { InvertApplication.LogError(string.Format("Couldn't find view-model for {0}", item.GetType())); continue; } vm.IsEditable = section1.IsEditable; vm.DiagramViewModel = DiagramViewModel; if (section1.HasPredefinedOptions) { vm.IsEditable = false; } ApplyInputConfiguration(section, item, vm.InputConnector, section.AllowMultipleInputs); ApplyOutputConfiguration(section, item, vm.OutputConnector, section.AllowMutlipleOutputs); ContentItems.Add(vm); } } } }
public void Execute(UndoCommand command) { Repository = Container.Resolve <IRepository>(); var undoGroup = Repository.All <UndoItem>().GroupBy(p => p.Group).LastOrDefault(); if (undoGroup == null) { return; } IsUndoRedo = true; try { foreach (var undoItem in undoGroup) { // Create redo item var redoItem = new RedoItem(); redoItem.Data = undoItem.Data; redoItem.Group = undoItem.Group; redoItem.DataRecordId = undoItem.DataRecordId; redoItem.Name = undoItem.Name; redoItem.Time = undoItem.Time; redoItem.Type = undoItem.Type; redoItem.RecordType = undoItem.RecordType; redoItem.UndoData = InvertJsonExtensions.SerializeObject(undoItem).ToString(); if (undoItem.Type == UndoType.Inserted) { var record = Repository.GetById <IDataRecord>(undoItem.DataRecordId); redoItem.Data = InvertJsonExtensions.SerializeObject(record).ToString(); Repository.Remove(record); redoItem.Type = UndoType.Removed; } else if (undoItem.Type == UndoType.Removed) { var obj = InvertJsonExtensions.DeserializeObject(Type.GetType(undoItem.RecordType), JSON.Parse(undoItem.Data).AsObject) as IDataRecord; Repository.Add(obj); redoItem.Type = UndoType.Inserted; redoItem.Data = InvertJsonExtensions.SerializeObject(obj).ToString(); } else { var record = Repository.GetById <IDataRecord>(undoItem.DataRecordId); // We don't want to signal any events on deserialization record.Repository = null; redoItem.Data = InvertJsonExtensions.SerializeObject(record).ToString(); InvertJsonExtensions.DeserializeExistingObject(record, JSON.Parse(undoItem.Data).AsObject); record.Changed = true; record.Repository = Repository; } Repository.Remove(undoItem); Repository.Add(redoItem); } } catch (Exception ex) { // If we don't catch the exception IsUndoRedo won't be set back to fals causing cascading issues InvertApplication.LogError(ex.Message); } IsUndoRedo = false; Repository.Commit(); }