public OsmApi() { var clientFactory = new ClientsFactory(null, new HttpClient(), "https://www.openstreetmap.org/api/"); _client = clientFactory.CreateNonAuthClient(); }
public OsmApiEnder(ILogger logger, string baseAddress, string userName, string password, TagsCollectionBase tags) { var factory = new ClientsFactory(logger, new HttpClient(), baseAddress); Client = factory.CreateBasicAuthClient(userName, password); Tags = tags; }
/// <summary> /// Contract_List页面行为 /// </summary> /// <returns>视图</returns> public ActionResult Contract_List() { //获取往来客户信息 ClientsFactory clientsfactory = new ClientsFactory(); List <IClientsB> lstclients = clientsfactory.GetDataClients(); List <ClientsM> clientsm = new List <ClientsM>(); if (lstclients != null && lstclients.Count > 0) { lstclients.ForEach(p => clientsm.Add(p.Infomation_clients)); } ViewBag.ClientsInfo = clientsm; //获取项目信息 ProjectsFactory projectsfactory = new ProjectsFactory(); List <IProjectsB> lstprojects = projectsfactory.GetDataProjects(); List <ProjectsM> projectsm = new List <ProjectsM>(); if (lstprojects != null && lstprojects.Count > 0) { lstprojects.ForEach(p => projectsm.Add(p.Infomation_projects)); } ViewBag.ProjectsInfo = projectsm; //获取合同信息 string id = ViewMethods.GetForm(Request, "ID", CommonEnums.ValueEnum.vlGet).ToString(); ContractFactory contractfactory = new ContractFactory(); IContractB lstContract = contractfactory.GetDataByID(id); ContractM contractm = (lstContract != null ? lstContract.Infomation_contract : null); ViewBag.ContractInfo = contractm; return(View()); }
public void TestInitialize() { using var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var logger = loggerFactory.CreateLogger("Tests"); var clientFactory = new ClientsFactory(logger, new HttpClient(), "https://master.apis.dev.openstreetmap.org/api/"); client = clientFactory.CreateNonAuthClient(); }
/// <summary> /// Projects_List页面 /// </summary> /// <returns>页面</returns> public ActionResult Projects_List() { //获取项目编号(id)数据信息 string id = ViewMethods.GetForm(Request, "PRID", CommonEnums.ValueEnum.vlGet).ToString(); //根据项目编号(id)获取项目信息 ProjectsFactory projectsfactory = new ProjectsFactory(); IProjectsB lstProjects = projectsfactory.GetDataByID(id); ProjectsM projectsm = (lstProjects != null ? lstProjects.Infomation_projects : null); ViewBag.ProjectsInfo = projectsm; //获取往来客户信息 ClientsFactory clientsFactory = new ClientsFactory(); List <IClientsB> lstClients = clientsFactory.GetDataClients(); List <ClientsM> clientsm = new List <ClientsM>(); if (lstClients != null && lstClients.Count > 0) { lstClients.ForEach(p => clientsm.Add(p.Infomation_clients)); } ViewBag.ClientsInfo = clientsm; //获取收付款信息 FinanceFactory financeFactory = new FinanceFactory(); List <IFinanceB> lstFinance = financeFactory.GetDataFinance(); List <FinanceM> financem = new List <FinanceM>(); if (lstFinance != null && lstFinance.Count > 0) { lstFinance.ForEach(p => financem.Add(p.Infomation_finance)); } ViewBag.FinanceInfo = financem; //获取工程量信息 QuantityFactory quantityFactory = new QuantityFactory(); List <IQuantityB> lstQuantity = quantityFactory.GetDataQuantity(); List <QuantityM> quantity = new List <QuantityM>(); if (lstQuantity != null && lstQuantity.Count > 0) { lstQuantity.ForEach(p => quantity.Add(p.Infomation_Quantity)); } ViewBag.QuantityInfo = quantity; //获取合同信息 ContractFactory contractFactory = new ContractFactory(); List <IContractB> lstContract = contractFactory.GetDataContract(); List <ContractM> contracts = new List <ContractM>(); if (lstContract != null && lstContract.Count > 0) { lstContract.ForEach(p => contracts.Add(p.Infomation_contract)); } ViewBag.ContractInfo = contracts; return(View()); }
public void TestInitialize() { using var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var logger = loggerFactory.CreateLogger("Tests"); var clientFactory = new ClientsFactory(logger, new HttpClient(), "https://master.apis.dev.openstreetmap.org/api/"); // Enter your user name and password here or OAuth credential below - do not check-in! client = clientFactory.CreateBasicAuthClient("user-email", "password"); //client = clientFactory.CreateOAuthClient("customerkey", "customerSecret", "token", "tokenSecret"); }
/// <summary> /// Clients_List页面行为 /// </summary> /// <returns>视图</returns> public ActionResult Clients_List() { //获取客户用户(id)数据信息 string id = ViewMethods.GetForm(Request, "ID", CommonEnums.ValueEnum.vlGet).ToString(); ClientsFactory clientsfactory = new ClientsFactory(); IClientsB lstClients = clientsfactory.GetDataByID(id); ClientsM clientsm = (lstClients != null ? lstClients.Infomation_clients : null); ViewBag.ClientsInfo = clientsm; return(View()); }
public ActionResult Clients() { int pageSize = 12; //每页要显示的行数 string orderby = ViewMethods.GetForm(Request, "OrderBy", CommonEnums.ValueEnum.vlGet); string belong = ViewMethods.GetForm(Request, "BELONG"); if (string.IsNullOrEmpty(orderby)) { orderby = "CL_ID"; } int desc = ViewMethods.GetForm(Request, "Desc", CommonEnums.ValueEnum.vlGet).ConvertToInt32(); int pagecurrent = ViewMethods.GetForm(Request, "Page", CommonEnums.ValueEnum.vlGet).ConvertToInt32();//分页 pagecurrent = (pagecurrent == 0 ? 1 : pagecurrent); object objkeys = ViewMethods.GetForm(Request, "keys", CommonEnums.ValueEnum.vlGet);//搜索内容 string keys = ""; if (objkeys != null) { keys = objkeys.ToString(); } long start = (pagecurrent - 1) * pageSize; string order = orderby; OrderType orderway = (desc == 0 ? OrderType.otDesc : OrderType.otAsc); long count = 0; ClientsFactory clientsfactory = new ClientsFactory(); List <IClientsB> lstclients = clientsfactory.GetPageData(ref count, start, pageSize, keys, order, orderway, belong); List <ClientsM> clientsinfo = new List <ClientsM>(); if (lstclients != null && lstclients.Count > 0) { lstclients.ForEach(p => clientsinfo.Add(p.Infomation_clients)); } int totalpages = 0; if ((count % pageSize) > 0) { totalpages = (int)Math.Ceiling((float)((count / pageSize) + 1)); } else { totalpages = (int)Math.Ceiling((float)(count / pageSize));//算出分页的总数 } ViewBag.TotalPages = totalpages; ViewBag.ClientsInfo = clientsinfo; TempData["OrderBy"] = desc; TempData["CurrentPage"] = pagecurrent; TempData["keys"] = objkeys; TempData["belong"] = belong; return(View()); }
/// <summary> /// Projects_Add页面行为 /// </summary> /// <returns>视图</returns> public ActionResult Projects_Add() { //获取往来客户信息 ClientsFactory clientsFactory = new ClientsFactory(); List <IClientsB> lstClients = clientsFactory.GetDataClients(); List <ClientsM> ClientsInfo = new List <ClientsM>(); lstClients.ForEach(p => ClientsInfo.Add(p.Infomation_clients)); TempData["ClientsInfo"] = ClientsInfo; return(View()); }
/// <summary> /// 编辑客户信息(Clients_Edit页面) /// </summary> public ActionResult Edit_Clients() { ClientsFactory clientsfactory = new ClientsFactory(); //获取客户编号(id)信息 string id = ViewMethods.GetForm(Request, "ID", CommonEnums.ValueEnum.vlGet).ToString(); IClientsB clientsb = clientsfactory.GetDataByID(id); ClientsM clientsm = (clientsb == null ? null : clientsb.Infomation_clients); //编辑客户信息 string clientsname = ViewMethods.GetForm(Request, "name", CommonEnums.ValueEnum.vlPost).ToString(); string clientsbelong = ViewMethods.GetForm(Request, "belong", CommonEnums.ValueEnum.vlPost).ToString(); string clientsperson = ViewMethods.GetForm(Request, "person", CommonEnums.ValueEnum.vlPost).ToString(); string clientstel = ViewMethods.GetForm(Request, "tel", CommonEnums.ValueEnum.vlPost).ToString(); string clientsaddress = ViewMethods.GetForm(Request, "address", CommonEnums.ValueEnum.vlPost).ToString(); string clientscode = ViewMethods.GetForm(Request, "code", CommonEnums.ValueEnum.vlPost).ToString(); string clientsbank = ViewMethods.GetForm(Request, "bank", CommonEnums.ValueEnum.vlPost).ToString(); string clientsaccount = ViewMethods.GetForm(Request, "account", CommonEnums.ValueEnum.vlPost).ToString(); bool isExist = clientsfactory.IsExist_clientsname(clientsname, id); if (isExist) { return(ViewMethods.AlertBack("客户已存在,请重新确认", "-1")); } if (clientsname == "") { return(ViewMethods.AlertBack("名称不能为空", "-1")); } clientsm.CLNAME = clientsname; clientsm.CLBELONG = clientsbelong.ConvertToInt32(); clientsm.CLPERSON = clientsperson; clientsm.CLTEL = clientstel; clientsm.CLADDRESS = clientsaddress; clientsm.CLCODE = clientscode; clientsm.CLBANK = clientsbank; clientsm.CLACCOUNT = clientsaccount; clientsfactory.Infomation_clients = clientsm; ViewBag.ClientsInfo = clientsm; bool isSuccess = clientsfactory.Update(); if (isSuccess) { return(ViewMethods.AlertBack("修改成功", "../../Clients/Clients?BELONG=" + clientsbelong)); } else { return(ViewMethods.AlertBack("修改失败", "-1")); } }
/// <summary> /// 删除客户信息(Clients页面) /// </summary> /// <returns></returns> public ActionResult Delete_Clients() { //获取客户编号(id)信息 string uid = ViewMethods.GetForm(Request, "uid", CommonEnums.ValueEnum.vlPost).ToString(); ClientsM clientsm = new ClientsM(); clientsm.CLID = uid.ConvertToInt32(); ClientsFactory clientsfactory = new ClientsFactory(); clientsfactory.Infomation_clients = clientsm; clientsfactory.Del_Clients(); return(new JsonResult() { Data = PublicMethods.JSonHelper <string> .ObjectToJson(new { status = "0", msg = "删除成功" }), ContentType = "json" }); }
static Global() { var clients = new Clients(); clients.Initialize(ClientsFactory.CreateClient(BoundedContextsContainer.Foundation, (viewStore, sender) => new SimpleClient <IFoundationCommand>(viewStore, sender), AttributesFactory)); clients.Initialize(ClientsFactory.CreateClient(BoundedContextsContainer.Channels, (viewStore, sender) => new SimpleClient <IChannelsCommand>(viewStore, sender), AttributesFactory)); clients.Initialize(ClientsFactory.CreateClient(BoundedContextsContainer.Data, (viewStore, sender) => new SimpleClient <IDataCommand>(viewStore, sender), AttributesFactory)); clients.Initialize(ClientsFactory.CreateClient(BoundedContextsContainer.Inventory, (viewStore, sender) => new SimpleClient <IInventoryCommand>(viewStore, sender), AttributesFactory)); clients.Initialize(ClientsFactory.CreateClient(BoundedContextsContainer.Receiving, (viewStore, sender) => new SimpleClient <IReceivingCommand>(viewStore, sender), AttributesFactory)); Foundation = clients.Foundation; Channels = clients.Channels; Data = clients.Data; Inventory = clients.Inventory; Receiving = clients.Receiving; }
public void SaveCredit_BankCredit() { // ПРОВЕРЯЕТ НА ВХОЖДЕНИЕ ПОСЛЕ ДОБАВЛЕНИЯ // инициализация var input = ClientsFactory.GetCredit("кр", 1, 1, 1, 0, "цель"); // выполнение SaveCredit SC = new SaveCredit(); RepositoryFake RF = new RepositoryFake(); bool rez = SC.Save(input, RF); // сравнение if (RF.CurrentList.FirstOrDefault() != input) { Assert.Fail(); } //Assert.AreEqual(true, rez); }
public static async Task CreateChange(IEnumerable <OsmGeo> objectsToUpdate) { var clientFactory = new ClientsFactory(null, new HttpClient(), "https://www.openstreetmap.org/api/"); var client = clientFactory.CreateBasicAuthClient("EtymologyWikidataBot", Passwords.WikidataBotPassword); var changeSetTags = new TagsCollection { new Tag("comment", "Add name:etymology:wikidata"), new Tag("created_by", "PieterVdvn's OSM BOT") }; var changeSetId = await client.CreateChangeset(changeSetTags); foreach (var obj in objectsToUpdate) { obj.Version = await client.UpdateElement(changeSetId, obj); } await client.CloseChangeset(changeSetId); }
/// <summary> /// 添加客户信息(Clients_Add页面) /// </summary> public ActionResult Add_Clients() { string id = ""; ClientsFactory clientsfactory = new ClientsFactory(); //添加客户信息 ClientsM clientsm = new ClientsM(); string clientsname = ViewMethods.GetForm(Request, "name", CommonEnums.ValueEnum.vlPost).ToString(); string clientsbelong = ViewMethods.GetForm(Request, "belong", CommonEnums.ValueEnum.vlPost).ToString(); string clientsperson = ViewMethods.GetForm(Request, "person", CommonEnums.ValueEnum.vlPost).ToString(); string clientstel = ViewMethods.GetForm(Request, "tel", CommonEnums.ValueEnum.vlPost).ToString(); string clientsaddress = ViewMethods.GetForm(Request, "address", CommonEnums.ValueEnum.vlPost).ToString(); string clientscode = ViewMethods.GetForm(Request, "code", CommonEnums.ValueEnum.vlPost).ToString(); string clientsbank = ViewMethods.GetForm(Request, "bank", CommonEnums.ValueEnum.vlPost).ToString(); string clientsaccount = ViewMethods.GetForm(Request, "account", CommonEnums.ValueEnum.vlPost).ToString(); bool isExist = clientsfactory.IsExist_clientsname(clientsname, id); if (isExist) { return(ViewMethods.AlertBack("客户已存在,请重新确认", "-1")); } if (clientsname == "") { return(ViewMethods.AlertBack("名称不能为空", "-1")); } clientsm.CLNAME = clientsname; clientsm.CLBELONG = clientsbelong.ConvertToInt32(); clientsm.CLPERSON = clientsperson; clientsm.CLTEL = clientstel; clientsm.CLADDRESS = clientsaddress; clientsm.CLCODE = clientscode; clientsm.CLBANK = clientsbank; clientsm.CLACCOUNT = clientsaccount; clientsfactory.Infomation_clients = clientsm; clientsfactory.Save(); return(ViewMethods.AlertBack("添加客户成功!", "../../Clients/Clients?BELONG=" + clientsbelong)); }
private async Task RunAsync(CancellationToken stoppingToken) { try { using var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("User-Agent", "BikeDataProject"); var clientFactory = new ClientsFactory(null, httpClient, _configuration["OSM_API"]); // get client credentials. var userName = await File.ReadAllTextAsync(_configuration["OSM_USER_ID"]); var userPass = await File.ReadAllTextAsync(_configuration["OSM_USER_PASS"]); var client = clientFactory.CreateBasicAuthClient(userName, userPass); // get unsynced track. var unSyncedTrack = await _db.GetUnSyncedPublicTrack(); if (unSyncedTrack == null) { return; } // sync gpx track. try { var track = await client.GetTraceData(unSyncedTrack.OsmTrackId); using (var memoryStream = new MemoryStream()) using (var gzipStream = new GZipStream(memoryStream, CompressionLevel.Optimal)) { await track.Stream.CopyToAsync(gzipStream); await gzipStream.FlushAsync(); await gzipStream.DisposeAsync(); unSyncedTrack.GpxFile = memoryStream.ToArray(); } unSyncedTrack.GpxContentType = track.ContentType.MediaType; unSyncedTrack.SyncState = TrackSyncStateEnum.GpxSynced; _db.Tracks.Update(unSyncedTrack); await _db.SaveChangesAsync(); _logger.LogInformation($"Synchronized GPX for public track: {unSyncedTrack.OsmTrackId}"); } catch (Exception e) { unSyncedTrack.SyncState = TrackSyncStateEnum.Error; _db.Tracks.Update(unSyncedTrack); await _db.SaveChangesAsync(); _logger.LogWarning(e, $"Failed to get public track: {unSyncedTrack.OsmTrackId}"); } } catch (Exception e) { _logger.LogError(e, $"Unhandled exception while synchronizing GPX track."); } }
private async Task RunAsync(CancellationToken stoppingToken) { try { using var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("User-Agent", "BikeDataProject"); var clientFactory = new ClientsFactory(null, httpClient, _configuration["OSM_API"]); // get client credentials. var userName = await File.ReadAllTextAsync(_configuration["OSM_USER_ID"]); var userPass = await File.ReadAllTextAsync(_configuration["OSM_USER_PASS"]); var client = clientFactory.CreateBasicAuthClient(userName, userPass); // get id to start from if any. var idToStartFrom = _configuration.GetValueOrDefault <int>("start-track-id", -1); // get current synchronization state. var latestPublic = await _db.GetLatestPublic(); var latestPublicId = latestPublic?.OsmTrackId ?? idToStartFrom; var latestUnknown = await _db.GetLatestUnknown(); var latestUnknownId = latestUnknown?.OsmTrackId ?? 0L; // make sure last unknown is after. if (latestPublicId > latestUnknownId) { latestUnknownId = latestPublicId + 1; } // increase the range. latestUnknownId += 10000; // start from 0 and work upwards. // get all public tracks until one with tag cycling is encountered. // synchronization algorithm: // every x-minutes try to access traces in range: [last public id -> last public id + average range] // if success : update last public id. // if not success: increase range for next try. // loop over the tracks. for (var osmId = latestPublicId + 1; osmId <= latestUnknownId; osmId++) { if (stoppingToken.IsCancellationRequested) { break; } GpxFile?track = null; try { track = await client.GetTraceDetails(osmId); } catch (Exception e) { track = null; } if (track != null) { var user = await _db.GetOrCreateUser(track.User); await _db.GetOrCreatePublicTrack(user, osmId, track.TimeStamp, track.Name, track.Tags); for (var p = latestPublicId + 1; p < osmId; p++) { await _db.SetToPrivateIfUnknown(p); } latestPublicId = osmId; _logger.LogInformation("Found public track: {osmId}", osmId); } else { await _db.GetOrCreateUnknownTrack(osmId); _logger.LogInformation("Assuming private track: {osmId}", osmId); } await Task.Delay(_configuration.GetValueOrDefault <int>("query-wait-time", 1000), stoppingToken); } } catch (Exception e) { _logger.LogError(e, "Unhandled exception while querying OSM-API"); } }
public AltcoinExplorer(string serverAddress) { _client = ClientsFactory.Create(serverAddress); }
public static void Main() { var Config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", false, true) .Build(); var loggerFactory = MakeLoggerFactory(); var clientLogger = loggerFactory.CreateLogger("Client"); var testsLogger = loggerFactory.CreateLogger("Tests"); var clientFactory = new ClientsFactory(clientLogger, new HttpClient(), Config["osmApiUrl"]); try { // Test no auth testsLogger.LogInformation("Testing unauthenticated client"); var client = clientFactory.CreateNonAuthClient(); Tests.TestClient(client).Wait(); testsLogger.LogInformation("All tests passed for the unauthenticated client."); // Test BasicAuth if (!string.IsNullOrEmpty(Config["basicAuth:Password"])) { if (!Config["osmApiUrl"].Contains("dev")) { throw new Exception("These tests modify data, and it looks like your running them in PROD, please don't"); } testsLogger.LogInformation("Testing BasicAuth client"); var basicAuth = clientFactory.CreateBasicAuthClient(Config["basicAuth:User"], Config["basicAuth:Password"]); Tests.TestAuthClient(basicAuth).Wait(); testsLogger.LogInformation("All tests passed for the BasicAuth client."); } else { testsLogger.LogWarning("Skipped BasicAuth tests, no credentials supplied."); } // Test OAuth if (!string.IsNullOrEmpty(Config["oAuth:consumerSecret"])) { if (!Config["osmApiUrl"].Contains("dev")) { throw new Exception("These tests modify data, and it looks like your running them in PROD, please don't"); } testsLogger.LogInformation("Testing OAuth client"); var oAuth = clientFactory.CreateOAuthClient(Config["oAuth:consumerKey"], Config["oAuth:consumerSecret"], Config["oAuth:token"], Config["oAuth:tokenSecret"]); Tests.TestAuthClient(oAuth).Wait(); testsLogger.LogInformation("All tests passed for the OAuth client."); } else { testsLogger.LogWarning("Skipped OAuth tests, no credentials supplied."); } } catch (Exception e) { testsLogger.LogCritical("Tests failed: {0}", e); } Console.ReadKey(true); }