Пример #1
0
        private Scheduler()
        {
            _from2set = new C5.HashDictionary <ISimEntity, C5.HashSet <ISimEventHandle> >();
            _to2set   = new C5.HashDictionary <ISimEntity, C5.HashSet <ISimEventHandle> >();

            _ud2ehandle = new C5.TreeDictionary <IUniqueDouble, ISimEventHandle>();
            _done       = false;
            _timeNow    = 0;
        }
Пример #2
0
        public static IEnumerable <IPathNode <N> > GetReachableNodes <N>(N start, float maxCost) where N : INode <N>
        {
            C5.IDictionary <N, PathNode <N> > nodeDictionary = new C5.HashDictionary <N, PathNode <N> >();
            C5.IPriorityQueue <PathNode <N> > openSet        = new C5.IntervalHeap <PathNode <N> >(new PathNodeComparer <N>(), C5.MemoryType.Normal);
            C5.ICollection <N>            closedSet          = new C5.HashSet <N>();
            C5.ArrayList <IPathNode <N> > res = new C5.ArrayList <IPathNode <N> >(C5.MemoryType.Normal);


            PathNode <N> curNode = new PathNode <N>(start);

            curNode.g = 0;
            nodeDictionary.Add(start, curNode);
            while (true)
            {
                res.Add(curNode);
                foreach (IEdge <N> edge in curNode.node)
                {
                    N other = edge.GetEnd();
                    if (!closedSet.Contains(other))
                    {
                        PathNode <N> otherNode = null;
                        if (!nodeDictionary.Find(ref other, out otherNode))
                        {
                            otherNode = new PathNode <N>(other);
                            nodeDictionary.Add(other, otherNode);
                        }
                        float newG = edge.GetCost() + curNode.g;
                        if (otherNode.g > newG)
                        {
                            otherNode.g = newG;
                            if (otherNode.queueHandle != null)
                            {
                                openSet.Replace(otherNode.queueHandle, otherNode);
                            }
                            otherNode.prev = curNode;
                        }
                        if (otherNode.queueHandle == null)
                        {
                            C5.IPriorityQueueHandle <PathNode <N> > handle = null;
                            openSet.Add(ref handle, otherNode);
                            otherNode.queueHandle = handle;
                        }
                    }
                }
                if (openSet.IsEmpty)
                {
                    return(res);
                }
                closedSet.Add(curNode.node);
                curNode = openSet.DeleteMin();
                if (curNode.g > maxCost)
                {
                    return(res);
                }
            }
        }
Пример #3
0
 static DocNet()
 {
     longtype2short    = new C5.HashDictionary <string, string>();
     cachedDocComments = new C5.HashDictionary <string, XmlNode>();
     longtype2short.Add("System.Boolean", "bool");
     longtype2short.Add("System.Byte", "byte");
     longtype2short.Add("System.Int32", "int");
     longtype2short.Add("System.Double", "double");
     longtype2short.Add("System.Void", "void");
     longtype2short.Add("System.Object", "object");
     longtype2short.Add("System.String", "string");
     longtype2short.Add("System.Collections.Generic.IEnumerable{T}", "IEnumerable{T}");
     longtype2short.Add("System.Collections.Generic.IEnumerable{U}", "IEnumerable{U}");
     //longtype2short.Add("", "");
 }
