Ejemplo n.º 1
0
        // ---------------------------- Common.GetConnectionString -------------------
        public static string GetConnectionString(AutoCoder.BasePage InPage)
        {
            System.IO.StreamReader reader = null;
            string connString             = null;
            string path = InPage.MapPath("ConnectString.txt");

            try
            {
                try
                {
                    reader     = new System.IO.StreamReader(path);
                    connString = reader.ReadLine( );
                }
                catch (System.IO.IOException excp)
                {
                    throw(new ApplicationException("GetConnectionString error. " +
                                                   excp.Message));
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close( );
                }
            }
            return(connString);
        }
Ejemplo n.º 2
0
        // --------------------- LoadMaster.CreateTable -------------------------
        // create the table in the database.
        public static void CreateTable(AutoCoder.BasePage InPage)
        {
            SqlConnection conn;
            SqlCommand    cmd;

            conn = new SqlConnection(Common.GetConnectionString(InPage));
            conn.Open();

            try
            {
                cmd = new SqlCommand("DROP TABLE LOADMASTER", conn);
                cmd.ExecuteNonQuery();
            }
            catch
            {
            }

            cmd = new SqlCommand("CREATE TABLE LOADMASTER ( " +
                                 "LoadId varchar(50), " +
                                 "RawUrl varchar(1000), " +
                                 "PageTitle varchar(80), " +
                                 "EntryTs DATETIME, " +
                                 "PRIMARY KEY( LoadId ))",
                                 conn);
            cmd.ExecuteNonQuery();

            conn.Close();
        }
