private List <InstanceTag> ParseTags(string idWithTags) { if (string.IsNullOrEmpty(idWithTags)) { return(null); } List <InstanceTag> list = new List <InstanceTag>(); string[] array = idWithTags.Split('~'); if (array == null || array.Length > 1) { for (int i = 1; i < array.Length; i++) { InstanceTag item; if (array[i].Contains('(')) { string[] array2 = array[i].Split('('); string n = array2[0]; string d = array2[1].TrimEnd(')'); item = new InstanceTag(n, d); } else { item = new InstanceTag(array[i]); } list.Add(item); } } return(list); }
private T TryGetInstance() { lock (_dataLock) { CleanupInstances(); InstanceTag tag; if (_freeInstances > 0) { //find free instance tag = _tags.First(t => t.IsAvailable); tag.IsAvailable = false; tag.LastUsed = DateTime.UtcNow; _freeInstances -= 1; return(tag.Instance); } if (_instanceCount < _capacity) { //create new instance as capacity allows it tag = new InstanceTag(); _tags.Add(tag); tag.Instance = _createFunction(); tag.IsAvailable = false; tag.LastUsed = DateTime.UtcNow; _instanceCount += 1; return(tag.Instance); } return(null); } }
public static InstanceTags GetInstanceTags(Collection<instancetag> instancetags) { var results = new InstanceTags(); foreach (instancetag instancetag in instancetags) { var tag = new InstanceTag(instancetag.Account, instancetag.Protocol); tag.SetInstanceTag(instancetag.InstanceTag); results.Add(tag); } return results; }
/// <summary> /// Returns instance to the object pool so it can be reused /// </summary> /// <param name="instance"></param> public void ReleaseInstance(T instance) { lock (_dataLock) { CleanupInstances(); InstanceTag tag = _tags.FirstOrDefault(t => ReferenceEquals(t.Instance, instance)); if (tag != null) //tag can be cleaned up { tag.IsAvailable = true; _freeInstances += 1; } } _instanceMayBeAvailable.Set(); }
public string GetInstanceCreator() { List <InstanceTag> list = ParseTags(idWithTags); if (list != null) { foreach (InstanceTag item in list) { InstanceTag current = item; if (current.name == accessDetails[AccessType.InviteOnly].tags[0] || current.name == accessDetails[AccessType.InvitePlus].tags[0] || current.name == accessDetails[AccessType.FriendsOnly].tags[0] || current.name == accessDetails[AccessType.FriendsOfGuests].tags[0]) { return(current.data); } } } return(null); }
unsafe public static extern int otrl_message_sending( IntPtr us, ref OtrlMessageAppOps ops, IntPtr opdata, string accountname, string protocol, string recipient, InstanceTag instag, string original_msg, //ref OtrlTLV tlvs, IntPtr tlvs, out IntPtr messagep, OtrlFragmentPolicy fragPolicy, //ref IntPtr contextp, out IntPtr contextp, add_app_data add_app_data, IntPtr data );
public static unsafe extern int otrl_message_sending( IntPtr us, ref OtrlMessageAppOps ops, IntPtr opdata, string accountname, string protocol, string recipient, InstanceTag instag, string original_msg, //ref OtrlTLV tlvs, IntPtr tlvs, out IntPtr messagep, OtrlFragmentPolicy fragPolicy, //ref IntPtr contextp, out IntPtr contextp, add_app_data add_app_data, IntPtr data );
public void IsValid() { InstanceTag.IsValid(0).Should().BeTrue(); InstanceTag.IsValid(256).Should().BeTrue(); }
public void IsValidShouldReturnFalseBetween0and100Hex([Range(1, 255, 1)] int x) { uint value = (uint)x; InstanceTag.IsValid(value).Should().BeFalse(); }