Example #1
0
        private async Task InitApi()
        {
            string           epsgCode        = "EPSG:28992";
            IAddressSettings addressSettings = AddressSettingsFactory.Create("nl", "CMDatabase");
            IDomElement      element         = DomElementFactory.Create();
            var _options = OptionsFactory.Create("gbo", "Gg200786001", "testdfdsfj", epsgCode, addressSettings, element);

            try
            {
                await StreetSmartAPI.Init(_options);

                // Open image
                IList <ViewerType> viewerTypes = new List <ViewerType> {
                    ViewerType.Panorama
                };
                IPanoramaViewerOptions panoramaOptions = PanoramaViewerOptionsFactory.Create(true, false, true, true, true, true);
                panoramaOptions.MeasureTypeButtonToggle = false;
                IViewerOptions viewerOptions = ViewerOptionsFactory.Create(viewerTypes, epsgCode, panoramaOptions);
                try
                {
                    IList <IViewer> viewers = await StreetSmartAPI.Open("Lange Haven 145, Schiedam", viewerOptions);
                }
                catch (StreetSmartImageNotFoundException)
                {
                    MessageBox.Show("image openen >> kapot");
                }
            }
            catch (StreetSmartLoginFailedException)
            {
                MessageBox.Show("api laden >> kapot");
            }
        }
        public TOptions Create(string name)
        {
            TOptions options = _innerFactory.Create(name);

            string formattedOptions = null;

            // See if we need to format these options, either from one of our Options
            // or from a registered IOptionsFormatter<TOptions>
            if (_optionsFormatter != null)
            {
                formattedOptions = _optionsFormatter.Format(options);
            }
            else if (options is IOptionsFormatter optionsFormatter)
            {
                formattedOptions = optionsFormatter.Format();
            }

            if (formattedOptions != null)
            {
                string logString = $"{typeof(TOptions).Name}{Environment.NewLine}{formattedOptions}";
                _logSource.LogOptions(logString);
            }

            return(options);
        }
Example #3
0
        public TOptions Create(string name = null)
        {
            var options = _rawOptions.Create(name);

            if (!_definitions.Any(x => x.Type == typeof(TOptions)))
            {
                return(options);
            }

            var context = _provider.GetRequiredService <BotDbContext>();

            var definition = _definitions.First(x => x.Type == typeof(TOptions));

            foreach (var property in definition.Type.GetProperties())
            {
                var entry = context.Options.FirstOrDefault(x => x.Id == $"{definition.Name}:{property.Name}");
                if (entry == null)
                {
                    continue;
                }

                var value = JsonConvert.DeserializeObject(entry.Value, property.PropertyType);
                property.SetValue(options, value);
            }

            return(options);
        }
Example #4
0
        public void CanCreateOptionsFactory()
        {
            var factory = new OptionsFactory <FakeOptions>(new IConfigureOptions <FakeOptions> [0],
                                                           new IPostConfigureOptions <FakeOptions>[] { });

            Assert.Equal("", factory.Create("").Message);
        }
Example #5
0
        public void GivenTheFileDoesNotExist_FileDoesNotExistExceptionIsThrown()
        {
            var givenOptions = OptionsFactory.Create("");
            var fileSystem   = new MockFileSystem();
            var sut          = new FileStorage(givenOptions, fileSystem);

            Action act = () => sut.Read("qwerty").Close();

            act.Should().Throw <FileDoesNotExistException>();
        }
        public void GivenShortFilename_ArgumentExceptionIsThrown(string givenFilename)
        {
            var givenOptions = OptionsFactory.Create("");
            var fileSystem   = new MockFileSystem();
            var sut          = new FileStorage(givenOptions, fileSystem);

            Action act = () => sut.CreateNew(givenFilename).Close();

            act.Should().Throw <ArgumentException>();
        }
Example #7
0
        public void GivenTheFileExists_ThenFileIsDeleted()
        {
            var givenOptions = OptionsFactory.Create("");
            var fileSystem   = new MockFileSystem()
                               .WithFile("q/w/qwerty", "Sample content");
            var sut = new FileStorage(givenOptions, fileSystem);

            sut.Delete("qwerty");

            fileSystem.GetFile("q/w/qwerty").Should().BeNull();
        }
Example #8
0
        public void GivenFileSystemContainingFileWithTheSameName_ThenFileExistsExceptionIsThrown()
        {
            var givenOptions = OptionsFactory.Create("");
            var fileSystem   = new MockFileSystem()
                               .WithFile("a/b/abcdef", "");
            var sut = new FileStorage(givenOptions, fileSystem);

            Action act = () => sut.CreateNew("abcdef").Close();

            act.Should().Throw <FileExistsException>();
        }
Example #9
0
        public void GivenEmptyFileSystem_ThenFileIsCreated()
        {
            var givenOptions = OptionsFactory.Create("");
            var fileSystem   = new MockFileSystem();
            var sut          = new FileStorage(givenOptions, fileSystem);

            sut.CreateNew("abcdef")
            .Close();

            fileSystem.GetFile("a/b/abcdef").Should().NotBeNull();
        }
        public void GivenLongAlphanumericFilename_FileIsCreated(string givenFilename)
        {
            var givenOptions     = OptionsFactory.Create("");
            var fileSystem       = new MockFileSystem();
            var sut              = new FileStorage(givenOptions, fileSystem);
            var initialFileCount = fileSystem.AllFiles.Count();

            sut.CreateNew(givenFilename)
            .Close();

            fileSystem.AllFiles.Count().Should().Be(1 + initialFileCount);
        }
Example #11
0
        public void GivenFileSystemContainingFileWithDifferentName_ThenFileIsCreated()
        {
            var givenOptions = OptionsFactory.Create("");
            var fileSystem   = new MockFileSystem()
                               .WithFile("OtherFile", "file content");
            var sut = new FileStorage(givenOptions, fileSystem);

            sut.CreateNew("abcdef")
            .Close();

            fileSystem.GetFile("a/b/abcdef").Should().NotBeNull();
        }
Example #12
0
        public void GivenTheFileExists_FileContentIsRead()
        {
            var givenOptions     = OptionsFactory.Create("");
            var givenFileContent = "SampleContent";
            var fileSystem       = new MockFileSystem()
                                   .WithFile("q/w/qwerty", givenFileContent);
            var sut = new FileStorage(givenOptions, fileSystem);

            var stream            = sut.Read("qwerty");
            var actualFileContent = new StreamReader(stream).ReadToEnd();

            actualFileContent.Should().Be(givenFileContent);
        }
Example #13
0
    public void NextDialog()
    {
        concurrentDialog = concurrentDialog.GetNextDialog();

        if (concurrentDialog.isOption())
        {
            gameController.ShowOptions();
            gameController.FillFildOfOption(concurrentDialog);
            gameController.FillOptions(optionFactory.Create(concurrentDialog.Dialogs().Count));
        }
        else
        {
            gameController.ShowDialog();
            gameController.FillFildOfDialog(concurrentDialog);
        }
    }
Example #14
0
        public void GivenEmptyFileSystemAndNonEmptyRootDirectory_ThenFileIsCreatedInsideRootDirectory()
        {
            var rootDirectory = "root-dir";
            var givenOptions  = OptionsFactory.Create(rootDirectory);
            var fileSystem    = new MockFileSystem();

            fileSystem.AddDirectory(rootDirectory);
            var sut = new FileStorage(givenOptions, fileSystem);

            sut.CreateNew("abcdef")
            .Close();

            var expectedPath = Path.Combine(rootDirectory, "a", "b", "abcdef");

            fileSystem.GetFile(expectedPath).Should().NotBeNull();
        }