Пример #4
0
        public void Reset()
        {
            _from2set = new C5.HashDictionary <ISimEntity, C5.HashSet <ISimEventHandle> >();
            _to2set   = new C5.HashDictionary <ISimEntity, C5.HashSet <ISimEventHandle> >();

            _ud2ehandle = new C5.TreeDictionary <IUniqueDouble, ISimEventHandle>();
            _done       = false;
            _timeNow    = 0;

            /*
             * this._from2set.Clear();
             * this._to2set.Clear();
             * this._ud2ehandle.Clear();
             * this._timeNow = 0;
             * this._uid = 0;
             * this._done = false;
             */
        }
        void _VerifyTerminalsStatus(ICommunicationMessage message)
        {
            C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
            AlarmManager.instance().GetAdaptersInfo(ads);

            foreach (C5.KeyValuePair <long, AdapterInfo> info in ads)
            {
                try
                {
                    System.Net.IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(info.Value.Address), info.Value.ControllerPort);
                    if (end.Port == 0)
                    {
                        continue;
                    }
                    else
                    {
                        ICommClient comm = CommManager.instance().CreateCommClient <CommandMsgV2, TKMessageV2Extractor, TKMessageV2Encoder>("控制器",
                                                                                                                                            end.Address.ToString(), end.Port, 30, false, false);

                        if (!comm.Start())
                        {
                            // remove adapter
                            AlarmManager.instance().RemoveAdapterInfo(info.Key);
                        }
                        else
                        {
                            comm.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    DefLib.Util.Logger.Instance().SendLog(ex.ToString());
                }
            }

            CommandMsgV2 msg = new CommandMsgV2();

            msg.TK_CommandType = Constants.TK_CommandType.MON_GETTERMINALSINFO;
            msg.SeqID          = message.SeqID;
            msg.SetValue("ClientID", message.GetValue("ClientID"));

            CommandProcessor.instance().DispatchCommand(msg);
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the Mapper class.
 /// </summary>
 public Mapper()
 {
     KToTMap = new TreeDictionary <K, T>();
     TToKMap = new HashDictionary <T, K>();
 }
Пример #7
0
 public UpdateQueue()
 {
     m_queue = new Queue <SceneObjectPart>();
     m_ids   = new C5.HashDictionary <uint, PrimUpdateFlags>();
 }
        CommandMsgV2 _StartAdapter(ICommunicationMessage message)
        {
            try
            {
                CommandMsgV2 resp = new CommandMsgV2();
                resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
                resp.SeqID          = CommandProcessor.AllocateID();
                resp.SetValue("ClientID", message.GetValue("ClientID"));
                resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);


                long adapterid = Convert.ToInt64(message.GetValue(Constants.MSG_PARANAME_ADAPTER_ID));

                C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
                AlarmManager.instance().GetAdaptersInfo(ads);
                if (!ads.Contains(adapterid))
                {
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    resp.SetValue(Constants.MSG_PARANAME_REASON, "采集器不存在.");
                    return(resp);
                }

                try
                {
                    CommandMsgV2 cmd = new CommandMsgV2();
                    cmd.SeqID          = CommandProcessor.AllocateID();
                    cmd.TK_CommandType = Constants.TK_CommandType.ADAPTER_START;
                    cmd.SetValue("ClientID", adapterid);
                    cmd.SetValue(Constants.MSG_PARANAME_ADAPTER_NAME, ads[adapterid].Name);

                    System.Net.IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ads[adapterid].Address), ads[adapterid].ControllerPort);
                    if (end.Port == 0)
                    {
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                        resp.SetValue(Constants.MSG_PARANAME_REASON, "不可远程控制的采集器");
                    }
                    else
                    {
                        ICommClient comm = CommManager.instance().CreateCommClient <CommandMsgV2, TKMessageV2Extractor, TKMessageV2Encoder>("控制器",
                                                                                                                                            end.Address.ToString(), end.Port, 30, false, false);

                        comm.Start();
                        ICommunicationMessage r2 = comm.SendCommand(cmd);
                        resp.SetValue(Constants.MSG_PARANAME_RESULT, r2.GetValue(Constants.MSG_PARANAME_RESULT));
                        comm.Close();
                    }
                }
                catch (Exception ex)
                {
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "NOK");
                    resp.SetValue(Constants.MSG_PARANAME_REASON, ex.Message);
                }

                return(resp);
            }
            catch (Exception ex)
            {
                Logger.Instance().SendLog(ex.ToString());
                return(null);
            }
        }
