public void TestAutoList2() { var auto = new AutoList<string>(5); Assert.AreEqual(0, auto.Count); Assert.IsNull(auto[1]); Assert.AreEqual(0, auto.Count); }
public void TestAutoListInitialize() { var auto = new AutoList <string>(new[] { "a", "b", "c" }); Assert.AreEqual(3, auto.Count); Assert.AreEqual("c", auto[2]); }
public ApiResult <AutoList> List([FromQuery] string type) { if (type.IsNullOrEmpty() || type == "undefined") { return(ApiResult.Failure <AutoList>("类型不能为空")); } var modelType = type.GetTypeByName(); var find = type.GetInstanceByName(); if (modelType == null || find == null) { return(ApiResult.Failure <AutoList>($"类型不存在,请确认{type}输入是否正确")); } var autoList = new AutoList(); if (find is IAutoList set) { var searchType = set.SearchType(); autoList = AutoListMapping.Convert(searchType.FullName); autoList.Result = set.PageList(Query, AutoModel); } return(ApiResult.Success(autoList)); }
public void TestAutoList2() { var auto = new AutoList <string>(5); Assert.AreEqual(0, auto.Count); Assert.IsNull(auto[1]); Assert.AreEqual(0, auto.Count); }
/// <summary> /// Check if any item of the given list is in the list /// </summary> /// <param name="values">List of items</param> public bool ContainsAny(AutoList <T, ST> values) { foreach (var v in values) { if (list.Contains((T)v)) { return(true); } } return(false); }
public void TestAutoList() { var auto = new AutoList<string>(); Assert.IsNotNull(auto); Assert.AreEqual(0, auto.Count); Assert.IsNull(auto[1]); Assert.AreEqual(0, auto.Count); auto[5] = "five"; for (int i = 0; i < 5; i++) Assert.IsNull(auto[i]); Assert.IsNotNull(auto[5]); Assert.AreEqual("five", auto[5]); }
public void TestAutoList() { var auto = new AutoList <string>(); Assert.IsNotNull(auto); Assert.AreEqual(0, auto.Count); Assert.IsNull(auto[1]); Assert.AreEqual(0, auto.Count); auto[5] = "five"; for (int i = 0; i < 5; i++) { Assert.IsNull(auto[i]); } Assert.IsNotNull(auto[5]); Assert.AreEqual("five", auto[5]); }
public void Start(ISocket socket, uint timeout, uint clock) { if (listener != null) { return; } //if (socket.State == SocketState.Listening) // return; //if (isRunning) // return; connections = new AutoList <TConnection, NetworkServer <TConnection> >(this); if (timeout > 0 & clock > 0) { timer = new Timer(MinuteThread, null, TimeSpan.FromMinutes(0), TimeSpan.FromSeconds(clock)); this.timeout = timeout; } //this.ip = ip; //this.port = port; this.clock = clock; // start a new thread for the server to live on //isRunning = true; listener = socket; // Start accepting listener.Accept().Then(NewConnection); //var rt = listener.Accept().Then() //thread = new Thread(new System.Threading.ThreadStart(ListenForConnections)); //thread.Start(); }
private static IResource[] QureyIn(string[] path, int index, AutoList <IResource, Instance> resources) { var rt = new List <IResource>(); if (index == path.Length - 1) { if (path[index] == "") { foreach (IResource child in resources) { rt.Add(child); } } else { foreach (IResource child in resources) { if (child.Instance.Name == path[index]) { rt.Add(child); } } } } else { foreach (IResource child in resources) { if (child.Instance.Name == path[index]) { rt.AddRange(QureyIn(path, index + 1, child.Instance.Children)); } } } return(rt.ToArray()); }
public void Start(Sockets.ISocket socket)//, uint timeout, uint clock) { if (listener != null) { return; } Connections = new AutoList <TConnection, NetworkServer <TConnection> >(this); if (Timeout > 0 & Clock > 0) { timer = new Timer(MinuteThread, null, TimeSpan.FromMinutes(0), TimeSpan.FromSeconds(Clock)); } listener = socket; // Start accepting //var r = listener.Accept(); //r.Then(NewConnection); //r.timeout?.Dispose(); //var rt = listener.Accept().Then() thread = new Thread(new ThreadStart(() => { while (true) { try { var s = listener.Accept(); if (s == null) { Console.Write("sock == null"); return; } //Console.WriteLine("New Socket ... " + DateTime.Now); var c = new TConnection(); //c.OnClose += ClientDisconnectedEventReceiver; c.Assign(s); Add(c); //Connections.Add(c); try { //ClientConnected(c); ClientConnected(c); //NetworkConnect(c); } catch { // something wrong with the child. } s.Begin(); // Accept more //listener.Accept().Then(NewConnection); } catch (Exception ex) { Console.WriteLine(ex); } } })); thread.Start(); }
public void TestAutoListInitialize() { var auto = new AutoList<string>(new[] { "a", "b", "c" }); Assert.AreEqual(3, auto.Count); Assert.AreEqual("c", auto[2]); }
/// <summary> /// Create new instance. /// </summary> /// <param name="id">Instance Id.</param> /// <param name="name">Name of the instance.</param> /// <param name="resource">Resource to manage.</param> /// <param name="store">Store responsible for the resource.</param> public Instance(uint id, string name, IResource resource, IStore store, ResourceTemplate customTemplate = null, ulong age = 0) { this.store = store; this.resource = resource; this.id = id; this.name = name; this.instanceAge = age; this.attributes = new KeyList <string, object>(this); children = new AutoList <IResource, Instance>(this); parents = new AutoList <IResource, Instance>(this); managers = new AutoList <IPermissionsManager, Instance>(this); children.OnAdd += Children_OnAdd; children.OnRemoved += Children_OnRemoved; parents.OnAdd += Parents_OnAdd; parents.OnRemoved += Parents_OnRemoved; resource.OnDestroy += Resource_OnDestroy; if (customTemplate != null) { this.template = customTemplate; } else { this.template = Warehouse.GetTemplate(resource.GetType()); } // set ages for (byte i = 0; i < template.Properties.Length; i++) { ages.Add(0); modificationDates.Add(DateTime.MinValue); } // connect events Type t = resource.GetType(); #if NETSTANDARD1_5 var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); #else var events = t.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); #endif foreach (var evt in events) { //if (evt.EventHandlerType != typeof(ResourceEventHanlder)) // continue; if (evt.EventHandlerType == typeof(ResourceEventHanlder)) { var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true); if (ca.Length == 0) { continue; } ResourceEventHanlder proxyDelegate = (args) => EmitResourceEvent(null, null, evt.Name, args); evt.AddEventHandler(resource, proxyDelegate); } else if (evt.EventHandlerType == typeof(CustomResourceEventHanlder)) { var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true); if (ca.Length == 0) { continue; } CustomResourceEventHanlder proxyDelegate = (issuer, receivers, args) => EmitResourceEvent(issuer, receivers, evt.Name, args); evt.AddEventHandler(resource, proxyDelegate); } /* * else if (evt.EventHandlerType == typeof(CustomUsersEventHanlder)) * { * var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true); * if (ca.Length == 0) * continue; * * CustomUsersEventHanlder proxyDelegate = (users, args) => EmitResourceEvent(evt.Name, users, null, args); * evt.AddEventHandler(resource, proxyDelegate); * } * else if (evt.EventHandlerType == typeof(CustomConnectionsEventHanlder)) * { * var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true); * if (ca.Length == 0) * continue; * * CustomConnectionsEventHanlder proxyDelegate = (connections, args) => EmitResourceEvent(evt.Name, null, connections, args); * evt.AddEventHandler(resource, proxyDelegate); * } * else if (evt.EventHandlerType == typeof(CustomReceiversEventHanlder)) * { * var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true); * if (ca.Length == 0) * continue; * * CustomReceiversEventHanlder proxyDelegate = (users, connections, args) => EmitResourceEvent(evt.Name, users, connections, args); * evt.AddEventHandler(resource, proxyDelegate); * * } */ } }