Ejemplo n.º 1
0
        void IPrgPrntTracker.AddTracker(ITrackable tracker)
        {
            if (!_trackerList.ContainsKey(tracker.Id))
                _trackerList.Add(tracker.Id, tracker);

            if (tracker is BasicTrackerCtrl)
            {
                BasicTrackerCtrl bCtrl = (BasicTrackerCtrl)tracker;
                _mPanel.Children.Add(bCtrl);
            }
            else if (tracker is PrgTrackerCtrl)
            {
                PrgTrackerCtrl pCtrl = (PrgTrackerCtrl)tracker;
                _mPanel.Children.Add(pCtrl);
            }
            else if (tracker is TrckCtnrCtrl)
            {
                TrckCtnrCtrl tCtrl = (TrckCtnrCtrl)tracker;
                _mPanel.Children.Add(tCtrl);
            }
            else
            {
                // An unknown tracker device has been added.
            }
        }
Ejemplo n.º 2
0
 public Camera(Rectangle view)
 {
     this.View = view;
     this.Target = Vector2.Zero;
     this.track = false;
     toTrack = null;
 }
 public static void ApplyTo(
     this string json,
     ITrackable trackable,
     JsonSerializerSettings jsonSerializerSettings)
 {
     var pathToChangeMap = JsonConvert.DeserializeObject<Dictionary<string, JObject>>(
         json, jsonSerializerSettings);
     pathToChangeMap.ApplyTo(trackable, jsonSerializerSettings);
 }
Ejemplo n.º 4
0
 public static void ApplyTo(
     this IEnumerable<KeyValuePair<string, ITracker>> pathAndTrackers,
     ITrackable trackable)
 {
     foreach (var item in pathAndTrackers)
     {
         var targetTrackable = trackable.GetTrackableByPath(item.Key);
         item.Value.ApplyTo(targetTrackable);
     }
 }
Ejemplo n.º 5
0
        public TrckCtnrCtrl(ITrackableCtrl tracker)
        {
            InitializeComponent();

            if (tracker == null)
                throw new ArgumentNullException("tracker");

            _mTracker = tracker;
            this.xMainGrid.Children.Add(tracker.TrackableCtrl);
        }
Ejemplo n.º 6
0
 public SimpleTorrentManager(ITrackable trackable, IPeerComparer comparer, Tracker tracker)
 {
     _comparer = comparer;
     _trackable = trackable;
     _tracker = tracker;
     _complete = new BEncodedNumber(0);
     _downloaded = new BEncodedNumber(0);
     _incomplete = new BEncodedNumber(0);
     _peers = new Dictionary<object, Peer>();
     _random = new Random();
 }
 public SimpleTorrentManager(ITrackable trackable, IPeerComparer comparer, Tracker tracker)
 {
     this.comparer = comparer;
     this.trackable = trackable;
     this.tracker = tracker;
     complete = new BEncodedNumber(0);
     downloaded = new BEncodedNumber(0);
     incomplete = new BEncodedNumber(0);
     peers = new Dictionary<object, Peer>();
     random = new Random();
 }
Ejemplo n.º 8
0
        public BEncodedValue Handle(PeerDetails d, Common.TorrentEvent e, ITrackable trackable)
        {
            NameValueCollection c = new NameValueCollection();
            c.Add("info_hash", trackable.InfoHash.UrlEncode());
            c.Add("peer_id", d.peerId);
            c.Add("port", d.Port.ToString());
            c.Add("uploaded", d.Uploaded.ToString());
            c.Add("downloaded", d.Downloaded.ToString());
            c.Add("left", d.Remaining.ToString());
            c.Add("compact", "0");

            return base.Handle(c, d.ClientAddress, false);
        }
