Example #1
0
        /// <summary>
        /// Create a new UDP receiver listening on the given IP socket.
        /// </summary>
        /// <param name="IPSocket">The IP socket to listen.</param>
        /// <param name="ServiceBanner">Service banner.</param>
        /// <param name="Mapper">A delegate to transform the incoming UDP packets into custom data structures.</param>
        /// <param name="ReceiverThreadName">The optional name of the UDP receiver thread.</param>
        /// <param name="ReceiverThreadPriority">The optional priority of the UDP receiver thread.</param>
        /// <param name="ReceiverThreadIsBackground">Whether the UDP receiver thread is a background thread or not.</param>
        /// <param name="PacketThreadsNameCreator">An optional delegate to set the name of the UDP packet threads.</param>
        /// <param name="PacketThreadsPriority">The optional priority of the UDP packet threads.</param>
        /// <param name="PacketThreadsAreBackground">Whether the UDP packet threads are background threads or not.</param>
        /// <param name="Autostart">Start the UDP receiver thread immediately.</param>
        public UDPReceiver(IPSocket IPSocket,
                           String ServiceBanner                  = DefaultServiceBanner,
                           MapperDelegate Mapper                 = null,
                           String ReceiverThreadName             = "UDP receiver thread",
                           ThreadPriority ReceiverThreadPriority = ThreadPriority.AboveNormal,
                           Boolean ReceiverThreadIsBackground    = true,
                           Func <UDPPacket <TData>, String> PacketThreadsNameCreator = null,
                           ThreadPriority PacketThreadsPriority = ThreadPriority.AboveNormal,
                           Boolean PacketThreadsAreBackground   = true,
                           Boolean Autostart = false)

            : this(IPSocket.IPAddress,
                   IPSocket.Port,
                   ServiceBanner,
                   Mapper,
                   null,
                   ReceiverThreadName,
                   ReceiverThreadPriority,
                   ReceiverThreadIsBackground,
                   PacketThreadsNameCreator,
                   PacketThreadsPriority,
                   PacketThreadsAreBackground,
                   Autostart)

        {
        }
Example #2
0
 protected IEnumerable <T> Map <T>(IDataReader query, MapperDelegate <T> recordMapper)
 {
     while (query.Read())
     {
         yield return(recordMapper(query));
     }
 }
        /// <summary>
        /// Initializes the layout algorithm and its layout data.
        /// </summary>
        private void InitializeLayout()
        {
            orthogonalEdgeRouter = new EdgeRouter {
                ConsiderNodeLabels = true
            };

            hl = new HierarchicLayout {
                OrthogonalRouting  = true,
                LayoutOrientation  = LayoutOrientation.LeftToRight,
                ConsiderNodeLabels = true
            };

            // outgoing edges must be routed to the right of the node
            // we use the same value for all edges, which is a strong port constraint that forces
            // the edge to leave at the east (right) side
            var east = PortConstraint.Create(PortSide.East, true);
            // incoming edges must be routed to the left of the node
            // we use the same value for all edges, which is a strong port constraint that forces
            // the edge to enter at the west (left) side
            var west = PortConstraint.Create(PortSide.West, true);

            MapperDelegate <IEdge, PortConstraint> sourceDelegate = edge => ((PortDescriptor)edge.SourcePort.Tag).X == 0 ? west : east;
            MapperDelegate <IEdge, PortConstraint> targetDelegate = edge => ((PortDescriptor)edge.TargetPort.Tag).X == 0 ? west : east;

            oerData = new PolylineEdgeRouterData {
                SourcePortConstraints = { Delegate = sourceDelegate },
                TargetPortConstraints = { Delegate = targetDelegate }
            };

            hlData = new HierarchicLayoutData {
                SourcePortConstraints = { Delegate = sourceDelegate },
                TargetPortConstraints = { Delegate = targetDelegate }
            };
        }