Пример #9
0
            public virtual IEnumerable<BrowseFacet> GetFacets()
            {
                C5.IDictionary<object, BrowseFacet> facetMap;
                if (FacetSpec.FacetSortSpec.OrderValueAsc.Equals(fspec.OrderBy))
                {
                    facetMap = new C5.TreeDictionary<object, BrowseFacet>();
                }
                else
                {
                    facetMap = new C5.HashDictionary<object, BrowseFacet>();
                }

                foreach (IFacetAccessible facetAccessor in this.list)
                {
                    IEnumerator<BrowseFacet> iter = facetAccessor.GetFacets().GetEnumerator();
                    if (facetMap.Count == 0)
                    {
                        while (iter.MoveNext())
                        {
                            BrowseFacet facet = iter.Current;
                            facetMap.Add(facet.Value, facet);
                        }
                    }
                    else
                    {
                        while (iter.MoveNext())
                        {
                            BrowseFacet facet = iter.Current;
                            BrowseFacet existing = facetMap[facet.Value];
                            if (existing == null)
                            {
                                facetMap.Add(facet.Value, facet);
                            }
                            else
                            {
                                existing.HitCount = existing.HitCount + facet.HitCount;
                            }
                        }
                    }
                }

                List<BrowseFacet> list = new List<BrowseFacet>(facetMap.Values);
                // FIXME: we need to reorganize all that stuff with comparators
                Comparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
                if (FacetSpec.FacetSortSpec.OrderHitsDesc.Equals(fspec.OrderBy))
                {
                    list.Sort(
                        delegate(BrowseFacet f1, BrowseFacet f2)
                        {
                            int val = f2.HitCount - f1.HitCount;
                            if (val == 0)
                            {
                                val = -(comparer.Compare(f1.Value, f2.Value));
                            }
                            return val;
                        }
                        );
                }
                return list;
            }
Пример #10
0
 public void C5_HashDictionary() => _ = new C5.HashDictionary <Char, String>();
Пример #11
0
        public void handleCommand(ICommunicationMessage message)
        {
            CommandMsgV2 resp = new CommandMsgV2();

            resp.TK_CommandType = Constants.TK_CommandType.RESPONSE;
            resp.SeqID          = CommandProcessor.AllocateID();
            resp.SetValue(Constants.MSG_PARANAME_RESPONSE_TO, message.SeqID);
            try
            {
                if (message.Contains("ClientID"))
                {
                    resp.SetValue("ClientID", message.GetValue("ClientID"));
                }
                else
                {
                    throw new Exception("No ClientID in incoming package.");
                }

                switch (message.TK_CommandType)
                {
                case Constants.TK_CommandType.SERVER_GETRUNTIMEINFO:
                {
                    Process p = Process.GetCurrentProcess();
                    resp.SetValue("PROCESSID", p.Id.ToString());
                    resp.SetValue("THREADCOUNT", p.Threads.Count.ToString());
                    resp.SetValue("MAX_THREADCOUNT", 30 + (AlarmManager.instance().MaxAdapters + AlarmManager.instance().MaxClients + AlarmManager.instance().MaxControllers) * 2);
                    resp.SetValue("PHYMEMORY", p.WorkingSet64.ToString());

                    /// SystemInfo使用了性能计数器,有可能构造不出来
                    ///
                    resp.SetValue("AVAIL_PHYMEMORY", 0);
                    resp.SetValue("MAX_PHYMEMORY", 0);
                    resp.SetValue("CPUUSAGE", 0);

                    try
                    {
                        resp.SetValue("AVAIL_PHYMEMORY", SystemInfo.Instance.MemoryAvailable);
                        resp.SetValue("MAX_PHYMEMORY", SystemInfo.Instance.PhysicalMemory);
                        resp.SetValue("CPUUSAGE", (int)SystemInfo.Instance.CpuLoad);
                    }
                    catch { }

                    resp.SetValue("STATUS", AlarmManager.instance().GetStatus().ToString());
                    resp.SetValue("STARTTIME", p.StartTime.ToString());
                    resp.SetValue("CPUTIME", ((long)p.TotalProcessorTime.TotalMinutes).ToString());
                    resp.SetValue("ALARMCLIENTS", AlarmManager.instance().GetAlarmClientsNum().ToString());
                    resp.SetValue("MAX_ALARMCLIENTS", AlarmManager.instance().MaxClients);
                    resp.SetValue("ADAPTERCLIENTS", AlarmManager.instance().GetAdapterClientsNum().ToString());
                    resp.SetValue("MAX_ADAPTERCLIENTS", AlarmManager.instance().MaxAdapters);
                    resp.SetValue("ACTIVEALARMNUM", AlarmManager.instance().GetActiveAlarmsNum().ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.SERVER_GETCURLOG:
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetCurrentLog())
                    {
                        sb.Append(s);
                    }

                    resp.SetValue("CURLOG", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.SERVER_GETLOGFILES:
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string s in GetLogFiles())
                    {
                        sb.Append(s);
                        sb.Append(",");
                    }

                    if (sb.Length > 0)
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }

                    resp.SetValue("LOGFILES", sb.ToString());
                    resp.SetValue(Constants.MSG_PARANAME_RESULT, "OK");
                }
                break;

                case Constants.TK_CommandType.MON_GETTERMINALSINFO:
                {
                    C5.HashDictionary <long, AdapterInfo> ads = new C5.HashDictionary <long, AdapterInfo>();
                    AlarmManager.instance().GetAdaptersInfo(ads);

                    resp.SetValue(Constants.MSG_PARANAME_TERMINALS_INFO, ads);
                }
                break;

                default:
                    break;
                }

                CommandProcessor.instance().DispatchCommand(resp);
            }
            catch (Exception ex)
            {
                Main_LogReceived("", ex.ToString());
            }
        }