Ejemplo n.º 3
0
        // --------------------- LoadMaster.CheckTable -------------------------
        // check for table existance.  return true if table exists.
        public static bool CheckTable(AutoCoder.BasePage InPage)
        {
            SqlCommand    cmd       = null;
            SqlConnection conn      = null;
            SqlDataReader reader    = null;
            bool          doesExist = false;

            try
            {
                conn            = Common.OpenConnection(InPage);
                cmd             = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add(new SqlParameter("@LoadId", "abc"));
                cmd.CommandText = "SELECT * from LoadMaster WHERE LoadId=@LoadId";
                reader          = cmd.ExecuteReader();
                doesExist       = true;
            }
            catch (SqlException)
            {
                doesExist = false;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(doesExist);
        }
Ejemplo n.º 4
0
        // ---------------------------- ArticleMaster.Add ------------------------
        // assign ArticleName and run sql insert for the fields stored in the class.
        public void Add(AutoCoder.BasePage InPage)
        {
            SqlConnection conn = null;

            try
            {
                SqlCommand cmd = new SqlCommand();
                conn = new SqlConnection(Common.GetConnectionString(InPage));
                conn.Open();

                cmd.Connection  = conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add(new SqlParameter("@ArticleName", mArticleName));
                cmd.Parameters.Add(new SqlParameter("@ArticleTitle", mArticleTitle));
                cmd.Parameters.Add(new SqlParameter("@SummaryDocFile", mSummaryDocFile));
                cmd.Parameters.Add(new SqlParameter("@FullDocFile", mFullDocFile));

                cmd.CommandText = "Insert ARTICLEMASTER ( " +
                                  "ArticleName, ArticleTitle, SummaryDocFile, FullDocFile ) " +
                                  "Values( @ArticleName, @ArticleTitle, @SummaryDocFile, @FullDocFile )";
                cmd.ExecuteNonQuery();
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 5
0
        // --------------------- ArticleMaster.CreateTable -------------------------
        // create the table in the database.
        public static void CreateTable(AutoCoder.BasePage InPage)
        {
            SqlConnection conn;
            SqlCommand    cmd;

            conn = new SqlConnection(Common.GetConnectionString(InPage));
            conn.Open();

            try
            {
                cmd = new SqlCommand("DROP TABLE ARTICLEMASTER", conn);
                cmd.ExecuteNonQuery();
            }
            catch
            {
            }

            cmd = new SqlCommand("CREATE TABLE ARTICLEMASTER ( " +
                                 "ArticleName varchar(50), " +
                                 "ArticleTitle varchar(100), " +
                                 "SummaryDocFile varchar(50), " +
                                 "FullDocFile varchar(50) " +
                                 "PRIMARY KEY( ArticleName ))",
                                 conn);
            cmd.ExecuteNonQuery();

            conn.Close();
        }
Ejemplo n.º 6
0
        // ----------------- Common.OpenConnection -----------------------------
        public static SqlConnection OpenConnection(AutoCoder.BasePage InPage)
        {
            SqlConnection conn;

            conn = new SqlConnection(GetConnectionString(InPage));
            conn.Open( );
            return(conn);
        }
Ejemplo n.º 7
0
        // ---------------------- BasePage.RedirectTo -------------------------
        // redirect to this page from another page.
        public void RedirectTo(AutoCoder.BasePage frompage)
        {
            StringBuilder url = new StringBuilder( );

            url.Append(mPageUrl);
            url.Append("?RefLoadId=");
            url.Append(frompage.PageLoadId);
            frompage.Response.Redirect(url.ToString( ));
        }
Ejemplo n.º 8
0
        // --------------------- ArticleMaster.CheckTable -------------------------
        // check for table existance.  return true if table exists.
        public static bool CheckTable(AutoCoder.BasePage InPage)
        {
            SqlCommand    cmd       = null;
            SqlConnection conn      = null;
            SqlDataReader reader    = null;
            bool          doesExist = false;
            bool          rc;

            try
            {
                conn            = Common.OpenConnection(InPage);
                cmd             = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from INFORMATION_SCHEMA.tables where table_name = " +
                                  "@TableName";
                cmd.Parameters.Add(new SqlParameter("@TableName", "ARTICLEMASTER"));
                reader = cmd.ExecuteReader();
                rc     = reader.Read();

                // not found exception.
                if (rc == false)
                {
                    doesExist = false;
                }
                else
                {
                    doesExist = true;
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(doesExist);
        }
Ejemplo n.º 9
0
        // --------------------- LoadMaster.Chain ------------------------------
        public void Chain(AutoCoder.BasePage InPage, string InLoadId)
        {
            SqlConnection conn   = null;
            SqlCommand    cmd    = null;
            SqlDataReader reader = null;
            bool          rc;

            try
            {
                conn = new SqlConnection(Common.GetConnectionString(InPage));
                conn.Open();
                cmd    = BuildChainCommand(conn, InLoadId);
                reader = cmd.ExecuteReader();
                rc     = reader.Read();

                // not found exception.
                if (rc == false)
                {
                    string msg = "Load master not found for LoadId " + InLoadId;
                    throw(new ApplicationException(msg));
                }

                // got a row. extract each column from the reader.
                mLoadId    = reader.GetString(0);
                mRawUrl    = reader.GetString(1);
                mPageTitle = reader.GetString(2);
                mEntryTs   = reader.GetDateTime(3);
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close( );
                }
                if (conn != null)
                {
                    conn.Close( );
                }
            }
        }
Ejemplo n.º 10
0
        // --------------------- ArticleMaster.Chain ------------------------------
        public void Chain(AutoCoder.BasePage InPage, string InArticleName)
        {
            SqlConnection conn   = null;
            SqlCommand    cmd    = null;
            SqlDataReader reader = null;
            bool          rc;

            try
            {
                conn = new SqlConnection(Common.GetConnectionString(InPage));
                conn.Open();
                cmd    = BuildChainCommand(conn, InArticleName);
                reader = cmd.ExecuteReader();
                rc     = reader.Read();

                // not found exception.
                if (rc == false)
                {
                    string msg = "Article master not found for ArticleName " + InArticleName;
                    throw(new ArticleMasterException(msg));
                }

                // got a row. extract each column from the reader.
                mArticleName    = reader.GetString(0);
                mArticleTitle   = reader.GetString(1);
                mSummaryDocFile = reader.GetString(2);
                mFullDocFile    = reader.GetString(3);
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close( );
                }
                if (conn != null)
                {
                    conn.Close( );
                }
            }
        }
Ejemplo n.º 11
0
        // ---------------------------- LoadMaster.Add ------------------------
        // assign LoadId and run sql insert for the fields stored in the class.
        public void Add(AutoCoder.BasePage InPage)
        {
            SqlConnection conn = null;

            try
            {
                SqlCommand cmd = new SqlCommand();
                conn = new SqlConnection(Common.GetConnectionString(InPage));
                conn.Open();

                // assign the LoadId.
                System.Guid guid;
                guid     = System.Guid.NewGuid();
                mLoadId  = guid.ToString();
                mEntryTs = DateTime.Now;

                cmd.Connection  = conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add(new SqlParameter("@LoadId", mLoadId));
                cmd.Parameters.Add(new SqlParameter("@RawUrl", mRawUrl));
                cmd.Parameters.Add(new SqlParameter("@PageTitle", mPageTitle));
                cmd.Parameters.Add(new SqlParameter("@EntryTs", mEntryTs));

                cmd.CommandText = "Insert LoadMaster ( " +
                                  "LoadId, RawUrl, PageTitle, EntryTs ) " +
                                  "Values( @LoadId, @RawUrl, @PageTitle, @EntryTs )";
                cmd.ExecuteNonQuery();
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 12
0
        // ------------------------ LoadMaster.NewPage --------------------------
        public static string NewPage(AutoCoder.BasePage InPage, string InPageTitle)
        {
            LoadMaster lm = new LoadMaster( );

            lm.RawUrl    = InPage.Request.RawUrl;
            lm.PageTitle = InPageTitle;
            try
            {
                lm.Add(InPage);
            }

            // catch the add exception. ( probably the table does not exist. ) If the LoadMaster
            // table does not exist, try to create it, then try the add again.
            catch (SqlException excp)
            {
                if (AutoCoder.Common.IsObjectNotFoundExcp(excp) == false)
                {
                    throw(excp);
                }
                LoadMaster.CreateTable(InPage);
                lm.Add(InPage);
            }
            return(lm.LoadId);
        }