Exemplo n.º 1
0
        // Creates a new epics client

        public CAClient( )
        {
            Udp        = DataPipe.CreateClientUdp(this);
            Searcher   = new Searcher(this);
            echoThread = new Thread(Echoer)
            {
                IsBackground = true
            };
            echoThread.Start();
        }
Exemplo n.º 2
0
 private void SetParams()
 {
     db.Host     = dbHostBox.Text;
     db.Port     = dbPortBox.Text;
     db.Database = dbDatabaseBox.Text;
     db.User     = dbUserBox.Text;
     db.Password = dbPasswordBox.Text;
     db.TessPath = tessPathBox.Text;
     db.SaveParams();
     db = new DataPipe();
 }
 internal void RemoveIocConnection(DataPipe ioc)
 {
     lock (Iocs)
     {
         try
         {
             IPEndPoint ip = Iocs.Where(row => row.Value == ioc).Select(row => row.Key).First();
             Iocs.Remove(ip);
         }
         catch
         {
         }
     }
 }
Exemplo n.º 4
0
 public void Clear()
 {
     this.@event = null;
     CommandPipe.Clear();
     DataPipe.Clear();
     ServicePipe.Clear();
     HistoricalPipe.Clear();
     ExecutionPipe.Clear();
     for (int i = 0; i < this.attachedCount; i++)
     {
         this.attached[i] = null;
     }
     this.attachedCount = 0;
 }
        public CAServer(IPAddress ipAddress = null, int tcpPort = 5064, int udpPort = 5064, int beaconPort = 0)
        {
            if (ipAddress == null)
            {
                ipAddress = IPAddress.Any;
            }

            if (beaconPort == 0)
            {
                beaconPort = udpPort + 1;
            }
            this.TcpPort    = tcpPort;
            this.UdpPort    = udpPort;
            this.BeaconPort = beaconPort;
            listener        = new CaServerListener(this, new IPEndPoint(ipAddress, tcpPort));
            udpPipe         = DataPipe.CreateServerUdp(this, ipAddress, udpPort);
        }
Exemplo n.º 6
0
        protected override RESULT Process(StringBuilder messager)
        {
            var working = Config.Instance.INFO.BizTime.IsWorkingTime;

            if (working > 0)
            {
                if (CheckTable <DBTStkFavoriteEntity>())
                {
                    accessor.RetrieveEntity <DBTStkFavoriteEntity>().FindAll(data => !workers.Any(worker => worker.id.Equals(data.Code))).ForEach(entity =>
                    {
                        var StockTask = new StockClient(entity.Code, null);

                        var pipe1 = new DataPipe();
                        var pipe2 = new DataPipe();
                        AddPuts[SocketClient.ID](StockTask.id, pipe1);
                        StockTask.AddGetPlug(SocketClient.ID, pipe1);
                        AddGets[SocketClient.ID](StockTask.id, pipe2);
                        StockTask.AddPutPlug(SocketClient.ID, pipe2);

                        var pipe3 = new DataPipe();
                        var pipe4 = new DataPipe();
                        StockTask.AddPutPlug(TradeClient.ID, pipe3);
                        AddGets[TradeClient.ID](StockTask.id, pipe3);
                        StockTask.AddGetPlug(TradeClient.ID, pipe4);
                        AddPuts[TradeClient.ID](StockTask.id, pipe4);

                        var pipe5 = new DataPipe();
                        var pipe6 = new DataPipe();
                        AddPuts[CollectClient.ID](StockTask.id, pipe5);
                        StockTask.AddGetPlug(CollectClient.ID, pipe5);
                        AddGets[CollectClient.ID](StockTask.id, pipe6);
                        StockTask.AddPutPlug(CollectClient.ID, pipe6);

                        var worker = new Worker(StockTask.id, StockTask);
                        workers.Add(worker);
                        worker.Start();
                    });
                }
            }
            else
            {
                tables.Clear();
            }

            return(RESULT.OK);
        }
Exemplo n.º 7
0
        internal DataPipe GetIocConnection(IPEndPoint iPEndPoint)
        {
            DataPipe ioc;

            lock (Iocs)
            {
                if (!Iocs.ContainsKey(iPEndPoint))
                {
                    ioc = DataPipe.CreateTcp(this, iPEndPoint);
                    Iocs.Add(iPEndPoint, ioc);
                }
                else
                {
                    ioc = Iocs[iPEndPoint];
                }
            }
            return(ioc);
        }
