private static void AddFileToQueue(FileObject fileObject) { var file = new UploadQueue { FileID = fileObject.FileId, OriginalFileName = fileObject.FileName, FileLocation = fileObject.Uri, ContentType = "application/zip", //TODO: I should try and actually figure out what the ContentType is. ContentSize = fileObject.FileSize, UserKey = "61e8b5db-d076-44c3-914d-05e37cef4abd", UserIP = "0.0.0.0", UploadedDate = DateTime.Now, Processing = false }; UploadQueueController.AddItemToQueue(file); }
private static void ProcessResult(Extension result, FileObject fileObject) { var connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; using (var sqlConnection = new SqlConnection(connString)) { sqlConnection.Open(); try { //we need to store the ExtensionDetail items foreach (var extensionDetails in result.ExtensionDetails) { using (var sqlCommand = new SqlCommand("[dbo].[Store_Downloads_EVS_ExtensionDetail_Insert]", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add(new SqlParameter("ExtensionDetailID", SqlDbType.Int) { Direction = ParameterDirection.Input, Value = extensionDetails.ExtensionDetailID }); sqlCommand.Parameters.Add(new SqlParameter("ItemID", SqlDbType.Int) { Direction = ParameterDirection.Input, Value = fileObject.ItemId }); sqlCommand.Parameters.Add(new SqlParameter("DetailID", SqlDbType.NChar) { Size = 36, Direction = ParameterDirection.Input, Value = extensionDetails.DetailID }); sqlCommand.Parameters.Add(new SqlParameter("DetailName", SqlDbType.NVarChar) { Size = 250, Direction = ParameterDirection.Input, Value = extensionDetails.DetailName }); sqlCommand.Parameters.Add(new SqlParameter("DetailValue", SqlDbType.NVarChar) { Size = 250, Direction = ParameterDirection.Input, Value = extensionDetails.DetailValue }); sqlCommand.ExecuteNonQuery(); } } //then we need to store the ExtensionMessage items foreach (var extensionMessages in result.ExtensionMessages) { using (var sqlCommand = new SqlCommand("[dbo].[Store_Downloads_EVS_ExtensionMessage_Insert]", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add(new SqlParameter("ExtensionMessageID", SqlDbType.Int) { Direction = ParameterDirection.Input, Value = extensionMessages.ExtensionMessageID }); sqlCommand.Parameters.Add(new SqlParameter("ItemID", SqlDbType.Int) { Direction = ParameterDirection.Input, Value = fileObject.ItemId }); sqlCommand.Parameters.Add(new SqlParameter("MessageTypeID", SqlDbType.Int) { Direction = ParameterDirection.Input, Value = extensionMessages.MessageTypeID }); sqlCommand.Parameters.Add(new SqlParameter("MessageID", SqlDbType.NChar) { Size = 36, Direction = ParameterDirection.Input, Value = extensionMessages.MessageID }); sqlCommand.Parameters.Add(new SqlParameter("Message", SqlDbType.NVarChar) { Size = -1, Direction = ParameterDirection.Input, Value = extensionMessages.Message }); sqlCommand.Parameters.Add(new SqlParameter("Rule", SqlDbType.NVarChar) { Size = 250, Direction = ParameterDirection.Input, Value = extensionMessages.Rule }); sqlCommand.ExecuteNonQuery(); } } //then we need to update the Store_Downloads_EVS_ScanLog table. using (var sqlCommand = new SqlCommand("[dbo].[Store_Downloads_EVS_ScanLog_Insert]", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add(new SqlParameter("ItemID", SqlDbType.Int) { Direction = ParameterDirection.Input, Value = fileObject.ItemId }); sqlCommand.Parameters.Add(new SqlParameter("LastScan", SqlDbType.DateTime) { Direction = ParameterDirection.Input, Value = DateTime.Now }); sqlCommand.ExecuteNonQuery(); } } finally { sqlConnection.Close(); } } }
private static FileObject MoveAFile() { var output = new FileObject(); using (var transactionScope = new TransactionScope()) { var connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; using (var sqlConnection = new SqlConnection(connString)) { sqlConnection.Open(); int itemId; string contentGUID; string filePath; byte[] transactionContext; Console.WriteLine("Obtaining next file to process."); using (var sqlCommand = new SqlCommand("[dbo].[Store_Downloads_EVS_GetNextItemToProcess]", sqlConnection)) { sqlCommand.CommandType = CommandType.StoredProcedure; using (var reader = sqlCommand.ExecuteReader()) { if (reader.HasRows) { reader.Read(); itemId = (int)reader["ItemID"]; contentGUID = reader["ContentGUID"].ToString(); filePath = (string)reader["Path"]; transactionContext = (byte[])reader["TransactionContext"]; reader.Close(); } else { return(null); } } } Console.WriteLine("Found a file, reading stream."); using (var source = new SqlFileStream(filePath, transactionContext, FileAccess.Read)) { var newFileName = contentGUID + ".dat"; var connectionString = ConfigurationManager.AppSettings[Constants.ConfigurationSectionKey]; var storageAccount = CloudStorageAccount.Parse(connectionString); var container = storageAccount.CreateCloudBlobClient().GetContainerReference(Constants.ContainerName); container.CreateIfNotExists(); var blob = container.GetBlockBlobReference(newFileName); var fileSize = (int)source.Length; var buffer = new byte[fileSize]; source.Read(buffer, 0, buffer.Length); source.Close(); using (var stream = new MemoryStream(buffer, false)) { blob.UploadFromStream(stream); } output.ItemId = itemId; output.FileId = Guid.NewGuid().ToString(); output.ContentId = contentGUID; output.FileName = contentGUID + ".zip"; output.FileSize = fileSize; output.Uri = blob.Uri.ToString(); } } transactionScope.Complete(); } return(output); }