Beispiel #1
0
        //修改比较多,多写点注释:(   oracle要改写...
        public object[] PackageUpload(object[] objParam)
        {
            string projectname = ((string)objParam[0]);
            string filename = (string)objParam[1];                    //应该包括.dll
            string package = Path.GetFileNameWithoutExtension(filename);
            DateTime dtclient = ((DateTime)objParam[2]);//取得Client传上来的Dll时间
            PackageType ptype = ((PackageType)objParam[3]);
            byte[] data = ((byte[])objParam[4]);   //取得Client传上来的Dll内容
            string packagetype = "";
            switch (ptype)
            {
                case PackageType.Client: packagetype = "C"; break;
                case PackageType.Server: packagetype = "S"; break;
                case PackageType.WebClient: packagetype = "W"; break;
            }

            ClientType ct = ClientType.ctMsSql;
            IDbConnection nwindConn = AllocateConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), ref ct, true);  //menuchecklog用sysDB里的
            try
            {
                IDbCommand cmd = nwindConn.CreateCommand();
                cmd.CommandText = string.Format("Select * from MENUCHECKLOG where FILENAME = '{0}' and ITEMTYPE = '{1}' and FILETYPE = '{2}' order by PACKAGEDATE desc"
                                , filename, projectname, packagetype);

                IDataReader reader = cmd.ExecuteReader();
                DateTime dtdb = DateTime.MinValue;
                if (reader.Read())                                             //找不到记录
                {
                    try
                    {
                        dtdb = (DateTime)reader["PACKAGEDATE"];                   //找到记录
                    }
                    catch { }
                }
                cmd.Cancel();
                reader.Close();
                DateTime dtserver = new DateTime();
                byte[] buff;
                string strsql = string.Empty;
                PackageService ps = new PackageService();
                if (nwindConn is SqlConnection)
                {
                    strsql = "Insert into MENUCHECKLOG (ITEMTYPE,PACKAGE,PACKAGEDATE,FILETYPE,[FILENAME],FILEDATE,FILECONTENT) values ('{0}', '{1}','{2:yyyy/MM/dd HH:mm:ss}','{3}','{4}','{5:yyyy/MM/dd HH:mm:ss}',@content)";
                }
                else if (nwindConn is OdbcConnection)
                {
                    strsql = "Insert into MENUCHECKLOG (ITEMTYPE,PACKAGE,PACKAGEDATE,FILETYPE,FILENAME,FILEDATE,FILECONTENT) values ('{0}', '{1}',to_date('{2:yyyyMMddHHmmss}','%Y%m%d%H%M%S'),'{3}','{4}',to_date('{5:yyyyMMddHHmmss}','%Y%m%d%H%M%S'),?)";
                }
                else if (nwindConn is OracleConnection)
                {
                    strsql = "Insert into MENUCHECKLOG (ITEMTYPE,PACKAGE,PACKAGEDATE,FILETYPE,FILENAME,FILEDATE,FILECONTENT) values ('{0}', '{1}',to_date('{2:yyyy/MM/dd HH:mm:ss}','yyyy/mm/dd hh24:mi:ss'),'{3}','{4}',to_date('{5:yyyy/MM/dd HH:mm:ss}','yyyy/mm/dd hh24:mi:ss'),:content)";
                }
                else if (nwindConn is OleDbConnection)
                {
                    strsql = "Insert into MENUCHECKLOG (ITEMTYPE,PACKAGE,PACKAGEDATE,FILETYPE,FILENAME,FILEDATE,FILECONTENT) values ('{0}', '{1}','{2:yyyy/MM/dd HH:mm:ss}','{3}','{4}','{5:yyyy/MM/dd HH:mm:ss}',?)";
                }
                else if (nwindConn.GetType().Name == "MySqlConnection")
                {
                    strsql = "Insert into MENUCHECKLOG (ITEMTYPE,PACKAGE,PACKAGEDATE,FILETYPE,FILENAME,FILEDATE,FILECONTENT) values ('{0}', '{1}','{2:yyyy/MM/dd HH:mm:ss}','{3}','{4}','{5:yyyy/MM/dd HH:mm:ss}',?content)";
                }
                else if (nwindConn.GetType().Name == "IfxConnection")
                {
                    strsql = "Insert into MENUCHECKLOG (ITEMTYPE,PACKAGE,PACKAGEDATE,FILETYPE,FILENAME,FILEDATE,FILECONTENT) values ('{0}', '{1}',to_date('{2:yyyyMMddHHmmss}','%Y%m%d%H%M%S'),'{3}','{4}',to_date('{5:yyyyMMddHHmmss}','%Y%m%d%H%M%S'),?)";
                }

                cmd = nwindConn.CreateCommand();
                if (ps.VersionControl(filename, projectname, ptype, dtdb, out buff, out dtserver))   //Server是否已经存在有这个DLL,如果有,而且比数据库里的版本新,要备份到数据库
                {
                    cmd.CommandText = string.Format(strsql, projectname, package, dtserver, packagetype, filename, dtserver);
                    IDbDataParameter parameter = cmd.CreateParameter();
                    if (nwindConn is SqlConnection)
                        parameter.ParameterName = "@content";
                    else if (nwindConn is OdbcConnection)
                        parameter.ParameterName = "content";
                    else if (nwindConn is OracleConnection)
                        parameter.ParameterName = ":content";
                    else if (nwindConn is OleDbConnection)
                    {
                        parameter.ParameterName = "@content";
                        (parameter as OleDbParameter).OleDbType = OleDbType.LongVarBinary;
                    }
                    else if (nwindConn.GetType().Name == "MySqlConnection")
                        parameter.ParameterName = "?content";
                    else if (nwindConn.GetType().Name == "IfxConnection")
                        parameter.ParameterName = "?";
                    parameter.Value = buff;
                    cmd.Parameters.Add(parameter);
                    cmd.ExecuteNonQuery();
                }
                cmd.CommandText = string.Format(strsql, projectname, package, DateTime.Now, packagetype, filename, dtclient);
                if (cmd.Parameters.Contains("@content"))
                {
                    (cmd.Parameters["@content"] as IDbDataParameter).Value = data;
                }
                else if (cmd.Parameters.Contains("content"))
                {
                    (cmd.Parameters["content"] as IDbDataParameter).Value = data;
                }
                else if (cmd.Parameters.Contains("?"))
                {
                    (cmd.Parameters["?"] as IDbDataParameter).Value = data;
                }
                else if (cmd.Parameters.Contains(":content"))
                {
                    (cmd.Parameters[":content"] as IDbDataParameter).Value = data;
                }
                else
                {
                    IDbDataParameter parameter = cmd.CreateParameter();
                    parameter.ParameterName = "content";
                    parameter.Value = data;
                    cmd.Parameters.Add(parameter);
                }
                cmd.ExecuteNonQuery();
                ps.Upload(filename, projectname, ptype, data, dtclient);//将DLL拷贝到Server端的临时文件夹,这个DLL的版本是最新的,在ServerUpdate.exe里更新后删除

                return new object[] { 0 };
            }
            finally
            {
                ReleaseConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), nwindConn, true);
            }
        }
