public StreamExpect()
 {
     streamState = new ObjectValue<int>(0);
     timer = new Timer(HandleReadTimeout, null, Timeout.Infinite, Timeout.Infinite);
     timeoutOn = DateTime.Now;
     ReadTimeout = 1000;
 }
        public void TypeRepositoryTest()
        {
            TypeRepository.Clear();

            var objValue = new ObjectValue(new List<JsonField>()
                {
                    new JsonField("aa", new NullValue()),
                    new JsonField("bb", new BoolValue(true)),
                    new JsonField("cc", new NumericValue(0))
                });
            var typ = TypeRepository.CreateType(objValue);
            typ.Fields["aa"].TypeName.Is("null");
            typ.Fields["bb"].TypeName.Is("bool");
            typ.Fields["cc"].TypeName.Is("double");
            objValue = new ObjectValue(new List<JsonField>()
                {
                    new JsonField("aa", new StringValue("test")),
                    new JsonField("bb", new NullValue()),
                    new JsonField("cc", new NumericValue(0))
                });
            var name = objValue.TypeName;
            name.Is(typ.Name);
            typ.Fields["aa"].TypeName.Is("string", "null -> string への昇格");
            typ.Fields["bb"].TypeName.Is("bool?", "bool -> bool? への昇格");
        }
 public TerminalRemoteFileSystemInfo(RecorderContext context, string fullName, string name)
 {
     Context = context;
     this.fullName = fullName;
     this.name = name;
     exists = new ObjectValue<int>(-1);
     directory = new ObjectValue<RecorderFileSystemInfo>();
 }
 public RemoteKernelPath(string ip, string user, string password)
 {
     this.user = user;
     this.ip = ip;
     this.password = password;
     status = new ObjectValue<int>(0);
     lastRefresh = DateTime.Now.Subtract(new TimeSpan(365, 0, 0, 0));
     translations = new Dictionary<string, string[]>();
     RefreshPeriod = 3600000;
 }
 public static JsonObjectType CreateTypeWithName(string name, ObjectValue objectValue)
 {
     var jsonObjectType = new JsonObjectType(name, true )
         {
             OriginalObject = objectValue
         };
     foreach (var field in objectValue.Fields)
     {
         jsonObjectType.Fields.Add(field.Name, new JsonObjectField(field.Value.TypeName));
     }
     _types.Add(jsonObjectType);
     return jsonObjectType;
 }
 public static JsonObjectType CreateType(ObjectValue objectValue)
 {
     var jsonObjectType = new JsonObjectType(CreateTmpolaryName(), false)
         {
             OriginalObject = objectValue
         };
     foreach (var field in objectValue.Fields)
     {
         jsonObjectType.Fields.Add(field.Name, new JsonObjectField( field.Value.TypeName ) );
     }
     _types.Add(jsonObjectType);
     return jsonObjectType;
 }
示例#7
0
	public static void Show(ObjectValue objVal, EditorWindow ed)
	{
		if (objVal == null)
		{
			Debug.LogError("Invalid value");
			return;
		}

		// make sure DB is loaded
		if (!UniRPGEditorGlobal.LoadDatabase()) return;

		// create window
		GlobalVarSelectWiz window = EditorWindow.GetWindow<GlobalVarSelectWiz>(true, "Select Variable",true);
		window.inited = false;
		window.ed = ed;
		window.objVal = objVal;

		// show window
		window.ShowUtility();
	}
示例#8
0
        public static ObjectValue ConvertToColorObject(ScriptContext ctx, Color color)
        {
            AbstractFunctionObject colorConstructor = ctx.Srm.CalcExpression("Graphics == null ? null : Graphics.Color")
                as AbstractFunctionObject;

            ObjectValue obj;

            if (colorConstructor != null)
            {
                obj = ctx.CreateNewObject(colorConstructor) as ObjectValue;
            }
            else
            {
                obj = new ObjectValue();
            }

            obj["a"] = color.A;
            obj["r"] = color.R;
            obj["g"] = color.G;
            obj["b"] = color.B;

            return obj;
        }