Example #4
0
        /// <summary>
        /// Create a new UDP receiver listening on the given IP address and port.
        /// </summary>
        /// <param name="IPAddress">The IP address to listen.</param>
        /// <param name="Port">The port to listen.</param>
        /// <param name="ServiceBanner">Service banner.</param>
        /// <param name="Mapper">A delegate to transform the incoming UDP packets into custom data structures.</param>
        /// <param name="ReceiverThreadName">The optional name of the UDP receiver thread.</param>
        /// <param name="ReceiverThreadPriority">The optional priority of the UDP receiver thread.</param>
        /// <param name="ReceiverThreadIsBackground">Whether the UDP receiver thread is a background thread or not.</param>
        /// <param name="PacketThreadsNameCreator">An optional delegate to set the name of the UDP packet threads.</param>
        /// <param name="PacketThreadsPriority">The optional priority of the UDP packet threads.</param>
        /// <param name="PacketThreadsAreBackground">Whether the UDP packet threads are background threads or not.</param>
        /// <param name="Autostart">Start the UDP receiver thread immediately.</param>
        public UDPReceiver(IIPAddress IPAddress,
                           IPPort Port,
                           String ServiceBanner                  = DefaultServiceBanner,
                           MapperDelegate Mapper                 = null,
                           MapReduceDelegate MapReduce           = null,
                           String ReceiverThreadName             = "UDP receiver thread",
                           ThreadPriority ReceiverThreadPriority = ThreadPriority.AboveNormal,
                           Boolean ReceiverThreadIsBackground    = true,
                           Func <UDPPacket <TData>, String> PacketThreadsNameCreator = null,
                           ThreadPriority PacketThreadsPriority = ThreadPriority.AboveNormal,
                           Boolean PacketThreadsAreBackground   = true,
                           Boolean Autostart = false)

        {
            if (Mapper == null && MapReduce == null)
            {
                throw new ArgumentNullException("The mapper and mapreduce delegate can not be both null!");
            }

            this._IPAddress               = IPAddress;
            this._IsMulticast             = IPAddress.IsMulticast;
            this._Port                    = Port;
            this._IPSocket                = new IPSocket(_IPAddress, _Port);
            this.ServiceBanner            = ServiceBanner;
            this.Mapper                   = Mapper;
            this.MapReduce                = MapReduce;
            this._ReceiverThreadName      = ReceiverThreadName;
            this._ReceiverThreadPriority  = ReceiverThreadPriority;
            this.PacketThreadsNameCreator = (PacketThreadsNameCreator == null)
                                                  ? UDPpacket => "UDP packet from " + UDPpacket.RemoteSocket.IPAddress + ":" + UDPpacket.RemoteSocket.Port
                                                  : PacketThreadsNameCreator;
            this._PacketThreadsPriority      = PacketThreadsPriority;
            this._PacketThreadsAreBackground = PacketThreadsAreBackground;

            var LocalIPEndPoint = new IPEndPoint(new System.Net.IPAddress(_IPAddress.GetBytes()), _Port.ToInt32());

            this.LocalSocket       = new IPSocket(LocalIPEndPoint);
            this.LocalDotNetSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.LocalDotNetSocket.Bind(LocalIPEndPoint);

            this.BufferSize     = 65536;
            this.ReceiveTimeout = 5000;

            if (IsMulticast)
            {
                LocalDotNetSocket.SetSocketOption(SocketOptionLevel.IP,
                                                  SocketOptionName.AddMembership,
                                                  new MulticastOption(System.Net.IPAddress.Parse(_IPAddress.ToString()),
                                                                      System.Net.IPAddress.Any));
            }

            this.CancellationTokenSource = new CancellationTokenSource();
            this.CancellationToken       = CancellationTokenSource.Token;

            if (Autostart)
            {
                Start();
            }
        }
Example #5
0
        public static IConnectorLinker <TOutput> Map <T, TOutput>(this IConnectorLinker <T> parent,
                                                                  MapperDelegate <T, TOutput> mapper)
        {
            var connector = new MappingConnector <T, TOutput>(mapper, parent.Context);

            parent.Link(connector);
            return(connector);
        }
Example #6
0
        public T ExecuteReader <T>(String sql, MapperDelegate <T> mapper)
        {
            using (OdbcConnection connection = new OdbcConnection(_connectionString))
            {
                connection.Open();

                using (OdbcCommand command = new OdbcCommand(sql, connection))
                {
                    using (OdbcDataReader reader = command.ExecuteReader())
                    {
                        return(mapper(reader));
                    }
                }
            }
        }
Example #7
0
        public List <decimal[]> GetData(List <Parameter> parameters, Wellbore wellbore, DateTime start, DateTime end)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (wellbore == null)
            {
                throw new ArgumentNullException("wellbore");
            }

            parameters.ForEach(x => FillParameter(x));

            StringBuilder queryBuilder = new StringBuilder();

            parameters.ForEach(x => queryBuilder.Append(", ").Append(x.Code));
            var limitCorrector = GetLimitPoints(wellbore.Id, start, parameters, queryBuilder);

            queryBuilder.Insert(0, "select time, ");
            queryBuilder.Append(" from temporal_measuring where wellbore_id = :wellboreId and time between :startTime and :endTime");

            var oldValues = new decimal[parameters.Count];

            for (var i = 0; i < parameters.Count; ++i)
            {
                oldValues[i] = limitCorrector[i];
            }

            MapperDelegate <decimal[]> mapper = x =>
            {
                var r = new decimal[parameters.Count + 1];

                for (var i = 0; i < parameters.Count; ++i)
                {
                    var val = x[i + 1];
                    r[i] = val == DBNull.Value ? oldValues[i] : Convert.ToDecimal(val) / parameters[i].Multiplier;
                }
                r[parameters.Count] = Convert.ToDateTime(x[0]).Ticks;

                oldValues = r;
                return(r);
            };

            return(new List <decimal[]>(QueryAndMap(queryBuilder.ToString(), new { wellboreId = wellbore.Id, startTime = start, endTime = end }, mapper)));
        }
Example #8
0
        public static List <TEntity> FillEntity <TEntity>(string SQLSelectCommand, MapperDelegate mapperMethod) where TEntity : class
        {
            OleDbConnection con     = new OleDbConnection(SqlConnection);
            OleDbCommand    command = new OleDbCommand(SQLSelectCommand, con);

            command.CommandTimeout = 60000;

            List <TEntity> entityList = new List <TEntity>();

            try
            {
                con.Open();

                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            entityList.Add(((TEntity)mapperMethod(reader)));
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

            return(entityList);
        }
Example #9
0
 public static IMapper <K, V> AddMapper <K, V>(this IMapperRegistry registry, object key, MapperDelegate <K, V> mapperDelegate)
 {
     return(registry.CreateDelegateMapper(key, mapperDelegate));
 }
Example #10
0
 public IEnumerable <T> QueryAndMap <T>(string query, object queryParameters, MapperDelegate <T> recordMapper)
 {
     return(Map(Query(query, queryParameters), recordMapper));
 }
Example #11
0
 public T ExecuteReader <T>(string sql, MapperDelegate <T> mapper)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #12
0
 public MappingConnector(MapperDelegate <TInput, TOutput> function, ConnectorContext context) : base(GetFunctionName(function), context)
 {
     _function = function;
 }