Пример #12
0
        public static IEnumerable <IPathNode <N> > GetShortestPath <N>(N start, N goal, IHeuristic <N> heuristic) where N : INode <N>
        {
            C5.IDictionary <N, PathNode <N> > nodeDictionary = new C5.HashDictionary <N, PathNode <N> >();
            C5.IPriorityQueue <PathNode <N> > openSet        = new C5.IntervalHeap <PathNode <N> >(new PathNodeComparer <N>());
            C5.ICollection <N> closedSet = new C5.HashSet <N>();

            PathNode <N> curNode = new PathNode <N>(start);

            curNode.g = 0;
            nodeDictionary.Add(start, curNode);
            while (true)
            {
                foreach (IEdge <N> edge in curNode.Node)
                {
                    N other = edge.GetEnd();
                    if (!closedSet.Contains(other))
                    {
                        PathNode <N> otherNode = null;
                        if (!nodeDictionary.Find(ref other, out otherNode))
                        {
                            otherNode = new PathNode <N>(other);
                            nodeDictionary.Add(other, otherNode);
                        }
                        float newG = edge.GetCost() + curNode.g;
                        if (otherNode.g > newG)
                        {
                            otherNode.g = newG;
                            if (otherNode.queueHandle != null)
                            {
                                openSet.Replace(otherNode.queueHandle, otherNode);
                            }
                            otherNode.prev = curNode;
                        }
                        if (otherNode.queueHandle == null)
                        {
                            otherNode.h = heuristic.MinDist(other, goal);
                            C5.IPriorityQueueHandle <PathNode <N> > handle = null;
                            openSet.Add(ref handle, otherNode);
                            otherNode.queueHandle = handle;
                        }
                    }
                }
                if (openSet.IsEmpty)
                {
                    return(null);
                }
                closedSet.Add(curNode.Node);
                curNode = openSet.DeleteMin();
                if (curNode.Node.Equals(goal))
                {
                    C5.ArrayList <IPathNode <N> > res = new C5.ArrayList <IPathNode <N> >();
                    do
                    {
                        res.Add(curNode);
                        curNode = curNode.prev;
                    } while (curNode != null);

                    res.Reverse();
                    return(res);
                }
            }
        }