Esempio n. 1
0
 public EndpointHandler(ITopLogger logger)
 {
     this._log       = logger;
     this._idByToken = new Dictionary <string, Identity>();
     this._callbacks = new Dictionary <int, SendCallback>();
     this._onMessage = this.OnMessage;
 }
Esempio n. 2
0
 public DefaultAliyunClient(string serverUrl, string accessKeyId, string accessKeySecret)
 {
     this.accessKeyId     = accessKeyId;
     this.accessKeySecret = accessKeySecret;
     this.serverUrl       = serverUrl;
     this.webUtils        = new AliyunWebUtils();
     this.topLogger       = Top.Api.Log.Instance;
 }
Esempio n. 3
0
 public TopClient(string serverUrl, string appKey, string appSecret)
 {
     this.apiKey    = appKey;
     this.appSecret = appSecret;
     this.ServerUrl = serverUrl;
     this.webUtils  = new WebUtils();
     this.topLogger = new DefaultTopLogger();
 }
 public DefaultAliyunClient(string serverUrl, string accessKeyId, string accessKeySecret)
 {
     this.accessKeyId     = accessKeyId;
     this.accessKeySecret = accessKeySecret;
     this.serverUrl       = serverUrl;
     this.webUtils        = new AliyunWebUtils();
     this.topLogger       = DefaultTopLogger.GetDefault();
 }
Esempio n. 5
0
        internal IDictionary <string, string> systemParameters; // 设置所有请求共享的系统级参数

        #region DefaultTopClient Constructors

        public DefaultTopClient(string serverUrl, string appKey, string appSecret)
        {
            this.appKey    = appKey;
            this.appSecret = appSecret;
            this.serverUrl = serverUrl;
            this.webUtils  = new WebUtils();
            this.topLogger = DefaultTopLogger.GetDefault();
        }
        internal IDictionary <string, string> systemParameters; // 设置所有请求共享的系统级参数

        #region DefaultQimenCloudClient Constructors

        public DefaultQimenCloudClient(string serverUrl, string appKey, string appSecret)
        {
            this.appKey    = appKey;
            this.appSecret = appSecret;
            this.serverUrl = serverUrl;
            this.webUtils  = new WebUtils();
            this.topLogger = Log.Instance;
        }
Esempio n. 7
0
 /// <summary>init tcp server channel
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="port"></param>
 /// <param name="ioWorker">deal with networkstream</param>
 public TcpServerChannel(ITopLogger log
                         , int port
                         , IOWorker ioWorker)
     : base(log
            , port)
 {
     this._ioWorker   = ioWorker;
     this._tcpClients = new LinkedList <TcpClient>();
 }
Esempio n. 8
0
 public MessageStreamImpl(StreamMsgConsumeFactory msgConsumeFactory, HttpResponse response, ITopCometMessageListener msgListener, TopCometStreamImpl cometStreamImpl) : base(msgConsumeFactory, response)
 {
     this.logger = new DefaultTopLogger();
     this.pattern = "\\{\"packet\":\\{\"code\":(?<code>(\\d+))(,\"msg\":(?<msg>((.+))))?\\}\\}";
     this.objLock = new object();
     this.msgListener = msgListener;
     this.objLock = cometStreamImpl.GetControlLock();
     this.cometStreamImpl = cometStreamImpl;
 }
Esempio n. 9
0
 public Endpoint(ITopLogger logger, Identity identity)
 {
     this._connected                 = new List <EndpointProxy>();
     this._log                       = logger;
     this.Identity                   = identity;
     this.ChannelSelector            = new ClientChannelSharedSelector(logger);
     this._handler                   = new EndpointHandler(logger);
     this._handler.MessageHandler    = ctx => OnMessage(this, ctx);
     this._handler.AckMessageHandler = (m, i) => OnAckMessage(this, new AckMessageArgs(m, i));
 }
Esempio n. 10
0
        public DefaultQimenClient(string serverUrl, string appKey, string appSecret, bool ownApi = false)
        {
            this.serverUrl = serverUrl;
            this.appKey    = appKey;
            this.appSecret = appSecret;

            this.ownApi = ownApi;

            this.webUtils  = new WebUtils();
            this.topLogger = DefaultTopLogger.GetDefault();
        }
