private void readJsonHeader(JToken node) { SaveVersion = node.Value <short>("saveVersion"); GameTime = node.Value <float>("gameTime"); SaveCount = node.Value <int>("saveCount"); JArray preservedNames = node.Value <JArray>("preservedNames"); OldNameList = preservedNames?.Any() == true?preservedNames.Values <string>().ToList() : null; }
public string Serialize([NotNull] IEnumerable <ButtplugMessage> aMsgs, uint clientSchemaVersion) { // Warning: Any log messages in this function must be localOnly. They will possibly recurse. var a = new JArray(); foreach (var msg in aMsgs) { // Support downgrading messages var tmp = msg; while (tmp.SchemaVersion > clientSchemaVersion) { if (tmp.PreviousType == null) { if (tmp.Id == ButtplugConsts.SystemMsgId) { // There's no previous version of this system message continue; } tmp = new Error($"No backwards compatible version for message #{tmp.GetType().Name}!", ErrorClass.ERROR_MSG, tmp.Id); continue; } tmp = (ButtplugMessage)tmp.PreviousType.GetConstructor( new Type[] { tmp.GetType() }).Invoke(new object[] { tmp }); } var o = new JObject(new JProperty(msg.GetType().Name, JObject.FromObject(tmp))); a.Add(o); } if (!a.Any()) { _bpLogger?.Warn($"No messages serialized!"); return(null); } _bpLogger?.Trace($"Message serialized to: {a.ToString(Formatting.None)}", true); return(a.ToString(Formatting.None)); }
private List <MovieDO> GetMovieList(JArray array) { var list = new List <MovieDO>(); if (array != null && array.Any()) { foreach (var element in array) { list.Add(new MovieDO { ID = element.Value <string>("id"), Title = element.Value <string>("title"), Genres = GetGenres(element.Value <string>("genres")), Date = element.Value <string>("releaseDate"), Poster = element.Value <string>("posterPath"), Rating = GetRating(element.Value <string>("voteAverage")), IsBasicSet = false }); } } return(list); }
void AddNodeBonuses(dynamic node, Saint.GatheringPoint sGatheringPoint) { if (sGatheringPoint.GatheringPointBonus.Length == 0) { return; } if (node.bonus == null) { node.bonus = new JArray(); } JArray bonuses = node.bonus; foreach (var sGatheringPointBonus in sGatheringPoint.GatheringPointBonus) { if (!bonuses.Any(j => (int)j == sGatheringPointBonus.Key)) { bonuses.Add(sGatheringPointBonus.Key); } } }
public static IEnumerable <User> ParseUsers(JArray array) { List <User> users = null; if (array != null && array.Any()) { users = new List <User>(); foreach (JObject item in array) { User user = new User(item); users.Add(user); } } else { logger.Warn("The array of users is empty."); logger.Warn(array.ToString()); } return(users); }
public async Task unregister() { int argPos = 0; if (!(Context.Message.HasStringPrefix("!gitlost ", ref argPos) || Context.Message.HasStringPrefix("!gl ", ref argPos))) { return; } if (!Context.IsPrivate && ((SocketGuildUser)Context.Message.Author).Roles.Any(x => x.Permissions.Administrator)) { ISocketMessageChannel channel = Context.Message.Channel; EmbedBuilder builder = new EmbedBuilder(); JToken token = JObject.Parse(await JsonHandler.LoadFile("channels.json")); JArray coll = (JArray)token.SelectToken("channels"); bool exists = coll.Any(x => x.Value <string>() == channel.Id.ToString()); if (!exists) { builder.WithDescription($"'{channel.Name}' hasn't been registered yet.\nType '!gl | !gitlost register' to register this channel.") .WithColor(Color.Blue); await ReplyAsync("", false, builder.Build()); } else { coll.Remove(coll.Where(x => x.Value <string>() == channel.Id.ToString()).First()); JObject newJson = new JObject(); newJson.Add(new JProperty("channels", coll)); JsonHandler.SaveFile("channels.json", newJson.ToString()); JsonHandler.UpdateChannels(coll.ToArray()); builder.WithDescription($"'{channel.Name}' has been unregistered from the newest post feed.") .WithColor(Color.Blue); await ReplyAsync("", false, builder.Build()); } } }
/// <summary> /// Serializes a collection of ButtplugMessage objects into a JSON string for a specified /// version of the schema. /// </summary> /// <param name="aMsgs">A collection of ButtplugMessage objects.</param> /// <param name="aClientSchemaVersion">The target schema version.</param> /// <returns>A JSON string representing one or more B******g messages.</returns> public string Serialize([NotNull] IEnumerable <ButtplugMessage> aMsgs, uint aClientSchemaVersion) { // Warning: Any log messages in this function must be localOnly. They will possibly recurse. var msgArray = new JArray(); foreach (var msg in aMsgs) { var obj = ButtplugMessageToJObject(msg, aClientSchemaVersion); if (obj == null) { continue; } msgArray.Add(obj); } // If we somehow didn't encode anything, throw. Otherwise we'll try to pass a string full // of nothing through the schema verifier and it will throw. if (!msgArray.Any()) { throw new ButtplugMessageException(_bpLogger, "No messages serialized."); } // Shove our JSON objects through the schema validator, just to make sure it'll be // accepted on the other end. var errors = _schema.Validate(msgArray); if (errors.Any()) { throw new ButtplugMessageException(_bpLogger, "Message does not conform to schema: " + string.Join(", ", errors.Select(aErr => aErr?.ToString()).ToArray())); } _bpLogger.Trace($"Message serialized to: {msgArray.ToString(Formatting.None)}", true); return(msgArray.ToString(Formatting.None)); }
private dynamic TransformJArray(JObject jsonObject, MappingRule mapping, bool ignoreNullVaue) { var tokens = jsonObject.SelectTokens(mapping.Node); JArray array = new JArray(); bool hasToken = false; foreach (var item in tokens) { hasToken = true; if (string.Equals(item.GetType().Name, "jarray", StringComparison.OrdinalIgnoreCase)) { JArray itemJArray = (JArray)item; if (itemJArray.Any()) { foreach (var a in itemJArray) { var o = (JToken)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(ExecuteToJson((JObject)a, mapping)), JsonConvertSettings); array.Add(o); } } else { itemJArray.Add(new JObject(new JProperty("temp", ""))); array.Add((JToken)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(ExecuteToJson((JObject)item.FirstOrDefault(), mapping)))); } } else { array.Add((JToken)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(ExecuteToJson((JObject)item, mapping)), JsonConvertSettings)); } } if (!hasToken && mapping.IgnoreEmptyArray) { return(null); } return(array); }
private string GetFirewallRule() { queryStringArray = null; httpMethod = "GET"; var response = ApiCAll(); if (response.StatusCode == HttpStatusCode.OK) { JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result); JArray ipRules = (JArray)json["properties"]["networkAcls"]["ipRules"]; if (ipRules.Count == 0 || ipRules.Any(x => x["value"].ToString() != ipAddress)) { ipRules.Add(new JObject { { "value", ipAddress }, { "action", "Allow" } }); } var action = json["properties"]["networkAcls"]["defaultAction"] = "Deny"; return(@"{ ""properties"": {" + json["properties"]["networkAcls"].Parent.ToString() + "}}"); } return(null); }
public static List <Filter> FromJArray(JArray array) { var filters = new List <Filter>(); if (array == null) { return(filters); } if (!array.Any()) { return(filters); } foreach (var element in array.Children <JObject>()) { var filter = new Filter { FilterId = element.TryGetPropertyValue <long>("filter_id"), ObjectName = element.TryGetPropertyValue <string>("object_name"), FilterName = element.TryGetPropertyValue <string>("filter_name"), IsDefault = element.TryGetPropertyValue <bool>("is_default"), IsDefaultAdmin = element.TryGetPropertyValue <bool>("is_default_admin"), FilterStatement = element.TryGetPropertyValue <string>("filter_statement"), ColumnName = element.TryGetPropertyValue <string>("column_name"), PropertyName = element.TryGetPropertyValue <string>("property_name"), FilterCondition = element.TryGetPropertyValue <int>("filter_condition"), FilterValue = element.TryGetPropertyValue <string>("filter_value"), FilterAndValue = element.TryGetPropertyValue <string>("filter_and_value") }; filters.Add(filter); } return(filters); }
public bool Partial(JArray TD) { if (!TD.Any()) { Console.WriteLine("no partial data"); return(false); } foreach (JObject item in TD) { Order or = new Order { Symbol = item["symbol"].ToString(), OrderQty = Convert.ToInt32(item["orderQty"].ToString()), ClOrdID = item["clOrdID"].ToString(), Side = item["side"].ToString(), StopPx = item["stopPx"].ToString(), OrdStatus = item["ordStatus"].ToString(), OrderId = item["orderID"].ToString() }; this.ordersDTO.TryInsertReplace(or); } return(true); }
public bool Update(JArray TD) { if (!TD.Any()) { Console.WriteLine("no update data"); return(false); } bool success = true; foreach (JObject item in TD) { string clOrdID = item["clOrdID"].ToString(); string stopPx = null; string ordStatus = null; int? orderQty = null; if (item.ContainsKey("stopPx")) { stopPx = item["stopPx"].ToString(); } if (item.ContainsKey("ordStatus")) { ordStatus = item["ordStatus"].ToString(); } if (item.ContainsKey("orderQty")) { orderQty = Convert.ToInt32(item["orderQty"].ToString()); } bool res = this.ordersDTO.TryUpdate(clOrdID, stopPx, ordStatus, orderQty); if (success = true && res == false) { success = res; } } return(success); }
/// <summary> /// Verifies the service implementation feature. /// </summary> /// <param name="context">The Interop service context</param> /// <param name="info">out parameter to return violation information when rule does not pass</param> /// <returns>true if the service implementation feature passes; false otherwise</returns> public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info) { if (context == null) { throw new ArgumentNullException("context"); } bool?passed = null; info = null; var svcStatus = ServiceStatus.GetInstance(); string entityTypeShortName; var propTypes = new string[2] { "Edm.Date", "Edm.DateTimeOffset" }; var propNames = MetadataHelper.GetPropertyNames(propTypes, out entityTypeShortName); if (null == propNames || !propNames.Any()) { return(passed); } string propName = propNames[0]; var entitySetUrl = entityTypeShortName.GetAccessEntitySetURL(); if (string.IsNullOrEmpty(entitySetUrl)) { return(passed); } string url = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl; var resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders); if (null != resp && HttpStatusCode.OK == resp.StatusCode) { JObject jObj = JObject.Parse(resp.ResponsePayload); JArray jArr = jObj.GetValue(Constants.Value) as JArray; var entity = jArr.First as JObject; var propVal = Convert.ToDateTime(entity[propName]).Hour; url = string.Format("{0}?$filter=hour({1}) eq {2}", url, propName, propVal); resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders); var detail = new ExtensionRuleResultDetail(this.Name, url, HttpMethod.Get, string.Empty); info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail); if (null != resp && HttpStatusCode.OK == resp.StatusCode) { jObj = JObject.Parse(resp.ResponsePayload); jArr = jObj.GetValue(Constants.Value) as JArray; if (null == jArr || !jArr.Any()) { return(false); } foreach (JObject et in jArr) { passed = Convert.ToDateTime(et[propName]).Hour == propVal; } } else { passed = false; } } return(passed); }
public async Task ReadFeedIteratorCore_CrossPartitionBiDirectional(bool useStatelessIteration) { ContainerInternal container = null; try { ContainerResponse containerResponse = await this.database.CreateContainerAsync( new ContainerProperties(id : Guid.NewGuid().ToString(), partitionKeyPath : "/id"), throughput : 50000, cancellationToken : this.cancellationToken); container = (ContainerInlineCore)containerResponse; // Create Items const int total = 30; QueryRequestOptions requestOptions = new QueryRequestOptions() { MaxItemCount = 10 }; List <string> items = new List <string>(); for (int i = 0; i < total; i++) { string item = $@" {{ ""id"": ""{i}"" }}"; using (ResponseMessage createResponse = await container.CreateItemStreamAsync( ReadFeedRangeTests.GenerateStreamFromString(item), new Cosmos.PartitionKey(i.ToString()))) { Assert.IsTrue(createResponse.IsSuccessStatusCode); } } string continuation = null; FeedIterator iter = container.GetItemQueryStreamIterator( continuationToken: continuation, requestOptions: requestOptions); int count = 0; List <string> forwardOrder = new List <string>(); while (iter.HasMoreResults) { if (useStatelessIteration) { iter = container.GetItemQueryStreamIterator( continuationToken: continuation, requestOptions: requestOptions); } using (ResponseMessage response = await iter.ReadNextAsync()) { Assert.IsNotNull(response); continuation = response.ContinuationToken; using (StreamReader reader = new StreamReader(response.Content)) { string json = await reader.ReadToEndAsync(); JArray documents = (JArray)JObject.Parse(json).SelectToken("Documents"); count += documents.Count; if (documents.Any()) { forwardOrder.Add(documents.First().SelectToken("id").ToString()); } } } } Assert.IsNotNull(forwardOrder); Assert.AreEqual(total, count); Assert.IsFalse(forwardOrder.Where(x => string.IsNullOrEmpty(x)).Any()); requestOptions.Properties = requestOptions.Properties = new Dictionary <string, object>() { { Documents.HttpConstants.HttpHeaders.EnumerationDirection, (byte)BinaryScanDirection.Reverse }, }; count = 0; List <string> reverseOrder = new List <string>(); continuation = null; iter = container .GetItemQueryStreamIterator(queryDefinition: null, continuationToken: continuation, requestOptions: requestOptions); while (iter.HasMoreResults) { if (useStatelessIteration) { iter = container .GetItemQueryStreamIterator(queryDefinition: null, continuationToken: continuation, requestOptions: requestOptions); } using (ResponseMessage response = await iter.ReadNextAsync()) { continuation = response.ContinuationToken; Assert.IsNotNull(response); using (StreamReader reader = new StreamReader(response.Content)) { string json = await reader.ReadToEndAsync(); JArray documents = (JArray)JObject.Parse(json).SelectToken("Documents"); count += documents.Count; if (documents.Any()) { reverseOrder.Add(documents.First().SelectToken("id").ToString()); } } } } Assert.IsNotNull(reverseOrder); Assert.AreEqual(total, count); forwardOrder.Reverse(); CollectionAssert.AreEqual(forwardOrder, reverseOrder); Assert.IsFalse(reverseOrder.Where(x => string.IsNullOrEmpty(x)).Any()); } finally { await container?.DeleteContainerAsync(); } }
/// <summary> /// ChangeToIdTokenFromAccessToken /// OIDC対応(AccessTokenからIdTokenを生成) /// </summary> /// <param name="access_token">string</param> /// <param name="code">string</param> /// <param name="HashClaimType">HashClaimType</param> /// <returns>IdToken</returns> /// <remarks> /// OIDC対応 /// </remarks> public static string ChangeToIdTokenFromAccessToken(string access_token, string code, HashClaimType hct) { if (access_token.Contains(".")) { string[] temp = access_token.Split('.'); string json = CustomEncode.ByteToString(CustomEncode.FromBase64UrlString(temp[1]), CustomEncode.UTF_8); Dictionary <string, object> authTokenClaimSet = JsonConvert.DeserializeObject <Dictionary <string, object> >(json); // ・access_tokenがJWTで、payloadに"nonce" and "scope=openidクレームが存在する場合、 if (authTokenClaimSet.ContainsKey("nonce") && authTokenClaimSet.ContainsKey("scopes")) { JArray scopes = (JArray)authTokenClaimSet["scopes"]; // ・OpenID Connect : response_type=codeに対応する。 if (scopes.Any(x => x.ToString() == ASPNETIdentityConst.Scope_Openid)) { //・payloadからscopeを削除する。 authTokenClaimSet.Remove("scopes"); //・payloadにat_hash, c_hashを追加する。 switch (hct) { case HashClaimType.None: break; case HashClaimType.AtHash: // at_hash authTokenClaimSet.Add( "at_hash", OidcTokenEditor.CreateHash(access_token)); break; case HashClaimType.CHash: // c_hash authTokenClaimSet.Add( "c_hash", OidcTokenEditor.CreateHash(code)); break; case HashClaimType.Both: // at_hash, c_hash authTokenClaimSet.Add( "at_hash", OidcTokenEditor.CreateHash(access_token)); authTokenClaimSet.Add( "c_hash", OidcTokenEditor.CreateHash(code)); break; } //・編集したpayloadを再度JWTとして署名する。 string newPayload = JsonConvert.SerializeObject(authTokenClaimSet); JWT_RS256 jwtRS256 = null; // 署名 jwtRS256 = new JWT_RS256(ASPNETIdentityConfig.OAuthJWT_pfx, ASPNETIdentityConfig.OAuthJWTPassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet); string id_token = jwtRS256.Create(newPayload); // 検証 jwtRS256 = new JWT_RS256(ASPNETIdentityConfig.OAuthJWT_cer, ASPNETIdentityConfig.OAuthJWTPassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet); if (jwtRS256.Verify(id_token)) { // 検証できた。 return(id_token); } else { // 検証できなかった。 } } else { // OIDCでない。 } } else { // OIDCでない。 } } else { // JWTでない。 } return(""); }
public JObject ToJson() { var ctl = new JObject(); if (TimeoutValue.HasValue) { ctl.Add(new JProperty("timeout", (long)TimeoutValue.Value.TotalMilliseconds)); } if (_scanConsistency.HasValue) { var consistency = new JObject( new JProperty("level", _scanConsistency.GetDescription())); if (_scanVectors != null && _scanVectors.Count > 0) { consistency.Add(new JProperty("vectors", _scanVectors)); } ctl.Add("consistency", consistency); } var parameters = new JObject(new JProperty("ctl", ctl)); if (_limit.HasValue) { parameters.Add(new JProperty("size", _limit)); } if (_skip.HasValue) { parameters.Add(new JProperty("from", _skip)); } if (!string.IsNullOrWhiteSpace(_highLightStyle)) { parameters.Add(new JProperty("highlight", new JObject( new JProperty("style", _highLightStyle), new JProperty("fields", _highLightFields)))); } if (_fields.Count > 0) { parameters.Add(new JProperty("fields", _fields)); } if (_facets != null && _facets.Count > 0) { var facets = new JObject(); _facets.ForEach(x => facets.Add(x.ToJson())); parameters.Add(new JProperty("facets", facets)); } if (_explain.HasValue) { parameters.Add(new JProperty("explain", _explain)); } if (_sort.Any()) { parameters.Add(new JProperty("sort", _sort)); } foreach (var rawParameter in _rawParameters) { parameters.Add(new JProperty(rawParameter.Key, rawParameter.Value)); } return(parameters); }
void BuildSupplementalFishData() { var comma = new string[] { ", " }; dynamic currentFishingSpot = null; JArray currentFishingSpotItems = null; dynamic currentNode = null; JArray currentNodeItems = null; var lines = Utils.Tsv(Path.Combine(Config.SupplementalPath, "FFXIV Data - Fishing.tsv")); foreach (var rLine in lines.Skip(1)) { // Line data var name = rLine[0]; // Name may reference either fishing spot, spearfishing node, or fish - check here. if (_builder.Db.SpearfishingNodesByName.TryGetValue(name, out var node)) { currentFishingSpot = null; currentFishingSpotItems = null; currentNode = node; currentNodeItems = node.items; continue; } if (_fishingSpotsByName.TryGetValue(name, out var fishingSpot)) { currentNode = null; currentNodeItems = null; currentFishingSpot = fishingSpot; currentFishingSpotItems = fishingSpot.items; continue; } // Fish info var bait = rLine[1]; var start = rLine[2]; var end = rLine[3]; var transition = rLine[4]; var weather = rLine[5]; var predator = rLine[6]; var tug = rLine[7]; var hookset = rLine[8]; var gathering = rLine[9]; var snagging = rLine[10]; var fishEyes = rLine[11]; var ff14anglerId = rLine[12]; Console.WriteLine(name); // Fill item fishing information. try { var item = GarlandDatabase.Instance.ItemsByName[name]; _fishItems.Add(item); // Some quest fish may not have been previously recognized as a fish. if (item.fish == null) { item.fish = new JObject(); } if (item.fish.spots == null) { item.fish.spots = new JArray(); } dynamic spot = new JObject(); if (currentFishingSpot != null) { spot.spot = currentFishingSpot.id; } else if (currentNode != null) { spot.node = currentNode.id; } // Sanity check weather and time restrictions. // Sanity check only applies to normal fishing spots. The // fields aren't available for spearfishing yet. if (currentFishingSpot != null) { CheckConditions(name, item.fish, ref weather, ref transition, ref start, ref end); } // Baits & Gigs if (bait.Contains("Gig Head")) { if (spot.gig == null) { spot.gig = new JArray(); } spot.gig.Add(bait); } else if (!string.IsNullOrEmpty(bait)) { spot.tmpBait = bait; // If not otherwise specified, fish should inherit the time // and weather restrictions of restricted bait (like predators). if (!_builder.Db.ItemsByName.TryGetValue(bait, out var baitItem)) { throw new InvalidOperationException($"Can't find bait {bait} for {name} at {currentFishingSpot.en.name}. Is the spelling correct?"); } if (baitItem.fish != null) { dynamic baitSpotView = ((JArray)baitItem.fish?.spots)?.FirstOrDefault(s => s["spot"] == spot.spot && s["node"] == spot.node); if (baitSpotView == null) { throw new InvalidOperationException($"Can't find mooch {bait} for {name} at {currentFishingSpot.en.name}. Did you forget to add it to the spot?"); } InheritConditions(spot, baitSpotView, weather, transition, start, end); } } // Time restrictions if (start != "" || end != "") { spot.during = new JObject(); if (start != "") { spot.during.start = int.Parse(start); } if (end != "") { spot.during.end = int.Parse(end); } } // Weather restrictions if (transition != "") { var transitionList = transition.Split(comma, StringSplitOptions.None); CheckWeather(transitionList); spot.transition = new JArray(transitionList); } if (weather != "") { var weatherList = weather.Split(comma, StringSplitOptions.None); CheckWeather(weatherList); spot.weather = new JArray(weatherList); } // Predators if (predator != "") { var tokens = predator.Split(comma, StringSplitOptions.None); spot.predator = new JArray(); for (var i = 0; i < tokens.Length; i += 2) { var predatorName = tokens[i]; spot.predator.Add(BuildPredator(predatorName, tokens[i + 1])); // If not otherwise specified, fish should inherit the time // and weather restrictions of restricted predators (like bait). var predatorItem = _builder.Db.ItemsByName[predatorName]; if (predatorItem.fish != null) { var predatorSpots = (JArray)predatorItem.fish.spots; dynamic predatorSpotView = predatorSpots.FirstOrDefault(s => s["spot"] == spot.spot && s["node"] == spot.node); if (predatorSpotView == null) { // Predators for spearfishing nodes may not exist on this spot/node. // Fallback to any available spot. predatorSpotView = predatorSpots.FirstOrDefault(); if (predatorSpotView == null) { throw new InvalidOperationException($"Can't find predator view for {name} predator {predatorName}."); } } InheritConditions(spot, predatorSpotView, weather, transition, start, end); } } } // Other properties. if (hookset != "") { spot.hookset = hookset + " Hookset"; } if (gathering != "") { spot.gatheringReq = int.Parse(gathering); } if (snagging != "") { spot.snagging = 1; } if (fishEyes != "") { spot.fishEyes = 1; } if (ff14anglerId != "") { spot.ff14anglerId = int.Parse(ff14anglerId); } // Add the fish to this gathering point if it's not otherwise there. if (currentFishingSpot != null && !currentFishingSpotItems.Any(i => (int)i["id"] == (int)item.id)) { if (item.fishingSpots == null) { item.fishingSpots = new JArray(); } item.fishingSpots.Add(currentFishingSpot.id); dynamic obj = new JObject(); obj.id = item.id; obj.lvl = item.ilvl; currentFishingSpot.items.Add(obj); _builder.Db.AddReference(currentFishingSpot, "item", (int)item.id, false); _builder.Db.AddReference(item, "fishing", (int)currentFishingSpot.id, true); } if (currentNode != null && !currentNodeItems.Any(i => (int)i["id"] == (int)item.id)) { if (item.nodes == null) { item.nodes = new JArray(); } item.nodes.Add(currentNode.id); dynamic obj = new JObject(); obj.id = item.id; currentNodeItems.Add(obj); _builder.Db.AddReference(currentNode, "item", (int)item.id, false); _builder.Db.AddReference(item, "node", (int)currentNode.id, true); } item.fish.spots.Add(spot); } catch (KeyNotFoundException e) { Console.WriteLine("No item found with name" + name); } } }
public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> InvertedInputVars, Message message) { JArray jarray = (JArray)vars["JArray"]; if (jarray.HasValues) { DBConnection db = COREobject.i.Entitron; bool searchInShared = vars.ContainsKey("SearchInShared") ? (bool)vars["SearchInShared"] : false; string tableName = vars.ContainsKey("TableName") ? (string)vars["TableName"] : (string)vars["__TableName__"]; DBTable table = db.Table(tableName, searchInShared); if (table == null) { throw new Exception($"Queried table not found (Tabulka: {tableName}, Akce: {Name} ({Id}))"); } var listDbItem = table.Select().ToList(); //check if table has column (IsDeleted),if no , the result is null var columnIsDeletedExist = table.Columns.SingleOrDefault(c => c.Name == "IsDeleted"); string uniqueCol; string uniqueExtCol; //basicly foreign key if (vars.ContainsKey("UniqueCol")) { uniqueCol = (string)vars["UniqueCol"]; uniqueExtCol = uniqueCol; } else { uniqueCol = "ext_id"; uniqueExtCol = DBCommandSet.PrimaryKey; } if (!table.Columns.Any(c => c.Name == uniqueCol)) { throw new Exception($"Table column named '{uniqueCol}' not found!"); } foreach (JObject jo in jarray) { if (columnIsDeletedExist != null) { //if theres column IsDeleted, check if the entity is in rising, if not, set isDeleted to true. for (int i = 0; i < listDbItem.Count; i++) { if (!jarray.Any(j => j["id"].ToString() == listDbItem[i]["ext_id"].ToString())) { DBItem foundItem = listDbItem[i]; foundItem["IsDeleted"] = true; table.Update(foundItem, (int)foundItem["id"]); } } } Dictionary <string, object> parsedColumns = new Dictionary <string, object>(); TapestryUtils.ParseJObjectRecursively(jo, parsedColumns); DBItem parsedRow = new DBItem(db, table, parsedColumns); DBItem updatedRow = table.Select().Where(c => c.Column(uniqueCol).Equal(parsedRow[uniqueExtCol])).FirstOrDefault(); if (updatedRow != null) //update { foreach (var col in parsedRow.getColumnNames()) { if (updatedRow.getColumnNames().Contains(col) && col != DBCommandSet.PrimaryKey && col != uniqueCol) { updatedRow[col] = parsedRow[col]; } } table.Update(updatedRow, (int)updatedRow[DBCommandSet.PrimaryKey]); } else // insert row if it does not exist { DBItem item = new DBItem(db, table); foreach (DBColumn col in table.Columns) { if (col.Name == DBCommandSet.PrimaryKey) { continue; } string parsedColName = (col.Name == "ext_id") ? DBCommandSet.PrimaryKey : col.Name; item[col.Name] = parsedRow[parsedColName]; } table.Add(item); } } db.SaveChanges(); outputVars["Result"] = true; } else { Watchtower.OmniusLog.Log($"{Name}: Input JArray has no values! Action aborted", Watchtower.OmniusLogLevel.Warning); outputVars["Result"] = false; } }
public IActionResult Post([FromQuery] QueryArgs queryArgs, [FromBody] JArray jArray) { try { if (jArray == null || !jArray.Any()) { return(JsonResultModel.Error($"Parameter invalid:data = null")); } //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); queryContext.MetaObject = metaObjectService.GetById(queryContext.MetaObjectId); if (queryContext.MetaObject == null) { return(JsonResultModel.Error($"未能找到对象Id为[{queryContext.MetaObjectId}]对应的对象信息")); } int successCount = 0; int errorCount = 0; List <BsonDocument> documents = new List <BsonDocument>(); foreach (var item in jArray) { try { var json = item.ToString(); documents.Add(BsonDocument.Parse(json)); successCount++; } catch (Exception) { errorCount++; } } //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_BatchAdd); //trigger before documents = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_BatchAdd_Before, documents, CurrentApplicationContext, queryContext.InterfaceCode, documents); //check data by form if (queryContext.FormId != default(int)) { var formCheckResult = _formMetaFieldService.ValidateFormData(queryContext.FormId, documents); if (!formCheckResult.IsSuccess) { return(formCheckResult.ToJsonResultModel()); } } //add data var addResult = dataAccessService.BatchAdd(queryContext.TenantId, queryContext.MetaObject, documents); //trigger after _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_BatchAdd_After, documents, CurrentApplicationContext, queryContext.InterfaceCode, documents); return(addResult.ToJsonResultModel()); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
public static ICollection <SCIMRepresentationAttribute> BuildAttributes(JArray jArr, SCIMSchemaAttribute schemaAttribute, SCIMSchema schema, bool ignoreUnsupportedCanonicalValues) { var result = new List <SCIMRepresentationAttribute>(); if (schemaAttribute.Mutability == SCIMSchemaAttributeMutabilities.READONLY) { return(result); } var attributeId = Guid.NewGuid().ToString(); if (schemaAttribute.Type == SCIMSchemaAttributeTypes.COMPLEX) { if (!jArr.Any()) { result.Add(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id)); } else { foreach (var jsonProperty in jArr) { var rec = jsonProperty as JObject; if (rec == null) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidJSON, jsonProperty.ToString())); } var subAttributes = schema.GetChildren(schemaAttribute).ToList(); CheckRequiredAttributes(schema, subAttributes, rec); var resolutionResult = Resolve(rec, schema, subAttributes); var parent = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id); var children = BuildRepresentationAttributes(resolutionResult, subAttributes, ignoreUnsupportedCanonicalValues); foreach (var child in children) { if (SCIMRepresentation.GetParentPath(child.FullPath) == parent.FullPath) { child.ParentAttributeId = parent.Id; } result.Add(child); } result.Add(parent); } } } else { switch (schemaAttribute.Type) { case SCIMSchemaAttributeTypes.BOOLEAN: var valuesBooleanResult = Extract <bool>(jArr); if (valuesBooleanResult.InvalidValues.Any()) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidBoolean, string.Join(",", valuesBooleanResult.InvalidValues))); } foreach (var b in valuesBooleanResult.Values) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueBoolean: b); result.Add(record); } break; case SCIMSchemaAttributeTypes.INTEGER: var valuesIntegerResult = Extract <int>(jArr); if (valuesIntegerResult.InvalidValues.Any()) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidInteger, string.Join(",", valuesIntegerResult.InvalidValues))); } foreach (var i in valuesIntegerResult.Values) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueInteger: i); result.Add(record); } break; case SCIMSchemaAttributeTypes.DATETIME: var valuesDateTimeResult = Extract <DateTime>(jArr); if (valuesDateTimeResult.InvalidValues.Any()) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidDateTime, string.Join(",", valuesDateTimeResult.InvalidValues))); } foreach (var d in valuesDateTimeResult.Values) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueDateTime: d); result.Add(record); } break; case SCIMSchemaAttributeTypes.STRING: var strs = jArr.Select(j => j.ToString()).ToList(); if (schemaAttribute.CanonicalValues != null && schemaAttribute.CanonicalValues.Any() && !ignoreUnsupportedCanonicalValues && !strs.All(_ => schemaAttribute.CaseExact ? schemaAttribute.CanonicalValues.Contains(_) : schemaAttribute.CanonicalValues.Contains(_, StringComparer.OrdinalIgnoreCase)) ) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidCanonicalValue, schemaAttribute.Name)); } foreach (var s in strs) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueString: s); result.Add(record); } break; case SCIMSchemaAttributeTypes.REFERENCE: var refs = jArr.Select(j => j.ToString()).ToList(); foreach (var reference in refs) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueReference: reference); result.Add(record); } break; case SCIMSchemaAttributeTypes.DECIMAL: var valuesDecimalResult = Extract <decimal>(jArr); if (valuesDecimalResult.InvalidValues.Any()) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidDecimal, string.Join(",", valuesDecimalResult.InvalidValues))); } foreach (var d in valuesDecimalResult.Values) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueDecimal: d); result.Add(record); } break; case SCIMSchemaAttributeTypes.BINARY: var invalidValues = new List <string>(); var valuesBinary = new List <string>(); foreach (var rec in jArr) { try { Convert.FromBase64String(rec.ToString()); valuesBinary.Add(rec.ToString()); } catch (FormatException) { invalidValues.Add(rec.ToString()); } } if (invalidValues.Any()) { throw new SCIMSchemaViolatedException(string.Format(Global.NotValidBase64, string.Join(",", invalidValues))); } foreach (var b in valuesBinary) { var record = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), attributeId, schemaAttribute, schema.Id, valueBinary: b); result.Add(record); } break; } } return(result); }
public JsonResult Import(int groupid, HttpPostedFileBase fileupload) { string IdUser = User.Identity.GetUserId(); string AppPath = AppDomain.CurrentDomain.BaseDirectory; HttpStatusCode status = HttpStatusCode.OK; string message; object response; Group group; Process pr; try { using (var scope = new TransactionScope()) { ZipFile zip = ZipFile.Read(fileupload.InputStream); ZipEntry jsonFile = zip.FirstOrDefault(x => x.FileName == "data.json"); if (jsonFile == null) { throw new ServerSideException("File is damaged, please try other file"); } //jsonFile.Password = "******"; var passsword = "clockworks-pms"; JObject data; using (StreamReader sr = new StreamReader(jsonFile.OpenReader(passsword), Encoding.UTF8)) { data = JsonConvert.DeserializeObject <JObject>(sr.ReadToEnd()); } //xử lý data group = groupService.findGroup(groupid); //process pr = new Process(); pr.Name = (string)data["processname"]; pr.Description = (string)data["description"]; pr.IdOwner = IdUser; pr.IdGroup = groupid; pr.DataJson = data["draw"].ToString(); pr.Avatar = (string)data["avatar"]; pr.IsRun = false; pr.Created_At = DateTime.Now; pr.Updated_At = DateTime.Now; db.Processes.Add(pr); db.SaveChanges(); //file process JArray processFile = (JArray)data["files"]; if (processFile.Any()) { foreach (JToken file in processFile) { ZipEntry f = zip.FirstOrDefault(x => x.FileName == string.Format("Upload/{0}/{1}", (string)data["processid"], file.ToString())); if (f != null) { Stream st = f.OpenReader(); ZipInputStream zp = new ZipInputStream(st); string processPath = string.Format("Upload/{0}/{1}", groupid.ToString(), pr.Id.ToString()); fileService.createDirectory(processPath); //System.IO.File.SetAttributes(Path.Combine(AppPath, processPath), FileAttributes.Temporary); using (FileStream fileStream = System.IO.File.Create(string.Format("{0}/{1}/{2}", AppPath, processPath, file.ToString()))) { string fileId; do { fileId = commonService.getRandomString(50); } while (fileService.findFile(fileId) != null); FileManager fm = new FileManager(); fm.Id = fileId; fm.IdGroup = groupid; fm.Name = Path.GetFileName(fileStream.Name); fm.Type = Path.GetExtension(fileStream.Name); fm.Path = processPath; fm.Direction = Direction.Process.ToString(); fm.Create_At = DateTime.Now; fm.Update_At = DateTime.Now; db.FileManagers.Add(fm); //zp.Seek(0, SeekOrigin.Begin); zp.CopyTo(fileStream); } } } } //role JArray roles = (JArray)data["roles"]; List <Role> roleList = new List <Role>(); foreach (var role in roles) { Role rl = new Role { Process = pr }; rl.IdProcess = pr.Id; rl.Name = (string)role["rolename"]; rl.Description = (string)role["description"]; rl.IsRun = false; rl.Create_At = DateTime.Now; rl.Update_At = DateTime.Now; roleList.Add(rl); } db.Roles.AddRange(roleList); db.SaveChanges(); JArray steps = (JArray)data["steps"]; foreach (JToken step in steps) { Step st = new Step { Process = pr }; st.IdProcess = pr.Id; st.Name = (string)step["stepname"]; st.Description = (string)step["description"]; st.StartStep = (bool)step["draw"]["isStartStep"]; st.Key = (int)step["draw"]["key"]; st.Figure = (string)step["draw"]["figure"]; st.NextStep1 = (int)step["draw"]["nextstep1"]; st.NextStep2 = (int)step["draw"]["nextstep2"]; st.Color = commonService.getRandomColor(); st.IsRun = false; st.Created_At = DateTime.Now; st.Updated_At = DateTime.Now; db.Steps.Add(st); db.SaveChanges(); //File Step JArray stepFile = (JArray)step["files"]; if (stepFile.Any()) { foreach (JToken file in stepFile) { ZipEntry f = zip.FirstOrDefault(x => x.FileName == string.Format("Upload/{0}/{1}/{2}", (string)data["processid"], (string)step["stepid"], file.ToString())); if (f != null) { Stream stm = f.OpenReader(); ZipInputStream zp = new ZipInputStream(stm); string stepPath = string.Format("Upload/{0}/{1}/{2}", groupid.ToString(), pr.Id.ToString(), st.Id.ToString()); fileService.createDirectory(stepPath); //System.IO.File.SetAttributes(Path.Combine(AppPath, processPath), FileAttributes.Temporary); using (FileStream fileStream = System.IO.File.Create(string.Format("{0}/{1}/{2}", AppPath, stepPath, file.ToString()))) { string fileId; do { fileId = commonService.getRandomString(50); } while (fileService.findFile(fileId) != null); FileManager fm = new FileManager(); fm.Id = fileId; fm.IdGroup = groupid; fm.Name = Path.GetFileName(fileStream.Name); fm.Type = Path.GetExtension(fileStream.Name); fm.Path = stepPath; fm.Direction = Direction.Step.ToString(); fm.Create_At = DateTime.Now; fm.Update_At = DateTime.Now; db.FileManagers.Add(fm); //zp.Seek(0, SeekOrigin.Begin); zp.CopyTo(fileStream); } } } } //Task JArray tasks = (JArray)step["tasks"]; foreach (JToken task in tasks) { int?rid; if ((string)task["role"] == "") { rid = null; } else { rid = roleList.First(x => x.Name == (string)task["role"]).Id; } string jText = task["config"]["input"].ToString(); string jFile = task["config"]["file"].ToString(); string jForm = task["config"]["form"].ToString(); TaskProcess tk = new TaskProcess { Step = st }; tk.IdStep = st.Id; tk.IdRole = rid; tk.Name = (string)task["taskname"]; tk.Description = (string)task["description"]; if (jText != "") { tk.ValueInputText = jText; } if (jFile != "") { tk.ValueInputFile = jFile; } if (jForm != "") { tk.ValueFormJson = jForm; } tk.Color = commonService.getRandomColor(); tk.Position = (int)task["position"]; tk.IsRun = false; tk.Created_At = DateTime.Now; tk.Updated_At = DateTime.Now; db.TaskProcesses.Add(tk); db.SaveChanges(); //file task //File Step JArray taskFile = (JArray)task["files"]; if (taskFile.Any()) { foreach (JToken file in taskFile) { ZipEntry f = zip.FirstOrDefault(x => x.FileName == string.Format("Upload/{0}/{1}/{2}/{3}", (string)data["processid"], (string)step["stepid"], (string)step["taskid"], file.ToString())); if (f != null) { Stream stm = f.OpenReader(); ZipInputStream zp = new ZipInputStream(stm); string taskPath = string.Format("Upload/{0}/{1}/{2}/{3}", groupid.ToString(), pr.Id.ToString(), st.Id.ToString(), tk.Id.ToString()); fileService.createDirectory(taskPath); //System.IO.File.SetAttributes(Path.Combine(AppPath, processPath), FileAttributes.Temporary); using (FileStream fileStream = System.IO.File.Create(string.Format("{0}/{1}/{2}", AppPath, taskPath, file.ToString()))) { string fileId; do { fileId = commonService.getRandomString(50); } while (fileService.findFile(fileId) != null); FileManager fm = new FileManager(); fm.Id = fileId; fm.IdGroup = groupid; fm.Name = Path.GetFileName(fileStream.Name); fm.Type = Path.GetExtension(fileStream.Name); fm.Path = taskPath; fm.Direction = Direction.Task.ToString(); fm.Create_At = DateTime.Now; fm.Update_At = DateTime.Now; db.FileManagers.Add(fm); //zp.Seek(0, SeekOrigin.Begin); zp.CopyTo(fileStream); } } } } } db.SaveChanges(); } //process scope.Complete(); } message = "Import Sucess"; object d = new { groupid = group.Id, groupslug = group.groupSlug, processid = pr.Id, }; response = new { message = message, data = d, status = status }; return(Json(response, JsonRequestBehavior.AllowGet)); } catch (Exception e) { status = HttpStatusCode.InternalServerError; message = e.GetType().Name == "ServerSideException" ? e.Message : "Something not right"; response = new { message = message, detail = e.Message, status = status }; return(Json(response, JsonRequestBehavior.AllowGet)); } }
private async Task DoWork() { while (!_source.IsCancellationRequested) { try { // determine if we need to write to log yet if (DateTime.UtcNow.Subtract(_lastrun) > TimeSpan.FromMilliseconds(Interval)) { if (_hasOrphans) { var result = new JArray(); AddServiceToResult(result, CouchbaseTags.ServiceKv, _kvOrphans, ref _kvOrphanCount); AddServiceToResult(result, CouchbaseTags.ServiceView, _viewOrphans, ref _viewOrphanCount); AddServiceToResult(result, CouchbaseTags.ServiceQuery, _queryOrphans, ref _queryOrphanCount); AddServiceToResult(result, CouchbaseTags.ServiceSearch, _searchOrphans, ref _searchOrphanCount); AddServiceToResult(result, CouchbaseTags.ServiceAnalytics, _analyticsOrphans, ref _analyticsOrphanCount); if (result.Any()) { Log.Warn("Orphaned responses observed: {0}", result.ToString(Formatting.None)); } _hasOrphans = false; } _lastrun = DateTime.UtcNow; } while (_queue.TryTake(out var context, WorkerSleep, _source.Token)) { // protects against there being lots of orphans blocking the process from existing if cancelled if (_source.IsCancellationRequested) { break; } switch (context.ServiceType) { case CouchbaseTags.ServiceKv: AddContextToService(_kvOrphans, context, ref _kvOrphanCount, SampleSize); break; case CouchbaseTags.ServiceView: AddContextToService(_viewOrphans, context, ref _viewOrphanCount, SampleSize); break; case CouchbaseTags.ServiceQuery: AddContextToService(_queryOrphans, context, ref _queryOrphanCount, SampleSize); break; case CouchbaseTags.ServiceSearch: AddContextToService(_searchOrphans, context, ref _searchOrphanCount, SampleSize); break; case CouchbaseTags.ServiceAnalytics: AddContextToService(_analyticsOrphans, context, ref _analyticsOrphanCount, SampleSize); break; default: Log.Info($"Unknown service type {context.ServiceType} for operation with ID '{context.OperationId}'"); break; } _hasOrphans = true; // indicates we have something to process } // sleep for a little while await Task.Delay(TimeSpan.FromMilliseconds(WorkerSleep), _source.Token).ContinueOnAnyContext(); } catch (ObjectDisposedException) { } // ignore catch (OperationCanceledException) { } // ignore catch (Exception exception) { Log.Error("Error when procesing Orphaned Responses", exception); } } }
void AddItemTrades(DatabaseBuilder builder, string itemId, string[] relatedItemIds, GtShopListing listing) { // Trade structure { // shop: shopName, // npcs: [ npc id 1, npc id 2, ... ], // listings: [ { shop entry 1 }, ... ] // } object itemKey = itemId; if (int.TryParse(itemId, out var itemNumber)) { itemKey = itemNumber; } if (!builder.Db.ItemsById.TryGetValue(itemKey, out var item)) { throw new InvalidOperationException(); } // Find the side this trade item is on in the trade. JArray trades; if (listing.Costs.Any(l => l.ItemId == itemId)) { if (item.tradeCurrency == null) { item.tradeCurrency = new JArray(); } trades = item.tradeCurrency; } else if (listing.Rewards.Any(l => l.ItemId == itemId)) { if (item.tradeShops == null) { item.tradeShops = new JArray(); } trades = item.tradeShops; } else { throw new InvalidOperationException("No visible trades"); } // Find the shop name in this trade array. dynamic shop = trades.FirstOrDefault(t => (string)t["shop"] == Name); if (shop == null) { shop = new JObject(); shop.shop = Name; shop.npcs = new JArray(); shop.listings = new JArray(); trades.Add(shop); } // Add related NPCs. foreach (var sNpc in ENpcs) { var npc = builder.Db.NpcsById[sNpc.Key]; builder.Db.AddReference(item, "npc", sNpc.Key, true); builder.Db.AddReference(npc, "item", relatedItemIds, false); JArray shopNpcs = shop.npcs; if (!shopNpcs.Any(t => (int)t == sNpc.Key)) { shopNpcs.Add(sNpc.Key); } } // Finally, add the shop listing. var entry = builder.CreateShopEntry(listing.Costs, listing.Rewards); if (!HasShopEntry((JArray)shop.listings, entry)) { var otherItemIds = relatedItemIds.Where(id => id != itemId); builder.Db.AddReference(item, "item", otherItemIds, true); shop.listings.Add(entry); } }
public async Task CrossPartitionBiDirectionalItemReadFeedTest(bool useStatelessIteration) { //create items const int total = 30; const int maxItemCount = 10; List <string> items = new List <string>(); for (int i = 0; i < total; i++) { string item = $@" {{ ""id"": ""{i}"" }}"; using (ResponseMessage createResponse = await this.Container.CreateItemStreamAsync( CosmosReadFeedTests.GenerateStreamFromString(item), new Cosmos.PartitionKey(i.ToString()))) { Assert.IsTrue(createResponse.IsSuccessStatusCode); } } string lastKnownContinuationToken = null; FeedIterator iter = this.Container.Database.GetContainer(this.Container.Id) .GetItemStreamIterator(maxItemCount, continuationToken: lastKnownContinuationToken); int count = 0; List <string> forwardOrder = new List <string>(); while (iter.HasMoreResults) { if (useStatelessIteration) { iter = this.Container.Database.GetContainer(this.Container.Id) .GetItemStreamIterator(maxItemCount, continuationToken: lastKnownContinuationToken); } using (ResponseMessage response = await iter.ReadNextAsync()) { lastKnownContinuationToken = response.Headers.Continuation; Assert.IsNotNull(response); using (StreamReader reader = new StreamReader(response.Content)) { string json = await reader.ReadToEndAsync(); JArray documents = (JArray)JObject.Parse(json).SelectToken("Documents"); count += documents.Count; if (documents.Any()) { forwardOrder.Add(documents.First().SelectToken("id").ToString()); } } } } Assert.IsNull(lastKnownContinuationToken); Assert.IsNotNull(forwardOrder); Assert.AreEqual(total, count); Assert.IsFalse(forwardOrder.Where(x => string.IsNullOrEmpty(x)).Any()); ItemRequestOptions requestOptions = new ItemRequestOptions(); requestOptions.Properties = requestOptions.Properties = new Dictionary <string, object>(); requestOptions.Properties.Add(HttpConstants.HttpHeaders.EnumerationDirection, (byte)BinaryScanDirection.Reverse); count = 0; List <string> reverseOrder = new List <string>(); lastKnownContinuationToken = null; iter = this.Container.Database.GetContainer(this.Container.Id) .GetItemStreamIterator(maxItemCount, continuationToken: lastKnownContinuationToken, requestOptions: requestOptions); while (iter.HasMoreResults) { if (useStatelessIteration) { iter = this.Container.Database.GetContainer(this.Container.Id) .GetItemStreamIterator(maxItemCount, continuationToken: lastKnownContinuationToken, requestOptions: requestOptions); } using (ResponseMessage response = await iter.ReadNextAsync()) { lastKnownContinuationToken = response.Headers.Continuation; Assert.IsNotNull(response); using (StreamReader reader = new StreamReader(response.Content)) { string json = await reader.ReadToEndAsync(); JArray documents = (JArray)JObject.Parse(json).SelectToken("Documents"); count += documents.Count; if (documents.Any()) { reverseOrder.Add(documents.First().SelectToken("id").ToString()); } } } } Assert.IsNull(lastKnownContinuationToken); Assert.IsNotNull(reverseOrder); Assert.AreEqual(total, count); forwardOrder.Reverse(); CollectionAssert.AreEqual(forwardOrder, reverseOrder); Assert.IsFalse(reverseOrder.Where(x => string.IsNullOrEmpty(x)).Any()); }
protected override async Task <ExchangeOrderResult> OnGetOrderDetailsAsync(string orderId, string symbol = null) { //{ // "status": "Finished", // "id": 1022694747, // "transactions": [ // { // "fee": "0.000002", // "bch": "0.00882714", // "price": "0.12120000", // "datetime": "2018-02-24 14:15:29.133824", // "btc": "0.0010698493680000", // "tid": 56293144, // "type": 2 // }] //} if (string.IsNullOrWhiteSpace(orderId)) { return(null); } string url = "/order_status/"; Dictionary <string, object> payload = await OnGetNoncePayloadAsync(); payload["id"] = orderId; JObject result = await MakeJsonRequestAsync <JObject>(url, null, payload, "POST"); // status can be 'In Queue', 'Open' or 'Finished' JArray transactions = result["transactions"] as JArray; // empty transaction array means that order is InQueue or Open and AmountFilled == 0 // return empty order in this case. no any additional info available at this point if (!transactions.Any()) { return(new ExchangeOrderResult() { OrderId = orderId }); } JObject first = transactions.First() as JObject; List <string> excludeStrings = new List <string>() { "tid", "price", "fee", "datetime", "type", "btc", "usd", "eur" }; string baseCurrency; string marketCurrency = first.Properties().FirstOrDefault(p => !excludeStrings.Contains(p.Name, StringComparer.InvariantCultureIgnoreCase))?.Name; if (string.IsNullOrWhiteSpace(marketCurrency)) { // the only 2 cases are BTC-USD and BTC-EUR marketCurrency = "btc"; excludeStrings.RemoveAll(s => s.Equals("usd") || s.Equals("eur")); baseCurrency = first.Properties().FirstOrDefault(p => !excludeStrings.Contains(p.Name, StringComparer.InvariantCultureIgnoreCase))?.Name; } else { excludeStrings.RemoveAll(s => s.Equals("usd") || s.Equals("eur") || s.Equals("btc")); excludeStrings.Add(marketCurrency); baseCurrency = first.Properties().FirstOrDefault(p => !excludeStrings.Contains(p.Name, StringComparer.InvariantCultureIgnoreCase))?.Name; } string _symbol = $"{marketCurrency}-{baseCurrency}"; decimal amountFilled = 0, spentBaseCurrency = 0, price = 0; foreach (var t in transactions) { int type = t["type"].ConvertInvariant <int>(); if (type != 2) { continue; } spentBaseCurrency += t[baseCurrency].ConvertInvariant <decimal>(); amountFilled += t[marketCurrency].ConvertInvariant <decimal>(); //set price only one time if (price == 0) { price = t["price"].ConvertInvariant <decimal>(); } } // No way to know if order IsBuy, Amount, OrderDate return(new ExchangeOrderResult() { AmountFilled = amountFilled, Symbol = _symbol, AveragePrice = spentBaseCurrency / amountFilled, Price = price, }); }
void BuildQuests() { var lQuestsByKey = _builder.Libra.Table <Libra.Quest>().ToDictionary(q => q.Key); foreach (var sQuest in _builder.Sheet <Saint.Quest>()) { if (sQuest.Key == 65536 || sQuest.Name == "") { continue; // Test quests } dynamic quest = new JObject(); quest.id = sQuest.Key; _builder.Localize.Strings((JObject)quest, sQuest, Utils.SanitizeQuestName, "Name"); quest.patch = PatchDatabase.Get("quest", sQuest.Key); quest.sort = sQuest.SortKey; // Quest location var questIssuer = (sQuest.IssuingENpc?.Locations?.Count() ?? 0) > 0 ? sQuest.IssuingENpc : null; var sPlaceName = sQuest.PlaceName; if (sPlaceName.Name == "" && questIssuer != null) { sPlaceName = questIssuer.Locations.First().PlaceName; } _builder.Localize.Column((JObject)quest, sPlaceName, "Name", "location", x => x == "" ? "???" : x.ToString()); // Repeatability if (sQuest.RepeatInterval == Saint.QuestRepeatInterval.Daily) { quest.interval = "daily"; } else if (sQuest.RepeatInterval == Saint.QuestRepeatInterval.Weekly) { quest.interval = "weekly"; } if (sQuest.IsRepeatable) { quest.repeatable = 1; } // Miscellaneous if (sQuest.Icon != null) { quest.icon = IconDatabase.EnsureEntry("quest", sQuest.Icon); } if (sQuest.BeastTribe.Key != 0) { quest.beast = sQuest.BeastTribe.Key; } ImportQuestEventIcon(quest, sQuest); // Quest issuer if (questIssuer != null) { var npc = AddQuestNpc(quest, questIssuer); if (npc != null) { quest.issuer = questIssuer.Key; } } // Quest target var questTarget = sQuest.TargetENpc; if (questTarget != null) { var npc = AddQuestNpc(quest, questTarget); if (npc != null) { quest.target = questTarget.Key; } } // Involved if (_npcsByQuestKey.TryGetValue(sQuest.Key, out var involvedNpcKeys)) { foreach (var npcKey in involvedNpcKeys) { var sInvolvedEnpc = _builder.Realm.GameData.ENpcs[npcKey]; if (sInvolvedEnpc == null || sInvolvedEnpc == questTarget || sInvolvedEnpc == questIssuer) { continue; } var npc = AddQuestNpc(quest, sInvolvedEnpc); if (npc == null) { continue; } if (quest.involved == null) { quest.involved = new JArray(); } quest.involved.Add(npcKey); } } // Journal Genre quest.genre = sQuest.JournalGenre.Key; // Rewards dynamic rewards = new JObject(); if (sQuest.Rewards.Gil > 0) { rewards.gil = sQuest.Rewards.Gil; } if (sQuest.Rewards.Emote.Key > 0) { rewards.emote = sQuest.Rewards.Emote.Name.ToString(); } if (sQuest.Rewards.ClassJob.Key > 0) { rewards.job = sQuest.Rewards.ClassJob.Key; } if (sQuest.AsInt32("CurrencyRewardCount") > 0) { rewards.gcseal = sQuest.AsInt32("CurrencyRewardCount"); } if (sQuest.Rewards.Action.Key > 0) { rewards.action = sQuest.Rewards.Action.Key; _builder.Db.AddReference(quest, "action", sQuest.Rewards.Action.Key, false); } var sInstanceContentReward = sQuest.Rewards.InstanceContent; if (sInstanceContentReward.Key > 0) { var instance = _builder.Db.Instances.FirstOrDefault(i => i.id == sInstanceContentReward.Key); if (instance != null) { instance.unlockedByQuest = sQuest.Key; rewards.instance = sInstanceContentReward.Key; _builder.Db.AddReference(quest, "instance", sInstanceContentReward.Key, false); _builder.Db.AddReference(instance, "quest", sQuest.Key, false); } } if (sQuest.Rewards.Reputation > 0) { rewards.reputation = sQuest.Rewards.Reputation; } if (sQuest.Rewards.QuestRewardOther.Name == "Aether Current") { rewards.aetherCurrent = 1; } foreach (var sQuestRewardItemGroup in sQuest.Rewards.Items) { foreach (var sQuestRewardItem in sQuestRewardItemGroup.Items) { if (rewards.items == null) { rewards.items = new JArray(); } var maxCount = sQuestRewardItem.Counts.Max(); dynamic o = new JObject(); if (maxCount > 1) { o.num = maxCount; } o.id = sQuestRewardItem.Item.Key; if (sQuestRewardItemGroup.Type == Saint.QuestRewardGroupType.One) { o.one = 1; } if (sQuestRewardItem.IsHq) { o.hq = 1; } rewards.items.Add(o); try { var item = _builder.Db.ItemsById[sQuestRewardItem.Item.Key]; if (item.quests == null) { item.quests = new JArray(); } JArray quests = item.quests; if (!quests.Any(id => ((int)id) == sQuest.Key)) { quests.Add(sQuest.Key); } _builder.Db.AddReference(item, "quest", sQuest.Key, false); } catch (KeyNotFoundException ignored) { DatabaseBuilder.PrintLine($"Reward item '{sQuestRewardItem.Item.Key}' not found for Quest '{quest.Key}'."); } _builder.Db.AddReference(quest, "item", sQuestRewardItem.Item.Key, false); } } // Libra supplemental rewards. if (lQuestsByKey.TryGetValue(sQuest.Key, out var lQuest)) { dynamic data = JsonConvert.DeserializeObject(lQuest.data); int xp = 0; if (data.exp != null && int.TryParse((string)data.exp, out xp)) { rewards.xp = xp; } } // Scripts var instructions = ScriptInstruction.Read(sQuest, 50); // Script instance unlocks. if (!sQuest.IsRepeatable) { var instanceReferences = instructions.Where(i => i.Label.StartsWith("INSTANCEDUNGEON")).ToArray(); foreach (var instanceReference in instanceReferences) { var key = (int)instanceReference.Argument; var instance = _builder.Db.Instances.FirstOrDefault(i => ((int)i.id) == key); if (instance == null) { continue; // Probably a guildhest. } if (instance.unlockedByQuest != null) { continue; } if (!instructions.Any(i => i.Label == "UNLOCK_ADD_NEW_CONTENT_TO_CF" || i.Label.StartsWith("UNLOCK_DUNGEON"))) { // Some quests reference instances for the retrieval of items. // Don't treat these as unlocks. if (instructions.Any(i => i.Label.StartsWith("LOC_ITEM"))) { continue; } } instance.unlockedByQuest = sQuest.Key; rewards.instance = key; _builder.Db.AddReference(quest, "instance", key, false); _builder.Db.AddReference(instance, "quest", sQuest.Key, false); } } // Used items. foreach (var instruction in instructions) { if (!instruction.Label.StartsWith("RITEM") && !instruction.Label.StartsWith("QUEST_ITEM")) { continue; } var key = (int)instruction.Argument; if (_builder.Db.ItemsById.TryGetValue(key, out var item)) { if (item.usedInQuest == null) { item.usedInQuest = new JArray(); } JArray usedInQuest = item.usedInQuest; if (usedInQuest.Any(i => (int)i == sQuest.Key)) { continue; } item.usedInQuest.Add(sQuest.Key); if (quest.usedItems == null) { quest.usedItems = new JArray(); } quest.usedItems.Add(key); _builder.Db.AddReference(item, "quest", sQuest.Key, false); _builder.Db.AddReference(quest, "item", key, false); } } ImportQuestLore(quest, sQuest, instructions); if (((JObject)rewards).Count > 0) { quest.reward = rewards; } ImportQuestRequirements(quest, sQuest); _builder.Db.Quests.Add(quest); _builder.Db.QuestsById[sQuest.Key] = quest; } }
/// <summary> /// 导入行业财务指标到实体表 /// </summary> /// <param name="taskId"></param> /// <param name="context"></param> /// <param name="dataModeling"></param> /// <param name="dataSource"></param> /// <param name="tenant"></param> private string ImportFinanceialReportToDataTable(Guid taskId, DataContext context, DataModeling dataModeling, DataSource dataSource, Tenant tenant) { string message = ""; Action <string> SetWarningMessage = new Action <string>((_) => { _logger.LogWarning($"taskId={taskId}, {_}"); message += _; }); JObject jObject = JObject.Parse(dataModeling.Config); JArray cols = jObject["cols"] as JArray; var companyPropertyName = cols.FirstOrDefault(_ => _["type"].ToString() == "binding" && _["bind"].ToString().ToLower() == "company")?["name"]?.ToString(); if (companyPropertyName == null) { message = $"模板({dataModeling.Name})未設置綁定公司的字段"; _logger.LogError($"taskId={taskId}, {message}"); return(message); } var periodPropertyName = cols.FirstOrDefault(_ => _["type"].ToString() == "binding" && _["bind"].ToString().ToLower() == "period")?["name"]?.ToString(); if (periodPropertyName == null) { message = $"模板({dataModeling.Name})未設置綁定期別的字段"; _logger.LogError($"taskId={taskId}, {message}"); return(message); } if (!cols.Any(_ => _["name"].ToString() == "爬蟲編號") || !cols.Any(_ => _["name"].ToString() == "指標公式") || !cols.Any(_ => _["name"].ToString() == "指標類型")) { message = $"模板({dataModeling.Name})未設置名稱為 '爬蟲編號'、'公式'、'指標類型' 的字段"; _logger.LogError($"taskId={taskId}, {message}"); return(message); } using MySqlConnection connection = new MySqlConnection(tenant.ConnectionStrings.Data); try { connection.Open(); using MySqlCommand command = new MySqlCommand { Connection = connection }; var data = _mySqlService.ExecuteWithAdapter(taskId, connection, dataSource.Content); IList <dynamic> industryCategories = new List <dynamic>();//財報數據按公司所屬行業進行歸類 foreach (var group in data.Rows.Cast <DataRow>().GroupBy(_ => _[companyPropertyName].ToString())) { var companyInfo = context.CompanyInfo.SingleOrDefault(_ => _.CompanyNo == group.Key);//目前只有台湾地区部署了正式的爬虫系统,现阶段只需抓财务区域为台湾地区公司的行业财务比率 if (companyInfo == null) { SetWarningMessage($"未找到匹配的系統參數設定>所屬行業及對比公司設定,公司編號:{group.Key}\n"); continue; } var crawler = _crawlers.FirstOrDefault(_ => _.Area == (FinanceArea)Enum.ToObject(typeof(FinanceArea), Convert.ToInt32(companyInfo.Area))); if (crawler == null) { SetWarningMessage($"未找到匹配的系統參數設定>所屬行業及對比公司設定,公司編號:{group.Key},目標財務區域:{companyInfo.AreaName}({companyInfo.Area})\n"); continue; } else if (string.IsNullOrEmpty(crawler.ApiHost)) { SetWarningMessage($"目標財務區域:{companyInfo.AreaName}({companyInfo.Area})未設置爬蟲API地址\n"); continue; } if (string.IsNullOrWhiteSpace(companyInfo.Industry)) { SetWarningMessage($"初始化行業財務比率發生錯誤,系統參數公司({companyInfo.CompanyName})未設置對比行業\n"); continue; } var groupItems = group.AsEnumerable().Where(_ => string.IsNullOrWhiteSpace(_["能力"].ToString()) && !string.IsNullOrWhiteSpace(_["爬蟲編號"].ToString()));//过滤已经写入行业财务指标数据的行 industryCategories.Add(new { crawler, industryNo = companyInfo.Industry, industryName = companyInfo.IndustryName, companyNo = group.Key, companyInfo, dataRows = groupItems }); } foreach (var industryGroup in industryCategories.GroupBy(_ => _.industryNo)) { var industry = industryGroup.First(); IEnumerable <DataRow> groupDataRows = Enumerable.Empty <DataRow>(); foreach (var companyGroup in industryGroup) { groupDataRows = groupDataRows.Union((IEnumerable <DataRow>)companyGroup.dataRows); } var financeialReportPeriods = GetFinanceialReportPeriods(groupDataRows.Min(_ => _[periodPropertyName].ToString()), groupDataRows.Max(_ => _[periodPropertyName].ToString())); var crawlerCodes = groupDataRows.Select(_ => _["爬蟲編號"].ToString()).Distinct().OrderBy(_ => _); //此处 爬蟲編號 名称采用定值方式,是经过与张晓彬讨论得出的最终结果,因此data-modeling一定是存在名称为 爬蟲編號 的列(注意是繁体中文) var dwthResponse = _dwthService.GetIndustryIndVal(industry.crawler, industry.companyInfo.Area, industryGroup.Key, crawlerCodes, "1", financeialReportPeriods[0].ToString("yyyyMM"), financeialReportPeriods[1].ToString("yyyyMM")); //type传定值1,表示取期(季)的数据,传2表示取年,但是目前没有取年的需求 var industryIndVals = (IEnumerable <IndustryIndVal>)dwthResponse.Response.Data; foreach (var companyGroup in industryGroup) { var dataRows = (IEnumerable <DataRow>)companyGroup.dataRows; var companyInfo = companyGroup.companyInfo; crawlerCodes = dataRows.Select(_ => _["爬蟲編號"].ToString()).Distinct().OrderBy(_ => _); financeialReportPeriods = GetFinanceialReportPeriods(dataRows.Min(_ => _[periodPropertyName].ToString()), dataRows.Max(_ => _[periodPropertyName].ToString())); dwthResponse = _dwthService.GetPeerIndVal(industry.crawler, companyInfo.Area, companyInfo.ContrastOne, crawlerCodes, "1", financeialReportPeriods[0].ToString("yyyyMM"), financeialReportPeriods[1].ToString("yyyyMM")); var peerOneIndVals = (IEnumerable <PeerIndVal>)dwthResponse.Response.Data; dwthResponse = _dwthService.GetPeerIndVal(industry.crawler, companyInfo.Area, companyInfo.ContrastTwo, crawlerCodes, "1", financeialReportPeriods[0].ToString("yyyyMM"), financeialReportPeriods[1].ToString("yyyyMM")); var peerTwoIndVals = (IEnumerable <PeerIndVal>)dwthResponse.Response.Data; foreach (var dataRow in dataRows) { var industryIndVal = industryIndVals.SingleOrDefault(_ => _.IndId == dataRow["爬蟲編號"].ToString() && _.Period == GetQuarterMarks(dataRow[periodPropertyName].ToString())); if (industryIndVal == null) { //参数年期可能会造成爬虫系统找不到指定周期的行业财务比率,出现这种情况则不需要更新行业财务比率 SetWarningMessage($"未找到匹配的行業財務比率,爬蟲編號={dataRow["爬蟲編號"]},對比行業=[{companyGroup.industryNo}]{companyGroup.industryName},日期={dataRow[periodPropertyName]}\n"); continue; } var category = dataRow["指標類型"].ToString(); IList <string> setItems = new List <string>(); foreach (var property in _demandProperties) { if (property.name == "能力") { setItems.Add($"`{property.name}` = '{GetAbilityMarks(decimal.Parse(dataRow["指標公式"].ToString()), category, industryIndVal)}'");//指標值對應的列名為定值:指標公式 } else if (!string.IsNullOrWhiteSpace(property.bindIndValPropertyName1) && !string.IsNullOrWhiteSpace(property.bindIndValPropertyName2)) { setItems.Add($"`{property.name}` = {GetClassPropertyValue<decimal>(industryIndVal, GetBindIndValPropertyName(category, property))}"); } else if (property.name == "對比公司一") { var peerIndVal = peerOneIndVals.SingleOrDefault(_ => _.IndId == dataRow["爬蟲編號"].ToString() && _.Period == GetQuarterMarks(dataRow[periodPropertyName].ToString())); if (peerIndVal != null) { setItems.Add($"`{property.name}` = {peerIndVal.IndVal}"); } } else if (property.name == "對比公司二") { var peerIndVal = peerTwoIndVals.SingleOrDefault(_ => _.IndId == dataRow["爬蟲編號"].ToString() && _.Period == GetQuarterMarks(dataRow[periodPropertyName].ToString())); if (peerIndVal != null) { setItems.Add($"`{property.name}` = {peerIndVal.IndVal}"); } } } var commandText = $@"update `{dataSource.TableName}` set {string.Join(",", setItems)} where `爬蟲編號` = '{dataRow["爬蟲編號"]}' and `{companyPropertyName}` = '{companyGroup.companyNo}' and `{periodPropertyName}` = '{dataRow[periodPropertyName]}'"; _mySqlService.ExecuteNonQuery(taskId, command, commandText); } } } } catch (Exception) { throw; } finally { if (connection != null && connection.State == ConnectionState.Open) { connection.Close(); } } return(message); }
/// <summary> /// Verifies the service implementation feature. /// </summary> /// <param name="context">The Interop service context</param> /// <param name="info">out parameter to return violation information when rule does not pass</param> /// <returns>true if the service implementation feature passes; false otherwise</returns> public override bool?Verify(ServiceContext context, out ExtensionRuleViolationInfo info) { if (context == null) { throw new ArgumentNullException("context"); } bool?passed = null; info = null; var svcStatus = ServiceStatus.GetInstance(); string entityTypeShortName; var propNames = MetadataHelper.GetPropertyNames("Edm.String", out entityTypeShortName); if (null == propNames || !propNames.Any()) { return(passed); } string propName = propNames[0]; var entitySetUrl = entityTypeShortName.GetAccessEntitySetURL(); if (string.IsNullOrEmpty(entitySetUrl)) { return(passed); } string url = svcStatus.RootURL.TrimEnd('/') + "/" + entitySetUrl; var resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders); if (null != resp && HttpStatusCode.OK == resp.StatusCode) { JObject jObj = JObject.Parse(resp.ResponsePayload); JArray jArr = jObj.GetValue("value") as JArray; var entity = jArr.First as JObject; var propVal = entity[propName].ToString(); url = string.Format("{0}?$search={1}", url, propVal); resp = WebHelper.Get(new Uri(url), string.Empty, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, svcStatus.DefaultHeaders); var detail = new ExtensionRuleResultDetail("ServiceImpl_SystemQueryOptionSearch", url, HttpMethod.Get, string.Empty); info = new ExtensionRuleViolationInfo(new Uri(url), string.Empty, detail); if (null != resp && HttpStatusCode.OK == resp.StatusCode) { jObj = JObject.Parse(resp.ResponsePayload); jArr = jObj.GetValue("value") as JArray; if (null == jArr || !jArr.Any()) { return(false); } entity = jArr.First as JObject; passed = propVal == entity[propName].ToString(); } else { passed = false; } } else { return(passed); } return(passed); }
public override void Start() { BuildDutyRoulette(); var skippedInstances = new[] { 0, 20015, 20016, 50002, 65000, 30048 }; // Index conditions. Some PvP instances have multiple conditions, but it doesn't matter. foreach (var sContentFinderCondition in _builder.Sheet <Saint.ContentFinderCondition>()) { if (sContentFinderCondition.Key == 0) { continue; } if (sContentFinderCondition.Content is Saint.InstanceContent sInstanceContent) { _builder.ContentFinderConditionByInstanceContent[sInstanceContent] = sContentFinderCondition; } } // todo: add new player bonus currency // todo: add weekly restriction stuff? foreach (var sInstanceContent in _builder.Sheet <Saint.InstanceContent>()) { if (skippedInstances.Contains(sInstanceContent.Key)) { continue; // Skip test and fan fest instances. } // Find entry conditions. if (!_builder.ContentFinderConditionByInstanceContent.TryGetValue(sInstanceContent, out var sContentFinderCondition)) { continue; // Skip unreleased content. } // Skip some instances. switch (sContentFinderCondition.ContentType.Key) { case 3: // Guildhests case 7: // Quest Battles case 8: // FATEs case 20: // Novice Hall continue; } var name = sInstanceContent.Name.ToString(); if (name == "") { continue; } var sContentFinderConditionTransient = _builder.Sheet("ContentFinderConditionTransient")[sContentFinderCondition.Key]; dynamic instance = new JObject(); instance.id = sInstanceContent.Key; _builder.Localize.Strings((JObject)instance, sInstanceContent, Utils.SanitizeInstanceName, "Name"); instance.patch = PatchDatabase.Get("instance", sInstanceContent.Key); instance.categoryIcon = IconDatabase.EnsureEntry("instance/type", sContentFinderCondition.ContentType.Icon); _builder.Localize.Column((JObject)instance, sContentFinderCondition.ContentType, "Name", "category", x => string.IsNullOrEmpty(x) ? Hacks.GetContentTypeNameOverride(sContentFinderCondition.ContentType) : x); _builder.Localize.Strings((JObject)instance, sContentFinderConditionTransient, "Description"); instance.time = (int)sInstanceContent.TimeLimit.TotalMinutes; instance.min_lvl = sContentFinderCondition.RequiredClassJobLevel; Hacks.SetInstanceIcon(sContentFinderCondition, instance); if (sContentFinderCondition.ContentMemberType.HealersPerParty > 0) { instance.healer = sContentFinderCondition.ContentMemberType.HealersPerParty; } if (sContentFinderCondition.ContentMemberType.TanksPerParty > 0) { instance.tank = sContentFinderCondition.ContentMemberType.TanksPerParty; } if (sContentFinderCondition.ContentMemberType.RangedPerParty > 0) { instance.ranged = sContentFinderCondition.ContentMemberType.RangedPerParty; } if (sContentFinderCondition.ContentMemberType.MeleesPerParty > 0) { instance.melee = sContentFinderCondition.ContentMemberType.MeleesPerParty; } // fixme: find where this went. //if (conditions.ContentRoulette.Key > 0) // instance.roulette = conditions.ContentRoulette.Key; if (sContentFinderCondition.ClassJobLevelSync > 0) { instance.max_lvl = sContentFinderCondition.ClassJobLevelSync; } if (sContentFinderCondition.RequiredItemLevel > 0) { instance.min_ilvl = sContentFinderCondition.RequiredItemLevel; } if (sContentFinderCondition.ItemLevelSync > 0) { instance.max_ilvl = sContentFinderCondition.ItemLevelSync; } var treasureSet = new HashSet <int>(); var currency = new Dictionary <string, int>(); // Bosses var sFights = new List <Saint.InstanceContentData.Fight>(); if (sInstanceContent.Data.Boss != null) { sFights.Add(sInstanceContent.Data.Boss); } if (sInstanceContent.Data.MidBosses != null) { sFights.AddRange(sInstanceContent.Data.MidBosses); } var fights = new JArray(); foreach (var sFight in sFights) { var bossCurrency = new Dictionary <string, int>(); if (sFight.CurrencyA > 0) { currency["ClearA"] = currency.ContainsKey("ClearA") ? currency["ClearA"] + sFight.CurrencyA : sFight.CurrencyA; bossCurrency["ClearA"] = sFight.CurrencyA; } if (sFight.CurrencyB > 0) { currency["ClearB"] = currency.ContainsKey("ClearB") ? currency["ClearB"] + sFight.CurrencyB : sFight.CurrencyB; bossCurrency["ClearB"] = sFight.CurrencyB; } if (sFight.CurrencyC > 0) { currency["ClearC"] = currency.ContainsKey("ClearC") ? currency["ClearC"] + sFight.CurrencyC : sFight.CurrencyC; bossCurrency["ClearC"] = sFight.CurrencyC; } if (sFight.PrimaryBNpcs.Count() == 0 && sFight.Treasures.Count() == 0) { continue; } dynamic fight = new JObject(); fights.Add(fight); if (bossCurrency.Count > 0) { fight.currency = CreateCurrencyArray(bossCurrency); } fight.type = (sFight == sInstanceContent.Data.Boss) ? "Boss" : "MidBoss"; var fightCoffer = CreateTreasureCoffer(instance, sFight.Treasures, sInstanceContent, treasureSet); if (fightCoffer != null) { fight.coffer = fightCoffer; } var mobs = new JArray(); fight.mobs = mobs; foreach (var sBoss in sFight.PrimaryBNpcs) { _builder.InstanceIdsByMobId[sBoss.Key] = sInstanceContent.Key; if (!mobs.Any(b => ((long)b) == sBoss.Key)) { _builder.Db.AddReference(instance, "mob", sBoss.Key.ToString(), false); mobs.Add(sBoss.Key); } if (!_builder.ItemDropsByMobId.TryGetValue(sBoss.Key, out var itemIds)) { itemIds = new List <int>(); _builder.ItemDropsByMobId[sBoss.Key] = itemIds; } foreach (var sTreasureItem in sFight.Treasures.SelectMany(t => t.Items)) { if (!itemIds.Contains(sTreasureItem.Key)) { itemIds.Add(sTreasureItem.Key); } var item = _builder.Db.ItemsById[sTreasureItem.Key]; if (item.drops == null) { item.drops = new JArray(); } JArray drops = item.drops; if (!drops.Any(t => ((long)t) == sBoss.Key)) { drops.Add(sBoss.Key); _builder.Db.AddReference(instance, "item", sTreasureItem.Key, false); _builder.Db.AddReference(item, "instance", sInstanceContent.Key, true); } } if (sFight.CurrencyA > 0) { _builder.AddBossCurrency(sFight.CurrencyA, _builder.TomestoneIds[0], sBoss.Key); } if (sFight.CurrencyB > 0) { _builder.AddBossCurrency(sFight.CurrencyB, _builder.TomestoneIds[1], sBoss.Key); } if (sFight.CurrencyC > 0) { _builder.AddBossCurrency(sFight.CurrencyC, _builder.TomestoneIds[2], sBoss.Key); } } } if (fights.Count > 0) { instance.fights = fights; } // Treasures var coffers = new JArray(); if (sInstanceContent.Data.MapTreasures != null) { foreach (var sTreasure in sInstanceContent.Data.MapTreasures) { var coffer = CreateTreasureCoffer(instance, new Saint.InstanceContentData.Treasure[] { sTreasure }, sInstanceContent, treasureSet); if (coffer != null) { coffers.Add(coffer); } } if (coffers.Count > 0) { instance.coffers = coffers; } } // Some items are not referenced by the instance, but by the item itself. // This snags them. if (_builder.Db.ItemsByInstanceId.TryGetValue(sInstanceContent.Key, out var instanceItems)) { var otherItemRewards = new JArray(); foreach (var item in instanceItems) { int itemId = item.id; if (!treasureSet.Contains(itemId)) { otherItemRewards.Add(itemId); _builder.Db.AddReference(instance, "item", itemId, false); } } if (otherItemRewards.Count > 0) { instance.rewards = otherItemRewards; } } // Currency var currencyArray = CreateCurrencyArray(currency); if (currencyArray.Count > 0) { instance.currency = currencyArray; } _builder.Db.Instances.Add(instance); _builder.Db.InstancesById[sInstanceContent.Key] = instance; } }
/// <summary> /// extract quest and add description, count, reward item, reward quantity to List<BundleInfoEntry> BundleData /// loop if stage exist /// </summary> /// <param name="questFile"></param> private static void getQuestData(string questFile, JToken questInfo) { try { string questFilePath = JohnWick.ExtractAsset(ThePak.AllpaksDictionary[questFile], questFile); if (questFilePath != null) { if (questFilePath.Contains(".uasset") || questFilePath.Contains(".uexp") || questFilePath.Contains(".ubulk")) { JohnWick.MyAsset = new PakAsset(questFilePath.Substring(0, questFilePath.LastIndexOf('.'))); try { if (JohnWick.MyAsset.GetSerialized() != null) { new UpdateMyState("Parsing " + questFile + "...", "Waiting").ChangeProcessState(); //prestige challenge check JToken questUnlockType = questInfo["QuestUnlockType"]; string unlockType = string.Empty; if (questUnlockType != null) { unlockType = questUnlockType.Value <string>(); } dynamic AssetData = JsonConvert.DeserializeObject(JohnWick.MyAsset.GetSerialized()); JArray AssetArray = JArray.FromObject(AssetData); //fortbyte check JToken rewards = AssetArray[0]["Rewards"]; JToken assetTypeToken = null; bool isFortbyte = false; if (rewards != null) { JArray rewardsArray = rewards.Value <JArray>(); assetTypeToken = rewardsArray.Where(item => item["ItemPrimaryAssetId"]["PrimaryAssetType"]["Name"].Value <string>().Equals("Token")).FirstOrDefault(); if (assetTypeToken != null) { isFortbyte = rewardsArray.Any(item => item["ItemPrimaryAssetId"]["PrimaryAssetName"].Value <string>().Equals("AthenaFortbyte")); } } JToken objectives = AssetArray[0]["Objectives"]; if (objectives != null) { long questCount = 0; string descriptionKey = string.Empty; string descriptionSource = string.Empty; JArray objectivesArray = objectives.Value <JArray>(); foreach (JToken token in objectivesArray) { //quest count JToken count = token["Count"]; if (count != null) { questCount = count.Value <long>(); JToken objectiveCompletionCount = AssetArray[0]["ObjectiveCompletionCount"]; if (objectiveCompletionCount != null && objectiveCompletionCount.Value <long>() > 0) { questCount = objectiveCompletionCount.Value <long>(); } } //quest description JToken description = token["Description"]; if (description != null) { JToken key = description["key"]; JToken sourceString = description["source_string"]; if (key != null && sourceString != null) { descriptionKey = key.Value <string>(); descriptionSource = sourceString.Value <string>(); } } JToken descriptionMain = AssetArray[0]["Description"]; if (descriptionMain != null) { JToken key = descriptionMain["key"]; JToken sourceString = descriptionMain["source_string"]; if (key != null && sourceString != null) { descriptionKey = key.Value <string>(); descriptionSource = sourceString.Value <string>(); } } } string questDescription = SearchResource.getTextByKey(descriptionKey, descriptionSource); if (string.IsNullOrEmpty(questDescription)) { questDescription = " "; } if (rewards != null && !isFortbyte) { //quest rewards JArray rewardsArray = rewards.Value <JArray>(); try { string rewardId = rewardsArray.Where(item => !item["ItemPrimaryAssetId"]["PrimaryAssetType"]["Name"].Value <string>().Equals("Quest") && !item["ItemPrimaryAssetId"]["PrimaryAssetType"]["Name"].Value <string>().Equals("Token")).FirstOrDefault()["ItemPrimaryAssetId"]["PrimaryAssetName"].Value <string>(); string rewardQuantity = rewardsArray.Where(item => !item["ItemPrimaryAssetId"]["PrimaryAssetType"]["Name"].Value <string>().Equals("Quest") && !item["ItemPrimaryAssetId"]["PrimaryAssetType"]["Name"].Value <string>().Equals("Token")).FirstOrDefault()["Quantity"].Value <string>(); BundleInfoEntry currentData = new BundleInfoEntry(questDescription, questCount, rewardId, rewardQuantity, unlockType); bool isAlreadyAdded = BundleData.Any(item => item.questDescr.Equals(currentData.questDescr, StringComparison.InvariantCultureIgnoreCase) && item.questCount == currentData.questCount); if (!isAlreadyAdded) { BundleData.Add(currentData); } } catch (NullReferenceException) { JToken hiddenRewards = AssetArray[0]["HiddenRewards"]; if (hiddenRewards != null) { string rewardId = hiddenRewards[0]["TemplateId"].Value <string>(); string rewardQuantity = hiddenRewards[0]["Quantity"].Value <string>(); BundleInfoEntry currentData = new BundleInfoEntry(questDescription, questCount, rewardId, rewardQuantity, unlockType); bool isAlreadyAdded = BundleData.Any(item => item.questDescr.Equals(currentData.questDescr, StringComparison.InvariantCultureIgnoreCase) && item.questCount == currentData.questCount); if (!isAlreadyAdded) { BundleData.Add(currentData); } } } //quest stage foreach (JToken token in rewardsArray) { string qAssetType = token["ItemPrimaryAssetId"]["PrimaryAssetType"]["Name"].Value <string>(); string qAssetName = token["ItemPrimaryAssetId"]["PrimaryAssetName"].Value <string>(); if (qAssetType == "Quest") { getQuestData(qAssetName, questInfo); } } } else if (isFortbyte && assetTypeToken != null) { //thank you Quest_BR_S9_Fortbyte_04 JToken weight = AssetArray[0]["Weight"]; JToken weightToUse = null; if (weight != null) { weightToUse = weight; } BundleInfoEntry currentData = new BundleInfoEntry(questDescription, questCount, assetTypeToken["ItemPrimaryAssetId"]["PrimaryAssetName"].Value <string>(), weightToUse == null ? "01" : weightToUse.Value <string>(), unlockType); bool isAlreadyAdded = BundleData.Any(item => item.questDescr.Equals(currentData.questDescr, StringComparison.InvariantCultureIgnoreCase) && item.questCount == currentData.questCount); if (!isAlreadyAdded) { BundleData.Add(currentData); } } else { BundleInfoEntry currentData = new BundleInfoEntry(questDescription, questCount, "", "", unlockType); bool isAlreadyAdded = BundleData.Any(item => item.questDescr.Equals(currentData.questDescr, StringComparison.InvariantCultureIgnoreCase) && item.questCount == currentData.questCount); if (!isAlreadyAdded) { BundleData.Add(currentData); } } } } } catch (JsonSerializationException) { //do not crash when JsonSerialization does weird stuff } } } } catch (KeyNotFoundException) { new UpdateMyConsole("Can't extract " + questFile, Color.Crimson, true).AppendToConsole(); } }