Ejemplo n.º 1
0
        internal static void create(IntPtr gcHandlePtr, out IntPtr __retval, IntPtr browser, out int browser_release, IntPtr frame, out int frame_release, IntPtr scheme_name_str, int scheme_name_length, IntPtr request, out int request_release)
        {
            var self = (CfxSchemeHandlerFactory)System.Runtime.InteropServices.GCHandle.FromIntPtr(gcHandlePtr).Target;

            if (browser == IntPtr.Zero)
            {
                //TODO:还是没搞懂,显示DevTools时,为啥会为空
                __retval        = default(IntPtr);
                browser_release = 0;
                frame_release   = 0;
                request_release = 0;
                return;
            }

            if (self == null || self.CallbacksDisabled)
            {
                __retval        = default(IntPtr);
                browser_release = 1;
                frame_release   = 1;
                request_release = 1;
                return;
            }
            var e = new CfxSchemeHandlerFactoryCreateEventArgs(browser, frame, scheme_name_str, scheme_name_length, request);

            self.m_Create?.Invoke(self, e);
            e.m_isInvalid   = true;
            browser_release = e.m_browser_wrapped == null? 1 : 0;
            frame_release   = e.m_frame_wrapped == null? 1 : 0;
            request_release = e.m_request_wrapped == null? 1 : 0;
            __retval        = CfxResourceHandler.Unwrap(e.m_returnValue);
        }
