示例#1
0
 public object GetValue(string key)
 {
     lock (m_SyncRoot)
     {
         if (!m_Content.Contains(key))
         {
             throw new Exception("CommandMsg中不包含指定键: " + key);
         }
         else
         {
             return(m_Content[key]);
         }
     }
 }
示例#2
0
        private HashSet <ISimEventHandle> GetEventsTo(ISimEntity simEntity)
        {
            HashSet <ISimEventHandle> hSet;

            if (_to2set.Contains(simEntity))
            {
                hSet = (HashSet <ISimEventHandle>)_to2set[simEntity];
            }
            else
            {
                hSet = new HashSet <ISimEventHandle>();
                _to2set.Add(simEntity, hSet);
            }
            return(hSet);
        }
示例#3
0
        private string prettyTypeName(Type t, ref int consumed)
        {
            StringBuilder ret = new StringBuilder();

            if (t.IsGenericParameter)
            {
                ret.Append(t.Name);
            }
            else if (t.IsArray)
            {
                ret.Append(prettyTypeName(t.GetElementType()) + "[]");
            }
            else if (t.IsByRef)
            {
                ret.Append("ref ").Append(prettyTypeName(t.GetElementType()));
            }
            else if (!t.IsGenericType)
            {
                ret.Append(t.IsNested ? prettyTypeName(t.DeclaringType, ref consumed) + "." + t.Name : t.FullName);
            }
            else
            {
                bool          first = true;
                StringBuilder gps   = new StringBuilder();
                Type[]        gp    = t.GetGenericArguments();

                ret.Append(t.IsNested ? prettyTypeName(t.DeclaringType, ref consumed) : t.Namespace).Append(".").Append(t.Name);
                if (consumed < gp.Length)
                {
                    //TODO: fix this ugly hack to remove `n
                    ret.Remove(ret.Length - 2, 2);
                    //ret = ret.Substring(0, ret.Length - 2);
                    for (int i = consumed, length = gp.Length; i < length; i++)
                    {
                        Type ty = gp[i];

                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            gps.Append(",");
                        }

                        gps.Append(prettyTypeName(ty));
                    }

                    consumed = gp.Length;
                    ret.Append("{").Append(gps.ToString()).Append("}");
                }
            }

            string retval = ret.ToString();

            if (retval.StartsWith(defaultNamespace + "."))
            {
                retval = retval.Substring(defaultNamespace.Length + 1);
            }

            if (longtype2short.Contains(retval))
            {
                retval = longtype2short[retval];
            }

            return(retval);
        }
        CommandMsgV2 _StartAdapter(ICommunicationMessage message)
        {
            try
            {
                CommandMsgV2 resp = new CommandMsgV2();
                resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                resp.SeqID          = CommandProcessor.AllocateID();
                resp.SetValue("ClientID", message.GetValue("ClientID"));
                resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);


                long adapterid = Convert.ToInt64(message.GetValue(Constants.MSG_PARANAME_ADAPTER_ID));

                C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
                AlarmManager.instance().GetAdaptersInfo(ads);
                if (!ads.Contains(adapterid))
                {
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    resp.SetValue(Constants.MSG_PARANAME_REASON, "采集器不存在.");
                    return(resp);
                }

                try
                {
                    CommandMsgV2 cmd = new CommandMsgV2();
                    cmd.SeqID          = CommandProcessor.AllocateID();
                    cmd.TK_CommandType = Constants.TK_CommandType.ADAPTER_START;
                    cmd.SetValue("ClientID", adapterid);
                    cmd.SetValue(Constants.MSG_PARANAME_ADAPTER_NAME, ads[adapterid].Name);

                    System.Net.IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ads[adapterid].Address), ads[adapterid].ControllerPort);
                    if (end.Port == 0)
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                        resp.SetValue(Constants.MSG_PARANAME_REASON, "不可远程控制的采集器");
                    }
                    else
                    {
                        ICommClient comm = CommManager.instance().CreateCommClient <CommandMsgV2, TKMessageV2Extractor, TKMessageV2Encoder>("控制器",
                                                                                                                                            end.Address.ToString(), end.Port, 30, false, false);

                        comm.Start();
                        ICommunicationMessage r2 = comm.SendCommand(cmd);
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, r2.GetValue(Constants.MSG_PARANAME_RESULT));
                        comm.Close();
                    }
                }
                catch (Exception ex)
                {
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
                }

                return(resp);
            }
            catch (Exception ex)
            {
                Logger.Instance().SendLog(ex.ToString());
                return(null);
            }
        }