Пример #1
0
 protected override void OnDispose(bool inIsDisposing)
 {
     if (inIsDisposing)
     {
         DisposableBase.SafeDispose(_requestor);
     }
 }
Пример #2
0
 protected override void OnDispose(bool inIsDisposing)
 {
     if (inIsDisposing)
     {
         DisposableBase.SafeDispose(ref _processingIntervalEvent);
     }
 }
Пример #3
0
 protected override void OnDispose(bool inIsDisposing)
 {
     if (inIsDisposing)
     {
         DisposableBase.SafeDispose(ref _mutex);
     }
 }
Пример #4
0
 public static void ClearAllWaitCursors()
 {
     for (int i = s_CurrentUseWaitCursors.Count - 1; i >= 0; --i)
     {
         DisposableBase.SafeDispose(s_CurrentUseWaitCursors[i]);
     }
     s_CurrentUseWaitCursors.Clear();
 }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableBase.SafeDispose(ref zipStream);
         DisposableBase.SafeDispose(ref fileStream);
     }
     base.Dispose(disposing);
 }
Пример #6
0
 protected override void OnShutdown()
 {
     try
     {
         base.OnShutdown();
     }
     finally
     {
         DisposableBase.SafeDispose(ref m_StartupMutex);
     }
 }
        public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, string username,
                                        string testPassword, string prodPassword)
        {
            ExceptionUtils.ThrowIfEmptyString(username);
            ExceptionUtils.ThrowIfEmptyString(testPassword);
            ExceptionUtils.ThrowIfEmptyString(prodPassword);

            INodeEndpointClient client = null;

            try
            {
                AuthenticationCredentials credentials = new AuthenticationCredentials(username, testPassword);
                client = Make(targetEndpointUrl, type, credentials);
                // First, check to ping the node to make sure it is up and running
                try
                {
                    client.NodePing();
                }
                catch (Exception pingEx)
                {
                    throw new ArgumentException(string.Format("The node endpoint \"{0}\" cannot be contacted.  NodePing returned the error: {1}",
                                                              targetEndpointUrl, ExceptionUtils.GetDeepExceptionMessage(pingEx)));
                }

                client.Authenticate();
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(ref client);
            }
            if (client == null)
            {
                try
                {
                    AuthenticationCredentials credentials = new AuthenticationCredentials(username, prodPassword);
                    client = Make(targetEndpointUrl, type, credentials);
                    client.Authenticate();
                }
                catch (Exception)
                {
                    DisposableBase.SafeDispose(ref client);
                }
            }
            if (client == null)
            {
                throw new ArgumentException(string.Format("The NAAS user \"{0}\" failed to authenticate against the node endpoint \"{1}\".  Please check that the NAAS user's username and password have been entered correctly.",
                                                          username, targetEndpointUrl));
            }
            return(client);
        }
Пример #8
0
        protected virtual PluginDomainInstanceLoader GetPluginInstanceLoader(string pluginConfigFilePath, string pluginFilePath)
        {
            if (string.IsNullOrEmpty(pluginConfigFilePath) || (PluginInstanceLoadersCacheTimeInMinutes <= 0))
            {
                // This is not an expensive case with string.IsNullOrEmpty(pluginConfigFilePath), since we are
                // not creating spring objects, so don't cache
                //
                // OR
                //
                // we've specified to turn off the cache with PluginInstanceLoadersCacheTimeInMinutes <= 0
                return(new PluginDomainInstanceLoader(pluginConfigFilePath, pluginFilePath));
            }
            const string CACHED_PLUGIN_INSTANCE_LOADERS = "_CACHED_PLUGIN_INSTANCE_LOADERS";
            string       cacheName = CACHED_PLUGIN_INSTANCE_LOADERS + "_" + pluginConfigFilePath + "_" + pluginFilePath;
            PluginDomainInstanceLoader loader;

            lock (s_CachedPluginInstanceLoadersLock)
            {
                loader = HttpRuntime.Cache[cacheName] as PluginDomainInstanceLoader;
            }
            if (loader != null)
            {
                return(loader);
            }
            string parentDirPath = Path.GetDirectoryName(Path.GetDirectoryName(pluginFilePath));

            loader = new PluginDomainInstanceLoader(pluginConfigFilePath, pluginFilePath);

            PluginDomainInstanceLoader loaderAlreadyThere = null;

            lock (s_CachedPluginInstanceLoadersLock)
            {
                loaderAlreadyThere = HttpRuntime.Cache[cacheName] as PluginDomainInstanceLoader;
                if (loaderAlreadyThere == null)
                {
                    loader.Acquire();
                    HttpRuntime.Cache.Add(cacheName, loader, new CacheDependency(parentDirPath),
                                          Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(PluginInstanceLoadersCacheTimeInMinutes),
                                          CacheItemPriority.AboveNormal, OnCachePluginDomainInstanceLoaderRemovedCallback);
                }
            }
            if (loaderAlreadyThere != null)
            {
                // Switch over to already cached instance
                DisposableBase.SafeDispose(ref loader);
                loader = loaderAlreadyThere;
            }
            return(loader);
        }