Exemplo n.º 8
0
        private void databaseConnectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dbConnectionForm dbForm = new dbConnectionForm();
            DialogResult     res    = dbForm.ShowDialog();

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                db = new DataPipe();
                if (CheckIfInitialized())
                {
                    RefreshFontList();
                    RefreshSubList();
                    RefreshLangList();
                }
                else
                {
                    MessageBox.Show("Franken+ was unable to initialize properly.  Please address the following issues and then restart Franken+:\r\n\r\n" + InitializationError);
                }
            }
        }
        internal DataPipe GetIocConnection(IPEndPoint iPEndPoint)
        {
            DataPipe ioc;

            lock (Iocs)
            {
                //Console.WriteLine("Getting IOC for " + iPEndPoint.ToString());
                if (!Iocs.ContainsKey(iPEndPoint))
                {
                    //Console.WriteLine("Creating new TCP");
                    ioc = DataPipe.CreateClientTcp(this, iPEndPoint);
                    Iocs.Add(iPEndPoint, ioc);
                }
                else
                {
                    //Console.WriteLine("Re-using TCP");
                    ioc = Iocs[iPEndPoint];
                }
            }
            return(ioc);
        }
Exemplo n.º 10
0
        internal void SetIoc(DataPipe pipe)
        {
            ClientTcpReceiver tcpReceiver = (ClientTcpReceiver)pipe[0];

            tcpReceiver.AddChannel(this);
            lock (ConnectionLock)
            {
                if (!Client.Searcher.Contains(this))
                {
                    return;
                }
                Client.Searcher.Remove(this);
                SID = 0;

                ioc = tcpReceiver;
                lock (ioc.ChannelSID)
                {
                    //Console.WriteLine(ioc.ChannelSID.Count);
                    // Channel already known
                    if (ioc.ChannelSID.ContainsKey(ChannelName))
                    {
                        SID = ioc.ChannelSID[ChannelName];
                        //Console.WriteLine("Here");
                        Channel chan = ioc.ConnectedChannels.FirstOrDefault(row => row.ChannelName == ChannelName && row.ChannelDataCount != 0);
                        if (chan != null)
                        {
                            this.ChannelDataCount   = chan.ChannelDataCount;
                            this.channelDefinedType = chan.ChannelDefinedType;
                            Status = ChannelStatus.CONNECTED;
                            ConnectionEvent.Set();
                        }
                    }
                }
            }
            if (SID != 0)
            {
                //Console.WriteLine("SID " + SID + " STATUS CHANGED");
                if (StatusChanged != null)
                {
                    StatusChanged(this, Status);
                }
                return;
            }
            if (Client.Configuration.DebugTiming)
            {
                lock (ElapsedTimings)
                {
                    if (!ElapsedTimings.ContainsKey("IocConnection"))
                    {
                        ElapsedTimings.Add("IocConnection", Stopwatch.Elapsed);
                    }
                }
            }

            // We need to create the channel
            int padding;

            if (ChannelName.Length % 8 == 0)
            {
                padding = 8;
            }
            else
            {
                padding = (8 - (ChannelName.Length % 8));
            }

            DataPacket packet = DataPacket.Create(16 + ChannelName.Length + padding);

            packet.Command    = (ushort)CommandID.CA_PROTO_CREATE_CHAN;
            packet.DataType   = 0;
            packet.DataCount  = 0;
            packet.Parameter1 = cid;
            packet.Parameter2 = (uint)CAConstants.CA_MINOR_PROTOCOL_REVISION;
            packet.SetDataAsString(ChannelName);
            //Status = ChannelStatus.CONNECTING;

            if (ioc != null)
            {
                ioc.Send(packet);
            }
            else
            {
                Disconnect();
                return;
            }
            lock (ElapsedTimings)
            {
                if (!ElapsedTimings.ContainsKey("SendCreateChannel"))
                {
                    ElapsedTimings.Add("SendCreateChannel", Stopwatch.Elapsed);
                }
            }
        }
