예제 #1
0
        public static void ActionCall <T1, T2>(ScriptDelegate fn, T1 a1, T2 a2)
        {
            if (!fn.isValid)
            {
                return;
            }
            var ctx  = fn.ctx;
            var argv = stackalloc JSValue[2];

            argv[0] = ReflectBindValueOp.js_push_tvar <T1>(ctx, a1);
            if (argv[0].IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            argv[1] = ReflectBindValueOp.js_push_tvar <T2>(ctx, a2);
            if (argv[1].IsException())
            {
                JSApi.JS_FreeValue(ctx, argv[0]);
                throw new Exception(ctx.GetExceptionString());
            }
            var rval = fn.Invoke(ctx, 2, argv);

            JSApi.JS_FreeValue(ctx, argv[0]);
            JSApi.JS_FreeValue(ctx, argv[1]);
            if (rval.IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            JSApi.JS_FreeValue(ctx, rval);
        }
예제 #2
0
        public static RT FuncCall <RT>(ScriptDelegate fn)
        {
            if (!fn.isValid)
            {
                return(default(RT));
            }
            var ctx  = fn.ctx;
            var rval = fn.Invoke(ctx);

            if (rval.IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            RT  ret0;
            var succ = ReflectBindValueOp.js_get_tvar <RT>(ctx, rval, out ret0);

            JSApi.JS_FreeValue(ctx, rval);
            if (succ)
            {
                return(ret0);
            }
            else
            {
                throw new Exception("js exception caught");
            }
        }
예제 #3
0
        public static RT FuncCall <T1, RT>(ScriptDelegate fn, T1 a1)
        {
            if (!fn.isValid)
            {
                return(default(RT));
            }
            var ctx  = fn.ctx;
            var argv = stackalloc JSValue[1];

            argv[0] = ReflectBindValueOp.js_push_tvar <T1>(ctx, a1);
            if (argv[0].IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            var rval = fn.Invoke(ctx, 1, argv);

            if (rval.IsException())
            {
                JSApi.JS_FreeValue(ctx, argv[0]);
                throw new Exception(ctx.GetExceptionString());
            }
            RT  ret0;
            var succ = ReflectBindValueOp.js_get_tvar <RT>(ctx, rval, out ret0);

            JSApi.JS_FreeValue(ctx, rval);
            JSApi.JS_FreeValue(ctx, argv[0]);
            if (succ)
            {
                return(ret0);
            }
            else
            {
                throw new Exception("js exception caught");
            }
        }
예제 #4
0
파일: Main.cs 프로젝트: AjitKumar5/A
        private void cmdCompare_Click(object sender, EventArgs e)
        {
            string aa      = so.Tables.ToString();
            Server server1 = null;

            if (rbSQLServerAuthentication1.Checked == true)
            {
                ServerConnection conn = new ServerConnection();
                conn.ServerInstance = cboServer1.Text;
                conn.LoginSecure    = false;
                conn.Login          = txtUser1.Text;
                conn.Password       = txtPassword1.Text;
                server1             = new Server(conn);
            }
            else
            {
                ServerConnection conn = new ServerConnection();
                conn.ServerInstance = cboServer1.Text;
                server1             = new Server(conn);
            }
            try
            {
                ScriptDelegate scriptDelelegate1 = Script;

                object[] scriptingParams = new object[2];
                scriptingParams[0] = server1;
                scriptingParams[1] = cboDatabase1.Text;

                Task scriptTask1 = Task.Factory.StartNew(delegate { scriptDelelegate1(scriptingParams); });
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #5
0
 public void AddDelegate(JSValue jso, ScriptDelegate o)
 {
     _delegateMap[jso] = new WeakReference(o);
     // 不能直接保留 o -> jso 的映射 (会产生o的强引用)
     // Delegate 对 ScriptDelegate 存在强引用 (首参), ScriptDelegate 对 jsobject 存在强引用
     // AddJSValue(o, jso);
 }
예제 #6
0
 public void AddDelegate(JSValue jso, ScriptDelegate o)
 {
     if (_disposed)
     {
         return;
     }
     _delegateMap.Add(jso, o);
 }
예제 #7
0
 private void InvokeEventHandler(ScriptDelegate handler, object value)
 {
     this.InvokeScript(handler, args =>
     {
         args.DataSource = GetDataSource();
         args.Value      = value;
     });
 }
예제 #8
0
 protected void InvokeEvent(ScriptDelegate handler, dynamic value)
 {
     DataSource.InvokeScript(handler, args =>
     {
         args.DataSource = DataSource.GetName();
         args.Value      = value;
     });
 }
예제 #9
0
        public void SetScriptDelegate(ScriptDelegate del, ReleaseDelegate destroy = null)
        {
            VerifyParameters(del);

            var ctx = DelegateProxies.CreateMultiUserData(del, destroy, this);

            HarfBuzzApi.hb_unicode_funcs_set_script_func(
                Handle, DelegateProxies.ScriptProxy, ctx, DelegateProxies.ReleaseDelegateProxyForMulti);
        }
예제 #10
0
 private void InvokePropertyValueEventHandler(ScriptDelegate handler, bool force)
 {
     this.InvokeScript(handler, args =>
     {
         args.DataSource = _dataSource;
         args.Property   = _property;
         args.Value      = _value;
         args.Force      = force;
     });
 }
예제 #11
0
 private void InvokeFindAndReplaceEvent(ScriptDelegate eventDelegate)
 {
     this.InvokeScript(eventDelegate, a =>
     {
         a.FindWhat    = GetFindWhat();
         a.ReplaceWith = GetReplaceWith();
         a.MatchCase   = GetMatchCase();
         a.WholeWord   = GetWholeWord();
     });
 }
예제 #12
0
        public bool TryGetDelegate(JSValue jso, out ScriptDelegate o)
        {
            WeakReference weakRef;

            if (_delegateMap.TryGetValue(jso, out weakRef))
            {
                o = weakRef.Target as ScriptDelegate;
                return(o != null);
            }
            o = null;
            return(false);
        }
예제 #13
0
        public Delegate CreateDelegate(Type type, ScriptDelegate fn)
        {
            MethodInfo method;

            if (_delegates.TryGetValue(type, out method))
            {
                var target = Delegate.CreateDelegate(type, fn, method, true);
                fn.target = target;
                return(target);
            }
            return(null);
        }
예제 #14
0
        public static void ActionCall(ScriptDelegate fn)
        {
            if (!fn.isValid)
            {
                return;
            }
            var ctx  = fn.ctx;
            var rval = fn.Invoke(ctx);

            if (rval.IsException())
            {
                throw new Exception(ctx.GetExceptionString());
            }
            JSApi.JS_FreeValue(ctx, rval);
        }
예제 #15
0
        public GtkWebview(WebviewBridge bridge)
        {
            this.bridge     = bridge ?? throw new ArgumentNullException(nameof(bridge));
            scriptCallbacks = new ConcurrentDictionary <Guid, GAsyncReadyDelegate>();

            // need to keep the delegates around or they will get garbage collected
            scriptDelegate      = ScriptCallback;
            loadFailedDelegate  = LoadFailedCallback;
            loadDelegate        = LoadCallback;
            contextMenuDelegate = ContextMenuCallback;
            closeDelegate       = CloseCallback;
            titleChangeDelegate = TitleChangeCallback;
            uriSchemeCallback   = UriSchemeCallback;

            manager = WebKit.Manager.Create();
            GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero);

            using (GLibString name = "external")
            {
                WebKit.Manager.RegisterScriptMessageHandler(manager, name);
            }

            using (GLibString initScript = Resources.GetInitScript("Linux"))
            {
                var script = WebKit.Manager.CreateScript(initScript, WebKitInjectedFrames.AllFrames, WebKitInjectionTime.DocumentStart, IntPtr.Zero, IntPtr.Zero);
                WebKit.Manager.AddScript(manager, script);
                WebKit.Manager.UnrefScript(script);
            }

            Handle    = WebKit.CreateWithUserContentManager(manager);
            settings  = WebKit.Settings.Get(Handle);
            inspector = WebKit.Inspector.Get(Handle);

            GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero);

            customHost = new Uri(UriTools.GetRandomResourceUrl(CustomScheme));

            IntPtr context = WebKit.Context.Get(Handle);

            using (GLibString gscheme = CustomScheme)
            {
                WebKit.Context.RegisterUriScheme(context, gscheme, uriSchemeCallback, IntPtr.Zero, IntPtr.Zero);
            }
        }
예제 #16
0
        protected UndupScriptAction(PipelineContext ctx, UndupScriptAction other)
        {
            originalNode = other.originalNode;
            ScriptName   = other.ScriptName;
            ScriptBody   = other.ScriptBody;
            bodyFunc     = other.bodyFunc;

            if (ScriptName != null)
            {
                scriptDelegate = (ctx.Pipeline.CreateScriptDelegate <ScriptDelegate>(ScriptName, originalNode));
            }
            else
            {
                scriptDelegate = (ctx.Pipeline.CreateScriptExprDelegate <ScriptDelegate>(bodyFunc, originalNode));
            }
        }
        public static void InvokeScript(this View target, ScriptDelegate script, Action <dynamic> initArguments = null)
        {
            if (script != null)
            {
                dynamic arguments = new DynamicWrapper();
                dynamic context   = target.GetContext();

                arguments.Source = target;

                if (initArguments != null)
                {
                    initArguments(arguments);
                }

                script(context, arguments);
            }
        }
예제 #18
0
        public void AddDelegate(JSValue jso, ScriptDelegate o)
        {
            if (_disposing)
            {
                return;
            }
            ScriptDelegate old;

            if (TryGetDelegate(jso, out old))
            {
                old.Dispose();
            }
            _delegateMap[jso] = new WeakReference(o);
            // 不能直接保留 o -> jso 的映射 (会产生o的强引用)
            // Delegate 对 ScriptDelegate 存在强引用 (首参), ScriptDelegate 对 jsobject 存在强引用
            // AddJSValue(o, jso);
        }
예제 #19
0
        public GtkWebview(WebviewBridge bridge)
        {
            this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));

            // need to keep the delegates around or they will get garbage collected
            scriptDelegate      = ScriptCallback;
            loadFailedDelegate  = LoadFailedCallback;
            loadDelegate        = LoadCallback;
            contextMenuDelegate = ContextMenuCallback;
            closeDelegate       = CloseCallback;
            titleChangeDelegate = TitleChangeCallback;

            manager = WebKit.Manager.Create();
            GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero);

            using (GLibString name = "external")
            {
                WebKit.Manager.RegisterScriptMessageHandler(manager, name);
            }

            Handle    = WebKit.CreateWithUserContentManager(manager);
            settings  = WebKit.Settings.Get(Handle);
            inspector = WebKit.Inspector.Get(Handle);

            GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero);

            const string scheme = "spidereye";

            customHost = new Uri(UriTools.GetRandomResourceUrl(scheme));

            IntPtr context = WebKit.Context.Get(Handle);

            using (GLibString gscheme = scheme)
            {
                WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero);
            }
        }
