Exemplo n.º 1
0
        public List <MunicipalityViewModel> GetListOfMunicipalityOrganizations()
        {
            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("municipalityorganizations");

            List <MunicipalityViewModel> Organizations = new List <MunicipalityViewModel>();

            if (cache != null)
            {
                Organizations = cache as List <MunicipalityViewModel>;
            }

            if (Organizations.Count < 1)
            {
                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var     json   = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/v2/organisasjoner/kommuner");
                dynamic result = Newtonsoft.Json.Linq.JArray.Parse(json);

                if (result != null)
                {
                    foreach (var item in result)
                    {
                        Organizations.Add(
                            new MunicipalityViewModel
                        {
                            Name = item.Name,
                            OrganizationNumber = item.OrganizationNumber,
                            MunicipalityCode   = item.MunicipalityCode,
                            BoundingBoxEast    = item.BoundingBoxEast,
                            BoundingBoxNorth   = item.BoundingBoxNorth,
                            BoundingBoxSouth   = item.BoundingBoxSouth,
                            BoundingBoxWest    = item.BoundingBoxWest,
                            GeographicCenterX  = item.GeographicCenterX,
                            GeographicCenterY  = item.GeographicCenterY
                        });
                    }
                }

                Organizations = Organizations.OrderBy(o => o.Name).ToList();
                memCacher.Set("municipalityorganizations", Organizations, new DateTimeOffset(DateTime.Now.AddYears(1)));
            }

            return(Organizations);
        }
Exemplo n.º 2
0
        public List<MunicipalityViewModel> GetListOfMunicipalityOrganizations()
        {
            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("municipalityorganizations");

            List<MunicipalityViewModel> Organizations = new List<MunicipalityViewModel>();

            if (cache != null)
            {
                Organizations = cache as List<MunicipalityViewModel>;
            }

            if (Organizations.Count < 1)
            {
                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var json = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/v2/organisasjoner/kommuner");
                dynamic result = Newtonsoft.Json.Linq.JArray.Parse(json);

                if (result != null)
                {
                    foreach (var item in result)
                    {
                        Organizations.Add(
                            new MunicipalityViewModel
                            {
                                Name = item.Name,
                                OrganizationNumber = item.OrganizationNumber,
                                MunicipalityCode = item.MunicipalityCode,
                                BoundingBoxEast = item.BoundingBoxEast,
                                BoundingBoxNorth = item.BoundingBoxNorth,
                                BoundingBoxSouth = item.BoundingBoxSouth,
                                BoundingBoxWest = item.BoundingBoxWest,
                                GeographicCenterX = item.GeographicCenterX,
                                GeographicCenterY = item.GeographicCenterY
                            });
                    }
                }
            }

            Organizations = Organizations.OrderBy(o => o.Name).ToList();
            memCacher.Add("municipalityorganizations", Organizations, new DateTimeOffset(DateTime.Now.AddYears(1)));

            return Organizations;
        }
        public Dictionary<string, string> GetListOfOrganizations()
        {
            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("organizations");

            Dictionary<string, string> Organizations = new Dictionary<string, string>();

            if (cache != null)
            {
                Organizations = cache as Dictionary<string, string>;
            }

            if (Organizations.Count < 1)
            {
                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/register/organisasjoner");
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var orgs = response["containeditems"];

                foreach (var org in orgs)
                {
                    if (!Organizations.ContainsKey(org["label"].ToString()))
                    {
                        Organizations.Add(org["label"].ToString(), org["label"].ToString());
                    }
                }
            }
            Organizations = Organizations.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);
            memCacher.Add("organizations", Organizations, new DateTimeOffset(DateTime.Now.AddYears(1)));

            return Organizations;
        }
        public Dictionary<string, string> GetCodeList(string systemid)
        {
            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue(systemid);

            Dictionary<string, string> CodeValues = new Dictionary<string, string>();

            if (cache != null)
            {
                CodeValues = cache as Dictionary<string, string>;
            }

            if (CodeValues.Count < 1)
            {
                string url = System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/kodelister/" + systemid;
                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data = c.DownloadString(url);
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var codeList = response["containeditems"];

                foreach (var code in codeList)
                {
                    JToken codevalueToken = code["codevalue"];
                    string codevalue = codevalueToken?.ToString();

                    if (string.IsNullOrWhiteSpace(codevalue))
                        codevalue = code["label"].ToString();

                    if (!CodeValues.ContainsKey(codevalue))
                    {
                        CodeValues.Add(codevalue, code["label"].ToString());
                    }
                }
            }
            CodeValues = CodeValues.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);
            memCacher.Add(systemid, CodeValues, new DateTimeOffset(DateTime.Now.AddYears(1)));

            return CodeValues;
        }
        public Dictionary<string, string> GetSubRegister(string registername, MetadataViewModel model)
        {
            string role = GetSecurityClaim("role");

            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("subregisteritem");

            Dictionary<string, string> RegisterItems = new Dictionary<string, string>();

            if (cache != null)
            {
                RegisterItems = cache as Dictionary<string, string>;
            }

            if (RegisterItems.Count < 1)
            {

                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/subregister/" + registername);
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var items = response["containeditems"];

                foreach (var item in items)
                {
                    var id = item["id"].ToString();
                    var owner = item["owner"].ToString();
                    string organization = item["owner"].ToString();

                    if (!RegisterItems.ContainsKey(id))
                    {
                        if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin") || model.HasAccess(organization))
                            RegisterItems.Add(id, item["label"].ToString());
                    }
                }
            }

            RegisterItems = RegisterItems.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);
            memCacher.Add("subregisteritem", RegisterItems, new DateTimeOffset(DateTime.Now.AddYears(1)));

            return RegisterItems;
        }
        public Dictionary<string, string> GetListOfReferenceSystems()
        {
            MemoryCacher memCacher = new MemoryCacher();

            var cache = memCacher.GetValue("referencesystems");

            Dictionary<string, string> ReferenceSystems = new Dictionary<string, string>();

            if (cache != null)
            {
                ReferenceSystems = cache as Dictionary<string, string>;
            }

            if (ReferenceSystems.Count < 1)
            {

                System.Net.WebClient c = new System.Net.WebClient();
                c.Encoding = System.Text.Encoding.UTF8;
                var data = c.DownloadString(System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"] + "api/register/epsg-koder");
                var response = Newtonsoft.Json.Linq.JObject.Parse(data);

                var refs = response["containeditems"];

                foreach (var refsys in refs)
                {

                    var documentreference = refsys["documentreference"].ToString();
                    if (!ReferenceSystems.ContainsKey(documentreference))
                    {
                        ReferenceSystems.Add(documentreference, refsys["label"].ToString());
                    }
                }
            }

            ReferenceSystems = ReferenceSystems.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);
            memCacher.Add("referencesystems", ReferenceSystems, new DateTimeOffset(DateTime.Now.AddYears(1)));

            return ReferenceSystems;
        }
 public ActionResult FlushCache()
 {
     MemoryCacher memCacher = new MemoryCacher();
     memCacher.DeleteAll();
     return new HttpStatusCodeResult(HttpStatusCode.OK);
 }