コード例 #1
0
        public void UpdateTrackerSnapshot()
        {
            var snapshots = TestSnapshots;

            var t = new LocationTracker(snapshots[0]);

            Assert.IsTrue(t.CanTranslateFrom(0));
            Assert.IsTrue(t.CanTranslateFrom(1));
            Assert.IsTrue(t.CanTranslateFrom(5));
            Assert.IsFalse(t.CanTranslateFrom(6));

            Assert.AreEqual(0, t.GetIndex(new SourceLocation(1, 1), 5));
            Assert.IsTrue(t.IsCached(0));
            Assert.IsTrue(t.IsCached(5));

            t.UpdateBaseSnapshot(snapshots[1]);
            Assert.IsFalse(t.CanTranslateFrom(0), "Should not be able to translate from old version 0");
            Assert.IsTrue(t.CanTranslateFrom(1));
            Assert.IsTrue(t.CanTranslateFrom(5));
            Assert.IsFalse(t.CanTranslateFrom(6));
            Assert.IsFalse(t.IsCached(0), "Old snapshot should have been removed from cache");
            Assert.IsTrue(t.IsCached(5), "Current snapshot should not have been removed from cache");

            t.UpdateBaseSnapshot(snapshots[4]);
            Assert.IsFalse(t.CanTranslateFrom(0), "Should not be able to translate from old version 0");
            Assert.IsFalse(t.CanTranslateFrom(1), "Should not be able to translate from old version 1");
            Assert.IsTrue(t.CanTranslateFrom(5));
            Assert.IsFalse(t.CanTranslateFrom(6));
        }
コード例 #2
0
        static async Task Main()
        {
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
            locationProvider           = new LocationTracker();
            var min = new LocationDTO {
                Longitude = -10, Latitude = -10
            };
            var max = new LocationDTO {
                Longitude = 10, Latitude = 10
            };

            locationReporter = new LocationReporter(Mapper.Map(min), Mapper.Map(max));

            locationReporter.Subscribe(locationProvider,
                                       Console.WriteLine,
                                       (x) => Console.WriteLine(x.Message),
                                       (x) => { },
                                       TurnOffAll,
                                       TurnOnAll
                                       );
            deviceProvider = new DeviceTracker();
            deviceReporter = new DeviceReporter();
            deviceReporter.Subscribe(deviceProvider,
                                     Console.WriteLine,
                                     (x) => Console.WriteLine(x.Message),
                                     (x) => { _ = CurrentConnection.SendAsync(MessageParser.CreateMessage("OnNext", x, x.GetType().Name)); }
                                     );
            await CreateServer();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: W3SS/dotnet-designpatterns
        public static void Observer()
        {
            // custom
            var weatherData = new WeatherData();

            var currentDisplay = new CurrentConditionDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.2f);

            // using buildin class
            var provider = new LocationTracker();

            var reporter1 = new LocationReporter("Report1");

            reporter1.Subscribe(provider);

            var reporter2 = new LocationReporter("Report2");

            reporter2.Subscribe(provider);

            provider.TrackLocation(new Location(47.6456, -122.1312));
            reporter1.Unsubscribe();
            provider.TrackLocation(new Location(47.6677, -122.1199));
            provider.TrackLocation(null);
            provider.EndTransmission();
        }
コード例 #4
0
        public void TranslateLocations()
        {
            var t = new LocationTracker(TestSnapshots[0]);

            // Translate forwards
            CheckTranslate(t, 1, 5, 1, 1, 5, 1);
            CheckTranslate(t, 1, 5, 1, 1, 5, 2);
            CheckTranslate(t, 1, 5, 1, 4, 5, 3);
            CheckTranslate(t, 1, 5, 1, 4, 5, 4);
            CheckTranslate(t, 1, 5, 1, 4, 5, 5);

            // Translate backwards (includes a delete, so doesn't always round-trip)
            CheckTranslate(t, 1, 5, 2, 1, 5, 1);
            CheckTranslate(t, 1, 5, 3, 1, 1, 1, checkReverse: false);
            CheckTranslate(t, 1, 5, 4, 1, 1, 1, checkReverse: false);
            CheckTranslate(t, 1, 5, 5, 1, 1, 1, checkReverse: false);

            // Translate to actual line location in same version
            CheckTranslate(t, 5, 5, 0, 1, 1, 0);
            CheckTranslate(t, 5, 5, 1, 2, 1, 1);
            CheckTranslate(t, 5, 5, 2, 3, 1, 2);
            CheckTranslate(t, 5, 5, 3, 5, 5, 3);
            CheckTranslate(t, 8, 5, 3, 6, 1, 3);
            CheckTranslate(t, 8, 5, 4, 5, 11, 4);
            CheckTranslate(t, 8, 5, 5, 6, 1, 5);
        }