Ejemplo n.º 9
0
        public BEncodedValue Handle(PeerDetails peerDetails, ITrackable trackable)
        {
            var c = new NameValueCollection();
            c.Add("info_hash", trackable.InfoHash.UrlEncode());
            c.Add("peer_id", peerDetails.PeerId);
            c.Add("port", peerDetails.Port.ToString(CultureInfo.InvariantCulture));
            c.Add("uploaded", peerDetails.Uploaded.ToString(CultureInfo.InvariantCulture));
            c.Add("downloaded", peerDetails.Downloaded.ToString(CultureInfo.InvariantCulture));
            c.Add("left", peerDetails.Remaining.ToString(CultureInfo.InvariantCulture));
            c.Add("compact", "0");

            return base.Handle(c, peerDetails.ClientAddress, false);
        }
 public static void ApplyTo(
     this IEnumerable<KeyValuePair<string, JObject>> pathAndTrackerJObjects,
     ITrackable trackable,
     JsonSerializerSettings jsonSerializerSettings)
 {
     foreach (var item in pathAndTrackerJObjects)
     {
         var targetTrackable = trackable.GetTrackableByPath(item.Key);
         if (targetTrackable != null)
         {
             var trackerType = TrackerResolver.GetDefaultTracker(targetTrackable.GetType());
             var tracker = (ITracker)item.Value.ToObject(
                 trackerType, JsonSerializer.Create(jsonSerializerSettings));
             tracker.ApplyTo(targetTrackable);
         }
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds the trackable to the server
        /// </summary>
        /// <param name="trackable">The trackable to add</param>
        /// <param name="comparer">The comparer used to decide whether two peers are the same.</param>
        /// <returns></returns>
        public bool Add(ITrackable trackable, IPeerComparer comparer)
        {
            CheckDisposed();
            if (trackable == null)
            {
                throw new ArgumentNullException(nameof(trackable));
            }

            lock (Torrents)
            {
                if (Torrents.ContainsKey(trackable.InfoHash))
                {
                    return(false);
                }

                Torrents.Add(trackable.InfoHash, new SimpleTorrentManager(trackable, comparer, this));
            }

            return(true);
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            logger.LogInfo("Log initialized");

            var lines = File.ReadAllLines(csvPath);

            logger.LogInfo($"Lines: {lines[0]}");

            var parser = new TacoParser();

            var        locations   = lines.Select(parser.Parse).ToArray(); // lists of tacobell location that conforms to Itrackable
            ITrackable locationA   = new TacoBell();
            ITrackable locationB   = new TacoBell();
            ITrackable location1   = null;
            ITrackable location2   = null;
            double     farDistance = 0;
            double     distance;

            for (int i = 0; i < locations.Count(); i++)
            {
                locationA = locations[i];
                var orgin = new GeoCoordinate(locationA.Location.Latitude, locationA.Location.Longitude);

                for (int j = 1; j < locations.Count(); j++)
                {
                    locationB = locations[j];

                    var destination = new GeoCoordinate(locationB.Location.Latitude, locationB.Location.Longitude);

                    distance = orgin.GetDistanceTo(destination);

                    if (distance > farDistance)
                    {
                        farDistance = distance * 0.621371;
                        location1   = locationA;
                        location2   = locationB;
                    }
                }
            }
            Console.WriteLine($"Farthest distance = {farDistance} miles between {location1.Name} and {location2.Name}");
        }
Ejemplo n.º 13
0
        // Recursively get entity states
        public static IEnumerable<EntityState> GetEntityStates(this DbContext context,
            ITrackable item, EntityState? entityState = null,
            ObjectVisitationHelper visitationHelper = null)
        {
            // Prevent endless recursion
            ObjectVisitationHelper.EnsureCreated(ref visitationHelper);
            if (!visitationHelper.TryVisit(item)) yield break;

            foreach (var colProp in item.GetNavigationProperties().OfCollectionType())
            {
                foreach (ITrackable child in colProp.EntityCollection)
                {
                    foreach (var state in context.GetEntityStates(child, visitationHelper: visitationHelper))
                    {
                        if (entityState == null || state == entityState)
                            yield return state;
                    }
                }
            }
            yield return context.Entry(item).State;
        }
Ejemplo n.º 14
0
 public static void Subscribe(ITrackable target, Action <ITrackable, PositionData, PositionData> callback)
 {
     if (_onPositionChangedCallbacks.TryGetValue(target, out var callbacks))
     {
         if (callbacks.Contains(callback))
         {
             throw new ArgumentException("Duplicate callbacks have been subscribed!");
         }
         else
         {
             callbacks.Add(callback);
         }
     }
     else
     {
         _onPositionChangedCallbacks.Add(target, new List <Action <ITrackable, PositionData, PositionData> >()
         {
             callback
         });
     }
 }
Ejemplo n.º 15
0
        public void ShouldDoSomething()
        {
            //Act
            Point location = new Point()
            {
                Latitude = 34.252214, Longitude = -84.088239
            };
            ITrackable expected = new TacoBell()
            {
                Name = "Taco Bell Cummin...", Location = location
            };

            //Arrange
            TacoParser parser = new TacoParser();
            ITrackable actual = parser.Parse("34.252214,84.088239,Taco Bell Cummin...");

            //Assert
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.Location.Latitude, actual.Location.Latitude);
            Assert.Equal(expected.Location.Longitude, actual.Location.Longitude);
        }
Ejemplo n.º 16
0
        public void ShouldParse(string str)
        {
            //Act
            Point location = new Point()
            {
                Latitude = 34.764965, Longitude = -86.48607
            };
            ITrackable expected = new TacoBell()
            {
                Name = "Taco Bell Huntsville", Location = location
            };

            //Arrange
            TacoParser parser = new TacoParser();
            ITrackable actual = parser.Parse(str);

            //Assert
            Assert.Equal(expected.Name, actual.Name);
            Assert.Equal(expected.Location.Latitude, actual.Location.Latitude);
            Assert.Equal(expected.Location.Longitude, actual.Location.Longitude);
        }
Ejemplo n.º 17
0
        // 元素发生改变时的处理事件
        void OnItemChanged(object sender, PropertyChangedEventArgs e)
        {
            if (Tracking)
            {
                ITrackable item = (ITrackable)sender;
                if (e.PropertyName != "TrackingState")
                {
                    // 标志元素被更新
                    if (item.TrackingState == TrackingInfo.Unchanged)
                    {
                        item.TrackingState = TrackingInfo.Updated;
                    }

                    // Notify interested parties
                    if (ItemChanged != null)
                    {
                        ItemChanged(this, new ItemChangedEventArgs <T>((T)sender));
                    }
                }
            }
        }
        public void DetectCondition_MultipleConditions_EventHandlerInvokedCorrect(int numConditions)
        {
            int        timesInvoked    = 0;
            ITrack     trackInAirspace = FakeTrackFactory.GetTrack(1000, 1000, 1000);
            ITrackable airspace        = FakeAirspaceGenerator.GetAirspace(0, 0, 0);

            airspace.Trackables.Add(trackInAirspace); //There must be one track always
            for (int i = 0; i < numConditions; i++)
            {
                airspace.Trackables.Add(trackInAirspace);
            }
            //Because each element in the airspace is compared to each other:
            int expectedVisitations = numConditions * airspace.Trackables.Count / 2;

            _fakeCondition.ConditionBetween(Arg.Any <ITrack>(), Arg.Any <ITrack>()).Returns(true);
            _uutConditionDetector.ConditionsHandler += (s, e) => ++ timesInvoked;

            _uutConditionDetector.DetectCondition(airspace);

            Assert.That(timesInvoked, Is.EqualTo(expectedVisitations));
        }
        public static void Track(this ITrackable model, bool creation = true, string user = null)
        {
            if (creation)
            {
                if (user != null)
                {
                    model.CreatedBy = user;
                }

                model.CreatedDateTimeUtc = DateTime.UtcNow;
            }
            else
            {
                if (user != null)
                {
                    model.ModifiedBy = user;
                }

                model.ModifiedDateTimeUtc = DateTime.UtcNow;
            }
        }
Ejemplo n.º 20
0
        public bool Add(ITrackable trackable, IPeerComparer comparer)
        {
            CheckDisposed();
            if (trackable == null)
            {
                throw new ArgumentNullException("trackable");
            }

            lock (torrents)
            {
                if (torrents.ContainsKey(trackable.InfoHash))
                {
                    return(false);
                }

                torrents.Add(trackable.InfoHash, new SimpleTorrentManager(trackable, comparer, this));
            }

            Debug.WriteLine(string.Format("Tracking Torrent: {0}", trackable.Name));
            return(true);
        }
Ejemplo n.º 21
0
        private void BeforeDrawingDeletion(AbstractDrawing drawing)
        {
            ITrackable trackableDrawing = drawing as ITrackable;

            if (trackableDrawing != null)
            {
                DeleteTrackableDrawing(trackableDrawing);
            }

            IMeasurable measurableDrawing = drawing as IMeasurable;

            if (measurableDrawing != null)
            {
                measurableDrawing.ShowMeasurableInfoChanged -= MeasurableDrawing_ShowMeasurableInfoChanged;
            }

            if (drawing is DrawingDistortionGrid)
            {
                ((DrawingDistortionGrid)drawing).LensCalibrationAsked -= LensCalibrationAsked;
            }
        }
Ejemplo n.º 22
0
        private async static Task LoadRelatedEntitiesOnPropertiesAsync(this DbContext context,
                                                                       ITrackable item, ObjectVisitationHelper visitationHelper, CancellationToken cancellationToken, bool loadAll)
        {
            // Recursively load related entities
            foreach (var navProp in item.GetNavigationProperties())
            {
                // Apply changes to 1-1 and M-1 properties
                foreach (var refProp in navProp.AsReferenceProperty())
                {
                    await context.LoadRelatedEntitiesAsync(new[] { refProp.EntityReference }, item, visitationHelper,
                                                           cancellationToken, loadAll).ConfigureAwait(false);
                }

                // Apply changes to 1-M and M-M properties
                foreach (var colProp in navProp.AsCollectionProperty())
                {
                    await context.LoadRelatedEntitiesAsync(colProp.EntityCollection, item, visitationHelper,
                                                           cancellationToken, loadAll).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Recursively set tracking state on trackable properties in an object graph.
        /// </summary>
        /// <param name="item">Trackable object</param>
        /// <param name="modified">Properties on an entity that have been modified</param>
        /// <param name="visitationHelper">Circular reference checking helper</param>
        public static void SetModifiedProperties(this ITrackable item,
                                                 ICollection <string> modified, ObjectVisitationHelper visitationHelper = null)
        {
            // Prevent endless recursion
            ObjectVisitationHelper.EnsureCreated(ref visitationHelper);
            if (!visitationHelper.TryVisit(item))
            {
                return;
            }

            // Iterate entity properties
            foreach (var colProp in item.GetNavigationProperties().OfCollectionType <ITrackingCollection>())
            {
                // Recursively set modified
                foreach (ITrackable child in colProp.EntityCollection)
                {
                    child.SetModifiedProperties(modified, visitationHelper);
                    child.ModifiedProperties = modified;
                }
            }
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            logger.LogInfo("Log initialized");

            var lines = File.ReadAllLines(csvPath);

            logger.LogInfo($"Lines: {lines[0]}");

            var parser = new TacoParser();

            var        locations   = lines.Select(parser.Parse).ToArray();
            ITrackable locA        = null;
            ITrackable locB        = null;
            Double     maxDistance = 0;

            for (int i = 0; i < locations.Length; i++)
            {
                GeoCoordinate corA = new GeoCoordinate();
                corA.Latitude  = locations[i].Location.Latitude;
                corA.Longitude = locations[i].Location.Longitude;
                for (int k = 0; k < locations.Length; k++)
                {
                    GeoCoordinate corB = new GeoCoordinate();
                    corB.Latitude  = locations[k].Location.Latitude;
                    corB.Longitude = locations[k].Location.Longitude;

                    if (corA.GetDistanceTo(corB) >= maxDistance)
                    {
                        maxDistance = corA.GetDistanceTo(corB);
                        locA        = locations[i];
                        locB        = locations[k];
                    }
                }
            }
            Console.WriteLine($"The Two Farthest Taco Bells are {locA.Name} and {locB.Name}");


            // TODO:  Find the two Taco Bells in Alabama that are the furthest from one another.
            // HINT:  You'll need two nested forloops
        }
Ejemplo n.º 25
0
        // Recursively get tracking states
        public static IEnumerable <TrackingState> GetTrackingStates
            (this ITrackable item, TrackingState?trackingState = null,
            ObjectVisitationHelper visitationHelper            = null)
        {
            // Prevent endless recursion
            ObjectVisitationHelper.EnsureCreated(ref visitationHelper);
            if (!visitationHelper.TryVisit(item))
            {
                yield break;
            }

            foreach (var navProp in item.GetNavigationProperties())
            {
                foreach (var refProp in navProp.AsReferenceProperty())
                {
                    foreach (var state in refProp.EntityReference.GetTrackingStates(visitationHelper: visitationHelper))
                    {
                        if (trackingState == null || state == trackingState)
                        {
                            yield return(state);
                        }
                    }
                }

                foreach (var colProp in navProp.AsCollectionProperty())
                {
                    foreach (ITrackable child in colProp.EntityCollection)
                    {
                        foreach (var state in child.GetTrackingStates(visitationHelper: visitationHelper))
                        {
                            if (trackingState == null || state == trackingState)
                            {
                                yield return(state);
                            }
                        }
                    }
                }
            }
            yield return(item.TrackingState);
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            logger.LogInfo("Log initialized\n");

            var lines = File.ReadAllLines(csvPath);

            var parser = new TacoParser();

            var locations = lines.Select(parser.Parse);

            ITrackable location1   = null;
            ITrackable location2   = null;
            var        distanceMax = 0.0;

            foreach (var locA in locations)
            {
                var origin = new GeoCoordinate(locA.Location.Latitude, locA.Location.Longitude);

                foreach (var locB in locations)
                {
                    var destination = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);

                    var currentDistance = origin.GetDistanceTo(destination);

                    if (currentDistance > distanceMax)
                    {
                        distanceMax = currentDistance;
                        location1   = locA;
                        location2   = locB;
                    }
                }
            }

            Console.WriteLine($"Location 1 : {location1.Name.Substring(1, location1.Name.IndexOf("(") - 1)}");
            Console.WriteLine($"Location 2 : {location2.Name.Substring(1, location2.Name.IndexOf("(") - 1)}");
            Console.WriteLine($"Distance : {Math.Round(distanceMax, 2)} meters");

            logger.LogInfo("Log Complete");
            Console.ReadKey();
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            //logger.LogInfo("Log initialized"); // print logs to console

            var lines = File.ReadAllLines(csvPath); //array designed to read locations a

            var parser = new TacoParser();

            var locations = lines.Select(parser.Parse).ToArray();

            ITrackable taco1    = null;
            ITrackable taco2    = null;
            double     distance = 0;

            for (int i = 0; i < locations.Length; i++)
            {
                // logger.LogInfo($"Lines: {lines[i]}");

                ITrackable    locA = locations[i];
                GeoCoordinate corA = new GeoCoordinate(locA.Location.Latitude, locA.Location.Longitude);

                for (int k = i + 1; k < locations.Length; k++)
                {
                    ITrackable    locB = locations[k];
                    GeoCoordinate corB = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);

                    if (corA.GetDistanceTo(corB) >= distance)
                    {
                        distance = corA.GetDistanceTo(corB);
                        taco1    = locA;
                        taco2    = locB;
                    }
                }
            }
            Console.WriteLine(taco1.Name);
            Console.WriteLine(taco2.Name);

            // TODO:  Find the two Taco Bells in Alabama that are the furthest from one another.
            // HINT:  You'll need two nested forloops
        }
Ejemplo n.º 28
0
        public static void Rollback(this ITrackable trackable)
        {
            var tracker = trackable.Tracker;

            if (tracker == null)
            {
                throw new ArgumentException("trackable should have Tracker");
            }

            if (trackable.Changed)
            {
                // To prevent tracker from saving rollback changes
                // detach tracker from trackable temporarily.
                trackable.Tracker = null;

                tracker.RollbackTo(trackable);
                tracker.Clear();

                // Attcah tracker to trackable to undo temporary touch.
                trackable.Tracker = tracker;
            }
        }
Ejemplo n.º 29
0
        private void OnEnemyPositionUpdate(ITrackable trackedEnemy, PositionData oldPosition, PositionData newPosition)
        {
            var enemy = trackedEnemy as EnemyHealth;

            if (newPosition.Chunk != this)
            {
                Unregister(enemy);

                if (newPosition.Chunk != null)
                {
                    newPosition.Chunk.Register(enemy);
                }
                else if (newPosition.Builder != null)
                {
                    newPosition.Builder.AddEnemy(enemy);
                }
                else
                {
                    _log.Error($"Enemy {trackedEnemy} has left known bounds at location {newPosition.Position}.");
                }
            }
        }
Ejemplo n.º 30
0
        object ReadField(object instanceEntity, ITrackable trackable, EntityAccessor entityAccessor, Property prop, Type type, int ordinal, DbDataReader dbReader)
        {
            var accessor = entityAccessor.Properties[prop.PropertyName];

            if (accessor == null)
            {
                throw new GoliathDataException("Could not find accessor for " + instanceEntity.ToString() + "." + prop.PropertyName);
            }

            var val       = dbReader[ordinal];
            var fieldType = dbReader.GetFieldType(ordinal);

            if (val == DBNull.Value || val == null)
            {
                return(null);
            }

            if ((fieldType == accessor.PropertyType) && (val != DBNull.Value))
            {
                accessor.SetMethod(instanceEntity, val);
                LoadInitialValueForInTracker(trackable, prop.PropertyName, val);
                return(val);
            }
            else if (accessor.PropertyType.IsEnum)
            {
                var enumVal = TypeConverterStore.ConvertToEnum(accessor.PropertyType, val);
                accessor.SetMethod(instanceEntity, enumVal);
                LoadInitialValueForInTracker(trackable, prop.PropertyName, enumVal);
                return(enumVal);
            }
            else
            {
                var converter      = TypeConverterStore.GetConverterFactoryMethod(accessor.PropertyType);
                var convertedValue = converter.Invoke(val);
                accessor.SetMethod(instanceEntity, convertedValue);
                LoadInitialValueForInTracker(trackable, prop.PropertyName, convertedValue);
                return(convertedValue);
            }
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            Logger.LogInfo("Log initialized");

            var lines = File.ReadAllLines(CsvPath);

            Logger.LogInfo($"Lines: {lines[0]}");

            var parser = new TacoParser();

            var locations = lines.Select(parser.Parse);

            ITrackable a        = null;
            ITrackable b        = null;
            double     distance = 0;

            foreach (var locA in locations)
            {
                var origin = new GeoCoordinate(locA.Location.Latitude, locA.Location.Longitude);

                foreach (var locB in locations)
                {
                    var destination = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);

                    double newDistance = origin.GetDistanceTo(destination);
                    if (!(newDistance > distance))
                    {
                        continue;
                    }
                    a        = locA;
                    b        = locB;
                    distance = newDistance;
                }
            }

            Console.WriteLine($"The two tacobells that are farthest apart are:\n\t{a?.Name} and \n\t{b?.Name}");
            Console.WriteLine($"These two locations are {distance/3.28} feet apart");
            Console.ReadLine();
        }
Ejemplo n.º 32
0
        private static void ApplyChangesOnCollectionProperties(TrackingState stateFilter, bool includeState,
                                                               EntityNavigationProperty navProp, EntityCollectionProperty <IList> colProp,
                                                               DbContext context, ITrackable item, ObjectVisitationHelper visitationHelper, TrackingState?state = null)
        {
            // Apply changes to 1-M and M-M properties filtering by tracking state
            var count = colProp.EntityCollection.Count;

            for (int i = count - 1; i > -1; i--)
            {
                var trackableChild = colProp.EntityCollection[i] as ITrackable;
                if (trackableChild != null)
                {
                    bool condition = includeState
                        ? trackableChild.TrackingState == stateFilter
                        : trackableChild.TrackingState != stateFilter;
                    if (condition)
                    {
                        context.ApplyChanges(trackableChild, item, visitationHelper, navProp.Property.Name, state);
                    }
                }
            }
        }
Ejemplo n.º 33
0
        public void StartTracking(ITrackable target)
        {
            if (isShuttingDown)
            {
                return;
            }

            if (IsTracking)
            {
                StopTracking();
            }

            if (target != null)
            {
                Target = target;
                GetDesiredPosition(Target.Position);
                subscribedProcessors.Add(GetDesiredPosition);
                Target.OnPositionChange += GetDesiredPosition;
                TrackingProcess         += HandleMovement;
                IsTracking = true;
            }
        }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            logger.LogInfo("Log initialized");

            Console.Write("Read from where? CSV or Database: ");
            var typeOfFile = Console.ReadLine();

            typeOfFile = CheckUserInput(typeOfFile);

            var locations = SelectFileType(typeOfFile);

            double     maxDistance = 0;
            ITrackable store1      = null;
            ITrackable store2      = null;

            foreach (var line1 in locations)
            {
                GeoCoordinate corA = new GeoCoordinate(line1.Location.Latitude, line1.Location.Longitude);

                foreach (var line2 in locations)
                {
                    GeoCoordinate corB = new GeoCoordinate(line2.Location.Latitude, line2.Location.Longitude);

                    double distance = corA.GetDistanceTo(corB);

                    if (maxDistance < distance)
                    {
                        store1 = line1;
                        store2 = line2;

                        maxDistance = distance;
                    }
                }
            }

            Console.WriteLine($"{store1.Name}, {store2.Name}, {maxDistance}");
            Console.ReadLine();
        }
        private static void Main(string[] args)
        {
            logger.LogInfo("Log initialized");

            var lines = File.ReadAllLines(CsvPath);

            var parser = new TacoParser();

            var locations = lines.Select(parser.Parse);

            ITrackable a        = null;
            ITrackable b        = null;
            double     distance = 0;

            foreach (var locA in locations)
            {
                var origin = new GeoCoordinate(locA.Location.Latitude, locA.Location.Longitude);

                foreach (var locB in locations)
                {
                    var destination = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);

                    var newDistance = origin.GetDistanceTo(destination);

                    if (!(newDistance > distance))
                    {
                        continue;
                    }

                    a        = locA;
                    b        = locB;
                    distance = newDistance;
                }
            }
            Console.WriteLine($"These are the two Taco Bells furthest away from each other: \n\t{a?.Name} and \n\t{b?.Name}");
            Console.WriteLine($"They are {distance / 0.000621371} miles apart.");
            Console.ReadLine();
        }
Ejemplo n.º 36
0
        private DomainResult WaitForCompletion(ITrackable command, bool commandOnly)
        {
            _logger.DebugFormat("Wait from completion, ID is {0}, command only is {1}", command.TrackingId, commandOnly);
            IEnumerable <DomainResult> results;
            bool hasOngoingProcessing;
            var  start = DateTime.Now;

            do
            {
                results = _resultStore.Get(command.TrackingId).ToArray();
                if (commandOnly)
                {
                    results = results.Where(x => x.IsCommand).ToArray();
                }
                hasOngoingProcessing = results.Any(x => x.ResultCode == ResultCode.Unknown);
                _logger.DebugFormat("Has ongoing for ID {0} : {1}", command.TrackingId, hasOngoingProcessing);
                if (hasOngoingProcessing)
                {
                    Thread.Sleep(_sleepInterval);
                }
            }while (hasOngoingProcessing && (DateTime.Now - start).TotalMilliseconds < _waitTimeout);
            _logger.DebugFormat("Done waiting for ID {0}, has ongoing: {1}, has results: {2}", command.TrackingId, hasOngoingProcessing, results.Any());
            _logger.DebugFormat("Last known results for ID {0} are", command.TrackingId);
            foreach (var cqrsResult in results)
            {
                _logger.DebugFormat("Result: {0}, isCommand: {1}", cqrsResult.ResultCode, cqrsResult.IsCommand);
            }

            if (hasOngoingProcessing || !results.Any())
            {
                return(new DomainResult {
                    TrackingId = command.TrackingId, ResultCode = ResultCode.Unknown,
                });
            }
            _resultStore.Delete(command.TrackingId);

            return(results.OrderByDescending(x => x.ResultCode).FirstOrDefault());
        }
Ejemplo n.º 37
0
        public void InitializeEnd(bool cancelCurrentPoint)
        {
            IInitializable initializable = hitDrawing as IInitializable;

            if (initializable == null || !initializable.Initializing)
            {
                return;
            }

            string key = initializable.InitializeEnd(cancelCurrentPoint);

            if (string.IsNullOrEmpty(key) || !cancelCurrentPoint)
            {
                return;
            }

            ITrackable trackable = hitDrawing as ITrackable;

            if (trackable != null)
            {
                trackabilityManager.RemovePoint(trackable, key);
            }
        }
Ejemplo n.º 38
0
        static void Main(string[] args)
        {
            var lines = File.ReadAllLines(csvPath);

            var parser = new TacoParser();

            var locations = lines.Select(parser.Parse).ToArray();

            ITrackable trackable1  = null;
            ITrackable trackable2  = null;
            double     maxDistance = 0;

            for (int i = 0; i < locations.Length; i++)
            {
                ITrackable    locA = locations[i];
                GeoCoordinate corA = new GeoCoordinate(locA.Location.Latitude, locA.Location.Longitude);

                for (int k = 0; k < locations.Length; k++)
                {
                    ITrackable    locB = locations[k];
                    GeoCoordinate corB = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);

                    double distance = corB.GetDistanceTo(corA);

                    if (distance > maxDistance)
                    {
                        maxDistance = distance;
                        trackable1  = locA;
                        trackable2  = locB;
                    }
                }
            }

            Console.WriteLine(trackable1.Name);
            Console.WriteLine(trackable2.Name);
            Console.WriteLine(maxDistance);
        }
