Exemplo n.º 1
0
        public ClientController(string rpc_addr, string bcast_addr) : base()
        {
            this.rpc_addr   = rpc_addr;
            this.bcast_addr = bcast_addr;

            handle          = this.Handle;
            dispatcher      = new EventDispatcher();
            activeSet       = new ActiveSet(dispatcher);
            positionManager = new PositionManager(dispatcher);

            //
            //  Set the socket addresses
            //

            rpc = rpc_ctx.Socket(SocketType.REQ);
            rpc.Connect(rpc_addr);

            //
            //  Create the RPC timer
            //

            timer = new System.Threading.Timer(
                this.TimeoutEvent, null,
                Timeout.Infinite,
                Timeout.Infinite);

            //
            //  Create the broadcast receiver thread
            //

            Thread broadcastThread = new Thread(new ThreadStart(BroadcastReceiver));

            broadcastThread.Name         = "BroadcastReceiver";
            broadcastThread.IsBackground = true;
            broadcastThread.Start();

            //
            //  Create the heartbeat thread
            //

            Thread heartbeatThread = new Thread(new ThreadStart(HeartbeatSender));

            heartbeatThread.Name         = "HeartbeatSender";
            heartbeatThread.IsBackground = true;
            heartbeatThread.Start();

            //
            //  Set the timeout
            //

            timeout = Convert.ToInt32((string)ConfigurationManager.AppSettings["timeout"]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tries to move the waypoint to the passive set.
        /// </summary>
        /// <param name="waypoint">The waypoint to move.</param>
        /// <returns>True, if the waypoint could be moved. False otherwise.</returns>
        public async Task <bool> MoveToPassiveSet(Waypoint waypoint)
        {
            if (waypoint != null)
            {
                return(DbManager.InTransaction(transaction =>
                {
                    var exists = ActiveSet.Contains(waypoint);
                    waypoint.Visited = true;
                    return exists;
                }));
            }

            return(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Tries to move the waypoint to the passive set.
 /// </summary>
 /// <param name="waypoint">The waypoint to move.</param>
 /// <returns>True, if the waypoint could be moved. False otherwise.</returns>
 public bool MoveToPassiveSet(Waypoint waypoint)
 {
     if (waypoint != null)
     {
         using (IoCManager.Resolve <IDataAccess>().StartTransaction())
         {
             bool exists = ActiveSet.Contains(waypoint);
             waypoint.Visited = true;
             if (exists)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Order the set of active exhibits by distance.
        /// </summary>
        private void OrderByDistance()
        {
            List <Exhibit> tmpList = new List <Exhibit> ();

            double minDistance = 0;
            var    minPosition = 0;
            double currentDistance;
            var    i = 0;

            while (ActiveSet.Count > 0)
            {
                currentDistance = ActiveSet [i].GetDistance(Position);
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (minDistance == 0)
                {
                    minDistance = currentDistance;
                    minPosition = i;
                }
                if (currentDistance < minDistance)
                {
                    minDistance = currentDistance;
                    minPosition = i;
                }
                if (i == ActiveSet.Count - 1)
                {
                    tmpList.Add(ActiveSet [minPosition]);
                    ActiveSet.RemoveAt(minPosition);
                    minDistance = 0;
                    i           = 0;
                }
                else
                {
                    i++;
                }
            }

            foreach (Exhibit exhibit in ActiveSet)
            {
                ActiveSet.Remove(exhibit);
            }
            foreach (Exhibit exhibit in tmpList)
            {
                ActiveSet.Add(exhibit);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update the currently active categories.
        /// </summary>
        /// <param name="categories">The categories to set, as strings.</param>
        public void UpdateCategories(List <string> categories)
        {
            foreach (Exhibit exhibit in ActiveSet)
            {
                ActiveSet.Remove(exhibit);
            }

            foreach (string category in categories)
            {
                foreach (Exhibit exhibit in InitSet)
                {
                    if (exhibit.Categories.Count(element => element.Value == category) > 0)
                    {
                        this.ActiveSet.Add(exhibit);
                    }
                }
            }

            this.OrderByDistance();
        }
Exemplo n.º 6
0
 public IEnumerator <Exhibit> GetEnumerator()
 {
     return(ActiveSet.GetEnumerator());
 }
Exemplo n.º 7
0
 public Exhibit this[int index]
 {
     get { return(ActiveSet.ElementAt <Exhibit>(index)); }
     set { ActiveSet.Insert(index, value); }
 }