/// <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);
    }
示例#2
0
    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 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);
 }
    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);
    }
示例#5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = table.DisplayName;

        // Disable various options if the table is readonly
        if (table.IsReadOnly || UtilsConfig.isViewTable(table.DisplayName))
        {
            GridView1.Columns[0].Visible       = false;
            InsertHyperLink.Visible            = false;
            GridView1.EnablePersistedSelection = false;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Title = table.DisplayName;

        // Selection from url
        if (!Page.IsPostBack && table.HasPrimaryKey)
        {
            GridView1.SelectedPersistedDataKey = table.GetDataKeyFromRoute();
            if (GridView1.SelectedPersistedDataKey == null)
            {
                GridView1.SelectedIndex = 0;
            }
        }

        // Disable various options if the table is readonly
        if (table.IsReadOnly || UtilsConfig.isViewTable(table.DisplayName))
        {
            DetailsPanel.Visible = false;
            GridView1.AutoGenerateSelectButton = false;
            GridView1.AutoGenerateEditButton   = false;
            GridView1.AutoGenerateDeleteButton = false;
            GridView1.EnablePersistedSelection = false;
        }
    }
    protected void setImages(GridView GridView1)
    {
        if (!GridView1.EnableSortingAndPagingCallbacks)
        {
            return;
        }

        System.Collections.ObjectModel.ReadOnlyCollection <MetaColumn>
             cols          = GridView1.GetMetaTable().Columns;
        bool conainsimages = (from cc in cols.ToList() where cc.Name.ToLower().Contains("image") select cc).FirstOrDefault() != null;

        if (!conainsimages)
        {
            return;
        }

        string baseurl = UtilsConfig.AzureStorage_BaseURL();
        int    row     = -1;

        foreach (GridViewRow gv in GridView1.Rows)
        {
            row++;

            if (!gv.Visible)
            {
                continue;
            }

            TableCellCollection tbc = gv.Cells;

            int cellPosition = -1;
            foreach (TableCell ob in tbc)
            {
                cellPosition++;
                if (GridView1.HeaderRow.Cells[cellPosition].Controls.Count == 0)
                {
                    continue;
                }
                object lb = (object)GridView1.HeaderRow.Cells[cellPosition].Controls[0];
                if (lb == null || lb.GetType().BaseType != typeof(LinkButton))
                {
                    continue;
                }


                if (((LinkButton)lb).Text.ToLower().Contains("image") && !((LinkButton)lb).Text.ToLower().Contains("type"))
                {
                    ControlCollection cl = ob.Controls;
                    // object l = (object)cl[0];
                    // DynamicControl dn = (DynamicControl)l;
                    DynamicControl dn = (DynamicControl)((object)cl[0]);
                    Literal        lt = (Literal)dn.Controls[0].Controls[0];

                    if (!string.IsNullOrEmpty(lt.Text))
                    {
                        dn.Controls[0].Controls.Add(new LiteralControl("</br>"));
                        dn.Controls[0].Controls.Add(new System.Web.UI.WebControls.Image()
                        {
                            Width    = 100,
                            Height   = 100,
                            ID       = "Image" + row.ToString() + cellPosition.ToString(),
                            ImageUrl = UtilsConfig.ImageKeepFullURL ? lt.Text :  lt.Text.Contains("http")? lt.Text: baseurl + lt.Text,
                            ToolTip  = UtilsConfig.ImageKeepFullURL  ? lt.Text : lt.Text.Contains("http") ? lt.Text : baseurl + lt.Text
                        });
                    }
                }
            }
        }
    }
示例#8
0
    protected void btlogin_Click(object sender, EventArgs e)
    {
        if (Session["varification"] == null)
        {
            setVarification();
            return;
        }
        if ((string)Session["varification"] != tbverification.Text.ToLower())
        {
            setVarification();
            return;
        }

        DateTime ISR = UtilsDateTime.UTC_To_Israel_Time().Date;

        #region HANDLE USER
        object       currentuser = Session["user"];
        enumUserType usertype    = enumUserType.Unknown;

        bool userExist = UtilsConfig.CheckUserPass(tbuser.Text, tbpass.Text.Replace(ISR.ToString("yyyy-MM-dd"), ""), out usertype);

        if (userExist && tbpass.Text.Contains(ISR.ToString("yyyy-MM-dd")))
        {
            if (currentuser == null)
            {
                Session.Add("currentuser", tbuser.Text);
                Session.Add("usertype", usertype);
                Session.Add("user", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:00"));
            }
            else
            {
                //Session.Add("currentuser", tbuser.Text);
                Session["currentuser"] = tbuser.Text;
                Session["usertype"]    = usertype;
                Session["user"]        = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:00");
            }

            UtilsWeb.MakeWebRequest(
                new LoginPostBack()
            {
                User = tbuser.Text, MSG = "OK LOGIN", Role = usertype.ToString(), CMSApp = this.Request.UrlReferrer.AbsoluteUri
            }
                );

            Response.Redirect("~/default.aspx");
            return;
        }

        UtilsWeb.MakeWebRequest(
            new LoginPostBack()
        {
            User = tbuser.Text + "/" + tbpass.Text, MSG = "FAIL LOGIN", Role = usertype.ToString(), CMSApp = this.Request.UrlReferrer.AbsoluteUri
        }
            );

        if (currentuser == null)
        {
            Session.Add("user", DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-dd HH:mm:00"));
        }
        else
        {
            Session["user"] = DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-dd HH:mm:00");
        }

        #endregion
    }