Esempio n. 1
0
        public string[] GetUserArgents(string dbConnectionString)
        {
            if (userAgents != null)
                return userAgents;

            DataDBService ddbs = new DataDBService();

            //Создание обьекта для соединения
            using(SqlConnection conn = ddbs.GetDBCon(dbConnectionString))
            try
            {
            if (conn != null)
            {
                // Assumes that connection is a valid SqlConnection object.
                string SQLstr =
                  "SELECT UserAgent FROM ParsersUseragents WHERE Active=1";

                using(SqlCommand SQLCmd = new SqlCommand(SQLstr, conn))
                try
                {
                    using (SqlDataReader MydataReader = SQLCmd.ExecuteReader())
                    {
                        if (MydataReader.HasRows)
                        {
                            int i = 0;
                            userAgents = new string[0];
                            while (MydataReader.Read())
                            {
                                i++;
                                object o0 = MydataReader.GetSqlString(0).ToString();
                                Array.Resize(ref userAgents, i);
                                userAgents[i - 1] = (string)o0;
                            }
                        }
                            MydataReader.Close();
                    }
                }
                catch (Exception ex)
                { Console.WriteLine("Ошибка при получении юзерагентов "+ ex.Message); }
                finally
                {
                    conn.Close();
                }
            }

            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
            finally
            { conn.Close(); conn.Dispose(); }
            return userAgents;
        }
Esempio n. 2
0
        /// <summary>
        /// Запрашиваем список useragents
        /// </summary>
        public string[] GetUserArgents(string dbConnectionString)
        {
            string[] userAgents = null;

            DataDBService ddbs = new DataDBService();

            //Создание обьекта для соединения
            using(SqlConnection conn = ddbs.GetDBCon(dbConnectionString))

            if (conn != null)
            {
                try
                {
                    // Assumes that connection is a valid SqlConnection object.
                    string SQLstr =
                      "SELECT UserAgent FROM ParsersUseragents WHERE Active=1";

                    SqlCommand SQLCmd = new SqlCommand(SQLstr, conn);
                    SqlDataReader MydataReader = SQLCmd.ExecuteReader();

                    if (MydataReader.HasRows)
                    {
                        int i = 0;
                        while (MydataReader.Read())
                        {
                            i++;
                            object o0 = MydataReader.GetSqlString(0).ToString();
                            Array.Resize(ref userAgents, i);
                            userAgents[i - 1] = (string)o0;
                        }
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
            return userAgents;
        }
Esempio n. 3
0
        private bool CheckDBConnection(string currentMessage, int streamNumber, bool ifOk, string _dbConnectionString)
        {
            bool ret = false;
            // Проверка соединения и активность: включение
            DataDBService ddbs = new DataDBService();
            lock (db_lock)
            using(SqlConnection conn = ddbs.GetDBCon(_dbConnectionString))
            try
            {
                if (conn != null)
                {
                    if (conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                        conn.Dispose();
                        //ddbs.WriteMessageAboutActivity(_dbConnectionString, streamNumber, currentMessage + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss."));

                        ret = true;
                    }
                }
                else
                {
                    ret = false;
                }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
            /*finally
            { conn.Close(); conn.Dispose(); GC.SuppressFinalize(conn); }*/
            return ret;
        }
Esempio n. 4
0
        private bool CheckDBConnection(string currentMessage, int streamNumber, bool ifOk)
        {
            // Проверка соединения и активность: включение
            using (DataDBService ddbs = new DataDBService())
            using (SqlConnection conn = ddbs.GetDBCon(_dbConnectionString))
            {
                try
                {
                    if (conn != null)
                    {
                        conn.Close();
                        conn.Dispose();
                        if (ifOk)
                        {
                            ddbs.WriteMessageAboutActivity(_dbConnectionString, streamNumber, " Соединение с БД установлено. " + currentMessage);

                        }
                        return true;
                    }
                    else
                    {

                        ddbs.WriteMessageAboutActivity(_dbConnectionString, streamNumber, " Нет соединения с БД. Проверьте доступ. Или внесите изменения в 'dbconnect.txt' и перестартуйте сервис. " + currentMessage);
                        return false;
                    }
                }
                finally
                { conn.Close(); conn.Dispose(); }
            }
        }
Esempio n. 5
0
        public void NSetStatistics(int jobID, string dbConnectionString, string hostName, int streamNumber)
        {
            try
            {
                DataDBService ddbs = new DataDBService();
                using(SqlConnection conn = ddbs.GetDBCon(dbConnectionString))
                if (conn != null)
                {
                    try
                    {
                        string sqlI =
                        @"INSERT INTO [ParsersStatistics] ([JobID],[SourceID],[SourceDescription],[DateBegin],[DateEnd],[Complete],[NumberOfRestart],[CountAnnouncement],[NewAnnouncement],[UpdatedAnnouncement],[Host],[Stream]) 
                    SELECT top 1  " + jobID +
                            @",s.ID, pj.SourceDescription,pj.DateBegin, 

                            case 
                             when pj.DateEnd >= pj.DateBegin 
                                 then pj.DateEnd 
                            else NULL
                            end, 

                        pj.[Complete],
                        pj.[NumberOfRestart],
                        pj.[CountAds],

                        (select COUNT(a.id)
                        from AddressesMask a
                        left join [PJobUpdate] p on a.JobID = p.ID
                        where a.DateLastUpload between p.DateBegin and p.DateEnd + CONVERT(TIME,'00:00:05.000',104)
                        and p.ID = " + jobID + @"
                        and a.DateLastUpload=a.DateFirstUpload),

                        (select COUNT(a.id)
                        from AddressesMask a
                        left join [PJobUpdate] p on a.JobID = p.ID
                        where a.DateLastUpload between p.DateBegin and p.DateEnd + CONVERT(TIME,'00:00:05.000',104)
                        and p.ID = " + jobID + @"
                        and a.DateLastUpload>a.DateFirstUpload),'" +
                            hostName + "'," + streamNumber + @"
                    FROM [PJobView] pj
                    INNER JOIN [Sources] s on s.[Source] = pj.[Source] 
                    WHERE pj.ID = " + jobID;

                        string sI = ddbs.ExecuteSQLCommand(sqlI, dbConnectionString);
                        if (!string.IsNullOrEmpty(sI))
                        {
                            ddbs.WriteErrorMessage(dbConnectionString, 0, null, "Ошибка добавленя записи в статистику"
                                 + "jobid = " + jobID + ". " + sI);
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                DataDBService ddbs = new DataDBService();
                ddbs.WriteErrorMessage(dbConnectionString, 0, null, "Ошибка в DataDBExtention.NSetStatistics." + e.ToString());
            }

        }
Esempio n. 6
0
        //ставим метку удаленного
        public void NSetDeletedAddresses(int jobID, string dbConnectionString)
        {

            /*
             * update AddressesMask
                set Deleted=1
                where Deleted is null and DateLastUpload<DATEADD(DAY,-5, CURRENT_TIMESTAMP)
                and JobID=N
                Где N - id'шник его джоба
             */
            try
            {
                DataDBService ddbs = new DataDBService();
                using(SqlConnection conn = ddbs.GetDBCon(dbConnectionString))
                if (conn != null)
                {
                    try
                    {
                        string sqlI = @"
                                    update AddressesMask
                                    set Deleted=1
                                    where Deleted is null and DateLastUpload<DATEADD(DAY,-5, CURRENT_TIMESTAMP)
                                    and JobID=" + jobID;

                        string sI = ddbs.ExecuteSQLCommand(sqlI, dbConnectionString);
                        if (!string.IsNullOrEmpty(sI))
                        {
                            ddbs.WriteErrorMessage(dbConnectionString, 0, null, "Ошибка метки deleted. "
                                 + "jobid = " + jobID + ". " + sI);
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                DataDBService ddbs = new DataDBService();
                ddbs.WriteErrorMessage(dbConnectionString, 0, null, "Ошибка в DataDBExtention.NSetStatistics." + e.ToString());
            }
        }
Esempio n. 7
0
        protected bool IUDAdressesMask(string hostName, int jobID)
        {
            //из upload в адреса
            using(DataDBService ddbs = new DataDBService())
            using(SqlConnection conn = ddbs.GetDBCon(_dbConnectionString))
            try
            {
            if (conn != null)
                    {

                        //проставление deleted старым ссылкам с изменившимся хэшем (чтоб по 100 раз не перепарсивать)

                        string SQLstrU0 =
                        "update AddressesMask "+
                        "set Deleted = 1 "+
                        "where ID in "+
                        "( "+
                        "    select id "+
                        "    from AddressesMask a "+

                        "    where a.Address>'' and Deleted is null and exists " +

                        "    ("+
                        "        select * "+
                        "        from AddressesMaskUpload u "+

                        "        where u.Address = a.Address "+

                        "        and u.Hash != a.Hash " +
                        "        AND u.Host ='" + hostName + "' AND u.StreamNumber =" + _streamNumber+
                        "    ) " +
                        ")";

                        string sU0 = ddbs.ExecuteSQLCommand(SQLstrU0, _dbConnectionString);
                        if (!string.IsNullOrEmpty(sU0))
                        {
                            ddbs.WriteErrorMessage(_dbConnectionString, _streamNumber, null, "Ошибка добавление ссылок в AddressesMask. "
                                 + "jobid = " + jobID + ". " + sU0);
                            return false;
                        }

                        //insert того чего еще нет

                        string SQLstrI =
                        "INSERT INTO [AddressesMask] ([JobID],[Source_ref],[Address] ,[Sticker],[DateFirstUpload],[DateLastUpload],[Hash]) " +
                        "SELECT up.[JobID],s.ID,up.[Address],up.[Sticker], up.[DateUpload], up.[DateUpload],up.[Hash] " +
                        "FROM [AddressesMaskUpload] up " +
                        "LEFT JOIN PjobStat pj on up.jobid = pj.ID " +
                        "LEFT JOIN Sources s on s.Source = pj.Source " +
                        "WHERE up.[Hash] NOT IN (SELECT a.[Hash] FROM AddressesMask a) " +
                        "AND up.Host ='" + hostName + "' AND up.StreamNumber =" + _streamNumber;

                        string sI = ddbs.ExecuteSQLCommand(SQLstrI, _dbConnectionString);
                        if (!string.IsNullOrEmpty(sI))
                        {
                            ddbs.WriteErrorMessage(_dbConnectionString, _streamNumber, null, "Ошибка добавление ссылок в AddressesMask. "
                                 + "jobid = " + jobID + ". " + sI);
                            return false;
                        }

                        //update тех что уже есть
                        //string SQLstrU =
                        //    "UPDATE [AddressesMask] " +
                        //    "SET DateLastUpload = up.DateUpload " +
                        //    "FROM [AddressesMaskUpload] up " +
                        //    "WHERE up.[Hash] = [AddressesMask].[Hash] " +
                        //    "AND up.Host ='" + hostName + "' AND up.StreamNumber =" + _streamNumber;
                        string SQLstrU =
                        "UPDATE [AddressesMask] " +
                        "SET DateLastUpload = s.DateUpload " +
                        "FROM (" +
                                "select [Hash], DateUpload " +
                                "from [AddressesMaskUpload] up " +
                                "WHERE up.Host ='" + hostName + "' AND up.StreamNumber = " + _streamNumber +
                                " except " +
                                "select [Hash], DateLastUpload " +
                                "from [AddressesMask] up " +
                                ") s " +
                        "where s.Hash=[AddressesMask].Hash";

                string sU = ddbs.ExecuteSQLCommand(SQLstrU, _dbConnectionString);
                if (!string.IsNullOrEmpty(sU))
                {
                    ddbs.WriteErrorMessage(_dbConnectionString, _streamNumber, null, "Ошибка обновления времени ссылок в AddressesMask. "
                         + "jobid = " + jobID + ". " + sU);
                    return false;
                }

                if (string.IsNullOrEmpty(sI) && string.IsNullOrEmpty(sU))
                {
                    //delete этих строк
                    string SQLstrD =
                        "DELETE FROM [AddressesMaskUpload] " +
                        "WHERE Host ='" + hostName + "' AND StreamNumber =" + _streamNumber;

                    string sD = ddbs.ExecuteSQLCommand(SQLstrD, _dbConnectionString);
                    if (!string.IsNullOrEmpty(sD))
                    {
                        ddbs.WriteErrorMessage(_dbConnectionString, _streamNumber, null, "Ошибка удаления ссылок из AddressesMaskUpload. "
                             + "jobid = " + jobID + ". " + sD);

                        return false;
                    }
                }

                conn.Close();
                return true;
            }
            else
            {
                return false;
            }
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
            finally
            { conn.Close(); conn.Dispose(); }
            return false;
        }
Esempio n. 8
0
        private string[][] GetJobs(string[] siteBusy)
        {

            string[][] jobs = new string[0][];

            DataDBService ddbs = new DataDBService();

            //Создание обьекта для соединения
            SqlConnection conn = ddbs.GetDBCon(_dbConnectionString);

            if (conn != null)
            {

                string filterSiteBusy = "";
                for (int i = 0; i < siteBusy.Length; i++)
                {
                    if (!string.IsNullOrEmpty(siteBusy[i]))
                    {
                        //проверка для каждого занятого потока какой сайт он парсит, 
                        //чтобы этот же парсер в другой поток не взяле такой же сайт
                        filterSiteBusy = filterSiteBusy + " and Site <> '" + siteBusy[i].Trim() + "'";
                    }
                }
                // Assumes that connection is a valid SqlConnection object.
                //берем строи из таблицы, которые не заняты и количество рестартов < допустимых рестартов
                string SQLstr =
                  "SELECT top 20 [ID]"
                + ",[ParserName]"
                + ",[Encoding]"
                + ",[FirstPage]"
                + ",[PageCount]"
                + ",[DelayFrom]"
                + ",[DelayTo]"
                + ",[IpProxy]"
                + ",[PortProxy]"
                + ",[StartPage]"
                + ",[WebPreAuthentificationPage]"
                + ",[WebAuthentificationPage]"
                + ",[WebConnectionString]"
                + ",[Busy]"
                + ",[Site]"
                + ",[Source]"
                + ",[SourceDescription]"
                + ",[TimeInHours]"
                + ",[ResetTimeInMinutes]"
                + ",[AllowRestarts]"
                + ",[NumberOfRestart]"
                + ",[PathForPhoto]"
                + " FROM ParsersJob"
                + " WHERE StartUp=1 AND Start=1 AND isnull(Busy,0) = 0 and isnull(NumberOfRestart,0)<=isnull(AllowRestarts,1) "
                + "   AND len(rtrim(ltrim(isnull(Site,' ')))) >0"
                + filterSiteBusy
                + " ORDER by LastDate + LastTime ASC";

                SqlCommand SQLCmd = new SqlCommand(SQLstr, conn);
                SqlDataReader MydataReader = SQLCmd.ExecuteReader();

                try
                {
                    if (MydataReader.HasRows)
                    {
                        while (MydataReader.Read())
                        {

                            string[] job = null;
                            object o0 = "";

                            if (MydataReader.IsDBNull(0))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(0).ToString();
                            Array.Resize(ref job, 1); job[0] = (string)o0; //[ID]
                            //Array.Resize(ref job, 1); job[0] = "70";

                            if (MydataReader.IsDBNull(1))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(1).ToString();
                            Array.Resize(ref job, 2); job[1] = (string)o0;//[ParserName]
                            //Array.Resize(ref job, 2); job[1] = "GilcomGotovoeDataCollector";

                            if (MydataReader.IsDBNull(2))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(2).ToString();
                            Array.Resize(ref job, 3); job[2] = (string)o0;//[Encoding]
                            //Array.Resize(ref job, 3); job[2] = "UTF8";

                            if (MydataReader.IsDBNull(3))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(3).ToString();
                            Array.Resize(ref job, 4); job[3] = (string)o0;//[FirstPage]
                            //Array.Resize(ref job, 4); job[3] = "1";

                            if (MydataReader.IsDBNull(4))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(4).ToString();
                            Array.Resize(ref job, 5); job[4] = (string)o0;//[PageCount]
                            //Array.Resize(ref job, 5); job[4] = "10";

                            if (MydataReader.IsDBNull(5))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(5).ToString();
                            Array.Resize(ref job, 6); job[5] = (string)o0;//[DelayFrom]
                            //Array.Resize(ref job, 6); job[5] = "0";//[DelayFrom]

                            if (MydataReader.IsDBNull(6))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(6).ToString();
                            Array.Resize(ref job, 7); job[6] = (string)o0;//[DelayTo]
                            //Array.Resize(ref job, 7); job[6] = "0";

                            if (MydataReader.IsDBNull(7))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(7).ToString();
                            Array.Resize(ref job, 8); job[7] = (string)o0;//[IpProxy]
                            //Array.Resize(ref job, 8); job[7] = "";

                            if (MydataReader.IsDBNull(8))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(8).ToString();
                            Array.Resize(ref job, 9); job[8] = (string)o0;//[PortProxy]
                            //Array.Resize(ref job, 9); job[8] = "0";

                            if (MydataReader.IsDBNull(9))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(9).ToString();
                            Array.Resize(ref job, 10); job[9] = (string)o0;//[StartPage]
                            //Array.Resize(ref job, 10); job[9] = "http://homes.gilcom.ru/sell/?intOption11%5B1%5D=&intOption2=250&intOption3Fake=&intOption25=&strOption25=&objectHomeNumber=&intOption5%5B3%5D=&intOption5%5B6%5D=&intOption1%5B3%5D=&intOption1%5B6%5D=&intOption12%5B1%5D=&typeOfOwner=allOwner&other=1&_owner=&btn=%D0%9D%D0%B0%D0%B9%D1%82%D0%B8&intOption6%5B3%5D=&intOption6%5B6%5D=&intOption7%5B3%5D=&intOption7%5B6%5D=&intOption14%5B3%5D=&intOption14%5B6%5D=&intOption27%5B3%5D=&intOption27%5B6%5D=&intOption10%5B1%5D=&intOption13%5B1%5D=&intOption15%5B1%5D=&intOption9%5B3%5D=&intOption9%5B6%5D=&intOption8%5B3%5D=&intOption8%5B6%5D=&period=&on_page=50&by=_orderDate&order=DESC";

                            if (MydataReader.IsDBNull(10))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(10).ToString();
                            Array.Resize(ref job, 11); job[10] = (string)o0;//[WebPreAuthentificationPage]
                            //Array.Resize(ref job, 11); job[10] = "";

                            if (MydataReader.IsDBNull(11))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(11).ToString();
                            Array.Resize(ref job, 12); job[11] = (string)o0;//[WebAuthentificationPage]
                            //Array.Resize(ref job, 12); job[11] = "";//[WebAuthentificationPage]

                            if (MydataReader.IsDBNull(12))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(12).ToString();
                            Array.Resize(ref job, 13); job[12] = (string)o0;//[WebConnectionString]
                            //Array.Resize(ref job, 13); job[12] = "";//[WebConnectionString]

                            if (MydataReader.IsDBNull(13))
                                o0 = "false";
                            else
                                o0 = MydataReader.GetBoolean(13).ToString();
                            Array.Resize(ref job, 14); job[13] = (string)o0; //[Busy]
                            // Array.Resize(ref job, 14); job[13] = "False"; //[Busy]

                            if (MydataReader.IsDBNull(14))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(14).ToString();
                            Array.Resize(ref job, 15); job[14] = (string)o0;//[Site]
                            //Array.Resize(ref job, 15); job[14] = "gilkcom.ru (готовое)  ";//[Site]

                            if (MydataReader.IsDBNull(15))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(15).ToString();
                            Array.Resize(ref job, 16); job[15] = (string)o0;//[Source]
                            //Array.Resize(ref job, 16); job[15] = "ЖИЛКОМ квартиры";//[Source]

                            if (MydataReader.IsDBNull(16))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(16).ToString();
                            Array.Resize(ref job, 17); job[16] = (string)o0;//[SourceDescription]
                            //Array.Resize(ref job, 17); job[16] = "Красноярск Gilcom готовое день";//[SourceDescription]

                            if (MydataReader.IsDBNull(17))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(17).ToString();
                            Array.Resize(ref job, 18); job[17] = (string)o0;//[TimeInHours]
                            //Array.Resize(ref job, 18); job[17] = "20";//[TimeInHours]

                            if (MydataReader.IsDBNull(18))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(18).ToString();
                            Array.Resize(ref job, 19); job[18] = (string)o0;//[ResetTimeInMinutes]
                            //Array.Resize(ref job, 19); job[18] = "15";//[ResetTimeInMinutes]

                            if (MydataReader.IsDBNull(19))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(19).ToString();
                            Array.Resize(ref job, 20); job[19] = (string)o0;//[AllowRestarts]
                            //Array.Resize(ref job, 20); job[19] = "20";//[AllowRestarts]

                            if (MydataReader.IsDBNull(20))
                                o0 = "0";
                            else
                                o0 = MydataReader.GetInt32(20).ToString();
                            Array.Resize(ref job, 21); job[20] = (string)o0;//[NumberOfRestart]
                            //Array.Resize(ref job, 21); job[20] = "0";//[NumberOfRestart]

                            if (MydataReader.IsDBNull(21))
                                o0 = "";
                            else
                                o0 = MydataReader.GetSqlString(21).ToString();
                            Array.Resize(ref job, 22); job[21] = (string)o0;//[PathForPhoto]
                            //Array.Resize(ref job, 22); job[21] = "\\\\195.208.47.9\\ParserPhotos";

                            Array.Resize(ref jobs, jobs.Count() + 1);
                            jobs[jobs.Count() - 1] = job;
                        }
                    }
                }
                catch (SystemException ex)
                {
                    string s = ex.Message;
                    ddbs.WriteErrorMessage(_dbConnectionString, 0, null, "Ошибка четния задания" + s);
                }

                conn.Close();
            }
            return jobs;
        }
Esempio n. 9
0
        public bool InsertIntoAddressesUpload(List<string> addresses, List<string> stickers, int jobID, string hostName)
        {
            if (addresses.Count == 0)
                return true;
            DateTime now = DateTime.Now;

            DataDBService ddbs = new DataDBService();
            using(SqlConnection conn = ddbs.GetDBCon(_dbConnectionString))
                try
                {
                    if (conn != null && addresses.Count > 0)
                    {
                        DataTable table = new DataTable();
                        table.Columns.Add("JobID", typeof(int));
                        table.Columns.Add("Address", typeof(string));
                        table.Columns.Add("Sticker", typeof(string));
                        table.Columns.Add("DateUpload", typeof(System.Data.SqlTypes.SqlDateTime));
                        table.Columns.Add("Host", typeof(string));
                        table.Columns.Add("StreamNumber", typeof(int));

                        //если пусто количество ссылок, берем количество стикеров - верно для досок
                        int count = (addresses.Count > 0) ? addresses.Count : stickers.Count;
                        for (int k = 0; k < count; k++)
                        {
                            DataRow newRow = table.NewRow();
                            newRow["JobID"] = jobID;
                            newRow["Address"] = addresses[k];
                            newRow["Sticker"] = stickers[k];
                            newRow["DateUpload"] = now;
                            newRow["Host"] = hostName;
                            newRow["StreamNumber"] = _streamNumber;
                            table.Rows.Add(newRow);
                        }
                        SqlBulkCopy sqlBulk = new SqlBulkCopy(_dbConnectionString, SqlBulkCopyOptions.FireTriggers);
                        sqlBulk.DestinationTableName = "AddressesMaskUpload";

                        DataDBSerializer ddbser = new DataDBSerializer();

                        List<string> DBNames = ddbser.GetDBTableFields(sqlBulk.DestinationTableName, _dbConnectionString);
                        foreach (DataColumn column in table.Columns)
                        {
                            string columnName = column.ColumnName;
                            //for (int t = 0; t < DBNames.Count(); t++)
                            {
                                //if (columnName.Trim().ToUpper() == DBNames[t].Trim().ToUpper())
                                //if (DBNames[t].Trim().ToUpper() != "ID")
                                sqlBulk.ColumnMappings.Add(columnName.Trim(), columnName.Trim());
                            }
                        }
                        try
                        {
                            // пишем все на сервер
                            sqlBulk.WriteToServer(table);
                            sqlBulk.Close();
                            return true;
                        }
                        catch (Exception ex)
                        {
                            ddbs.WriteErrorMessage(_dbConnectionString, _streamNumber, null, "Ошибка записи в AddressesMaskUpload. "
                                                                            + "jobId " + jobID + ". " + ex);

                            return false;
                        }
                        finally
                        {
                            GC.SuppressFinalize(sqlBulk);
                        }
                    }
                    else
                    {
                        //если подключение вернуло null
                        return false;
                    }
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
                finally
                { conn.Close(); conn.Dispose(); }
            return false;
        }
Esempio n. 10
0
        public List<string> GetDBTableFields(string t, string s)
        {
            //Создание обьекта для соединения
            DataDBService ddbs = new DataDBService();
                List<string> tt = null;
            try
            {
                lock (DataDBService.db_lock)
                    using (SqlConnection conn = ddbs.GetDBCon(s))
                        try
                        {
                            tt= GetDBFieldsSub(t, conn);

                        }
                        catch (Exception ex) { Console.WriteLine(ex.Message); }
                        /*finally
                        { conn.Close(); conn.Dispose(); GC.SuppressFinalize(conn); }*/
            }
            catch { return null; }
                return tt;
        }
Esempio n. 11
0
        public bool GetTuning()
        {
            bool boolRet = false;

            // имя хоста
            string hostName = Dns.GetHostName();
            string ipAddress = "";

            // IP хоста
            IPHostEntry ipEntry = Dns.GetHostEntry(hostName);
            IPAddress[] addr = ipEntry.AddressList;

            for (int i = 0; i < addr.Length; i++)
            {
                ipAddress = ipAddress + addr[i].ToString() + ";";
            }
            ipAddress = ipAddress.Substring(0, ipAddress.Length - 1);

            DataDBService ddbs = new DataDBService();

            //Создание обьекта для соединения
            SqlConnection conn = ddbs.GetDBCon(_dbConnectionString);

            if (conn != null)
            {
                conn.Close();
            }
            return boolRet;
        }
Esempio n. 12
0
        private string[] GetJob(string[] siteBusy)
        {

            string[] job = null;

            DataDBService ddbs = new DataDBService();

            //Создание обьекта для соединения
            {
                string filterSiteBusy = "";
                for (int i = 0; i < siteBusy.Length; i++)
                {
                    if (!string.IsNullOrEmpty(siteBusy[i]))
                    {
                        filterSiteBusy = filterSiteBusy + " and Site <> '" + siteBusy[i].Trim() + "'";
                    }
                }
                // Assumes that connection is a valid SqlConnection object.
                string SQLstr =
                  "SELECT top 1 [ID]"
                + ",[ParserName]"
                + ",[Encoding]"
                + ",[FirstPage]"
                + ",[PageCount]"
                + ",[DelayFrom]"
                + ",[DelayTo]"
                + ",[IpProxy]"
                + ",[PortProxy]"
                + ",[StartPage]"
                + ",[WebPreAuthentificationPage]"
                + ",[WebAuthentificationPage]"
                + ",[WebConnectionString]"
                + ",[Busy]"
                + ",[Site]"
                + ",[Source]"
                + ",[SourceDescription]"
                + ",[TimeInHours]"
                + ",[ResetTimeInMinutes]"
                + ",[AllowRestarts]"
                + ",[NumberOfRestart]"
                + ",[PathForPhoto]"
                + ", cast((cast(cast(dateend as date) as nvarchar(455))+' '+spltime) as datetime)sdate"
                + " FROM [PJobView]"
                + " WHERE StartUp=1 /*AND Start=1*/ AND isnull(Busy,0) = 0 and isnull(NumberOfRestart,0)<=isnull(AllowRestarts,1) "

                + " and cast((cast(cast(current_timestamp as date) as nvarchar(455))+' '+spltime) as datetime) > datebegin "
                + " and cast((cast(cast(current_timestamp as date) as nvarchar(455))+' '+spltime) as datetime) < current_timestamp "
                    //+ "   AND len(rtrim(ltrim(isnull(Site,' ')))) >0"
                + " AND ParserName not like 'avito%' "

                //+ " AND ParserName not like '%irr%' "

                + " AND ParserName not like 'domofond%' "
                //+ " and LastDate< DATEADD(hour, -12, CURRENT_TIMESTAMP)"
                + filterSiteBusy
                + " ORDER by sdate, LastDate ASC";
                
                
                using(SqlConnection conn = ddbs.GetDBCon(_dbConnectionString))

                    if (conn != null)
                    {
                        SqlCommand SQLCmd = new SqlCommand(SQLstr, conn);
                        SqlDataReader MydataReader = SQLCmd.ExecuteReader();

                        try
                        {
                            if (MydataReader.HasRows)
                            {
                                while (MydataReader.Read())
                                {

                                    object o0 = "";

                                    if (MydataReader.IsDBNull(0))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(0).ToString();
                                    Array.Resize(ref job, 1); job[0] = (string)o0; //[ID]

                                    if (MydataReader.IsDBNull(1))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(1).ToString();
                                    Array.Resize(ref job, 2); job[1] = (string)o0;//[ParserName]

                                    if (MydataReader.IsDBNull(2))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(2).ToString();
                                    Array.Resize(ref job, 3); job[2] = (string)o0;//[Encoding]

                                    if (MydataReader.IsDBNull(3))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(3).ToString();
                                    Array.Resize(ref job, 4); job[3] = (string)o0;//[FirstPage]

                                    if (MydataReader.IsDBNull(4))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(4).ToString();
                                    Array.Resize(ref job, 5); job[4] = (string)o0;//[PageCount]

                                    if (MydataReader.IsDBNull(5))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(5).ToString();
                                    Array.Resize(ref job, 6); job[5] = (string)o0;//[DelayFrom]

                                    if (MydataReader.IsDBNull(6))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(6).ToString();
                                    Array.Resize(ref job, 7); job[6] = (string)o0;//[DelayTo]

                                    if (MydataReader.IsDBNull(7))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(7).ToString();
                                    Array.Resize(ref job, 8); job[7] = (string)o0;//[IpProxy]

                                    if (MydataReader.IsDBNull(8))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(8).ToString();
                                    Array.Resize(ref job, 9); job[8] = (string)o0;//[PortProxy]

                                    if (MydataReader.IsDBNull(9))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(9).ToString();
                                    Array.Resize(ref job, 10); job[9] = (string)o0;//[StartPage]

                                    if (MydataReader.IsDBNull(10))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(10).ToString();
                                    Array.Resize(ref job, 11); job[10] = (string)o0;//[WebPreAuthentificationPage]

                                    if (MydataReader.IsDBNull(11))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(11).ToString();
                                    Array.Resize(ref job, 12); job[11] = (string)o0;//[WebAuthentificationPage]

                                    if (MydataReader.IsDBNull(12))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(12).ToString();
                                    Array.Resize(ref job, 13); job[12] = (string)o0;//[WebConnectionString]

                                    if (MydataReader.IsDBNull(13))
                                        o0 = "false";
                                    else
                                        o0 = MydataReader.GetBoolean(13).ToString();
                                    Array.Resize(ref job, 14); job[13] = (string)o0; //[Busy]


                                    if (MydataReader.IsDBNull(14))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(14).ToString();
                                    Array.Resize(ref job, 15); job[14] = (string)o0;//[Site]

                                    if (MydataReader.IsDBNull(15))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(15).ToString();
                                    Array.Resize(ref job, 16); job[15] = (string)o0;//[Source]

                                    if (MydataReader.IsDBNull(16))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(16).ToString();
                                    Array.Resize(ref job, 17); job[16] = (string)o0;//[SourceDescription]

                                    if (MydataReader.IsDBNull(17))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(17).ToString();
                                    Array.Resize(ref job, 18); job[17] = (string)o0;//[TimeInHours]

                                    if (MydataReader.IsDBNull(18))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(18).ToString();
                                    Array.Resize(ref job, 19); job[18] = (string)o0;//[ResetTimeInMinutes]

                                    if (MydataReader.IsDBNull(19))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(19).ToString();
                                    Array.Resize(ref job, 20); job[19] = (string)o0;//[AllowRestarts]

                                    if (MydataReader.IsDBNull(20))
                                        o0 = "0";
                                    else
                                        o0 = MydataReader.GetInt32(20).ToString();
                                    Array.Resize(ref job, 21); job[20] = (string)o0;//[NumberOfRestart]

                                    if (MydataReader.IsDBNull(21))
                                        o0 = "";
                                    else
                                        o0 = MydataReader.GetSqlString(21).ToString();
                                    Array.Resize(ref job, 22); job[21] = (string)o0;//[PathForPhoto]
                                    if (o0 != null)
                                        GC.SuppressFinalize(o0);
                                    break; // читаем одну запись
                                }
                            }
                        }
                        catch (SystemException ex)
                        {
                            string s = ex.Message;
                            ddbs.WriteErrorMessage(_dbConnectionString, _streamNumber, null, "Ошибка четния задания" + _parserName + " " + _sourceDescription + ". " + s);
                        }
                        finally
                        {
                            if (MydataReader != null)
                            { MydataReader.Close(); GC.SuppressFinalize(MydataReader); }
                            if (SQLCmd != null)
                            { SQLCmd.Dispose(); GC.SuppressFinalize(SQLCmd); }
                            if (conn != null)
                            {
                                conn.Close();
                                conn.Dispose();
                                GC.SuppressFinalize(conn);
                            }
                        }
                    }
            }
            return job;
        }
Esempio n. 13
0
        public bool GetTuningScheduler()
        {
            bool boolRet = false;

            // имя хоста
            string hostName = Dns.GetHostName();
            string ipAddress = "";

            // IP хоста
            IPHostEntry ipEntry = Dns.GetHostEntry(hostName);
            IPAddress[] addr = ipEntry.AddressList;

            for (int i = 0; i < addr.Length; i++)
            {
                ipAddress = ipAddress + addr[i].ToString() + ";";
            }
            ipAddress = ipAddress.Substring(0, ipAddress.Length - 1);

            DataDBService ddbs = new DataDBService();

            //Создание обьекта для соединения
            using(SqlConnection conn = ddbs.GetDBCon(_dbConnectionString))

            if (conn != null)
            {
                try
                {
                    //// Assumes that connection is a valid SqlConnection object.
                    string SQLstr =
                      "SELECT [StartScheduler]"
                    + " FROM ParsersTuning"
                        // --
                    + " Where "
                    + " Host = '" + hostName + "'";
                    //+ " and '" + ipAddress + "' like '%'+IP+'%' ";

                    SqlCommand SQLCmd = new SqlCommand(SQLstr, conn);
                    SqlDataReader MydataReader = SQLCmd.ExecuteReader();

                    if (MydataReader.HasRows)
                    {

                        while (MydataReader.Read())
                        {
                            var o0 = MydataReader.GetBoolean(0);
                            boolRet = o0;

                            break; // читаем одну запись
                        }
                        //    }
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
            return boolRet;
        }