private void ItemListDoubleClicked(object sender, MouseButtonEventArgs e) { if (CollectionValues.SelectedIndex < 0) { return; } DisplayableString item = (DisplayableString)CollectionValues.SelectedItem; if (_instanceValue.Fields != null && _instanceValue.Fields.Length == 1 && _instanceValue.Fields[0].Kind == ClrElementKind.String) { if (!item.IsLong()) { return; } var fld = _instanceValue.Fields[0]; var inst = new InstanceValue(fld.TypeId, fld.Address, fld.TypeName, string.Empty, item.FullContent); Dispatcher.CurrentDispatcher.InvokeAsync(() => ValueWindows.ShowContentWindow(fld.GetDescription(), inst, ValueWindows.WndType.Content)); return; } ulong addr = GetAddressFromEntry(item.FullContent); if (addr != Constants.InvalidAddress) { Dispatcher.CurrentDispatcher.InvokeAsync(() => ((MainWindow)Owner).ExecuteInstanceValueQuery("Getting object value at: " + Utils.RealAddressString(addr), addr)); } }
/// <summary> /// Invokes a given class. /// </summary> /// <param name="vm">The environment in which to invoke the class.</param> /// <param name="value">The class to invoke.</param> /// <returns>A new <see cref="InstanceValue"/> of the given class.</returns> /// <exception cref="Exception"> /// If Rhs doesn't return a <see cref="Block"/> or /// if 'init()' doesn't return a <see cref="NilValue"/>. /// </exception> private Value InvokeClass(VM vm, ClassValue value) { var self = new InstanceValue(value); if (value.Methods.ContainsKey("init")) { var init = value.Methods["init"].Lambda; Block args = Rhs as Block; if (args == null) { throw new Exception("Internal: 'rhs' of 'Invocation' was not a 'Block'."); } VM @new = new VM(null, vm.Global); @new.Constants.Add(value.Name, value); @new.Constants.Add("self", self); SetArguments(vm, @new, init, args.Nodes); try { init.Body.Execute(@new); } catch (ReturnStatement.Signal sig) { if (!sig.Value.IsNil()) { throw new Exception("Cannot return a non-nil value from class initializer."); } } } return(self); }
//Reads data from xml file and creates a dictionary based off of that. IDictionary <System.Xml.Linq.XName, InstanceValue> LoadInstanceDataFromFile(Stream inputStream) { IDictionary <System.Xml.Linq.XName, InstanceValue> data = new Dictionary <System.Xml.Linq.XName, InstanceValue>(); var s = new NetDataContractSerializer(); var doc = new XmlDocument(); using (var rdr = XmlReader.Create(inputStream)) doc.Load(rdr); var instances = doc.GetElementsByTagName("InstanceValue"); foreach (XmlElement instanceElement in instances) { var keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key"); var key = (System.Xml.Linq.XName)DeserializeObject(s, keyElement); var valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value"); var value = DeserializeObject(s, valueElement); var instVal = new InstanceValue(value); data.Add(key, instVal); } return(data); }
public void SetParameterValue(string name, object value) { if (string.Compare(name, ActionAssignInstance.Instance_Value, StringComparison.Ordinal) == 0) { InstanceValue.SetValue(value); if (_valueChanged != null) { _valueChanged(this, EventArgs.Empty); } } if (_var != null) { if (string.Compare(name, ActionAssignInstance.Instance_Type, StringComparison.Ordinal) == 0) { bool typeChanged = false; DataTypePointer dp = value as DataTypePointer; if (dp != null) { if (_var.ClassType.IsAssignableFrom(dp)) { InstanceType.SetValue(dp); typeChanged = true; } } if (typeChanged) { if (_valueChanged != null) { _valueChanged(this, EventArgs.Empty); } } } } }
public void UpdateInstanceValue(InstanceValue instVal, string descr) { _instValue = instVal; Title = TypeExtractor.GetDisplayableTypeName(instVal.TypeName); CollectionInfo.Text = GuiUtils.GetExtraDataString(instVal.ExtraData as KeyValuePair <string, string>[], instVal.TypeName, instVal.Address); KeyValuePairs.ItemsSource = instVal.KeyValuePairs; }
void ReadInstanceMetadataChanges(SqlDataReader reader, Dictionary <XName, InstanceValue> instanceMetadata) { Exception exception = StoreUtilities.GetNextResultSet(base.InstancePersistenceCommand.Name, reader); if (exception == null) { if (reader.IsDBNull(1)) { return; } } do { InstanceEncodingOption encodingOption = (InstanceEncodingOption)reader.GetByte(1); byte[] serializedMetadataChanges = (byte[])reader.GetValue(2); Dictionary <XName, InstanceValue> metadataChangeSet = SerializationUtilities.DeserializeMetadataPropertyBag(serializedMetadataChanges, encodingOption); foreach (KeyValuePair <XName, InstanceValue> metadataChange in metadataChangeSet) { XName xname = metadataChange.Key; InstanceValue propertyValue = metadataChange.Value; if (propertyValue.Value is DeletedMetadataValue) { instanceMetadata.Remove(xname); } else { instanceMetadata[xname] = propertyValue; } } }while (reader.Read()); }
//Reads data from xml file and creates a dictionary based off of that. IDictionary <XName, InstanceValue> LoadInstanceDataFromFile(Stream inputStream) { IDictionary <XName, InstanceValue> data = new Dictionary <XName, InstanceValue>(); NetDataContractSerializer s = new NetDataContractSerializer(); XmlReader rdr = XmlReader.Create(inputStream); XmlDocument doc = new XmlDocument(); doc.Load(rdr); XmlNodeList instances = doc.GetElementsByTagName("InstanceValue"); foreach (XmlElement instanceElement in instances) { XmlElement keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key"); XName key = (XName)DeserializeObject(s, keyElement); XmlElement valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value"); object value = DeserializeObject(s, valueElement); InstanceValue instVal = new InstanceValue(value); data.Add(key, instVal); } return(data); }
public void UpdateInstanceValue(InstanceValue instVal, string descr) { _instanceValue = instVal; Debug.Assert(instVal.ArrayValues != null); Title = TypeExtractor.GetDisplayableTypeName(instVal.TypeName); CollectionValues.ItemsSource = instVal.ArrayValues; CollectionInfo.Text = descr == null?GuiUtils.GetExtraDataString(instVal.ExtraData as KeyValuePair <string, string>[], instVal.TypeName, instVal.Address) : descr; }
public override object Visit(InstanceValue e) { if (e.I is NamedInstance) { (e.I as NamedInstance).name = applyFullUri((e.I as NamedInstance).name); } return(base.Visit(e)); }
public static bool IsPropertyTypeSqlVariantCompatible(InstanceValue value) { if (((!value.IsDeletedValue && (value.Value != null)) && (!(value.Value is string) || (((string)value.Value).Length > 0xfa0))) && (((!(value.Value is Guid) && !(value.Value is DateTime)) && (!(value.Value is int) && !(value.Value is double))) && ((!(value.Value is float) && !(value.Value is long)) && ((!(value.Value is short) && !(value.Value is byte)) && (!(value.Value is decimal) || !CanDecimalBeStoredAsSqlVariant((decimal)value.Value)))))) { return(false); } return(true); }
public override object Visit(InstanceValue e) { if (e.I is NamedInstance) { (e.I as NamedInstance).name = removeDefaultPfx((e.I as NamedInstance).name); } return(base.Visit(e)); }
public static string InstanceValueValueString(InstanceValue val) { var value = val.Value.ToString(); return((value.Length > 0 && value[0] == Constants.NonValueChar) ? (Constants.FancyKleeneStar.ToString() + Utils.RealAddressString(val.Address)) : val.Value.ToString()); }
public object Visit(InstanceValue e) { if (e.modality != Statement.Modality.IS && !(e.I is NamedInstance)) { return(CreateNull()); } return(INSVAL((e.I as NamedInstance).name, e.R)); }
public CollectionDisplay(int id, string descr, InstanceValue instVal, bool locked = true) { _wndType = ValueWindows.WndType.List; _id = id; InitializeComponent(); SetLock(locked); UpdateInstanceValue(instVal, descr); Title = TypeExtractor.GetDisplayableTypeName(instVal.TypeName); }
public static void ShowContentWindow(string description, InstanceValue inst, WndType wndType) { lock (_lock) { var list = _unlockledWindows[(int)wndType]; if (list.Count > 0) { var node = list.First; list.RemoveFirst(); list.AddLast(node); node.Value.UpdateInstanceValue(inst, description); return; } int id = Utils.GetNewID(); IValueWindow wnd = null; switch (wndType) { case WndType.Content: wnd = new ContentDisplay(id, description != null ? description : inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; case WndType.Tree: wnd = new ClassStructDisplay(id, inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; case WndType.List: wnd = new CollectionDisplay(id, inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; case WndType.KeyValues: wnd = new KeyValueCollectionDisplay(id, inst.GetDescription(), inst) { Owner = GuiUtils.MainWindowInstance }; break; } if (wnd == null) { throw new MdrDeskException("[ValueWindows.ShowContentWindow] Creating content window failed."); } _wndDct.Add(id, wnd); if (!wnd.Locked) { list.AddFirst(wnd); } ((Window)wnd).Show(); } }
public void UpdateInstanceValue(InstanceValue instVal, string descr) { _path = descr; string title; _mdString = LoadHelpFile(_path, out title); DocumentViewer.Document = _markdown.Transform(_mdString); this.Title = title; }
public static StackPanel GetInstanceValueStackPanel(InstanceValue val) { var stackPanel = new StackPanel() { Orientation = Orientation.Horizontal }; stackPanel.Children.Add(GetInstanceValueTextBlock(val)); return(stackPanel); }
private static Scope GetScope(IValue type) { return(type switch { InstanceValue instanceValue => instanceValue.Item.Scope, ListValue _ => new Scope(), MapValue _ => new Scope(), StringValue _ => new Scope(), _ => throw new ArgumentOutOfRangeException(nameof(type)) });
/// <summary> /// Assigns new value to a field of an instance. /// The new value is gotten by executing <see cref="assigner"/>. /// The instance is gotten by executing <see cref="instance"/>. /// <see cref="member"/> is used to access the correct field of the instance. /// </summary> /// <param name="vm">Environment to execute <see cref="instance"/> and <see cref="assigner"/> in.</param> /// <returns>A <see cref="NilValue"/>.</returns> /// <exception cref="Exception">If <see cref="instance"/> doesn't return a <see cref="InstanceValue"/>.</exception> public Value Execute(VM vm) { Value instValue = instance.Execute(vm); Value.AssertType(Value.ValueType.Instance, instValue, "First operand of '.' expected to be an instance of a class but was given '{0}'.", instValue.Type); InstanceValue inst = instValue.Instance; inst.Fields[member] = assigner.Execute(vm); return(new NilValue()); }
// Converts XML data back to the original form. private IDictionary <XName, InstanceValue> XmlToDictionary(string data) { try { IDictionary <System.Xml.Linq.XName, InstanceValue> result = new Dictionary <System.Xml.Linq.XName, InstanceValue>(); //NetDataContractSerializer s = new NetDataContractSerializer(); JArray doc = JArray.Parse(data); foreach (JObject instanceElement in doc) { try { //XmlElement keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key"); //System.Xml.Linq.XName key = (System.Xml.Linq.XName)DeserializeObject(s, keyElement); //XmlElement valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value"); //object value = DeserializeObject(s, valueElement); var typestring = instanceElement.Value <string>("type"); Type type = Type.GetType(typestring); var json = instanceElement.Value <string>("value"); if (type.FullName == "System.Activities.Runtime.ActivityExecutor") { //var h = new System.Activities.Hosting.WorkflowInstance(null); object o = Activator.CreateInstance(type); // an instance of target type } var val = JsonConvert.DeserializeObject(json, type, new JsonSerializerSettings { Error = (sender, errorArgs) => { var currentError = errorArgs.ErrorContext.Error.Message; errorArgs.ErrorContext.Handled = true; } }); InstanceValue instVal = new InstanceValue(val); var name = instanceElement.Value <string>("key"); var xname = (XName)name; result.Add(xname, instVal); } catch (Exception ex) { Log.Error(ex.ToString()); } } return(result); } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
/// <summary> /// Calls the init method of an instance's superclass. /// </summary> /// <remarks> /// Expects a constant called 'self' to be present in the VM. /// Expects it to have a superclass with an 'init()' method. /// </remarks> /// <param name="vm">Used to access global scope.</param> /// <returns>A <see cref="NilValue"/>.</returns> /// <exception cref="Exception">If an expectation is not met or another runtime error occurs.</exception> public override Value Execute(VM vm) { if (!vm.Parent.Constants.ContainsKey("self") || !(vm.Parent.Constants["self"] is InstanceValue)) { throw new Exception("Can only call 'super()' inside a class."); } InstanceValue self = vm.Parent.Constants["self"].Instance; ClassValue selfClass = self.UpCast(); if (!selfClass.Methods.ContainsKey("<SUPER>")) { throw new Exception(string.Format("Cannot call 'super()'. '{0}' is not a subclass.", selfClass.Name)); } LambdaExpression super = selfClass.Methods["<SUPER>"].Lambda; if (Nodes.Count != super.Args.Count) { throw new Exception(string.Format( "Argument Mistmatch! {0}.super takes {1} argument(s) but was given {2}.", selfClass.Name, super.Args.Count, Nodes.Count)); } VM @new = new VM(null, vm.Global); @new.Constants.Add("self", self); for (int i = 0; i < super.Args.Count; i++) { string argId = super.Args[i]; Value arg = Nodes[i].Execute(vm); @new.Variables.Add(argId, arg); } try { super.Body.Execute(@new); } catch (ReturnStatement.Signal sig) { if (!sig.Value.IsNil()) { throw new Exception("Cannot return a value from class initializer."); } } self.Cast(selfClass); return(new NilValue()); }
public KeyValueCollectionDisplay(int id, string description, InstanceValue instVal, bool locked = true) { _wndType = ValueWindows.WndType.KeyValues; _id = id; InitializeComponent(); _lockedImg = new Image(); _lockedImg.Source = ValueWindows.LockedImage.Source; _unlockedImg = new Image(); _unlockedImg.Source = ValueWindows.UnlockedImage.Source; UpdateInstanceValue(instVal, description); _locked = locked; LockBtn.Content = locked ? _lockedImg : _unlockedImg; }
public void UpdateInstanceValue(InstanceValue instVal, string descr) { if (instVal.Parent == null) { Title = TypeExtractor.GetDisplayableTypeName(instVal.TypeName); } ClassStructInfo.Text = descr; var stackPanel = new StackPanel() { Orientation = Orientation.Horizontal }; var textBlk = new TextBlock(); textBlk.Inlines.Add(instVal.ToString()); stackPanel.Children.Add(textBlk); var tvRoot = new TreeViewItem { Header = GuiUtils.GetInstanceValueStackPanel(instVal), Tag = instVal }; var que = new Queue <KeyValuePair <InstanceValue, TreeViewItem> >(); que.Enqueue(new KeyValuePair <InstanceValue, TreeViewItem>(instVal, tvRoot)); while (que.Count > 0) { var info = que.Dequeue(); InstanceValue parentNode = info.Key; TreeViewItem tvParentNode = info.Value; InstanceValue[] descendants = parentNode.Fields; for (int i = 0, icount = descendants.Length; i < icount; ++i) { var descNode = descendants[i]; var tvNode = new TreeViewItem { Header = GuiUtils.GetInstanceValueStackPanel(descNode), Tag = descNode }; tvParentNode.Items.Add(tvNode); que.Enqueue(new KeyValuePair <InstanceValue, TreeViewItem>(descNode, tvNode)); } } var treeView = InstanceValueTreeview; treeView.Items.Clear(); treeView.Items.Add(tvRoot); tvRoot.IsSelected = true; tvRoot.ExpandSubtree(); }
private void LoadSingleEntry(NetDataContractSerializer serializer, IDictionary<XName, InstanceValue> instanceData, XElement entry) { XName key = (XName)Deserialize(serializer, entry.Element("Key")); Object value = Deserialize(serializer, entry.Element("Value")); InstanceValue iv = new InstanceValue(value); InstanceValueOptions options = (InstanceValueOptions)Deserialize( serializer, entry.Element("Options")); if(!options.HasFlag(InstanceValueOptions.WriteOnly)) { instanceData.Add(key, iv); } }
public ClassStructDisplay(int id, string description, InstanceValue instValue, bool locked = true) { _wndType = ValueWindows.WndType.Tree; _id = id; _locked = locked; InitializeComponent(); _mainWindow = GuiUtils.MainWindowInstance; _lockedImg = new Image(); _lockedImg.Source = ValueWindows.LockedImage.Source; _unlockedImg = new Image(); _unlockedImg.Source = ValueWindows.UnlockedImage.Source; UpdateInstanceValue(instValue, description); _locked = locked; LockBtn.Content = locked ? _lockedImg : _unlockedImg; }
public ContentDisplay(int id, string description, InstanceValue instVal, bool locked = true) { _wndType = ValueWindows.WndType.Content; _id = id; InitializeComponent(); _wordWrapped = true; _instanceValue = instVal; _lockedImg = new Image(); _lockedImg.Source = ValueWindows.LockedImage.Source; _unlockedImg = new Image(); _unlockedImg.Source = ValueWindows.UnlockedImage.Source; UpdateInstanceValue(instVal, description); _locked = locked; LockBtn.Content = locked ? _lockedImg : _unlockedImg; Title = TypeExtractor.GetDisplayableTypeName(instVal.TypeName); }
public static TextBlock GetInstanceValueTextBlock(InstanceValue val) { var txtBlk = new TextBlock(); if (!string.IsNullOrWhiteSpace(val.FieldName)) { txtBlk.Inlines.Add(new Run(val.FieldName + " ") { Foreground = Brushes.DarkRed, FontStyle = FontStyles.Italic }); } txtBlk.Inlines.Add(new Run(InstanceValueValueString(val)) { FontWeight = FontWeights.Bold }); txtBlk.Inlines.Add(new Run(" " + val.TypeName)); return(txtBlk); }
/// <summary> /// The deserialize data. /// </summary> /// <param name="payload">The payload.</param> /// <returns>The <see cref="IDictionary" />.</returns> private static IDictionary <XName, InstanceValue> DeserializeData(string payload) { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(payload); IDictionary <XName, InstanceValue> data = new Dictionary <XName, InstanceValue>(); var netDataContractSerializer = new NetDataContractSerializer(); var instances = xmlDocument.GetElementsByTagName("InstanceValue"); foreach (XmlElement instanceElement in instances) { var keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key"); var key = (XName)DeserializeObject(netDataContractSerializer, keyElement); var valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value"); var value = DeserializeObject(netDataContractSerializer, valueElement); var instVal = new InstanceValue(value); data.Add(key, instVal); } return(data); }
// Converts XML data back to the original form. private IDictionary <XName, InstanceValue> XmlToDictionary(XmlDocument doc) { IDictionary <System.Xml.Linq.XName, InstanceValue> data = new Dictionary <System.Xml.Linq.XName, InstanceValue>(); NetDataContractSerializer s = new NetDataContractSerializer(); XmlNodeList instances = doc.GetElementsByTagName("InstanceValue"); foreach (XmlElement instanceElement in instances) { XmlElement keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key"); System.Xml.Linq.XName key = (System.Xml.Linq.XName)DeserializeObject(s, keyElement); XmlElement valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value"); object value = DeserializeObject(s, valueElement); InstanceValue instVal = new InstanceValue(value); data.Add(key, instVal); } return(data); }
private void GetInstValueClicked(bool forKey) { string value = GetSelectionString(forKey); // true for key if (value == null) { return; } ulong addr = GetAddressFromEntry(value); if (addr != Constants.InvalidAddress) { System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeAsync(() => ((MainWindow)Owner).ExecuteInstanceValueQuery("Getting object value at: " + Utils.RealAddressString(addr), addr)); } if (DisplayableString.IsLargeString(value)) { var inst = new InstanceValue(Constants.InvalidIndex, ClrElementKind.Unknown, Constants.InvalidAddress, "FROM: " + _instValue.TypeName, null, value); ValueWindows.ShowContentWindow("A collection item " + (forKey ? "key." : "value."), inst, ValueWindows.WndType.Content); return; } ((MainWindow)Owner).MainStatusShowMessage("The value requested cannot be elaborated more. The values is what you see."); }