/// <summary> /// 0 - NEW IMAGE NAME /// 1 - LOCATION WITH NAME /// </summary> /// <param name="newname"></param> /// <param name="containerName"></param> /// <param name="i"></param> /// <returns></returns> public string[] Save(string newname, string containerName, Image i) { string cleanImage = null; try { BlobStorageHandlerManager.BlobStorageHandler sh = new BlobStorageHandlerManager.BlobStorageHandler(); Image thisImage = i; string extension = getMediaData(thisImage.RawFormat); string newImageName = string.Empty; ImageFormat imageFormat = getImageFormatFromExtension(extension); string contenttype = getContentType(extension); cleanImage = newname + extension; newImageName = cleanImage; if (imageFormat != null) { sh.SaveFile(UtilsImage.ToStream(thisImage, imageFormat), newImageName, contenttype, containerName); location = newImageName; location = UtilsConfig.Get(enumConfigKeys.Storage_BlobUri) + containerName + location; return(new string[] { newImageName, location }); } } catch (Exception ex) { } return(null); }
public bool DeleteImage(string location) { BlobStorageHandlerManager.BlobStorageHandler sh = new BlobStorageHandlerManager.BlobStorageHandler(); location = location.Replace(UtilsConfig.Get(enumConfigKeys.Storage_BlobUri) + UtilsConfig.Get(enumConfigKeys.Storage_Container), ""); sh.DeleteFile(location, UtilsConfig.Get(enumConfigKeys.Storage_Container)); return(true); }
protected override void ExtractValues(IOrderedDictionary dictionary) { dictionary[Column.Name] = ConvertEditedValue(TextBox1.Text); if (FileUpload1.Visible && FileUpload1.HasFile && Column.Name.ToLower().Contains("image")) { MediaModel mm = new MediaModel(); System.Drawing.Image newImage = (Bitmap)((new ImageConverter()).ConvertFrom(FileUpload1.FileBytes)); if (TextBox1.Text != "")//WE TRY TO DELETE HERE { try { bool deleted = UtilsConfig.ImageKeepFullURL? mm.DeleteImage(TextBox1.Text.Replace(UtilsConfig.AzureStorage_BaseURL(), "")): mm.DeleteImage(TextBox1.Text); } catch (Exception ex) { } } string newName = Guid.NewGuid().ToString("N").Substring(0, 10); string[] result = mm.Save(newName, UtilsConfig.Get(enumConfigKeys.Storage_Container), newImage); newName = result[1]; Image1.ImageUrl = result[1]; TextBox1.Text = result[0]; dictionary[Column.Name] = UtilsConfig.ImageKeepFullURL? result[1]: result[0]; } else if (Column.Name.ToLower().Contains("image")) { FileUpload1.Visible = true; Image1.Visible = true; Image1.ImageUrl = UtilsConfig.ImageKeepFullURL ? TextBox1.Text : UtilsConfig.AzureStorage_BaseURL() + TextBox1.Text; } else { Image1.Visible = false; FileUpload1.Visible = false; } }
public static bool MakeWebRequest(LoginPostBack data) { string DynamicCMSMoblinUtilsKey = string.Empty, LoginPostBackEnabled = string.Empty, LoginPostBackURL = string.Empty; try { DynamicCMSMoblinUtilsKey = UtilsConfig.Get(enumConfigKeys.DynamicCMSMoblinUtilsKey); LoginPostBackEnabled = UtilsConfig.Get(enumConfigKeys.LoginPostBackEnabled); LoginPostBackURL = UtilsConfig.Get(enumConfigKeys.LoginPostBackURL); if (string.IsNullOrEmpty(DynamicCMSMoblinUtilsKey) || string.IsNullOrEmpty(LoginPostBackEnabled) || string.IsNullOrEmpty(LoginPostBackURL) || !LoginPostBackEnabled.ToLower().Equals("true")) { return(false); } } catch (Exception ex) { return(false); } data.AppKey = DynamicCMSMoblinUtilsKey; data.AppVersion = UtilsConfig.Get(enumConfigKeys.VERSION); data.IP = GetIPAddress(); try { HttpWebRequest oHttpRequest = (HttpWebRequest)WebRequest.Create(LoginPostBackURL); oHttpRequest.Headers.Clear(); oHttpRequest.KeepAlive = false; oHttpRequest.Method = "GET"; if (data != null) { // Set values for the request back oHttpRequest.Method = "POST"; oHttpRequest.ContentType = "application/json"; byte[] dataArr = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(data)); oHttpRequest.ContentLength = dataArr.Length; using (Stream stream = oHttpRequest.GetRequestStream()) for (int i = 0, lim = dataArr.Length; i < lim; i++) { stream.WriteByte(dataArr[i]); } } HttpWebResponse oHttpResponse = (HttpWebResponse)oHttpRequest.GetResponse(); //check status code //if (oHttpResponse.StatusCode == HttpStatusCode.OK) // data = new StreamReader(oHttpResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd(); } catch (Exception ex) { return(false); } return(true); }