Пример #9
0
        public virtual IPluginDisposer LoadPluginInterface <T>(DataService inDataService, out T plugin) where T : class
        {
            IPluginDisposer disposer =
                LoadPluginInterfaceInstance <T>(inDataService, true, out plugin);

            try
            {
                ConfigurePlugin <T>(inDataService, plugin);
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(ref disposer);
                throw;
            }
            return(disposer);
        }
Пример #10
0
        private IDbConnection OpenDbConnection(string connectionString)
        {
            IDbConnection dbConnection = GetDbConnection(connectionString);

            try
            {
                LOG.Debug("OpenDbConnection: Attempting to open database connection: {0}", dbConnection.ConnectionString);
                dbConnection.Open();
                return(dbConnection);
            }
            catch (Exception e)
            {
                LOG.Error("OpenDbConnection: Failed to open database connection: {0}", e, dbConnection.ConnectionString);
                DisposableBase.SafeDispose(dbConnection);
                throw;
            }
        }
        /// <summary>
        /// Create a new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.
        /// The input credentials are authenticated against the client node before this method returns.
        /// </summary>
        /// <param name="targetEndpointUrl">The url for the Exchange node endpoint.</param>
        /// <param name="type">The version of the Exchange node endpoint.</param>
        /// <param name="credentials">The credentials used to authenticate with the Exchange node endpoint.</param>
        /// <param name="tempDirectoryPath">A local directory path used for creating temporary files during INodeEndpointClient method
        /// execution.  This value can be null, in which case the dafault system temp directory will be used.</param>
        /// <param name="proxy">Proxy information for accessing the Exchange node endpoint.  This value can be null if
        /// no proxy is required.</param>
        /// <returns>A new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.  Dispose()
        /// should be called on the returned instance when the caller is finished using the instance.</returns>
        public static INodeEndpointClient CreateClientAndAuthenticate(string targetEndpointUrl, EndpointVersionType type,
                                                                      AuthenticationCredentials credentials,
                                                                      string tempDirectoryPath, IWebProxy proxy)
        {
            INodeEndpointClient client = new NodeEndpointClientFactory().Make(targetEndpointUrl, type, credentials,
                                                                              tempDirectoryPath, proxy);

            try
            {
                client.Authenticate();
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(client);
                throw;
            }
            return(client);
        }
        /// <summary>
        /// Create a new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.
        /// The node is pinged after is it created to ensure it can be accessed.
        /// </summary>
        /// <param name="targetEndpointUrl">The url for the Exchange node endpoint.</param>
        /// <param name="type">The version of the Exchange node endpoint.</param>
        /// <param name="naasUserToken">A valid NAAS user token that will be used for validating this endpoint.</param>
        /// <param name="tempDirectoryPath">A local directory path used for creating temporary files during INodeEndpointClient method
        /// execution.  This value can be null, in which case the dafault system temp directory will be used.</param>
        /// <param name="proxy">Proxy information for accessing the Exchange node endpoint.  This value can be null if
        /// no proxy is required.</param>
        /// <returns>A new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.  Dispose()
        /// should be called on the returned instance when the caller is finished using the instance.</returns>
        public static INodeEndpointClient CreateClientAndPing(string targetEndpointUrl, EndpointVersionType type,
                                                              string naasUserToken, string tempDirectoryPath,
                                                              IWebProxy proxy)
        {
            INodeEndpointClient client = new NodeEndpointClientFactory().Make(targetEndpointUrl, type, naasUserToken,
                                                                              tempDirectoryPath, proxy);

            try
            {
                client.NodePing();
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(client);
                throw;
            }
            return(client);
        }
