示例#1
0
 public static void DetachEvent(string eventName, ElementEventHandler handler)
 {
 }
示例#2
0
 public void DetachEvent(string eventName, ElementEventHandler handler) {
 }
        protected override void EndProcessing()
        {
            if (ParameterSetName == "HTML")
            {
                Log.Debug("HTML");

                var events = new List <ElementEventHandler>();

                if (Attributes != null)
                {
                    var keysToRemove = new List <object>();
                    foreach (DictionaryEntry attribute in Attributes)
                    {
                        var eventHandler = attribute.Value as ElementEventHandler;
                        if (eventHandler == null)
                        {
                            Endpoint callback = null;

                            var scriptBlock = attribute.Value as ScriptBlock;
                            if (scriptBlock != null)
                            {
                                callback = GenerateCallback(Id + attribute.Key.ToString(), scriptBlock, null);
                            }
                            else
                            {
                                var psobject = attribute.Value as PSObject;
                                callback = psobject?.BaseObject as Endpoint;
                            }

                            if (callback == null)
                            {
                                continue;
                            }

                            eventHandler = new ElementEventHandler {
                                Callback = callback,
                                Event    = attribute.Key.ToString(),
                            };
                        }

                        events.Add(eventHandler);
                        keysToRemove.Add(attribute.Key);
                    }

                    foreach (var key in keysToRemove)
                    {
                        Attributes.Remove(key);
                    }
                }

                var element = new Element
                {
                    Id              = Id,
                    Tag             = Tag,
                    Attributes      = Attributes,
                    Events          = events.ToArray(),
                    Content         = Content?.Invoke().Where(m => m != null).Select(m => m.BaseObject).ToArray(),
                    Callback        = GenerateCallback(Id),
                    AutoRefresh     = AutoRefresh,
                    RefreshInterval = RefreshInterval,
                    OnMount         = OnMount
                };

                Log.Debug(JsonConvert.SerializeObject(element));

                WriteObject(element);
            }
            else
            {
                Log.Debug("JS");

                var path = GetUnresolvedProviderPathFromPSPath(JavaScriptPath);

                if (Properties != null)
                {
                    if (!Properties.ContainsKey("id"))
                    {
                        Properties.Add("id", Id);
                    }
                }

                AssetService.Instance.RegisterAsset(path);

                var element = new Element
                {
                    Id             = Id,
                    JavaScriptPath = path,
                    Callback       = GenerateCallback(Id),
                    Properties     = Properties.ToDictionary(),
                    ComponentName  = ComponentName,
                    ModuleName     = ModuleName
                };

                Log.Debug(JsonConvert.SerializeObject(element));

                WriteObject(element);
            }
        }
示例#4
0
 public static void AttachEvent(string eventName, ElementEventHandler handler)
 {
 }
示例#5
0
 public void AttachEvent(string eventName, ElementEventHandler handler)
 {
 }
示例#6
0
        protected override void EndProcessing()
        {
            var events = new List <ElementEventHandler>();

            if (Attributes != null)
            {
                var keysToRemove = new List <object>();
                foreach (DictionaryEntry attribute in Attributes)
                {
                    var eventHandler = attribute.Value as ElementEventHandler;
                    if (eventHandler == null)
                    {
                        Endpoint callback = null;

                        var scriptBlock = attribute.Value as ScriptBlock;
                        if (scriptBlock != null)
                        {
                            callback = GenerateCallback(Id + attribute.Key.ToString(), scriptBlock, null);
                        }
                        else
                        {
                            var psobject = attribute.Value as PSObject;
                            callback = psobject?.BaseObject as Endpoint;
                        }

                        if (callback == null)
                        {
                            continue;
                        }

                        eventHandler = new ElementEventHandler
                        {
                            Callback = callback,
                            Event    = attribute.Key.ToString(),
                        };
                    }

                    events.Add(eventHandler);
                    keysToRemove.Add(attribute.Key);
                }

                foreach (var key in keysToRemove)
                {
                    Attributes.Remove(key);
                }
            }

            var element = new Element
            {
                Id              = Id,
                Tag             = Tag,
                Attributes      = Attributes,
                Events          = events.ToArray(),
                Content         = Content?.Invoke().Where(m => m != null).Select(m => m.BaseObject).ToArray(),
                Callback        = GenerateCallback(Id),
                AutoRefresh     = AutoRefresh,
                RefreshInterval = RefreshInterval,
                OnMount         = OnMount
            };

            Log.Debug(JsonConvert.SerializeObject(element));

            WriteObject(element);
        }
        protected override void EndProcessing()
        {
            if (ParameterSetName == "HTML")
            {
                Log.Debug("HTML");

                var events = new List <ElementEventHandler>();

                if (Attributes != null)
                {
                    var keysToRemove = new List <object>();
                    foreach (DictionaryEntry attribute in Attributes)
                    {
                        var eventHandler = attribute.Value as ElementEventHandler;
                        if (eventHandler == null)
                        {
                            var scriptBlock = attribute.Value as ScriptBlock;
                            if (scriptBlock == null)
                            {
                                continue;
                            }

                            eventHandler = new ElementEventHandler {
                                Callback = GenerateCallback(Id + attribute.Key.ToString(), scriptBlock),
                                Event    = attribute.Key.ToString(),
                            };
                        }

                        events.Add(eventHandler);
                        keysToRemove.Add(attribute.Key);
                    }

                    foreach (var key in keysToRemove)
                    {
                        Attributes.Remove(key);
                    }
                }

                var element = new Element
                {
                    Id              = Id,
                    Tag             = Tag,
                    Attributes      = Attributes,
                    Events          = events.ToArray(),
                    Content         = Content?.Invoke().Where(m => m != null).Select(m => m.BaseObject).ToArray(),
                    Callback        = GenerateCallback(Id),
                    AutoRefresh     = AutoRefresh,
                    RefreshInterval = RefreshInterval
                };

                Log.Debug(JsonConvert.SerializeObject(element));

                WriteObject(element);
            }
            else
            {
                Log.Debug("JS");

                var path = GetUnresolvedProviderPathFromPSPath(JavaScriptPath);

                if (Properties != null)
                {
                    if (!Properties.ContainsKey("id"))
                    {
                        Properties.Add("id", Id);
                    }
                }

                var dashboardService = GetVariableValue("DashboardService") as IDashboardService;
                if (dashboardService != null)
                {
                    var id = path.GetHashCode();
                    if (!dashboardService.ElementScripts.ContainsKey(id))
                    {
                        Log.Debug("Adding element script: " + path);
                        dashboardService.ElementScripts.Add(id, path);
                    }
                }

                var element = new Element
                {
                    Id             = Id,
                    JavaScriptPath = path,
                    Callback       = GenerateCallback(Id),
                    Properties     = Properties,
                    ComponentName  = ComponentName,
                    ModuleName     = ModuleName
                };

                Log.Debug(JsonConvert.SerializeObject(element));

                WriteObject(element);
            }
        }