Exemplo n.º 1
0
        public static Connection GetConnection(ServiceContext context)
        {
            Connection conn = new Connection();

            ConnectionSetup conSetup = new ConnectionSetup();

            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, context[SettingVariable.ServerName]);
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.UserID, context[SettingVariable.LoginUser]);
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Password, context[SettingVariable.LoginPassword]);
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Port, context[SettingVariable.ClientPort]);
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Authenticate, "true");
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.WindowsDomain, context[SettingVariable.WindowDomain]);
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.IsPrimaryLogin, "true");
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.TimeOut, context[SettingVariable.ConnectionTimeout]);

            var label = context[SettingVariable.SecurityLabelName];
            conSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.SecurityLabelName, label);
            if (label.ToLower() != "k2")
            {
                conSetup.ConnectionParameters[ConnectionSetup.ParamKeys.Integrated] = "false";
            }

            conn.Open(context[SettingVariable.ServerName], conSetup.ConnectionString);

            return conn;
        }
Exemplo n.º 2
0
 public static void InitConfigValue(ServiceContext context)
 {
     domain = context[SettingVariable.WindowDomain];
     k2User = context[SettingVariable.LoginUser];
     k2PassWord = context[SettingVariable.LoginPassword];
     label = context[SettingVariable.SecurityLabelName];
     clientPort = context[SettingVariable.ClientPort];
 }