Exemplo n.º 11
0
        void ReceiveConn(IAsyncResult result)
        {
            TcpListener listener = null;
            Socket      client   = null;

            try
            {
                listener = (TcpListener)result.AsyncState;
                client   = listener.EndAcceptSocket(result);
                //Console.WriteLine("!!! Received TCP connection");

                if (server.AcceptConnections == false)
                {
                    client.Shutdown(SocketShutdown.Both);
                    client.Close();
                    try
                    {
                        listener.BeginAcceptSocket(new AsyncCallback(ReceiveConn), listener);
                    }
                    catch
                    {
                        if (!disposed)
                        {
                            Rebuild();
                        }
                    }
                    return;
                }

                client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
            }
            catch (Exception ex)
            {
                try
                {
                    listener.BeginAcceptSocket(new AsyncCallback(ReceiveConn), listener);
                }
                catch
                {
                    if (!disposed)
                    {
                        Rebuild();
                    }
                }
                return;
            }

            if (disposed)
            {
                return;
            }

            if (client != null)
            {
                // Create the client chain and register the client in the Tcp Manager
                IPEndPoint clientEndPoint;
                DataPipe   chain = null;
                try
                {
                    clientEndPoint = (IPEndPoint)client.RemoteEndPoint;

                    chain = DataPipe.CreateServerTcp(this.server, client);

                    server.RegisterClient(chain);

                    // Send version
                    DataPacket packet = DataPacket.Create(16);
                    packet.Sender      = ipSource;
                    packet.Destination = clientEndPoint;
                    packet.Command     = 0;
                    packet.DataType    = 1;
                    packet.DataCount   = (uint)CAConstants.CA_MINOR_PROTOCOL_REVISION;
                    packet.Parameter1  = 0;
                    packet.Parameter2  = 0;
                    client.Send(packet.Data, 0, packet.Data.Length, SocketFlags.None);
                }
                catch (Exception ex)
                {
                    try
                    {
                        if (chain != null)
                        {
                            chain.Dispose();
                        }
                    }
                    catch
                    {
                    }
                }
            }

            // Wait for the next one
            try
            {
                listener.BeginAcceptSocket(new AsyncCallback(ReceiveConn), listener);
            }

            /*catch (ObjectDisposedException)
             * {
             *  return;
             * }*/
            catch (Exception ex)
            {
                if (!disposed)
                {
                    Rebuild();
                }
            }
        }