Esempio n. 11
0
 public static ITopLogger GetDefault()
 {
     if (_default == null)
     {
         lock (lazyLock)
         {
             if (_default == null)
             {
                 _default = new DefaultTopLogger();
             }
         }
     }
     return(_default);
 }
Esempio n. 12
0
 private static void On <T>(ITopLogger log, EventHandler <T> eventHandler, T args) where T : EventArgs
 {
     try
     {
         if (eventHandler != null)
         {
             eventHandler(null, args);
         }
     }
     catch (Exception e)
     {
         //here is global on error
         log.Error(e.StackTrace);
         //TODO:close channel here?
     }
 }
Esempio n. 13
0
        /// <summary>connect to uri via websocket
        /// </summary>
        /// <param name="loggerFactory">loggerFactory</param>
        /// <param name="uri">remote address</param>
        /// <param name="timeout">timeout in milliseconds</param>
        /// <returns></returns>
        public static IClientChannel Connect(ITopLogger logger, Uri uri, int timeout)
        {
            //log first
            var log = logger;

            var h       = new WaitHandle();
            var onOpen  = new EventHandler((o, e) => h.Set());
            var onError = new EventHandler <ErrorEventArgs>((o, e) => h.Set(e.Message));

            var socket  = new WebSocketSharp.WebSocket(uri.ToString());
            var channel = new WebSocketClientChannel(socket)
            {
                Uri = uri
            };

            socket.OnOpen  += onOpen;
            socket.OnError += onError;

            socket.Connect();

            if (!h.WaitOne(timeout, false))
            {
                throw new LinkException("connect timeout");
            }
            if (h.IsError)
            {
                throw new LinkException(h.Error);
            }

            socket.OnOpen  -= onOpen;
            socket.OnError -= onError;

            socket.OnError += (o, e) => On(log
                                           , channel.OnError
                                           , new ChannelContext(new LinkException(e.Message)));
            socket.OnClose += (o, e) => On(log
                                           , channel.OnClosed
                                           , new ChannelClosedEventArgs(e.Reason));
            socket.OnMessage += (o, e) => On(log
                                             , channel.OnMessage
                                             , new ChannelContext(e.RawData, channel));
            return(channel);
        }
Esempio n. 14
0
 public void SetTopLogger(ITopLogger topLogger)
 {
     this.topLogger = topLogger;
 }
Esempio n. 15
0
        internal IDictionary <string, string> systemParameters; // 设置所有请求共享的系统级参数

        #region DefaultDingTalkClient Constructors

        public DefaultDingTalkClient(string serverUrl)
        {
            this.serverUrl = serverUrl;
            this.webUtils  = new WebUtils();
            this.topLogger = DefaultTopLogger.GetDefault();
        }
Esempio n. 16
0
        internal IDictionary <string, string> systemParameters; // 设置所有请求共享的系统级参数

        #region DefaultDingTalkClient Constructors

        public DefaultDingTalkClient(string serverUrl)
        {
            this.serverUrl = serverUrl;
            this.webUtils  = new WebUtils();
            this.topLogger = Top.Api.Log.Instance;
        }
Esempio n. 17
0
 public ServerChannel(ITopLogger logger, int port)
 {
     this.Logger = logger;
     this.Port   = port;
 }
Esempio n. 18
0
 public ClientChannelSharedSelector(ITopLogger logger)
 {
     this._logger     = logger;
     this._lockObject = new object();
     this._channels   = new Dictionary <string, IClientChannel>();
 }
