Пример #1
0
 public static string Sum(SrvTypes m)
 {
     if (!srvmd5memo.ContainsKey(m))
     {
         IRosService irm = IRosService.generate(m);
         string      req = PrepareToHash(irm.RequestMessage);
         string      res = PrepareToHash(irm.ResponseMessage);
         srvmd5memo.Add(m, Sum(req, res));
     }
     return(srvmd5memo[m]);
 }
Пример #2
0
        public static IRosService generate <RequestType> (SrvTypes t) where RequestType : IRosMessage
        {
            lock ( constructors )
            {
                if (constructors.ContainsKey(t))
                {
                    return(constructors [t].Invoke(t));
                }
                Type thistype = typeof(IRosService);
                foreach (Type othertype in Assembly.GetAssembly(typeof(RequestType)).GetTypes())
                {
                    if (thistype == othertype || !othertype.IsSubclassOf(thistype) || othertype.IsAbstract || othertype.Name.Contains("Decorator"))
                    {
                        continue;
                    }
                    IRosService srv = Activator.CreateInstance(othertype) as IRosService;
                    if (srv != null)
                    {
                        if (srv.srvtype() == SrvTypes.Unknown)
                        {
                            throw new Exception("OH NOES IRosService.generate is borked!");
                        }
                        if (!_typeregistry.ContainsKey(srv.srvtype()))
                        {
                            _typeregistry.Add(srv.srvtype(), srv.GetType());
                        }
                        if (!constructors.ContainsKey(srv.srvtype()))
                        {
                            constructors.Add(srv.srvtype(), T => Activator.CreateInstance(_typeregistry [T]) as IRosService);
                        }
                        srv.RequestMessage  = IRosMessage.generate <RequestType> ((MsgTypes)Enum.Parse(typeof(MsgTypes), srv.srvtype().ToString() + "__Request"));
                        srv.ResponseMessage = IRosMessage.generate <RequestType> ((MsgTypes)Enum.Parse(typeof(MsgTypes), srv.srvtype().ToString() + "__Response"));
                    }
                }

                if (constructors.ContainsKey(t))
                {
                    return(constructors [t].Invoke(t));
                }
                else
                {
                    throw new Exception("OH NOES IRosService.generate is borked!");
                }
            }
        }