public void UpdateBeforeSimulation() { if (_uninitializedHandTools.Count == 0) { return; } var finished = new List <IMyEngineerToolBase>(); foreach (IMyEngineerToolBase handTool in _uninitializedHandTools) { if (handTool.Closed) { finished.Add(handTool); continue; } var player = FindPlayer(handTool); if (player == null) { return; } _cache.Update(player, handTool); finished.Add(handTool); } _uninitializedHandTools.RemoveAll(e => finished.Contains(e)); }
public EntityMapper <TEntity> Column(Expression <Func <TEntity, object> > column, string columnName) { // 只有 p=>p.property 这种形式才为有效值 if (column.NodeType == ExpressionType.Lambda) { // 成员名称 string name = string.Empty; LambdaExpression columnLambda = column as LambdaExpression; switch (columnLambda.Body.NodeType) { case ExpressionType.MemberAccess: name = (columnLambda.Body as MemberExpression).Member.Name; // 映射到列 _columnNameMapper.Update(name, columnName); break; case ExpressionType.Convert: var operand = (columnLambda.Body as UnaryExpression).Operand as MemberExpression; name = operand.Member.Name; // 映射到列 _columnNameMapper.Update(name, columnName); break; } } return(this); }
public void UpdateTest() { Dictionary <string, string> target = new Dictionary <string, string>() { { "test1", "test1" }, { "test2", "test2" }, { "test3", "test3" } }; Dictionary <string, string> append = new Dictionary <string, string>() { { "test4", "test4" }, { "test5", "test5" }, { "test2", "test6" } }; Dictionary <string, string> result = new Dictionary <string, string>() { { "test1", "test1" }, { "test2", "test2" }, { "test3", "test3" }, { "test4", "test4" }, { "test5", "test5" } }; target.Update(append); AssertExtras.DictionaryIsEqual(result, target); target.Update(null); AssertExtras.DictionaryIsEqual(result, target); }
/// <summary> /// Tests the dictionary methods. /// </summary> private static void TestDictionary() { Console.WriteLine("Dictionary Test:"); Console.WriteLine(string.Empty); var dictionary = new Dictionary <string, string>(); dictionary.AddIfNotExists("a", "abc"); dictionary.AddIfNotExists("a", "abc"); dictionary.AddIfNotExists("b", "def"); PrintDictionaryToConsole(dictionary); dictionary.Update("b", "defg"); PrintDictionaryToConsole(dictionary); var pair = dictionary.First(x => x.Key.Equals("b")); dictionary.Update(pair); PrintDictionaryToConsole(dictionary); dictionary.DeleteIfExistsKey("a"); PrintDictionaryToConsole(dictionary); dictionary.DeleteIfExistsValue("defg"); PrintDictionaryToConsole(dictionary); Print(dictionary.AreKeysNull()); Print(dictionary.AreValuesNull()); var dict1 = new Dictionary <string, string>(); var dict2 = dict1.Clone(); dict2.Add("1", "1"); PrintDictionaryToConsole(dict1); PrintDictionaryToConsole(dict2); }
public TreeWrapper GetFeedSubmissionCount(string[] feedTypes=null, string[] processingStatuses=null, string fromDate=null, string toDate=null) { var data = new Dictionary<string, string>() { {"Action", "GetFeedSubmissionCount"}, {"SubmittedFromDate", fromDate}, {"SubmittedToDate", toDate} }; data.Update(EnumerateParam("FeedTypeList.Type.", feedTypes)); data.Update(EnumerateParam("FeedProcessingStatusList.Status.", processingStatuses)); return MakeRequest(data); }
public TreeWrapper CancelFeedSubmissions(string[] feedIds=null, string[] feedTypes=null, string fromDate=null, string toDate=null) { var data = new Dictionary<string, string>() { {"Action", "CancelFeedSubmissions"}, {"SubmittedFromDate", fromDate}, {"SubmittedToDate", toDate} }; data.Update(EnumerateParam("FeedSubmissionIdList.Id.", feedIds)); data.Update(EnumerateParam("FeedTypeList.Type.", feedTypes)); return MakeRequest(data); }
/// <inheritdoc /> public CacheResult RetrieveOrCache(TKey key, Func <TValue> newValue, out TValue value) { lock (cacheLock) { //Case 1: the value is cached -> return it and put the retrieved key at the front of the history. if (dict.TryGetValue(key, out value)) { var oldPosition = cachePositions[key]; cacheRetrievalHistory.RemoveAt(oldPosition); for (int i = 0; i < oldPosition; i++) { cachePositions.Update(cacheRetrievalHistory[i], x => x + 1); } cacheRetrievalHistory.Insert(0, key); cachePositions.Update(key, _ => 0); cachePositions[key] = 0; return(CacheResult.WasFoundCached); } //Case 2: the value is not cached, but we can cache it without deleting any old element. else if (dict.Count < cacheSize) { cacheRetrievalHistory.Insert(0, key); cachePositions.Add(key, 0); value = newValue(); dict.TryAdd(key, value); return(CacheResult.WasInserted); } //Case 3: the value is not cached and we can cache it by removing an old element. else if (cacheSize > 0) { var keyToRemove = cacheRetrievalHistory[cacheRetrievalHistory.Count - 1]; cacheRetrievalHistory.RemoveAt(cacheRetrievalHistory.Count - 1); cachePositions.Remove(keyToRemove); dict.Remove(keyToRemove, out var _); cacheRetrievalHistory.Insert(0, key); cachePositions.Add(key, 0); value = newValue(); dict.TryAdd(key, value); return(CacheResult.WasInserted); } //Case 4: the value is not cached and we can't cache it because the cache-size is 0. else { value = newValue(); return(CacheResult.WasMissingAndNotCached); } } }
public TreeWrapper GetFeedSubmissionCount(string[] feedTypes = null, string[] processingStatuses = null, string fromDate = null, string toDate = null) { var data = new Dictionary <string, string>() { { "Action", "GetFeedSubmissionCount" }, { "SubmittedFromDate", fromDate }, { "SubmittedToDate", toDate } }; data.Update(EnumerateParam("FeedTypeList.Type.", feedTypes)); data.Update(EnumerateParam("FeedProcessingStatusList.Status.", processingStatuses)); return(MakeRequest(data)); }
public TreeWrapper CancelFeedSubmissions(string[] feedIds = null, string[] feedTypes = null, string fromDate = null, string toDate = null) { var data = new Dictionary <string, string>() { { "Action", "CancelFeedSubmissions" }, { "SubmittedFromDate", fromDate }, { "SubmittedToDate", toDate } }; data.Update(EnumerateParam("FeedSubmissionIdList.Id.", feedIds)); data.Update(EnumerateParam("FeedTypeList.Type.", feedTypes)); return(MakeRequest(data)); }
public TreeWrapper GetReportRequestList(string[] requestIds = null, string[] types = null, string[] processingStatuses = null, string maxCount = null, string fromDate = null, string toDate = null) { var data = new Dictionary<string, string>() { {"Action", "GetReportRequestList"}, {"MaxCount", maxCount}, {"RequestedFromDate", fromDate}, {"RequestedToDate", toDate}, }; data.Update(EnumerateParam("ReportRequestIdList.Id.", requestIds)); data.Update(EnumerateParam("ReportTypeList.Type.", types)); data.Update(EnumerateParam("ReportProcessingStatusList.Status.", processingStatuses)); return MakeRequest(data); }
private static bool WaitInternal(object container, Delegate action) { if (_dictionaryEvent.IsNotNullAndTryGetValue(container, out var del)) { try { _dictionaryEvent.Update(container, Delegate.Combine(del, action)); } catch (ArgumentException e) { LogManager.LogWarning(e.Message); return(false); } } else { _dictionaryEvent.Add(container, action); } if (methodWaits.IsNotNullAndTryGetValue(action, out var list)) { list.Add(container); } else { list = new List <object> { container }; methodWaits.Add(action, list); } return(true); }
/// <summary> /// Handles the damage in ProtectionAreas if Protection is enabled. This method is desinged for server side use and will notify the players if they tried to damage the wrong block. /// </summary> /// <param name="target"></param> /// <param name="info"></param> private static void DamageHandler_Server(object target, ref MyDamageInformation info) { if (!Config.ProtectionEnabled) { return; } IMySlimBlock block = target as IMySlimBlock; if (block != null) { IMyPlayer player; if (CanDamageBlock(info.AttackerId, block, info.Type, out player)) { return; } info.Amount = 0; // notify player DateTime time; if (player != null && (!_sentFailedMessage.TryGetValue(player, out time) || DateTime.Now - time >= TimeSpan.FromMilliseconds(GrindFailedMessageInterval))) { MessageClientNotification.SendMessage(player.SteamUserId, "You are not allowed to damage this block.", GrindFailedMessageInterval, MyFontEnum.Red); _sentFailedMessage.Update(player, DateTime.Now); } return; } // disable pvp in PAs IMyCharacter character = target as IMyCharacter; if (character != null) { var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players, p => p != null && p.Controller.ControlledEntity != null && p.Controller.ControlledEntity.Entity != null); var player = players.FirstOrDefault(p => p.GetCharacter() == character); if (player == null) { return; } if (!IsProtected(player.Controller.ControlledEntity.Entity)) { return; } if (info.Type == MyDamageType.LowPressure || info.Type == MyDamageType.Asphyxia || info.Type == MyDamageType.Environment || info.Type == MyDamageType.Fall || info.Type == MyDamageType.Fire || info.Type == MyDamageType.Radioactivity || info.Type == MyDamageType.Suicide || info.Type == MyDamageType.Unknown) { return; } info.Amount = 0; } }
public static Dictionary <string, ContainerString> GetDictionaryString(string container, string equals = "=", string finishMark = ";") { int startIndex = 0; int indexFinish = 0; int indexValue = container.IndexOf(equals, startIndex); Dictionary <string, ContainerString> dict = new Dictionary <string, ContainerString>(); while (indexValue != -1 && indexValue - 1 >= 0 && indexValue + 1 < container.Length) { startIndex = indexValue + 1; indexFinish = container.LastIndexOf(finishMark, indexValue); indexFinish = indexFinish != -1 ? indexFinish + 1 : 0; string title = container.SubstringWithIndex(indexFinish, indexValue - 1); indexFinish = container.IndexOf(finishMark, indexValue + 1); indexFinish = indexFinish != -1 ? indexFinish - 1 : container.Length - 1; string content = container.SubstringWithIndex(indexValue + 1, indexFinish); if (title != null && content != null) { dict.Update(title, new ContainerString(title.Trim(), content.Trim())); } indexValue = container.IndexOf(equals, startIndex); } return(dict); }
public TreeWrapper GetOrder(string[] amazonOrderIds) { var data = new Dictionary<string, string>() { {"Action", "GetOrder"}, }; data.Update(EnumerateParam("AmazonOrderId.Id.", amazonOrderIds)); return MakeRequest(data); }
public TreeWrapper GetReportRequestList(string[] requestIds = null, string[] types = null, string[] processingStatuses = null, string maxCount = null, string fromDate = null, string toDate = null) { var data = new Dictionary <string, string>() { { "Action", "GetReportRequestList" }, { "MaxCount", maxCount }, { "RequestedFromDate", fromDate }, { "RequestedToDate", toDate }, }; data.Update(EnumerateParam("ReportRequestIdList.Id.", requestIds)); data.Update(EnumerateParam("ReportTypeList.Type.", types)); data.Update(EnumerateParam("ReportProcessingStatusList.Status.", processingStatuses)); return(MakeRequest(data)); }
private static void UpdateTimers(Delegate action, TimerContainer newTimer) { if (_timers.IsNotNullAndTryGetValue(action, out var oldTimer)) { oldTimer.Kill(); } _timers?.Update(action, newTimer); }
/// <summary> /// Returns the current competitive pricing of a product, /// based on the SellerSKU and MarketplaceId that you specify. /// </summary> /// <param name="marketplaceId"></param> /// <param name="skus"></param> /// <returns></returns> public TreeWrapper GetCompetitivePricingForSku(string marketplaceId, string[] skus) { var data = new Dictionary<string, string>() { {"Action", "GetCompetitivePricingForSKU"}, {"MarketplaceId", marketplaceId}, }; data.Update(EnumerateParam("SellerSKUList.SellerSKU.", skus)); return MakeRequest(data); }
/// <summary> /// Returns the current competitive pricing of a product, /// based on the ASIN and MarketplaceId that you specify. /// </summary> /// <param name="?"></param> /// <param name="?"></param> /// <returns></returns> public TreeWrapper GetCompetitivePricingForAsin(string marketplaceId, string[] asins) { var data = new Dictionary<string, string>() { {"Action", "GetCompetitivePricingForASIN"}, {"MarketplaceId", marketplaceId}, }; data.Update(EnumerateParam("ASINList.ASIN.", asins)); return MakeRequest(data); }
/// <summary> /// Adds/updates or removes a certain key from the dictionary. The key is removed when the value is null. /// </summary> /// <typeparam name = "TKey">The type of the keys in the dictionary.</typeparam> /// <typeparam name = "TValue">The type of the values in the dictionary.</typeparam> /// <param name = "source">The source for this extension method.</param> /// <param name = "key">The key of the element in the dictionary to update.</param> /// <param name = "value">The new value for the key.</param> public static void Update <TKey, TValue>(this Dictionary <TKey, TValue> source, TKey key, TValue value) where TValue : class { // ReSharper disable CompareNonConstrainedGenericWithNull Contract.Requires(source != null && key != null); // ReSharper restore CompareNonConstrainedGenericWithNull source.Update(key, value, v => v != null); }
/// <summary> /// Adds/updates or removes a certain key from the dictionary. The key is removed when the value is null. /// </summary> /// <typeparam name = "TKey">The type of the keys in the dictionary.</typeparam> /// <typeparam name = "TValue">The type of the values in the dictionary.</typeparam> /// <param name = "source">The source for this extension method.</param> /// <param name = "key">The key of the element in the dictionary to update.</param> /// <param name = "value">The new value for the key.</param> public static void Update <TKey, TValue>(this Dictionary <TKey, TValue> source, TKey key, TValue value) where TValue : class { if (source == null || key == null) { throw new ArgumentNullException("Both source and key should be different from null."); } source.Update(key, value, v => v != null); }
public TreeWrapper GetOrder(string[] amazonOrderIds) { var data = new Dictionary <string, string>() { { "Action", "GetOrder" }, }; data.Update(EnumerateParam("AmazonOrderId.Id.", amazonOrderIds)); return(MakeRequest(data)); }
public TreeWrapper GetLowestOfferListingsForAsin(string marketplaceId, string[] asins, string condition="All") { var data = new Dictionary<string, string>() { {"Action", "GetLowestOfferListingsForASIN"}, {"MarketplaceId", marketplaceId}, {"ItemCondition", condition}, }; data.Update(EnumerateParam("ASINList.ASIN.", asins)); return MakeRequest(data); }
/// <summary> /// Returns the current competitive pricing of a product, /// based on the SellerSKU and MarketplaceId that you specify. /// </summary> /// <param name="marketplaceId"></param> /// <param name="skus"></param> /// <returns></returns> public TreeWrapper GetCompetitivePricingForSku(string marketplaceId, string[] skus) { var data = new Dictionary <string, string>() { { "Action", "GetCompetitivePricingForSKU" }, { "MarketplaceId", marketplaceId }, }; data.Update(EnumerateParam("SellerSKUList.SellerSKU.", skus)); return(MakeRequest(data)); }
/// <summary> /// Returns the current competitive pricing of a product, /// based on the ASIN and MarketplaceId that you specify. /// </summary> /// <param name="?"></param> /// <param name="?"></param> /// <returns></returns> public TreeWrapper GetCompetitivePricingForAsin(string marketplaceId, string[] asins) { var data = new Dictionary <string, string>() { { "Action", "GetCompetitivePricingForASIN" }, { "MarketplaceId", marketplaceId }, }; data.Update(EnumerateParam("ASINList.ASIN.", asins)); return(MakeRequest(data)); }
/// <summary> /// Returns a list of products and their attributes, based on a list of /// ASIN values that you specify. /// </summary> /// <param name="marketplaceId"></param> /// <param name="asins"></param> /// <returns></returns> public TreeWrapper GetMatchingProduct(string marketplaceId, string[] asins) { var data = new Dictionary <string, string>() { { "Action", "GetMatchingProduct" }, { "MarketplaceId", marketplaceId }, }; data.Update(EnumerateParam("ASINList.ASIN.", asins)); return(MakeRequest(data)); }
public TreeWrapper GetReportCount(string[] reportTypes = null, string acknowledged = null, string fromDate = null, string toDate = null) { var data = new Dictionary<string, string>() { {"Action", "GetReportCount"}, {"Acknowledged", acknowledged}, {"AvailableFromDate", fromDate}, {"AvailableToDate", toDate}, }; data.Update(EnumerateParam("ReportTypeList.Type.", reportTypes)); return MakeRequest(data); }
private void Button_Click(object sender, RoutedEventArgs e) { if (mod == 0) { Current.Meaning++; } else if (mod == 1) { Current.Spelling++; } else if (mod == 2) { Current.Meaning++; } else if (mod == 3) { Current.PronScore++; } dic.Update(Current); next(); }
public TreeWrapper RequestReport(string reportType, string startDate = null, string endDate = null, string[] marketplaceIds = null) { var data = new Dictionary<string, string>() { {"Action", "RequestReport"}, {"ReportType", reportType}, {"StartDate", startDate}, {"EndDate", endDate}, }; data.Update(EnumerateParam("MarketplaceIdList.Id.", marketplaceIds)); return MakeRequest(data); }
public TreeWrapper GetLowestOfferListingsForAsin(string marketplaceId, string[] asins, string condition = "All") { var data = new Dictionary <string, string>() { { "Action", "GetLowestOfferListingsForASIN" }, { "MarketplaceId", marketplaceId }, { "ItemCondition", condition }, }; data.Update(EnumerateParam("ASINList.ASIN.", asins)); return(MakeRequest(data)); }
public TreeWrapper GetLowestOfferListingsForSku(string marketplaceId, string[] skus, string condition = "Any") { var data = new Dictionary <string, string>() { { "Action", "GetLowestOfferListingsForSKU" }, { "MarketplaceId", marketplaceId }, { "ItemCondition", condition }, }; data.Update(EnumerateParam("SellerSKUList.SellerSKU.", skus)); return(MakeRequest(data)); }
public void When_Update() { var source = new Dictionary <int, string> { { 1, "a" }, { 2, "b" } }; var expected = "c"; source.Update(2, "c"); var actual = source[2]; Assert.AreEqual(expected, actual); }
public TreeWrapper RequestReport(string reportType, string startDate = null, string endDate = null, string[] marketplaceIds = null) { var data = new Dictionary <string, string>() { { "Action", "RequestReport" }, { "ReportType", reportType }, { "StartDate", startDate }, { "EndDate", endDate }, }; data.Update(EnumerateParam("MarketplaceIdList.Id.", marketplaceIds)); return(MakeRequest(data)); }
public void When_Update() { Dictionary <int, string> source = new Dictionary <int, string>(); source.Add(1, "a"); source.Add(2, "b"); string expected = "c"; source.Update(2, "c"); string actual = source[2]; Assert.AreEqual(expected, actual); }
public TreeWrapper GetReportCount(string[] reportTypes = null, string acknowledged = null, string fromDate = null, string toDate = null) { var data = new Dictionary <string, string>() { { "Action", "GetReportCount" }, { "Acknowledged", acknowledged }, { "AvailableFromDate", fromDate }, { "AvailableToDate", toDate }, }; data.Update(EnumerateParam("ReportTypeList.Type.", reportTypes)); return(MakeRequest(data)); }
public static void SetVariableString(string variableName, string newValue) { if (isInitStatic) { ResetDefaultVariableString(); isInitStatic = false; } if (stringVars != null && variableName != null && newValue != null) { stringVars.Update(variableName, newValue); OnModifyVar?.Invoke(); } }
/// <summary> /// Make request to Amazon MWS API with these parameters /// </summary> /// <param name="extraData"></param> /// <param name="method"></param> /// <param name="extraHeaders"></param> /// <param name="body"></param> /// <returns></returns> public TreeWrapper MakeRequest(IDictionary <string, string> extraData, string method = WebRequestMethods.Http.Get, IDictionary <HttpRequestHeader, string> extraHeaders = null, string body = null) { var qParams = new Dictionary <string, string>() { { "AWSAccessKeyId", this.accessKey }, { ACCOUNT_TYPE, this.accountId }, { "SignatureVersion", "2" }, { "Timestamp", this.GetTimestamp() }, { "Version", this.version }, { "SignatureMethod", "HmacSHA256" }, }; qParams.Update(extraData.Where(i => !string.IsNullOrEmpty(i.Value)).ToDictionary(p => p.Key, p => p.Value)); //TODO add encode('utf-8') var requestDescription = string.Join("&", from param in qParams select string.Format("{0}={1}", param.Key, Uri.EscapeDataString(param.Value))); var signature = this.CalcSignature(method, requestDescription); var url = string.Format("{0}{1}?{2}&Signature={3}", this.domain, this.uri, requestDescription, Uri.EscapeDataString(signature)); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = method.ToString(); request.UserAgent = "csharp-amazon-mws/0.0.1 (Language=CSharp)"; if (extraHeaders != null) { foreach (var x in extraHeaders) { request.Headers.Add(x.Key, x.Value); } } if (!string.IsNullOrEmpty(body)) { var dataStream = request.GetRequestStream(); var bytes = Encoding.UTF8.GetBytes(body); dataStream.Write(bytes, 0, body.Length); dataStream.Close(); } var response = request.GetResponse(); var parsedResponse = new TreeWrapper(response.GetResponseStream(), NS); response.Close(); return(parsedResponse); }
public static void StartCalculateMethod(string nameMethod) { if (nameMethod != null) { if (mapAverageMethod != null && !mapAverageMethod.ContainsKey(nameMethod)) { mapAverageMethod.Add(nameMethod, new SpeedMethodInfo()); } if (startTimeMethod != null) { startTimeMethod.Update(nameMethod, Time.realtimeSinceStartup); } } }
public TreeWrapper ListOrders(string[] marketplaceIds, string createdAfter = null, string createdBefore = null, string lastUpdatedAfter = null, string lastUpdatedBefore = null, string[] orderStatus = null, string[] fulfillmentChannels = null, string[] paymentMethods = null, string buyerEmail = null, string sellerOrderid = null, int maxResults = 100) { var data = new Dictionary <string, string>() { { "Action", "ListOrders" }, { "CreatedAfter", createdAfter }, { "CreatedBefore", createdBefore }, { "LastUpdatedAfter", lastUpdatedAfter }, { "LastUpdatedBefore", lastUpdatedBefore }, { "BuyerEmail", buyerEmail }, { "SellerOrderId", sellerOrderid }, { "MaxResultsPerPage", maxResults.ToString() }, }; data.Update(EnumerateParam("OrderStatus.Status.", orderStatus)); data.Update(EnumerateParam("MarketplaceId.Id.", marketplaceIds)); data.Update(EnumerateParam("FulfillmentChannel.Channel.", fulfillmentChannels)); data.Update(EnumerateParam("PaymentMethod.Method.", paymentMethods)); return(MakeRequest(data)); }
protected virtual void Init() { if (_defaultValues != null) { var props = GetType().GetProperties(); foreach (var prop in props) { _defaultValues.Update(prop.Name, prop.GetValue(this)); } } if (TunningManager.UseTunningVars) { LoadVarsPrivate(); } }
/// <summary> /// Uploads a feed ( xml or .tsv ) to the seller's inventory. /// Can be used for creating/updating products on amazon. /// </summary> /// <param name="feed"></param> /// <param name="feed_type"></param> /// <param name="marketplaceids"></param> /// <param name="content_type"></param> /// <param name="purge"></param> /// <returns></returns> public TreeWrapper SubmitFeed(string feed, string feedType, string[] marketplaceIds = null, string contentType = "text/xml", string purge = "false") { var data = new Dictionary<string, string>() { {"Action", "SubmitFeed"}, {"FeedType", feedType}, {"PurgeAndReplace", purge}, }; if (marketplaceIds != null) data.Update(EnumerateParam("MarketplaceIdList.Id.", marketplaceIds)); var md = CalcMD5(feed); var headers = new Dictionary<HttpRequestHeader, string>(){ {HttpRequestHeader.ContentMd5, md}, {HttpRequestHeader.ContentType, contentType}, }; return MakeRequest(data, WebRequestMethods.Http.Post, headers, feed); }
public TreeWrapper GetLowestOfferListingsForSku(string marketplaceId, string[] skus, string condition="Any") { var data = new Dictionary<string, string>() { {"Action", "GetLowestOfferListingsForSKU"}, {"MarketplaceId", marketplaceId}, {"ItemCondition", condition}, }; data.Update(EnumerateParam("SellerSKUList.SellerSKU.", skus)); return MakeRequest(data); }
/// <summary> /// Make request to Amazon MWS API with these parameters /// </summary> /// <param name="extraData"></param> /// <param name="method"></param> /// <param name="extraHeaders"></param> /// <param name="body"></param> /// <returns></returns> public TreeWrapper MakeRequest(IDictionary<string, string> extraData, string method = WebRequestMethods.Http.Get, IDictionary<HttpRequestHeader, string> extraHeaders = null, string body = null) { var qParams = new Dictionary<string, string>(){ {"AWSAccessKeyId", this.accessKey}, {ACCOUNT_TYPE, this.accountId}, {"SignatureVersion", "2"}, {"Timestamp", this.GetTimestamp()}, {"Version", this.version}, {"SignatureMethod", "HmacSHA256"}, }; qParams.Update(extraData.Where(i => !string.IsNullOrEmpty(i.Value)).ToDictionary(p => p.Key, p => p.Value)); //TODO add encode('utf-8') var requestDescription = string.Join("&", from param in qParams select string.Format("{0}={1}", param.Key, Uri.EscapeDataString(param.Value))); var signature = this.CalcSignature(method, requestDescription); var url = string.Format("{0}{1}?{2}&Signature={3}", this.domain, this.uri, requestDescription, Uri.EscapeDataString(signature)); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = method.ToString(); request.UserAgent = "csharp-amazon-mws/0.0.1 (Language=CSharp)"; if (extraHeaders != null) foreach (var x in extraHeaders) request.Headers.Add(x.Key, x.Value); if (!string.IsNullOrEmpty(body)) { var dataStream = request.GetRequestStream(); var bytes = Encoding.UTF8.GetBytes(body); dataStream.Write(bytes, 0, body.Length); dataStream.Close(); } var response = request.GetResponse(); var parsedResponse = new TreeWrapper(response.GetResponseStream(), NS); response.Close(); return parsedResponse; }
/// <summary> /// Reads the KeyValuePairs from the given string and adds them to a dictionary /// </summary> /// <param name="dataString"></param> /// <returns></returns> public static Dictionary<string, string> Parse(string dataString) { var data = new Dictionary<string, string>(); StringBuilder strBuild = new StringBuilder(); bool isEscaped = false; bool terminated = true; bool isKey = true; string key = ""; foreach (char c in dataString) { if (isEscaped) { isEscaped = false; strBuild.Append(c); continue; } switch (c) { case '"': if (terminated) { //new key or value terminated = false; } else { //end of key or value terminated = true; if (isKey) { key = strBuild.ToString(); } else { data.Update(key, strBuild.ToString()); } strBuild.Clear(); } break; case '\\': if (!terminated) isEscaped = true; break; case ':': if (terminated) isKey = false; else strBuild.Append(c); break; case ';': if (terminated) isKey = true; else strBuild.Append(c); break; default: if (!terminated) strBuild.Append(c); break; } } return data; }
public void Update() { Dictionary<int, int> dict = new Dictionary<int, int>(); dict.Add(1, 1); dict.Add(2, 2); dict.Add(3, 3); dict.Add(4, 2); Dictionary<int, int> dictCopy = new Dictionary<int, int>(); dictCopy.Add(1, 3); dictCopy.Add(3, 9); dict.Update(dictCopy); Dictionary<int, int> dictOther = new Dictionary<int, int>(); dictOther.Add(1, 3); dictOther.Add(2, 2); dictOther.Add(3, 9); dictOther.Add(4, 2); Assert.AreEqual(dictOther, dict); }
public TreeWrapper ListOrders(string[] marketplaceIds, string createdAfter=null, string createdBefore=null, string lastUpdatedAfter=null, string lastUpdatedBefore=null, string[] orderStatus=null, string[] fulfillmentChannels=null, string[] paymentMethods = null, string buyerEmail = null, string sellerOrderid = null, int maxResults=100) { var data = new Dictionary<string, string>() { {"Action", "ListOrders"}, {"CreatedAfter", createdAfter}, {"CreatedBefore", createdBefore}, {"LastUpdatedAfter", lastUpdatedAfter}, {"LastUpdatedBefore", lastUpdatedBefore}, {"BuyerEmail", buyerEmail}, {"SellerOrderId", sellerOrderid}, {"MaxResultsPerPage", maxResults.ToString()}, }; data.Update(EnumerateParam("OrderStatus.Status.", orderStatus)); data.Update(EnumerateParam("MarketplaceId.Id.", marketplaceIds)); data.Update(EnumerateParam("FulfillmentChannel.Channel.", fulfillmentChannels)); data.Update(EnumerateParam("PaymentMethod.Method.", paymentMethods)); return MakeRequest(data); }
/// <summary> /// Returns a list of products and their attributes, based on a list of /// ASIN values that you specify. /// </summary> /// <param name="marketplaceId"></param> /// <param name="asins"></param> /// <returns></returns> public TreeWrapper GetMatchingProduct(string marketplaceId, string[] asins) { var data = new Dictionary<string, string>() { {"Action", "GetMatchingProduct"}, {"MarketplaceId", marketplaceId}, }; data.Update(EnumerateParam("ASINList.ASIN.", asins)); return MakeRequest(data); }