Esempio n. 19
0
        static void Main(string[] args)
        {
            //DataTable dt = new DataTable();
            //dt.Columns.Add("Type", typeof(int));
            //dt.Columns.Add("MainNo", typeof(string));
            //dt.Columns.Add("SubNo", typeof(string));


            //List<TestEntity> entities = new List<TestEntity> { new TestEntity{ Type = 1, MainNo = "1", SubNo = "11" },
            //                                                   new TestEntity { Type = 1, MainNo = "1", SubNo = "12"},
            //                                                   new TestEntity { Type = 1, MainNo = "2", SubNo = "21"},
            //                                                   new TestEntity { Type = 1, MainNo = "2", SubNo = "22"},
            //                                                   new TestEntity { Type = 1, MainNo = "3", SubNo = "31"},
            //                                                   new TestEntity { Type = 1, MainNo = "3", SubNo = "32"},
            //                                                   new TestEntity { Type = 2, MainNo = "1", SubNo = "11"},
            //                                                   new TestEntity { Type = 2, MainNo = "1", SubNo = "12"},
            //                                                   new TestEntity { Type = 2, MainNo = "2", SubNo = "21"},
            //                                                   new TestEntity { Type = 2, MainNo = "2", SubNo = "22"},
            //                                                   new TestEntity { Type = 2, MainNo = "3", SubNo = "31"},
            //                                                   new TestEntity { Type = 2, MainNo = "3", SubNo = "32"}

            //};

            //foreach(var ent in entities)
            //{
            //    DataRow dr = dt.NewRow();
            //    dr["Type"] = ent.Type;
            //    dr["MainNo"] = ent.MainNo;
            //    dr["SubNo"] = ent.SubNo;
            //    dt.Rows.Add(dr);
            //}

            //DataRow[] drs = dt.Select("Type = 2");
            //List<string> deleteNos = new List<string>() { "1", "2" };
            //foreach (var no in deleteNos)
            //{
            //    var drRemoves = from dr in drs
            //                    where dr["MainNo"].ToString() == no
            //                    select dr;
            //    foreach (DataRow drRemove in drRemoves)
            //        drRemove.d
            //}

            //Console.WriteLine(drs.Length);
            //Console.ReadKey();

            //WebClient wc = new WebClient();
            //wc.Encoding = Encoding.UTF8;

            //var html = wc.DownloadString("https://www.meet99.com/map-beijing.html");

            //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.meet99.com/map-beijing.html");
            //HttpWebResponse response =  (HttpWebResponse)request.GetResponse();
            //using (Stream stream = response.GetResponseStream())
            //{
            //    using (StreamReader sr = new StreamReader(stream))
            //    {
            //        var html = sr.ReadToEnd();
            //    }
            //}


            //    HtmlConvent<Area> convertor = ConvertHtmlToAreas;


            //ExtractData ed = new ExtractData();
            //ed.Extract<Area>(basUrl  + "/map", convertor);

            //Regex reg = new Regex(@"result=(-?\d+)");
            //if(reg.Matches("result=0&msgid=12343545465675").Count > 0)
            //{
            //    Console.WriteLine(reg.Matches("result=0&msgid=12343545465675")[1].Value);


            //}

            //DataTable dt = new DataTable();
            //dt.Columns.Add("num", typeof(int));
            //for(int i = 0; i < 10; i++)
            //{
            //    DataRow dr = dt.NewRow();
            //    dr["num"] = i + 1;
            //    dt.Rows.Add(dr);
            //}

            //foreach(DataRow dr in dt.Rows)
            //{
            //    dt.Rows.Remove(dr);
            //}

            //SerialPort sp = new SerialPort("COM2", 9600);


            ////SerialPort sp2 = new SerialPort("COM3", 9600);
            ////Console.WriteLine(sp2.IsOpen);
            ////try
            ////{
            ////    sp2.Open();
            ////}catch(Exception ex)
            ////{
            ////    Console.WriteLine(ex.Message);
            ////}
            //if (!sp.IsOpen)
            //{
            //    sp.Open();
            //    //sp2.Open();
            //}
            //for (int i = 0; i < 10; i++)
            //{
            //    sp.WriteLine("hello world" + i);
            //    Thread.Sleep(3000);
            //}

            ////if (sp2.BytesToRead > 0)
            ////{
            ////    var line = sp2.ReadLine();
            ////    Console.WriteLine(line + "aa");
            ////}
            //sp.Close();
            ////sp2.Close();
            //Console.WriteLine("结束");

            ITopLogger logger = DefaultTopLogger.GetDefault();

            logger.Error("123");
            Console.ReadKey();
        }