static bool CalculateDelay(List <DeliveryConstraint> deliveryConstraints, out long delay) { DoNotDeliverBefore doNotDeliverBefore; DelayDeliveryWith delayDeliveryWith; delay = 0; var delayed = false; if (deliveryConstraints.TryGet(out doNotDeliverBefore)) { delayed = true; delay = Convert.ToInt64(Math.Ceiling((doNotDeliverBefore.At - DateTime.UtcNow).TotalSeconds)); if (delay > DelayInfrastructure.MaxDelayInSeconds) { throw new Exception($"Message cannot be sent with {nameof(DoNotDeliverBefore)} value '{doNotDeliverBefore.At}' because it exceeds the maximum delay value '{TimeSpan.FromSeconds(DelayInfrastructure.MaxDelayInSeconds)}'."); } } else if (deliveryConstraints.TryGet(out delayDeliveryWith)) { delayed = true; delay = Convert.ToInt64(Math.Ceiling(delayDeliveryWith.Delay.TotalSeconds)); if (delay > DelayInfrastructure.MaxDelayInSeconds) { throw new Exception($"Message cannot be sent with {nameof(DelayDeliveryWith)} value '{delayDeliveryWith.Delay}' because it exceeds the maximum delay value '{TimeSpan.FromSeconds(DelayInfrastructure.MaxDelayInSeconds)}'."); } } return(delayed); }
public void TestTryGet() { List <int> i = new List <int> { 1, 2, 3 }; Assert.IsTrue(i.TryGet(I => I == 2, out int value)); Assert.IsTrue(value == 2); Assert.IsFalse(i.TryGet(I => I == 4, out value)); }
static bool CalculateDelay(List <DeliveryConstraint> deliveryConstraints, Dictionary <string, string> messageHeaders, bool routingTopologySupportsDelayedDelivery, out long delay, out string destination) { destination = null; DoNotDeliverBefore doNotDeliverBefore; DelayDeliveryWith delayDeliveryWith; delay = 0; var delayed = false; if (deliveryConstraints.TryGet(out doNotDeliverBefore)) { delayed = true; delay = Convert.ToInt64(Math.Ceiling((doNotDeliverBefore.At - DateTime.UtcNow).TotalSeconds)); if (delay > DelayInfrastructure.MaxDelayInSeconds) { throw new Exception($"Message cannot be sent with {nameof(DoNotDeliverBefore)} value '{doNotDeliverBefore.At}' because it exceeds the maximum delay value '{TimeSpan.FromSeconds(DelayInfrastructure.MaxDelayInSeconds)}'."); } } else if (deliveryConstraints.TryGet(out delayDeliveryWith)) { delayed = true; delay = Convert.ToInt64(Math.Ceiling(delayDeliveryWith.Delay.TotalSeconds)); if (delay > DelayInfrastructure.MaxDelayInSeconds) { throw new Exception($"Message cannot be sent with {nameof(DelayDeliveryWith)} value '{delayDeliveryWith.Delay}' because it exceeds the maximum delay value '{TimeSpan.FromSeconds(DelayInfrastructure.MaxDelayInSeconds)}'."); } } else if (routingTopologySupportsDelayedDelivery && messageHeaders.TryGetValue(TimeoutManagerHeaders.Expire, out var expire)) { delayed = true; var expiration = DateTimeExtensions.ToUtcDateTime(expire); delay = Convert.ToInt64(Math.Ceiling((expiration - DateTime.UtcNow).TotalSeconds)); destination = messageHeaders[TimeoutManagerHeaders.RouteExpiredTimeoutTo]; messageHeaders.Remove(TimeoutManagerHeaders.Expire); messageHeaders.Remove(TimeoutManagerHeaders.RouteExpiredTimeoutTo); if (delay > DelayInfrastructure.MaxDelayInSeconds) { throw new Exception($"Message cannot be sent with delay value '{expiration}' because it exceeds the maximum delay value '{TimeSpan.FromSeconds(DelayInfrastructure.MaxDelayInSeconds)}'."); } } return(delayed); }
//载入路径 add by tianjinpeng 2018/02/07 16:23:37 string ConsumableItemListpanduan(int index, string name) { ConsumableData consumableDataw; if (ConsumableDatas.TryGet(index, out consumableDataw)) { if (name == "icon") { return("Textures/Icon/" + consumableDataw.icon); //"Textures/Icon/"+consumableDataw.icon; } else if (name == "count") { return("" + consumableDataw.count); } else { return(""); } } else { return(""); } //return ""; }
public static T GetRandomByWeight <T>(this List <T> sequence, Func <T, float> weightSelector) { float TotalWeight = 0; foreach (var el in sequence) { TotalWeight += weightSelector(el); } float itemWeightIndex = UnityEngine.Random.Range(0f, TotalWeight); float currentWeightIndex = 0; foreach (var item in sequence) { currentWeightIndex += weightSelector(item); if (currentWeightIndex >= itemWeightIndex) { return(item); } } return(sequence.TryGet(0)); }
bool IsCombiningTimeToBeReceivedWithTransactions(TransportTransaction transaction, DispatchConsistency requiredDispatchConsistency, List <DeliveryConstraint> deliveryConstraints) { if (!settings.UseTransactionalQueues) { return(false); } if (requiredDispatchConsistency == DispatchConsistency.Isolated) { return(false); } DiscardIfNotReceivedBefore discardIfNotReceivedBefore; var timeToBeReceivedRequested = deliveryConstraints.TryGet(out discardIfNotReceivedBefore) && discardIfNotReceivedBefore.MaxTime < MessageQueue.InfiniteTimeout; if (!timeToBeReceivedRequested) { return(false); } if (Transaction.Current != null) { return(true); } MessageQueueTransaction activeReceiveTransaction; return(TryGetNativeTransaction(transaction, out activeReceiveTransaction)); }
internal static void Add(this List <InsertionPoint> lst, string key, InsertionPoint ip) { if (lst.TryGet(key, out var _)) { throw new ArgumentException($"An item with the key {key} has already been added."); } lst.Add(ip); }
public static Message Convert(OutgoingMessage message, List <DeliveryConstraint> deliveryConstraints) { var result = new Message(); if (message.Body != null) { result.BodyStream = new MemoryStream(message.Body); } AssignMsmqNativeCorrelationId(message, result); result.Recoverable = !deliveryConstraints.Any(c => c is NonDurableDelivery); DiscardIfNotReceivedBefore timeToBeReceived; if (deliveryConstraints.TryGet(out timeToBeReceived) && timeToBeReceived.MaxTime < MessageQueue.InfiniteTimeout) { result.TimeToBeReceived = timeToBeReceived.MaxTime; } var addCorrIdHeader = !message.Headers.ContainsKey("CorrId"); using (var stream = new MemoryStream()) { var headers = message.Headers.Select(pair => new HeaderInfo { Key = pair.Key, Value = pair.Value }).ToList(); if (addCorrIdHeader) { headers.Add(new HeaderInfo { Key = "CorrId", Value = result.CorrelationId }); } headerSerializer.Serialize(stream, headers); result.Extension = stream.ToArray(); } var messageIntent = default(MessageIntentEnum); string messageIntentString; if (message.Headers.TryGetValue(Headers.MessageIntent, out messageIntentString)) { Enum.TryParse(messageIntentString, true, out messageIntent); } result.AppSpecific = (int)messageIntent; return(result); }
//------------------------------------------------------------------------- // State:Attack Start private void ActionStartEnter() { actor.OnActionStartWhenActor(); target = targets.TryGet(targetIndex); if (target != null) { target.OnActionStartWhenTarget(); } }
static void EliminateTinySections(List <Section> list, int minLineLengthPx) { // Eliminate tiny sections Section cur; int i; while ((cur = list[i = list.IndexOfMin(s => s.LengthPx)]).LengthPx < minLineLengthPx) { var prev = list.TryGet(i - 1, null); var next = list.TryGet(i + 1, null); if (PickMerge(ref prev, cur, ref next)) { if (prev != null) { list[i - 1] = prev; } if (next != null) { list[i + 1] = next; } list.RemoveAt(i); } else { break; } } // Merge adjacent sections that now have the same mod-8 angle for (i = 1; i < list.Count; i++) { Section s0 = list[i - 1], s1 = list[i]; if (s0.AngleMod8 == s1.AngleMod8) { s0.EndSS = s1.EndSS; s0.iEnd = s1.iEnd; s0.LengthPx += s1.LengthPx; list.RemoveAt(i); i--; } } }
public bool InspectInList(IList list, int ind, ref int edited) { var changed = this.inspect_Name(); if (icon.Enter.BgColor(_colors.TryGet(0).ToOpaque()).Click().RestoreBGColor()) { edited = ind; } return(changed); }
internal void AddItem(Resource resource) { if (items.TryGet(r => r.name == resource.name, out Resource item)) { item.amount += resource.amount; } else { items.Add(resource); } }
public static void AddOrUpdateParameter(this List <QueryParameter> queryParameters, string parameter, string value) { if (!queryParameters.TryGet(parameter, out var qp)) { qp = new QueryParameter { Key = parameter }; queryParameters.Add(qp); } qp.Value = value; }
//显示列表回调函数 add by tianjinpeng 2018/03/09 15:30:43 void RenderListItem(int index, GObject obj) { GButton button = obj.asButton; GLoader sda = button.GetChild("icon").asLoader; BagData bagData; if (bagDataList.TryGet(index, out bagData)) { sda.url = "Textures/Icon/" + bagData.icon; button.text = bagData.price.ToString(); } }
public bool HasDecoration(int index) { DecorationData decorationData; if (decorationDataList.TryGet(index, out decorationData)) { return(true); } else { return(false); } }
public void TestTryGet() { var obj1 = new object(); var obj3 = new object(); var list = new List <object> { obj1, null, obj3, }; var o1 = list.TryGet(0); var o2 = list.TryGet(1); var o3 = list.TryGet(2); var o4 = list.TryGet(3); Assert.AreSame(obj1, o1); Assert.IsNull(o2); Assert.AreSame(obj3, o3); Assert.IsNull(o4); }
public bool SelectCategory(PickedCategory pc, int depth) { var changed = false; var categoryFound = false; if (pc.path.Count > depth) { NameForPEGI.nl(); if (pc.path.Count == depth + 1 && icon.Exit.Click(ref changed)) { pc.path.RemoveLast(); } else { var ind = pc.path[depth]; foreach (var t in subCategories) { if (t.IndexForPEGI == ind) { categoryFound = true; t.SelectCategory(pc, depth + 1).changes(ref changed); break; } } } } if (categoryFound) { return(false); } NameForPEGI.write(PEGI_Styles.ClickableText); int tmp = -1; if ("Sub Category".select_Index(ref tmp, subCategories).nl(ref changed)) { var c = subCategories.TryGet(tmp); if (c != null) { pc.path.ForceSet(depth, c.IndexForPEGI); } } return(changed); }
// ToListOfSTD public static bool TryDecodeInto <T>(this string data, List <T> val) { if (val != null) { var cody = new StdDecoder(data); while (cody.GotData) { var ind = cody.GetTag().ToIntFromTextSafe(-1); cody.GetData().TryDecodeInto(val.TryGet(ind)); } return(true); } return(false); }
private static T Decode <T>(string tag, string data, List <Type> tps) where T : ICfg { if (tag == CfgEncoder.NullTag) { return(default(T)); } var type = tps.TryGet(tag.ToIntFromTextSafe(-1)); if (type != null) { return(data.DecodeInto_Type <T>(type)); } return(tag == CfgDecoder.ListElementTag ? data.DecodeInto_Type <T>(tps[0]) : default(T)); }
public static List <T> DecodeInto <T>(this string data, out List <T> l) where T : ISTD, new() { StdDecoder cody = new StdDecoder(data); l = new List <T>(); List <Type> tps = typeof(T).TryGetDerrivedClasses(); foreach (var tag in cody) { var d = cody.GetData(); var isNull = tag == StdEncoder.nullTag; if (isNull) { l.Add(default(T)); } else { if (tps != null) { var type = tps.TryGet(tag.ToIntFromTextSafe(-1)); if (type == null) { type = tps[0]; #if UNITY_EDITOR Debug.Log("Couldn't decode class no: " + tag + " for " + typeof(T).ToString()); #endif } if (type != null) { l.Add(d.DecodeInto <T>(type)); } } else { l.Add(d.DecodeInto <T>()); } } } return(l); }
private static T Decode <T>(string tag, string data, List <Type> tps, ListMetaData ld, int index) where T : ICfg { if (tag == CfgEncoder.NullTag) { return(default(T)); } var type = tps.TryGet(tag.ToIntFromTextSafe(-1)); if (type != null) { return(data.DecodeInto_Type <T>(type)); } ld.elementDatas[index].Unrecognized(tag, data); return(default(T)); }
public static LNode TupleType(LNode node, IMessageSink sink) { var stem = node.Args[0, F._Missing]; if (stem.IsId && (stem.Name == S.List || stem.Name == S.Tuple)) { MaybeInitTupleMakers(); var bareType = TupleMakers.TryGet(node.Args.Count - 1, new Pair <LNode, LNode>()).A; if (bareType == null) { bareType = DefaultTupleMaker.A; } if (bareType != null) { return(node.WithArgChanged(0, bareType)); } } return(null); }
private static bool enter_DirectlyToElement <T>(this List <T> list, ref int inspected) { if ((inspected == -1 && list.Count > 1) || list.Count == 0) { return(false); } int suggestedIndex = Mathf.Max(inspected, 0); if (suggestedIndex >= list.Count) { suggestedIndex = 0; } icon ico; string msg; if (NeedsAttention(list, out msg)) { if (inspected == -1) { suggestedIndex = LastNeedAttentionIndex; } ico = icon.Warning; } else { ico = icon.Next; msg = "->"; } var el = list.TryGet(suggestedIndex);// as IPEGI; if (ico.Click(msg + el.GetNameForInspector())) { inspected = suggestedIndex; ef.isFoldedOutOrEntered = true; return(true); } return(false); }
public bool Component_PEGI() { bool changed = false; if (buffers.Count > 0) { if ((pauseBuffers ? icon.Play : icon.Pause).Click("Stop/Start ALL")) { pauseBuffers = !pauseBuffers; } int cur = -1; if ("Buffers".select(60, ref cur, buffers, (x) => x.CanBeAssignedToPainter).nl()) { changed = true; InspectedPainter.SetTextureOnMaterial(buffers.TryGet(cur).GetTextureDisplay()); } } return(changed); }
public bool SelectCategory(PickedCategory pc) { var changed = false; var categoryFound = false; if (pc.path.Count > 0) { var ind = pc.path[0]; foreach (var t in subCategories) { if (t.IndexForPEGI == ind) { categoryFound = true; t.SelectCategory(pc, 1).changes(ref changed); break; } } } if (categoryFound) { return(changed); } int tmp = -1; if ("Category".select_Index(ref tmp, subCategories).changes(ref changed)) { var c = subCategories.TryGet(tmp); if (c != null) { pc.path.ForceSet(0, c.IndexForPEGI); } } return(changed); }
public bool InspectInList(IList inspList, int ind, ref int edited) { var changed = false; var name = Enum.ToObject(inspectedEnum, ind).ToString(); if (!nameForInspector.Equals(name)) { nameForInspector = name; changed = true; } "{0} [{1}]".F(nameForInspector, CountForInspector()).write(); if (list == null) { list = new List <Object>(); changed = true; } if (list.Count < 2) { var el = list.TryGet(0); if (pegi.edit(ref el, inspectedObjectType, 90)) { list.ForceSet(0, el); } } if (icon.Enter.Click()) { edited = ind; } return(changed); }
public T GetReferenced <T>(int index) where T : Object => nestedReferences.TryGet(index) as T;
public static T TryGet <T>(this List <T> list, ListMetaData meta) => list.TryGet(meta.inspected);
public static Message Convert(OutgoingMessage message, List<DeliveryConstraint> deliveryConstraints) { var result = new Message(); if (message.Body != null) { result.BodyStream = new MemoryStream(message.Body); } AssignMsmqNativeCorrelationId(message, result); result.Recoverable = !deliveryConstraints.Any(c => c is NonDurableDelivery); DiscardIfNotReceivedBefore timeToBeReceived; if (deliveryConstraints.TryGet(out timeToBeReceived) && timeToBeReceived.MaxTime < MessageQueue.InfiniteTimeout) { result.TimeToBeReceived = timeToBeReceived.MaxTime; } var addCorrIdHeader = !message.Headers.ContainsKey("CorrId"); using (var stream = new MemoryStream()) { var headers = message.Headers.Select(pair => new HeaderInfo { Key = pair.Key, Value = pair.Value }).ToList(); if (addCorrIdHeader) { headers.Add(new HeaderInfo { Key = "CorrId", Value = result.CorrelationId }); } headerSerializer.Serialize(stream, headers); result.Extension = stream.ToArray(); } var messageIntent = default(MessageIntentEnum); string messageIntentString; if (message.Headers.TryGetValue(Headers.MessageIntent, out messageIntentString)) { Enum.TryParse(messageIntentString, true, out messageIntent); } result.AppSpecific = (int)messageIntent; return result; }
bool IsCombiningTimeToBeReceivedWithTransactions(TransportTransaction transaction, DispatchConsistency requiredDispatchConsistency, List<DeliveryConstraint> deliveryConstraints) { if (!settings.UseTransactionalQueues) { return false; } if (requiredDispatchConsistency == DispatchConsistency.Isolated) { return false; } DiscardIfNotReceivedBefore discardIfNotReceivedBefore; var timeToBeReceivedRequested = deliveryConstraints.TryGet(out discardIfNotReceivedBefore) && discardIfNotReceivedBefore.MaxTime < MessageQueue.InfiniteTimeout; if (!timeToBeReceivedRequested) { return false; } if (Transaction.Current != null) { return true; } MessageQueueTransaction activeReceiveTransaction; return TryGetNativeTransaction(transaction, out activeReceiveTransaction); }
public static void Fill(this IBasicProperties properties, OutgoingMessage message, List <DeliveryConstraint> deliveryConstraints, bool routingTopologySupportsDelayedDelivery, out string destination) { if (message.MessageId != null) { properties.MessageId = message.MessageId; } properties.Persistent = !deliveryConstraints.Any(c => c is NonDurableDelivery); var messageHeaders = message.Headers ?? new Dictionary <string, string>(); long delay; var delayed = CalculateDelay(deliveryConstraints, messageHeaders, routingTopologySupportsDelayedDelivery, out delay, out destination); properties.Headers = messageHeaders.ToDictionary(p => p.Key, p => (object)p.Value); if (delayed) { properties.Headers[DelayInfrastructure.DelayHeader] = Convert.ToInt32(delay); } DiscardIfNotReceivedBefore timeToBeReceived; if (deliveryConstraints.TryGet(out timeToBeReceived) && timeToBeReceived.MaxTime < TimeSpan.MaxValue) { // align with TimeoutManager behavior if (delayed) { throw new Exception("Postponed delivery of messages with TimeToBeReceived set is not supported. Remove the TimeToBeReceived attribute to postpone messages of this type."); } properties.Expiration = timeToBeReceived.MaxTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture); } string correlationId; if (messageHeaders.TryGetValue(NServiceBus.Headers.CorrelationId, out correlationId) && correlationId != null) { properties.CorrelationId = correlationId; } string enclosedMessageTypes; if (messageHeaders.TryGetValue(NServiceBus.Headers.EnclosedMessageTypes, out enclosedMessageTypes) && enclosedMessageTypes != null) { var index = enclosedMessageTypes.IndexOf(','); if (index > -1) { properties.Type = enclosedMessageTypes.Substring(0, index); } else { properties.Type = enclosedMessageTypes; } } string contentType; if (messageHeaders.TryGetValue(NServiceBus.Headers.ContentType, out contentType) && contentType != null) { properties.ContentType = contentType; } else { properties.ContentType = "application/octet-stream"; } string replyToAddress; if (messageHeaders.TryGetValue(NServiceBus.Headers.ReplyToAddress, out replyToAddress) && replyToAddress != null) { properties.ReplyTo = replyToAddress; } }
static void EliminateTinySections(List<Section> list, int minLineLengthPx) { // Eliminate tiny sections Section cur; int i; while ((cur = list[i = list.IndexOfMin(s => s.LengthPx)]).LengthPx < minLineLengthPx) { var prev = list.TryGet(i - 1, null); var next = list.TryGet(i + 1, null); if (PickMerge(ref prev, cur, ref next)) { if (prev != null) list[i - 1] = prev; if (next != null) list[i + 1] = next; list.RemoveAt(i); } else break; } // Merge adjacent sections that now have the same mod-8 angle for (i = 1; i < list.Count; i++) { Section s0 = list[i - 1], s1 = list[i]; if (s0.AngleMod8 == s1.AngleMod8) { s0.EndSS = s1.EndSS; s0.iEnd = s1.iEnd; s0.LengthPx += s1.LengthPx; list.RemoveAt(i); i--; } } }
public string GetURL(int ind) { var el = _loadedTextures.TryGet(ind); return((el == null) ? "" : el.URL); }