public async Task <AdapterServer> FindASAsync(string name)
        {
            AdapterServer ret = null;

            using (var client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri(ConfigHelper.GetServiceUrl("centralserver"));
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = await client.GetAsync($"api/central/adapterserver?name={name}");

                    if (response.IsSuccessStatusCode)
                    {
                        ret = await response.Content.ReadAsAsync <AdapterServer>();
                    }
                }
                catch (Exception ex)
                {
                    throw new BeContractException("Error with Central Service when finding the AdapterServer: " + ex.Message);
                }
            }

            return(ret);
        }
        public async Task <BeContractReturn> CallAsync(AdapterServer ads, BeContractCall call)
        {
            BeContractReturn res = null;

            using (var client = new HttpClient())
            {
                try
                {
                    //Use the ads.Url as baseaddress, don't send this to Be-Road !
                    client.BaseAddress = new Uri(ads.Url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    var httpContent = new StringContent(JsonConvert.SerializeObject(call), Encoding.UTF8, "application/json");
                    HttpResponseMessage response = await client.PostAsync(ads.Root + "/" + call.Id, httpContent);

                    if (response.IsSuccessStatusCode)
                    {
                        res = await response.Content.ReadAsAsync <BeContractReturn>();
                    }
                }
                catch (Exception ex)
                {
                    throw new BeContractException("Cannot call the Adapter Server: " + ex.Message);
                }
            }

            return(res);
        }
Beispiel #3
0
        public async Task <ActionResult> Save(AdapterServer ads)
        {
            var newAds = ctx.AdapterServers.FirstOrDefault(a => a.ISName == ads.ISName);

            if (newAds != null)
            {
                newAds.Url  = ads.Url;
                newAds.Root = ads.Root;
                if (ads.ContractNames.Count > newAds.ContractNames.Count)
                {
                    ads.ContractNames.ForEach(cn => {
                        newAds.ContractNames.Add(ctx.Contracts.FirstOrDefault(c => c.Id.Equals(cn.Id)));
                    });
                }
                if (ads.ContractNames.Count < newAds.ContractNames.Count)
                {
                    newAds.ContractNames.Clear();
                    ads.ContractNames.ForEach(cn => {
                        var contract = ctx.Contracts.FirstOrDefault(c => c.Id.Equals(cn.Id));
                        newAds.ContractNames.Add(contract);
                    });
                }
                ctx.SaveChanges();
                await CallToMLAsync(new { UserName = newAds.ISName, UserType = "TEMP" }, "api/AdapterServer/Update");

                return(Json("OK"));
            }
            else
            {
                return(Json("Cannot edit this Adapter Server !"));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Find an adapter server with the name of the contract used
        /// </summary>
        /// <param name="name">The name of the contract used</param>
        /// <returns>The found adapter server</returns>
        public async Task <AdapterServer> FindASAsync(string name)
        {
            AdapterServer ads = null;
            await Task.Run(() => ads = ADSList.FirstOrDefault(s => s.ContractNames.Any(cn => cn.Id.Equals(name))));

            return(ads);
        }
Beispiel #5
0
        public async Task <BeContractReturn> CallAsync(AdapterServer ads, BeContractCall call)
        {
            //Empty await for the method
            await Task.Run(() => { });

            switch (call.Id)
            {
            case "GetOwnerIdByDogId": return(HandleGetOwnerIdByDogId(call));

            default: return(new BeContractReturn());
            }
        }
Beispiel #6
0
        public async Task <BeContractReturn> CallAsync(AdapterServer ads, BeContractCall call)
        {
            BeContractReturn ret = null;
            await Task.Run(() =>
            {
                switch (ads.ISName)
                {
                case "Doggies": ret = VeterinaryMock.GetOwnerId(call); break;

                case "MathLovers": ret = MathematicsMock.GetSumFunction(call); break;

                case "CitizenDatabank": ret = AddressMock.GetAddressByOwnerId(call); break;

                default: ret = new BeContractReturn(); break;
                }
            });

            return(ret);
        }
Beispiel #7
0
        public async Task <ActionResult> Create(AdapterServer ads)
        {
            if (ads.ISName == null || ads.Root == null || ads.Url == null)
            {
                ViewBag.Error = "You must fill all inputs !";
                return(View("Create"));
            }
            if (ctx.AdapterServers.Any(a => a.ISName == ads.ISName))
            {
                ViewBag.Error = "This Adapter Server already exists !";
                return(View("Create"));
            }
            else
            {
                ctx.AdapterServers.Add(ads);
                ctx.SaveChanges();
                await CallToMLAsync(new { UserName = ads.ISName, UserType = "TEMP" }, "api/AdapterServer/Add");

                ViewBag.Message = "Adapter Server successfully added !";
                return(View("Create"));
            }
        }
Beispiel #8
0
        private void PrivacyPassportADSSeed(ContractContext context)
        {
            var ads1 = new AdapterServer()
            {
                Id            = 4,
                ContractNames = new List <BeContract>()
                {
                    context.Contracts.FirstOrDefault(c => c.Id.Equals("GetBankContract"))
                },
                ISName = "Bank Service",
                Url    = "http://adsmock/",
                Root   = "api/bank"
            };
            var ads2 = new AdapterServer()
            {
                Id            = 5,
                ContractNames = new List <BeContract>()
                {
                    context.Contracts.FirstOrDefault(c => c.Id.Equals("GetDivContract"))
                },
                ISName = "Div Service",
                Url    = "http://adsmock/",
                Root   = "api/div"
            };
            var ads3 = new AdapterServer()
            {
                Id            = 6,
                ContractNames = new List <BeContract>()
                {
                    context.Contracts.FirstOrDefault(c => c.Id.Equals("GetPopulationContract"))
                },
                ISName = "Population Service",
                Url    = "http://adsmock/",
                Root   = "api/population"
            };
            var ads4 = new AdapterServer()
            {
                Id            = 6,
                ContractNames = new List <BeContract>()
                {
                    context.Contracts.FirstOrDefault(c => c.Id.Equals("GetFunnyContract"))
                },
                ISName = "Funny Service",
                Url    = "http://adsmock/",
                Root   = "api/funny"
            };

            var ads1db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads1.ISName);
            var ads2db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads2.ISName);
            var ads3db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads3.ISName);
            var ads4db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads4.ISName);

            if (ads1db != null)
            {
                context.AdapterServers.Remove(ads1db);
            }
            if (ads2db != null)
            {
                context.AdapterServers.Remove(ads2db);
            }
            if (ads3db != null)
            {
                context.AdapterServers.Remove(ads3db);
            }
            if (ads4db != null)
            {
                context.AdapterServers.Remove(ads3db);
            }

            context.AdapterServers.Add(ads1);
            context.AdapterServers.Add(ads2);
            context.AdapterServers.Add(ads3);
            context.AdapterServers.Add(ads4);
            context.SaveChanges();
        }
