コード例 #1
0
 protected void ButtonAllFilesDelete_Click(object sender, EventArgs e)
 {
     BlobManager blobManager = new BlobManager();
     foreach (GridViewRow row in fileGrid.Rows)
     {
         string fname = row.Cells[2].Text;
         FileInforMa.File_Delete(fileId.Text, fname);
     }
     blobManager.DeleteBlobDirectory(HiddenFieldCustomerID.Value);
     ButtonBack_Click(sender, e);
 }
コード例 #2
0
        public void DeleteDirectoryNotExistInDB()
        {
            try
            {
                if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "") //only case for has blob , manage blob
                {

                    logger.Debug("Begin DeleteDirectoryNotExistInDB ");
                    BlobManager blob = new BlobManager();
                    List<string> listDirectory = blob.GetDirectoryListInContainer();
                    string listCustomerId = "";
                    foreach (string i in listDirectory)
                    {
                        listCustomerId += string.Format("'{0}',", i);
                    }
                    if (listCustomerId.EndsWith(","))
                        listCustomerId = listCustomerId.Remove(listCustomerId.Length - 1, 1);

                    List<SharingInfo> listSharingInfo = new List<SharingInfo>();
                    using (SqlConnection cnn = new SqlConnection(Common.GetConnectString()))
                    {
                        SqlCommand cmd = new SqlCommand();
                        cmd.CommandType = System.Data.CommandType.Text;

                        cmd.CommandText = string.Format("select distinct S.customer_id from TD_SHARING_INFO as S , TD_FILE_INFO as F where S.ID = F.File_Sharing_ID and S.customer_id in ({0})", listCustomerId);
                        cmd.Connection = cnn;
                        cnn.Open();
                        SqlDataReader dr = cmd.ExecuteReader();
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                SharingInfo objSharingInfo = new SharingInfo();
                                objSharingInfo.customer_id = (dr["customer_id"] is DBNull) ? string.Empty : dr["customer_id"].ToString();

                                listSharingInfo.Add(objSharingInfo);
                            }
                        }
                        cnn.Close();
                    }

                    if (listDirectory.Count > listSharingInfo.Count)
                    {
                        foreach (string i in listDirectory)
                        {
                            SharingInfo objShare = listSharingInfo.FirstOrDefault(p => p.customer_id == i);
                            if (objShare == null)
                            {
                                logger.Debug("Delete directory = " + i);
                                blob.DeleteBlobDirectory(i);
                            }
                        }
                    }
                    logger.Debug("End DeleteDirectoryNotExistInDB ");

                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in DeleteDirectoryNotExistInDB ", ex);
            }
        }
コード例 #3
0
        public void DeleteFiles()
        {
            try
            {
                logger.Info("Begin WS DeleteFiles from Webservice");
                List<SharingInfo> listSharingInfo = new List<SharingInfo>();
                SharingInfo objSharingInfo = new SharingInfo();
                using (SqlConnection cnn = new SqlConnection(Common.GetConnectString()))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = "select * from TD_SHARING_INFO where Expiration_date < getdate() and delete_flag = 0";
                    cmd.Connection = cnn;
                    cnn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            listSharingInfo.Add(objSharingInfo.CustomerIDataReader(dr));
                        }
                    }
                    cnn.Close();
                }

                if (listSharingInfo.Count > 0)
                {
                    if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
                    {
                        BlobManager blobManger = new BlobManager();
                        for (int i = 0; i < listSharingInfo.Count; i++)
                        {
                            blobManger.DeleteBlobDirectory(listSharingInfo[i].customer_id);
                            UpdateSharingInfo(listSharingInfo[i].ID);
                        }
                    }
                    else
                    {
                        string hostPath = GetMapPath();
                        for (int i = 0; i < listSharingInfo.Count; i++)
                        {
                            string pathCustomerID = System.IO.Path.Combine(hostPath, Constant.UPLOAD_STORAGE + "\\" + listSharingInfo[i].customer_id);
                            if (Directory.Exists(pathCustomerID))
                                Directory.Delete(pathCustomerID, true);

                            UpdateSharingInfo(listSharingInfo[i].ID);

                        }
                    }
                }

                logger.Info("End DeleteFiles from Webservice");
            }
            catch (Exception ex)
            {
                logger.Error("Error in DeleteFiles " , ex);
                throw ex;
            }
        }
