示例#1
0
            public static void RunTestClient(string pathToServerXmlList)
            {
                List <Task <IActorMessage> > connectionTasks = new List <Task <IActorMessage> >();
                XElement el = XElement.Load(pathToServerXmlList);

                foreach (var hostinfo in el.Elements("hostinfo"))
                {
                    string hostName = hostinfo.Element("hostname").Value;

                    ServerConnection conn = new ServerConnection(hostName, "", "", 1, false);

                    var connctionRequest = new Messages.ConnectToServer(conn);
                    connectionTasks.Add(Telegraph.Instance.Ask(connctionRequest));
                    System.Threading.Thread.Sleep(100);

                    //var disconnectRequest = new Messages.DisconnectFromServer(conn);
                    //connectionTasks.Add(Telegraph.Instance.Ask(disconnectRequest));
                }

                Task.WaitAll(connectionTasks.ToArray());

                Telegraph.Instance.WaitTillEmpty(new TimeSpan(0, 10, 0));
            }
示例#2
0
            public static void RunClientTest(ServerConnection conn)
            {
                ServerConnection[]           conns           = new ServerConnection[(int)conn.MaxConcurrentConnectionCount];
                List <Task <IActorMessage> > connectionTasks = new List <Task <IActorMessage> >();

                for (int i = 0; i < conn.MaxConcurrentConnectionCount; ++i)
                {
                    conns[i] = new ServerConnection(conn.ServerName, conn.UserName, conn.Password, conn.MaxConcurrentConnectionCount, conn.Authenticate);
                    var connctionRequest = new Messages.ConnectToServer(conns[i]);
                    connectionTasks.Add(Telegraph.Instance.Ask(connctionRequest));
                }

                Task.WaitAll(connectionTasks.ToArray());
                conn = conns[0];

                var getCommands        = new Messages.PopulateCommandList(conn);
                var populateCommandAsk = Telegraph.Instance.Ask(getCommands);

                populateCommandAsk.Wait();

                Console.WriteLine("Connected!!");
                for (int i = 1; i < conn.MaxConcurrentConnectionCount; ++i)
                {
                    conns[i].SupportedCommands = conns[0].SupportedCommands;
                }

                var listNewsGroup    = new Messages.ListNewsGroups(conn);
                var listNewsGroupAsk = Telegraph.Instance.Ask(listNewsGroup);

                listNewsGroupAsk.Wait();

                //Retrieve Articles on multiple threads.
                uint articleStartID = 25;
                List <Task <IActorMessage> > articleRetrievalTasks = new List <Task <IActorMessage> >();

                for (uint i = 0; i < conn.MaxConcurrentConnectionCount; ++i)
                {
                    var getArticleHead = new Messages.GetArticleHead(conns[i], "microsoft.public.windows.vista.mail", articleStartID + i);
                    articleRetrievalTasks.Add(Telegraph.Instance.Ask(getArticleHead));
                }
                Task.WaitAll(articleRetrievalTasks.ToArray());

                foreach (var t in articleRetrievalTasks)
                {
                    string val = (t.Result.ProcessingResult as string);
                    Telegraph.Instance.Tell(val);
                }

                var getArticleBody    = new Messages.GetArticleBody(conn, "microsoft.public.windows.vista.mail", 25);
                var getArticleBodyAsk = Telegraph.Instance.Ask(getArticleBody);

                getArticleBodyAsk.Wait();

                var getNextArticle    = new Messages.GetNextArticleId(conn, "microsoft.public.windows.vista.mail");
                var getNextArticleAsk = Telegraph.Instance.Ask(getNextArticle);

                getNextArticleAsk.Wait();
                uint nextID = (uint)getNextArticleAsk.Result.ProcessingResult;

                var getNextArticleHead    = new Messages.GetArticleHead(conn, "microsoft.public.windows.vista.mail", nextID);
                var getNextArticleHeadAsk = Telegraph.Instance.Ask(getNextArticleHead);

                getNextArticleHeadAsk.Wait();

                var postArticle = new Messages.PostArticle(conn, "microsoft.public.nntp.test");

                postArticle.Message = "Testing";
                var postArticleAsk = Telegraph.Instance.Ask(postArticle);

                postArticleAsk.Wait();

                List <Task <IActorMessage> > disconnectTasks = new List <Task <IActorMessage> >();

                for (uint i = 0; i < conn.MaxConcurrentConnectionCount; ++i)
                {
                    var disconnect = new Messages.DisconnectFromServer(conns[i]);
                    disconnectTasks.Add(Telegraph.Instance.Ask(disconnect));
                }

                Task.WaitAll(disconnectTasks.ToArray());
            }