コード例 #5
0
        private PythonTextBufferInfo(PythonEditorServices services, ITextBuffer buffer)
        {
            Services                = services;
            Buffer                  = buffer;
            _eventSinks             = new ConcurrentDictionary <object, IPythonTextBufferInfoEventSink>();
            _filename               = new Lazy <string>(GetOrCreateFilename);
            _documentUri            = new Lazy <Uri>(GetOrCreateDocumentUri);
            _tokenCache             = new TokenCache();
            _defaultLanguageVersion = PythonLanguageVersion.None;

            ITextDocument doc;

            if (Buffer.Properties.TryGetProperty(typeof(ITextDocument), out doc))
            {
                Document = doc;
                Document.EncodingChanged += Document_EncodingChanged;
            }
            Buffer.ContentTypeChanged += Buffer_ContentTypeChanged;
            Buffer.Changed            += Buffer_TextContentChanged;
            Buffer.ChangedLowPriority += Buffer_TextContentChangedLowPriority;

            if (Buffer is ITextBuffer2 buffer2)
            {
                _hasChangedOnBackground      = true;
                buffer2.ChangedOnBackground += Buffer_TextContentChangedOnBackground;
            }

            _locationTracker = new LocationTracker(Buffer.CurrentSnapshot);

            _traceLog = OpenTraceLog();
        }
コード例 #6
0
 /// <summary>Update the tracked values.</summary>
 /// <param name="watcher">The watcher to snapshot.</param>
 public void Update(LocationTracker watcher)
 {
     this.Buildings.Update(watcher.BuildingsWatcher);
     this.Debris.Update(watcher.DebrisWatcher);
     this.LargeTerrainFeatures.Update(watcher.LargeTerrainFeaturesWatcher);
     this.Npcs.Update(watcher.NpcsWatcher);
     this.Objects.Update(watcher.ObjectsWatcher);
     this.TerrainFeatures.Update(watcher.TerrainFeaturesWatcher);
 }
コード例 #7
0
        public void TestTrackerByWalkingAround()
        {
            var locationTracker = LocationTracker.GetInstance(positionChangedArgs =>
            {
                Assert.IsNotNull(positionChangedArgs.Position);

                EnqueueTestComplete();
            });
        }
コード例 #8
0
        public void Initialize(string mapboxToken, string storyTagCatalogName = null)
        {
            m_tileCache = new TileCache(StorageManager.EnsureCacheFolder("mapboxPoiTileCache"), TileCacheSize, TileCacheSize * 2, TimeSpan.FromDays(7));

            m_mapboxToken = mapboxToken;

            Catalog <LocationTypeMap>          osmMap    = null;
            Catalog <LocationTypeMap>          makiMap   = null;
            IEnumerable <StoryTagLocationType> storyTags = null;

            Motive.WebServices.Instance.AddCatalogLoad <LocationTypeMap>("motive.ar", "maki_location_type_map", (catalog) =>
            {
                makiMap = catalog;
            }, false);

            Motive.WebServices.Instance.AddCatalogLoad <LocationTypeMap>("motive.ar", "osm_location_type_map", (catalog) =>
            {
                osmMap = catalog;
            }, false);

            if (storyTagCatalogName != null)
            {
                Motive.WebServices.Instance.AddCatalogLoad <StoryTagLocationType>(storyTagCatalogName, (catalog) =>
                {
                    storyTags = catalog;
                });
            }

            AppManager.Instance.OnLoadComplete((callback) =>
            {
                m_osmMapper  = new LocationTypeMapper(osmMap);
                m_makiMapper = new LocationTypeMapper(makiMap);

                if (storyTagCatalogName == null)
                {
                    storyTags = ScriptObjectDirectory.Instance.GetAllObjects <StoryTagLocationType>();
                }

                if (storyTags != null)
                {
                    m_storyTagMap = new StoryTagLocationTypeMap(storyTags);
                }

                m_locationTracker = UserLocationService.Instance.CreateLocationTracker(25);
                m_locationTracker.UpdateDistance = 25;

                m_locationTracker.Updated += t_Updated;

                m_locationTracker.Start();

                callback();
            });
        }
