示例#1
0
        private Channel ChannelFromDataReader(SqlDataReader rdr)
        {
            var channel = new Channel();
            channel.Id = rdr.GetInt32(rdr.GetOrdinal("Id"));
            channel.Title = rdr.GetString(rdr.GetOrdinal("Title"));
            channel.ApplicationId = rdr.GetString(rdr.GetOrdinal("ApplicationId"));
            channel.PlatformType = (PlatformType)Enum.Parse(typeof(PlatformType), rdr.GetString(rdr.GetOrdinal("PlatformType")), true);

            if (!rdr.IsDBNull(rdr.GetOrdinal("Cert")))
                channel.Cert = rdr.GetSqlBinary(rdr.GetOrdinal("Cert")).Value;
            if (!rdr.IsDBNull(rdr.GetOrdinal("CertName")))
                channel.CertName = rdr.GetString(rdr.GetOrdinal("CertName"));
            if (!rdr.IsDBNull(rdr.GetOrdinal("CertPassword")))
                channel.CertPassword = rdr.GetString(rdr.GetOrdinal("CertPassword"));

            channel.State = rdr.GetInt32(rdr.GetOrdinal("State"));

            return channel;
        }
        private void SaveChannel(HttpContextBase context)
        {
            var form = context.Request.Form;
            var channel = new Channel();
            string idStr = form["Id"];
            if (!string.IsNullOrEmpty(idStr))
                channel.Id = Convert.ToInt32(idStr);
            channel.Title = form["Title"];
            channel.ApplicationId = form["ApplicationId"];
            channel.PlatformType = (Beyondbit.Push.Service.PlatformType)Enum.Parse(typeof(Beyondbit.Push.Service.PlatformType), form["PlatformType"], true);
            channel.CertPassword = form["CertPassword"];
            channel.State = 1;

            var cert = context.Request.Files["Cert"];
            string certName = form["CertName"];
            if (cert == null || string.IsNullOrEmpty(cert.FileName))
            {
                PushBo.Instance.SaveChannel(channel, channel.Id == 0 || string.IsNullOrEmpty(certName));
            }
            else
            {
                using (var ms = new MemoryStream())
                {
                    cert.InputStream.CopyTo(ms);
                    channel.Cert = ms.ToArray();
                }
                channel.CertName = cert.FileName;
                PushBo.Instance.SaveChannel(channel, true);
            }
        }
示例#3
0
        public void SaveChannel(Channel channel, bool saveCert)
        {
            using (var con = new SqlConnection(ConfigHelp.ConnectionString))
            {
                con.Open();
                var cmd = con.CreateCommand();
                cmd.Parameters.Add(new SqlParameter("@Id", channel.Id));
                cmd.Parameters.Add(new SqlParameter("@Title", channel.Title));
                cmd.Parameters.Add(new SqlParameter("@ApplicationId", channel.ApplicationId));
                cmd.Parameters.Add(new SqlParameter("@PlatformType", channel.PlatformType.ToString()));
                cmd.Parameters.Add(new SqlParameter("@CertName", channel.CertName ?? (object)DBNull.Value));
                cmd.Parameters.Add(new SqlParameter("@CertPassword", channel.CertPassword ?? (object)DBNull.Value));
                cmd.Parameters.Add(new SqlParameter("@State", channel.State));

                if (saveCert)
                {
                    cmd.Parameters.Add(new SqlParameter("@Cert", System.Data.SqlDbType.Image) { Value = channel.Cert ?? (object)DBNull.Value });
                    if (channel.Id == 0)
                    {
                        cmd.CommandText = @"insert into Channel (Title,ApplicationId,PlatformType,Cert,CertName,CertPassword,State)
            values (@Title,@ApplicationId,@PlatformType,@Cert,@CertName,@CertPassword,@State)";
                    }
                    else
                    {
                        cmd.CommandText =
            @"update Channel set Title=@Title,ApplicationId=@ApplicationId,PlatformType=@PlatformType,Cert=@Cert,CertName=@CertName,CertPassword=@CertPassword where Id=@Id";
                    }
                }
                else
                {
                    cmd.CommandText =
            @"update Channel set Title=@Title,ApplicationId=@ApplicationId,PlatformType=@PlatformType,CertPassword=@CertPassword where Id=@Id";
                }

                cmd.ExecuteNonQuery();
            }
        }