示例#1
0
 public List<SharingInfo> Sharing_GetByAll()
 {
     List<SharingInfo> list = new List<SharingInfo>();
     using (SqlConnection Conn = new SqlConnection(Common.GetConnectString()))
     {
         try
         {
             Conn.Open();
             using (SqlCommand dbCmd = new SqlCommand("DDV_GetSharingInfo", Conn))
             {
                 dbCmd.CommandType = CommandType.StoredProcedure;
                 SharingInfo obj = new SharingInfo();
                 SqlDataReader dr = dbCmd.ExecuteReader();
                 if (dr.HasRows)
                 {
                     while (dr.Read())
                     {
                         list.Add(obj.CustomerIDataReader(dr));
                     }
                 }
                 dr.Close();
                 obj = null;
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             Conn.Close();
         }
     }
     return list;
 }
        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;
            }
        }
示例#3
0
 public SharingInfo CustomerIDataReader(IDataReader dr)
 {
     SharingInfo obj = new SharingInfo();
     obj.ID = Convert.ToInt32(dr["ID"]);
     obj.dd_member_account = (dr["dd_member_account"] is DBNull) ? string.Empty : dr["dd_member_account"].ToString();
     obj.Mode_code = (dr["Mode_code"] is DBNull) ? string.Empty : dr["Mode_code"].ToString();
     obj.customer_id = (dr["customer_id"] is DBNull) ? string.Empty : dr["customer_id"].ToString();
     obj.customer_password = (dr["customer_password"] is DBNull) ? string.Empty : dr["customer_password"].ToString();
     obj.delete_flag = (dr["delete_flag"] is DBNull) ? string.Empty : dr["delete_flag"].ToString();
     obj.Create_date = Convert.ToDateTime(dr["Create_date"]);
     obj.Expiration_date = Convert.ToDateTime(dr["Expiration_date"]);
     return obj;
 }
        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);
            }
        }