コード例 #9
0
        void CheckTranslate(LocationTracker tracker, int fromLine, int fromCol, int fromVersion, int toLine, int toCol, int toVersion, bool checkReverse = true)
        {
            var from_ = new SourceLocation(fromLine, fromCol);
            var to_   = new SourceLocation(toLine, toCol);

            var actualTo = tracker.Translate(from_, fromVersion, toVersion);

            Assert.AreEqual(to_, actualTo, $"Translating {from_} from {fromVersion} to {toVersion}");
            if (checkReverse && fromVersion != toVersion)
            {
                var actualFrom = tracker.Translate(actualTo, toVersion, fromVersion);
                Assert.AreEqual(from_, actualFrom, $"Reverse translating {actualTo} from {toVersion} to {fromVersion}");
            }
        }
コード例 #10
0
        private async void OnNewAnalysis(object sender, EventArgs e)
        {
            var entry = _buffer.AnalysisEntry;

            if (!_provider._colorNames || entry == null)
            {
                bool raise = false;
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        raise      = true;
                    }
                }

                if (raise)
                {
                    OnNewClassifications(_buffer.Buffer.CurrentSnapshot);
                }
                return;
            }


            var classifications = await entry.Analyzer.GetAnalysisClassificationsAsync(
                entry,
                _buffer.Buffer,
                _provider._colorNamesWithAnalysis
                );

            if (classifications != null)
            {
                Debug.WriteLine("Received {0} classifications", classifications.Data.classifications.Length);
                // sort the spans by starting position so we can use binary search when handing them out
                Array.Sort(
                    classifications.Data.classifications,
                    (x, y) => x.start - y.start
                    );

                lock (_spanCacheLock) {
                    _spanCache      = classifications.Data.classifications;
                    _spanTranslator = classifications.GetTracker(classifications.Data.version);
                }

                if (_spanTranslator != null)
                {
                    OnNewClassifications(_buffer.Buffer.CurrentSnapshot);
                }
            }
        }
コード例 #11
0
        private async void OnNewAnalysis(AnalysisEntry entry)
        {
            var pyService = _provider._serviceProvider.GetPythonToolsService();
            var options   = pyService != null ? pyService.AdvancedOptions : null;

            if (options == null || options.ColorNames == false)
            {
                bool raise = false;
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        raise      = true;
                    }
                }

                if (raise)
                {
                    OnNewClassifications(_buffer.CurrentSnapshot);
                }
                return;
            }

            var classifications = await entry.Analyzer.GetAnalysisClassificationsAsync(
                entry,
                _buffer,
                options.ColorNamesWithAnalysis
                );

            if (classifications != null)
            {
                Debug.WriteLine("Received {0} classifications", classifications.Data.classifications.Length);
                // sort the spans by starting position so we can use binary search when handing them out
                Array.Sort(
                    classifications.Data.classifications,
                    (x, y) => x.start - y.start
                    );

                lock (_spanCacheLock) {
                    _spanCache      = classifications.Data.classifications;
                    _spanTranslator = classifications.GetTracker(classifications.Data.version);
                }

                if (_spanTranslator != null)
                {
                    OnNewClassifications(_buffer.CurrentSnapshot);
                }
            }
        }
コード例 #12
0
        public void TestMethod1()
        {
            // Define a provider and two observers.
            LocationTracker provider = new LocationTracker();
            LocationReporter reporter1 = new LocationReporter("FixedGPS");
            reporter1.Subscribe(provider);
            LocationReporter reporter2 = new LocationReporter("MobileGPS");
            reporter2.Subscribe(provider);

            provider.TrackLocation(new Location(47.6456, -122.1312));
            reporter1.Unsubscribe();
            provider.TrackLocation(new Location(47.6677, -122.1199));
            provider.TrackLocation(null);
            provider.EndTransmission();
        }
