示例#1
0
文件: CronEngine.cs 项目: s72785/des
        }         // proc StartJob

        public Task ExecuteJobAsync(ICronJobExecute job, CancellationToken cancellation)
        {
            using (currentJobs.EnterWriteLock())
            {
                if (currentJobs.FindIndex(c => job == c.Job) >= 0)
                {
                    throw new InvalidOperationException("Job is already running.");
                }

                using (currentJobs.EnterReadLock())
                {
                    foreach (var j in currentJobs)
                    {
                        if (!job.CanRunParallelTo(j.Job))
                        {
                            throw new InvalidOperationException(String.Format("Job is blocked (job: {0})", j.Job.DisplayName));
                        }
                    }
                }

                Log.Info("jobstart: {0}", job.DisplayName);
                var currentJob = new CurrentRunningJob(this, job, cancellation);
                currentJobs.Add(currentJob);
                return(currentJob.Task);
            }
        }         // func ExecuteJobAsync
示例#2
0
文件: DEServer.cs 项目: s72785/des
        private void HttpDumpLoadAction(IDEContext r, int id = -1)
        {
            // get the dump file
            DumpFileInfo di = null;

            using (dumpFiles.EnterReadLock())
            {
                var index = dumpFiles.FindIndex(c => c.Id == id);
                if (index >= 0)
                {
                    di = dumpFiles[index];
                }
            }

            // send the file
            if (di == null)
            {
                throw new ArgumentException("dump id is wrong.");
            }
            var fi = new FileInfo(di.FileName);

            if (!fi.Exists)
            {
                throw new ArgumentException("dump id is invalid.");
            }

            r.SetAttachment(fi.Name)
            .WriteFile(fi.FullName, MimeTypes.Application.OctetStream + ";gzip");
        }         // HttpDumpLoadAction
示例#3
0
        }         // func AcceptWebSocket

        private void FireEventOnSocket(string path, string eventId, XElement xEvent)
        {
            // prepare line
            var eventLine = xEvent.ToString(SaveOptions.DisableFormatting);

            var notifyTasks = new List <Task>();

            using (eventSessions.EnterReadLock())
            {
                // a call to notify can cause a remove of this session, this will be done in a different thread
                foreach (var es in eventSessions.List.Cast <EventSession>())
                {
                    notifyTasks.Add(es.NotifyAsync(path, eventId, eventLine, CancellationToken.None));
                }
            }

            Task.Run(() => Task.WhenAll(notifyTasks));
        }         // proc FireEventOnSocket
示例#4
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