示例#9
0
        private void ExecuteButton_Click(object sender, RoutedEventArgs e)
        {
            Expression Exp;
            TextBlock  ScriptBlock;

            try
            {
                string s = this.Input.Text.Trim();
                if (string.IsNullOrEmpty(s))
                {
                    return;
                }

                Exp = new Expression(s);

                ScriptBlock = new TextBlock()
                {
                    Text         = this.Input.Text,
                    FontFamily   = new FontFamily("Courier New"),
                    TextWrapping = TextWrapping.Wrap
                };

                ScriptBlock.PreviewMouseDown += TextBlock_PreviewMouseDown;

                this.HistoryPanel.Children.Add(ScriptBlock);
                this.HistoryScrollViewer.ScrollToBottom();

                this.Input.Text = string.Empty;
                this.Input.Focus();
            }
            catch (Exception ex)
            {
                ex = Log.UnnestException(ex);
                MessageBox.Show(this, ex.Message, "Unable to parse script.", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Task.Run(() =>
            {
                try
                {
                    IElement Ans;

                    try
                    {
                        Ans = Exp.Root.Evaluate(this.variables);
                    }
                    catch (ScriptReturnValueException ex)
                    {
                        Ans = ex.ReturnValue;
                    }
                    catch (Exception ex)
                    {
                        Ans = new ObjectValue(ex);
                    }

                    this.variables["Ans"] = Ans;

                    this.Dispatcher.Invoke(() =>
                    {
                        SKImage Img;

                        if (Ans is Graph G)
                        {
                            using (SKImage Bmp = G.CreateBitmap(this.variables, out object[] States))
                            {
                                this.AddImageBlock(ScriptBlock, Bmp, G, States);
                            }
                        }
                        else if ((Img = Ans.AssociatedObjectValue as SKImage) != null)
                        {
                            this.AddImageBlock(ScriptBlock, Img, null, null);
                        }
                        else if (Ans.AssociatedObjectValue is Exception ex)
                        {
                            ex = Log.UnnestException(ex);

                            if (ex is AggregateException ex2)
                            {
                                foreach (Exception ex3 in ex2.InnerExceptions)
                                {
                                    ScriptBlock = this.AddTextBlock(ScriptBlock, ex3.Message, Colors.Red, FontWeights.Bold);
                                }
                            }
                            else
                            {
                                this.AddTextBlock(ScriptBlock, ex.Message, Colors.Red, FontWeights.Bold);
                            }
                        }
                        else
                        {
                            this.AddTextBlock(ScriptBlock, Ans.ToString(), Colors.Red, FontWeights.Normal);
                        }
                    });
                }
        public void Objects()
        {
            ObjectValue value1 = new ObjectValue();
            ObjectValue value2 = new ObjectValue();
            ObjectValue value3 = new ObjectValue();
            ObjectValue value4 = new ObjectValue();
            ObjectValue value5 = new ObjectValue();

            value1.Entity = Builder.Create<TestEntity>();
            value2.Entity = value1.Entity;
            value3.Entity = Builder.Create<TestEntity>();
            value4.Entity = null;
            value5.Entity = null;

            Assert.That(value1 == value2);
            Assert.That(value1 != value3);
            Assert.That(value4 == value5);
            Assert.That(value1 != value4);
            Assert.That(value4 != value1);
            Assert.That(value1 != null);
            Assert.That(null != value1);
        }
示例#11
0
        public void VirtualProperty()
        {
            var soft = Session as SoftDebuggerSession;

            if (soft != null && soft.ProtocolVersion < new Version(2, 31))
            {
                Assert.Ignore("A newer version of the Mono runtime is required.");
            }

            IgnoreVsDebugger("TODO: make virtual properties in NetCoreDebugger work like Sdb");

            var ops = EvaluationOptions.DefaultOptions.Clone();

            ops.FlattenHierarchy = false;

            ObjectValue val = Frame.GetExpressionValue("c", ops);

            Assert.IsNotNull(val);
            val = val.Sync();
            Assert.IsFalse(val.IsError);
            Assert.IsFalse(val.IsUnknown);

            // The C class does not have a Prop property

            ObjectValue prop = val.GetChildSync("Prop", ops);

            Assert.IsNull(prop);

            prop = val.GetChildSync("PropNoVirt1", ops);
            Assert.IsNull(prop);

            prop = val.GetChildSync("PropNoVirt2", ops);
            Assert.IsNull(prop);

            val = val.GetChildSync("base", ops);
            Assert.IsNotNull(val);
            val.WaitHandle.WaitOne();
            Assert.IsFalse(val.IsError);
            Assert.IsFalse(val.IsUnknown);

            // The B class has a Prop property, value is 2

            prop = val.GetChildSync("Prop", ops);
            Assert.IsNotNull(prop);
            Assert.AreEqual("2", prop.Value);

            prop = val.GetChildSync("PropNoVirt1", ops);
            Assert.IsNotNull(prop);
            Assert.AreEqual("2", prop.Value);

            prop = val.GetChildSync("PropNoVirt2", ops);
            Assert.IsNotNull(prop);
            Assert.AreEqual("2", prop.Value);

            val = val.GetChildSync("base", ops);
            Assert.IsNotNull(val);
            val.WaitHandle.WaitOne();
            Assert.IsFalse(val.IsError);
            Assert.IsFalse(val.IsUnknown);

            // The A class has a Prop property, value is 1, but must return 2 becasue it is overriden

            prop = val.GetChildSync("Prop", ops);
            Assert.IsNotNull(prop);
            Assert.AreEqual("2", prop.Value);

            prop = val.GetChildSync("PropNoVirt1", ops);
            Assert.IsNotNull(prop);
            Assert.AreEqual("1", prop.Value);

            prop = val.GetChildSync("PropNoVirt2", ops);
            Assert.IsNotNull(prop);
            Assert.AreEqual("1", prop.Value);
        }
示例#12
0
 public bool StoreValue(ObjectValue val)
 {
     return(false);
 }
示例#13
0
 public static void ShowPreviewVisualizer(ObjectValue val, MonoDevelop.Components.Control widget, Gdk.Rectangle previewButtonArea)
 {
     PreviewWindowManager.Show(val, widget, previewButtonArea);
 }
示例#14
0
 internal static bool HasPreviewVisualizer(ObjectValue val)
 {
     return(GetPreviewVisualizer(val) != null);
 }
示例#15
0
 internal static bool HasValueVisualizers(ObjectValue val)
 {
     return(GetValueVisualizers(val).Any());
 }
示例#16
0
        private VariableKeyBase getObjectInfoStorage(ObjectValue obj)
        {
            var name = string.Format("$obj{0}#info", obj.UID);

            return(getMeta(name));
        }
示例#17
0
 public NotEqualCondition(IFilterFactory filterFactory, IFilter leftPart, ObjectValue rightPart)
     : base(filterFactory, leftPart, rightPart, rightPart.IsNull ? IsNot : NotEqual)
 {
 }
示例#18
0
        public UnityDebugSession() : base()
        {
            m_ResumeEvent     = new AutoResetEvent(false);
            m_Breakpoints     = new SourceBreakpoint[0];
            m_VariableHandles = new Handles <ObjectValue[]>();
            m_FrameHandles    = new Handles <Mono.Debugging.Client.StackFrame>();
            m_SeenThreads     = new Dictionary <int, VSCodeDebug.Thread>();

            m_DebuggerSessionOptions = new DebuggerSessionOptions {
                EvaluationOptions = EvaluationOptions.DefaultOptions
            };

            m_Session             = new UnityDebuggerSession();
            m_Session.Breakpoints = new BreakpointStore();

            m_Catchpoints = new List <Catchpoint>();

            DebuggerLoggingService.CustomLogger = new CustomLogger();

            m_Session.ExceptionHandler = ex => {
                return(true);
            };

            m_Session.LogWriter = (isStdErr, text) => {
            };

            m_Session.TargetStopped += (sender, e) => {
                if (e.Backtrace != null)
                {
                    Frame = e.Backtrace.GetFrame(0);
                }
                else
                {
                    SendOutput("stdout", "e.Bracktrace is null");
                }
                Stopped();
                SendEvent(CreateStoppedEvent("step", e.Thread));
                m_ResumeEvent.Set();
            };

            m_Session.TargetHitBreakpoint += (sender, e) => {
                Frame = e.Backtrace.GetFrame(0);
                Stopped();
                SendEvent(CreateStoppedEvent("breakpoint", e.Thread));
                m_ResumeEvent.Set();
            };

            m_Session.TargetExceptionThrown += (sender, e) => {
                Frame = e.Backtrace.GetFrame(0);
                for (var i = 0; i < e.Backtrace.FrameCount; i++)
                {
                    if (!e.Backtrace.GetFrame(i).IsExternalCode)
                    {
                        Frame = e.Backtrace.GetFrame(i);
                        break;
                    }
                }
                Stopped();
                var ex = DebuggerActiveException();
                if (ex != null)
                {
                    m_Exception = ex.Instance;
                    SendEvent(CreateStoppedEvent("exception", e.Thread, ex.Message));
                }
                m_ResumeEvent.Set();
            };

            m_Session.TargetUnhandledException += (sender, e) => {
                Stopped();
                var ex = DebuggerActiveException();
                if (ex != null)
                {
                    m_Exception = ex.Instance;
                    SendEvent(CreateStoppedEvent("exception", e.Thread, ex.Message));
                }
                m_ResumeEvent.Set();
            };

            m_Session.TargetStarted += (sender, e) => {
            };

            m_Session.TargetReady += (sender, e) => {
                m_ActiveProcess = m_Session.GetProcesses().SingleOrDefault();
            };

            m_Session.TargetExited += (sender, e) => {
                DebuggerKill();

                Terminate("target exited");

                m_ResumeEvent.Set();
            };

            m_Session.TargetInterrupted += (sender, e) => {
                m_ResumeEvent.Set();
            };

            m_Session.TargetEvent += (sender, e) => {
            };

            m_Session.TargetThreadStarted += (sender, e) => {
                int tid = (int)e.Thread.Id;
                lock (m_SeenThreads) {
                    m_SeenThreads[tid] = new Thread(tid, e.Thread.Name);
                }
                SendEvent(new ThreadEvent("started", tid));
            };

            m_Session.TargetThreadStopped += (sender, e) => {
                int tid = (int)e.Thread.Id;
                lock (m_SeenThreads) {
                    m_SeenThreads.Remove(tid);
                }
                SendEvent(new ThreadEvent("exited", tid));
            };

            m_Session.OutputWriter = (isStdErr, text) => {
                SendOutput(isStdErr ? "stderr" : "stdout", text);
            };
        }
示例#19
0
 public virtual bool CanSetValue(ObjectValue val)
 {
     return(false);
 }
示例#20
0
 public bool DeleteValue(string propertyName)
 {
     CheckIsObject();
     return(ObjectValue.Remove(propertyName));
 }
示例#21
0
 public bool HasValue(string propertyName)
 {
     CheckIsObject();
     return(ObjectValue.ContainsKey(propertyName));
 }
示例#22
0
	/// <summary>show a field where the designer can either enter a value or choose a global variable</summary>
	public static ObjectValue GlobalObjectVarOrValueField(EditorWindow ed, string label, ObjectValue objectVal, System.Type objectType, bool allowSceneObject = true, int labelWidth = 100, int fieldWidth = 0)
	{
		if (objectVal == null)
		{
			Debug.LogWarning("GlobalObjectVarOrValueField: ObjectValue not initialised.");
			return objectVal;
		}
		EditorGUILayout.BeginHorizontal();
		{
			if (!string.IsNullOrEmpty(label))
			{
				if (labelWidth > 0) GUILayout.Label(label, GUILayout.Width(labelWidth));
				else GUILayout.Label(label);
				EditorGUILayout.Space();
			}
			if (!string.IsNullOrEmpty(objectVal.objectVarName))
			{
				GUI.enabled = false;
				if (fieldWidth > 0) EditorGUILayout.TextField(objectVal.objectVarName, GUILayout.Width(fieldWidth));
				else EditorGUILayout.TextField(objectVal.objectVarName);
				GUI.enabled = true;
			}
			else
			{
				if (fieldWidth > 0) objectVal.SetAsValue = EditorGUILayout.ObjectField(objectVal.GetValue(null), objectType, allowSceneObject, GUILayout.Width(fieldWidth));
				else objectVal.SetAsValue = EditorGUILayout.ObjectField(objectVal.GetValue(null), typeof(Object), allowSceneObject);
			}

			if (GUILayout.Button(new GUIContent(UniRPGEdGui.Icon_Tag, "Select variable"), EditorStyles.miniButton, GUILayout.Width(25)))
			{
				GlobalVarSelectWiz.Show(objectVal, ed);
			}
		}
		EditorGUILayout.EndHorizontal();
		return objectVal;
	}
示例#23
0
 public virtual void SetValue(T value, ObjectValue val)
 {
     throw new NotImplementedException();
 }
示例#24
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(
                    @"ReoScript(TM) Running Machine
Copyright(c) 2012-2013 unvell, All Rights Reserved.

Usage: ReoScript.exe [filename|-workpath|-debug|-exec|-console]");
                return;
            }


            List <string> files      = new List <string>();
            string        workPath   = null;
            bool          debug      = false;
            string        initScript = null;

            bool consoleMode = false;
            bool compileMode = false;

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i];

                    if (arg.StartsWith("-"))
                    {
                        string param = arg.Substring(1);

                        switch (param)
                        {
                        case "workpath":
                            workPath = GetParameter(args, i);
                            i++;
                            break;

                        case "debug":
                            debug = true;
                            break;

                        case "exec":
                            initScript = GetParameter(args, i);
                            i++;
                            break;

                        case "com":
                            compileMode = true;
                            break;

                        case "console":
                            consoleMode = true;
                            break;
                        }
                    }
                    else
                    {
                        files.Add(arg);
                    }
                }
            }
            catch (Exception ex)
            {
                OutLn(ex.Message);
                return;
            }

            List <FileInfo> sourceFiles = new List <FileInfo>();

            foreach (string file in files)
            {
                FileInfo fi = new FileInfo(string.IsNullOrEmpty(workPath)
                                        ? file : Path.Combine(workPath, file));

                if (!fi.Exists)
                {
                    Console.WriteLine("Resource not found: " + fi.FullName);
                }
                else
                {
                    sourceFiles.Add(fi);

                    if (string.IsNullOrEmpty(workPath))
                    {
                        workPath = fi.DirectoryName;
                    }
                }
            }

            if (string.IsNullOrEmpty(workPath))
            {
                workPath = Environment.CurrentDirectory;
            }

            // for test!
            if (compileMode)
            {
                using (StreamReader sr = new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    Console.WriteLine(unvell.ReoScript.Compiler.ReoScriptCompiler.Run(sr.ReadToEnd()));
                }
                return;
            }

            // create SRM
            ScriptRunningMachine srm = new ScriptRunningMachine(CoreFeatures.FullFeatures);

            if (debug)
            {
                new ScriptDebugger(srm);
            }

            // set to full work mode
            srm.WorkMode |= MachineWorkMode.AllowImportTypeInScript
                            | MachineWorkMode.AllowCLREventBind
                            | MachineWorkMode.AllowDirectAccess;

            // change work path
            srm.WorkPath = workPath;

            // add built-in output listener
            srm.AddStdOutputListener(new BuiltinConsoleOutputListener());

            // not finished yet!
            //srm.SetGlobalVariable("File", new FileConstructorFunction());

            try
            {
                foreach (FileInfo file in sourceFiles)
                {
                    // load script file
                    srm.Run(file);
                }

                if (!string.IsNullOrEmpty(initScript))
                {
                    srm.Run(initScript);
                }
            }
            catch (ReoScriptException ex)
            {
                string str = string.Empty;

                if (ex.ErrorObject == null)
                {
                    str = ex.ToString();
                }
                else if (ex.ErrorObject is ErrorObject)
                {
                    ErrorObject e = (ErrorObject)ex.ErrorObject;

                    str += "Error: " + e.GetFullErrorInfo();
                }
                else
                {
                    str += Convert.ToString(ex.ErrorObject);
                }

                Console.WriteLine(str);
            }

            if (consoleMode)
            {
                OutLn("\nReady.\n");

                bool isQuitRequired = false;

                while (!isQuitRequired)
                {
                    Prompt();

                    string line = In().Trim();
                    if (line == null)
                    {
                        isQuitRequired = true;
                        break;
                    }
                    else if (line.StartsWith("."))
                    {
                        srm.Load(line.Substring(1, line.Length - 1));
                    }
                    else if (line.StartsWith("/"))
                    {
                        string consoleCmd = line.Substring(1);

                        switch (consoleCmd)
                        {
                        case "q":
                        case "quit":
                        case "exit":
                            isQuitRequired = true;
                            break;

                        case "h":
                        case "help":
                            Help();
                            break;

                        default:
                            break;
                        }
                    }
                    else if (line.Equals("?"))
                    {
                        ObjectValue obj = srm.DefaultContext.ThisObject as ObjectValue;
                        if (obj != null)
                        {
                            OutLn(obj.DumpObject());
                        }
                    }
                    else if (line.StartsWith("?"))
                    {
                        string expression = line.Substring(1);
                        try
                        {
                            object value = srm.CalcExpression(expression);
                            if (value is ObjectValue)
                            {
                                OutLn(((ObjectValue)value).DumpObject());
                            }
                            else
                            {
                                OutLn(ScriptRunningMachine.ConvertToString(value));
                            }
                        }
                        catch (Exception ex)
                        {
                            OutLn("error: " + ex.Message);
                        }
                    }
                    else if (line.Length == 0)
                    {
                        continue;
                    }
                    else
                    {
                        try
                        {
                            srm.Run(line);
                        }
                        catch (ReoScriptException ex)
                        {
                            Console.WriteLine("error: " + ex.Message + "\n");
                        }
                    }
                }

                OutLn("Bye.");
            }
        }
示例#25
0
 private void Stopped()
 {
     m_Exception = null;
     m_VariableHandles.Reset();
     m_FrameHandles.Reset();
 }
示例#26
0
 /// <inheritdoc />
 public void SetObjectValue(ObjectValue objectValue)
 {
     this.objectValue = objectValue;
 }
示例#27
0
        public static ObjectValue GetChildSync(this ObjectValue val, string name, EvaluationOptions ops)
        {
            var result = val.GetChild(name, ops);

            return(result != null?result.Sync() : null);
        }
示例#28
0
        public IObjectDescriptor CreateObjectDescriptor(IWriteableSnapshotStructure targetStructure, ObjectValue createdObject, TypeValue type, MemoryIndex memoryIndex)
        {
            CopyObjectDescriptor descriptor = new CopyObjectDescriptor();

            descriptor.SetObjectValue(createdObject);
            descriptor.SetType(type);
            descriptor.SetUnknownIndex(memoryIndex);
            return(descriptor);
        }
 private void VisitObjectValue(ObjectValue node)
 {
     VisitCollection(node);
 }
示例#30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyObjectDescriptor"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="objectValue">The object value.</param>
 public CopyObjectDescriptor(TypeValue type, ObjectValue objectValue)
 {
     this.type        = type;
     this.objectValue = objectValue;
 }
示例#31
0
 internal static bool HasInlineVisualizer(ObjectValue val)
 {
     return(GetInlineVisualizer(val) != null);
 }
示例#32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyObjectDescriptor"/> class.
 /// New instance contains copy of given object.
 /// </summary>
 /// <param name="objectDescriptor">The object descriptor.</param>
 public CopyObjectDescriptor(CopyObjectDescriptor objectDescriptor)
     : base(objectDescriptor)
 {
     this.type        = objectDescriptor.type;
     this.objectValue = objectDescriptor.objectValue;
 }
示例#33
0
 public static bool HasSetConverter <T> (ObjectValue val)
 {
     return(GetSetConverter <T> (val) != null);
 }
示例#34
0
        public DebugValueWindow(Gtk.Window transientFor, PinnedWatchLocation location, StackFrame frame, ObjectValue value, PinnedWatch watch) : base(Gtk.WindowType.Toplevel)
        {
            TypeHint    = WindowTypeHint.PopupMenu;
            AllowShrink = false;
            AllowGrow   = false;
            Decorated   = false;

            TransientFor = transientFor;
            // Avoid getting the focus when the window is shown. We'll get it when the mouse enters the window
            AcceptFocus = false;

            sw = new ScrolledWindow {
                HscrollbarPolicy = PolicyType.Never,
                VscrollbarPolicy = PolicyType.Never
            };

            UpdateTreeStyle(Theme.BackgroundColor);

            if (useNewTreeView)
            {
                controller = new ObjectValueTreeViewController();
                controller.SetStackFrame(frame);
                controller.AllowEditing        = true;
                controller.PinnedWatch         = watch;
                controller.PinnedWatchLocation = location;

                treeView = controller.GetGtkControl(ObjectValueTreeViewFlags.TooltipFlags);

                if (treeView is IObjectValueTreeView ovtv)
                {
                    ovtv.StartEditing += OnStartEditing;
                    ovtv.EndEditing   += OnEndEditing;
                    ovtv.NodePinned   += OnPinStatusChanged;
                }

                controller.AddValue(value);
            }
            else
            {
                objValueTreeView = new ObjectValueTreeView();
                objValueTreeView.RootPinAlwaysVisible = true;
                objValueTreeView.HeadersVisible       = false;
                objValueTreeView.AllowEditing         = true;
                objValueTreeView.AllowPinning         = true;
                objValueTreeView.CompactView          = true;
                objValueTreeView.PinnedWatch          = watch;
                objValueTreeView.PinnedWatchLocation  = location;
                objValueTreeView.Frame = frame;

                objValueTreeView.AddValue(value);

                objValueTreeView.PinStatusChanged += OnPinStatusChanged;
                objValueTreeView.StartEditing     += OnStartEditing;
                objValueTreeView.EndEditing       += OnEndEditing;

                treeView = objValueTreeView;
            }

            treeView.Name = innerTreeName;
            treeView.Selection.UnselectAll();
            treeView.SizeAllocated += OnTreeSizeChanged;

            sw.Add(treeView);
            ContentBox.Add(sw);
            sw.ShowAll();

            ShowArrow          = true;
            Theme.CornerRadius = 3;
            PreviewWindowManager.WindowClosed += PreviewWindowManager_WindowClosed;
        }
示例#35
0
        /// <summary>
        /// Executes the POST method on the resource.
        /// </summary>
        /// <param name="Request">HTTP Request</param>
        /// <param name="Response">HTTP Response</param>
        /// <exception cref="HttpException">If an error occurred when processing the method.</exception>
        public void POST(HttpRequest Request, HttpResponse Response)
        {
            if (Request.Session == null)
            {
                throw new BadRequestException();
            }

            object Obj = Request.HasData ? Request.DecodeData() : null;
            string s   = Obj as string;
            string Tag = Request.Header["X-TAG"];

            if (string.IsNullOrEmpty(Tag))
            {
                throw new BadRequestException();
            }

            Variables Variables = new Variables();

            Request.Session.CopyTo(Variables);

            Variables["Request"]  = Request;
            Variables["Response"] = Response;

            StringBuilder sb = new StringBuilder();

            Variables.ConsoleOut = new StringWriter(sb);

            Expression Exp = null;
            IElement   Result;

            if (string.IsNullOrEmpty(s))
            {
                if (!string.IsNullOrEmpty(s = Request.Header["X-X"]) && int.TryParse(s, out int x) &&
                    !string.IsNullOrEmpty(s = Request.Header["X-Y"]) && int.TryParse(s, out int y))
                {
                    Dictionary <string, KeyValuePair <Graph, object[]> > Graphs = Variables["Graphs"] as Dictionary <string, KeyValuePair <Graph, object[]> >;
                    if (Graphs == null)
                    {
                        throw new NotFoundException();
                    }

                    KeyValuePair <Graph, object[]> Rec;

                    lock (Graphs)
                    {
                        if (!Graphs.TryGetValue(Tag, out Rec))
                        {
                            throw new NotFoundException();
                        }
                    }

                    s = Rec.Key.GetBitmapClickScript(x, y, Rec.Value);

                    Response.ContentType = "text/plain";
                    Response.Write(s);
                    Response.SendResponse();
                }
                else
                {
                    lock (this.expressions)
                    {
                        if (!this.expressions.TryGetValue(Tag, out Exp))
                        {
                            throw new NotFoundException();
                        }
                    }

                    Exp.Tag = Response;
                }
            }
            else
            {
                try
                {
                    Exp = new Expression(s);
                }
                catch (Exception ex)
                {
                    this.SendResponse(Variables, new ObjectValue(ex), null, Response, false);
                    return;
                }

                Exp.Tag = Response;

                lock (this.expressions)
                {
                    this.expressions[Tag] = Exp;
                }

                Exp.OnPreview += (sender, e) =>
                {
                    if (Exp.Tag is HttpResponse Response2 && !Response2.HeaderSent)
                    {
                        this.SendResponse(Variables, e.Preview, null, Response2, true);
                    }
                };

                Task.Run(() =>
                {
                    try
                    {
                        try
                        {
                            Result = Exp.Root.Evaluate(Variables);
                        }
                        catch (ScriptReturnValueException ex)
                        {
                            Result = ex.ReturnValue;
                        }
                        catch (Exception ex)
                        {
                            Result = new ObjectValue(ex);
                        }

                        if (Exp.Tag is HttpResponse Response2 && !Response2.HeaderSent)
                        {
                            lock (this.expressions)
                            {
                                this.expressions.Remove(Tag);
                            }

                            this.SendResponse(Variables, Result, sb, Response2, false);
                        }

                        Variables.CopyTo(Request.Session);
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                });
            }
        }
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            string type = ctx.Adapter.GetTypeName(ctx, exception.Type);

            ObjectValue excInstance = exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue = null;

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate
                {
                    ValueReference mref = exception.GetChild("Message", options);
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }
                    else
                    {
                        return(ObjectValue.CreateUnknown("Message"));
                    }
                });
            }
            else
            {
                ValueReference mref = exception.GetChild("Message", options);
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }
            if (messageValue == null)
            {
                messageValue = ObjectValue.CreateUnknown("Message");
            }

            messageValue.Name = "Message";

            // Inner exception

            ObjectValue childExceptionValue = null;

            if (withTimeout)
            {
                childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate
                {
                    ValueReference inner = exception.GetChild("InnerException", options);
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        //Console.WriteLine ("pp got child:" + type);
                        ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner);
                        ObjectValue res = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }
                    else
                    {
                        return(ObjectValue.CreateUnknown("InnerException"));
                    }
                });
            }
            else
            {
                ValueReference inner = exception.GetChild("InnerException", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    //Console.WriteLine ("pp got child:" + type);
                    ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }
            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Stack trace

            ObjectValue stackTraceValue;

            if (withTimeout)
            {
                stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate
                {
                    return(GetStackTrace(options));
                });
            }
            else
            {
                stackTraceValue = GetStackTrace(options);
            }

            ObjectValue[] children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue };
            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }
示例#37
0
 public bool CanEdit(ObjectValue val)
 {
     return(false);
 }
示例#38
0
        private void ExecuteButton_Click(object sender, RoutedEventArgs e)
        {
            Waher.Script.Expression Exp;
            TextBlock ScriptBlock;

            try
            {
                Exp = new Waher.Script.Expression(this.Input.Text);

                ScriptBlock = new TextBlock()
                {
                    Text         = this.Input.Text,
                    FontFamily   = new FontFamily("Courier New"),
                    TextWrapping = TextWrapping.Wrap,
                    Tag          = Exp
                };

                ScriptBlock.PreviewMouseDown += TextBlock_PreviewMouseDown;

                this.HistoryPanel.Children.Add(ScriptBlock);
                this.HistoryScrollViewer.ScrollToBottom();

                this.Input.Text = string.Empty;
                this.Input.Focus();
            }
            catch (Exception ex)
            {
                ex = Log.UnnestException(ex);
                MessageBox.Show(MainWindow.currentInstance, ex.Message, "Unable to parse script.", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Task.Run(() =>
            {
                try
                {
                    IElement Ans;

                    try
                    {
                        Ans = Exp.Root.Evaluate(this.variables);
                    }
                    catch (ScriptReturnValueException ex)
                    {
                        Ans = ex.ReturnValue;
                    }
                    catch (Exception ex)
                    {
                        Ans = new ObjectValue(ex);
                    }

                    this.variables["Ans"] = Ans;

                    this.Dispatcher.Invoke(() =>
                    {
                        Graph G = Ans as Graph;
                        SKImage Img;
                        object Obj;

                        if (G != null)
                        {
                            GraphSettings Settings = new GraphSettings();
                            Tuple <int, int> Size;
                            double d;

                            if ((Size = G.RecommendedBitmapSize) != null)
                            {
                                Settings.Width  = Size.Item1;
                                Settings.Height = Size.Item2;

                                Settings.MarginLeft  = (int)Math.Round(15.0 * Settings.Width / 640);
                                Settings.MarginRight = Settings.MarginLeft;

                                Settings.MarginTop     = (int)Math.Round(15.0 * Settings.Height / 480);
                                Settings.MarginBottom  = Settings.MarginTop;
                                Settings.LabelFontSize = 12.0 * Settings.Height / 480;
                            }
                            else
                            {
                                if (this.variables.TryGetVariable("GraphWidth", out Variable v) && (Obj = v.ValueObject) is double && (d = (double)Obj) >= 1)
                                {
                                    Settings.Width       = (int)Math.Round(d);
                                    Settings.MarginLeft  = (int)Math.Round(15 * d / 640);
                                    Settings.MarginRight = Settings.MarginLeft;
                                }
                                else if (!this.variables.ContainsVariable("GraphWidth"))
                                {
                                    this.variables["GraphWidth"] = (double)Settings.Width;
                                }

                                if (this.variables.TryGetVariable("GraphHeight", out v) && (Obj = v.ValueObject) is double && (d = (double)Obj) >= 1)
                                {
                                    Settings.Height        = (int)Math.Round(d);
                                    Settings.MarginTop     = (int)Math.Round(15 * d / 480);
                                    Settings.MarginBottom  = Settings.MarginTop;
                                    Settings.LabelFontSize = 12 * d / 480;
                                }
                                else if (!this.variables.ContainsVariable("GraphHeight"))
                                {
                                    this.variables["GraphHeight"] = (double)Settings.Height;
                                }
                            }

                            using (SKImage Bmp = G.CreateBitmap(Settings, out object[] States))
                            {
                                this.AddImageBlock(ScriptBlock, Bmp);
                            }
                        }
                        else if ((Img = Ans.AssociatedObjectValue as SKImage) != null)
                        {
                            this.AddImageBlock(ScriptBlock, Img);
                        }
                        else if (Ans.AssociatedObjectValue is Exception ex)
                        {
                            AggregateException ex2;

                            ex = Log.UnnestException(ex);

                            if ((ex2 = ex as AggregateException) != null)
                            {
                                foreach (Exception ex3 in ex2.InnerExceptions)
                                {
                                    ScriptBlock = this.AddTextBlock(ScriptBlock, ex3.Message, Colors.Red, FontWeights.Bold, ex3);
                                }
                            }
                            else
                            {
                                this.AddTextBlock(ScriptBlock, ex.Message, Colors.Red, FontWeights.Bold, ex);
                            }
                        }
                        else
                        {
                            this.AddTextBlock(ScriptBlock, Ans.ToString(), Colors.Red, FontWeights.Normal, true);
                        }
                    });
                }
示例#39
0
 public abstract bool CanGetValue(ObjectValue val);
示例#40
0
 public abstract T GetValue(ObjectValue val);
示例#41
0
 void AddObjectToCache(Dictionary<object, ObjectValue> objectDictionary, object objectKey, object obj) {
     objectDictionary[objectKey] = new ObjectValue(_currentImportGeneration, obj);
 }
示例#42
0
        /// <summary>
        /// Fire predefined event to call function of script
        /// </summary>
        /// <param name="eventName">Event name (global function name in script)</param>
        /// <param name="eventArg">Event arguments</param>
        public object RaiseScriptEvent(string eventName, ObjectValue eventArg)
        {
            if (srm == null)
            {
                InitSRM();
            }

            return (gridObj != null) ? srm.InvokeFunctionIfExisted(gridObj, eventName, eventArg) : null;
        }