public APIClient(string appKey, string secretKey, string serverHost = "gw.open.1688.com") { clientPolicy = new ClientPolicy(); clientPolicy.AppKey = appKey; //测试上的账号 clientPolicy.SecretKey = secretKey; clientPolicy.ServerHost = serverHost; }
static void Main(string[] args) { Console.WriteLine("Example starting...."); //create the connection information for accessing API server ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.AppKey = ""; clientPolicy.SecretKey = ""; String refreshToken = "ecc43432-87f9-4bd6-b8c0-5a741820c5a2"; //create an object for handling API request SyncAPIClient instance = new SyncAPIClient(clientPolicy); //create the API request, here the simple example is retrieve some information from API server. ExampleFamilyGetParam exampleFamilyGetParam = new ExampleFamilyGetParam(); exampleFamilyGetParam.setFamilyNumber(1); //call the API server with request ExampleFamilyGetResult exampleFamilyGetResult = instance.send <ExampleFamilyGetResult>(exampleFamilyGetParam); //get the result from API server. ExampleFamily exampleFamily = exampleFamilyGetResult.getResult(); Console.WriteLine("exampleFamilyGet:" + exampleFamily.getFather() + " and the name of father is " + exampleFamily.getFather().getName() + ", the birthday of fanther is " + exampleFamily.getFather().getBirthday()); }
public SyncAPIClient(String appKey, String appSecret, String gatewayHost) { this.clientPolicy = new ClientPolicy(); this.clientPolicy.AppKey = appKey; this.clientPolicy.SecretKey = appSecret; this.clientPolicy.ServerHost = gatewayHost; }
public static void AddRelatedData(ClientPolicy clientPolicy) { clientPolicy.Policy = Policies .First(p => p.PolicyId == clientPolicy.PolicyId); clientPolicy.PolicyStatus = PolicyStatus .First(ps => ps.PolicyStatusId == clientPolicy.PolicyStatusId); }
public async Task <IHttpActionResult> PutClientPolicy(int id, ClientPolicy clientPolicy) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != clientPolicy.client_policy_id) { return(BadRequest()); } this.clientPolicyRepository.Update(clientPolicy); try { await this.clientPolicyRepository.Save(); } catch (DbUpdateConcurrencyException) { if (!ClientPolicyExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <List <ClientPolicy> > AddOrUpdateClientPolicies(ClientPolicies clientPolicies) { List <ClientPolicy> clientPolicyListSaved = await _context.ClientPolicies.Where(cp => cp.ClientId == clientPolicies.ClientId).ToListAsync(); List <ClientPolicy> clientPoliciesToAdd = new List <ClientPolicy>(); List <ClientPolicy> clientPoliciesToDelete = new List <ClientPolicy>(); if (clientPolicyListSaved.Count > 0) { clientPolicyListSaved.ForEach(client => { if (clientPolicies.PoliciesIds.Contains(client.PolicyId) == false) { clientPoliciesToDelete.Add(client); } }); } clientPolicies.PoliciesIds.ForEach(id => { ClientPolicy clientPolicy = clientPolicyListSaved.Find(e => e.ClientId == clientPolicies.ClientId && e.PolicyId == id); if (clientPolicy == null) { clientPoliciesToAdd.Add(new ClientPolicy { ClientId = clientPolicies.ClientId, PolicyId = id }); } }); await _context.ClientPolicies.AddRangeAsync(clientPoliciesToAdd); _context.ClientPolicies.RemoveRange(clientPoliciesToDelete); await _context.SaveChangesAsync(); return(await _context.ClientPolicies.Where(cp => cp.ClientId == clientPolicies.ClientId).ToListAsync()); }
private void ConnectSync() { ClientPolicy policy = new ClientPolicy(); policy.failIfNotConnected = true; if (!user.Equals("")) { policy.user = user; policy.password = password; } client = new AerospikeClient(policy, host, port); try { SetServerSpecific(); } catch (Exception e) { client.Close(); client = null; throw e; } }
private void ConnectSync() { ClientPolicy policy = new ClientPolicy(); policy.clusterName = clusterName; policy.tlsPolicy = tlsPolicy; policy.authMode = authMode; if (!user.Equals("")) { policy.user = user; policy.password = password; } client = new AerospikeClient(policy, hosts); try { SetServerSpecific(); } catch (Exception e) { client.Close(); client = null; throw e; } }
public APIClient() { clientPolicy = new ClientPolicy(); clientPolicy.AppKey = ConfigurationManager.AppSettings["AppKey"]; clientPolicy.SecretKey = ConfigurationManager.AppSettings["SecretKey"]; clientPolicy.ServerHost = ConfigurationManager.AppSettings["ServerHost"]; }
public override void RunExample(Arguments a) { this.args = (BenchmarkArguments)a; shared = new BenchmarkShared(args); if (args.sync) { ClientPolicy policy = new ClientPolicy(); policy.user = args.user; policy.password = args.password; policy.tlsPolicy = args.tlsPolicy; policy.authMode = args.authMode; client = new AerospikeClient(policy, args.hosts); try { args.SetServerSpecific(client); threads = new BenchmarkThreadSync[args.threadMax]; for (int i = 0; i < args.threadMax; i++) { threads[i] = new BenchmarkThreadSync(console, args, shared, this, client); } RunThreads(); } finally { client.Close(); } } else { console.Info("Maximum concurrent commands: " + args.commandMax); AsyncClientPolicy policy = new AsyncClientPolicy(); policy.user = args.user; policy.password = args.password; policy.tlsPolicy = args.tlsPolicy; policy.authMode = args.authMode; policy.asyncMaxCommands = args.commandMax; AsyncClient client = new AsyncClient(policy, args.hosts); this.client = client; try { args.SetServerSpecific(client); threads = new BenchmarkThreadAsync[args.threadMax]; for (int i = 0; i < args.threadMax; i++) { threads[i] = new BenchmarkThreadAsync(console, args, shared, this, client); } RunThreads(); } finally { client.Close(); } } }
public async Task <ActionResult> DeleteConfirmed(int id) { ClientPolicy clientPolicy = await db.ClientPolicies.FindAsync(id); db.ClientPolicies.Remove(clientPolicy); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IHttpActionResult Post(ClientPolicy entity) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } unit.ClientPolicy.Add(entity); return(Ok()); }
public GoodRequest(string alistr) { ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.AppKey = "4291F75C-A7B9-4DB3-AADC-234490550B14"; instance = new SyncAPIClient(clientPolicy); //解析规格 dspec = new DeserialSpec(instance, alistr); this.alistr = alistr; }
public MetricsReportingGraphiteOptions() { FlushInterval = TimeSpan.FromSeconds(10); ClientPolicy = new ClientPolicy { FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff, BackoffPeriod = Constants.DefaultBackoffPeriod, Timeout = Constants.DefaultTimeout }; Graphite = new GraphiteOptions(); }
public async Task <IHttpActionResult> GetClientPolicy(int id) { ClientPolicy clientPolicy = await this.clientPolicyRepository.GetById(id); if (clientPolicy == null) { return(NotFound()); } return(Ok(clientPolicy)); }
public async Task <IHttpActionResult> PostClientPolicy(ClientPolicy clientPolicy) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } this.clientPolicyRepository.Insert(clientPolicy); await this.clientPolicyRepository.Save(); return(CreatedAtRoute("DefaultApi", new { id = clientPolicy.client_policy_id }, clientPolicy)); }
private void Login() { int port = int.Parse(portBox.Text.Trim()); Host[] hosts = Host.ParseHosts(hostBox.Text.Trim(), tlsName, port); string userName = userBox.Text.Trim(); string password = passwordBox.Text.Trim(); ClientPolicy policy = new ClientPolicy(); policy.user = userName; policy.password = password; policy.clusterName = clusterName; policy.failIfNotConnected = true; policy.timeout = 600000; policy.tlsPolicy = tlsPolicy; policy.authMode = authMode; AerospikeClient client = new AerospikeClient(policy, hosts); try { if (userName.Equals("admin") && password.Equals("admin")) { Form form = new PasswordForm(client, userName); form.ShowDialog(); } // Query own user. User user = client.QueryUser(null, userName); if (user != null) { bool admin = user.roles.Contains("user-admin"); // Initialize Global Data Globals.RefreshRoles(client, user, admin); Form form = new AdminForm(client, user, admin); form.Show(); } else { throw new Exception("Failed to find user: " + userName); } } catch (Exception) { client.Close(); throw; } }
public async Task <IHttpActionResult> DeleteClientPolicy(int id) { ClientPolicy clientPolicy = await this.clientPolicyRepository.GetById(id); if (clientPolicy == null) { return(NotFound()); } this.clientPolicyRepository.Delete(clientPolicy); await this.clientPolicyRepository.Save(); return(Ok(clientPolicy)); }
public async Task <ActionResult> Edit([Bind(Include = "IdClientPolicy,IdClient,IdPolicy,IdRiskType,CoveragePct")] ClientPolicy clientPolicy) { if (ModelState.IsValid) { db.Entry(clientPolicy).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.IdClient = new SelectList(db.Clients, "IdClient", "IdNumber", clientPolicy.IdClient); ViewBag.IdPolicy = new SelectList(db.Policies, "IdPolicy", "Name", clientPolicy.IdPolicy); ViewBag.IdRiskType = new SelectList(db.RiskTypes, "IdRiskType", "Name", clientPolicy.IdRiskType); return(View(clientPolicy)); }
protected virtual ClientPolicy GetClientPolicy() { var policy = new ClientPolicy { failIfNotConnected = true, maxSocketIdle = 100000, timeout = 30000 }; policy.user = string.Empty; policy.password = string.Empty; return(policy); }
// GET: ClientPolicies/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ClientPolicy clientPolicy = await db.ClientPolicies.FindAsync(id); if (clientPolicy == null) { return(HttpNotFound()); } return(View(clientPolicy)); }
public void ConvertsRequirementsCorrectly() { var clientPolicy = new ClientPolicy("policy", this.policy); Assert.Equal(4, this.policy.Requirements.Count()); // Should be 3 instead of 4 since we'll be ignoring DenyAnonymouseAuthorizationRole Assert.Equal(3, clientPolicy.Requirements.Count()); Assert.True(clientPolicy.Requirements.All(r => this.IsTargetRequirement(r))); Assert.Single(clientPolicy.Requirements, r => r is ClientRoleRequirement); Assert.Single(clientPolicy.Requirements, TestRequirement.TrueRequirement); Assert.Single(clientPolicy.Requirements, TestRequirement.FalseRequirement); }
public ActionResult Index() { ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.AppKey = "9769930"; clientPolicy.SecretKey = "RkBsy8k9v5h"; SyncAPIClient instance = new SyncAPIClient(clientPolicy); Model.CategoryGetParam categoryGetParam = new Model.CategoryGetParam(); categoryGetParam.setCategoryID(2); categoryGetParam.setWebSite("1688"); string category = instance.sendJson(categoryGetParam); return(View()); }
// GET: ClientPolicies/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ClientPolicy clientPolicy = await db.ClientPolicies.FindAsync(id); if (clientPolicy == null) { return(HttpNotFound()); } ViewBag.IdClient = new SelectList(db.Clients, "IdClient", "IdNumber", clientPolicy.IdClient); ViewBag.IdPolicy = new SelectList(db.Policies, "IdPolicy", "Name", clientPolicy.IdPolicy); ViewBag.IdRiskType = new SelectList(db.RiskTypes, "IdRiskType", "Name", clientPolicy.IdRiskType); return(View(clientPolicy)); }
public IHttpActionResult PostList(String id, String id2) { String idClient = "1"; if (!id.Equals(String.Empty) && !idClient.Equals(String.Empty)) { try { int ids = int.Parse(idClient); Client existingClient = unit.Client.GetFirst(x => x.id == ids); if (existingClient != null) { foreach (String item in id.Split('|')) { if (int.TryParse(item, out ids)) { var existingPolicy = unit.Policy.GetFirst(x => x.id == ids); if (existingPolicy != null) { ClientPolicy cp = new ClientPolicy() { client = existingClient, policy = existingPolicy }; unit.ClientPolicy.Update(cp); } } } } else { return(BadRequest("Client not found")); } return(Ok()); } catch (Exception) { //If any exception occurs Internal Server Error i.e. Status Code 500 will be returned return(InternalServerError()); } } return(BadRequest("Data error")); }
public override void RunExample(Arguments args) { ClientPolicy policy = new ClientPolicy(); policy.user = args.user; policy.password = args.password; policy.failIfNotConnected = true; AerospikeClient client = new AerospikeClient(policy, args.host, args.port); try { args.SetServerSpecific(client); RunExample(client, args); } finally { client.Close(); } }
// PUT api/client public IHttpActionResult Put(ClientPolicy entity) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } var existingClient = unit.ClientPolicy.GetFirst(x => x.id == entity.id); if (existingClient != null) { //existingClient.firstName = client.firstName; //existingClient.lastName = client.lastName; unit.ClientPolicy.Update(existingClient); } else { return(NotFound()); } return(Ok()); }
internal static IGraphiteClient CreateClient( MetricsReportingGraphiteOptions options, ClientPolicy clientPolicy) { if (options.Graphite.Protocol == Protocol.Tcp) { return(new DefaultGraphiteTcpClient(options.Graphite, clientPolicy)); } if (options.Graphite.Protocol == Protocol.Udp) { return(new DefaultGraphiteUdpClient(options.Graphite, clientPolicy)); } if (options.Graphite.Protocol == Protocol.Pickled) { throw new NotImplementedException("Picked protocol not implemented, use UDP or TCP"); } throw new NotSupportedException("Unsupported protocol, UDP, TCP and Pickled protocols are accepted"); }
public override void RunExample(Arguments args) { ClientPolicy policy = new ClientPolicy(); policy.user = args.user; policy.password = args.password; policy.clusterName = args.clusterName; policy.tlsPolicy = args.tlsPolicy; AerospikeClient client = new AerospikeClient(policy, args.hosts); try { args.SetServerSpecific(client); RunExample(client, args); } finally { client.Close(); } }
public virtual void SetUp() { try { Console.WriteLine("Creating AerospikeClient"); ClientPolicy clientPolicy = new ClientPolicy(); clientPolicy.timeout = TIMEOUT; client = new AerospikeClient(clientPolicy, HOST, PORT); client.writePolicyDefault.expiration = EXPIRY; //client.writePolicyDefault.recordExistsAction = RecordExistsAction.REPLACE; Key key = new Key(NS, SET, "CDT-list-test-key"); client.Delete(null, key); key = new Key(NS, SET, "setkey"); client.Delete(null, key); key = new Key(NS, SET, "accountId"); client.Delete(null, key); } catch (Exception ex) { caughtException = ex; Console.WriteLine(string.Format("TestFixtureSetUp failed in {0} - {1} {2}", this.GetType(), caughtException.GetType(), caughtException.Message)); Console.WriteLine(caughtException.StackTrace); } }