Пример #13
0
        public SingleInstanceApplication(string inUniqueId, bool inRunPerWindowsUser)
        {
            this.IsSingleInstance   = true;
            this.EnableVisualStyles = true;
            this.ShutdownStyle      = ShutdownMode.AfterMainFormCloses;
            string mutexName =
                inRunPerWindowsUser ? inUniqueId : cGlobalKernelObjectPrefix + inUniqueId;
            bool isMutexOwner = false;

            m_StartupMutex     = new Mutex(true, mutexName, out isMutexOwner);
            m_IsRunningAlready = !isMutexOwner;
            if (m_IsRunningAlready)
            {
                // If there is already an instance running, set the m_IsRunningAlready flag so that
                // we will exit gracefully.  The Mutex check is needed here since the base class does not check
                // for "global" single-instance apps, only per-user single-instance apps.
                DisposableBase.SafeDispose(ref m_StartupMutex);
            }
        }
Пример #14
0
        protected virtual ICollection <SimpleDataService> GetDataServiceImplementersInDirectory(string inDirectoryPath,
                                                                                                bool ignoreInstallingAssemblies)
        {
            OrderedSet <SimpleDataService> implementers = new OrderedSet <SimpleDataService>();

            if (Directory.Exists(inDirectoryPath))
            {
                OrderedSet <string>        processedAssemblies = new OrderedSet <string>();
                PluginDomainInstanceLoader loader = null;
                try
                {
                    PluginInstanceFinder pluginFinder = null;
                    foreach (string dllPath in Directory.GetFiles(inDirectoryPath, "*.dll", SearchOption.AllDirectories))
                    {
                        if (!ignoreInstallingAssemblies || !IsInstallingPluginAssemblyPath(dllPath))
                        {
                            string assemblyName = Path.GetFileName(dllPath);
                            if (!processedAssemblies.Contains(assemblyName))
                            {
                                string assemblyPath = GetPluginFilePathInDirectory(assemblyName, inDirectoryPath,
                                                                                   ignoreInstallingAssemblies);
                                if (assemblyPath != null)
                                {
                                    if (loader == null)
                                    {
                                        // Don't need to load spring objects here
                                        loader       = GetPluginInstanceLoader(null, assemblyPath);
                                        pluginFinder = loader.GetInstance <PluginInstanceFinder>();
                                    }
                                    GetDataServiceImplementers(pluginFinder, assemblyPath, ref implementers);
                                }
                                processedAssemblies.Add(assemblyName);
                            }
                        }
                    }
                }
                finally
                {
                    DisposableBase.SafeDispose(ref loader);
                }
            }
            return(implementers);
        }
Пример #15
0
        protected virtual IPluginDisposer LoadPluginInterfaceInstance <T>(DataService inDataService,
                                                                          bool ignoreInstallingAssemblies,
                                                                          string pluginConfigFilePath,
                                                                          out T plugin) where T : class
        {
            string pluginFilePath               = GetPluginFilePath(inDataService, ignoreInstallingAssemblies);
            PluginDomainInstanceLoader loader   = GetPluginInstanceLoader(pluginConfigFilePath, pluginFilePath);
            PluginDisposer             disposer = new PluginDisposer(loader);

            try
            {
                plugin = loader.GetInstance <T>(pluginFilePath, inDataService.PluginInfo.ImplementingClassName);
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(ref disposer);
                throw;
            }
            return(disposer);
        }
Пример #16
0
 protected override void DoStop()
 {
     try
     {
         foreach (INodeProcessor processor in Processors)
         {
             processor.RequestStop();
         }
         foreach (INodeProcessor processor in Processors)
         {
             processor.Join();
         }
         DisposableBase.SafeDispose(ThreadQueueServer);
     }
     catch (Exception e)
     {
         LOG.Error("DoStop() threw an exception.", e);
         throw;
     }
 }
Пример #17
0
 public void Dispose()
 {
     DisposableBase.SafeDispose(ref m_StartupMutex);
 }
Пример #18
0
 private static async Task DisposeAsyncTestCore(DisposableBase disp)
 {
     await using (disp.ConfigureAwait(false)) { }
 }