Beispiel #2
0
        public static bool RegisterRemoteServer(string ipAddress, int port)
        {
            foreach (RemoteServer rs in ServerConfig.RemoteServers)
            {
                if (rs.IpAddress == ipAddress && rs.Port == port)
                {
                    rs.Activated = true;

                    //传送那些未成功的package
                    if (ServerConfig.AutoTransferPackage)
                    {
                        DataRow[] rows = ServerConfig.PackageTransferList.Tables[0].Select("IP='" + ipAddress + "'");

                        PackageService packageLocalService = new PackageService();
                        PackageService packageService = Activator.GetObject(typeof(PackageService),
                            string.Format("http://{0}:{1}/PackageService.rem", ipAddress, port)) as PackageService;

                        foreach (DataRow row in rows)
                        {
                            string fileName = row["FileName"].ToString();
                            string solutionName = row["SolutionName"].ToString();
                            PackageType packageType = (PackageType)Enum.Parse(typeof(PackageType), row["PackageType"].ToString(), true);

                            byte[] buffer = null;
                            DateTime dt = new DateTime();
                            if (packageLocalService.GetTransferFile(fileName, solutionName, packageType, out buffer, out dt))
                            {
                                try
                                {
                                    packageService.Upload(fileName, solutionName, packageType, buffer, dt);
                                    ServerConfig.RemovePackageTransferListItem(ipAddress, fileName, solutionName, packageType);
                                }
                                catch { }
                            }
                            else
                            {
                                //dispatch error
                            }
                        }
                    }
                    return true;
                }
            }

            return false;
        }