Exemplo n.º 12
0
        public void Initial(Action <string> progress, Action <long> complete)
        {
            FProgress = progress;
            FComplete = complete;
            IsReady   = false;
            DataPipe pipe1 = null;
            DataPipe pipe2 = null;

            managers.Clear();
            workers.Clear();

            // 1. Create Managers
            var SocketTask  = new SocketClient(Progress);
            var CollectTask = new CollectClient(Progress);
            var TradeTask   = new TradeClient(Progress);

            var GenerateTask = new GenerateClient(Progress);

            GenerateTask.AddGetPlugAction(SocketClient.ID, SocketTask.AddGetPlug);
            GenerateTask.AddPutPlugAction(SocketClient.ID, SocketTask.AddPutPlug);
            GenerateTask.AddGetPlugAction(CollectClient.ID, CollectTask.AddGetPlug);
            GenerateTask.AddPutPlugAction(CollectClient.ID, CollectTask.AddPutPlug);
            GenerateTask.AddGetPlugAction(TradeClient.ID, TradeTask.AddGetPlug);
            GenerateTask.AddPutPlugAction(TradeClient.ID, TradeTask.AddPutPlug);

            pipe1 = new DataPipe();
            pipe2 = new DataPipe();
            SocketTask.AddPutPlug(CollectClient.ID, pipe1);
            CollectTask.AddGetPlug(SocketClient.ID, pipe1);
            SocketTask.AddGetPlug(CollectClient.ID, pipe2);
            CollectTask.AddPutPlug(SocketClient.ID, pipe2);

            pipe1 = new DataPipe();
            pipe2 = new DataPipe();
            SocketTask.AddPutPlug(TradeClient.ID, pipe1);
            TradeTask.AddGetPlug(SocketClient.ID, pipe1);
            SocketTask.AddGetPlug(TradeClient.ID, pipe2);
            TradeTask.AddPutPlug(SocketClient.ID, pipe2);


            managers.Add(new Worker(GenerateClient.ID, GenerateTask));
            managers.Add(new Worker(SocketClient.ID, SocketTask));
            managers.Add(new Worker(CollectClient.ID, CollectTask));
            managers.Add(new Worker(TradeClient.ID, TradeTask));

            //// 2. Create Workers
            //if (stocks != null && stocks.Count > 0)
            //{
            //    foreach (string id in stocks)
            //    {
            //        if(string.IsNullOrWhiteSpace(id) || workers.Any(w=>w.id.Equals(id.Trim().ToUpper())))continue;
            //        var StockTask = new StockClient(id.Trim().ToUpper(), Progress);

            //        pipe1 = new DataPipe();
            //        pipe2 = new DataPipe();
            //        SocketTask.AddPutPlug(StockTask.id, pipe1);
            //        StockTask.AddGetPlug(SocketClient.ID, pipe1);
            //        SocketTask.AddGetPlug(StockTask.id, pipe2);
            //        StockTask.AddPutPlug(SocketClient.ID, pipe2);

            //        pipe1 = new DataPipe();
            //        pipe2 = new DataPipe();
            //        StockTask.AddPutPlug(TradeClient.ID, pipe1);
            //        TradeTask.AddGetPlug(StockTask.id, pipe1);
            //        StockTask.AddGetPlug(TradeClient.ID, pipe2);
            //        TradeTask.AddPutPlug(StockTask.id, pipe2);

            //        pipe1 = new DataPipe();
            //        pipe2 = new DataPipe();
            //        DatabaseTask.AddPutPlug(StockTask.id, pipe1);
            //        StockTask.AddGetPlug(DatabaseClient.ID, pipe1);
            //        DatabaseTask.AddGetPlug(StockTask.id, pipe2);
            //        StockTask.AddPutPlug(DatabaseClient.ID, pipe2);

            //        workers.Add(new Worker(StockTask.id, StockTask, 1000));
            //    }
            //}
            IsReady = true;
        }
