}         // func CreateDictionary

        /// <summary></summary>
        /// <param name="configItem"></param>
        /// <param name="id"></param>
        /// <param name="displayName"></param>
        /// <param name="listDescriptor"></param>
        /// <param name="comparer"></param>
        /// <returns></returns>
        public static DEDictionary <TKey, TItem> CreateSortedList(DEConfigItem configItem, string id, string displayName, IDEListDescriptor listDescriptor = null, IComparer <TKey> comparer = null)
        {
            return(new DEDictionary <TKey, TItem>(configItem, id, displayName,
                                                  listDescriptor ?? DEConfigItem.CreateListDescriptorFromType(typeof(KeyValuePair <TKey, TItem>)),
                                                  new SortedDictionary <TKey, TItem>(comparer ?? Comparer <TKey> .Default)
                                                  ));
        } // func CreateSortedList
Esempio n. 2
0
        }         // proc CloseEventSessions

        #region -- Events -----------------------------------------------------------------

        public void AppendNewEvent(DEConfigItem item, string eventId, string index, XElement values = null)
        {
            lock (propertyChanged)
            {
                if (currentRevision == sendedRevision)
                {
                    currentRevision++;
                }

                CleanOutdatedEvents();

                var        configPath = item.ConfigPath;
                var        key        = GetEventKey(configPath, eventId, index);
                FiredEvent ev;
                if (propertyChanged.TryGetValue(key, out ev))
                {
                    ev.Reset(currentRevision, values);
                }
                else
                {
                    propertyChanged[key] = ev = new FiredEvent(currentRevision, configPath, eventId, index, values);
                }

                // web socket event handling
                FireEventOnSocket(configPath, eventId, ev.GetEvent());
            }
        }         // proc AppendNewEvent
Esempio n. 3
0
        private XElement HttpDumpAction(bool mini = false)
        {
            // check for the procdump.exe
            var procDump = Config.Element(xnServer)?.GetAttribute("procdump", String.Empty);

            if (String.IsNullOrEmpty(procDump) || !File.Exists(procDump))
            {
                throw new ArgumentException("procdump.exe is not available.");
            }

            // prepare arguments
            var sbArgs = new StringBuilder();

            if (!mini)
            {
                sbArgs.Append("-ma ");                                 // dump all
            }
            sbArgs.Append("-o ");                                      // overwrite existing dump
            sbArgs.Append("-accepteula ");                             // accept eula
            sbArgs.Append(Process.GetCurrentProcess().Id).Append(' '); // process id

            // create the dump in the temp directory
            DumpFileInfo fi;

            using (dumpFiles.EnterWriteLock())
            {
                var newId = ++lastDumpFileInfoId;
                dumpFiles.Add(fi = new DumpFileInfo(newId, Path.Combine(Path.GetTempPath(), $"DEServer_{newId:000}.dmp")));
            }

            sbArgs.Append(fi.FileName);

            // prepare calling procdump
            ProcessStartInfo psi = new ProcessStartInfo(procDump, sbArgs.ToString());

            psi.UseShellExecute        = false;
            psi.RedirectStandardOutput = true;
            using (var p = Process.Start(psi))
            {
                if (!p.WaitForExit(5 * 60 + 1000))
                {
                    p.Kill();
                }

                var outputText = p.StandardOutput.ReadToEnd();

                return(DEConfigItem.SetStatusAttributes(
                           new XElement("return",
                                        new XAttribute("id", fi.Id),
                                        new XAttribute("exitcode", p.ExitCode)
                                        ),
                           p.ExitCode > 0,
                           outputText
                           ));
            }
        }         // proc HttpDumpAction
Esempio n. 4
0
        public DEListControllerBase(DEConfigItem configItem, IDEListDescriptor descriptor, string id, string displayName)
        {
            this.configItem  = configItem;
            this.id          = id;
            this.displayName = displayName;
            this.descriptor  = descriptor;
            this.listLock    = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

            configItem.RegisterList(id, this);
        }         // ctor
