Пример #1
0
        public static void UpdateFromServer()
        {
            string filePath;
            //Ops Op = bulidOp();

            //// 数组  【】    对象{}     值“”
            string json1 = "{type:'image',url:'http://i1.hoopchina.com.cn/blogfile/201501/08/BbsImg142070525332424_550*550.jpg'}";
            string json2 = "{type:'video',url:'http://i2.hoopchina.com.cn/blogfile/201411/27/BbsImg141707487288557_1271*988.jpg'}";
            //string json2 = "{type:'video',url:'http://v.youku.com/v_show/id_XODczMTA2OTc2.html'}";
            string json3      = "{type:'image',url:'http://i1.hoopchina.com.cn/blogfile/201304/09/136548593327743.jpg'}";
            string jsonString = "[" + json1 + "," + json2 + "," + json3 + "]";

            StringBuilder sb     = new StringBuilder();
            JArray        array1 = (JArray)JsonConvert.DeserializeObject(jsonString);

            for (int i = 0; i < 3; ++i)
            {
                WebClient mywebclient = new WebClient();
                JObject   jo          = (JObject)array1[i];
                string    url         = jo["url"].ToString();
                string    newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
                                        + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + i + ".jpg";
                //下载很快,如果不在文件名加入i的话,会在一秒内下载完,使用时间当做文件名,最后就只剩一个文件。
                //string filePath = @"D:\VSPROJECT\WindowsFormsApplication3\" + newfilename;
                if (jo["type"].ToString().Equals("image"))
                {
                    filePath = @Environment.CurrentDirectory + "/Image/" + newfilename;
                }
                else if (jo["type"].ToString().Equals("video"))
                {
                    filePath = @Environment.CurrentDirectory + "/Video/" + newfilename;
                }
                else
                {
                    filePath = @"D:\";
                }
                try
                {
                    mywebclient.DownloadFile(url, filePath);
                    SQLiteParameter[] Params1 = new SQLiteParameter[] {
                        new SQLiteParameter("@type", jo["type"]),
                        new SQLiteParameter("@url", jo["url"]),
                        new SQLiteParameter("@filename", newfilename),
                        new SQLiteParameter("@filepath", filePath),
                        new SQLiteParameter("@state", 1)
                    };

                    if (File.Exists(filePath))
                    {
                        Op.ChangeCommand(cmdInsertTableupdateText, Params1);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            int j = updateSq.checkLastUpdate();
        }
Пример #2
0
        public static int getCloums()
        {
            string           cmd = "SELECT type FROM tableConf";
            Ops              Op  = new Ops(dbPath);
            SQLiteDataReader sdr = Op.noChangeCommand(cmd);
            int              i   = 0;

            while (sdr.Read())
            {
                i++;
            }
            if (i == 0)
            {
                string cmdInsertC1 = "INSERT INTO tableConf(type,val) VALUES ('url','null')";
                string cmdInsertC2 = "INSERT INTO tableConf(type,val) VALUES ('com','null')";
                Op.ChangeCommand(cmdInsertC1, null);
                Op.ChangeCommand(cmdInsertC2, null);
                int a = i;
                return(i);
            }
            else
            {
                return(i);
            }
        }
Пример #3
0
        public static void initUsingTable()
        {
            Ops Op = new Ops(dbPath);

            //string cmdCreateUsingtableText = getCreateText("fileUsing");
            Op.ChangeCommand(cmdCreateUsingtableText, null);
        }
Пример #4
0
        public static void setCOM(string value)
        {
            string str1 = "UPDATE tableConf SET val=";
            string str2 = "WHERE type = 'com'";
            string cmdUpdateConfTable = str1 + "'" + value + "'" + str2;
            Ops    Op = new Ops(dbPath);

            Op.ChangeCommand(cmdUpdateConfTable, null);
        }
Пример #5
0
        public static void initUsingTable()
        {
            Ops Op = bulidOp();
            SQLiteConnection conn = Ops.buildConn();

            //Op.PrepareCommand(cmdCreteText, null);
            Ops.ChangeCommand(cmdCreteUsingtableText, conn);
            conn.Close();
        }
Пример #6
0
        public static void initUsingTable()
        {
            Ops              Op           = bulidOp();
            string           cmdCreteText = "CREATE TABLE IF NOT EXISTS fileUsing(type varchar(30),url varchar(1000),filename varcharo(30),filepath varchar(1000),state integer)";
            SQLiteConnection conn         = Ops.buildConn();

            //Op.PrepareCommand(cmdCreteText, null);
            Ops.ChangeCommand(cmdCreteText, conn);
            conn.Close();
        }
Пример #7
0
        public static int checkLastUpdate()
        {
            string           filePath     = null;
            SQLiteConnection conn         = Ops.buildConn();
            string           cmdQueryText = "SELECT  * FROM fileUpdate WHERE state<1";
            SQLiteDataReader sdr          = Ops.noChangeCommand(cmdQueryText, conn);

            Ops.ChangeCommand(cmdQueryText, conn);
            int i = 0;
            int j = 0;

            while (sdr.Read())
            {
                i++;
                string        filenamestr = sdr.GetString(2);
                SQLiteCommand cmdChangeTable;
                if (sdr.GetString(0).Equals("image"))
                {
                    filePath = @Environment.CurrentDirectory + "/Image/" + filenamestr;
                }
                else if (sdr.GetString(0).Equals("video"))
                {
                    filePath = @Environment.CurrentDirectory + "/Video/" + filenamestr;
                }
                else
                {
                    filePath = @"D:\";
                }
                //写程序时要严格注意语法规则,可以节省不少时间
                string cmdUpdateText = "UPDATE fileUpdate SET state=1 WHERE filename =" + "'" + filenamestr + "'";
                if (File.Exists(filePath))
                {
                    Ops.ChangeCommand(cmdUpdateText, conn);
                    Console.WriteLine(j);
                }
                Console.WriteLine(sdr.GetString(1) + "  " + sdr.GetString(2));
            }

            if (i == 0)
            {
                Console.WriteLine(i);
                string cmdDropText = "DROP TABLE fileUsing";
                Ops.ChangeCommand(cmdDropText, conn);
                initSqlite.initUsingTable();
                string cmdCopyText = "INSERT INTO fileUsing SELECT * FROM  fileUpdate";
                Ops.ChangeCommand(cmdCopyText, conn);
            }
            conn.Close();
            return(i);
        }
Пример #8
0
        public static void UpdateFromServer()
        {
            string filePath;
            //Ops Op = bulidOp();
            //// 数组  【】    对象{}     值“”
            string json1 = "{type:'image',url:'http://i1.hoopchina.com.cn/blogfile/201501/08/BbsImg142070525332424_550*550.jpg'}";
            //string json2 = "{type:'video',url:'http://i2.hoopchina.com.cn/blogfile/201411/27/BbsImg141707487288557_1271*988.jpg'}";
            string json2      = "{type:'image',url:'http://p0.qhimg.com/dmsmty/70_70_100/t0152c6ddbb22a37797.png'}";
            string json3      = "{type:'image',url:'http://i1.hoopchina.com.cn/blogfile/201304/09/136548593327743.jpg'}";
            string jsonString = "[" + json1 + "," + json2 + "," + json3 + "]";

            // string jsonString = myfile.readname();
            StringBuilder sb     = new StringBuilder();
            JArray        array1 = (JArray)JsonConvert.DeserializeObject(jsonString);
            int           le     = array1.ToArray().Length;

            for (int i = 0; i < le; ++i)
            {
                WebClient mywebclient = new WebClient();
                JObject   jo          = (JObject)array1[i];
                //string frontUrl = "http://10.108.158.5:8080/cpServerPro";
                //string backUrl = jo["url"].ToString();
                //string url = frontUrl + backUrl;
                //string newfilename = backUrl;

                //Boolean b = backUrl.Equals("");
                //if (b) { continue; }

                string  url    = jo["url"].ToString();
                Boolean isHave = urlSearch(url);
                if (isHave)
                {
                    continue;
                }

                //if (backUrl.Equals("")) { continue; }
                string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()
                                     + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + i + ".jpg";
                //下载很快,如果不在文件名加入i的话,会在一秒内下载完,使用时间当做文件名,最后就只剩一个文件。
                //string filePath = @"D:\VSPROJECT\WindowsFormsApplication3\" + newfilename;
                if (jo["type"].ToString().Equals("image"))
                {
                    filePath = @Environment.CurrentDirectory + "/Image/" + newfilename;
                }
                else if (jo["type"].ToString().Equals("video"))
                {
                    filePath = @Environment.CurrentDirectory + "/Video/" + newfilename;
                }
                else
                {
                    filePath = @"D:\";
                }
                try
                {
                    mywebclient.DownloadFile(url, filePath);
                    SQLiteParameter[] Params1 = new SQLiteParameter[] {
                        new SQLiteParameter("@type", jo["type"]),
                        new SQLiteParameter("@url", jo["url"]),
                        new SQLiteParameter("@filename", newfilename),
                        new SQLiteParameter("@filepath", filePath),
                        new SQLiteParameter("@state", 1)
                    };

                    if (File.Exists(filePath))
                    {
                        Op.ChangeCommand(cmdInsertTableupdateText, Params1);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            int j = updateSq.checkLastUpdate();
        }
Пример #9
0
        public static void initUsingTable()
        {
            Ops Op = new Ops(dbPath);

            Op.ChangeCommand(cmdCreteUsingtableText, null);
        }
Пример #10
0
        public static void createConfTable()
        {
            Ops Op = new Ops(dbPath);

            Op.ChangeCommand(cmdCreateConfTable, null);
        }