Example #1
0
 public void Set(IAIRoute[] route, IAIPath[] path)
 {
     Routes.Clear();
     Paths.Clear();
     Routes.AddRange(route);
     Paths.AddRange(path);
 }
 public Task RefreshRoutesAsync()
 {
     return(SafeExecuteAsync(async() =>
     {
         var routes = await _routeService.GetAllRoutesAsync();
         Routes.Clear();
         Routes.AddRange(routes);
     }));
 }
Example #3
0
        internal void Setup(string jsonData)
        {
            try
            {
                BusServices.Clear();
                _theSchedule = JsonConvert.DeserializeObject <ScheduleData>(jsonData);
                foreach (var service in _theSchedule.BusServices)
                {
                    BusServices.Add(service);
                }

                BusStations.Clear();
                foreach (var station in _theSchedule.BusStations)
                {
                    BusStations.Add(station);
                }
                Routes.Clear();
                Routes.AddRange(_theSchedule.Routes);

                RouteDetails.Clear();
                RouteDetails.AddRange(_theSchedule.RoutesDetails.Select(rd => new RouteStationViewModel {
                    RouteId = rd.BusRouteId, BusStation = BusStations.FirstOrDefault(BusStopSchedule => BusStopSchedule.Id == rd.BusStopId), OrderNum = rd.OrderNum, TimeDiff = rd.TimeDiff, RouteVariantId = rd.RouteVariant
                }));

                RouteBeginTimes.Clear();
                RouteBeginTimes.AddRange(_theSchedule.RoutesBeginTimes);

                TimeAdjustments.Clear();
                TimeAdjustments.AddRange(_theSchedule.TimeAdjustments.Select(adj => new TimeAdjustmentViewModel(RouteBeginTimes.First(rbt => rbt.RouteId == adj.RouteId && rbt.RouteVariant == adj.RouteVariantId && rbt.Id == adj.BeginTimeId && rbt.Days == adj.Days), TimeSpan.FromMinutes(adj.TimeAdjustmentMin), adj.StationId)));

                OnPropertyChanged(nameof(BusServices));
                OnPropertyChanged(nameof(BusStations));
            }
            catch (Exception exc)
            {
                var msg = exc.Message;
            }
        }