Esempio n. 5
0
            public ConfigItemProperty(DEConfigItem configItem, PropertyDescriptor property)
            {
                var name   = (PropertyNameAttribute)property.Attributes[typeof(PropertyNameAttribute)];
                var format = (FormatAttribute)property.Attributes[typeof(FormatAttribute)];

                Init(configItem,
                     name != null && !String.IsNullOrEmpty(name.Name) ? Name = name.Name : property.ComponentType.Name + "_" + property.Name,
                     format != null ? format.Format : null,
                     property
                     );
            }             // ctor
Esempio n. 6
0
        public void TestDictionaryDescriptor()
        {
            var descriptor = DEConfigItem.CreateListDescriptorFromType(typeof(KeyValuePair <string, IDEConfigItemProperty>));
            var typeString = GetListTypeString(descriptor);

            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><property><attribute name=\"key\" type=\"string\" /><attribute name=\"name\" type=\"string\" /><attribute name=\"displayname\" type=\"string\" /><attribute name=\"category\" type=\"string\" /><attribute name=\"description\" type=\"string\" /><attribute name=\"format\" type=\"string\" /><attribute name=\"type\" type=\"type\" /><element type=\"object\" /></property>", typeString);

            var rowString = GetListItemString(descriptor, new KeyValuePair <string, IDEConfigItemProperty>("key", new SimpleConfigItemProperty <int>(null, "Name", "DisplayName", "Category", "Description", "N0", 23)));

            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><property key=\"key\" name=\"Name\" displayname=\"DisplayName\" category=\"Category\" description=\"Description\" format=\"N0\" type=\"int\">23</property>", rowString);
        }
Esempio n. 7
0
            }             // ctor

            private void Init(DEConfigItem configItem, string name, string format, PropertyDescriptor property)
            {
                this.configItem = configItem;
                this.property   = property;

                this.Name   = name;
                this.Format = format;

                this.property = property;

                valueChangedHandler = ValueChangedHandler;
            }             // proc Init
Esempio n. 8
0
        }         // proc Dispose

        #endregion

        #region -- Configuration ----------------------------------------------------------

        private static void CollectCronJobItems(List <ICronJobItem> cronItems, DEConfigItem current)
        {
            if (current is ICronJobItem)
            {
                cronItems.Add((ICronJobItem)current);
            }
            else             // No recursion, for nested cron jobs
            {
                foreach (var c in current.UnsafeChildren)
                {
                    CollectCronJobItems(cronItems, c);
                }
            }
        }         // proc CollectCronJobItems
Esempio n. 9
0
        }         // proc Disposing

        private void GetFullName(DEConfigItem cur, StringBuilder sb)
        {
            if (cur == null)
            {
                return;
            }

            // Vorgänger
            GetFullName(cur.Owner as DEConfigItem, sb);

            // AKtuelle
            if (sb.Length > 0)
            {
                sb.Append('\\');
            }
            sb.Append(cur.Name);
        }         // func GetFullName
Esempio n. 10
0
        }         // ctor

        /// <summary></summary>
        /// <param name="item"></param>
        /// <param name="context"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public object Invoke(DEConfigItem item, IDEWebRequestScope context, LogMessageScopeProxy log = null)
        {
            if (action != null)
            {
                if (isNativeCall)
                {
                    action(item, context, log);
                    return(DBNull.Value);
                }
                else
                {
                    return(action(item, context, log));
                }
            }
            else
            {
                return(null);
            }
        }         // proc Invoke
Esempio n. 11
0
        }         // ctor

        public object Invoke(DEConfigItem item, IDEContext context)
        {
            if (action != null)
            {
                if (isNativeCall)
                {
                    action(item, context);
                    return(DBNull.Value);
                }
                else
                {
                    return(action(item, context));
                }
            }
            else
            {
                return(null);
            }
        }         // proc Invoke