예제 #20
0
        private void Newobj(Instruction instruction)
        {
            var methodRef = (MethodReference)instruction.Operand;
            var typeRef   = methodRef.DeclaringType;

            if (typeRef.IsArray)
            {
                var arrayType     = (ArrayType)typeRef;
                var scriptType    = ScriptContext.GetType(arrayType.ElementType);
                var hostArrayType = scriptType.HostType.MakeArrayType(arrayType.Rank);
                var callArgs      = new ScriptCallArguments(methodRef.Parameters.Count,
                                                            methodRef.Parameters.Select(_ => ScriptContext.GetType(_.ParameterType)).ToArray());

                _runtimeContext.PushToStack(Activator.CreateInstance(hostArrayType, callArgs.Arguments));
            }
            else
            {
                var scriptType   = ScriptContext.GetType(typeRef);
                var method       = scriptType.GetMethod(methodRef);
                var callArgs     = new ScriptCallArguments(method);
                var scriptObject = new ScriptObject(scriptType);

                if (scriptType.HostType.IsSubclassOf(typeof(Delegate)))
                {
                    var scriptDelegate = new ScriptDelegate(callArgs.Arguments[0],
                                                            (ScriptMethodBase)callArgs.Arguments[1]);
                    var invokeMethod = scriptType.TypeDefinition.Methods.FirstOrDefault(_ => _.Name == "Invoke");
                    if (invokeMethod != null)
                    {
                        method.Invoke(scriptObject, scriptDelegate,
                                      ScriptDelegate.GetInvokePtr(invokeMethod.Parameters.Count));
                    }
                }
                else
                {
                    method.Invoke(scriptObject, callArgs.Arguments);
                }
                _runtimeContext.PushToStack(scriptObject);
            }
        }