Beispiel #9
0
        private void ADSSeed(ContractContext context)
        {
            var cn1 = new List <BeContract>
            {
                context.Contracts.FirstOrDefault(c => c.Id.Equals("GetOwnerIdByDogId")),
                context.Contracts.FirstOrDefault(c => c.Id.Equals("GetAddressByOwnerId")),
                context.Contracts.FirstOrDefault(c => c.Id.Equals("GetAddressByDogId")),
                context.Contracts.FirstOrDefault(c => c.Id.Equals("GetServiceInfo"))
            };

            var cn2 = new List <BeContract>
            {
                context.Contracts.FirstOrDefault(c => c.Id.Equals("GetMathemathicFunction"))
            };

            var cn3 = new List <BeContract>
            {
                context.Contracts.FirstOrDefault(c => c.Id.Equals("DoubleInputContract"))
            };

            var ads1 = new AdapterServer()
            {
                Id            = 1,
                ContractNames = cn1,
                ISName        = "Doggie style",
                Url           = "http://adsmock/",
                Root          = "api/read"
            };
            var ads2 = new AdapterServer()
            {
                Id            = 2,
                ContractNames = cn2,
                ISName        = "MathLovers",
                Url           = "http://adsmock/",
                Root          = "api/read"
            };
            var ads3 = new AdapterServer()
            {
                Id            = 3,
                ContractNames = cn3,
                ISName        = "CitizenDatabank",
                Url           = "http://adsmock/",
                Root          = "api/read"
            };

            var ads1db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads1.ISName);
            var ads2db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads2.ISName);
            var ads3db = context.AdapterServers.FirstOrDefault(ads => ads.ISName == ads3.ISName);

            if (ads1db != null)
            {
                context.AdapterServers.Remove(ads1db);
            }

            if (ads2db != null)
            {
                context.AdapterServers.Remove(ads2db);
            }

            if (ads3db != null)
            {
                context.AdapterServers.Remove(ads3db);
            }

            //if (!System.Diagnostics.Debugger.IsAttached)
            //    System.Diagnostics.Debugger.Launch();

            context.AdapterServers.Add(ads1);
            context.AdapterServers.Add(ads2);
            context.AdapterServers.Add(ads3);
            context.SaveChanges();
        }