// GET: Files/Details/5 public ActionResult Details(Guid?systemid) { if (systemid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Symbol symbol = _symbolService.GetSymbol(systemid.Value); if (symbol == null) { return(HttpNotFound()); } ViewBag.HasAccess = false; ViewBag.IsAdmin = false; if (Request.IsAuthenticated) { ViewBag.HasAccess = _authorizationService.HasAccess(symbol.Owner, ClaimsPrincipal.Current.GetOrganizationName()); ViewBag.IsAdmin = _authorizationService.IsAdmin(); } return(View(symbol)); }
public void UpdateSymbol(Models.Symbol originalSymbol, Models.Symbol symbol) { if (symbol != null) { originalSymbol.Name = symbol.Name; originalSymbol.Description = symbol.Description; originalSymbol.SymbolId = symbol.SymbolId; string owner = ClaimsPrincipal.Current.GetOrganizationName(); if (_authorizationService.IsAdmin() && !string.IsNullOrEmpty(symbol.Owner)) { owner = symbol.Owner; } originalSymbol.Owner = owner; originalSymbol.Source = symbol.Source; originalSymbol.SourceUrl = symbol.SourceUrl; var symbolPackages = originalSymbol.SymbolPackages; originalSymbol.SymbolPackages = symbol.SymbolPackages; originalSymbol.Theme = symbol.Theme; if (symbol.Thumbnail != null) { originalSymbol.Thumbnail = symbol.Thumbnail; } originalSymbol.LastEditedBy = ClaimsPrincipal.Current.GetUsername(); _dbContext.Entry(originalSymbol).State = EntityState.Modified; _dbContext.SaveChanges(); } }
// GET: Files/Edit/5 public ActionResult Edit(Guid?systemid) { if (systemid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Symbol symbol = _symbolService.GetSymbol(systemid.Value); if (symbol == null) { return(HttpNotFound()); } ViewBag.Themes = new SelectList(CodeList.Themes(), "Key", "Value", symbol.Theme); ViewBag.SymbolPackages = new MultiSelectList(_symbolService.GetPackagesWithAccessControl(), "SystemId", "Name", symbol.SymbolPackages.Select(c => c.SystemId).ToArray()); ViewBag.IsAdmin = false; if (Request.IsAuthenticated) { ViewBag.IsAdmin = _authorizationService.IsAdmin(); } return(View(symbol)); }
public ActionResult Create(Models.Symbol symbol, HttpPostedFileBase uploadFile, string[] packages) { ViewBag.Themes = new SelectList(CodeList.Themes(), "Key", "Value", symbol.Theme); ViewBag.SymbolPackages = new SelectList(_symbolService.GetPackagesWithAccessControl(), "SystemId", "Name"); symbol.SymbolPackages = new List <SymbolPackage>(); if (packages != null) { foreach (var package in packages) { symbol.SymbolPackages.Add(_symbolService.GetPackage(Guid.Parse(package))); } } ViewBag.IsAdmin = false; if (Request.IsAuthenticated) { ViewBag.IsAdmin = _authorizationService.IsAdmin(); } if (ModelState.IsValid) { ImageService img = new ImageService(); if (uploadFile != null) { symbol.Thumbnail = img.SaveThumbnail(uploadFile, symbol); } var addedSymbol = _symbolService.AddSymbol(symbol); return(RedirectToAction("Details", "Files", new { systemid = addedSymbol.SystemId })); } return(View(symbol)); }
public async Task <CandleResponse> getCandles(Models.Symbol symbol, string timeFrame) { var startDate = (Int32)DateTime.UtcNow.AddDays(-1).Subtract(new DateTime(1970, 1, 1)).TotalSeconds; var endDate = (Int32)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; return(await _api.Execute(new RestRequest($"/api/getChart?baseCurrencyType={symbol.BaseCurrency}¤cyType={symbol.QuoteCurrency}&stickType={timeFrame}&start={startDate}000&end={endDate}000", Method.GET))); }
public ActionResult DeleteConfirmed(Guid systemid) { Models.Symbol symbol = _symbolService.GetSymbol(systemid); bool hasAccess = _authorizationService.HasAccess(symbol.Owner, ClaimsPrincipal.Current.GetOrganizationName()); if (!hasAccess) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } _symbolService.RemoveSymbol(symbol); return(RedirectToAction("Index")); }
private void AddFile(SymbolFile symbolFile, Models.Symbol symbol, SymbolFileVariant variant, string filename, string format) { SymbolFile file = new SymbolFile(); file.SystemId = Guid.NewGuid(); file.Color = symbolFile.Color; file.Size = symbolFile.Size; file.Symbol = symbol; file.SymbolFileVariant = variant; file.Type = symbolFile.Type; file.FileName = filename; file.Format = format; _dbContext.SymbolFiles.Add(file); _dbContext.SaveChanges(); }
public async Task <Ticker> getTicker(Models.Symbol symbol) { var res = await _api.Execute(new RestRequest($"/api/getDetail", Method.GET)); var type = (Detail)res; var type2 = type.obj.Value <JObject>(symbol.BaseCurrency); var type3 = type2.Value <JObject>(symbol.QuoteCurrency); var t = new Ticker() { vol24 = type3.Value <float>("vol24") }; return(t); }
// GET: Files/Delete/5 public ActionResult Delete(Guid?systemid) { if (systemid == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Symbol symbol = _symbolService.GetSymbol(systemid.Value); if (symbol == null) { return(HttpNotFound()); } return(View(symbol)); }
private string GetVariantName(Models.Symbol symbol, SymbolFile symbolFile) { string variantName = symbol.Name; if (!string.IsNullOrEmpty(symbolFile.Type)) { variantName = variantName + " " + symbolFile.Type; } if (!string.IsNullOrEmpty(symbolFile.Color)) { variantName = variantName + " " + symbolFile.Color; } return(variantName); }
public ActionResult Edit(Models.Symbol symbol, HttpPostedFileBase uploadFile, string[] packages) { symbol.SymbolPackages = new List <SymbolPackage>(); if (packages != null) { foreach (var package in packages) { symbol.SymbolPackages.Add(_symbolService.GetPackage(Guid.Parse(package))); } } ImageService img = new ImageService(); if (uploadFile != null) { symbol.Thumbnail = img.SaveThumbnail(uploadFile, symbol); } Models.Symbol originalSymbol = _symbolService.GetSymbol(symbol.SystemId); ViewBag.IsAdmin = false; if (Request.IsAuthenticated) { ViewBag.IsAdmin = _authorizationService.IsAdmin(); } if (!_authorizationService.HasAccess(originalSymbol.Owner, ClaimsPrincipal.Current.GetOrganizationName())) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } if (ModelState.IsValid) { _symbolService.UpdateSymbol(originalSymbol, symbol); return(RedirectToAction("Index")); } ViewBag.Themes = new SelectList(CodeList.Themes(), "Key", "Value", symbol.Theme); ViewBag.SymbolPackages = new MultiSelectList(_symbolService.GetPackagesWithAccessControl(), "SystemId", "Name", symbol.SymbolPackages.Select(c => c.SystemId).ToArray()); return(View(symbol)); }
public Models.Symbol AddSymbol(Models.Symbol symbol) { string owner = ClaimsPrincipal.Current.GetOrganizationName(); if (_authorizationService.IsAdmin() && !string.IsNullOrEmpty(symbol.Owner)) { owner = symbol.Owner; } symbol.SystemId = Guid.NewGuid(); symbol.Owner = owner; symbol.LastEditedBy = ClaimsPrincipal.Current.GetUsername(); _dbContext.Symbols.Add(symbol); _dbContext.SaveChanges(); return(symbol); }
public string CreateFileName(Models.Symbol symbol, string ext, string targetFolder = null, Models.SymbolFile symbolFile = null, string width = null, bool useWidthInFilname = true) { if (string.IsNullOrEmpty(targetFolder)) { targetFolder = System.Web.HttpContext.Current.Server.MapPath("~/files"); } string filename; filename = MakeSeoFriendlyString(symbol.Name); if (symbolFile != null) { if (!string.IsNullOrEmpty(symbolFile.Type)) { filename = filename + "_" + MakeSeoFriendlyString(symbolFile.Type); } if (!string.IsNullOrEmpty(symbolFile.Color)) { filename = filename + "_" + MakeSeoFriendlyString(symbolFile.Color); } if (useWidthInFilname && !string.IsNullOrEmpty(width) && width != "0" && ext != ".pdf" && ext != ".ai") { filename = filename + "_" + MakeSeoFriendlyString(width); } } string additionalNumber = ""; for (int i = 1; ; i++) { if (!File.Exists(Path.Combine(targetFolder, filename + additionalNumber + ext))) { filename = filename + additionalNumber + ext; break; } additionalNumber = i.ToString(); } return(filename); }
public string SaveImage(HttpPostedFileBase file, Models.Symbol symbol, Models.SymbolFile symbolFile, int width = 0, bool useWidthInFilname = false) { string targetFolder = System.Web.HttpContext.Current.Server.MapPath("~/files"); if (!string.IsNullOrEmpty(symbol.SymbolPackages.FirstOrDefault()?.Folder)) { targetFolder = targetFolder + "\\" + symbol.SymbolPackages.FirstOrDefault().Folder; } var ext = Path.GetExtension(file.FileName); string fileName = CreateFileName(symbol, ext, targetFolder, symbolFile, width.ToString(), useWidthInFilname); string targetPath = Path.Combine(targetFolder, fileName); file.SaveAs(targetPath); return(fileName); }
public string ConvertToGif(string inputFileName, Models.Symbol symbol, string format, Models.SymbolFile symbolFile, int maxWidth = 0, bool useWidthInFilname = true) { string targetFolder = System.Web.HttpContext.Current.Server.MapPath("~/files"); if (!string.IsNullOrEmpty(symbol.SymbolPackages.FirstOrDefault()?.Folder)) { targetFolder = targetFolder + "\\" + symbol.SymbolPackages.FirstOrDefault().Folder; } var ext = "." + format; string fileName; MagickReadSettings readerSettings = new MagickReadSettings(); readerSettings.Height = 1500; readerSettings.Width = 1500; readerSettings.BackgroundColor = MagickColors.Transparent; using (MemoryStream memStream = new MemoryStream()) { using (MagickImage image = new MagickImage(targetFolder + "\\" + inputFileName, readerSettings)) { image.Format = MagickFormat.Gif; image.Settings.ColorType = ColorType.TrueColorAlpha; if (maxWidth > 0) { image.Resize(new MagickGeometry { IgnoreAspectRatio = false, Width = maxWidth, Height = 0 }); } fileName = CreateFileName(symbol, ext, targetFolder, symbolFile, image.Width.ToString(), useWidthInFilname); string targetPath = Path.Combine(targetFolder, fileName); image.Write(targetPath); } } return(fileName); }
public void RemoveSymbol(Models.Symbol symbol) { var symbolFiles = symbol.SymbolFiles.ToList(); foreach (var file in symbolFiles) { if (file.SymbolFileVariant != null) { _dbContext.SymbolFileVariants.Remove(file.SymbolFileVariant); _dbContext.SymbolFiles.Remove(file); } else { _dbContext.SymbolFiles.Remove(file); } _dbContext.SaveChanges(); DeleteFile(file.FileName, symbol.SymbolPackages.FirstOrDefault()?.Folder); } _dbContext.Symbols.Remove(symbol); _dbContext.SaveChanges(); DeleteThumbnailFile(symbol.Thumbnail, symbol.SymbolPackages.FirstOrDefault()?.Folder); }
public string ConvertImage(HttpPostedFileBase file, Models.Symbol symbol, string format, Models.SymbolFile symbolFile, int maxWidth = 0, bool useWidthInFilname = true) { string targetFolder = System.Web.HttpContext.Current.Server.MapPath("~/files"); if (!string.IsNullOrEmpty(symbol.SymbolPackages.FirstOrDefault()?.Folder)) { targetFolder = targetFolder + "\\" + symbol.SymbolPackages.FirstOrDefault().Folder; } var ext = "." + format; string fileName; MagickReadSettings readerSettings = new MagickReadSettings(); readerSettings.Height = 1500; readerSettings.Width = 1500; readerSettings.BackgroundColor = MagickColors.Transparent; if (file.ContentType.Equals("image/svg+xml")) { readerSettings.Format = MagickFormat.Svg; } using (MemoryStream memStream = new MemoryStream()) { file.InputStream.CopyTo(memStream); using (MagickImage image = new MagickImage(memStream, readerSettings)) { switch (format) { case "png": { image.Format = MagickFormat.Png32; break; } case "jpg": { image.Format = MagickFormat.Jpg; break; } case "gif": { image.Format = MagickFormat.Gif; image.Settings.ColorType = ColorType.TrueColorAlpha; break; } case "ai": { image.Format = MagickFormat.Ai; break; } case "svg": { image.Format = MagickFormat.Svg; break; } case "tiff": { image.Format = MagickFormat.Tif; image.CompressionMethod = CompressionMethod.Zip; break; } default: { image.Format = MagickFormat.Png; break; } } if (maxWidth > 0) { image.Resize(new MagickGeometry { IgnoreAspectRatio = false, Width = maxWidth, Height = 0 }); } fileName = CreateFileName(symbol, ext, targetFolder, symbolFile, image.Width.ToString(), useWidthInFilname); string targetPath = Path.Combine(targetFolder, fileName); image.Write(targetPath); } } return(fileName); }
private void DownloadFileButton_Click(object sender, System.EventArgs e) { System.Net.WebClient webClient = null; try { string id = "33603212156438463"; string remotePathName = $"{ RemoteDownloadUri }t=i&a=1&b=0&i={ id }"; // ************************************************** webClient = new System.Net.WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; byte[] result = webClient.DownloadData(address: remotePathName); byte[] decompressedResult = Infrastructure.Utility.DecompressGZip(result); contentTextBox.Text = System.Text.Encoding.UTF8.GetString(decompressedResult); // ************************************************** // ************************************************** string temp = contentTextBox.Text.Replace("\r", string.Empty); System.Collections.Generic.List <Models.Symbol> symbols = new System.Collections.Generic.List <Models.Symbol>(); string[] rows = contentTextBox.Text.Split('\n'); for (int index = 1; index <= rows.Length - 1; index++) { Models.Symbol symbol = new Models.Symbol(rows[index]); symbols.Add(symbol); } // ************************************************** myDataGridView.DataSource = symbols; } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { if (webClient != null) { webClient.Dispose(); //webClient = null; } } }
public ActionResult DownloadFile(int id) { string RemoteDownloadUri = ""; RemoteDownloadUri = "http://www.tsetmc.com/tsev2/data/Export-txt.aspx?"; // public System.Windows.Forms.WebBrowser MyWebBrowser { get; set; } WebClient webClient = null; try { string unicId = ""; string content = ""; SubCategories subCategories = new SubCategories(); using (ApplicationDbContext dbContext = new ApplicationDbContext()) { subCategories = dbContext.SubCategories.Find(id); } unicId = subCategories.UniqueID; string remotePathName = $"{ RemoteDownloadUri }t=i&a=1&b=0&i={ unicId }"; // ************************************************** webClient = new System.Net.WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; byte[] result = webClient.DownloadData(address: remotePathName); byte[] decompressedResult = Infrastructure.Utility.DecompressGZip(result); content = System.Text.Encoding.UTF8.GetString(decompressedResult); // ************************************************** // ************************************************** string temp = content.Replace("\r", string.Empty); System.Collections.Generic.List <Models.Symbol> symbols = new System.Collections.Generic.List <Models.Symbol>(); string[] rows = content.Split('\n'); for (int index = 1; index <= rows.Length - 1; index++) { Models.Symbol symbol = new Models.Symbol(rows[index]); symbol.SubCategoriesId = subCategories.Id; symbols.Add(symbol); } // model.Symbols = symbols; using (ApplicationDbContext dbContext = new ApplicationDbContext()) { dbContext.Symbols.AddRange(symbols); dbContext.SaveChanges(); } // ************************************************** // myDataGridView.DataSource = symbols; } catch (Exception ex) { throw; } finally { if (webClient != null) { webClient.Dispose(); webClient = null; } } return(RedirectToAction("Index", "SubCategories")); }
public ActionResult DownloadFile(DownloadFile model) { string RemoteDownloadUri = ""; RemoteDownloadUri = "http://www.tsetmc.com/tsev2/data/Export-txt.aspx?"; // public System.Windows.Forms.WebBrowser MyWebBrowser { get; set; } WebClient webClient = null; try { //string id = // "33603212156438463"; string id = "47302318535715632"; string remotePathName = $"{ RemoteDownloadUri }t=i&a=1&b=0&i={ id }"; // ************************************************** webClient = new System.Net.WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; byte[] result = webClient.DownloadData(address: remotePathName); byte[] decompressedResult = Infrastructure.Utility.DecompressGZip(result); model.Content = System.Text.Encoding.UTF8.GetString(decompressedResult); // ************************************************** // ************************************************** string temp = model.Content.Replace("\r", string.Empty); System.Collections.Generic.List <Models.Symbol> symbols = new System.Collections.Generic.List <Models.Symbol>(); string[] rows = model.Content.Split('\n'); for (int index = 1; index <= rows.Length - 1; index++) { Models.Symbol symbol = new Models.Symbol(rows[index]); symbols.Add(symbol); } model.Symbols = symbols; using (ApplicationDbContext dbContext = new ApplicationDbContext()) { dbContext.Symbols.AddRange(symbols); dbContext.SaveChanges(); } // ************************************************** // myDataGridView.DataSource = symbols; } catch (Exception ex) { throw; } finally { if (webClient != null) { webClient.Dispose(); //webClient = null; } } return(View(model)); }
public string SaveThumbnail(HttpPostedFileBase file, Models.Symbol symbol) { string targetFolder = System.Web.HttpContext.Current.Server.MapPath("~/files/thumbnail"); var ext = Path.GetExtension(file.FileName); string format = ext.Replace(".", ""); string fileName = CreateFileName(symbol, ext, targetFolder); if (format == "svg") { string targetPath = Path.Combine(targetFolder, fileName); file.SaveAs(targetPath); } else { MagickReadSettings readerSettings = new MagickReadSettings(); readerSettings.Height = 1500; readerSettings.Width = 1500; readerSettings.BackgroundColor = MagickColors.Transparent; if (file.ContentType.Equals("image/svg+xml")) { readerSettings.Format = MagickFormat.Svg; } using (MemoryStream memStream = new MemoryStream()) { file.InputStream.CopyTo(memStream); using (MagickImage image = new MagickImage(memStream, readerSettings)) { switch (format) { case "png": { image.Format = MagickFormat.Png32; break; } case "jpg": { image.Format = MagickFormat.Jpg; break; } case "gif": { image.Format = MagickFormat.Gif; image.Settings.ColorType = ColorType.TrueColorAlpha; break; } case "svg": { image.Format = MagickFormat.Svg; break; } default: { image.Format = MagickFormat.Png; break; } } image.Resize(new MagickGeometry { IgnoreAspectRatio = false, Width = 50, Height = 0 }); string targetPath = Path.Combine(targetFolder, fileName); image.Write(targetPath); } } } return(fileName); }