Exemple #1
0
 internal void Dispose()
 {
     if (Context != null)
     {
         Context.Dispose();
     }
     Context = null; ID = null;
 }
        private WSDCItem CreateIfNotValid(Type _ContextType, WSRequestID _RequestID, WSDCState State, Func <WSDCItem, bool> iFunc)
        {
            WSDCItem DCItem = null;

            switch (State)
            {
            case WSDCState.Broken:                                                                          //RESET current connection
                DCItem = new WSDCItem((WSDataContext)Activator.CreateInstance(_ContextType), _RequestID);
                Items  = Items.Select(x => x.Context.GetType().Equals(_ContextType) ? DCItem : x).ToList(); //).ToList();
                break;

            case WSDCState.Disposed:                                                                        //RESET current connection
                DCItem = new WSDCItem((WSDataContext)Activator.CreateInstance(_ContextType), _RequestID);
                Items  = Items.Select(x => x.Context.GetType().Equals(_ContextType) ? DCItem : x).ToList(); //).ToList();
                break;

            case WSDCState.NotExists:    //ADD new connection
                DCItem = new WSDCItem((WSDataContext)Activator.CreateInstance(_ContextType), _RequestID);
                Items.Add(DCItem);
                break;

            case WSDCState.Connecting:    //ADD new connection
                DCItem = new WSDCItem((WSDataContext)Activator.CreateInstance(_ContextType), _RequestID);
                Items.Add(DCItem);
                break;

            case WSDCState.Executing:    //ADD new connection
                DCItem = new WSDCItem((WSDataContext)Activator.CreateInstance(_ContextType), _RequestID);
                Items.Add(DCItem);
                break;

            case WSDCState.Fetching:    //ADD new connection
                DCItem = new WSDCItem((WSDataContext)Activator.CreateInstance(_ContextType), _RequestID);
                Items.Add(DCItem);
                break;

            case WSDCState.Closed:    //SKIP : may not update open connection!!!
                DCItem = Items.FirstOrDefault(iFunc);
                break;

            case WSDCState.Open:    //SKIP : may not update open connection!!!DCItem.Context.Dispose();
                DCItem = Items.FirstOrDefault(iFunc);
                break;

            default:    //SKIP : may not update open connection!!!DCItem.Context.Dispose();
                DCItem = Items.FirstOrDefault(iFunc);
                break;
            }
            return(DCItem);
        }
Exemple #3
0
        internal bool GetContext(Type _ContextType, WSRequestID _RequestID, out WSDataContext _context)
        {
            _context = null;
            try
            {
                WSSessionCache SessionCache = SessionsCache.FirstOrDefault(x => x.SessionID.Equals(_RequestID.SessionID));
                if (SessionCache == null)
                {
                    SessionCache = new WSSessionCache(_RequestID.SessionID);
                    SessionsCache.Add(SessionCache);
                }

                return(SessionCache.GetContext(_ContextType, _RequestID, out _context));
            }
            catch (Exception) { return(false); }
        }
        internal bool GetContext(Type _ContextType, WSRequestID _RequestID, out WSDataContext _Context)
        {
            _Context = null;
            try
            {
                WSDCState             State = _ContextType.GetState(Items);
                Func <WSDCItem, bool> iFunc = (x =>
                                               x.Context != null &&
                                               !x.Context.IsDisposed &&
                                               x.Context.GetType() == _ContextType &&
                                               (State == WSDCState.Closed || State == WSDCState.Open)
                                               );

                WSDCItem DCItem = Items.Any(iFunc) ? Items.FirstOrDefault(iFunc) : CreateIfNotValid(_ContextType, _RequestID, State, iFunc);

                WSDCItem.Open(DCItem);

                _Context = DCItem == null ? null : DCItem.Context;

                return(_Context != null);
            }
            catch (Exception) { return(false); }
        }
Exemple #5
0
 public WSDCItem(WSDataContext _Context, WSRequestID _ID)
 {
     Context = _Context;
     ID      = _ID;
 }
        private static WSDataContext GetClientContext(string dbName, WSRequestID RequestID, string _Caller)
        {
            WSDataContext dc = null;

            if (CoreSources == null) /*LoadStatus.AddNote("CS is NULL : [{LoadStatusStatic:" + LoadStatusStatic + "}]");*/ } {
 internal static WSDataContext GetInternalContext(string dbName, WSRequestID RequestID, string _Caller)
 {
     return(GetClientContext(dbName, RequestID, _Caller));
 }