Beispiel #3
0
        public object[] PackageRollback(object[] objParam)
        {
            string projectname = ((string)objParam[0]);
            string filename = ((string)objParam[1]);
            string dt = ((string)objParam[2]);
            PackageType ptype = ((PackageType)objParam[3]);
            string packagetype = "";
            switch (ptype)
            {
                case PackageType.Client: packagetype = "C"; break;
                case PackageType.Server: packagetype = "S"; break;
                case PackageType.WebClient: packagetype = "W"; break;
            }
            ClientType ct = ClientType.ctMsSql;
            //IDbConnection nwindConn = AllocateConnection(GetSystemDBName(), ref ct, false);  //menuchecklog用sysDB里的
            IDbConnection nwindConn = AllocateConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), ref ct, true);  //取登陆后的DBAlias ——by Rei
            try
            {
                string strsql = "";
                if (nwindConn is SqlConnection)
                    strsql = "DELETE FROM MENUCHECKLOG WHERE ITEMTYPE ='" + projectname + "' AND [FILENAME] ='" + filename
                        + "' AND FILETYPE='" + packagetype + "' AND PACKAGEDATE >'" + dt + "'";
                else if (nwindConn is OdbcConnection)
                    strsql = "DELETE FROM MENUCHECKLOG WHERE ITEMTYPE ='" + projectname + "' AND FILENAME ='" + filename
                        + "' AND FILETYPE='" + packagetype + "' AND PACKAGEDATE > to_date('" + String.Format("{0:yyyyMMddHHmmss}", Convert.ToDateTime(dt)) + "', '%Y%m%d%H%M%S')";
                else if (nwindConn is OracleConnection)
                    strsql = "DELETE FROM MENUCHECKLOG WHERE ITEMTYPE ='" + projectname + "' AND FILENAME ='" + filename
                        + "' AND FILETYPE='" + packagetype + "' AND PACKAGEDATE > to_date('" + dt + "', 'yyyy-mm-dd hh24:mi:ss')";
                else if (nwindConn is OleDbConnection)
                    strsql = "DELETE FROM MENUCHECKLOG WHERE ITEMTYPE ='" + projectname + "' AND FILENAME ='" + filename
                        + "' AND FILETYPE='" + packagetype + "' AND PACKAGEDATE >'" + dt + "'";
                else if (nwindConn.GetType().Name == "MySqlConnection")
                    strsql = "DELETE FROM MENUCHECKLOG WHERE ITEMTYPE ='" + projectname + "' AND FILENAME ='" + filename
                        + "' AND FILETYPE='" + packagetype + "' AND PACKAGEDATE > '" + dt + "'";
                else if (nwindConn.GetType().Name == "IfxConnection")
                    strsql = "DELETE FROM MENUCHECKLOG WHERE ITEMTYPE ='" + projectname + "' AND FILENAME ='" + filename
                        + "' AND FILETYPE='" + packagetype + "' AND PACKAGEDATE > to_date('" + String.Format("{0:yyyyMMddHHmmss}", Convert.ToDateTime(dt)) + "', '%Y%m%d%H%M%S')";

                InfoCommand cmd = new InfoCommand(ClientInfo);
                cmd.Connection = nwindConn;
                cmd.CommandText = strsql;
                cmd.ExecuteNonQuery();

                string strBlob = "";
                if (nwindConn is SqlConnection)
                    strBlob = "SELECT FILECONTENT, FILEDATE FROM MENUCHECKLOG WHERE [FILENAME] = '" + filename + "' AND PACKAGEDATE = '" + dt
                            + "' AND ITEMTYPE ='" + projectname + "' AND FILETYPE='" + packagetype + "'";
                else if (nwindConn is OdbcConnection)
                    strBlob = "SELECT FILECONTENT, FILEDATE FROM MENUCHECKLOG WHERE FILENAME = '" + filename + "' AND PACKAGEDATE = to_date('" + String.Format("{0:yyyyMMddHHmmss}", Convert.ToDateTime(dt)) + "', '%Y%m%d%H%M%S') "
                            + " AND ITEMTYPE ='" + projectname + "' AND FILETYPE='" + packagetype + "'";
                else if (nwindConn is OracleConnection)
                    strBlob = "SELECT FILECONTENT, FILEDATE FROM MENUCHECKLOG WHERE FILENAME = '" + filename + "' AND PACKAGEDATE = to_date('" + dt + "', 'yyyy-mm-dd hh24:mi:ss')"
                            + " AND ITEMTYPE ='" + projectname + "' AND FILETYPE='" + packagetype + "'";
                else if (nwindConn is OleDbConnection)
                    strBlob = "SELECT FILECONTENT, FILEDATE FROM MENUCHECKLOG WHERE FILENAME = '" + filename + "' AND PACKAGEDATE = '" + dt
                            + "' AND ITEMTYPE ='" + projectname + "' AND FILETYPE='" + packagetype + "'";
                else if (nwindConn.GetType().Name == "MySqlConnection")
                    strBlob = "SELECT FILECONTENT, FILEDATE FROM MENUCHECKLOG WHERE FILENAME = '" + filename + "' AND PACKAGEDATE = '" + dt + "'"
                            + " AND ITEMTYPE ='" + projectname + "' AND FILETYPE='" + packagetype + "'";
                else if (nwindConn.GetType().Name == "IfxConnection")
                    strBlob = "SELECT FILECONTENT, FILEDATE FROM MENUCHECKLOG WHERE FILENAME = '" + filename + "' AND PACKAGEDATE = to_date('" + String.Format("{0:yyyyMMddHHmmss}", Convert.ToDateTime(dt)) + "', '%Y%m%d%H%M%S') "
                            + " AND ITEMTYPE ='" + projectname + "' AND FILETYPE='" + packagetype + "'";
                cmd.CommandText = strBlob;

                IDataReader idr = cmd.ExecuteReader();
                idr.Read();

                try
                {
                    byte[] blob = new byte[idr.GetBytes(0, 0, null, 0, int.MaxValue)];
                    idr.GetBytes(0, 0, blob, 0, blob.Length);
                    DateTime dtfile = new DateTime();
                    try
                    {
                        dtfile = (DateTime)idr.GetValue(1);                   //找到记录
                    }
                    catch
                    {
                        dtfile = DateTime.MinValue;
                    }
                    cmd.Cancel();
                    idr.Close();
                    PackageService ps = new PackageService();
                    ps.Upload(filename, projectname, ptype, blob, dtfile);
                    return new object[] { 0, 0 };
                }
                catch (Exception e)
                {
                    return new object[] { 0, 1, e.Message };
                }
            }
            finally
            {
                ReleaseConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), nwindConn, true);
            }
        }