Ejemplo n.º 39
0
        static void Main(string[] args)
        {
            logger.LogInfo("Log initialized");

            var lines = File.ReadAllLines(csvPath);

            logger.LogInfo($"Lines: {lines[0]}");

            var parser = new TacoParser();

            var locations = lines.Select(parser.Parse).ToArray();

            ITrackable firstTacoBell  = null;
            ITrackable secondTacoBell = null;
            double     distance       = 0;


            for (int i = 0; i < locations.Length; i++)
            {
                ITrackable    locA = locations[i];
                GeoCoordinate corA = new GeoCoordinate(locA.Location.Latitude, locA.Location.Longitude);
                for (int x = 1; x < locations.Length; x++)
                {
                    ITrackable    locB = locations[x];
                    GeoCoordinate corB = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude);
                    if (corA.GetDistanceTo(corB) > distance)
                    {
                        distance       = corA.GetDistanceTo(corB);
                        firstTacoBell  = locA;
                        secondTacoBell = locB;
                    }
                }
            }
            Console.WriteLine(firstTacoBell.Name);
            Console.WriteLine(secondTacoBell.Name);
            Console.ReadLine();
        }
        /// <summary>
        /// Получить из делева плоский список ВСЕХ дочерние сущьностей, относительно текущего узла
        /// </summary>
        /// <param name="rootEntity">Элемент, от которого поиск</param>
        /// <param name="predicat">Фильтр полученных элементов </param>
        public static IEnumerable <BaseEntity> GetFromCurrent([NotNull] this ITrackable rootEntity, Func <BaseEntity, bool> predicat = null)
        {
            var flatList = new Dictionary <BaseEntity, BaseEntity>(ReferenceEqualityComparer.Instance);

            var monitor = rootEntity.GetMonitor() as EntityStateMonitor;

            if (monitor == null)
            {
                return(new List <BaseEntity>());
            }


            monitor.TraverseGraph(rootEntity, x =>
            {
                if (x is BaseEntity baseEntity) // это сущьность
                {
                    if (!flatList.ContainsKey(baseEntity))
                    {
                        if (predicat != null)
                        {
                            if (predicat.Invoke(baseEntity))
                            {
                                flatList.Add(baseEntity, baseEntity);
                            }
                        }
                        else
                        {
                            flatList.Add(baseEntity, baseEntity);
                        }
                    }
                }
                return(true); //обходим дерево дальше
            });

            return(flatList.Keys);
        }
