public LocalApiContext(ApiContext context, CommerceInstance instance) { InstanceName = context.InstanceName; Culture = context.Culture; Customer = context.Customer; _instance = instance; }
public ApiContext GetApiContext() { //ApiContext is a singleton, if (apiContext != null) { return apiContext; } else { apiContext = new ApiContext(); //supply Api Server Url apiContext.SoapApiServerUrl = ConfigurationManager.AppSettings["Environment.ApiServerUrl"]; //Supply user token ApiCredential apiCredential = new ApiCredential(); apiCredential.eBayToken = ConfigurationManager.AppSettings["UserAccount.ApiToken"]; apiContext.ApiCredential = apiCredential; //Specify site: here we use US site apiContext.Site = eBay.Service.Core.Soap.SiteCodeType.US; return apiContext; } // else }
public bool TryGetRelevantType( ApiContext context, string name, out Type relevantType) { relevantType = typeof(string); return true; }
static void Main(string[] args) { int port = 4028; if (args.Length > 0) int.TryParse(args.First(), out port); Console.WriteLine(String.Format("Enter bfgminer API command verbs to send them to port {0}.", port)); Console.WriteLine("QUIT will quit both bfgminer and this utility."); Console.WriteLine("EXIT will quit only this utility."); Console.WriteLine(String.Empty); Console.WriteLine("Ensure bfgminer is running and try DEVS or POOLS to get started."); Console.WriteLine(String.Empty); MultiMiner.Xgminer.Api.ApiContext apiContext = new ApiContext(port); while (true) { string apiVerb = Console.ReadLine(); if (apiVerb.Equals("exit", StringComparison.OrdinalIgnoreCase)) break; string response = apiContext.GetResponse(apiVerb.ToLower()); Console.WriteLine(String.Empty); Console.WriteLine(String.Format("{0} => {1}", apiVerb, response)); Console.WriteLine(String.Empty); if (apiVerb.Equals("quit", StringComparison.OrdinalIgnoreCase)) break; } }
public void NewApiContextIsConfiguredCorrectly() { var configuration = new ApiConfiguration(); configuration.EnsureCommitted(); var context = new ApiContext(configuration); Assert.Same(configuration, context.Configuration); }
public async Task GetModelUsingDefaultModelHandler() { var services = new ServiceCollection(); services.CutoffPrevious<IModelBuilder>(new TestModelProducer()); services.ChainPrevious<IModelBuilder>(next => new TestModelExtender(2) { InnerHandler = next, }); services.ChainPrevious<IModelBuilder>(next => new TestModelExtender(3) { InnerHandler = next, }); var configuration = services.BuildApiConfiguration(); var context = new ApiContext(configuration); var model = await context.GetModelAsync(); Assert.Equal(4, model.SchemaElements.Count()); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName")); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName2")); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName3")); Assert.NotNull(model.EntityContainer); Assert.NotNull(model.EntityContainer.Elements .SingleOrDefault(e => e.Name == "TestEntitySet")); Assert.NotNull(model.EntityContainer.Elements .SingleOrDefault(e => e.Name == "TestEntitySet2")); Assert.NotNull(model.EntityContainer.Elements .SingleOrDefault(e => e.Name == "TestEntitySet3")); }
public static bool IsRequestValid(HttpRequestBase request) { var body = HttpUtility.UrlDecode(request.Form.ToString()); var messageHash = request.QueryString["messageHash"]; var tenantId = request.QueryString["tenantId"]; if (tenantId == null) { ApiContext context = new ApiContext(request.Form); tenantId = context.TenantId.ToString(); } var date = request.QueryString["dt"]; var requestDate = DateTime.Parse(date, null, DateTimeStyles.AssumeUniversal).ToUniversalTime(); var currentDate = DateTime.UtcNow; _logger.Info(String.Format("Current DateTime : {0}", currentDate)); _logger.Info(String.Format("Request DateTime : {0}", requestDate)); var diff = (currentDate - requestDate).TotalSeconds; _logger.Info(String.Format("Date Diff : {0}", diff)); _logger.Info(String.Format("ApplicationID : {0}", AppAuthenticator.Instance.AppAuthInfo.ApplicationId)); var hash = SHA256Generator.GetHash(AppAuthenticator.Instance.AppAuthInfo.SharedSecret, date, body); _logger.Info(String.Format("Computed Hash : {0}", hash)); if (body != null && (hash != messageHash || diff > MozuConfig.CapabilityTimeoutInSeconds || (!body.Contains("t" + tenantId+".")))) { _logger.Error(String.Format("Unauthorized access from {0}, {1}, {2}, {3} Computed: {4}", request.UserHostAddress, messageHash, date, body, hash)); return false; } return true; }
public static bool Validate(HttpRequestBase request) { var tenantId = GetCookie(request.Cookies, "tenantId"); if (string.IsNullOrEmpty(tenantId)) throw new UnauthorizedAccessException(); var hash = GetCookie(request.Cookies, "hash"); if (string.IsNullOrEmpty(hash)) throw new UnauthorizedAccessException(); var userId = GetCookie(request.Cookies, "userId"); request.Headers.Add(Headers.X_VOL_TENANT, tenantId); request.Headers.Add(Headers.X_VOL_HMAC_SHA256, HttpUtility.UrlDecode(hash)); if (!request.Url.AbsoluteUri.Contains(tenantId)) return false; if (!string.IsNullOrEmpty(userId)) request.Headers.Add(Headers.USERID, userId); var apiContext = new ApiContext(request.Headers); var formToken = GetCookie(request.Cookies, "formToken"); if (string.IsNullOrEmpty(formToken)) return false; var cookieToken = GetCookie(request.Cookies, "cookieToken"); if (string.IsNullOrEmpty(cookieToken)) return false; var isSubNavLink = GetCookie(request.Cookies, "subNavLink") == "1"; return !string.IsNullOrEmpty(cookieToken) && Validate(apiContext, HttpUtility.UrlDecode(formToken), HttpUtility.UrlDecode(cookieToken), isSubNavLink); }
static void Main(string[] args) { int port = 4028; if (args.Length > 0) int.TryParse(args.First(), out port); string ipAddress = "127.0.0.1"; if (args.Length > 1) ipAddress = args[1]; Console.WriteLine(String.Format("Enter BFGMiner API command verbs to send them to port {0}.", port)); Console.WriteLine("QUIT will quit both BFGMiner and this utility."); Console.WriteLine("EXIT will quit only this utility."); Console.WriteLine(String.Empty); Console.WriteLine("Ensure BFGMiner is running and try DEVS or POOLS to get started."); Console.WriteLine(String.Empty); while (true) { string apiVerb = Console.ReadLine(); if (apiVerb.Equals("exit", StringComparison.OrdinalIgnoreCase)) break; string response = new ApiContext(port, ipAddress).GetResponse(apiVerb.ToLower(), ApiContext.LongCommandTimeoutMs); Console.WriteLine(String.Empty); Console.WriteLine(String.Format("{0} => {1}", apiVerb, response)); Console.WriteLine(String.Empty); if (apiVerb.Equals("quit", StringComparison.OrdinalIgnoreCase)) break; } }
public bool TryGetRelevantType( ApiContext context, string namespaceName, string name, out Type relevantType) { relevantType = typeof(DateTime); return true; }
public override void Dispose( ApiContext context, Type type, object instance) { Assert.Same(typeof(TestApiWithParticipants), type); context.SetProperty(this.Value, false); base.Dispose(context, type, instance); }
public void InvocationContextGetsHookPointsCorrectly() { var hook = new HookA(); var configuration = new ApiConfiguration().AddHookHandler<IHookA>(hook); configuration.EnsureCommitted(); var apiContext = new ApiContext(configuration); var context = new InvocationContext(apiContext); Assert.Same(hook, context.GetHookHandler<IHookA>()); }
public override object InvokeMethod(IApiMethodCall methodToCall, object instance, IEnumerable<object> callArg, ApiContext apicontext) { string cacheKey = null; object result = null; IEnumerable<Type> knownTypes = null; var cacheManager = Container.Resolve<ICacheManager>(); if (ShouldCacheMethod(methodToCall) && cacheManager != null) { cacheKey = BuildCacheKey(methodToCall, callArg, apicontext); result = cacheManager[cacheKey]; knownTypes = cacheManager[cacheKey + "_knowntypes"] as IEnumerable<Type>; apicontext.FromCache = result != null; Log.Debug(apicontext.FromCache ? "hit from cache: {0}" : "miss from cache: {0}", methodToCall); } if (result == null) //if not null than it's from cache { //Call api method var sw = new Stopwatch(); sw.Start(); result = base.InvokeMethod(methodToCall, instance, callArg, apicontext); sw.Stop(); long cacheTime; bool shouldCache; GetCachingPolicy(methodToCall, sw.Elapsed, out cacheTime, out shouldCache); Log.Debug("cache policy: {0}", cacheTime > 0 ? TimeSpan.FromMilliseconds(cacheTime).ToString() : "no-cache"); knownTypes = apicontext.GetKnownTypes().ToList(); if (cacheKey != null && cacheTime>0) { cacheManager.Add(cacheKey, result, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMilliseconds(cacheTime))); if (knownTypes!=null) { cacheManager.Add(cacheKey + "_knowntypes", knownTypes, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromMilliseconds(cacheTime * 2))); } Log.Debug("added to cache: {0}. Key: {1}", methodToCall, cacheKey); } } //Get cached known types if (knownTypes!=null) { apicontext.RegisterTypes(knownTypes); } return result; }
public override void Initialize( ApiContext context, Type type, object instance) { base.Initialize(context, type, instance); Assert.Same(typeof(TestApiWithParticipants), type); context.SetProperty(this.Value + ".Self", instance); context.SetProperty(this.Value, true); }
public void GetCoinInformation_BitcoinBasis_IsBasedOnBitcoin() { //act List<CoinInformation> coinInformation = new ApiContext().GetCoinInformation().ToList(); //assert CoinInformation coin = coinInformation.Single(c => c.Symbol.Equals("BTC")); Assert.AreEqual(coin.Profitability, 100); coin = coinInformation.Single(c => c.Symbol.Equals("LTC")); Assert.AreNotEqual(coin.Profitability, 100); }
public void GetApiName_ReturnsValue() { //arrange string name; //act name = new ApiContext().GetApiName(); //assert Assert.IsFalse(String.IsNullOrEmpty(name)); }
public void GetInfoUrl_ReturnsUrl() { //arrange string url; //act url = new ApiContext().GetInfoUrl(); //assert Assert.IsTrue(url.StartsWith("http")); }
public void GetInfoUrl_ReturnsUrl() { //arrange string url; //act url = new ApiContext(Properties.Settings.Default.CoinWarzApiKey).GetInfoUrl(); //assert Assert.IsTrue(url.StartsWith("http")); }
public void GetApiName_ReturnsValue() { //arrange string name; //act name = new ApiContext(Properties.Settings.Default.CoinWarzApiKey).GetApiName(); //assert Assert.IsFalse(String.IsNullOrEmpty(name)); }
public override void OnAuthorization(HttpActionContext actionContext) { base.OnAuthorization(actionContext); var corrID = HttpHelper.GetHeaderValue(Headers.X_VOL_CORRELATION, actionContext.Request.Headers); _logger.Info(String.Format("{0} - Validating Capability Request", corrID)); var content = actionContext.Request.Content.ReadAsStringAsync().Result; var apiContext = new ApiContext(actionContext.Request.Headers); var requestDate = DateTime.Parse(apiContext.Date, null, DateTimeStyles.AssumeUniversal).ToUniversalTime(); var currentDate = DateTime.UtcNow; var diff = (currentDate - requestDate).TotalSeconds; var hash = SHA256Generator.GetHash(AppAuthenticator.Instance.AppAuthInfo.SharedSecret, apiContext.Date, content); if (hash == apiContext.HMACSha256 && diff <= MozuConfig.CapabilityTimeoutInSeconds) return; _logger.Debug(String.Format("{0} Unauthorized access : Header Hash - {1}, Computed Hash - {2}, Request Date - {3}",corrID, apiContext.HMACSha256, hash, apiContext.Date)); actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized); }
public void GetCoinInformation_ReturnsCoinInformation() { //act List<CoinInformation> coinInformation = new ApiContext().GetCoinInformation().ToList(); //assert Assert.IsTrue(coinInformation.Count > 0); Assert.IsTrue(coinInformation.Count(c => c.AdjustedProfitability > 0.00) > 0); Assert.IsTrue(coinInformation.Count(c => c.Price > 0.00) > 0); Assert.IsTrue(coinInformation.Count(c => c.Profitability > 0.00) > 0); Assert.IsTrue(coinInformation.Count(c => c.AverageProfitability > 0.00) > 0); Assert.IsTrue(coinInformation.Count(c => c.Difficulty > 0.00) > 0); Assert.IsTrue(coinInformation.Count(c => c.Algorithm.Equals("scrypt")) > 0); Assert.IsTrue(coinInformation.Count(c => c.Algorithm.Equals("SHA-256")) > 0); }
public void Execute(ApiContext context) { context.Stream.Write("List of Parked Extensions:" + Environment.NewLine); if (ParkingLot.ParkedCalls.Count == 0) { context.Stream.Write("No calls parked." + Environment.NewLine); } else { foreach (string key in ParkingLot.ParkedCalls.Keys) { context.Stream.Write(string.Format("{0}: {1}{2}", key, ParkingLot.ParkedCalls[key], Environment.NewLine)); } } }
/// <summary> /// Tries to get the category (either from the communicator's cache, or from API if not in cache) /// </summary> /// <param name="apiContext"></param> /// <param name="categoryId"></param> /// <returns>Category if successful, null otherwise.</returns> public InventoryCategoryType GetCategory(ApiContext apiContext, int categoryId) { if (_categories.Keys.Contains(categoryId)) { return _categories[categoryId]; } List<InventoryCategoryType> someCategories = GetCategoryFromApi(apiContext, categoryId); if ((someCategories != null && someCategories.Count != 0)) //if someCategories != null and !empty { foreach (InventoryCategoryType newCategory in someCategories) { if (! _categories.Keys.ToList().Contains(Convert.ToInt32(newCategory.CategoryId))) { _categories.Add(Convert.ToInt32(newCategory.CategoryId), newCategory); } } } //Depending on the reliability of the API, this maybe overkill, could just return categories[categoryId]. return _categories.Keys.Contains(categoryId) ? _categories[categoryId] : null; }
/// <summary> /// Attempts to get a category from the API, it makes no guarantees that it will succeed. /// </summary> /// <param name="apiContext"></param> /// <param name="categoryId"></param> /// <returns>It will return a list of all categories it finds during the search. The list may or maynot contain the requested category.</returns> private List<InventoryCategoryType> GetCategoryFromApi(ApiContext apiContext, int categoryId) { var categories = new Dictionary<int, InventoryCategoryType>(50); int pageNum = 0; while (!categories.Keys.Contains(categoryId)) { List<InventoryCategoryType> pageOfCategories = GetPageOfInventoryCategories(apiContext, pageNum++, 50); if (!(pageOfCategories != null && pageOfCategories.Count != 0)) //(if pageOfCategories == null or count==0) { //Break out because we didnt get anything more back. break; } //Union the pageOfCategories into the category cache. foreach (InventoryCategoryType newCat in pageOfCategories) { categories.Add(Convert.ToInt32(newCat.CategoryId), newCat); } } return categories.Values.ToList(); }
//Constructor public BlogsController(ApiContext context) { db = context; }
public HomeController(ApiContext context) { _context = context; }
public ReceivedInvoiceClient(ApiContext apiContext) : base(apiContext) { }
/// <summary> /// /// </summary> /// <param name="ApiContext">The <see cref="ApiCall.ApiContext"/> for this API Call of type <see cref="ApiContext"/>.</param> public ReviseSellingManagerSaleRecordCall(ApiContext ApiContext) { ApiRequest = new ReviseSellingManagerSaleRecordRequestType(); this.ApiContext = ApiContext; }
public SigfoxController(ApiContext context) { _context = context; }
public PublisherRepository(ApiContext context) : base(context) { }
public SubTodoController(ApiContext context, SubTodoService subTodoService) { _context = context; _subTodoService = subTodoService; }
/// <summary> /// /// </summary> /// <param name="ApiContext">The <see cref="ApiCall.ApiContext"/> for this API Call of type <see cref="ApiContext"/>.</param> public GetUserPreferencesCall(ApiContext ApiContext) { ApiRequest = new GetUserPreferencesRequestType(); this.ApiContext = ApiContext; }
private static bool CheckContext(ApiContext context, string field) { return(context == null || context.Fields == null || (context.Fields != null && context.Fields.Contains(field))); }
public Task <object> GetConfig(ApiContext context, bool replaceParameter = true) { throw new NotImplementedException(); }
public UnitOfWork(ApiContext context) { _context = context; }
public Task <ResultModel> ConfigChanged(ApiContext context, object newConfig) { throw new NotImplementedException(); }
public QuestionsController(ApiContext context, Iserializer serializer, IErrorFormatter errorFormatter) : base(context, serializer, errorFormatter) { }
public CommentsController(ApiContext context) { _context = context; }
public EnrollmentsController(ApiContext _db) : base(_db) { }
public EmployeeWraperFull(UserInfo userInfo, ApiContext context) : base(userInfo) { UserName = userInfo.UserName; IsVisitor = userInfo.IsVisitor(); FirstName = userInfo.FirstName; LastName = userInfo.LastName; Birthday = (ApiDateTime)userInfo.BirthDate; if (userInfo.Sex.HasValue) { Sex = userInfo.Sex.Value ? "male" : "female"; } Status = userInfo.Status; ActivationStatus = userInfo.ActivationStatus; Terminated = (ApiDateTime)userInfo.TerminatedDate; WorkFrom = (ApiDateTime)userInfo.WorkFromDate; Email = userInfo.Email; if (!string.IsNullOrEmpty(userInfo.Location)) { Location = userInfo.Location; } if (!string.IsNullOrEmpty(userInfo.Notes)) { Notes = userInfo.Notes; } if (!string.IsNullOrEmpty(userInfo.MobilePhone)) { MobilePhone = userInfo.MobilePhone; } MobilePhoneActivationStatus = userInfo.MobilePhoneActivationStatus; if (!string.IsNullOrEmpty(userInfo.CultureName)) { CultureName = userInfo.CultureName; } FillConacts(userInfo); var groups = CoreContext.UserManager.GetUserGroups(userInfo.ID).Select(x => new GroupWrapperSummary(x)).ToList(); if (groups.Any()) { Groups = groups; Department = string.Join(", ", Groups.Select(d => d.Name.HtmlEncode())); } else { Department = ""; } if (CheckContext(context, "avatarSmall")) { AvatarSmall = UserPhotoManager.GetSmallPhotoURL(userInfo.ID); } if (CheckContext(context, "avatarMedium")) { AvatarMedium = UserPhotoManager.GetMediumPhotoURL(userInfo.ID); } if (CheckContext(context, "avatar")) { Avatar = UserPhotoManager.GetBigPhotoURL(userInfo.ID); } IsOnline = false; IsAdmin = userInfo.IsAdmin(); if (CheckContext(context, "listAdminModules")) { var listAdminModules = userInfo.GetListAdminModules(); if (listAdminModules.Any()) { ListAdminModules = listAdminModules; } } IsOwner = userInfo.IsOwner(); IsLDAP = userInfo.IsLDAP(); IsSSO = userInfo.IsSSO(); }
//constructor public AttributesController(ApiContext apiContext) { this.apiContext = apiContext; }
/// <summary> /// /// </summary> /// <param name="ApiContext">The <see cref="ApiCall.ApiContext"/> for this API Call of type <see cref="ApiContext"/>.</param> public MoveSellingManagerInventoryFolderCall(ApiContext ApiContext) { ApiRequest = new MoveSellingManagerInventoryFolderRequestType(); this.ApiContext = ApiContext; }
public GetPublication() { Context = new ApiContext(); }
public Customers(ApiContext apiContext) { InitializeComponent(); _apiContext = apiContext; }
public ProductsController(ApiContext context) { _context = context; }
protected string BuildCacheKey(IApiMethodCall methodToCall, IEnumerable<object> callArg, ApiContext context) { return Container.Resolve<IApiCacheMethodKeyBuilder>().BuildCacheKeyForMethodCall(methodToCall, callArg, context); }
public OrderController(ApiContext ctx) { _ctx = ctx; }
public ValuesController(ApiContext ctx) { _ctx = ctx; }
internal MetaInfoClient(ApiContext apiContext) : base(apiContext) { }
public RequiredMedicamentAmountSeed(ApiContext context) { _context = context; }
public UsuarioService(ApiContext contexto) { repository = new UsuarioRepo(contexto); }
public Reporting(ScenarioContext scenarioContext, FeatureContext featureContext, ApiContext apiContext) { this.scenarioContext = scenarioContext; this.featureContext = featureContext; this.apiContext = apiContext; }
/// <summary> /// Initializes a new instance of the <see cref="SubmitContext" /> class. /// </summary> /// <param name="apiContext"> /// An API context. /// </param> /// <param name="changeSet"> /// A change set. /// </param> public SubmitContext(ApiContext apiContext, ChangeSet changeSet) : base(apiContext) { this.ChangeSet = changeSet; }
///<summary> /// Constructor ///</summary> ///<param name="context"></param> public CommunityApi(ApiContext context) { _context = context; }
private void setContext() { var site = (Site)cbSite.SelectedItem; var masterCatalog = (from mc in _tenant.MasterCatalogs from c in mc.Catalogs where c.Id == site.CatalogId select mc).SingleOrDefault(); _apiContext = new ApiContext(site.TenantId, site.Id, masterCatalogId:masterCatalog.Id,catalogId:site.CatalogId); }
///<summary> /// Constructor ///</summary> ///<param name="context"></param> ///<param name="documentsApi">Docs api</param> public ProjectApi(ApiContext context, DocumentsApi documentsApi) { this.documentsApi = documentsApi; _context = context; }
public ActionsService(ApiContext context) { this.actionsRepository = new ActionsRepository(context); }
public NewsRepository(ApiContext context) : base(context) { }
public SeedingService(ApiContext context) { _context = context; }
public FilterStatusRepository(ApiContext context) : base(context) { _context = context; }