Example #1
0
        public async Task <IActionResult> Create([Bind("Id,Heading,Description,File")] Image image)
        {
            if (ModelState.IsValid)
            {
                if (SignInManager.IsSignedIn(User))
                {
                    UplaodToGallery(image);
                    _context.Add(image);
                    await _context.SaveChangesAsync();

                    var publisher = (from publishers in _context.Publisher

                                     where publishers.EmailAddresss.Equals(User.Identity.Name)
                                     select publishers).FirstOrDefault();

                    UploadRecord record = new UploadRecord();

                    record.ImageId     = image.Id;
                    record.PublisherId = publisher.Id;
                    record.UploadTime  = DateTime.Now;

                    _context.Add(record);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index), "UploadRecords"));
                }
            }
            return(View(image));
        }
        // POST: UploadRecords/Delete/5
        public async Task <ActionResult> WithDraw(string id)
        {
            UploadRecord uploadRecord = await db.UploadRecords.FindAsync(id);

            // Find relevant data

            switch (uploadRecord.Category.Type)
            {
            case SuperCategory.EnglishTest:
                db.EnglishTests.Where(o => o.UploadRecordID.Equals(id)).Delete();
                break;

            case SuperCategory.RefresherTraining:
                db.RefresherTrainings.Where(o => o.UploadRecordID.Equals(id)).Delete();
                break;
            }

            // Set uploadRecord IsWithdrawn
            uploadRecord.IsWithdrawn     = true;
            db.Entry(uploadRecord).State = EntityState.Modified;


            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #3
0
        public string UploadLog(UploadRecord record)
        {
            IQATools client = null;
            string   result = string.Empty;

            try
            {
                client = channel_factory.CreateChannel();
                string rs = client.UploadLog(record);
                if (result.ToLower().Contains("exception"))
                {
                    result = string.Format("{0} {1}", TX_RESULT_FAIL, rs);
                }
                else
                {
                    result = string.Format("{0} {1}", TX_RESULT_SUC, rs);
                }
                ((ICommunicationObject)client).Close();
            }
            catch (Exception ex)
            {
                result = string.Format("{0} communication failure, {1}", TX_RESULT_FAIL, ex.Message);
                if (client != null)
                {
                    ((ICommunicationObject)client).Abort();
                }
            }
            return(result);
        }
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            UploadRecord uploadRecord = await db.UploadRecords.FindAsync(id);

            db.UploadRecords.Remove(uploadRecord);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #5
0
        public string UploadLog(UploadRecord record)
        {
            var       pwd       = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            IUploader uploadder = new WinSCPUploader(record)
            {
                PrvKeyLoc = Path.Combine(pwd, "prvkf.xml")
            };
            string rs = uploadder.Upload();

            return(rs);
        }
        // GET: UploadRecords/Delete/5
        public async Task <ActionResult> Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UploadRecord uploadRecord = await db.UploadRecords.FindAsync(id);

            if (uploadRecord == null)
            {
                return(HttpNotFound());
            }
            return(View(uploadRecord));
        }