Exemplo n.º 3
0
 public static Connection GetConnectionFromPool(ServiceContext context)
 {
     Connection conn = null;
     try
     {
         conn = K2ConnectionPool.GetConnection(context);
         if (conn != null && !string.IsNullOrEmpty(context.UserName) && conn.User.Name.ToLower() != context.UserName.ToLower())
             conn.ImpersonateUser(context.UserName);
     }
     catch (Exception ex)
     {
         if (conn == null)
             conn = GetConnection(context);
     }
     return conn;
 }
        public WorklistItem OpenWorklistItem(string userName, string shareUser, string sn, PlatformType platform, bool allocated)
        {
            try
            {
                ServiceContext context = new ServiceContext();
                context.UserName = K2User.ApplySecurityLabel(shareUser);
                GetK2OpenConnection(context.UserName);
                SourceCode.Workflow.Client.WorklistItem clientItem = null;
                if (!string.IsNullOrEmpty(shareUser))
                    clientItem = conn.OpenSharedWorklistItem(shareUser, string.Empty, sn, platform.ToString(), allocated);
                else
                    clientItem = conn.OpenWorklistItem(sn, platform.ToString(), allocated);
                WorklistItem item = ObjectConverter.ConvertToWFWorklistItem(context, clientItem);
                return item;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }
 public WorklistItem OpenWorklistItem(string userName, string sn, PlatformType platform, bool allocated)
 {
     try
     {
         ServiceContext context = new ServiceContext();
         context.UserName = K2User.ApplySecurityLabel(userName);
         GetK2OpenConnection(context.UserName);
         SourceCode.Workflow.Client.WorklistItem clientItem = conn.OpenWorklistItem(sn);
         WorklistItem item = ObjectConverter.ConvertToWFWorklistItem(context, clientItem);
         return item;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         conn.Close();
     }
 }
        public WorklistItem OpenWorklistItem(string userName, string sn, string shareUser)
        {
            try
            {
                ServiceContext context = new ServiceContext();
                context.UserName = K2User.ApplySecurityLabel(userName);
                GetK2OpenConnection(context.UserName);
                SourceCode.Workflow.Client.WorklistItem clientItem;
                if (shareUser == "null")
                {
                    shareUser = "";
                }
                if (!string.IsNullOrEmpty(shareUser))
                {
                    clientItem = conn.OpenSharedWorklistItem(shareUser, null, sn);
                }
                else
                {
                    clientItem = conn.OpenWorklistItem(sn);
                }

                WorklistItem item = ObjectConverter.ConvertToWFWorklistItem(context, clientItem);
                return item;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 7
0
        public static WorklistItem ConvertToWFWorklistItem(ServiceContext context, Client.WorklistItem origObj)
        {
            if (origObj == null)
            {
                return null;
            }
            WorklistItem wlItem = new WorklistItem();
            wlItem.ID = origObj.ID;
            wlItem.ProcInstID = origObj.ProcessInstance.ID;
            wlItem.ActInstDestID = origObj.ActivityInstanceDestination.ID;
            wlItem.ActInstID = origObj.ActivityInstanceDestination.ActInstID;
            //wlItem.ProcID = origObj.ProcID;
            wlItem.ActID = origObj.ActivityInstanceDestination.ActID;
            wlItem.EventID = origObj.EventInstance.ID;
            wlItem.Destination = origObj.AllocatedUser;
            wlItem.AssignedDate = origObj.ActivityInstanceDestination.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.StartDate = origObj.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            //wlItem.FinishDate = origObj.FinishDate;
            wlItem.Status = (WorklistStatus)(int)origObj.Status;
            //wlItem.ProfileID = origObj.ProfileID;
            //wlItem.TenantID = origObj.TenantID;
            wlItem.ActivityName = origObj.ActivityInstanceDestination.Name;
            wlItem.ActivityDispName = origObj.ActivityInstanceDestination.Name;
            wlItem.FullName = origObj.ProcessInstance.FullName;
            wlItem.ProcDispName = origObj.ProcessInstance.Name;
            //Added By:BingYi 2014-07-17 Fixed:The Originator should be included in worklist item.
            wlItem.Originator = origObj.ProcessInstance.Originator.Name;
            wlItem.Folio = origObj.ProcessInstance.Folio;
            //wlItem.FlowNumber = origObj.ProcessInstance.;
            wlItem.ProcInstStatus = (ProcInstStatus)(int)origObj.ProcessInstance.Status1;
            wlItem.ProcStartDate = origObj.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.SN = origObj.SerialNumber;
            wlItem.Data = origObj.Data;
            if (origObj.AllocatedUser.ToLower() != (K2User.ApplySecurityLabel(context.UserName)).ToLower())
            {
                wlItem.Data += "&SharedUser=" + origObj.AllocatedUser;
            }

            if (origObj.ProcessInstance != null)
            {
                wlItem.ProcessInstance = ConvertToWFProcessInstance(origObj.ProcessInstance, true);
            }

            var activityDataFields = new Dictionary<string, object>();
            foreach (Client.DataField item in origObj.ActivityInstanceDestination.DataFields)
            {
                if (activityDataFields.ContainsKey(item.Name))
                    activityDataFields[item.Name] = item.Value;
                else
                    activityDataFields.Add(item.Name, item.Value);
            }
            wlItem.ActivityDataFields = activityDataFields;

            foreach (Client.Action origAction in origObj.Actions)
            {
                ApproveAction action = new ApproveAction();
                action.Name = origAction.Name;
                action.MetaData = origAction.MetaData;
                //action.WorklistItem = wlItem;
                wlItem.Actions.Add(action);
            }
            return wlItem;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取一个K2连接池
        /// </summary>
        /// <returns></returns>
        public static Connection GetConnection(ServiceContext context)
        {
            InitConfigValue(context);
            //todo:   
            lock (oLock)
            {
                InitK2ConnPool(context);
            }

            lock (oLock)
            {
                CheckK2ConnPool();
            }

            int seed = 0;
            int currPoolId = -1;

            lock (oLock)
            {
                seed = rndGen.Next(maxPoolSize);

                for (int i = seed; i < maxPoolSize; i++)
                {
                    if (k2ConnWrap[i].Initialized
                        && k2ConnWrap[i].Status == 0)
                    {
                        k2ConnWrap[i].Status = 1;
                        currPoolId = i;
                        break;
                    }
                }

                if (currPoolId == -1)
                {
                    for (int i = seed - 1; i >= 0; i--)
                    {
                        if (k2ConnWrap[i].Initialized
                            && k2ConnWrap[i].Status == 0)
                        {
                            k2ConnWrap[i].Status = 1;
                            currPoolId = i;
                            break;
                        }
                    }
                }
            }

            //todo:
            try
            {
                if (currPoolId != -1)
                {
                    k2ConnWrap[currPoolId].TimeOfGetting = DateTime.Now;
                    k2ConnWrap[currPoolId].StackOfGetting = getStackInfo();

                    k2ConnWrap[currPoolId].K2Conn.RevertUser();
                    return k2ConnWrap[currPoolId].K2Conn;
                }
                else
                {
                    Exception exp = null;
                    int hasNoInitializedIndex = -1;
                    lock (oLock)
                    {

                        for (int i = 0; i < k2ConnWrap.Length; i++)
                        {
                            if (k2ConnWrap[i].Initialized) continue;

                            K2ConnWrap[i].Status = 1;
                            k2ConnWrap[i].Initialized = true;

                            hasNoInitializedIndex = i;
                            break;
                        }
                    }

                    if (hasNoInitializedIndex == -1)
                    {
                        return GetNewK2Conn(context);
                    }

                    int tryCount = 0;
                    for (; tryCount < aryServerName.Length; tryCount++)
                    {
                        curK2ServerIndex = curK2ServerIndex % aryServerName.Length;

                        try
                        {
                            k2ConnWrap[hasNoInitializedIndex].TimeOfGetting = DateTime.Now;
                            k2ConnWrap[hasNoInitializedIndex].StackOfGetting = getStackInfo();
                            k2ConnWrap[hasNoInitializedIndex].InitConn(context, aryServerName[curK2ServerIndex]);
                            return k2ConnWrap[hasNoInitializedIndex].K2Conn;
                        }
                        catch (Exception e)
                        {
                            exp = e;
                            curK2ServerIndex++;
                            continue;
                        }

                    }

                    K2PoolLogger.logError(
                        "所有的K2服务器都无法连接。\r\n"
                        + exp.Message + "\r\n" + exp.StackTrace);

                    throw exp;
                }
            }
            catch (Exception ex)
            {
                K2PoolLogger.logError("得到连接时出错K2ConnnectionPool.GetConnection(), \r\n "
                    + "currPoolId = " + currPoolId + ", \r\n"
                    + "ex.Messagee = " + ex.Message + "\r\n"
                    + "ex.StackTrace = " + ex.StackTrace);

                if (currPoolId >= 0 && currPoolId < k2ConnWrap.Length)
                {
                    k2ConnWrap[currPoolId].ReTryConn(context);
                    return k2ConnWrap[currPoolId].K2Conn;
                }

            }
            return null;
        }
Exemplo n.º 9
0
 public K2ServerProvider(ServiceContext context)
 {
     K2ServerProvider.InitConfigValue(context);
     //this.serverNames = System.Configuration.ConfigurationManager.AppSettings["K2Server"].ToString().Split(',');
     this.serverNames = context[SettingVariable.ServerName].Split(',');
     K2ServerProvider.availableServerName = this.serverNames[0];
 }
Exemplo n.º 10
0
        //public K2ConnWrap()
        //{
        //    this.k2conn = new Connection();
        //    try
        //    {
        //        ConnectionSetup k2ConSetup = new ConnectionSetup();
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, k2Servers.getServerName());
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.UserID, k2User);
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Password, k2PassWord);
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Port, "5252");
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Authenticate, "true");
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.WindowsDomain, domain);
        //        k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.IsPrimaryLogin, "true");
        //        //k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.TimeOut, _timeoutNum);

        //        this.k2conn.Open(k2ConSetup);
        //        this.status = 0;
        //    }
        //    catch (Exception e)
        //    {
        //        K2PoolLogger.logError("K2ConnnectionPool.K2ConnWrap():" + e.Message + "\r\n" + e.StackTrace);
        //        throw e;
        //    }
        //    //this._connTime = DateTime.Now;
        //}

        public void ReTryConn(ServiceContext context)
        {
            this.k2Servers = new K2ServerProvider(context);
            try
            {
                this.k2conn.Close();
            }
            catch (Exception)
            { }

            this.k2conn = new Connection();
            try
            {
                ConnectionSetup k2ConSetup = new ConnectionSetup();
                this.k2Servers.findAvailableServer();

                string serverName = this.k2Servers.getServerName();

                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, serverName);
                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.UserID, k2User);
                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Password, k2PassWord);
                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Port, clientPort);
                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Authenticate, "true");
                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.IsPrimaryLogin, "true");
                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.SecurityLabelName, label);
                //k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.TimeOut, _timeoutNum);

                k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.WindowsDomain, domain);
                if (label.ToLower() != "k2")
                    k2ConSetup.ConnectionParameters[ConnectionSetup.ParamKeys.Integrated] = "false";

                this.k2conn.Open(serverName, k2ConSetup.ConnectionString);

                this.K2ServerName += "Retry:" + serverName + "[" + DateTime.Now.ToString("HH:mm") + "],";

            }
            catch (Exception e)
            {
                K2PoolLogger.logError("K2ConnnectionPool.ReTryConn():" + e.Message + "\r\n" + e.StackTrace);
                throw e;
            }

            //this.status = 0;
            //this._connTime = DateTime.Now;
        }