コード例 #13
0
        public void Initialize()
        {
            m_fences = new HashSet <LocationFence>();
            //m_triggers = new HashSet<LocationTrigger>();

            if (Platform.Instance.UseDeadReckoning)
            {
                var proc = new DeadReckoningProcessor(Platform.Instance.Pedometer, Compass);
                // Smooth location updates create a "spongy" feeling in the editor that gets
                // annoying really quickly
                proc.SmoothLocationUpdates = Platform.Instance.SmoothLocationUpdates && !Application.isEditor;

                UserLocationService.Instance.SystemReadingProcessor = proc;

                proc.Start();
            }

            LocationTracker          = UserLocationService.Instance.CreateLocationTracker();
            LocationTracker.Updated += LocationTracker_Updated;

            LocationTracker.Start();

            Platform.Instance.OnEnterBackground.AddListener(() =>
            {
                LocationTracker.Stop();

                lock (m_fences)
                {
                    foreach (var fence in m_fences)
                    {
                        fence.Suspend();
                    }
                }
            });

            Platform.Instance.OnExitBackground.AddListener(() =>
            {
                LocationTracker.Start();

                lock (m_fences)
                {
                    foreach (var fence in m_fences)
                    {
                        fence.Resume();
                    }
                }
            });
        }
コード例 #14
0
        public ActivitySystem(DatabaseConfiguration databaseConfiguration, bool localCaching = true)
        {
            DatabaseName = databaseConfiguration.DatabaseName;

            LocalCaching = localCaching;

            InitializeEvents();

            Ip = Net.GetIp(IpType.All);

            Port = databaseConfiguration.Port;

            Tracker = new LocationTracker(Ip);

            InitializeDocumentStore(Net.GetUrl(databaseConfiguration.Address, databaseConfiguration.Port, "").ToString());
        }
コード例 #15
0
        //public event EventHandler Updated;

        public void Initialize()
        {
            if (m_initialized)
            {
                return;
            }

            m_initialized = true;

            m_logger = new Logger(this);

            m_locationTracker          = UserLocationService.Instance.CreateLocationTracker(SearchMoveDistance / 2);
            m_locationTracker.Updated += LocationTracker_Updated;

            m_logger.Debug("Initialize");
        }
コード例 #16
0
        static void Main(string[] args)
        {
            LocationTracker  provider  = new LocationTracker();
            LocationReporter reporter1 = new LocationReporter("FixedGPS");

            reporter1.Subscribe(provider);
            LocationReporter reporter2 = new LocationReporter("MobileGPS");

            reporter2.Subscribe(provider);

            provider.TrackLocation(new Location(1, 2));
            reporter1.Unsubscribe();
            provider.TrackLocation(new Location(3, 4));
            provider.TrackLocation(null);
            provider.EndTransmission();
        }
コード例 #17
0
        private async Task OnNewAnalysisAsync(PythonTextBufferInfo sender, AnalysisEntry entry)
        {
            if (!_provider._colorNames || entry == null)
            {
                bool raise = false;
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        raise      = true;
                    }
                }

                if (raise)
                {
                    OnNewClassifications(sender.CurrentSnapshot);
                }
                return;
            }


            var classifications = await entry.Analyzer.GetAnalysisClassificationsAsync(
                entry,
                sender.Buffer,
                _provider._colorNamesWithAnalysis
                );

            if (classifications != null)
            {
                Debug.WriteLine("Received {0} classifications", classifications.Data.classifications?.Length ?? 0);

                lock (_spanCacheLock) {
                    // sort the spans by starting position so we can use binary search when handing them out
                    _spanCache = classifications.Data.classifications
                                 .MaybeEnumerate()
                                 .OrderBy(c => c.start)
                                 .Distinct(ClassificationComparer.Instance)
                                 .ToArray();
                    _spanTranslator = classifications.GetTracker(classifications.Data.version);
                }

                if (_spanTranslator != null)
                {
                    OnNewClassifications(sender.CurrentSnapshot);
                }
            }
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: Louis0503/IObservableTest
        static void Main(string[] args)
        {

            //Define a provider and two observers

            LocationTracker provider = new LocationTracker();
            LocationReporter reporter1 = new LocationReporter("FixGPS");
            reporter1.Subscribe(provider);
            LocationReporter reporter2 = new LocationReporter("MobileGPS");
            reporter2.Subscribe(provider);
            provider.TrackLocation(new Location(47.6456, -122.1312));
            reporter1.Unsubscribe();
            provider.TrackLocation(new Location(47.6677, -122.1199));
            provider.TrackLocation(null);
            provider.EndTransmission();
            Console.ReadKey();
        }