예제 #21
0
        private void ObjectFetch_Load(object sender, EventArgs e)
        {
            object[] scriptingParams1 = new object[6];

            try
            {
                scriptingParams1[0] = server1;
                scriptingParams1[1] = database1;
                scriptingParams1[2] = scriptOpt;
                scriptingParams1[3] = hsObject1;
            }
            catch (Exception err)
            {
                string errrr = err.Message;
            }

            object[] scriptingParams2 = new object[6];

            scriptingParams2[0] = server2;
            scriptingParams2[1] = database2;
            scriptingParams2[2] = scriptOpt;
            scriptingParams2[3] = hsObject2;

            ScriptDelegate  scriptDelelegate1 = Script;
            ScriptDelegate  scriptDelelegate2 = Script;
            CompareDelegate compareDelegate1  = CompareObjects;

            //Task scriptTask1 = new Task(obj => Script((object[])obj), scriptingParams1);
            try
            {
                Task scriptTask1 = Task.Factory.StartNew(delegate { scriptDelelegate1(scriptingParams1); });
                Task scriptTask2 = scriptTask1.ContinueWith(delegate { scriptDelelegate2(scriptingParams2); });
                Task scriptTask3 = scriptTask2.ContinueWith(delegate { compareDelegate1(); });
                //scriptTask1.Start();
            }
            catch (Exception err)
            {
                string a = err.Message;
            }
        }