Exemplo n.º 11
0
        public void InitConn(ServiceContext context, string serverName)
        {
            InitConfigValue(context);

            this.k2conn = new Connection();

            ConnectionSetup k2ConSetup = new ConnectionSetup();
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, serverName);
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.UserID, k2User);
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Password, k2PassWord);
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Port, clientPort);
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Authenticate, "true");
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.IsPrimaryLogin, "true");
            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.SecurityLabelName, label);
            //k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.TimeOut, _timeoutNum);

            k2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.WindowsDomain, domain);
            if (label.ToLower() != "k2")
                k2ConSetup.ConnectionParameters[ConnectionSetup.ParamKeys.Integrated] = "false";

            this.k2conn.Open(serverName, k2ConSetup.ConnectionString);

            this.TimeOfInit = DateTime.Now;
            this.K2ServerName += serverName + "[" + this.TimeOfInit.ToString("HH:mm:ss") + "],";

        }
Exemplo n.º 12
0
        /// <summary>
        /// 连接池无空闲连接,获取新的连接 
        /// </summary>
        /// <returns></returns>
        private static Connection GetNewK2Conn(ServiceContext context)
        {
            InitConfigValue(context);
            Connection k2conn = new Connection();
            ConnectionSetup k2ConSetup = new ConnectionSetup();

            try
            {
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.Host, K2ServerProvider.AvailableServerName);
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.UserID, k2User);
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.Password, k2PassWord);
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.Port, clientPort);
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.Authenticate, "true");
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.IsPrimaryLogin, "true");
                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.SecurityLabelName, label);

                SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.WindowsDomain, domain);
                if (label.ToLower() != "k2")
                    SetK2Param(k2ConSetup, ConnectionSetup.ParamKeys.Integrated, "false");

                k2conn.Open(K2ServerProvider.AvailableServerName, k2ConSetup.ConnectionString);

                lock (oLock)
                {
                    noPoolConnCount++;
                }
            }
            catch (Exception ex)
            {
                K2PoolLogger.logError("得到新连接时出错K2ConnnectionPool.GetNewK2Conn(), \r\n "
                    + "K2ServerProvider.AvailableServerName = " + K2ServerProvider.AvailableServerName + ", \r\n"
                    + "ex.Messagee = " + ex.Message + "\r\n"
                    + "ex.StackTrace = " + ex.StackTrace);
                //2012-2-14 pcitljw
                //得到新连接出错时 重新查找别的主机建立连接
                K2ConnWrap wrap = new K2ConnWrap();
                wrap.K2Conn = k2conn;
                wrap.ReTryConn(context);
                k2conn = wrap.K2Conn;
                //throw;
            }

            return k2conn;
        }
Exemplo n.º 13
0
        /// <summary>
        /// 初始化连接池
        /// </summary>
        private static void InitK2ConnPool(ServiceContext context)
        {

            if (IsConstructed) return;

            SetMaxPoolSize();
            k2ConnWrap = new K2ConnWrap[maxPoolSize];

            for (int i = 0; i < k2ConnWrap.Length; i++)
            {
                k2ConnWrap[i] = new K2ConnWrap();
            }

            //string strK2Server = System.Configuration.ConfigurationManager.AppSettings["K2Server"].ToString();
            string strK2Server = context[SettingVariable.ServerName];
            aryServerName = strK2Server.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);


            //初始化结束
            IsConstructed = true;
        }