SourceSubmitContext CreateSourceSubmitContext(QueryParam query)
        {
            var context = new SourceSubmitContext();

            lock (_lockObject)
            {
                context.UsingSharedContext = QueryConfiguration.Current.StopQueryWhenFoundTicket;

                if (!context.UsingSharedContext)
                {
                    context.Queries = new List <QueryParam>()
                    {
                        query
                    }
                }
                ;
            }

            return(context);
        }

        void EnsureCreateSharedSubmitContext(IOrderSubmitEventSource source)
        {
            lock (_lockObject)
            {
                if (_sharedSourceSubmitContext != null)
                {
                    return;
                }

                _sharedSourceSubmitContext = new SourceSubmitContext();
                var queries = Session.UserProfile.QueryParams;
                //非停止状态/有票状态
                _sharedSourceSubmitContext.Queries = queries.Where(s => s.QueryState == QueryState.Query || s.QueryState == QueryState.Wait || s == source.Query).ToList();
            }
        }

        void LogMessage(string msg)
        {
            Events.OnMessage(this, new EventInfoArgs(msg));
            OnNotificationCreated(this, new GeneralEventArgs <string>(msg));
        }
        void source_SubmitClosed(object sender, System.EventArgs e)
        {
            var source = sender as IOrderSubmitEventSource;

            if (source == null || !_sources.ContainsKey(source))
            {
                return;
            }


            lock (_lockObject)
            {
                if (!_sources.ContainsKey(source))
                {
                    return;
                }

                var context = _sources[source];
                _sources.Remove(source);

                //如果不是使用共享的context,则关闭后恢复对应的查询
                if (context.OperationByAutoResume && !context.IsSubmitSuccess)
                {
                    if (!context.UsingSharedContext)
                    {
                        context.Queries.ForEach(s => s.OnRequestQuery(false));
                    }
                    //如果没有查询了,则恢复查询
                    if (_sources.Count == 0)
                    {
                        _sharedSourceSubmitContext?.Queries.ForEach(s => s.OnRequestQuery(false));
                        _sharedSourceSubmitContext = null;
                    }
                }
            }
        }