Beispiel #1
0
        public void TestGoogleSearch()
        {
            GoogleProxy proxy  = new GoogleProxy();
            string      result = proxy.DoSearch(".net").Result.Content.ReadAsStringAsync().Result;

            Assert.IsNotNull(result);
        }
Beispiel #2
0
 public ProjectAnalyzer(ProgramConfiguration configuration, MongoProxy mongoProxy, GitProxy gitProxy, GoogleProxy googleProxy,
                        AliasReader aliasReader, ILogger <ProjectAnalyzer> logger)
 {
     _configuration = configuration;
     _mongoProxy    = mongoProxy;
     _gitProxy      = gitProxy;
     _googleProxy   = googleProxy;
     _aliasReader   = aliasReader;
     _logger        = logger;
 }
Beispiel #3
0
        public static async Task GL(GoogleProxy googleProxy, List <BsonDocument> users)
        {
            // get user locations
            var authorLocationTasks = users
                                      .Select(o =>
            {
                // TODO: Move this logic to a user class

                // parse bson
                var login    = o["login"];
                var location = o["location"];

                return(new GLOutput
                {
                    Login = login != BsonNull.Value ? login.AsString : string.Empty,
                    GitLocation = location != BsonNull.Value ? location.AsString : string.Empty,
                });
            })
                                      // treat only users who provided their locations
                                      .Where(o => !string.IsNullOrWhiteSpace(o.GitLocation) &&
                                             !string.IsNullOrWhiteSpace(o.Login))
                                      .Select(async o =>
            {
                // send query to google geocode API
                var location = o.GitLocation;
                var geocode  = await googleProxy.LookupGeocode(location);

                return(new GLOutput(o, geocode));
            })
                                      .ToList();

            // wait for completion
            await Task.WhenAll(authorLocationTasks);

            var authorLocations = authorLocationTasks.Select(o => o.Result);

            // output to file
            using (var streamWriter = new StreamWriter("Metrics/GL.csv"))
                using (var csvWriter = new CsvWriter(streamWriter))
                    csvWriter.WriteRecords(authorLocations);
        }
Beispiel #4
0
        public static void proxy()
        {
            Console.WriteLine("直接访问Google:");
            Google google = new Google();

            try
            {
                google.Search("特朗普");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("----------------------------");
            Console.WriteLine("使用代理访问Google:");
            ISearchEngine searchEngine = new GoogleProxy();

            searchEngine.Search("特朗普");

            Console.ReadLine();
        }
        private void Cleanup(bool fromClient = false)
        {
            lock (this)
            {
                if (Closed == false)
                {
                    Closed = true;

                    MainForm.Instance.AddLog("[" + Client.GetHashCode() + "] disconnect from " + ((fromClient) ? "client" : "google"));
                    LogActiveConnections();

                    Client.Close(10);

                    if (GoogleProxy != null)
                    {
                        GoogleProxy.Close(10);
                    }

                    Server.Disconnect(this);
                }
            }
        }
        /// <summary>
        /// 두개의 연결이 서로 데이터를 받을때마다 서로에게 보내주도록 핸들러를 설정
        /// </summary>
        private void LinkConnection()
        {
            GoogleProxy.NoDelay = true;
            Client.NoDelay      = true;

            var ev = new SocketAsyncEventArgs();

            ev.SetBuffer(new byte[8196], 0, 8196);
            ev.Completed += OnReceived;
            if (GoogleProxy.ReceiveAsync(ev) == false)
            {
                OnReceived(GoogleProxy, ev);
            }

            ev = new SocketAsyncEventArgs();
            ev.SetBuffer(new byte[8196], 0, 8196);
            ev.Completed += OnReceived;

            if (Client.ReceiveAsync(ev) == false)
            {
                OnReceived(Client, ev);
            }
        }