コード例 #19
0
ファイル: program.cs プロジェクト: zhimaqiao51/docs
    static void Main(string[] args)
    {
        // Define a provider and two observers.
        LocationTracker  provider  = new LocationTracker();
        LocationReporter reporter1 = new LocationReporter("FixedGPS");

        reporter1.Subscribe(provider);
        LocationReporter reporter2 = new LocationReporter("MobileGPS");

        reporter2.Subscribe(provider);

        provider.TrackLocation(new Location(47.6456, -122.1312));
        reporter1.Unsubscribe();
        provider.TrackLocation(new Location(47.6677, -122.1199));
        provider.TrackLocation(null);
        provider.EndTransmission();
    }
コード例 #20
0
ファイル: LocationSnapshot.cs プロジェクト: wxwssg/SMAPI
        /// <summary>Update the tracked values.</summary>
        /// <param name="watcher">The watcher to snapshot.</param>
        public void Update(LocationTracker watcher)
        {
            // main lists
            this.Buildings.Update(watcher.BuildingsWatcher);
            this.Debris.Update(watcher.DebrisWatcher);
            this.LargeTerrainFeatures.Update(watcher.LargeTerrainFeaturesWatcher);
            this.Npcs.Update(watcher.NpcsWatcher);
            this.Objects.Update(watcher.ObjectsWatcher);
            this.TerrainFeatures.Update(watcher.TerrainFeaturesWatcher);

            // chest inventories
            this.ChestItems.Clear();
            foreach (ChestTracker tracker in watcher.ChestWatchers.Values)
            {
                if (tracker.TryGetInventoryChanges(out SnapshotItemListDiff changes))
                {
                    this.ChestItems[tracker.Chest] = changes;
                }
            }
        }
コード例 #21
0
        private static void RecreatedReporterAndTrackerExample()
        {
            Console.WriteLine("02 Rebuild Observable with Rx");
            var provider = new LocationTracker(); // Observable

            var reporter1 = new LocationReporter("FixedGPS "); // Observer
            reporter1.Subscribe(provider);

            var reporter2 = new LocationReporter("MobileGPS"); // Observer
            reporter2.Subscribe(provider);

            provider.TrackLocation(new Location(47.6456, -123.1312));
            provider.TrackLocation(new Location(31.6677, -11.1199));

            reporter1.OnCompleted();

            provider.TrackLocation(new Location(84.6677, -21.1023));
            provider.TrackLocation(null);
            provider.EndTransmission();

            ConsoleUtils.WaitForEnter();
        }
コード例 #22
0
        private PythonTextBufferInfo(PythonEditorServices services, ITextBuffer buffer)
        {
            Services                = services;
            Buffer                  = buffer;
            _eventSinks             = new ConcurrentDictionary <object, IPythonTextBufferInfoEventSink>();
            _filename               = new Lazy <string>(GetOrCreateFilename);
            _documentUri            = new Lazy <Uri>(GetOrCreateDocumentUri);
            _tokenCache             = new TokenCache();
            _defaultLanguageVersion = PythonLanguageVersion.None;

            ITextDocument doc;

            if (Buffer.Properties.TryGetProperty(typeof(ITextDocument), out doc))
            {
                Document = doc;
                Document.EncodingChanged += Document_EncodingChanged;
            }
            Buffer.ContentTypeChanged += Buffer_ContentTypeChanged;
            Buffer.Changed            += Buffer_TextContentChanged;
            Buffer.ChangedLowPriority += Buffer_TextContentChangedLowPriority;

            if (Buffer is ITextBuffer2 buffer2)
            {
                _hasChangedOnBackground      = true;
                buffer2.ChangedOnBackground += Buffer_TextContentChangedOnBackground;
            }

            _locationTracker = new LocationTracker(Buffer.CurrentSnapshot);

#if BUFFERINFO_TRACING
            _traceLog = new AnalysisLogWriter(
                PathUtils.GetAvailableFilename(System.IO.Path.GetTempPath(), "PythonTools_Buffer_{0}_{1:yyyyMMddHHmmss}".FormatInvariant(PathUtils.GetFileOrDirectoryName(_filename.Value), DateTime.Now), ".log"),
                false,
                false,
                cacheSize: 1
                );
#endif
        }
