Пример #1
0
 private ulong AddRealTimer(AbsTimerData p)
 {
     lock (m_QueueLock)
     {
         m_RealTimeQueue.Enqueue(p.TimerId, p, p.NextTick);
         m_TimerDict.ForceAdd(p.TimerId, p);
     }
     return(p.TimerId);
 }
Пример #2
0
        public static RawMetadataDto GetAllMetadata(this HtmlDocument document)
        {
            var title = document.ReadFirstNodeValue("//head/title");
            var meta  = document.ReadNodes("//head/meta");

            var metaEntries = new Dictionary <string, string>();

            foreach (var htmlNode in meta)
            {
                var content = htmlNode.GetAttributeValue("content", null);
                if (string.IsNullOrEmpty(content))
                {
                    continue;
                }

                var name = htmlNode.GetAttributeValue("name", null);
                if (!string.IsNullOrEmpty(name))
                {
                    metaEntries.ForceAdd(name, content);
                }

                var property = htmlNode.GetAttributeValue("property", null);
                if (!string.IsNullOrEmpty(property))
                {
                    metaEntries.ForceAdd(property, content);
                }
            }

            var links = document.ReadNodes("//head/link");

            var linkEntries = new Dictionary <string, string>();

            foreach (var htmlNode in links)
            {
                var rel = htmlNode.GetAttributeValue("rel", null);
                if (string.IsNullOrEmpty(rel))
                {
                    continue;
                }

                var href = htmlNode.GetAttributeValue("href", null);
                if (!string.IsNullOrEmpty(href))
                {
                    linkEntries.ForceAdd(rel, href);
                }
            }

            return(new RawMetadataDto {
                Title = title, Meta = metaEntries, Links = linkEntries
            });
        }
Пример #3
0
        //------------------------------------------------------------------------------------------------------------------------
        public virtual void AddFromSource(IEnumerable <KeyValuePair <TKey, TValue> > source)
        {
            if (source == null)
            {
                return;
            }

            //perform operation
            lock (locker)
            {
                IncreaseRevision();
                if (InternalObject == null)
                {
                    InternalObject = new Dictionary <TKey, TValue>();
                }
                foreach (var entry in source)
                {
                    if (InternalObject.ContainsKey(entry.Key))
                    {
                        InternalObject[entry.Key] = entry.Value;
                    }
                    else
                    {
                        InternalObject.ForceAdd(entry.Key, entry.Value);
                    }
                }
            }
        }
Пример #4
0
        public static Dictionary <string, object> GetSemantics(string semantics)
        {
            //checks
            if (string.IsNullOrWhiteSpace(semantics))
            {
                return(null);
            }
            //deserialize
            var des = semantics.FromJSON <Dictionary <string, object> >();
            var ret = new Dictionary <string, object>();

            //restore values
            foreach (var __entry in des)
            {
                try
                {
                    var key   = __entry.Key;
                    var value = __entry.Value;

                    //fix values (deserialized json from object)
                    if (key == nameof(Boolean_Format))
                    {
                        value = Enum.Parse(typeof(Boolean_Format), value.ToStringInvariant());
                    }
                    else if (key == nameof(String_Case))
                    {
                        value = Enum.Parse(typeof(String_Case), value.ToStringInvariant());
                    }
                    else if (key == nameof(Decimal_Range))
                    {
                        value = (value as string).FromJSON <Decimal_Range>();
                    }
                    else if (key == nameof(Integer_Range))
                    {
                        value = (value as string).FromJSON <Integer_Range>();
                    }
                    //else if ...
                    else
                    {
                        DebugEx.Assert("Could not deserialize semantic entry");
                    }

                    //add to final dictionary
                    if (value != null)
                    {
                        ret.ForceAdd(key, value);
                    }
                }
                catch { }
            }
            //return result
            return(ret);
        }
Пример #5
0
 //------------------------------------------------------------------------------------------------------------------------
 public void Save()
 {
     try
     {
         lock (locker)
         {
             //compile data
             var data = new Dictionary <string, string>();
             foreach (var entry in Graphs)
             {
                 data.ForceAdd(entry.Key, entry.Value.GraphDescriptorString);
             }
             //save
             if (Node.SaveObject(DataIdentifier_Graphs, data, Secure: true) == false)
             {
                 DebugEx.TraceError("Could not save graphs");
             }
         }
     }
     catch (Exception ex) { DebugEx.Assert(ex, "Unhandled exception caught"); }
 }