Ejemplo n.º 2
0
        internal static void create(IntPtr gcHandlePtr, out IntPtr __retval, IntPtr browser, IntPtr frame, IntPtr scheme_name_str, int scheme_name_length, IntPtr request)
        {
            var self = (CfxSchemeHandlerFactory)System.Runtime.InteropServices.GCHandle.FromIntPtr(gcHandlePtr).Target;

            if (self == null || browser == IntPtr.Zero)
            {
                //TOD:这里为什么会为空?
                __retval = default(IntPtr);
                return;
            }
            var e            = new CfxSchemeHandlerFactoryCreateEventArgs(browser, frame, scheme_name_str, scheme_name_length, request);
            var eventHandler = self.m_Create;

            if (eventHandler != null)
            {
                eventHandler(self, e);
            }
            e.m_isInvalid = true;
            if (e.m_browser_wrapped == null)
            {
                CfxApi.cfx_release(e.m_browser);
            }
            if (e.m_frame_wrapped == null)
            {
                CfxApi.cfx_release(e.m_frame);
            }
            if (e.m_request_wrapped == null)
            {
                CfxApi.cfx_release(e.m_request);
            }
            __retval = CfxResourceHandler.Unwrap(e.m_returnValue);
        }
        public BitstampSocket() : base("https://www.bitstamp.net/", false)
        {
            InitializeComponent();

            this.LoadHandler.OnLoadEnd += (s, e) =>
            {
                //this.ShowDevTools();
            };

            this.GlobalObject.AddFunction("saveData").Execute += (s, e) =>
            {
                var price = e.Arguments[0].StringValue;
                var amt   = e.Arguments[1].StringValue;
                var time  = e.Arguments[2].StringValue;
                Console.WriteLine($"{price}|{amt}|{time}");
            };

            this.RequestHandler.GetResourceHandler += (sender, e) =>
            {
                if (e.Request.Url.Contains("https://www.bitstamp.net/s/js/bitstamp-front.js"))
                {
                    Chromium.CfxResourceHandler handler = new Chromium.CfxResourceHandler();
                    byte[] data = new byte[0];
                    handler.ProcessRequest += (o, ent) =>
                    {
                        data = System.IO.File.ReadAllBytes(Application.StartupPath + "/bitstampPusher.txt");
                        ent.Callback.Continue();
                        ent.SetReturnValue(true);
                    };
                    handler.GetResponseHeaders += (o, ent) =>
                    {
                        ent.ResponseLength    = -1;
                        ent.Response.MimeType = "text/plain";
                        ent.Response.Status   = 200;
                    };
                    int readResponseStreamOffset = 0;
                    handler.ReadResponse += (o, ent) =>
                    {
                        if (readResponseStreamOffset >= data.Length)
                        {
                            ent.SetReturnValue(false);
                            return;
                        }
                        int bytesToCopy = data.Length - readResponseStreamOffset;
                        if (bytesToCopy > ent.BytesToRead)
                        {
                            bytesToCopy = ent.BytesToRead;
                        }
                        System.Runtime.InteropServices.Marshal.Copy(data, readResponseStreamOffset, ent.DataOut, bytesToCopy);
                        ent.BytesRead             = bytesToCopy;
                        readResponseStreamOffset += bytesToCopy;
                        ent.SetReturnValue(true);
                    };

                    e.SetReturnValue(handler);
                }
            };
        }
        public HuobiSocket() : base(null, false)
        {
            InitializeComponent();

            this.LoadHandler.OnLoadEnd += (s, e) =>
            {
                if (isFirst)
                {
                    isFirst = false;
                    ShowDevTools();
                    this.ExecuteJavascript("location.href = 'https://www.huobi.pro/zh-cn/btc_usdt/exchange/'");
                }
            };

            this.GlobalObject.AddFunction("saveData").Execute += (s, e) =>
            {
                try
                {
                    var price = e.Arguments[0].StringValue;
                    var amt   = e.Arguments[1].StringValue;
                    var time  = e.Arguments[2].StringValue;
                    //Console.WriteLine($"{price}|{amt}|{time}");
                    Insert(price, time);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            };



            this.RequestHandler.GetResourceHandler += (sender, e) =>
            {
                if (e.Request.Url.Contains("https://www.huobi.pro/assets/scripts/exchange"))
                {
                    using (var web = new System.Net.WebClient()
                    {
                        Encoding = Encoding.UTF8
                    })
                    {
                        var html = web.DownloadString(e.Request.Url);

                        var index = html.IndexOf("var e=t.rep?\"rep\":t.unsubbed?\"unsubbed\":\"ch\",");

                        html = html.Insert(index, @"
                        if(t.ch == ""market.btcusdt.trade.detail""){
                            for(var index = 0;index < t.tick.data.length;index++)
                            {
                                var date = new Date(t.tick.data[index].ts)
                                var dateStr = date.getFullYear() + ""-"" + (date.getMonth() + 1) + ""-"" + date.getDate() + "" "" + date.getHours() + "":"" + date.getMinutes() + "":"" + date.getSeconds() + ""."" + date.getMilliseconds();
                                window.top.saveData(t.tick.data[index].price + """",t.tick.data[index].amount + """",dateStr)
                            }
                        }
                        ");

                        //System.IO.File.WriteAllText("C:\\1.js", html);

                        Chromium.CfxResourceHandler handler = new Chromium.CfxResourceHandler();
                        byte[] data = new byte[0];
                        handler.ProcessRequest += (o, ent) =>
                        {
                            //data = System.IO.File.ReadAllBytes(@"C:\Users\Cheney\Desktop\exchange_8532b9a8.js");
                            data = System.Text.Encoding.UTF8.GetBytes(html);
                            ent.Callback.Continue();
                            ent.SetReturnValue(true);
                        };
                        handler.GetResponseHeaders += (o, ent) =>
                        {
                            ent.ResponseLength    = -1;
                            ent.Response.MimeType = "text/plain";
                            ent.Response.Status   = 200;
                        };
                        int readResponseStreamOffset = 0;
                        handler.ReadResponse += (o, ent) =>
                        {
                            if (readResponseStreamOffset >= data.Length)
                            {
                                ent.SetReturnValue(false);
                                return;
                            }
                            int bytesToCopy = data.Length - readResponseStreamOffset;
                            if (bytesToCopy > ent.BytesToRead)
                            {
                                bytesToCopy = ent.BytesToRead;
                            }
                            System.Runtime.InteropServices.Marshal.Copy(data, readResponseStreamOffset, ent.DataOut, bytesToCopy);
                            ent.BytesRead             = bytesToCopy;
                            readResponseStreamOffset += bytesToCopy;
                            ent.SetReturnValue(true);
                        };

                        e.SetReturnValue(handler);
                    }
                }
            };
        }