Ejemplo n.º 41
0
        private static void ApplyChangesOnProperties(this DbContext context,
                                                     ITrackable item, ObjectVisitationHelper visitationHelper, TrackingState?state = null)
        {
            // Recursively apply changes
            foreach (var navProp in item.GetNavigationProperties())
            {
                // Apply changes to 1-1 and M-1 properties
                foreach (var refProp in navProp.AsReferenceProperty())
                {
                    context.ApplyChanges(refProp.EntityReference, item, visitationHelper, navProp.Property.Name, state);
                }

                // Apply changes to 1-M and M-M properties
                foreach (var colProp in navProp.AsCollectionProperty <IList>())
                {
                    // Apply changes on collection property for each state.
                    // Process added items first, then process others.
                    ApplyChangesOnCollectionProperties(TrackingState.Added, true,
                                                       navProp, colProp, context, item, visitationHelper, state);
                    ApplyChangesOnCollectionProperties(TrackingState.Added, false,
                                                       navProp, colProp, context, item, visitationHelper, state);
                }
            }
        }
Ejemplo n.º 42
0
 public bool Remove(ITrackable item)
 {
     return _workingSet.Remove(item);
 }
Ejemplo n.º 43
0
 public bool Contains(ITrackable item)
 {
     return _workingSet.Contains(item);
 }
Ejemplo n.º 44
0
 public void Add(ITrackable item)
 {
     _workingSet.Add(item);
 }
Ejemplo n.º 45
0
 public void UnTrack()
 {
     this.track = false;
     this.toTrack = null;
 }
Ejemplo n.º 46
0
 public void CopyTo(ITrackable[] array, int arrayIndex)
 {
     _workingSet.CopyTo(array, arrayIndex);
 }
Ejemplo n.º 47
0
 public void Track(ITrackable obj)
 {
     this.track = true;
     this.toTrack = obj;
 }
Ejemplo n.º 48
0
 bool IPrgPrntTracker.TryGetTracker(string id, out ITrackable tracker)
 {
     return _trackerList.TryGetValue(id, out tracker);
 }