Exemplo n.º 13
0
        private Event Dequeue_origin()
        {
            if (this.Mode == EventBusMode.Simulation)
            {
                while (true)
                {
                    if (!DataPipe.IsEmpty() && this.@event == null)
                    {
                        Event @event = DataPipe.Read();
                        if (@event.dateTime < this.framework.Clock.DateTime)
                        {
                            if (@event.TypeId != 205 && @event.TypeId != 206 && @event.TypeId != 229)
                            {
                                if (@event.TypeId != 230)
                                {
                                    Console.WriteLine(string.Concat(new object[]
                                    {
                                        "EventBus::Dequeue Skipping: ",
                                        @event,
                                        " ",
                                        @event.dateTime,
                                        " <> ",
                                        this.framework.Clock.DateTime
                                    }));
                                    continue;
                                }
                            }
                            @event.dateTime = this.framework.Clock.DateTime;
                            this.@event     = @event;
                        }
                        else
                        {
                            this.@event = @event;
                        }
                    }
                    if (!ExecutionPipe.IsEmpty())
                    {
                        goto IL_25D;
                    }
                    if (!LocalClockEventQueue.IsEmpty() && this.@event != null)
                    {
                        if (ReminderOrder == ReminderOrder.Before)
                        {
                            if (LocalClockEventQueue.PeekDateTime() <= [email protected])
                            {
                                break;
                            }
                        }
                        else if (LocalClockEventQueue.PeekDateTime() < [email protected])
                        {
                            goto IL_275;
                        }
                    }
                    if (!ExchangeClockEventQueue.IsEmpty() && this.@event != null && ([email protected] == 2 || [email protected] == 3 || [email protected] == 4))
                    {
                        if (ReminderOrder == ReminderOrder.Before)
                        {
                            if (ExchangeClockEventQueue.PeekDateTime() <= ((Tick)this.@event).ExchangeDateTime)
                            {
                                goto Block_12;
                            }
                        }
                        else if (ExchangeClockEventQueue.PeekDateTime() < ((Tick)this.@event).ExchangeDateTime)
                        {
                            goto IL_28D;
                        }
                    }
                    if (!CommandPipe.IsEmpty())
                    {
                        goto IL_299;
                    }
                    if (!ServicePipe.IsEmpty())
                    {
                        goto IL_2A5;
                    }
                    if (this.@event != null)
                    {
                        goto IL_2B1;
                    }
                    Thread.Sleep(1);
                }
                return(LocalClockEventQueue.Read());

Block_12:
                return(ExchangeClockEventQueue.Read());

IL_25D:
                return(ExecutionPipe.Read());

IL_275:
                return(LocalClockEventQueue.Read());

IL_28D:
                return(ExchangeClockEventQueue.Read());

IL_299:
                return(CommandPipe.Read());

IL_2A5:
                return(ServicePipe.Read());

IL_2B1:
                Event event2 = this.@event;
                this.@event  = null;
                for (int i = 0; i < this.attachedCount; i++)
                {
                    if (event2.TypeId != 205 && event2.TypeId != 206)
                    {
                        this.attached[i].Enqueue(event2);
                    }
                }
                return(event2);
            }
            while (true)
            {
                if (!DataPipe.IsEmpty() && this.@event == null)
                {
                    this.@event = DataPipe.Read();
                }
                if (!LocalClockEventQueue.IsEmpty())
                {
                    if (ReminderOrder == ReminderOrder.Before)
                    {
                        if (LocalClockEventQueue.PeekDateTime() <= this.framework.Clock.DateTime)
                        {
                            break;
                        }
                    }
                    else if (LocalClockEventQueue.PeekDateTime() < this.framework.Clock.DateTime)
                    {
                        goto IL_4AF;
                    }
                }
                if (!ExchangeClockEventQueue.IsEmpty() && this.@event != null && ([email protected] == 2 || [email protected] == 3 || [email protected] == 4))
                {
                    if (ReminderOrder == ReminderOrder.Before)
                    {
                        if (ExchangeClockEventQueue.PeekDateTime() <= ((Tick)this.@event).ExchangeDateTime)
                        {
                            goto Block_34;
                        }
                    }
                    else if (ExchangeClockEventQueue.PeekDateTime() < ((Tick)this.@event).ExchangeDateTime)
                    {
                        goto IL_4C7;
                    }
                }
                if (!ExecutionPipe.IsEmpty())
                {
                    goto IL_4D3;
                }
                if (!CommandPipe.IsEmpty())
                {
                    goto IL_4DF;
                }
                if (!ServicePipe.IsEmpty())
                {
                    goto IL_4EB;
                }
                if (this.@event != null)
                {
                    goto IL_4F7;
                }
                switch (this.IdleMode)
                {
                case EventBusIdleMode.Sleep:
                    Thread.Sleep(1);
                    break;

                case EventBusIdleMode.Wait:
                    this.hasWorkEvent.Reset();
                    this.hasWorkEvent.Wait(1);
                    break;
                }
            }
            return(LocalClockEventQueue.Read());

Block_34:
            return(ExchangeClockEventQueue.Read());

IL_4AF:
            return(LocalClockEventQueue.Read());

IL_4C7:
            return(ExchangeClockEventQueue.Read());

IL_4D3:
            return(ExecutionPipe.Read());

IL_4DF:
            return(CommandPipe.Read());

IL_4EB:
            return(ServicePipe.Read());

IL_4F7:
            Event result = this.@event;

            this.@event = null;
            return(result);
        }
