예제 #1
0
        private static void trigerEvent(InterprocessStruct detail)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            Action ac;
            EventType et = (EventType)Enum.Parse(typeof(EventType), detail.CmdType);
            switch (et)
            {
                case EventType.Reset://Reset
                    #region <<
                    if (Reset != null)
                    {
                        ac = delegate
                        {
                            Reset(null, null);
                        };
                        _dispatcher.Invoke(DispatcherPriority.Send, ac);
                    }
                    break;
                    #endregion
                case EventType.PushResource://PushMedia
                    #region <<
                    if (PushMedia != null)
                    {
                        PushMediaEventArgs pmea = new PushMediaEventArgs();
                        try
                        {
                            var type = detail.Values["type"].ToString();
                            if (detail.Values.ContainsKey("iceid"))
                            {
                                pmea.iceid = (string)detail.Values["iceid"];
                            }
                            switch (type)
                            {
                                case "resource"://中控资源
                                    pmea.Type = PushMediaType.Resource;
                                    pmea.Resource = jss.Deserialize<PushResourceConainer[]>(jss.Serialize(detail.Values["detail"]));
                                    break;
                                case "stream"://流
                                    pmea.Type = PushMediaType.Stream;
                                    pmea.Stream = jss.Deserialize<PushStreamData>(jss.Serialize(detail.Values));
                                    break;
                                case "web"://网页资源
                                    pmea.Type = PushMediaType.Web;
                                    pmea.Web = jss.Deserialize<PushWebData[]>(jss.Serialize(detail.Values["detail"]));
                                    break;
                                default:
                                    break;
                            }
                            if (detail.Values.ContainsKey("direction"))
                            {
                                try
                                {
                                    pmea.direction = (int)detail.Values["direction"];
                                }
                                catch
                                {
                                    try
                                    {
                                        pmea.direction = int.Parse(detail.Values["direction"].ToString());
                                    }
                                    catch { }
                                }
                            }

                            ac = delegate
                            {
                                PushMedia(detail.Sender, pmea);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                    #endregion
                case EventType.Command://Cmd
                    #region <<
                    if (GetCmd != null)
                    {
                        ControlCmdEventArgs ccea = new ControlCmdEventArgs();
                        try
                        {
                            if (detail.Values.ContainsKey("iceid"))
                            {
                                ccea.iceid = (string)detail.Values["iceid"];
                            }
                            if (detail.Values.ContainsKey("cmd"))//单命令
                            {
                                var cmd = detail.Values["cmd"].ToString().ToUpper();
                                ccea.OneCmd = new ControlCmdStruct();
                                ccea.OneCmd.CmdType = (ControlCmd)Enum.Parse(typeof(ControlCmd), cmd);
                                ccea.OneCmd.Data = detail.Values["body"].ToString();
                            }
                            else
                            {
                                ControlCmd[] cmds = jss.Deserialize<ControlCmd[]>(jss.Serialize(detail.Values["cmds"]));
                                ccea.MultiCmds = cmds;
                            }

                            ac = delegate
                            {
                                GetCmd(detail.Sender, ccea);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                    #endregion
                case EventType.ResourceUpdate://ResourceUpdate
                    #region <<
                    if (UpdateResource != null)
                    {
                        var arg = new ResourceUpdateEventArgs();
                        try
                        {
                            arg.Action = jss.Deserialize<ResourceAction>(detail.Values["action"].ToString());
                            arg.Data = jss.Deserialize<ResourceContainerStruct>(jss.Serialize(detail.Values["data"]));
                            ac = delegate
                            {
                                UpdateResource(detail.Sender, arg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                    #endregion
                case EventType.SupportExtend://Extend
                    #region <<
                    if (GetExtendCmd != null)
                    {
                        var arg = new ExtendEventArgs();
                        try
                        {
                            if (detail.Values.ContainsKey("iceid"))
                            {
                                arg.iceid = (string)detail.Values["iceid"];
                            }
                            if (detail.Values["extend"] is string)
                            {
                                arg.Msg = (string)detail.Values["extend"];
                            }
                            else
                            {
                                arg.Msg = jss.Serialize(detail.Values["extend"]);
                            }
                            ac = delegate
                            {
                                GetExtendCmd(detail.Sender, arg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                    #endregion
                case EventType.SurportPassword://RequirePassword
                    #region <<
                    if (RequirePassword != null)
                    {
                        ac = delegate
                        {
                            RequirePassword(null, null);
                        };
                        _dispatcher.Invoke(DispatcherPriority.Send, ac);
                    }
                    break;
                    #endregion
                case EventType.LinkState://LinkState
                    if (LinkState != null)
                    {
                        var arg = new LinkStateEventArgs();
                        try
                        {
                            arg.LinkState = (ServerLinkState)detail.Values["state"];
                            ac = delegate
                            {
                                LinkState(detail.Sender, arg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }

                    }
                    break;
                case EventType.Error://Error
                    if (GetError != null)
                    {
                        var arg = new ServerErrorEventArgs();
                        try
                        {
                            arg.ErrorType = (ServerError)detail.Values["code"];
                            arg.ErrorMsg = (string)detail.Values["msg"];
                            ac = delegate
                            {
                                GetError(detail.Sender, arg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                case EventType.Sync://Sync
                    if (GetSync != null)
                    {
                        var arg = new SyncEventArgs();
                        try
                        {
                            if (detail.Values.ContainsKey("iceid"))
                            {
                                arg.iceid = (string)detail.Values["iceid"];
                            }
                            arg.PkgName = detail.Values["pkg"].ToString();
                            arg.Guid = detail.Values["guid"].ToString();
                            arg.Tag = detail.Values["tag"].ToString();
                            ac = delegate
                            {
                                GetSync(detail.Sender, arg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                case EventType.Follow://Follow
                    if (GetFollow != null)
                    {
                        FollowEventArgs fea = jss.Deserialize<FollowEventArgs>(jss.Serialize(detail.Values));
                        ac = delegate
                        {
                            GetFollow(detail.Sender, fea);
                        };
                        _dispatcher.Invoke(DispatcherPriority.Send, ac);
                    }
                    break;
                case EventType.Symbol://Symbol
                    if (GetSymbol != null)
                    {
                        SymbolEventArgs sea = jss.Deserialize<SymbolEventArgs>(jss.Serialize(detail.Values));
                        ac = delegate
                        {
                            GetSymbol(detail.Sender, sea);
                        };
                        _dispatcher.Invoke(DispatcherPriority.Send, ac);
                    }
                    break;
                case EventType.UserMsg:
                    if (GetUserMsg != null)
                    {
                        var arg = new UserMsgEventArgs();
                        try
                        {
                            if (detail.Values.ContainsKey("iceid"))
                            {
                                arg.iceid = (string)detail.Values["iceid"];
                            }
                            arg.Msg = (string)detail.Values["msg"];
                            ac = delegate
                            {
                                GetUserMsg(detail.Sender, arg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                case EventType.Approaching:
                    if (UserApproaching != null)
                    {
                        try
                        {
                            UserInfoStruct sea = jss.Deserialize<UserInfoStruct>(jss.Serialize(detail.Values["result"]));
                            ac = delegate
                            {
                                UserApproaching(detail.Sender, sea);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);

                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                case EventType.Lock:
                    if (GetLock != null)
                    {
                        try
                        {
                            LockEventArgs sea = new LockEventArgs
                            {
                                power = (string)detail.Values["power"] == "on",
                                iceid = (string)detail.Values["iceid"],
                            };
                            ac = delegate
                            {
                                GetLock(detail.Sender, sea);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);

                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                case EventType.Force:
                    if (GetForce != null)
                    {
                        try
                        {
                            ForceEventArgs sea = new ForceEventArgs
                            {
                                iceid = (string)detail.Values["iceid"],
                                action = (ForeceCmdAction)Enum.Parse(typeof(ForeceCmdAction), (string)detail.Values["action"]),
                                guid = (string)detail.Values["guid"],
                                power = (string)detail.Values["power"] == "on",
                            };
                            ac = delegate
                            {
                                GetForce(detail.Sender, sea);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);

                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    } break;
                case EventType.CCLinkState:
                    if (GetCCLink != null)
                    {
                        bool connect = false;
                        try
                        {
                            connect = (bool)detail.Values["connect"];
                            ac = delegate
                            {
                                GetCCLink(connect);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch { }
                    }
                    break;
                case EventType.FailedToSendMsg:
                    if (FailedToSendMsg != null)
                    {
                        string msg = "";
                        try
                        {
                            msg = (string)detail.Values["msg"];
                            ac = delegate
                            {
                                FailedToSendMsg(msg);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch { }
                    }
                    break;
                case EventType.RunApp:
                    if (GetRunApp != null)
                    {
                        try
                        {
                            //RunAppArgs sea = jss.Deserialize<RunAppArgs>(jss.Serialize(detail.Values["result"]));
                            RunAppArgs raa = new RunAppArgs
                            {
                                iceid = (string)detail.Values["iceid"],
                                key = (string)detail.Values["app"],
                            };
                            ac = delegate
                            {
                                GetRunApp(detail.Sender, raa);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);

                        }
                        catch (Exception ex)
                        {
                            error(et, ex);
                        }
                    }
                    break;
                case EventType.Raw:
                    if (GetRaw != null)
                    {
                        try
                        {
                            string body = jss.Serialize(detail.Values);
                            ac = delegate
                            {
                                GetRaw(body);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch { }
                    }
                    break;
                case EventType.OtherCmd:
                    if (GetOtherCmd != null)
                    {
                        try
                        {
                            OtherCmd oc = jss.Deserialize<OtherCmd>(jss.Serialize(detail.Values));
                            ac = delegate
                            {
                                GetOtherCmd(oc);
                            };
                            _dispatcher.Invoke(DispatcherPriority.Send, ac);
                        }
                        catch { }
                    }
                    break;
                default:
                    break;
            }
        }
예제 #2
0
 static bool sendInterprocessMsg(CmdType ct, string evidence, Dictionary<string, object> value, Dictionary<string, object> msg)
 {
     IntPtr hwnd = FindWindow(null, BC_TITLE);
     if (hwnd == IntPtr.Zero)
     {
         if (ServerDown != null)
         {
             ServerDown();
         }
         return false;
     }
     else
     {
         InterprocessStruct interP = new InterprocessStruct()
         {
             Sender = WIN_TITLE,
             Evidence = evidence,
             CmdType = ((int)ct).ToString(),
             Values = value,
             Msgs = msg,
         };
         JavaScriptSerializer jss = new JavaScriptSerializer();
         jss.MaxJsonLength = int.MaxValue;
         var str = jss.Serialize(interP);
         sendMessage(hwnd, str);
         return true;
     }
 }