Esempio n. 12
0
            }             // proc UseNode

            #endregion

            #region -- List -----------------------------------------------------------------

            private IEnumerable <XElement> GetNodeList(DEConfigItem current, bool recusive)
            {
                using (currentItem.EnterReadLock())
                {
                    foreach (var c in current.UnsafeChildren)
                    {
                        var x = new XElement("n",
                                             new XAttribute("name", c.Name),
                                             new XAttribute("displayName", c.DisplayName)
                                             );

                        if (recusive)
                        {
                            x.Add(GetNodeList(c, true));
                        }

                        yield return(x);
                    }
                }
            }             // func GetNodeList
Esempio n. 13
0
        }         // proc CloseEventSessions

        #endregion

        #region -- Events -------------------------------------------------------------

        public void AppendNewEvent(DEConfigItem item, string securityToken, string eventId, string index, XElement values = null)
        {
            lock (propertyChanged)
            {
                if (currentRevision == sendedRevision)
                {
                    currentRevision++;
                }

                CleanOutdatedEvents();

                var configPath = item.ConfigPath;
                var key        = GetEventKey(configPath, eventId, index);
                if (propertyChanged.TryGetValue(key, out var ev))
                {
                    ev.Reset(currentRevision, values);
                }
                else
                {
                    propertyChanged[key] = ev = new FiredEvent(currentRevision, configPath, eventId, index, values);
                }

                // use security from item as default
                if (String.IsNullOrEmpty(securityToken))
                {
                    securityToken = item.SecurityToken;
                }

                // internal event handling, copy the event session, because they might changed during the post
                EventSession[] currentSventSessions;
                using (eventSessions.EnterReadLock())
                    currentSventSessions = eventSessions.List.Cast <EventSession>().ToArray();

                foreach (var es in currentSventSessions)
                {
                    es.TryPostNotify(configPath, securityToken, eventId, ev.GetEvent(), CancellationToken.None);
                }
            }
        }         // proc AppendNewEvent
Esempio n. 14
0
            }             // proc UseItem

            private void UseNode(DEConfigItem current, string path, int offset)
            {
                if (offset >= path.Length)
                {
                    currentItem = current;
                    return;
                }
                else
                {
                    var pos = path.IndexOf('/', offset);
                    if (pos == offset)
                    {
                        throw new ArgumentException("Invalid path format.");
                    }
                    if (pos == -1)
                    {
                        pos = path.Length;
                    }

                    if (pos - offset == 0)                     // end
                    {
                        this.currentItem = current;
                    }
                    else                     // find node
                    {
                        var currentName = path.Substring(offset, pos - offset);
                        var newCurrent  = current.UnsafeFind(currentName);
                        if (newCurrent == null)
                        {
                            throw new ArgumentException("Invalid path.");
                        }

                        UseNode(newCurrent, path, pos + 1);
                    }
                }
            }             // proc UseNode
Esempio n. 15
0
 private DEDictionary(DEConfigItem configItem, string id, string displayName, IDEListDescriptor listDescriptor, IDictionary <TKey, TItem> innerDictionary)
     : base(configItem, listDescriptor, id, displayName)
 {
     this.innerDictionary = innerDictionary;
 }         // ctor
Esempio n. 16
0
            }             // ctor

            public ConfigItemProperty(DEConfigItem configItem, string name, string format, PropertyDescriptor property)
            {
                Init(configItem, name, format, property);
            }             // ctor
Esempio n. 17
0
 public DEList(DEConfigItem configItem, string id, string displayName)
     : base(configItem, DEConfigItem.CreateListDescriptorFromType(typeof(T)), id, displayName)
 {
 }         // ctor
Esempio n. 18
0
        }         // ctor

        public DEDictionary(DEConfigItem configItem, string id, string displayName, IComparer <TKey> comparer)
            : base(configItem, null, id, displayName)
        {
            this.innerDictionary = new SortedDictionary <TKey, TItem>(comparer == null ? Comparer <TKey> .Default : comparer);
        }         // ctor
Esempio n. 19
0
 public ConfigActionDictionary(DEConfigItem configItem)
     : base(configItem, ConfigActionListDescriptor.Instance, ActionsListId, "Actions")
 {
 }             // ctor