Esempio n. 1
0
        public void GetResult()
        {
            Provider provider = new Provider(new T9Parser());

            provider.Add(new StringProvider());
            provider.Add(new ArrayProvider());

            string inputStr = "hi";

            Assert.AreEqual(inputStr.GetType(), provider.GetResult(inputStr).GetType());
            Assert.AreEqual("44 444", provider.GetResult(inputStr));
            string[] arr = { "hi", "yes", "foo  bar", "hello world" };
            Assert.AreEqual(arr.GetType(), provider.GetResult(arr).GetType());
            Assert.AreEqual("44 444", (provider.GetResult(arr) as string[])[0]);
            FileInfo fileInputSmall = new FileInfo(Directory.GetCurrentDirectory() + "\\in\\C-small-practice.in");

            try
            {
                var resfile = provider.GetResult(fileInputSmall) as string;
                Assert.AreEqual(true, File.Exists(resfile));
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Unregistered input type", ex.Message);
            }
            provider.Add(new FileProvider());
            var resfile1 = provider.GetResult(fileInputSmall) as string;

            Assert.AreEqual(true, File.Exists(resfile1));
        }
Esempio n. 2
0
        public void TestConfigSimpleDatabase()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> {
            });

            fileSystem.AddDirectory(Database.DefaultConfigDir);

            var db  = new Database(fileSystem);
            var fsp = new Provider("FileSystem");

            db.Providers.Add("FileSystem", fsp);
            var e1 = new Entry(@"c:\dir1\", 12, DateTime.Now, false);
            var e2 = new Entry(@"c:\dir1\file2", 34, DateTime.Now, true);

            fsp.Add(e1);
            fsp.Add(e2);
            db.Save(100);

            var fsFileName = System.IO.Path.Combine(Database.DefaultConfigDir, $"{Database.ConfigFilePrefix}.FileSystem.txt");

            Assert.IsTrue(fileSystem.FileExists(FileSystemConfigPath));
            Assert.AreEqual(
                string.Join(Environment.NewLine, e1.ToString(), e2.ToString(), ""),
                fileSystem.File.ReadAllText(fsFileName));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Provider provider = new Provider(new T9Parser());

            provider.Add(new StringProvider());
            provider.Add(new ArrayProvider());
            provider.Add(new FileProvider());

            var str = provider.GetResult("hi");

            Console.WriteLine($"Case #1: {str}");

            string[] arr = { "hi", "yes", "foo  bar", "hello world" };
            int      idx = 1;

            foreach (var item in (string[])provider.GetResult(arr))
            {
                Console.WriteLine($"Case #{idx}: {item}");
            }
            var curDir = Directory.GetCurrentDirectory();

            Console.WriteLine(curDir);
            FileInfo file    = new FileInfo(curDir + "\\samples\\C-small-practice.in");
            var      resfile = provider.GetResult(file);

            Console.WriteLine(resfile);
            Console.ReadLine();
        }
        public void AddAndRemove()
        {
            int counterAdd     = 0;
            int counterRemove  = 0;
            int counterCleared = 0;
            var provider       = new Provider <string, string>();

            provider.Added   += (provider1, id, entry) => counterAdd++;
            provider.Removed += (provider1, id, entry) => counterRemove++;
            provider.Cleared += provider1 => counterCleared++;

            Assert.IsEmpty(provider.Entries);
            Assert.AreEqual(0, counterAdd);
            Assert.AreEqual(0, counterRemove);
            Assert.AreEqual(0, counterCleared);

            provider.Add("0", "0");
            provider.Add("1", "1");

            Assert.IsNotEmpty(provider.Entries);
            Assert.AreEqual(2, counterAdd);
            Assert.AreEqual(0, counterRemove);
            Assert.AreEqual(0, counterCleared);

            string entry0 = provider.Get("0");
            string entry1 = provider.Get("1");

            Assert.NotNull(entry0);
            Assert.NotNull(entry1);
            Assert.AreEqual("0", entry0);
            Assert.AreEqual("1", entry1);
            Assert.AreEqual(2, counterAdd);
            Assert.AreEqual(0, counterRemove);
            Assert.AreEqual(0, counterCleared);

            bool result0 = provider.Remove("0");

            Assert.True(result0);
            Assert.AreEqual(1, provider.Entries.Count);
            Assert.AreEqual(2, counterAdd);
            Assert.AreEqual(1, counterRemove);
            Assert.AreEqual(0, counterCleared);

            provider.Clear();

            Assert.IsEmpty(provider.Entries);
            Assert.AreEqual(2, counterAdd);
            Assert.AreEqual(1, counterRemove);
            Assert.AreEqual(1, counterCleared);
        }
