Esempio n. 1
0
        public override async Task ExecuteAsync(TaskExecutionContext ctx)
        {
            // Delete all media records which are in transient state since at least 3 hours.
            var olderThan          = DateTime.UtcNow.AddHours(-3);
            var fileAutoCommit     = _fileRepository.AutoCommitEnabled;
            var downloadAutoCommit = _downloadRepository.AutoCommitEnabled;

            _fileRepository.AutoCommitEnabled     = false;
            _downloadRepository.AutoCommitEnabled = false;

            try
            {
                using (var scope = new DbContextScope(autoDetectChanges: false, validateOnSave: false, hooksEnabled: false))
                {
                    var files = await _fileRepository.Table.Where(x => x.IsTransient && x.UpdatedOnUtc < olderThan).ToListAsync();

                    foreach (var file in files)
                    {
                        _mediaService.DeleteFile(file, true);
                    }

                    await _fileRepository.Context.SaveChangesAsync();

                    var downloads = await _downloadRepository.Table.Where(x => x.IsTransient && x.UpdatedOnUtc < olderThan).ToListAsync();

                    foreach (var download in downloads)
                    {
                        _downloadService.DeleteDownload(download);
                    }

                    await _downloadRepository.Context.SaveChangesAsync();

                    if (DataSettings.Current.IsSqlServer && (files.Any() || downloads.Any()))
                    {
                        try
                        {
                            _fileRepository.Context.ExecuteSqlCommand("DBCC SHRINKDATABASE(0)", true);
                        }
                        catch { }
                    }
                }
            }
            finally
            {
                _fileRepository.AutoCommitEnabled     = fileAutoCommit;
                _downloadRepository.AutoCommitEnabled = downloadAutoCommit;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Delete file by its guid
        /// </summary>
        /// <param name="id">file guid</param>
        /// <returns></returns>
        public ActionResult DeleteFile(Guid id)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Json(new
                {
                    success = false,
                    id = 0
                }, "text/plain"));
            }
            var download = _downloadService.GetDownloadByGuid(id);
            var newId    = download.DownloadGuid;

            _downloadService.DeleteDownload(download);
            return(Json(new
            {
                success = true,
                id = newId
            }, "text/plain"));
        }
        public ActionResult SubmissionDelete(DataSourceRequest command, int submissionRecordId)
        {
            var submissionRec = _submissionRepo.GetById(submissionRecordId);

            //delete download file if there is such
            if (String.IsNullOrEmpty(submissionRec.DownloadLink) == false)
            {
                int startIndex = submissionRec.DownloadLink.IndexOf("downloadId=");
                int length     = "downloadId=".Length;

                string downloadGuid = submissionRec.DownloadLink.Substring(startIndex + length);

                var download = _downloadService.GetDownloadByGuid(new Guid(downloadGuid));
                _downloadService.DeleteDownload(download);
            }

            _submissionRepo.Delete(submissionRec);

            return(new NullJsonResult());
        }
