/// <summary> /// 从缓存文件恢复TCP服务信息集合 /// </summary> private void fromCacheFile() { cache cache = new cache(); if (File.Exists(cacheFile)) { int isCache = 0; try { if (fastCSharp.emit.dataDeSerializer.DeSerialize(File.ReadAllBytes(cacheFile), ref cache)) { isCache = 1; } else { cache = new cache(); } } catch (Exception error) { fastCSharp.log.Error.Add(error, null, false); } if (isCache == 0) { try { File.Delete(cacheFile); } catch (Exception error) { fastCSharp.log.Default.Add(error, null, false); } } } Monitor.Enter(serviceLock); try { hostPorts = dictionary.CreateHashString <int>(); serviceCache = dictionary.CreateHashString <services>(); hostClients = dictionary <host> .Create <indexIdentity>(); foreach (services value in cache.Services.notNull()) { serviceCache.Add(value.Name, value); } foreach (keyValue <string, int> value in cache.HostPorts.notNull()) { hostPorts.Add(value.Key, value.Value); } } finally { Monitor.Exit(serviceLock); } }
/// <summary> /// 保存TCP服务信息集合到缓存文件 /// </summary> internal unsafe void SaveCacheFile() { cache cache = new cache(); byte[] buffer = fastCSharp.memoryPool.StreamBuffers.Get(); try { fixed(byte *bufferFixed = buffer) { using (unmanagedStream stream = new unmanagedStream(bufferFixed, buffer.Length)) { Monitor.Enter(serviceLock); try { cache.Services = serviceCache.Values.getArray(); cache.HostPorts = hostPorts.getArray(value => new keyValue <string, int>(value.Key.ToString(), value.Value)); fastCSharp.emit.dataSerializer.Serialize(cache, stream); if (stream.data.data == bufferFixed) { using (FileStream file = new FileStream(cacheFile, FileMode.Create, FileAccess.Write, FileShare.None)) { file.Write(buffer, 0, stream.Length); } } else { File.WriteAllBytes(cacheFile, stream.GetArray()); } } finally { isSaveCacheFile = 0; Monitor.Exit(serviceLock); } } } } finally { fastCSharp.memoryPool.StreamBuffers.PushNotNull(buffer); } }
/// <summary> /// 添加远程缓存成员 /// </summary> /// <param name="member"></param> internal void Push(MemberIndex member) { members.Add(new RemoteLinkMember { Member = member, Attribute = member.GetSetupAttribute <AutoCSer.Net.TcpStaticServer.RemoteLinkAttribute>(false), Index = members.Length }); cache cache = getCache(member.MemberSystemType); if (cache.Members.Length != 0) { RemoteLinkMember[] memberArray = members.ToArray(); foreach (RemoteLink nextMember in cache.Members) { Caches.Add(new RemoteLink { Members = memberArray, Method = nextMember.Method, Member = nextMember.Member, PropertyParameters = nextMember.PropertyParameters, Attribute = nextMember.Attribute }); } } foreach (MemberIndex nextMember in cache.Caches) { bool isMember = true; foreach (RemoteLinkMember cacheMember in members) { if (cacheMember.Member.MemberSystemType == nextMember.MemberSystemType) { Messages.Message("远程调用链类型循环引用 " + members.JoinString(" . ", value => value.Member.MemberType.FullName + " " + value.Member.MemberName) + " . " + nextMember.MemberType.FullName + " " + nextMember.MemberName); isMember = false; break; } } if (isMember) { Push(nextMember); } } --members.Length; }
private unsafe static void deSerialize(fastCSharp.emit.dataDeSerializer deSerializer, ref cache <valueType> value) { if (deSerializer.CheckNull() != 0) { int length = deSerializer.ReadInt(); if (length == 1) { fastCSharp.emit.dataDeSerializer.typeDeSerializer <valueType> .DeSerialize(deSerializer, ref value.Value); } else { if (fastCSharp.emit.dataDeSerializer.DeSerialize(deSerializer.Read, length, ref value.Value)) { deSerializer.Read += length; } else { deSerializer.Error(binaryDeSerializer.deSerializeState.Custom); } } } }
private static void serialize(fastCSharp.emit.dataSerializer serializer, cache <valueType> value) { value.serialize(serializer); }
yield return(CreateCloneMemberExpression(source, destination, cache, target.Item1, target.Item2));
public wpt(XmlNode Node) { Coordinates.lat = Node.Attributes["lat"].Value.ToString(); Coordinates.lon = Node.Attributes["lon"].Value.ToString(); foreach (XmlNode ChildNode in Node.ChildNodes) { switch (ChildNode.Name) { case "time": Time = ChildNode.InnerText; break; case "name": Name = ChildNode.InnerText; break; case "desc": Desc = ChildNode.InnerText; break; case "url": URL = ChildNode.InnerText; break; case "urlname": URLName = ChildNode.InnerText; break; case "sym": Sym = ChildNode.InnerText; break; case "type": Type = ChildNode.InnerText; break; case "ele": Ele = ChildNode.InnerText; break; case "cmt": Cmt = ChildNode.InnerText; break; case "groundspeak:cache": Groundspeak_Cache = new cache(ChildNode); break; case "ox:opencaching": foreach (XmlNode OpenCachingChildNode in ChildNode.ChildNodes) { switch (OpenCachingChildNode.Name) { case "ox:ratings": foreach (XmlNode OpenCachingRatingsChildNode in OpenCachingChildNode.ChildNodes) { switch (OpenCachingRatingsChildNode.Name) { case "ox:awesomeness": Opencaching_Awesomeness = (OpenCachingRatingsChildNode).InnerText; break; case "ox:difficulty": Opencaching_Difficulty = (OpenCachingRatingsChildNode).InnerText; break; case "ox:terrain": Opencaching_Terrain = (OpenCachingRatingsChildNode).InnerText; break; case "ox:size": Opencaching_Size = (OpenCachingRatingsChildNode).InnerText; break; default: throw new Exception("Unhandled for Child Object: " + OpenCachingRatingsChildNode.Name); } } break; case "ox:tags": foreach (XmlNode OpenCachingTagNode in OpenCachingChildNode.ChildNodes) { switch (OpenCachingTagNode.Name) { case "ox:tag": Opencaching_Tags.Add((OpenCachingTagNode).InnerXml); break; default: throw new Exception("Unhandled for Child Object: " + OpenCachingTagNode.Name); } } break; case "ox:verification": foreach (XmlNode OpenCachingVerificationNode in OpenCachingChildNode.ChildNodes) { switch (OpenCachingVerificationNode.Name) { case "ox:phrase": Opencaching_VerificationPhrase = OpenCachingChildNode.InnerText; break; case "ox:number": Opencaching_VerificationNumber = OpenCachingChildNode.InnerText; break; case "ox:QR": Opencaching_VerificationQR = OpenCachingChildNode.InnerText; break; case "ox:chirp": Opencaching_VerificationChirp = OpenCachingChildNode.InnerText; break; default: throw new Exception("Unhandled for Child Object: " + OpenCachingVerificationNode.Name); } } break; case "ox:series": Opencaching_SeriesName = OpenCachingChildNode.InnerText; Opencaching_SeriesID = (OpenCachingChildNode).Attributes["id"].Value.ToString(); break; default: throw new Exception("Unhandled for Child Object: " + OpenCachingChildNode.Name); } } break; default: throw new Exception("Unhandled for Child Object: " + ChildNode.Name); } } }
=> _repository = new ServerRegistryRepository(cache, store);