Esempio n. 5
0
        public void DuplicateCheck()
        {
            Provider provider = new Provider();

            provider.Add(new Resource(ResourceType.Firmware, 10));

            try
            {
                provider.Add(new Resource(ResourceType.Firmware, 20));
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }
        }
Esempio n. 6
0
        public void DoubleAdditionException()
        {
            Provider provider = new Provider(new T9Parser());

            provider.Add(new StringProvider());
            try
            {
                provider.Add(new StringProvider());
            }
            catch (Exception ex)
            {
                string[] arr = ex.Message.Split(':');
                Assert.AreEqual("The provider exists in dictionary", arr[0]);
            }
        }
Esempio n. 7
0
        public void Add()
        {
            Provider provider = new Provider(new T9Parser());

            provider.Add(new StringProvider());
            Assert.AreEqual(1, provider.Providers.Count);
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PointOfInterestModel"/> class from Azure Maps Point of Interest.
        /// </summary>
        /// <param name="azureMapsPoi">Azure Maps point of interest.</param>
        public PointOfInterestModel(SearchResult azureMapsPoi)
        {
            Id = !string.IsNullOrEmpty(azureMapsPoi.Id)
                ? azureMapsPoi.Id
                : Id;
            Name = !string.IsNullOrEmpty(azureMapsPoi.Poi?.Name)
                ? azureMapsPoi.Poi?.Name
                : Name;
            City = !string.IsNullOrEmpty(azureMapsPoi.Address?.MunicipalitySubdivision)
                ? azureMapsPoi.Address.MunicipalitySubdivision
                : City;
            Street = !string.IsNullOrEmpty(azureMapsPoi.Address?.ToBingAddress()?.AddressLine)
                ? azureMapsPoi.Address?.ToBingAddress()?.AddressLine
                : Street;
            Geolocation = azureMapsPoi.Position
                          ?? Geolocation;
            Category = (azureMapsPoi.Poi?.Categories != null)
            ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(azureMapsPoi.Poi.Categories.First().ToLower())
            : Category;

            if (Provider == null)
            {
                Provider = new SortedSet <string> {
                    AzureMaps
                };
            }
            else
            {
                Provider.Add(AzureMaps);
            }
        }
Esempio n. 9
0
        public Frontend(string[] args)
        {
            var httpFEId = Guid.NewGuid();

            HttpSockets.Add(this, httpFEId, new _socket <HttpListener,
                                                         HttpListenerContext, long, Exception>(httpFEId, new IPEndPoint(IPAddress.Any, 90), AuthenticationSchemes.None));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PointOfInterestModel"/> class from Azure Maps Point of Interest.
        /// </summary>
        /// <param name="azureMapsPoi">Azure Maps point of interest.</param>
        public PointOfInterestModel(SearchResult azureMapsPoi)
        {
            Id = !string.IsNullOrEmpty(azureMapsPoi.Id)
                ? azureMapsPoi.Id
                : Id;
            Name = !string.IsNullOrEmpty(azureMapsPoi.Poi?.Name)
                ? azureMapsPoi.Poi?.Name
                : Name;
            Address = !string.IsNullOrEmpty(azureMapsPoi.Address?.FreeformAddress)
                ? azureMapsPoi.Address?.FreeformAddress
                : Address;

            // Set if to be the same as Address for now
            // Change it to proper handling when using AzureMaps again
            AddressForSpeak = Address;
            Geolocation     = azureMapsPoi.Position
                              ?? Geolocation;
            Category = (azureMapsPoi.Poi?.Classifications != null)
            ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(azureMapsPoi.Poi.Classifications.FirstOrDefault().Names.FirstOrDefault().NameProperty)
            : Category;

            if (Provider == null)
            {
                Provider = new SortedSet <string> {
                    AzureMaps
                };
            }
            else
            {
                Provider.Add(AzureMaps);
            }
        }
Esempio n. 11
0
        public void CountIntersect()
        {
            Provider provider = new Provider();

            provider.Add(new Resource(ResourceType.Firmware, 10));
            provider.Add(new Resource(ResourceType.Hardware, 20));

            Demands demands = new Demands();

            demands.Add(new Resource(ResourceType.Firmware, 10));
            demands.Add(new Resource(ResourceType.Other, 30));

            int c = Create(provider, demands);

            Assert.IsTrue(c == 1);
        }
Esempio n. 12
0
        // Called from native class VCSAssetMenuHandler as "Assets/Version Control/Mark Add" menu handler
        static void MarkAdd(MenuCommand cmd)
        {
            AssetList selected = Provider.GetAssetListFromSelection();

            selected = Provider.ConsolidateAssetList(selected, CheckoutMode.Both);
            Provider.Add(selected, true).SetCompletionAction(CompletionAction.UpdatePendingWindow);
        }
    void InstallManifest(PackageManifest packageManifest)
    {
        if (Directory.Exists(packageManifestPath) == false)
        {
            Directory.CreateDirectory(packageManifestPath);
        }
        string manifestFilePath = Path.Combine(packageManifestPath, packageManifest.title) + ".manifest";

        if (Provider.isActive)
        {
            Asset manifestAsset = new Asset(manifestFilePath);
            Task  statusTask    = Provider.Status(manifestAsset);
            statusTask.Wait();
            AssetList manifestAssetList = statusTask.assetList;
            manifestAsset = manifestAssetList[0];

            if (File.Exists(manifestFilePath) == true)
            {
                if (Provider.IsOpenForEdit(manifestAssetList[0]) == false)
                {
                    Task checkoutTask = Provider.Checkout(manifestAssetList, CheckoutMode.Asset);
                    checkoutTask.Wait();
                    if (checkoutTask.success == false)
                    {
                        throw new Exception(string.Format("Failed to check out manifest file {0}", manifestFilePath));
                    }
                }
            }
        }

        //If there's an existing manifest at this point, merge in the installed files from previous runs.
        //Since you can install a package multiple times with different subsets of the files, we need to aggregate the results of the separate
        //installations
        if (File.Exists(manifestFilePath) == true)
        {
            PackageManifest oldManifest = (PackageManifest)JsonUtility.FromJson(File.ReadAllText(manifestFilePath), typeof(PackageManifest));
            packageManifest.filelistInstalled.AddRange(oldManifest.filelistInstalled.Except(packageManifest.filelistInstalled, new PackageManifestEntryComparer()));
        }

        File.WriteAllText(manifestFilePath, JsonUtility.ToJson(packageManifest));

        if (Provider.isActive)
        {
            Asset manifestAsset = new Asset(manifestFilePath);
            Task  statusTask    = Provider.Status(manifestAsset);
            statusTask.Wait();
            AssetList manifestAssetList = statusTask.assetList;
            manifestAsset = manifestAssetList[0];
            if (manifestAsset.isInCurrentProject == false)
            {
                Task addTask = Provider.Add(manifestAssetList, false);
                addTask.Wait();
                if (addTask.success == false)
                {
                    throw new Exception(string.Format("Failed to add manifest file {0} to version control", manifestFilePath));
                }
            }
        }
    }
Esempio n. 14
0
        public void TestSaveMaxEntries()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> {
            });

            fileSystem.AddDirectory(Database.DefaultConfigDir);
            var db  = new Database(fileSystem);
            var fsp = new Provider("FileSystem");

            db.Providers.Add("FileSystem", fsp);
            fsp.Add(new Entry(@"c:\dir1\", 12, DateTime.Now, false));
            fsp.Add(new Entry(@"c:\dir1\file2", 34, DateTime.Now, true));
            db.Save(1);
            db.Load();

            Assert.AreEqual(1, db.Providers["FileSystem"].Entries.Count);
        }
Esempio n. 15
0
        public void CheckMaxSize()
        {
            Provider provider = new Provider();

            provider.Add(new Resource(ResourceType.Firmware, 10));
            provider.Add(new Resource(ResourceType.Hardware, 20));
            provider.Add(new Resource(ResourceType.Software, 30));
            provider.Add(new Resource(ResourceType.Other, 40));
            try
            {
                provider.Add(new Resource(ResourceType.Other, 50));
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentOutOfRangeException));
            }
        }