예제 #22
0
        private void OnInitView(IDataSource dataSource, string elementPath, string configId, string documentId,
                                string version, string elementId, object template)
        {
            if (dataSource != null)
            {
                // Установка подсказки для редактора

                var view = dataSource.GetView();
                view.SetToolTip(elementPath);

                // Настройка источника данных открываемого редактора

                dataSource.SuspendUpdate();
                dataSource.SetEditMode();
                dataSource.SetConfigId(configId);
                dataSource.SetDocumentId(documentId);
                dataSource.SetIdFilter(elementId);
                dataSource.SetVersion(version);
                dataSource.ResumeUpdate();

                if (template != null)
                {
                    dataSource.SetSelectedItem(template);
                    dataSource.ResetModified(template);
                }

                // Регистрация источника данных, чтобы можно было найти связанные редакторы

                ScriptDelegate onClose = null;

                onClose = (c, a) =>
                {
                    view.OnClosed -= onClose;
                    _dataSources.Remove(dataSource);
                };

                view.OnClosed += onClose;
                _dataSources.Add(dataSource);
            }
        }
예제 #23
0
        public static bool js_get_delegate <T>(JSContext ctx, JSValue val, out T o)
            where T : class
        {
            //TODO: 20200320 !!! 如果 o 不是 jsobject, 且是 Delegate 但不是 ScriptDelegate, 则 ... 处理
            if (val.IsNullish())
            {
                o = null;
                return(true);
            }

            if (JSApi.JS_IsObject(val) || JSApi.JS_IsFunction(ctx, val) == 1)
            {
                ScriptDelegate fn;
                var            cache = ScriptEngine.GetObjectCache(ctx);
                if (cache.TryGetDelegate(val, out fn))
                {
                    // Debug.LogWarningFormat("cache hit {0}", heapptr);
                    o = fn.target as T;
                    return(true);
                }
                // 默认赋值操作
                var types = ScriptEngine.GetTypeDB(ctx);
                fn = new ScriptDelegate(ScriptEngine.GetContext(ctx), val);
                o  = types.CreateDelegate(typeof(T), fn) as T;

                // ScriptDelegate 拥有 js 对象的强引用, 此 js 对象无法释放 cache 中的 object, 所以这里用弱引用注册
                // 会出现的问题是, 如果 c# 没有对 ScriptDelegate 的强引用, 那么反复 get_delegate 会重复创建 ScriptDelegate
                // Debug.LogWarningFormat("cache create : {0}", heapptr);
                cache.AddDelegate(val, fn);
                return(true);
            }
            // else if (DuktapeDLL.duk_is_object(ctx, idx))
            // {
            //     return js_get_classvalue<T>(ctx, idx, out o);
            // }
            o = null;
            return(false);
        }
