Esempio n. 1
0
 protected virtual void ProcessDELETE(ConnectorBase connector, Package package)
 {
     RaiseLogEvent(LogType.Error, "TornadoNetList.ProcessDELETE() Not Implemented");
 }
Esempio n. 2
0
        public void Process(ConnectorBase connector, Filter filter, string logFile, CancellationToken ct)
        {
            try
            {
                connector.Connect();
                RaiseLogEvent(LogType.Info, string.Format("Connected to Server"));
                Package package;

                if (logFile != null && logFile != string.Empty)
                {
                    RaiseLogEvent(LogType.Info, string.Format("Log file: {0}", logFile));
                    logFileFileStream   = new FileStream(logFile, FileMode.OpenOrCreate);
                    logFileStreamWriter = new StreamWriter(logFileFileStream);
                }
                bool first         = true;
                int  packagesCount = 0;
                var  sw            = new Stopwatch();

                while (true)
                {
                    Thread.Sleep(1);
                    while (connector.Receive(out package))
                    {
                        packagesCount++;
                        if (first)
                        {
                            sw.Start();
                            first = false;
                        }
                        try
                        {
                            bool processMessage = filter.applyFilter(package);
                            if (processMessage)
                            {
                                package.PrintToConsole(packagesCount, ConsoleColor.Green);

                                LogType infoLogType = LogType.Info;
                                switch (package.Method)
                                {
                                case Method.Response:
                                    infoLogType = LogType.InfoRed;
                                    break;

                                case Method.GET:
                                    infoLogType = LogType.InfoBlue;
                                    break;

                                case Method.POST:
                                    infoLogType = LogType.InfoGreen;
                                    break;

                                case Method.PUT:
                                    infoLogType = LogType.InfoYellow;
                                    break;

                                case Method.DELETE:
                                    infoLogType = LogType.InfoMagenta;
                                    break;

                                default:
                                    break;
                                }

                                RaiseLogEvent(infoLogType, string.Format("{0} {1}", packagesCount.ToString().PadRight(7), package.ToStringShort()));

                                switch (package.Method)
                                {
                                case Method.GET:
                                    ProcessGET(connector, package);
                                    Package eofPackage = new Package(senderId, package.Sender, 2, Method.Response, null);
                                    connector.Send(eofPackage);
                                    // TODO updates while sending hole list ?
                                    break;

                                case Method.POST:
                                    ProcessPOST(connector, package);
                                    Package postOKPackage = new Package(senderId, package.Sender, 1, Method.Response, null);
                                    //connector.Send(postOKPackage);

                                    break;

                                case Method.PUT:
                                    ProcessPUT(connector, package);
                                    Package putOKPackage = new Package(senderId, package.Sender, 1, Method.Response, null);
                                    //connector.Send(putOKPackage);
                                    break;

                                case Method.DELETE:
                                    ProcessDELETE(connector, package);
                                    Package deleteOKPackage = new Package(senderId, package.Sender, 1, Method.Response, null);
                                    //connector.Send(deleteOKPackage);
                                    break;

                                default:
                                    break;
                                }


                                if (logFileStreamWriter != null)
                                {
                                    logFileStreamWriter.WriteLine("{0}", package.ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            RaiseLogEvent(LogType.Error, "TornadoNetList.Process() Process Message: " + ex.Message);
                            return;
                        }

                        if (ct.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                    if (ct.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                RaiseLogEvent(LogType.Error, "TornadoNetList.Process(): " + e.Message);
            }

            return;
        }
Esempio n. 3
0
 public ClientPackageReceivedArgs(ConnectorBase Connector, ConcurrentQueue <Package> queue)
 {
     Connector = Connector;
     Queue     = queue;
 }