Ejemplo n.º 1
0
        public static void Init(int capacity)
        { 
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);
			try
            {

                    if (configAdapter == null)
                    {
                        configAdapter = new ConfigurationSectionAdapter(new List<string> { "appSettings", "connectionStrings" });
                        configAdapter.ConfigSectionChanged += new ConfigurationSectionAdapter.ConfigChangedHandler(configAdapter_ConfigSectionChanged);
                    }

                    string timeout = ConfigurationManager.AppSettings[TaskMangerTimeOut] ?? "60000";
                    Timeout = int.Parse(timeout);
                     IList<PoolMsg> msgList = new List<PoolMsg>();                      
					for(int i=0;i<capacity; i++)
                    {
                        PoolMsg msg = new PoolMsg();
                        msg.id = i+1;
                        msgList.Add(msg);
                        //ThreadPool.QueueUserWorkItem(BatenderPool.worker,null);
                        Thread td = new Thread(new ParameterizedThreadStart(BartenderPool.worker));
                        td.Priority = ThreadPriority.AboveNormal;
                        td.Start(msg);                  
                                        
                        logger.InfoFormat("Waiting for stating BtEngine instance:{0}", (i + 1).ToString());
                        //msg.WaitEvent.WaitOne();
                        //logger.DebugFormat("Started BtEngine instance:{0} completed", (i + 1).ToString());
                        //if (msg.HasError)
                        //{
                        //    throw new Exception(msg.ErrorText);
                        //}
                    }
                    var waiteventList = msgList.Select(x=>x.WaitEvent).ToArray();
                    WaitHandle.WaitAll(waiteventList);
                    foreach (PoolMsg item in msgList)
                    {
                        if (item.HasError)
                        {
                            logger.ErrorFormat("Started BtEngine instance:{0} fail, error text :{1}", item.id.ToString(),item.ErrorText);
                        }
                        else
                        {
                            logger.InfoFormat("Started BtEngine instance:{0} completed", item.id.ToString());
                        }
                    }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
				throw;					
            }
			finally
			{
                logger.InfoFormat("END: {0}()", methodName);
			}
            
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Instance used for singleton
        /// </summary>
        public static void Start(int capacity)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                if (configAdapter==null)
                {
                    configAdapter =new ConfigurationSectionAdapter(new List<string> { "appSettings", "connectionStrings" });
                    configAdapter.ConfigSectionChanged += new ConfigurationSectionAdapter.ConfigChangedHandler(configAdapter_ConfigSectionChanged);
                }

                if (_instance == null)
                {
                    _instance = new TaskManager();
                    _instance.Start(capacity);
                    logger.InfoFormat("Task Manager instance {0} success! ", capacity.ToString());
                    foreach (TaskEngine engine in _instance.TaskEngines)
                    {                       
                        engine.VisibleWindows = Seagull.BarTender.Print.VisibleWindows.None;
                    }
                    string serverIP = ConfigurationManager.AppSettings[LicenseServerAdress];
                    string serverPort = ConfigurationManager.AppSettings[LicenseServerPort];
                    string serverRetries = ConfigurationManager.AppSettings[LicenseServerRetries];
                    string serverTimeout = ConfigurationManager.AppSettings[LicenseServerTimeout];

                    if (!string.IsNullOrEmpty(serverIP) &&
                        !string.IsNullOrEmpty(serverPort))
                    {
                        // Create a new LicenseServerTask.
                        LicenseServerTask task = new LicenseServerTask();
                        // Specify the license server connection.
                        task.PreferredConnection.Address = serverIP;
                        task.PreferredConnection.Port = int.Parse(serverPort);


                        if (!string.IsNullOrEmpty(serverRetries))
                        {
                            task.PreferredConnection.Retries = int.Parse(serverRetries);
                        }

                        if (!string.IsNullOrEmpty(serverTimeout))
                        {
                            task.PreferredConnection.Timeout = int.Parse(serverTimeout);
                        }
                        string timeout = ConfigurationManager.AppSettings[TaskMangerTimeOut] ?? "60000";
                        Timeout = int.Parse(timeout);
                        // Execute the task and wait for completion.
                        _instance.TaskQueue.QueueTaskAndWait(task, int.Parse(timeout));

                        // Report the results. 
                        if (task.IsConnected)
                        {
                            logger.InfoFormat("Bartender connected to license server:{0} port:{1} succes! ", serverIP, serverPort);
                        }
                        else
                        {
                            string errorText = string.Format("Bartender connect to license server:{0} port:{1} fail! ", serverIP, serverPort);
                            throw new Exception(errorText);
                        }
                    }
                    else
                    {
                        string errorText = string.Format("No setup license server address & Port! ");
                        logger.Error(errorText);
                        //throw new Exception("No setup license server address & Port");
                    }

                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
           
            
        }