예제 #24
0
 public void LoadDelegate()
 {
     scriptDelegate = Parser.Create(Script);
 }
예제 #25
0
 /// <summary>
 /// Add a script to an Entity, based on a function (delegate)
 /// </summary>
 /// <param name="e">The Entity to add script to</param>
 /// <param name="scriptCode">Script to run</param>
 /// <returns>IScript object created from the function</returns>
 public static BasicScript AddScript(Entity e, ScriptDelegate scriptCode)
 {
     if (!e.HasComponent<ScriptComp>())
     {
         e.AddComponent(new ScriptComp());
         e.Refresh();
     }
     var sc = e.GetComponent<ScriptComp>();
     var script = new BasicScript(scriptCode);
     sc.Add(script);
     return script;
 }
예제 #26
0
 public BasicScript(ScriptDelegate scriptCode)
 {
     this.scriptCode = scriptCode;
 }
예제 #27
0
        /// <summary>
        /// 从 JSValue 反推 Delegate, JSValue 可能是一个 js function, cs delegate (js object) <br/>
        /// 注意: 会自动创建 ScriptDelegate 映射
        /// </summary>
        public static bool js_get_delegate(JSContext ctx, JSValue val, Type delegateType, out Delegate o)
        {
            if (val.IsNullish())
            {
                o = null;
                return(true);
            }

            // 检查 val 是否是一个委托对象 wrapped object
            if (JSApi.JS_IsObject(val))
            {
                if (js_get_classvalue <Delegate>(ctx, val, out o))
                {
                    return(o == null || o.GetType() == delegateType);
                }
                if (JSApi.JS_IsFunction(ctx, val) == 1)
                {
                    ScriptDelegate fn;
                    var            cache = ScriptEngine.GetObjectCache(ctx);

                    if (cache.TryGetDelegate(val, out fn))
                    {
                        // 已经存在映射关系, 找出符合预期类型的委托
                        o = fn.Match(delegateType);
                        if (o == null)
                        {
                            // 存在 JSValue => Delegate 的多重映射
                            var types = ScriptEngine.GetTypeDB(ctx);
                            var func  = types.GetDelegateFunc(delegateType);
                            o = Delegate.CreateDelegate(delegateType, fn, func, false);
                            if (o != null)
                            {
                                fn.Add(o);
                            }
                        }
                        return(o != null);
                    }
                    else
                    {
                        // 建立新的映射关系
                        var context = ScriptEngine.GetContext(ctx);
                        var types   = context.GetTypeDB();
                        var func    = types.GetDelegateFunc(delegateType);

                        if (func == null)
                        {
                            o = null;
                            return(false);
                        }

                        fn = new ScriptDelegate(context, val);
                        o  = Delegate.CreateDelegate(delegateType, fn, func, false);
                        if (o != null)
                        {
                            fn.Add(o);
                        }

                        return(o != null);
                    }
                }
            }

            o = null;
            return(false);
        }
