Ejemplo n.º 1
0
        public int GetCountByCity(GeoFilter city)
        {
            var temp    = TempData == null ? 0 : TempData.Where(d => d.Person.Location == city).Count();
            var glucose = GlucoseData == null ? 0 : GlucoseData.Where(d => d.Person.Location == city).Count();
            var oxygen  = OxygenData == null ? 0 : OxygenData.Where(d => d.Person.Location == city).Count();
            var hr      = HeartRateData == null ? 0 : HeartRateData.Where(d => d.Person.Location == city).Count();
            int count   = 0;

            if (temp > count)
            {
                count = temp;
            }
            if (glucose > count)
            {
                count = glucose;
            }
            if (oxygen > count)
            {
                count = oxygen;
            }
            if (hr > count)
            {
                count = hr;
            }
            return(count);
        }
Ejemplo n.º 2
0
        public int GetCountByCityState(GeoFilter city, Condition state)
        {
            var temp    = TempData == null ? 0 : TempData.Where(d => d.State == state && d.Person.Location == city).Count();
            var glucose = GlucoseData == null ? 0 : GlucoseData.Where(d => d.State == state && d.Person.Location == city).Count();
            var oxygen  = OxygenData == null ? 0 : OxygenData.Where(d => d.State == state && d.Person.Location == city).Count();
            var hr      = HeartRateData == null ? 0 : HeartRateData.Where(d => d.State == state && d.Person.Location == city).Count();

            return(temp + glucose + oxygen + hr);
        }
        public void GetFilterSerializationTest()
        {
            // Arrange
            var filter = new GeoFilter(34.06021, -118.41828, 5000);

            // Act
            var result = JsonConvert.SerializeObject(filter);

            // Assert
            Assert.AreEqual("{\"$circle\":{\"$center\":[34.06021,-118.41828],\"$meters\":5000}}", result);
        }
Ejemplo n.º 4
0
        public void QueryWithGeoFilter()
        {
            // Arrange
            var filter = new GeoFilter(34.06018, -118.41835, 500);

            // Act
            string  result = Factual.Query("t/global", filter);
            dynamic json   = JsonConvert.DeserializeObject(result);

            // Assert
            Assert.AreEqual("ok", (string)json.status);
        }
Ejemplo n.º 5
0
        public List <Location> GetLocationsByCity(GeoFilter city)
        {
            var list = new List <Location>();

            var temp    = TempData == null ? new List <Measurement>() : TempData.Where(d => d.Person.Location == city);
            var glucose = GlucoseData == null ? new List <Measurement>() : GlucoseData.Where(d => d.Person.Location == city);
            var oxygen  = OxygenData == null ? new List <Measurement>() : OxygenData.Where(d => d.Person.Location == city);
            var hr      = HeartRateData == null ? new List <Measurement>() : HeartRateData.Where(d => d.Person.Location == city);

            list.AddRange(ExtractLocations(temp));
            return(list);
        }
Ejemplo n.º 6
0
        public void GeoAndRowFilterTest()
        {
            // Arrange
            var filter  = new RowFilter("name", "Stand");
            var filter2 = new GeoFilter(34.06018, -118.41835, 5000);

            // Act
            string  result = Factual.Query("t/restaurants", filter, filter2);
            dynamic json   = JsonConvert.DeserializeObject(result);

            // Assert
            Assert.AreEqual("ok", (string)json.status);
        }
Ejemplo n.º 7
0
        public static String Text(this GeoFilter operation)
        {
            switch (operation)
            {
            case GeoFilter.All: return("All");

            case GeoFilter.Boston: return("Boston");

            case GeoFilter.Chicago: return("Chicago");

            case GeoFilter.NewYork: return("New York");

            default:   return("All");
            }
        }
Ejemplo n.º 8
0
        ///GENMHASH:79A840C9F24220C8EF02C0B73BAD3C0F:3586CFD7AEFDBFA89168B9EFC6A2C18C
        private GeoFilter CreateGeoFiltersObject(string relativePath, GeoFilterActions action)
        {
            if (Inner.GeoFilters == null)
            {
                Inner.GeoFilters = new List <GeoFilter>();
            }
            var geoFilter = Inner.GeoFilters
                            .FirstOrDefault(s => s.RelativePath.Equals(
                                                relativePath,
                                                System.StringComparison.OrdinalIgnoreCase));

            if (geoFilter == null)
            {
                geoFilter = new GeoFilter();
            }
            else
            {
                Inner.GeoFilters.Remove(geoFilter);
            }
            geoFilter.RelativePath = relativePath;
            geoFilter.Action       = action;
            return(geoFilter);
        }