Пример #6
0
        //------------------------------------------------------------------------------------------------------------------------
        public static Type GetType(string name, bool DeFriendlify = true)
        {
            //sanity check
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            //find type
            Type result = null;

            lock (cache)
                if (cache.TryGetValue(name, out result) == false)
                {
                    try
                    {
                        //resolve type
                        result = Type.GetType(name);

                        //If null go for fallback mechanisms
                        if (result == null)
                        {
                            //This is now in fallback. do not keep lock since what follows are expensive operations
                            Monitor.Exit(cache);
                            try
                            {
                                //if not found and not fully qualified search in all assemblies
                                if (result == null)
                                {
                                    string strippedName;
                                    //process name (strip assembly and recersivly extract generic types)
                                    if (name.Contains('['))
                                    {
                                        var lefovers = name.RightOf("[");
                                        var generics = new List <string>();
                                        int i        = 0;
                                        int start    = 0;
                                        for (int n = 0; n < lefovers.Length; n++)
                                        {
                                            var c = lefovers[n];
                                            if (c == '[')
                                            {
                                                if (i == 0)
                                                {
                                                    start = n + 1;
                                                }
                                                i++;
                                            }
                                            else if (c == ']')
                                            {
                                                i--;
                                                if (i == 0)
                                                {
                                                    generics.Add(lefovers.Substring(start, n - start));
                                                    start = n + 1;
                                                }
                                            }
                                        }
                                        //get types for each generic
                                        var genericsTypes = new List <Type>();
                                        foreach (var entry in generics)
                                        {
                                            var gt = GetType(entry);
                                            if (gt == null)
                                            {
                                                return(null);
                                            }
                                            genericsTypes.Add(gt);
                                        }
                                        //process found generics recursively
                                        strippedName = name.LeftOf("`") + "`" + generics.Count + "[" + string.Join(", ", genericsTypes.Select(t => "[" + t.AssemblyQualifiedName + "]")) + "]";
                                        //try a fast re-check of processed name
                                        result = Type.GetType(strippedName);
                                    }
                                    else
                                    {
                                        strippedName = name.LeftOf(",");
                                    }

                                    //search assemblies
                                    if (result == null)
                                    {
                                        foreach (var entry in GetAssemblies())
                                        {
                                            result = entry.GetType(strippedName);
                                            if (result != null)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }

                                //Try to find friendly named types
                                if (result == null && DeFriendlify)
                                {
                                    try { result = Type.GetType(Extensions.DeFriendlifyName(name)); }
                                    catch (Exception ex) { DebugEx.Assert(ex, "DeFriendlifyName failed"); }
                                }
                            }
                            catch (Exception ex) { DebugEx.Assert(ex, "Caught unhandled exception during type resolve"); }
                            finally { Monitor.Enter(cache); } //re-aquire lock before continuing
                        }
                    }
                    catch (Exception ex) { DebugEx.Assert(ex, "Unhandled excpetion while trying to resolve type"); }

                    //cache it
                    cache.ForceAdd(name, result);
                }

            //done and done
            return(result);
        }
Пример #7
0
 //------------------------------------------------------------------------------------------------------------------------
 public void Save()
 {
     try
     {
         lock (locker)
         {
             //compile data
             var data = new Dictionary<string, string>();
             foreach (var entry in Graphs)
                 data.ForceAdd(entry.Key, entry.Value.GraphDescriptorString);
             //save
             if (Node.SaveObject(DataIdentifier_Graphs, data, Secure: true) == false)
                 DebugEx.TraceError("Could not save graphs");
         }
     }
     catch (Exception ex) { DebugEx.Assert(ex, "Unhandled exception caught"); }
 }
Пример #8
0
        public static Dictionary<string, object> GetSemantics(string semantics)
        {
            //checks
            if (string.IsNullOrWhiteSpace(semantics))
                return null;
            //deserialize
            var des = semantics.FromJSON<Dictionary<string, object>>();
            var ret = new Dictionary<string, object>();
            //restore values
            foreach (var __entry in des)
            {
                try
                {
                    var key = __entry.Key;
                    var value = __entry.Value;

                    //fix values (deserialized json from object)
                    if (key == nameof(Boolean_Format))
                        value = Enum.Parse(typeof(Boolean_Format), value.ToStringInvariant());
                    else if (key == nameof(String_Case))
                        value = Enum.Parse(typeof(String_Case), value.ToStringInvariant());
                    else if (key == nameof(Decimal_Range))
                        value = (value as string).FromJSON<Decimal_Range>();
                    else if (key == nameof(Integer_Range))
                        value = (value as string).FromJSON<Integer_Range>();
                    //else if ...
                    else DebugEx.Assert("Could not deserialize semantic entry");

                    //add to final dictionary
                    if (value != null)
                        ret.ForceAdd(key, value);
                }
                catch { }
            }
            //return result
            return ret;
        }