예제 #28
0
        public GtkWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge)
        {
            this.config          = config ?? throw new ArgumentNullException(nameof(config));
            this.contentProvider = contentProvider ?? throw new ArgumentNullException(nameof(contentProvider));
            this.bridge          = bridge ?? throw new ArgumentNullException(nameof(bridge));

            // need to keep the delegates around or they will get garbage collected
            scriptDelegate      = ScriptCallback;
            loadFailedDelegate  = LoadFailedCallback;
            loadDelegate        = LoadCallback;
            contextMenuDelegate = ContextMenuCallback;
            closeDelegate       = CloseCallback;
            titleChangeDelegate = TitleChangeCallback;

            if (config.EnableScriptInterface)
            {
                manager = WebKit.Manager.Create();
                GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero);

                using (GLibString name = "external")
                {
                    WebKit.Manager.RegisterScriptMessageHandler(manager, name);
                }

                Handle = WebKit.CreateWithUserContentManager(manager);
            }
            else
            {
                Handle = WebKit.Create();
            }

            GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero);
            GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero);

            if (config.UseBrowserTitle)
            {
                GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero);
            }

            if (string.IsNullOrWhiteSpace(config.ExternalHost))
            {
                const string scheme = "spidereye";
                customHost = UriTools.GetRandomResourceUrl(scheme);

                IntPtr context = WebKit.Context.Get(Handle);
                using (GLibString gscheme = scheme)
                {
                    WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero);
                }
            }

            var bgColor = new GdkColor(config.BackgroundColor);

            WebKit.SetBackgroundColor(Handle, ref bgColor);

            if (enableDevTools)
            {
                var settings = WebKit.Settings.Get(Handle);
                WebKit.Settings.SetEnableDeveloperExtras(settings, true);
                var inspector = WebKit.Inspector.Get(Handle);
                WebKit.Inspector.Show(inspector);
            }
        }
예제 #29
0
 public void LoadDelegate()
 {
     scriptDelegate = Parser.Create(Script);
 }
예제 #30
0
 public bool TryGetDelegate(JSValue jso, out ScriptDelegate o)
 {
     return(_delegateMap.TryGetValue(jso, out o));
 }
예제 #31
0
        /// <summary>
        ///     Открыть представление или переключить фокус на открытое представление.
        /// </summary>
        /// <param name="viewKey">Уникальный ключ представления.</param>
        /// <param name="linkViewFactory">Метод получения ссылки на представление.</param>
        /// <param name="onInit">Обработчик инициализации открываемого представления.</param>
        /// <param name="onAccept">Обработчик сохранения или подтверждения данных представления.</param>
        public static void ShowView(object viewKey, Func <LinkView> linkViewFactory, Action <IDataSource> onInit = null,
                                    Action <IDataSource> onAccept = null)
        {
            View view;

            // Если представление уже открыто
            if (TryGetView(viewKey, out view))
            {
                view.Focus();
            }
            else
            {
                var linkView = linkViewFactory();

                if (linkView != null)
                {
                    // Создание представления
                    view = linkView.CreateView();

                    if (view != null)
                    {
                        // Выборка источника данных
                        var viewDataSources = view.GetDataSources();
                        var mainDataSource  = (viewDataSources != null) ? viewDataSources.FirstOrDefault() : null;

                        // Инициализация представления
                        TryInvoke(onInit, mainDataSource);

                        var saved = false;

                        // Обработка события сохранения данных
                        ScriptDelegate onSaved = (c, a) =>
                        {
                            saved = true;

                            TryInvoke(onAccept, mainDataSource);
                        };

                        if (mainDataSource != null)
                        {
                            mainDataSource.OnItemSaved += onSaved;
                        }

                        ScriptDelegate onClosed = null;

                        // Обработка события закрытия представления
                        onClosed
                            = (c, a) =>
                            {
                            if (mainDataSource != null)
                            {
                                mainDataSource.OnItemSaved -= onSaved;
                            }

                            view.OnClosed -= onClosed;
                            RemoveView(viewKey);

                            // Если окно закрыли с подтверждением
                            if (saved == false && view.GetDialogResult() == DialogResult.Accepted)
                            {
                                TryInvoke(onAccept, mainDataSource);
                            }
                            };

                        view.OnClosed += onClosed;
                        AddView(viewKey, view);

                        view.Open();
                    }
                }
            }
        }
예제 #32
0
 protected RecordScriptAction(PipelineContext ctx, RecordScriptAction other)
 {
     ScriptName     = other.ScriptName;
     scriptDelegate = ctx.Pipeline.CreateScriptDelegate <ScriptDelegate>(ScriptName);
 }
 /// <summary>
 ///     Добавляет прикладной скрипт.
 /// </summary>
 public void AddScript(string name, ScriptDelegate action)
 {
     _scripts[name] = action;
     _context[name] = action;
 }