コード例 #4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                string userLogin = hiddenAccount.Value;
                logger.Info("Begin btnUpload_Click userLogin = "******"0" : "1";
                DateTime expireDate = DateTime.Now.Date.AddDays(Convert.ToInt32(dropdownTermUpload.SelectedValue));
                //1. check Customer list
                if (this.CustomerInfo.Count == 0)
                    throw new Exception(GetResource("MSG_AT_LEAST_ONE_CUSTOMER"));

                //1.2 Check At least ONE upload file
                if (panelUploadFiles.Visible == false || PostedFiles.Count == 0)
                    throw new Exception(GetResource("MSG_AT_LEST_ONE_FILE_UPLOAD"));

                //2.Update Database
                string hostPath = GetMapPath();
                List<UserMail> listMailSystem = new List<UserMail>();
                using (SqlConnection Conn = new SqlConnection(Common.GetConnectString()))
                {
                    SqlTransaction Trans = null;
                    try
                    {
                        Conn.Open();
                        UserMail accountMailLogin = null;
                        using (SqlCommand cmd = new SqlCommand("DDV_GetDDMemberEmail", Conn))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@Account", userLogin);
                            var emailAdress = cmd.ExecuteScalar();
                            if (emailAdress != null)
                                accountMailLogin = new UserMail(userLogin, userLogin, emailAdress.ToString());
                        }
                        logger.Debug("Begin Transaction for update db");
                        Trans = Conn.BeginTransaction();

                        #region Update Database , files

                        foreach (CustomerInfo customer in this.CustomerInfo)
                        {
                            customer.CustomerId = KeyGenerator.GetUniqueKey(20);
                            string customerPass = KeyGenerator.GetUniqueKey(10);
                            string fileSharingId = "";
                            using (SqlCommand cmd = new SqlCommand("DDV_InsertSharingInfo", Conn, Trans))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
                                cmd.Parameters.AddWithValue("@dd_member_account", userLogin);
                                cmd.Parameters.AddWithValue("@Mode_code", modeCode);
                                cmd.Parameters.AddWithValue("@customer_id", customer.CustomerId);
                                cmd.Parameters.AddWithValue("@customer_password", customerPass);
                                cmd.Parameters.AddWithValue("@expiration_date", expireDate);

                                cmd.ExecuteNonQuery();
                                fileSharingId = cmd.Parameters["@id"].Value.ToString();
                            }
                            using (SqlCommand cmd = new SqlCommand("DDV_InsertCustomerInfo", Conn, Trans))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.AddWithValue("@File_Sharing_ID", fileSharingId);
                                cmd.Parameters.AddWithValue("@Customer_name", customer.CustomerName);
                                cmd.Parameters.AddWithValue("@Customer_Email", customer.CustomerEmail);
                                cmd.ExecuteNonQuery();
                            }

                            //Case Upload File
                            string listFileName = "";
                            if (panelUploadFiles.Visible)
                            {
                                logger.Debug("Upload files in customerID =  " + customer.CustomerId);
                                if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
                                {
                                    BlobManager blobManager = new BlobManager();

                                    foreach (DetailsFile objfile in PostedFiles)
                                    {
                                        string blobName = customer.CustomerId + "/" + objfile.FileName;
                                        string soureBlob = "Temp/" + hiddenAccount.Value + "/" + objfile.FileName;

                                        long contentLenght =  blobManager.CopyBlob(soureBlob, blobName);

                                        if (contentLenght > 0)
                                        {
                                            listFileName += objfile.FileName + ",";

                                            using (SqlCommand cmd = new SqlCommand("DDV_InsertFileInfo", Conn, Trans))
                                            {
                                                cmd.CommandType = CommandType.StoredProcedure;
                                                cmd.Parameters.AddWithValue("@File_Sharing_ID", fileSharingId);
                                                cmd.Parameters.AddWithValue("@File_Name", Path.GetFileName(objfile.FileName));
                                                cmd.Parameters.AddWithValue("@File_Size", objfile.ContentLength);
                                                cmd.Parameters.AddWithValue("@Upload_Date", DateTime.Now.Date);
                                                cmd.ExecuteNonQuery();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    string pathCustomerID = CreateUploadCustomerID(hostPath, customer.CustomerId);
                                    foreach (DetailsFile postedFile in PostedFiles)
                                    {

                                        listFileName += postedFile.FileName + "\n";
                                        using (SqlCommand cmd = new SqlCommand("DDV_InsertFileInfo", Conn, Trans))
                                        {
                                            cmd.CommandType = CommandType.StoredProcedure;
                                            cmd.Parameters.AddWithValue("@File_Sharing_ID", fileSharingId);
                                            cmd.Parameters.AddWithValue("@File_Name", postedFile.FileName);
                                            cmd.Parameters.AddWithValue("@File_Size", postedFile.ContentLength);
                                            cmd.Parameters.AddWithValue("@Upload_Date", DateTime.Now.Date);
                                            cmd.ExecuteNonQuery();
                                        }
                                    }
                                }
                            }
                            //Add Mail System
                            UserMail mailSystem = new UserMail(customer.CustomerName, customer.CustomerName, customer.CustomerEmail);
                            mailSystem.AddParams("{DD_MEMBER_NAME}", userLogin);
                            mailSystem.AddParams("{customer_id}", customer.CustomerId);
                            mailSystem.AddParams("{customer_Password}", customerPass);
                            mailSystem.AddParams("{TD_FILE_SHARING_INFORATION.ID}", fileSharingId);
                            mailSystem.AddParams("{TD_FILE_SHARING_INFORMATION.Expiration_date}", expireDate.ToShortDateString());
                            mailSystem.AddParams("{UrlPortal}", Common.AppSettingKey(Constant.PORTAL_URL));
                            if (listFileName.Length > 0)
                                mailSystem.AddParams("{File_Name}", listFileName.Remove(listFileName.Length - 1, 1));
                            listMailSystem.Add(mailSystem);
                        }

                        Trans.Commit();
                        Conn.Close();
                        PostedFiles = null;
                        #endregion

                        #region SendMail
                        logger.Debug("Begin send Email ");
                        string mailBody = "";
                        string subject = "";
                        if (panelUploadFiles.Visible)
                        {
                            mailBody = GetMailBody(hostPath, "Invitation_mail_body_download.txt");
                            subject = Common.GetResourceString("MAIL_DownloadSubject");
                        }
                        else
                        {
                            mailBody = GetMailBody(hostPath, "Invitation_mail_body_upload.txt");
                            subject = Common.GetResourceString("MAIL_InvitationSubject");
                        }
                        foreach (UserMail mail in listMailSystem)
                        {
                            mail.SendEmail(accountMailLogin, mail, subject, mailBody);
                        }
                        #endregion

                    }
                    catch (Exception ex)
                    {
                        Trans.Rollback();
                        Conn.Close();
                        try
                        {
                            if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
                            {
                                BlobManager blobManager = new BlobManager();
                                foreach (CustomerInfo customer in this.CustomerInfo)
                                {
                                    blobManager.DeleteBlobDirectory(customer.CustomerId);
                                }
                            }
                            else
                            {
                                foreach (CustomerInfo customer in this.CustomerInfo)
                                {
                                    string pathCustomerID = System.IO.Path.Combine(hostPath, Constant.UPLOAD_STORAGE + "\\" + customer.CustomerId);
                                    if (Directory.Exists(pathCustomerID))
                                        Directory.Delete(pathCustomerID, true);
                                }
                            }
                        }
                        catch { logger.Error("Error when try to delete storage", ex); }
                        throw ex;
                    }

                }

                logger.Debug("End btnUpload_Click , loadData()");

                ScriptManager.RegisterStartupScript(this, typeof(Page), "Redirect", "alert(\"" + GetJSMessage(GetResource("TITLE_SUCESS"), GetResource("MSG_UPLOAD_SUCESS")) + "\");window.location='Upload.aspx';", true);
            }
            catch (Exception ex)
            {
                ButtonUpload.Enabled = true;
                logger.Error("Error btnUpload_Click", ex);
                RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("TITLE_ERROR"), ex.Message) + "\");");
            }
        }