コード例 #23
0
        public void GetLineLocationsTest()
        {
            var t = new LocationTracker(TestSnapshots[0]);

            var lines = t.GetLineLocations(0);

            AssertLines(lines, 0);

            lines = t.GetLineLocations(1);
            AssertLines(lines, 10, 0);

            lines = t.GetLineLocations(2);
            AssertLines(lines, 10, 13, 0);

            lines = t.GetLineLocations(3);
            AssertLines(lines, 10, 17, 1, 10, 13, 0);

            lines = t.GetLineLocations(4);
            AssertLines(lines, 10, 17, 1, 10, 10);

            lines = t.GetLineLocations(5);
            AssertLines(lines, 10, 17, 1, 10, 15, 0);
        }
コード例 #24
0
ファイル: Hunter.cs プロジェクト: travisnelson/blood-meridian
    // Update is called once per frame
    void Update()
    {
        if (dead)
        {
            return;
        }

        // chase mouse pointer
        Vector3    mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Person     victim        = null;
        StatusText status        = (StatusText)GameObject.Find("StatusText").GetComponent("StatusText");

        if ((victim = walkTowards(mousePosition)) != null)
        {
            if ((victim as Hunter) == null && victim.dead != true)
            {
                fight(victim);
            }
            else
            {
                fidget();
            }
        }

        // sell scalps, upgrade, heal
        LocationTracker location = (LocationTracker)GameObject.Find("LocationTracker").GetComponent("LocationTracker");

        if (location.currentLocation != null && location.currentLocation.locationName == "Chihuahua")
        {
            if (horse == false && scalps > Config.HORSE_COST)
            {
                scalps -= Config.HORSE_COST;
                horse   = true;
                status.addText(personNameCap + " buys a horse.", true);
            }

            if (damage == Config.BAREHAND_DAMAGE && scalps >= Config.KNIFE_COST)
            {
                scalps -= Config.KNIFE_COST;
                damage  = Config.KNIFE_DAMAGE;
                status.addText(personNameCap + " buys a large knife.", true);
            }
            else if (damage == Config.KNIFE_DAMAGE && scalps >= Config.PISTOL_COST)
            {
                scalps -= Config.PISTOL_COST;
                damage  = Config.PISTOL_DAMAGE;
                status.addText(personNameCap + " buys a " + (Random.Range(0, 2) == 0?"Colt Paterson pistol":"Whitneyville Colt pistol") + ".", true);
            }
            else if (damage == Config.PISTOL_DAMAGE && scalps >= Config.RIFLE_COST)
            {
                scalps -= Config.RIFLE_COST;
                damage  = Config.RIFLE_DAMAGE;
                status.addText(personNameCap + " buys a Wesson rifle.", true);
            }

            if (health < Config.HUNTER_MAX_HEALTH - 10 && scalps > 0)
            {
                health = Config.HUNTER_MAX_HEALTH;
                status.addText(personNameCap + " eats, drinks and feels better.", true);
                --scalps;
            }
        }
    }
コード例 #25
0
        public void Constructor()
        {
            var locationTracker = LocationTracker.GetInstance(positionChangedArgs => { });

            Assert.IsNotNull(locationTracker);
        }
コード例 #26
0
 // Start is called before the first frame update
 void Start()
 {
     Instance = this;
     DontDestroyOnLoad(gameObject);
     StartCoroutine(StartLocationService());
 }