Esempio n. 4
0
        public ActionResult Setup(AnaliticsSetupModel model)
        {
            if (ModelState.IsValid)
            {
                _googleAnliticsSettings.AccountId = model.AccountId;
                _googleAnliticsSettings.ClientId  = model.ClientId;
                if (_googleAnliticsSettings.PrivateKeyId != model.PrivateKeyDownnloadId)
                {
                    var download = _downloadService.GetDownloadById(_googleAnliticsSettings.PrivateKeyId);
                    if (download != null)
                    {
                        _downloadService.DeleteDownload(download);
                    }
                }
                _googleAnliticsSettings.PrivateKeyId = model.PrivateKeyDownnloadId;
                _settingService.SaveSetting(_googleAnliticsSettings);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 5
0
        public ActionResult UploadSongFile(int SongId, string FieldName, HttpPostedFileBase File)
        {
            //lets get the song first
            var song = _songService.GetById(SongId);

            if (CanEdit(song) && (FieldName == "SongFile" || FieldName == "SampleFile"))
            {
                //ok so user can edit the song. let's see if it's a sample file or product file
                if (FieldName == "SongFile")
                {
                    //size check
                    if (File.ContentLength > _mobSocialSettings.SongFileMaximumUploadSize * 1024)
                    {
                        return(Json(new { Success = false, Message = "Maximum allowed file size is " + _mobSocialSettings.SongFileMaximumUploadSize + "KB" }));
                    }
                }
                else if (FieldName == "SampleFile")
                {
                    //size check
                    if (File.ContentLength > _mobSocialSettings.SongFileSampleMaximumUploadSize * 1024)
                    {
                        return(Json(new { Success = false, Message = "Maximum allowed file size is " + _mobSocialSettings.SongFileSampleMaximumUploadSize + "KB" }));
                    }
                }
                //we are here so files are good to download
                //save the downloaded files
                var songFile = new Download()
                {
                    ContentType    = File.ContentType,
                    DownloadGuid   = Guid.NewGuid(),
                    Filename       = Path.GetFileNameWithoutExtension(File.FileName),
                    Extension      = Path.GetExtension(File.FileName),
                    IsNew          = true,
                    UseDownloadUrl = false,
                    DownloadBinary = File.GetDownloadBits(),
                    DownloadUrl    = ""
                };
                _downloadService.InsertDownload(songFile);

                //now let's find the associated downloadable product and change it's download
                var product = _productService.GetProductById(song.AssociatedProductId);
                int oldDownloadId;
                if (FieldName == "SongFile")
                {
                    oldDownloadId      = product.DownloadId;
                    product.DownloadId = songFile.Id;
                    product.IsDownload = true;
                }
                else
                {
                    oldDownloadId             = product.SampleDownloadId;
                    product.SampleDownloadId  = songFile.Id;
                    product.HasSampleDownload = true;
                    //set preview url of song

                    song.PreviewUrl = Url.RouteUrl("GetSampleDownload", new { productId = product.Id });
                    _songService.Update(song);
                }

                //save the product now
                _productService.UpdateProduct(product);

                //delete the old download to clean up
                var download = _downloadService.GetDownloadById(oldDownloadId);
                if (download != null)
                {
                    _downloadService.DeleteDownload(download);
                }


                //and now that we have the song with us. let's send the preview and product id to the client
                return(Json(new { Success = true, PreviewUrl = song.PreviewUrl, ProductId = product.Id }));
            }
            else
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }
        }
 protected override Func <ServiceOperationResult> DeleteEntityAndReturnOperationResult(Download download, bool onlyChangeFlag = true)
 {
     return(() => _downloadService.DeleteDownload(download, onlyChangeFlag));
 }
Esempio n. 7
0
        public void UploadStructure(Download download)
        {
            var productAttributeList       = new List <ExportProductAttribute>();
            var productAttributeValueLists = new List <ExportProductAttributeValueList>();
            var categoryList = new List <ExportCategory>();
            var binary       = download.DownloadBinary;

            if (binary.Length == 0)
            {
                return;
            }
            using (MemoryStream ms = new MemoryStream(binary))
            {
                ExcelPackage pck = new ExcelPackage(ms);

                ExportProductAttributeValueList currentAttributesValueList = null;
                var currentProductAttribute = new ExportProductAttribute();
                var rootCategory            = new ExportCategory();
                var firstCategory           = new ExportCategory();
                var secondCategory          = new ExportCategory();
                var thirdCategory           = new ExportCategory();
                int categoryIdIncrement     = 1;
                int productAttributeValueListIdIncrement = 1;
                foreach (var workSheet in pck.Workbook.Worksheets)
                {
                    for (int i = 2; i <= workSheet.Dimension.End.Row - workSheet.Dimension.Start.Row + 1; i++)
                    {
                        if (workSheet.Cells[i, 1].Style.Font.Size == 20)
                        {
                            rootCategory = new ExportCategory()
                            {
                                CategoryId       = categoryIdIncrement,
                                ParentCategoryId = 0,
                                Title            = workSheet.GetValue <string>(i, 1).TrimEnd(),
                                TitleRu          = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                TitleDe          = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                TitleEs          = workSheet.GetValue <string>(i, 4).TrimEnd()
                            };
                            firstCategory  = null;
                            secondCategory = null;
                            thirdCategory  = null;
                            categoryList.Add(rootCategory);
                            categoryIdIncrement++;
                        }
                        if (workSheet.Cells[i, 1].Style.Font.Size == 18)
                        {
                            firstCategory = new ExportCategory()
                            {
                                CategoryId       = categoryIdIncrement,
                                ParentCategoryId = rootCategory.CategoryId,
                                Title            = workSheet.GetValue <string>(i, 1).TrimEnd(),
                                TitleRu          = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                TitleDe          = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                TitleEs          = workSheet.GetValue <string>(i, 4).TrimEnd()
                            };
                            if (secondCategory != null)
                            {
                                currentAttributesValueList = null;
                                secondCategory             = null;
                                thirdCategory = null;
                            }
                            else
                            {
                                if (currentAttributesValueList != null)
                                {
                                    if (firstCategory.Title != "Other")
                                    {
                                        firstCategory.AttributeValueListId = currentAttributesValueList.Id;
                                    }
                                    else
                                    {
                                        firstCategory.AttributeValueListId = int.MaxValue;
                                    }
                                }
                            }
                            categoryList.Add(firstCategory);
                            categoryIdIncrement++;
                        }

                        if (workSheet.Cells[i, 1].Style.Font.Size == 16)
                        {
                            secondCategory = new ExportCategory()
                            {
                                CategoryId       = categoryIdIncrement,
                                ParentCategoryId = firstCategory.CategoryId,
                                Title            = workSheet.GetValue <string>(i, 1).TrimEnd(),
                                TitleRu          = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                TitleDe          = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                TitleEs          = workSheet.GetValue <string>(i, 4).TrimEnd()
                            };
                            if (thirdCategory != null)
                            {
                                currentAttributesValueList = null;
                                thirdCategory = null;
                            }
                            else
                            {
                                if (currentAttributesValueList != null)
                                {
                                    if (secondCategory.Title != "Other")
                                    {
                                        secondCategory.AttributeValueListId = currentAttributesValueList.Id;
                                    }
                                    else
                                    {
                                        secondCategory.AttributeValueListId = int.MaxValue;
                                    }
                                }
                            }
                            categoryList.Add(secondCategory);
                            categoryIdIncrement++;
                        }

                        if (workSheet.Cells[i, 1].Style.Font.Size == 14)
                        {
                            thirdCategory = new ExportCategory()
                            {
                                CategoryId       = categoryIdIncrement,
                                ParentCategoryId = secondCategory.CategoryId,
                                Title            = workSheet.GetValue <string>(i, 1).TrimEnd(),
                                TitleRu          = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                TitleDe          = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                TitleEs          = workSheet.GetValue <string>(i, 4).TrimEnd()
                            };
                            if (currentAttributesValueList != null)
                            {
                                if (thirdCategory.Title != "Other")
                                {
                                    thirdCategory.AttributeValueListId = currentAttributesValueList.Id;
                                }
                                else
                                {
                                    thirdCategory.AttributeValueListId = int.MaxValue;
                                }
                            }
                            categoryList.Add(thirdCategory);
                            if (thirdCategory.Title == "Other")
                            {
                                thirdCategory = null;
                            }
                            categoryIdIncrement++;
                        }

                        if (workSheet.Cells[i, 1].Style.Font.Size == 10 && workSheet.Cells[i, 1].Style.Font.Bold)
                        {
                            var fontSize = workSheet.Cells[i - 1, 1].Style.Font.Size;
                            if (fontSize > 10)
                            {
                                var    cat    = categoryList.Last();
                                var    parent = categoryList.Where(x => x.CategoryId == cat.ParentCategoryId).FirstOrDefault();
                                string name   = parent.Title + "-" + cat.Title;
                                string nameRu = parent.TitleRu + "-" + cat.TitleRu;
                                string nameDe = parent.TitleDe + "-" + cat.TitleDe;
                                string nameEs = parent.TitleEs + "-" + cat.TitleEs;
                                currentAttributesValueList = new ExportProductAttributeValueList()
                                {
                                    List   = new List <ExportProductAttributeValue>(),
                                    Id     = productAttributeValueListIdIncrement,
                                    Name   = name,
                                    NameDe = nameDe,
                                    NameRu = nameRu,
                                    NameEs = nameEs
                                };
                                cat.AttributeValueListId = currentAttributesValueList.Id;
                                productAttributeValueListIdIncrement++;
                                productAttributeValueLists.Add(currentAttributesValueList);
                            }

                            var attrVal = workSheet.GetValue <string>(i, 1).TrimEnd();
                            var attr    = productAttributeList.Where(x => x.Name == attrVal).FirstOrDefault();
                            if (attr == null)
                            {
                                productAttributeList.Add(new ExportProductAttribute()
                                {
                                    Name   = attrVal,
                                    NameRu = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                    NameDe = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                    NameEs = workSheet.GetValue <string>(i, 4).TrimEnd()
                                });
                                currentProductAttribute = new ExportProductAttribute()
                                {
                                    Name   = attrVal,
                                    NameRu = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                    NameDe = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                    NameEs = workSheet.GetValue <string>(i, 4).TrimEnd()
                                };
                            }
                            else
                            {
                                currentProductAttribute = attr;
                            }
                        }

                        if (workSheet.Cells[i, 1].Style.Font.Size == 10 && !workSheet.Cells[i, 1].Style.Font.Bold)
                        {
                            currentAttributesValueList.List.Add(new ExportProductAttributeValue()
                            {
                                AttributeTitle = currentProductAttribute.Name,
                                Title          = workSheet.GetValue <string>(i, 1).TrimEnd(),
                                TitleRu        = workSheet.GetValue <string>(i, 2).TrimEnd(),
                                TitleDe        = workSheet.GetValue <string>(i, 3).TrimEnd(),
                                TitleEs        = workSheet.GetValue <string>(i, 4).TrimEnd(),
                            });
                        }
                    }
                }

                var resetCategoryList = categoryList.Where(x => categoryList.Where(c => x.CategoryId == c.ParentCategoryId).FirstOrDefault() != null);
                foreach (var cats in resetCategoryList)
                {
                    cats.AttributeValueListId = 0;
                }
            }

            UpdateDb(categoryList, productAttributeValueLists, productAttributeList);
            _downloadService.DeleteDownload(download);
        }
Esempio n. 8
0
 /// <summary>
 /// Deletes a download
 /// </summary>
 /// <param name="download">Download</param>
 public void DeleteDownload([FromBody] Download download)
 {
     _downloadService.DeleteDownload(download);
 }
Esempio n. 9
0
        public override void Uninstall()
        {
            //Delete all attached files before removing Submission table from DB
            List <SubmissionRecord> records = _submissionReop.Table.ToList();

            foreach (var item in records)
            {
                if (String.IsNullOrEmpty(item.DownloadLink) == false)
                {
                    int startIndex = item.DownloadLink.IndexOf("downloadId=");
                    int length     = "downloadId=".Length;

                    string downloadGuid = item.DownloadLink.Substring(startIndex + length);

                    var download = _downloadService.GetDownloadByGuid(new Guid(downloadGuid));
                    _downloadService.DeleteDownload(download);
                }
            }

            _context.Uninstall();

            _commonSettings.DeleteSetting <SubmissionAdminSettings>();

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.MenuTitle");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.FullNameLabel");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.FullNameLabel.Hint");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.FullNameRequired");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.FullNameTooLong");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EmailLabel");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EmailLabel.Hint");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EmailRequired");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EmailFormat");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.SubjectLabel");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.SubjectLabel.Hint");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.SubjectRequired");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.SubjectTooLong");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EnquiryPlaceholder");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EnquiryLabel");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EnquiryLabel.Hint");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EnquiryRequired");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.EnquiryTooLong");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.PhoneLabel");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.PhoneLabel.Hint");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.PhoneTooLong");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.SubmissionHeader");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.SubmissionSettings");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.SubmissionFilter");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.MaxFileSize");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.AllowedFiletypes");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Save");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.FullName");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Subject");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Phone");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Enquiry");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Type");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.DownloadLink");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Attachment");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.JobApplication");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.PartnerOffer");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.VendorOffer");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Other");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.NewEntry.Title");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.NewEntry.AttachFileHint");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.NewEntry.Send");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Error.MaxSizeExeeded");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Error.InvalidFiletype");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Info.SubmissionSucceeded");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Error.InvalidMaxSizeNum");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Error.NonpositiveMaxFileSize");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.Error.InvalidFiletype");

            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.EnquiryEmailSubscriber");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.JobApplicationEmailSubscriber");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.ParnterOfferEmailSubscriber");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.VendorOfferEmailSubscriber");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.OtherEmailSubscriber");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.IvnalidSuscriberEmail");
            this.DeletePluginLocaleResource("Plugins.Zingasoft.Submission.Admin.EmailNotificationIntro");

            base.Uninstall();
        }