Ejemplo n.º 9
0
        internal static CdnEndpointData DeserializeCdnEndpointData(JsonElement element)
        {
            IDictionary <string, string> tags = default;
            AzureLocation                         location                   = default;
            ResourceIdentifier                    id                         = default;
            string                                name                       = default;
            ResourceType                          type                       = default;
            SystemData                            systemData                 = default;
            Optional <string>                     originPath                 = default;
            Optional <IList <string> >            contentTypesToCompress     = default;
            Optional <string>                     originHostHeader           = default;
            Optional <bool>                       isCompressionEnabled       = default;
            Optional <bool>                       isHttpAllowed              = default;
            Optional <bool>                       isHttpsAllowed             = default;
            Optional <QueryStringCachingBehavior> queryStringCachingBehavior = default;
            Optional <OptimizationType?>          optimizationType           = default;
            Optional <string>                     probePath                  = default;
            Optional <IList <GeoFilter> >         geoFilters                 = default;
            Optional <EndpointPropertiesUpdateParametersDefaultOriginGroup> defaultOriginGroup = default;
            Optional <IList <UriSigningKey> > urlSigningKeys = default;
            Optional <EndpointDeliveryPolicy> deliveryPolicy = default;
            Optional <EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink> webApplicationFirewallPolicyLink = default;
            Optional <string> hostName = default;
            Optional <IList <DeepCreatedOrigin> >           origins       = default;
            Optional <IList <DeepCreatedOriginGroup> >      originGroups  = default;
            Optional <IReadOnlyList <CdnCustomDomainData> > customDomains = default;
            Optional <EndpointResourceState>     resourceState            = default;
            Optional <EndpointProvisioningState> provisioningState        = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("originPath"))
                        {
                            originPath = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("contentTypesToCompress"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <string> array = new List <string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            contentTypesToCompress = array;
                            continue;
                        }
                        if (property0.NameEquals("originHostHeader"))
                        {
                            originHostHeader = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("isCompressionEnabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isCompressionEnabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("isHttpAllowed"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isHttpAllowed = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("isHttpsAllowed"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isHttpsAllowed = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("queryStringCachingBehavior"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            queryStringCachingBehavior = property0.Value.GetString().ToQueryStringCachingBehavior();
                            continue;
                        }
                        if (property0.NameEquals("optimizationType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                optimizationType = null;
                                continue;
                            }
                            optimizationType = new OptimizationType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("probePath"))
                        {
                            probePath = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("geoFilters"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <GeoFilter> array = new List <GeoFilter>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(GeoFilter.DeserializeGeoFilter(item));
                            }
                            geoFilters = array;
                            continue;
                        }
                        if (property0.NameEquals("defaultOriginGroup"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                defaultOriginGroup = null;
                                continue;
                            }
                            defaultOriginGroup = EndpointPropertiesUpdateParametersDefaultOriginGroup.DeserializeEndpointPropertiesUpdateParametersDefaultOriginGroup(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("urlSigningKeys"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                urlSigningKeys = null;
                                continue;
                            }
                            List <UriSigningKey> array = new List <UriSigningKey>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(UriSigningKey.DeserializeUriSigningKey(item));
                            }
                            urlSigningKeys = array;
                            continue;
                        }
                        if (property0.NameEquals("deliveryPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                deliveryPolicy = null;
                                continue;
                            }
                            deliveryPolicy = EndpointDeliveryPolicy.DeserializeEndpointDeliveryPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("webApplicationFirewallPolicyLink"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                webApplicationFirewallPolicyLink = null;
                                continue;
                            }
                            webApplicationFirewallPolicyLink = EndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink.DeserializeEndpointPropertiesUpdateParametersWebApplicationFirewallPolicyLink(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("hostName"))
                        {
                            hostName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("origins"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DeepCreatedOrigin> array = new List <DeepCreatedOrigin>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DeepCreatedOrigin.DeserializeDeepCreatedOrigin(item));
                            }
                            origins = array;
                            continue;
                        }
                        if (property0.NameEquals("originGroups"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DeepCreatedOriginGroup> array = new List <DeepCreatedOriginGroup>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DeepCreatedOriginGroup.DeserializeDeepCreatedOriginGroup(item));
                            }
                            originGroups = array;
                            continue;
                        }
                        if (property0.NameEquals("customDomains"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <CdnCustomDomainData> array = new List <CdnCustomDomainData>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(CdnCustomDomainData.DeserializeCdnCustomDomainData(item));
                            }
                            customDomains = array;
                            continue;
                        }
                        if (property0.NameEquals("resourceState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            resourceState = new EndpointResourceState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new EndpointProvisioningState(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new CdnEndpointData(id, name, type, systemData, tags, location, originPath.Value, Optional.ToList(contentTypesToCompress), originHostHeader.Value, Optional.ToNullable(isCompressionEnabled), Optional.ToNullable(isHttpAllowed), Optional.ToNullable(isHttpsAllowed), Optional.ToNullable(queryStringCachingBehavior), Optional.ToNullable(optimizationType), probePath.Value, Optional.ToList(geoFilters), defaultOriginGroup.Value, Optional.ToList(urlSigningKeys), deliveryPolicy.Value, webApplicationFirewallPolicyLink.Value, hostName.Value, Optional.ToList(origins), Optional.ToList(originGroups), Optional.ToList(customDomains), Optional.ToNullable(resourceState), Optional.ToNullable(provisioningState)));
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            bool _isRemove  = false,
                 _isCreate  = false;
            string _geoPath = String.Empty,
                   _geoLock = String.Empty;

            stGeo.GeoFilter          _geof    = null;
            stCore.IniConfig.IniFile _iniFile = null;
            stCore.IMessage          _iLog    = null;
            GeoUpdateMain.rootAppPath = stCore.IOBaseAssembly.BaseDataDir();

            Thread.CurrentThread.Name = stCore.IOBaseAssembly.BaseName(Assembly.GetExecutingAssembly());

            args.Process(
                () => { },
                new CommandLine.Switch("geodir", val => _geoPath             = string.Join("", val), "-d"),
                new CommandLine.Switch("clear", val => _isRemove             = true, "-c"),
                new CommandLine.Switch("create", val => _isCreate            = true, "-a"),
                new CommandLine.Switch("quiet", val => GeoUpdateMain.isQuiet = true, "-q")
                );

            if (GeoUpdateMain.isQuiet)
            {
                _iLog = new IMessage();
            }
            else
            {
                _iLog = new IMessage()
                {
                    LogInfo     = GeoUpdateMain.PrnInfo,
                    LogError    = GeoUpdateMain.PrnError,
                    ProgressBar = stConsole.ProgressTxt
                };
                string AppDesc = IOBaseAssembly.BaseDescription(Assembly.GetExecutingAssembly());
                stApp.AppInformation.PrnBanner(
                    new string[] {
                    string.Format(
                        "{0}: {1}",
                        Thread.CurrentThread.Name,
                        ((string.IsNullOrWhiteSpace(AppDesc)) ? "" : AppDesc)
                        ),
                    Properties.Resources.banRun
                }
                    );
            }
            try
            {
                if (string.IsNullOrWhiteSpace(_geoPath))
                {
                    try
                    {
                        string iniPath = Path.Combine(
                            GeoUpdateMain.rootAppPath,
                            "stCoCServer.ini"
                            );
                        if (!File.Exists(iniPath))
                        {
                            throw new FileNotFoundException(
                                      string.Format(
                                          Properties.Resources.GeoIniNotFound,
                                          iniPath
                                          )
                                      );
                        }
                        _iniFile = new stCore.IniConfig.IniFile(iniPath);
                        if (_iniFile == null)
                        {
                            throw new FileLoadException(
                                      string.Format(
                                          Properties.Resources.GeoInErrorLoad,
                                          iniPath
                                          )
                                      );
                        }
                        string lng = _iniFile.Section("SYS").Get("SYSLANGConsole");
                        if (!string.IsNullOrWhiteSpace(lng))
                        {
                            try
                            {
                                CultureInfo ci = null;
                                if ((ci = CultureInfo.GetCultureInfo(lng)) != null)
                                {
                                    System.Threading.Thread.CurrentThread.CurrentCulture   = ci;
                                    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        _geoPath = _iniFile.Section("SYS").Get("SYSGEOPath");
                        if (_geoPath == null)
                        {
                            throw new ArgumentNullException(Properties.Resources.GeoConfigNotFound);
                        }
                    }
                    catch (Exception e)
                    {
                        _geoPath = Path.Combine(
                            GeoUpdateMain.rootAppPath,
                            "geo"
                            );
                        if (!Directory.Exists(_geoPath))
                        {
                            _iLog.LogError(e.Message);
                            return;
                        }
                    }
                    finally
                    {
                        if (_iniFile != null)
                        {
                            _iniFile.Clear();
                        }
                    }
                }
                if (!Directory.Exists(_geoPath))
                {
                    if (_isCreate)
                    {
                        Directory.CreateDirectory(_geoPath);
                    }
                    else
                    {
                        throw new DirectoryNotFoundException(Properties.Resources.GeoDirNotFound);
                    }
                }

                string[] allFiles = GeoUpdateMain.MakeFileList(_geoPath);

                if (_isRemove)
                {
                    foreach (string fn in allFiles)
                    {
                        if (File.Exists(fn))
                        {
                            File.Delete(fn);
                        }
                    }
                }
                if (
                    (!File.Exists(allFiles[0])) &&
                    (!File.Exists(allFiles[1]))
                    )
                {
                    if (!GeoUpdateMain.GetUrlToFile(
                            stGeo.MaxMindUtil.MaxMindDownloadASNURL,
                            stGeo.MaxMindUtil.GetASNZipFileName,
                            _geoPath,
                            _iLog)
                        )
                    {
                        throw new FileNotFoundException(Properties.Resources.GeoFileNotFound);
                    }
                }
                if (
                    (!File.Exists(allFiles[2])) &&
                    (!File.Exists(allFiles[3]))
                    )
                {
                    if (!GeoUpdateMain.GetUrlToFile(
                            stGeo.MaxMindUtil.MaxMindDownloadCountryURL,
                            stGeo.MaxMindUtil.GetCountryZipFileName,
                            _geoPath,
                            _iLog)
                        )
                    {
                        throw new FileNotFoundException(Properties.Resources.GeoFileNotFound);
                    }
                }
                if (File.Exists(allFiles[4]))
                {
                    File.Delete(allFiles[4]);
                }
                _geof = new GeoFilter(_iLog, false);
                if (_geof == null)
                {
                    throw new ArgumentNullException(Properties.Resources.GeoClassInitError);
                }

                _geoLock = Path.Combine(_geoPath, MaxMindUtil.GetGeoDataLockFileName);
                File.Create(_geoLock);

                if (!_geof.InitBase(_geoPath, false, stConsole.GetCursorAlign(2)))
                {
                    GeoUpdateMain.PrnError(Properties.Resources.GeoClassInitError);
                }
                else
                {
                    GeoUpdateMain.PrnInfo(
                        string.Format(
                            Properties.Resources.GeoComplette,
                            _geoPath
                            )
                        );
                }
            }
            catch (Exception e)
            {
                GeoUpdateMain.PrnError(e.Message);
            }
            finally
            {
                try
                {
                    if (_geof != null)
                    {
                        _geof.Dispose();
                    }
                    if (
                        (!string.IsNullOrWhiteSpace(_geoLock)) &&
                        (File.Exists(_geoLock))
                        )
                    {
                        File.Delete(_geoLock);
                        string geoDb = Path.Combine(_geoPath, MaxMindUtil.GetGeoDataFileName);
                        if (File.Exists(geoDb))
                        {
                            File.SetCreationTime(geoDb, DateTime.Now);
                        }
                    }
                }
                catch (Exception e)
                {
                    GeoUpdateMain.PrnError(e.Message);
                }
            }
#if DEBUG
            Console.ReadLine();
#endif
            return;
        }
Ejemplo n.º 11
0
 public void onGeoFilterChanged(Dropdown dropdown)
 {
     geoFilter = (GeoFilter)dropdown.value;
 }