Exemplo n.º 14
0
        private Event Dequeue_me()
        {
            if (Mode == EventBusMode.Simulation)
            {
                while (true)
                {
                    if (!DataPipe.IsEmpty() && this.@event == null)
                    {
                        var e = DataPipe.Read();
                        if (e.dateTime < this.framework.Clock.DateTime)
                        {
                            if (e.TypeId != EventType.OnQueueOpened && e.TypeId != EventType.OnQueueClosed && e.TypeId != EventType.OnSimulatorStop)
                            {
                                if (e.TypeId != EventType.OnSimulatorProgress)
                                {
                                    if (ShowWarnings)
                                    {
                                        Console.WriteLine($"EventBus::Dequeue Skipping: {e} {e.dateTime} <> {this.framework.Clock.DateTime}");
                                    }
                                    continue;
                                }
                            }
                            e.DateTime  = this.framework.Clock.DateTime;
                            this.@event = e;
                        }
                        else
                        {
                            this.@event = e;
                        }
                    }

                    if (!ExecutionPipe.IsEmpty())
                    {
                        return(this.ExecutionPipe.Read());
                    }

                    if (!LocalClockEventQueue.IsEmpty() && this.@event != null)
                    {
                        if (ReminderOrder == ReminderOrder.Before)
                        {
                            if (LocalClockEventQueue.PeekDateTime() <= [email protected])
                            {
                                return(LocalClockEventQueue.Read());
                            }
                        }
                        else if (this.LocalClockEventQueue.PeekDateTime() < [email protected])
                        {
                            return(LocalClockEventQueue.Read());
                        }
                    }

                    if (!LocalClockEventQueue.IsEmpty() && this.@event != null && ([email protected] == EventType.Bid || [email protected] == EventType.Ask || [email protected] == EventType.Trade))
                    {
                        if (ReminderOrder == ReminderOrder.Before)
                        {
                            if (ExchangeClockEventQueue.PeekDateTime() <= ((Tick)this.@event).ExchangeDateTime)
                            {
                                return(this.ExchangeClockEventQueue.Read());
                            }
                        }
                        else if (ExchangeClockEventQueue.PeekDateTime() < ((Tick)this.@event).ExchangeDateTime)
                        {
                            return(ExchangeClockEventQueue.Read());
                        }
                    }

                    if (!CommandPipe.IsEmpty())
                    {
                        return(CommandPipe.Read());
                    }

                    if (!ServicePipe.IsEmpty())
                    {
                        return(ServicePipe.Read());
                    }

                    if (this.@event != null)
                    {
                        // forward the event to externally attached queues
                        var e = this.@event;
                        this.@event = null;
                        for (int i = 0; i < this.attachedCount; i++)
                        {
                            if (e.TypeId != EventType.OnQueueOpened && e.TypeId != EventType.OnQueueClosed)
                            {
                                this.attached[i].Enqueue(e);
                            }
                        }
                        return(e);
                    }

                    // still not getting any event, try later
                    Thread.Sleep(1);
                }
            }

            // Mode == EventBusMode.Realtime
            while (true)
            {
                if (!DataPipe.IsEmpty() && this.@event == null)
                {
                    this.@event = DataPipe.Read();
                }

                if (!LocalClockEventQueue.IsEmpty())
                {
                    if (ReminderOrder == ReminderOrder.Before)
                    {
                        if (LocalClockEventQueue.PeekDateTime() <= this.framework.Clock.DateTime)
                        {
                            return(LocalClockEventQueue.Read());
                        }
                    }
                    else if (LocalClockEventQueue.PeekDateTime() < this.framework.Clock.DateTime)
                    {
                        return(LocalClockEventQueue.Read());
                    }
                }

                if (!ExchangeClockEventQueue.IsEmpty() && this.@event != null && ([email protected] == EventType.Bid || [email protected] == EventType.Ask || [email protected] == EventType.Trade))
                {
                    if (ReminderOrder == ReminderOrder.Before)
                    {
                        if (ExchangeClockEventQueue.PeekDateTime() <= ((Tick)this.@event).ExchangeDateTime)
                        {
                            return(this.ExchangeClockEventQueue.Read());
                        }
                    }
                    else if (ExchangeClockEventQueue.PeekDateTime() < ((Tick)this.@event).ExchangeDateTime)
                    {
                        return(ExchangeClockEventQueue.Read());
                    }
                }

                if (!ExecutionPipe.IsEmpty())
                {
                    return(ExecutionPipe.Read());
                }

                if (!CommandPipe.IsEmpty())
                {
                    return(CommandPipe.Read());
                }

                if (!ServicePipe.IsEmpty())
                {
                    return(ServicePipe.Read());
                }

                if (this.@event != null)
                {
                    var result = this.@event;
                    this.@event = null;
                    return(result);
                }

                // still not getting an event, go idle for a while
                switch (IdleMode)
                {
                case EventBusIdleMode.Sleep:
                    Thread.Sleep(1);
                    break;

                case EventBusIdleMode.Wait:
                    this.hasWorkEvent.Reset();
                    this.hasWorkEvent.Wait(1);
                    break;
                }
            }
        }