Example #7
0
        public static Task <string[]> UploadLogToSftp(string usr, string pwd, string bugnum, string location, Action <string> callback)
        {
            GeneralUtility.IUploadRecord upload_rec = new UploadRecord()
            {
                Usr = usr, Passwd = pwd, Target = bugnum, Source = location
            };
            var tx_mgr = GammaClientTXManagerFactory.GetGammaClientTXManager();
            var tasks  = new List <Task <string> >();

            foreach (var m in from machine in NetworkManagerFactory.GetSimpleNetworkManager().Machines where machine.Alive == NodeState.Online && machine.IsSelected select machine)
            {
                tasks.Add(tx_mgr.StartQAToolsTransaction(m, GammaTXQATools.UPLOAD, upload_rec));
            }
            return(Task.WhenAll(tasks));
        }
        // POST: UploadRecords/Delete/5
        public async Task <ActionResult> CheckDetails(string id)
        {
            UploadRecord uploadRecord = await db.UploadRecords.Where(o => o.ID.Equals(id)).Include(o => o.Category).FirstOrDefaultAsync();

            // Find relevant data

            switch (uploadRecord.Category.Type)
            {
            case SuperCategory.EnglishTest:

                return(RedirectToAction("Search", "EnglishTests", new { UploadRecordID = id, Area = "Search" }));

                break;

            case SuperCategory.RefresherTraining:
                return(RedirectToAction("Search", "RefresherTrainings", new { UploadRecordID = id }));

                break;
            }

            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// 获取上传记录。
        /// </summary>
        /// <returns></returns>
        private UploadRecord GetUploadRecord(T data)
        {
            string sql    = $"SELECT TOP 1 S.data_type, S.data_id, S.uploaded_data, S.upload_result, S.upload_time, S.is_success, S.project_name FROM upload_record S WHERE S.data_type = '{ data.GetType().Name }' AND S.data_id = { data.DataId } AND is_deleted = 0 ORDER BY S.upload_time DESC;";
            var    result = ArDBConnection.ExceuteSQLDataTable(sql);

            if (result == null || result.Rows.Count == 0)
            {
                return(null);
            }
            DataRow      first  = result.AsEnumerable().First();
            UploadRecord record = new UploadRecord
            {
                DataType     = Convert.ToString(first["data_type"]),
                DataId       = Convert.ToInt32(first["data_id"]),
                UploadTime   = Convert.ToDateTime(first["upload_time"]),
                UploadedData = Convert.ToString(first["uploaded_data"]),
                UploadResult = Convert.ToString(first["upload_result"]),
                IsSuccess    = Convert.ToBoolean(first["is_success"]),
                ProjectName  = Convert.ToString(first["project_name"]),
            };

            return(record);
        }
Example #10
0
        public async Task <IActionResult> Upload()
        {
            var user = await GetCurrentUserAsync();

            var file  = Request.Form.Files.First();
            var model = await _storageService
                        .SaveToOSS(file, Convert.ToInt32(_configuration["ColossusPublicBucketId"]), 30);

            var record = new UploadRecord
            {
                UploaderId     = user.Id,
                FileId         = model.FileKey,
                SourceFileName = file.FileName.Replace(" ", "")
            };

            _dbContext.UploadRecords.Add(record);
            await _dbContext.SaveChangesAsync();

            return(Json(new
            {
                message = "Uploaded!",
                value = model.Path
            }));
        }
Example #11
0
 public async Task <bool> ReportUpload(UploadRecord uploadRecord)
 {
     throw new NotImplementedException();
 }
Example #12
0
 public async Task <bool> CreateUploadAsync(UploadRecord uploadRecord)
 {
     return(await _uploadDAO.CreateAsync(uploadRecord).ConfigureAwait(false));
 }
Example #13
0
        public async Task <Result <bool> > CreateUploadAsync(UploadPost post, int failureCount)
        {
            var result = false;

            // Escape condition for recursive call if exception is thrown.
            if (failureCount >= Constants.OperationRetry)
            {
                return(SystemUtilityService.CreateResult(Constants.UploadCreationErrorMessage, result, true));
            }

            try
            {
                if (!await _userManagementService.CheckUserExistenceAsync(post.Username).ConfigureAwait(false))
                {
                    // Log the fact user was invalid.
                    await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                                   Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.UploadUserDNESystemMessage).ConfigureAwait(false);

                    return(SystemUtilityService.CreateResult(Constants.UploadUserDNEUserMessage, result, false));
                }


                var latLong   = LocationUtilityService.GetImageLatitudeAndLongitude(post.Image);
                var latitude  = latLong.Item1;
                var longitude = latLong.Item2;

                var withinScope = LocationUtilityService.CheckLocationWithinPolygon(latitude, longitude, Constants.CurrentScopePolygon);

                if (!withinScope)
                {
                    // Log the fact that scope was violated.
                    await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                                   Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.ImageNotWithinScopeSystemMessage).ConfigureAwait(false);

                    return(SystemUtilityService.CreateResult(Constants.ImageNotWithinScopeUserMessage, result, false));
                }

                var storeID = await _storeService.FindStoreAsync(latitude, longitude).ConfigureAwait(false);

                if (storeID == Constants.NoStoreFoundCode)
                {
                    // Log the fact that scope was violated.
                    await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                                   Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.NoStoreFoundSystemMessage).ConfigureAwait(false);

                    return(SystemUtilityService.CreateResult(Constants.NoStoreFoundUserMessage, result, false));
                }

                var imagePath = Constants.PhotoFolder + "\\" + post.Username + "_" + TimeUtilityService.CurrentUnixTime() + post.FileExtension;

                var uploadDTO = new UploadDTO(imagePath, post.Image, post.Category, post.Name, (DateTime)post.PostTime, post.Username, post.Description,
                                              post.Rating, post.Price, post.PriceUnit, post.ImageSize);

                var verification = _uploadService.VerifyUpload(uploadDTO, Constants.MaximumPhotoCharacters, Constants.MinimumPhotoCharacters, Constants.MinimumImageSizeMB, Constants.MaximumImageSizeMB, Constants.ValidImageExtensions,
                                                               Constants.IngredientNameMaximumCharacters, Constants.IngredientNameMinimumCharacters, Constants.MaximumIngredientPrice,
                                                               Constants.DescriptionMaximumCharacters, Constants.DescriptionMinimumCharacters, Constants.ExogredientCategories,
                                                               Constants.ExogredientPriceUnits, Constants.ValidTimeBufferMinutes, Constants.MaximumRating, Constants.MinimumRating);

                if (!verification.VerificationStatus)
                {
                    // Log the fact that scope was violated.
                    await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                                   Constants.CreateUploadOperation, post.Username, post.IPAddress, Constants.UploadNotValidSystemMessage).ConfigureAwait(false);

                    return(SystemUtilityService.CreateResult(verification.Message, result, false));
                }

                Directory.CreateDirectory(Constants.PhotoFolder);
                post.Image.Save(imagePath);

                var uploadRecord = new UploadRecord(post.PostTime, post.Username, storeID, post.Description, post.Rating.ToString(), imagePath,
                                                    post.Price, post.PriceUnit, post.Name, Constants.NoValueInt, Constants.NoValueInt, Constants.NotInProgressStatus, post.Category);

                await _uploadService.CreateUploadAsync(uploadRecord).ConfigureAwait(false);

                result = true;
            }
            catch (Exception ex)
            {
                // Log exception.
                await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                               Constants.CreateUploadOperation, post.Username, post.IPAddress, ex.ToString()).ConfigureAwait(false);

                // Recursively retry the operation until the maximum amount of retries is reached.
                await CreateUploadAsync(post, ++failureCount).ConfigureAwait(false);
            }

            // Log the fact that the operation was successful.
            await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                           Constants.CreateUploadOperation, post.Username, post.IPAddress).ConfigureAwait(false);

            return(SystemUtilityService.CreateResult(Constants.UploadCreationSuccessMessage, result, false));
        }
Example #14
0
 public Task <string> UploadLogAsync(UploadRecord record)
 {
     return(Task.Run(() => {
         return UploadLog(record);
     }));
 }