Example #4
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// @param node the {@link ZigBeeNode} that contains the newer node data.
        /// @return true if there were changes made as a result of the update
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                return(false);
            }

            bool updated = false;

            if (!NetworkAddress.Equals(node.NetworkAddress))
            {
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (!NodeDescriptor.Equals(node.NodeDescriptor))
            {
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (!PowerDescriptor.Equals(node.PowerDescriptor))
            {
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (AssociatedDevices)
            {
                if (!AssociatedDevices.Equals(node.AssociatedDevices))
                {
                    updated = true;
                    AssociatedDevices.Clear();
                    AssociatedDevices.AddRange(node.AssociatedDevices);
                }
            }

            lock (BindingTable)
            {
                if (!BindingTable.Equals(node.BindingTable))
                {
                    updated = true;
                    BindingTable.Clear();
                    BindingTable.AddRange(node.BindingTable);
                }
            }

            lock (Neighbors)
            {
                if (!Neighbors.Equals(node.Neighbors))
                {
                    updated = true;
                    Neighbors.Clear();
                    Neighbors.AddRange(node.Neighbors);
                }
            }

            lock (Routes)
            {
                if (!Routes.Equals(node.Routes))
                {
                    updated = true;
                    Routes.Clear();
                    Routes.AddRange(node.Routes);
                }
            }

            // TODO: How to deal with endpoints

            return(updated);
        }
Example #5
0
        /// <summary>
        /// Create and initialize a new instance of <see cref="HttpHandler"/>.
        /// </summary>
        /// <param name="rootUrl">URL under which the service will be available.</param>
        /// <param name="rootPath">Path to directory containing index.html and any other page that can be navigated to</param>
        public HttpHandler(string rootUrl, string rootPath)
        {
            RootUrl  = rootUrl;
            RootPath = Path.Combine(AppContext.BaseDirectory, rootPath);

            if (!RootUrl.EndsWith("/"))
            {
                RootUrl += "/";
            }

            if (!Directory.Exists(RootPath))
            {
                throw new Exception("Path for HttpHandler is invalid.");
            }

            if (!HttpListener.IsSupported)
            {
                throw new Exception("HttpServer requires functionality that isn't supported by your OS.");
            }

            // add all routes
            Routes.AddRange(Assembly.GetEntryAssembly()
                            .GetTypes()
                            .SelectMany(x => x.GetMethods())
                            .Select(x => x.GetCustomAttribute <HttpRoute>())
                            .Where(x => x != null));

            // check if there aren't duplicates
            var duplicate = Routes.GroupBy(x => new { Route = x.Route, Method = x.HttpMethod })
                            .Where(x => x.Count() > 1)
                            .FirstOrDefault()?.Key;

            if (duplicate != null)
            {
                throw new Exception($"There's a duplicate route: {duplicate.Route}({duplicate.Method})");
            }

            Listener.Prefixes.Add(RootUrl);

            Listener.Start();

            Task.Run(() =>
            {
                while (Listener.IsListening)
                {
                    var context = Listener.GetContext();

                    Request = context.Request;

                    Response = context.Response;

                    if (GetSession() == null)
                    {
                        Sessions.Add(new Session(Request.RemoteEndPoint.Address.ToString()));
                    }

                    var path = Request.Url.AbsolutePath;

                    if (path.StartsWith("/"))
                    {
                        path = path.TrimStart('/');
                    }

                    Route = GetRoute(path);

                    if (path.Equals(""))
                    {
                        path = "index.html";
                    }

                    path = Path.Combine(RootPath, path);

                    switch (Request.HttpMethod)
                    {
                    case "GET":
                        HandleGet(path);
                        continue;

                    case "POST":
                        HandlePost(path);
                        continue;
                    }
                }

                Listener.Close();
            });
        }
Example #6
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param>
        /// <returns>true if there were changes made as a result of the update</returns>
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                return(false);
            }

            bool updated = false;

            if (!NetworkAddress.Equals(node.NetworkAddress))
            {
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (!NodeDescriptor.Equals(node.NodeDescriptor))
            {
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (!PowerDescriptor.Equals(node.PowerDescriptor))
            {
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (AssociatedDevices)
            {
                if (!AssociatedDevices.Equals(node.AssociatedDevices))
                {
                    updated = true;
                    AssociatedDevices.Clear();
                    AssociatedDevices.AddRange(node.AssociatedDevices);
                }
            }

            lock (BindingTable)
            {
                if (!BindingTable.Equals(node.BindingTable))
                {
                    updated = true;
                    BindingTable.Clear();
                    BindingTable.AddRange(node.BindingTable);
                }
            }

            lock (Neighbors)
            {
                if (!Neighbors.Equals(node.Neighbors))
                {
                    updated = true;
                    Neighbors.Clear();
                    Neighbors.AddRange(node.Neighbors);
                }
            }

            lock (Routes)
            {
                if (!Routes.Equals(node.Routes))
                {
                    updated = true;
                    Routes.Clear();
                    Routes.AddRange(node.Routes);
                }
            }

            // Endpoints are only copied over if they don't exist in the node
            // The assumption here is that endpoints are only set once, and not changed.
            // This should be valid as they are set through the SimpleDescriptor.
            foreach (var endpoint in node.Endpoints)
            {
                if (Endpoints.ContainsKey(endpoint.Key))
                {
                    continue;
                }
                updated = true;
                Endpoints[endpoint.Key] = endpoint.Value;
            }

            return(updated);
        }
Example #7
0
 public void  ExtendLength(OptionalRoutes route)
 {
     Routes.AddRange(route.Routes);
     Distance += route.Distance;
 }
Example #8
0
 public void Save(RoutesOfTown saveTown)
 {
     Name = saveTown.Name;
     Routes.Clear();
     Routes.AddRange(saveTown.Routes);
 }