public override JToken ToJToken(ApiVersion version, ResultFormat format) { var obj = new JObject(); obj["usageType"] = UsageType.ToString(); if (Display != null) { obj["dispay"] = Display.ToJToken(version, format); } if (Description != null) { obj["description"] = Description.ToJToken(version, format); } obj["contentType"] = ContentType; obj["length"] = Length; obj["sha2"] = SHA2; if (FileUrl != null) { obj["fileUrl"] = FileUrl.ToString(); } return(obj); }
public override int SimilarityScore(PostBase post) { var otherPost = (DanbooruPost)post; int similarityScore = 0; if (FileUrl.Contains(".gif") || FileUrl.Contains(".webm") || FileUrl.Contains(".mp4")) { return(-1000000); } List <string> thisTags = new List <string>(TagStringGeneral.Split(' ').Where(w => w != "#tagme" && w != "" && w != "#solo")); List <string> postTags = new List <string>(otherPost.TagStringGeneral.Split(' ').Where(w => w != "#tagme" && w != "" && w != "#solo")); var generalIntersect = thisTags.Intersect(postTags); thisTags = new List <string>(TagStringCharacter.Split(' ')); postTags = new List <string>(otherPost.TagStringCharacter.Split(' ')); var characterIntersect = thisTags.Intersect(postTags); thisTags = new List <string>(TagStringCopyright.Split(' ')); postTags = new List <string>(otherPost.TagStringCopyright.Split(' ')); var copyrightIntersect = thisTags.Intersect(postTags); thisTags = new List <string>(TagStringArtist.Split(' ')); postTags = new List <string>(otherPost.TagStringArtist.Split(' ')); var artistIntersect = thisTags.Intersect(postTags); similarityScore += generalIntersect.Count(); similarityScore += characterIntersect.Count() * 10; similarityScore += generalIntersect.Count() * 100; similarityScore += generalIntersect.Count() * 1000; return(similarityScore); }
public override int SimilarityScore(PostBase post) { var otherPost = (YanderePost)post; int similarityScore = 0; if (FileUrl.Contains(".gif") || FileUrl.Contains(".webm")) { return(-10); } List <string> thisTags = new List <string>(GetTags().Split(' ').Where(w => w != "#tagme" && w != "")); List <string> postTags = new List <string>(otherPost.GetTags().Split(' ').Where(w => w != "#tagme" && w != "")); similarityScore += thisTags.Intersect(postTags).Count(); if (GetPostAuthor().Equals(otherPost.GetPostAuthor())) { similarityScore += 10; } if (ParentId != null && otherPost.ParentId != null) { if (ParentId.Equals(otherPost.ParentId)) { similarityScore += 10; } } return(similarityScore); }
void ImageBtnDelete_Click(object sender, ImageClickEventArgs e) { if (!string.IsNullOrEmpty(FileUrl) && !string.IsNullOrEmpty(ContainerName)) { //Trim Url down to filename int lastSlash = FileUrl.LastIndexOf("/") + 1; string fileName = FileUrl.Substring(lastSlash); //Delete file from container here Factory factory = new Factory(Options.Username, Options.ApiKey); factory.DeleteItemFromContainer(ContainerName, fileName); //TODO Need to trigger Save() for datatype to remove saved data from property //NOTE Maybe set the ID from datatype to this control, load Content object and set property-alias-value to string.empty. But where does the alias come from? if (Data != null) { //Clear the current datatypes property Property property = new Property(Data.PropertyId) { Value = string.Empty }; //Clear file from controls properties FileUrl = string.Empty; FileUrlField.Text = string.Empty; } } }
public async Task <IActionResult> SavePhotos(SavePhotoViewModel SavePhoto, int BurialId) { // save iploaded photo yeet if (ModelState.IsValid) { Burial burial_to_add = _context.Burials.Where(b => b.BurialID == BurialId).FirstOrDefault(); string url = await _s3storage.AddItem(SavePhoto.PhotoFile, burial_to_add.DisplayBurialLocation(), SavePhoto.Type); FileUrl FileRecord = new FileUrl(_context) { Url = url, Type = SavePhoto.Type, Burial = burial_to_add, BurialID = burial_to_add.BurialID }; _context.Add(FileRecord); _context.SaveChanges(); return(Redirect("/Research/AddSite")); } else { return(View("UploadPhotos")); } }
private void _downFile(Uri uri) { var file = new FileUrl(uri); FileList.Add(file); file.DownFileAsync(); }
public FileUrl Create(FileUrl item) { db.Create(item); var items = GetAll().ToList(); return(items[0]); }
public override int GetHashCode() { if (FileUrl == null) { return(0); } return(FileUrl.GetHashCode()); }
internal static void ShowHelpFAQ() { string browserPath = FileUrl.GetDefaultBrowserPath(); if (!string.IsNullOrEmpty(browserPath)) { Process.Start(browserPath, "https://github.com/Hofknecht/SystemTrayMenu#FAQ"); } }
public void Create(FileUrl item) { var parameters = new List <SqlParameter> { db.CreateParameter("@Url", item.Url, DbType.String), }; db.Insert("CreateFileUrl", CommandType.StoredProcedure, parameters.ToArray()); }
public void Update(FileUrl item) { var parameters = new List <SqlParameter> { db.CreateParameter("@Id", item.Id, DbType.Int32), db.CreateParameter("@Url", item.Url, DbType.String) }; db.Update("UpdateFileUrl", CommandType.StoredProcedure, parameters.ToArray()); }
private bool SetUrl() { bool handled = false; string iconFile = string.Empty; try { FileIni file = new FileIni(TargetFilePath); iconFile = file.Value("IconFile", string.Empty); if (string.IsNullOrEmpty(iconFile)) { string browserPath = FileUrl.GetDefaultBrowserPath(); if (string.IsNullOrEmpty(browserPath)) { Log.Info($"Resolve *.URL '{TargetFilePath}'" + $"No default browser found!"); } else { Icon = IconReader.GetFileIconWithCache(browserPath, false); diposeIcon = false; handled = true; } } else if (System.IO.File.Exists(iconFile)) { Icon = Icon.ExtractAssociatedIcon(iconFile); handled = true; } else { Log.Info($"Resolve *.URL '{TargetFilePath}' has no icon"); } } catch (Exception ex) { if (ex is SecurityException || ex is ArgumentException || ex is UnauthorizedAccessException || ex is PathTooLongException || ex is NotSupportedException) { Log.Warn($"path:'{TargetFilePath}', " + $"iconFile:'{iconFile}'", ex); } else { throw; } } SetText($"{FileInfo.Name.Substring(0, FileInfo.Name.Length - 4)}"); return(handled); }
public IActionResult Put(int id, [FromBody] FileUrl model) { if (model == null || model.Id != id) { return(BadRequest()); } db.FileUrls.Update(model); return(Ok(model)); }
public async Task <IActionResult> Upload([FromForm] CreateFileModel model) { if (model == null) { return(BadRequest()); } var uploads = Path.Combine(hostingEnvironment.ContentRootPath, "uploads"); if (!Directory.Exists(uploads)) { Directory.CreateDirectory(uploads); } if (model.File.Length > 0) { var filePath = Path.Combine(uploads, model.File.FileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await model.File.CopyToAsync(fileStream); } } var file = new Common.Entity.FileService.File(); file.DownloadDate = DateTime.Now; file.FileAccessId = Convert.ToInt32(model.AccessId); file.CategoryId = Convert.ToInt32(model.CategoryId); file.Description = model.Description; file.Name = model.File.FileName; file.Size = model.File.Length; var fileUrl = new FileUrl(); fileUrl.Url = uploads; var newFileUrl = db.FileUrls.Create(fileUrl); if (newFileUrl == null) { return(BadRequest()); } file.UserId = 1; file.FileUrlId = newFileUrl.Id; FileCard newFile = db.Files.Create(file); if (newFile == null) { return(BadRequest()); } return(Ok(newFile)); }
// save file url public bool SaveFileUrl(FileUrl fileUrl) { int rowsAffected = projectGateway.UploadFileUrl(fileUrl); if (rowsAffected > 0) { return(true); } else { return(false); } }
private bool CanViewCommand(object aObject) { if (FileUrl == null) { string manufactureNumberTemp = manufactureNumber.TrimEnd(); string rmanufactureNumberTemp = ""; if (!String.IsNullOrEmpty(rmanufactureNumber)) { rmanufactureNumberTemp = rmanufactureNumber.TrimEnd(); } FileUrl = (CustomUri.GetAbsoluteUrl(String.IsNullOrEmpty(rmanufactureNumber) ? manufactureNumberTemp : rmanufactureNumberTemp) + "/" + fileName); } if (FileUrl != null) { int lastDot = FileUrl.LastIndexOf("."); if (lastDot <= 0) { return(false); } String lExt = FileUrl.Substring(lastDot, FileUrl.Length - lastDot).ToLower(); if (lExt == ".pdf" || lExt == ".doc" || lExt == ".docx" || lExt == ".xls" || lExt == ".xlsx" || lExt == ".jpeg" || lExt == ".jpg" || lExt == ".png" || lExt == ".bmp" || lExt == ".tiff" || lExt == ".tif" || lExt == ".gif") { DateTime lToday = DateTime.Now; if (lToday.Year == fileUpdateTime.Value.Year && lToday.Month == fileUpdateTime.Value.Month && lToday.Day == fileUpdateTime.Value.Day) { return(false); } return(true); } else { return(false); } } else { return(false); } }
public IActionResult Get(int id) { if (id < 0) { return(BadRequest()); } FileUrl item = db.FileUrls.GetItemById(id); if (item == null) { return(NotFound()); } return(Ok(item)); }
public IEnumerable <FileUrl> GetAll() { var fileUrlDataTable = db.GetDataTable("GetFileUrls", CommandType.StoredProcedure); var fileUrls = new List <FileUrl>(); foreach (DataRow row in fileUrlDataTable.Rows) { var fileUrl = new FileUrl { Id = Convert.ToInt32(row["Id"]), Url = row["Url"].ToString() }; fileUrls.Add(fileUrl); } return(fileUrls); }
public IActionResult Post(FileUrl model) { if (model == null) { return(BadRequest()); } FileUrl item = db.FileUrls.Create(model); if (item == null) { return(BadRequest()); } return(Ok(item)); }
private bool CanViewCommand(object aObject) { if (FileUrl == null) { FileUrl = CustomUri.GetAbsoluteUrl("PlanOutline/" + fileName); } if (FileUrl != null) { int lastDot = FileUrl.LastIndexOf("."); String lExt = FileUrl.Substring(lastDot, FileUrl.Length - lastDot).ToLower(); if (lExt == ".pdf" || lExt == ".doc" || lExt == ".docx" || lExt == ".xls" || lExt == ".xlsx" || lExt == ".jpeg" || lExt == ".png" || lExt == ".bmp" || lExt == ".tiff" || lExt == ".gif") { DateTime lToday = DateTime.Now; if (lToday.Year == fileUploadTime.Year && lToday.Month == fileUploadTime.Month && lToday.Day == fileUploadTime.Day) { return(false); } return(true); } else { return(false); } } else { return(false); } }
public FileUrl GetItemById(int id) { var parameters = new List <SqlParameter> { db.CreateParameter("@Id", id, DbType.Int32) }; var fileUrlDataTable = db.GetDataTable("GetFileUrlById", CommandType.StoredProcedure, parameters.ToArray()); var fileUrls = new List <FileUrl>(); foreach (DataRow row in fileUrlDataTable.Rows) { var fileUrl = new FileUrl { Id = Convert.ToInt32(row["Id"]), Url = row["Url"].ToString() }; fileUrls.Add(fileUrl); } return(fileUrls[0]); }
private string PopulateWithMetaData() { if (string.IsNullOrEmpty(ContainerName) || string.IsNullOrEmpty(FileUrlField.Text)) { return(string.Empty); } //Trim Url down to filename int lastSlash = FileUrl.LastIndexOf("/") + 1; string fileName = FileUrl.Substring(lastSlash); Factory factory = new Factory(Options.Username, Options.ApiKey); var cloudFile = factory.GetStorageItemInformation(ContainerName, fileName); StringBuilder sb = new StringBuilder(); sb.Append("</span>"); sb.Append("</div>"); //close propertyItemContent sb.Append("</div>"); //close propertyItem sb.Append("<div class=\"propertyItem\">"); sb.Append("<div class=\"propertyItemheader\">Content Type</div>"); sb.Append("<div class=\"propertyItemContent\">"); sb.Append(cloudFile.ContentType); sb.Append("</div>"); //close propertyItemContent sb.Append("</div>"); //close propertyItem sb.Append("<div class=\"propertyItem\">"); sb.Append("<div class=\"propertyItemheader\">Content Length</div>"); sb.Append("<div class=\"propertyItemContent\">"); sb.Append(cloudFile.ContentLength); sb.Append("</div>"); //close propertyItemContent sb.Append("</div>"); //close propertyItem sb.Append("<div><div><span>"); return(sb.ToString()); }
public ActionResult AddProject(ProjectDetail projectDetails, List <HttpPostedFileBase> files) { if (CheckAuthProjectManager() == 0) { ViewBag.ErrorMessage = "Log in first"; return(RedirectToAction("LogIn", "UserAuthentication")); } else if (CheckAuthProjectManager() == 1) { User user = userManager.GetUserById(Convert.ToInt32(Session["UserId"])); ViewBag.UserName = user.Name; if (ModelState.IsValid) { DateTime date1 = DateTime.Parse(projectDetails.StartDate); DateTime date2 = DateTime.Parse(projectDetails.EndDate); if (date2 <= date1) { ViewBag.Response = "Invalid Start and End Date"; return(View(projectDetails)); } else { if (files[0] != null) { projectDetails.ActionBy = Convert.ToInt32(Session["UserId"]); projectDetails.ActionDone = ActionUtility.ActionInsert; projectDetails.ActionTime = DateTime.Now.ToString(); projectDetails.ProjectCode = Guid.NewGuid().ToString(); int projectId = projectManager.SaveProject(projectDetails); if (projectId > 0) { foreach (HttpPostedFileBase file in files) { FileUrl fileUrl = new FileUrl(); fileUrl.ProjectId = projectId; fileUrl.FileName = file.FileName; fileUrl.FileLocation = "~/Files/" + projectDetails.ProjectCode + "_" + file.FileName; fileUrl.ActionBy = Convert.ToInt32(Session["UserId"]); fileUrl.ActionDone = ActionUtility.ActionInsert; fileUrl.ActionTime = DateTime.Now.ToString(); bool fileUrlSaved = projectManager.SaveFileUrl(fileUrl); if (fileUrlSaved) { var path = Path.Combine(Server.MapPath("~/Files/"), projectDetails.ProjectCode + "_" + file.FileName); file.SaveAs(path); count++; } else { count = 0; } } if (count == files.Count()) { ViewBag.Response = "Project Files Uploaded Successfully"; ModelState.Clear(); return(View()); } else { ViewBag.Response = "Project Files Upload Failed"; return(View(projectDetails)); } } else { ViewBag.Response = "Failed to Upload Project"; return(View(projectDetails)); } } else { ViewBag.Response = "Browse files"; return(View(projectDetails)); } } } else { ViewBag.Response = "Fill up all fields correctly"; return(View(projectDetails)); } } else { return(HttpNotFound()); } }
public int CompareTo(ImageCacherObject other) { return(FileUrl.CompareTo(other.FileUrl)); }
public void Update(FileUrl item) { db.Update(item); }
/// <summary> /// Saves the edit model. /// </summary> public bool SaveAll(bool draft) { var context = HttpContext.Current; var hasfile = UploadedFile != null || ServerFile != null; byte[] data = null; WebClient web = new WebClient(); // Check if the original URL has been updated, and if so if (!Content.IsNew && !String.IsNullOrEmpty(Content.OriginalUrl)) { var old = Content.GetSingle(Content.Id); if (old != null) { if (Content.OriginalUrl != old.OriginalUrl) { FileUrl = Content.OriginalUrl; } } } // Download file from web if (!hasfile && !String.IsNullOrEmpty(FileUrl)) { data = web.DownloadData(FileUrl); Content.OriginalUrl = FileUrl; Content.LastSynced = Convert.ToDateTime(web.ResponseHeaders[HttpResponseHeader.LastModified]); } var media = new MediaFileContent(); if (hasfile) { if (UploadedFile != null) { media.Filename = UploadedFile.FileName; media.ContentType = UploadedFile.ContentType; using (var reader = new BinaryReader(UploadedFile.InputStream)) { media.Body = reader.ReadBytes(Convert.ToInt32(UploadedFile.InputStream.Length)); } } else { media.Filename = ServerFile.Name; media.ContentType = MimeType.Get(ServerFile.Name); using (var stream = ServerFile.OpenRead()) { media.Body = new byte[ServerFile.Length]; stream.Read(media.Body, 0, media.Body.Length); } } } else if (data != null) { media.Filename = FileUrl.Substring(FileUrl.LastIndexOf('/') + 1); media.ContentType = web.ResponseHeaders["Content-Type"]; media.Body = data; } else { media = null; } var saved = false; if (!Content.IsFolder) { // Only save permalinks for non-folders var filename = !String.IsNullOrEmpty(Content.Filename) ? Content.Filename : (!String.IsNullOrEmpty(media.Filename) ? media.Filename : ""); if (Permalink.IsNew && String.IsNullOrEmpty(Permalink.Name)) { Permalink.Name = Permalink.Generate(!Content.IsFolder ? filename : Content.Name, Models.Permalink.PermalinkType.MEDIA); } try { Permalink.Save(); } catch (DuplicatePermalinkException) { if (Permalink.IsNew) { Permalink.Name = Content.Id + Permalink.Name.Substring(Permalink.Name.LastIndexOf('.')); Permalink.Save(); } else { throw; } } } else { Content.PermalinkId = Guid.Empty; } if (draft) { saved = Content.Save(media); } else { saved = Content.SaveAndPublish(media); } if (saved) { // Save related information Relation.DeleteByDataId(Content.Id); List <Relation> relations = new List <Relation>(); ContentCategories.ForEach(c => relations.Add(new Relation() { DataId = Content.Id, RelatedId = c, IsDraft = false, Type = Relation.RelationType.CONTENTCATEGORY }) ); relations.ForEach(r => r.Save()); // Save extensions foreach (var ext in Extensions) { // Call OnSave ext.Body.OnManagerSave(Content); ext.ParentId = Content.Id; ext.Save(); if (!draft) { if (Extension.GetScalar("SELECT COUNT(extension_id) FROM extension WHERE extension_id=@0 AND extension_draft=0", ext.Id) == 0) { ext.IsNew = true; } ext.IsDraft = false; ext.Save(); } } // Reset file url FileUrl = ""; return(true); } return(false); }
// save project url on FileUrl public int UploadFileUrl(FileUrl fileUrl) { Context.FileUrls.Add(fileUrl); return(Context.SaveChanges()); }
// update file url public int UpdateFileUrl(FileUrl fileUrl) { Context.FileUrls.AddOrUpdate(fileUrl); return(Context.SaveChanges()); }
public override int GetHashCode() { return(FileUrl?.GetHashCode() ?? 0); }
public ActionResult UpdateProjectDetail(ProjectDetail projectDetail, int selectedFile, HttpPostedFileBase file) { if (CheckAuthProjectManager() == 0) { ViewBag.ErrorMessage = "Log in first"; return(RedirectToAction("LogIn", "UserAuthentication")); } else if (CheckAuthProjectManager() == 1) { User user = userManager.GetUserById(Convert.ToInt32(Session["UserId"])); ViewBag.UserName = user.Name; if (projectManager.IsProjectExistsById(projectDetail.Id)) { if (ModelState.IsValid) { DateTime date1 = DateTime.Parse(projectDetail.StartDate); DateTime date2 = DateTime.Parse(projectDetail.EndDate); if (date2 <= date1) { ViewBag.Response = "Invalid Start and End Date"; ProjectDetail projectDetailModel = projectManager.GetProjectDetailsById(projectDetail.Id); ViewBag.Files = projectManager.GetProjectFilesForDropDown(projectDetail.Id); return(View(projectDetailModel)); } else { if (file != null && selectedFile != 0) { projectDetail.ActionBy = Convert.ToInt32(Session["UserId"]); projectDetail.ActionDone = ActionUtility.ActionUpdate; projectDetail.ActionTime = DateTime.Now.ToString(); int updateDetailsCheck = projectManager.UpdateProjectDetails(projectDetail); FileUrl fileUrl = projectManager.GetProjectFilesByFileUrlId(selectedFile); fileUrl.FileName = file.FileName; fileUrl.FileLocation = "~/Files/" + projectDetail.ProjectCode + "_" + file.FileName; fileUrl.ActionBy = Convert.ToInt32(Session["UserId"]); fileUrl.ActionDone = ActionUtility.ActionUpdate; fileUrl.ActionTime = DateTime.Now.ToString(); bool updateFileUrl = projectManager.UpdateFileUrl(fileUrl); if (updateFileUrl && updateDetailsCheck == 1) { var path = Path.Combine(Server.MapPath("~/Files/"), projectDetail.ProjectCode + "_" + file.FileName); file.SaveAs(path); ViewBag.Response = "Successfully Updated"; } else if (updateFileUrl && updateDetailsCheck == 2) { var path = Path.Combine(Server.MapPath("~/Files/"), projectDetail.ProjectCode + "_" + file.FileName); file.SaveAs(path); ViewBag.Response = "Successfully Updated File but Details remains same"; } else if (!updateFileUrl && updateDetailsCheck == 1) { ViewBag.Response = "Failed Updated File but Details Updated Successfully"; } else if (updateFileUrl && updateDetailsCheck == 0) { var path = Path.Combine(Server.MapPath("~/Files/"), projectDetail.ProjectCode + "_" + file.FileName); file.SaveAs(path); ViewBag.Response = "Success to Update files but failed to update details"; } else { ViewBag.Response = "Not Updated any thing"; } ProjectDetail projectDetailModel = projectManager.GetProjectDetailsById(projectDetail.Id); ViewBag.Files = projectManager.GetProjectFilesForDropDown(projectDetail.Id); return(View(projectDetailModel)); } else { projectDetail.ActionBy = Convert.ToInt32(Session["UserId"]); projectDetail.ActionDone = ActionUtility.ActionUpdate; projectDetail.ActionTime = DateTime.Now.ToString(); int updateDetailsCheck = projectManager.UpdateProjectDetails(projectDetail); if (updateDetailsCheck == 2) { ViewBag.Response = "Remaining Same"; } else if (updateDetailsCheck == 1) { ViewBag.Response = "Details information Updated without files"; } else { ViewBag.Response = "Failed to Update"; } ProjectDetail projectDetailModel = projectManager.GetProjectDetailsById(projectDetail.Id); ViewBag.Files = projectManager.GetProjectFilesForDropDown(projectDetail.Id); return(View(projectDetailModel)); } } } else { ViewBag.Response = "Fill up all fields correctly"; ProjectDetail projectDetailModel = projectManager.GetProjectDetailsById(projectDetail.Id); ViewBag.Files = projectManager.GetProjectFilesForDropDown(projectDetail.Id); return(View(projectDetailModel)); } } else { return(HttpNotFound()); } } else { return(HttpNotFound()); } }