Ejemplo n.º 1
0
 internal static void Dispose(WSDCItem DCItem)
 {
     if (DCItem != null)
     {
         DCItem.Dispose(); DCItem.LastModified = DateTime.Now;
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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); }
        }
Ejemplo n.º 4
0
 internal static void Open(WSDCItem DCItem)
 {
     DCItem.Open(); DCItem.LastModified = DateTime.Now;
 }