Esempio n. 16
0
        public void TestConfigCanMerge()
        {
            var now         = DateTime.Now;
            var mockE1      = new Entry(@"c:\dir2\", 1, now, false);
            var mockE2      = new Entry(@"c:\dir2\file3", 10, now, true);
            var mockE3      = new Entry(@"c:\dir3\file1", 101, now, true);
            var mockContent = string.Join(Environment.NewLine,
                                          mockE1.ToString(),
                                          mockE2.ToString(),
                                          mockE3.ToString());

            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> {
                { FileSystemConfigPath, new MockFileData(mockContent) }
            });

            var db  = new Database(fileSystem);
            var fsp = new Provider("FileSystem");

            db.Providers.Add("FileSystem", fsp);
            now = now.AddSeconds(1);
            var e1 = new Entry(@"c:\dir1\", 12, now, false);
            var e2 = new Entry(@"c:\dir1\file2", 34, now, true);
            var e3 = new Entry(@"c:\dir2\file3", 11, now, true);
            var e4 = new Entry(@"c:\dir3\file1", 11, now, true);

            fsp.Add(e1);
            fsp.Add(e2);
            fsp.Add(e3);
            fsp.Add(e4);
            Assert.IsTrue(fsp.Remove(e4.FullPath));
            db.Save(100);

            var fsFileName = System.IO.Path.Combine(db.ConfigDir, $"{Database.ConfigFilePrefix}.FileSystem.txt");

            Assert.IsTrue(fileSystem.FileExists(FileSystemConfigPath));
            var configContent = fileSystem.File.ReadAllText(fsFileName);

            StringAssert.Contains(e1 + Environment.NewLine, configContent);
            StringAssert.Contains(e2 + Environment.NewLine, configContent);
            StringAssert.Contains(e3 + Environment.NewLine, configContent);
            StringAssert.Contains(mockE1 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain(mockE2 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain(mockE3 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain(e4 + Environment.NewLine, configContent);
        }
Esempio n. 17
0
 public static bool Add(string key, object value, DateTime expiry)
 {
     if (WebCache.KeyExists(key))
     {
         return(false);
     }
     WebCache.Add(key, value, expiry);
     return(Provider.Add(key, value, expiry));
 }
Esempio n. 18
0
        async Task <bool> ImportChannelsFromDataBase()
        {
            var result = false;

            var chs = db.SQLQuery <ulong>(string.Format("SELECT * FROM channels")).Result;

            if (chs.Count != 0)
            {
                for (var i = ulong.MinValue; i < (ulong)chs.Count; i++)
                {
                    var channel = new Channel();
                    channel.Name     = GetChannelNameByID(db, int.Parse(chs[i]["name"])).Result;
                    channel.Logo     = GetLogoByID(db, int.Parse(chs[i]["logo"])).Result;
                    channel.Provider = int.Parse(chs[i]["provider"]);
                    channel.ChanDBID = int.Parse(chs[i]["id"]);
                    channel.ID       = int.Parse(chs[i]["epgid"]);
                    channel.ChanNo   = int.Parse(chs[i]["channo"]);

                    var servers = db.SQLQuery <ulong>(string.Format("SELECT * FROM servers WHERE channel='{0}'", chs[i]["id"])).Result;
                    if (servers.Count != 0)
                    {
                        for (var i2 = ulong.MinValue; i2 < (ulong)servers.Count; i2++)
                        {
                            channel.Servers.Add(new Server(servers[i2]["url"],
                                                           int.Parse(servers[i2]["type"]), int.Parse(servers[i2]["ua"])));
                        }
                    }

                    if (!Channels.Exist(channel.Name))
                    {
                        Channels.Add(channel.Name, channel);
                    }
                }

                result = true;
            }
            else
            {
                Task.Run(() => Console.WriteLine("No Channels to load from Database!"));
            }

            return(result);
        }
Esempio n. 19
0
        public void TestConfigCanMerge()
        {
            var now = DateTime.Now;
            var mockE1 = new Entry (@"c:\dir2\", 1, now, false);
            var mockE2 = new Entry(@"c:\dir2\file3",10,now,true);
            var mockE3 = new Entry(@"c:\dir3\file1",101,now,true);
            var mockContent = string.Join (Environment.NewLine,
                mockE1.ToString (),
                mockE2.ToString (),
                mockE3.ToString ());

            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> {
                {   FileSystemConfigPath, new MockFileData(mockContent) }
            });

            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add ("FileSystem", fsp);
            now = now.AddSeconds (1);
            var e1 = new Entry (@"c:\dir1\", 12, now, false);
            var e2 = new Entry (@"c:\dir1\file2", 34, now, true);
            var e3 = new Entry(@"c:\dir2\file3",11,now,true);
            var e4 = new Entry(@"c:\dir3\file1",11,now,true);

            fsp.Add(e1);
            fsp.Add(e2);
            fsp.Add(e3);
            fsp.Add(e4);
            Assert.IsTrue(fsp.Remove(e4.FullPath));
            db.Save(100);

            var fsFileName = System.IO.Path.Combine (db.ConfigDir,$"{Database.ConfigFilePrefix}.FileSystem.txt");

            Assert.IsTrue(fileSystem.FileExists(FileSystemConfigPath));
            var configContent = fileSystem.File.ReadAllText (fsFileName);
            StringAssert.Contains (e1 + Environment.NewLine, configContent);
            StringAssert.Contains (e2 + Environment.NewLine, configContent);
            StringAssert.Contains (e3 + Environment.NewLine, configContent);
            StringAssert.Contains (mockE1 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain (mockE2 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain (mockE3 + Environment.NewLine, configContent);
            StringAssert.DoesNotContain(e4 + Environment.NewLine, configContent);
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            foreach (KeyValuePair <string, IDatabaseBuilder> pair in Description.Databases)
            {
                IDatabase database = pair.Value.Build();

                Provider.Add(pair.Key, database);
            }
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            foreach ((string key, IBuilder <IApplication, IDataLoader> value) in Description.Loaders)
            {
                IDataLoader loader = value.Build(Application);

                Provider.Add(key, loader);
            }
        }
Esempio n. 22
0
        /// <inheritdoc/>
        public IParameterBuilder AddContext <TValue>(string alias, Expression <Func <TValue> > contextExpression)
        {
            var builder = New();

            builder.Alias = alias;
            builder._values.Add(new ParameterBuilderValue(null, alias, null, contextExpression));

            Provider.Add(builder);

            return(builder);
        }
Esempio n. 23
0
        /// <summary>
        /// Implements the Ignore operation by adding values to the builder.
        /// </summary>
        /// <param name="parameterName">The name of the parameter to add.</param>
        /// <param name="type">An optional type to ignore.</param>
        /// <returns>A continuation of the configuration.</returns>
        private ParameterBuilder IgnoreImpl(string parameterName, Type type)
        {
            var value = new ParameterBuilderValue(parameterName, parameterName, type, null);

            value.Ignore = true;
            _values.Add(value);

            Provider.Add(this);

            return(this);
        }
Esempio n. 24
0
        public void ConsumerClient()
        {
            Provider provider = new Provider();

            provider.Add(new Resource(ResourceType.Firmware, 10));

            Demands demands = new Demands();

            demands.Add(new Requirements(ResourceType.Firmware, 5));

            int c = Create(provider, demands);
        }
Esempio n. 25
0
        public Backend(string[] args)
        {
            var credentials = Convert.ToBase64String(Encoding.ASCII
                                                     .GetBytes("Namiono-Client:6452312135464321"));

            var httpBEId = Guid.NewGuid();

            HttpSockets.Add(this, httpBEId, new _socket <HttpListener, HttpListenerContext,
                                                         long, Exception>(httpBEId, new IPEndPoint(IPAddress.Any, 91), AuthenticationSchemes.Basic));

            HttpSockets.Members[httpBEId].Credentials = credentials;
        }
Esempio n. 26
0
        public void TestGetEntries()
        {
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> {
            });

            fileSystem.AddDirectory(Database.DefaultConfigDir);
            var db  = new Database(fileSystem);
            var fsp = new Provider("FileSystem");

            db.Providers.Add("FileSystem", fsp);
            var e1 = new Entry(@"c:\dir1\", 12, DateTime.Now, false);
            var e2 = new Entry(@"c:\dir1\file2", 34, DateTime.Now, true);

            fsp.Add(e1);
            fsp.Add(e2);

            Entry[] entries = null;
            Assert.IsTrue(db.GetEntries("FileSystem", out entries));
            Assert.AreEqual(e2, entries[0]);
            Assert.AreEqual(e1, entries[1]);
        }
Esempio n. 27
0
        public override void Add(Site parent, Site site)
        {
            site.Parent = parent;

            var query = Provider.Get(site);

            if (query != null)
            {
                throw new ItemAlreadyExistsException();
            }

            Provider.Add(site);
        }
Esempio n. 28
0
        public static void CreateFile(string contents, string destinationFile, bool sourceControlAdd, LineEndingsMode lineEndings)
        {
            string fileContents = ConvertLineEndings(contents, lineEndings);

            // actually writing out the contents
            File.WriteAllText(destinationFile, fileContents);

            // telling source control to add the file
            if (sourceControlAdd && Provider.enabled && Provider.isActive)
            {
                AssetDatabase.Refresh();
                Provider.Add(new Asset(destinationFile), false).Wait();
            }
        }
Esempio n. 29
0
        public void ValueEquals()
        {
            Provider provider = new Provider();

            provider.Add(new Resource(ResourceType.Firmware, 10));

            Demands demands = new Demands();

            demands.Add(new Resource(ResourceType.Firmware, 10));

            int c = Create(provider, demands);

            Assert.IsTrue(c == 1);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PointOfInterestModel"/> class from Foursquare Point of Interest.
        /// </summary>
        /// <param name="foursquarePoi">Foursquare point of interest.</param>
        public PointOfInterestModel(Venue foursquarePoi)
        {
            Id = !string.IsNullOrEmpty(foursquarePoi.Id)
                ? foursquarePoi.Id
                : Id;
            PointOfInterestImageUrl = !string.IsNullOrEmpty(foursquarePoi.BestPhoto?.AbsoluteUrl)
               ? $"{foursquarePoi.BestPhoto?.Prefix}440x240{foursquarePoi.BestPhoto?.Suffix}"
               : PointOfInterestImageUrl;
            Name = !string.IsNullOrEmpty(foursquarePoi.Name)
                ? foursquarePoi.Name
                : Name;
            Address = foursquarePoi.Location?.FormattedAddress != null
                ? string.Join(", ", foursquarePoi.Location.FormattedAddress.Take(foursquarePoi.Location.FormattedAddress.Length - 1))
                : Address;

            AddressForSpeak = foursquarePoi.Location?.FormattedAddress != null
                ? foursquarePoi.Location.FormattedAddress[0]
                : Address;
            Geolocation = (foursquarePoi.Location != null)
                ? new LatLng()
            {
                Latitude = foursquarePoi.Location.Lat, Longitude = foursquarePoi.Location.Lng
            }
                : Geolocation;
            Price = (foursquarePoi.Price != null)
                ? foursquarePoi.Price.Tier
                : Price;
            Hours = !string.IsNullOrEmpty(foursquarePoi.Hours?.Status)
                ? foursquarePoi.Hours?.Status
                : Hours;
            Rating = foursquarePoi.Rating.ToString("N1")
                     ?? Rating;
            RatingCount = foursquarePoi.RatingSignals != 0
                ? foursquarePoi.RatingSignals
                : RatingCount;
            Category = (foursquarePoi.Categories != null)
                ? foursquarePoi.Categories.First().ShortName
                : Category;

            if (Provider == null)
            {
                Provider = new SortedSet <string> {
                    Foursquare
                };
            }
            else
            {
                Provider.Add(Foursquare);
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PointOfInterestModel"/> class from Foursquare Point of Interest.
        /// </summary>
        /// <param name="foursquarePoi">Foursquare point of interest.</param>
        public PointOfInterestModel(Venue foursquarePoi)
        {
            Id = !string.IsNullOrEmpty(foursquarePoi.Id)
                ? foursquarePoi.Id
                : Id;
            PointOfInterestImageUrl = !string.IsNullOrEmpty(foursquarePoi.BestPhoto?.AbsoluteUrl)
               ? foursquarePoi.BestPhoto?.AbsoluteUrl
               : PointOfInterestImageUrl;
            Name = !string.IsNullOrEmpty(foursquarePoi.Name)
                ? foursquarePoi.Name
                : Name;
            City = !string.IsNullOrEmpty(foursquarePoi.Location?.City)
                ? foursquarePoi.Location?.City
                : City;
            Street = !string.IsNullOrEmpty(foursquarePoi.Location?.Address)
                ? foursquarePoi.Location?.Address
                : City;
            Geolocation = (foursquarePoi.Location != null)
                ? new LatLng()
            {
                Latitude = foursquarePoi.Location.Lat, Longitude = foursquarePoi.Location.Lng
            }
                : Geolocation;
            Price = (foursquarePoi.Price != null)
                ? foursquarePoi.Price.Tier
                : Price;
            Hours = !string.IsNullOrEmpty(foursquarePoi.Hours?.Status)
                ? foursquarePoi.Hours?.Status
                : Hours;
            Rating = foursquarePoi.Rating.ToString("N1")
                     ?? Rating;
            RatingCount = foursquarePoi.RatingSignals != 0
                ? foursquarePoi.RatingSignals
                : RatingCount;
            Category = (foursquarePoi.Categories != null)
                ? foursquarePoi.Categories.First().ShortName
                : Category;

            if (Provider == null)
            {
                Provider = new SortedSet <string> {
                    Foursquare
                };
            }
            else
            {
                Provider.Add(Foursquare);
            }
        }
Esempio n. 32
0
        public void TestConfigSimpleDatabase()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> {});
            fileSystem.AddDirectory (Database.DefaultConfigDir);

            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add ("FileSystem", fsp);
            var e1 = new Entry (@"c:\dir1\", 12, DateTime.Now, false);
            var e2 = new Entry (@"c:\dir1\file2", 34, DateTime.Now, true);

            fsp.Add(e1);
            fsp.Add(e2);
            db.Save(100);

            var fsFileName = System.IO.Path.Combine (Database.DefaultConfigDir,$"{Database.ConfigFilePrefix}.FileSystem.txt");

            Assert.IsTrue(fileSystem.FileExists(FileSystemConfigPath));
            Assert.AreEqual(
                string.Join(Environment.NewLine,e1.ToString(),e2.ToString(),""),
                fileSystem.File.ReadAllText(fsFileName));
        }
Esempio n. 33
0
        public void TestSaveMaxEntries()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { });
            fileSystem.AddDirectory(Database.DefaultConfigDir);
            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add("FileSystem", fsp);
            fsp.Add(new Entry(@"c:\dir1\", 12, DateTime.Now, false));
            fsp.Add(new Entry(@"c:\dir1\file2", 34, DateTime.Now, true));
            db.Save(1);
            db.Load();

            Assert.AreEqual(1,db.Providers["FileSystem"].Entries.Count);
        }
Esempio n. 34
0
        public void TestGetEntries()
        {
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { });
            fileSystem.AddDirectory(Database.DefaultConfigDir);
            var db = new Database(fileSystem);
            var fsp = new Provider("FileSystem");
            db.Providers.Add("FileSystem", fsp);
            var e1 = new Entry(@"c:\dir1\", 12, DateTime.Now, false);
            var e2 = new Entry(@"c:\dir1\file2", 34, DateTime.Now, true);
            fsp.Add(e1);
            fsp.Add(e2);

            Entry[] entries = null;
            Assert.IsTrue(db.GetEntries("FileSystem", out entries));
            Assert.AreEqual(e2, entries[0]);
            Assert.AreEqual(e1, entries[1]);
        }