Example #1
0
        /// <summary>
        /// upload file create from user
        /// </summary>
        public void uploadFile_User()
        {
            try
            {
                ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, storegetsys);

                int n = ds.Tables[0].Rows.Count;

                if (n < 1)
                {
                    ds.Clear();
                    //Console.WriteLine("! chua co file Video dong bo from Itemmovie to Storage -" + DateTime.Now + " !");
                    Ultils.AddToLogFile("! chua co file Video dong bo from Itemmovie to Storage -" + DateTime.Now + " !");
                    Thread.Sleep(2000);
                    return;
                }

                for (int i = 0; i < n; i++)
                {
                    ID         = Convert.ToInt64(ds.Tables[0].Rows[i]["ID"]);
                    idVideo    = Convert.ToInt64(ds.Tables[0].Rows[i]["Itemcode"]);
                    type       = ds.Tables[0].Rows[i]["type"].ToString();
                    ItemFile   = ds.Tables[0].Rows[i]["ItemFile"].ToString();
                    FolderName = ds.Tables[0].Rows[i]["FolderName"].ToString();

                    //Console.WriteLine("! Dang dong bo file Video " + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + DateTime.Now + " !");
                    Ultils.AddToLogFile("! Dang dong bo file Video " + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + DateTime.Now + " !");
                    try
                    {
                        if (type == "1")
                        {
                            file_path       = FolderMP4 + FolderName + "/" + ItemFile;
                            s3DirectoryName = s3DirectoryName + "/" + FolderName;
                            // upload file storage
                            if (sendMyFileToS3(file_path, myBucketName, s3DirectoryName, s3FileName))
                            {
                                status = true;
                            }
                        }

                        if (status == true)
                        {
                            SqlParameter[] param =
                            {
                                new SqlParameter("@id",      ID),
                                new SqlParameter("@idvideo", idVideo),
                                new SqlParameter("@status", 1)
                            };
                            ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, storeupdatesys_success, param);

                            //Console.WriteLine("! Upload phim:" + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + " to storage success- " + DateTime.Now + " !");
                            Ultils.AddToLogFile("! Upload phim:" + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + " to storage success- " + DateTime.Now + " !");
                        }
                        else
                        {
                            SqlParameter[] param =
                            {
                                new SqlParameter("@id",      ID),
                                new SqlParameter("@idvideo", idVideo),
                                new SqlParameter("@status", 2)
                            };

                            ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, storeupdatesys_fail, param);

                            //Console.WriteLine("! Upload phim:" + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + " to storage fail -" + DateTime.Now + " !");
                            Ultils.AddToLogFile("! Upload phim:" + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + " to storage fail -" + DateTime.Now + " !");
                        }
                    }
                    catch (Exception ex)
                    {
                        SqlParameter[] param =
                        {
                            new SqlParameter("@id",      ID),
                            new SqlParameter("@idvideo", idVideo),
                            new SqlParameter("@status", 2)
                        };

                        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, storeupdatesys_fail, param);

                        //Console.WriteLine("! Upload phim:" + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + " to storage fail " + DateTime.Now + " !");
                        Ultils.AddToLogFile("! Upload phim:" + FolderName + "/" + ItemFile + "--- idmoviegroup" + idVideo + "--" + " to storage fail " + DateTime.Now + " !");
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        public void DowloadFile()
        {
            try
            {
                string  host              = "10.60.135.32";
                string  user              = "******";
                string  pass              = "******";
                string  path_host         = "/media2/phimonbox/mp4/";//20171020/a6110324-17f6-460d-9927-8b72e769b06a_3.mp4
                string  path_local        = @"E:\fileMP4.mp4";
                DataSet ds                = null;
                string  store_sync_to_cdn = "PHIM_sync_to_cdn";

                ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, store_sync_to_cdn);
                int n = ds.Tables[0].Rows.Count;

                if (n < 1)
                {
                    ds.Clear();
                    Console.WriteLine("! chua co file Video dong bo from Itemmovie to Storage -" + DateTime.Now + " !");
                    //Ultils.AddToLogFile("! chua co file Video dong bo from Itemmovie to Storage -" + DateTime.Now + " !");
                    Thread.Sleep(2000);
                    return;
                }

                for (int i = 0; i < n; i++)
                {
                    string ID       = ds.Tables[0].Rows[i]["ID"].ToString();
                    string FileName = ds.Tables[0].Rows[i]["FileName"].ToString();
                    string Folder   = ds.Tables[0].Rows[i]["Folder"].ToString();
                    string id_group = ds.Tables[0].Rows[i]["id_group"].ToString();
                    FileName = FileName + ".mp4";

                    string path_host1 = path_host + Folder + "/" + FileName;
                    path_local = @"E:\onkeeng\mp4\" + Folder + "/" + FileName;

                    if (!Directory.Exists(@"E:\onkeeng\mp4\" + Folder))
                    {
                        Directory.CreateDirectory(@"E:\onkeeng\mp4\" + Folder);
                    }

                    if (FTPDownload(host, user, pass, path_host1, path_local))
                    {
                        SqlParameter[] param =
                        {
                            new SqlParameter("@itemfile", FileName),
                            new SqlParameter("@idvideo",  id_group),
                        };

                        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, "INSERT_SYNC_TO_CDN", param);

                        Console.WriteLine("upload success " + ds.Tables[0].Rows[0][0].ToString());
                    }
                    else
                    {
                        SqlParameter[] param =
                        {
                            new SqlParameter("@idvideo", id_group),
                            new SqlParameter("@status",         3),
                        };

                        ds = SqlHelper.ExecuteDataset(ConnStr, CommandType.StoredProcedure, "UPDATE_SYNC_TO_CDN", param);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }