Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Load Form variables into NameValueCollection variable.
            NameValueCollection coll = Request.Form;

            // Get names of all forms into a string array.
            string title = null;
            string css   = null;
            Bitmap logo  = null;

            if ((string)coll.Get("skipTheme") == "false")
            {
                title = coll.Get("generatedTitle");
                css   = coll.Get("generatedCss");
                logo  = (Bitmap)Page.Session["TE_currentLogo"];


                if (title.Trim() == "")
                {
                    title = null;
                }
                if (css.Trim() == "")
                {
                    css = null;
                }
            }
            Response.Expires = -1; //required to keep the page from being cached on the client's browser
            Response.Clear();
            Response.ContentType = "text/plain";


            IWorkflowThemeReference wf = (IWorkflowThemeReference)Page.Session["WFE_CurrentWorkflow"];

            Security.IToken tok = (Security.IToken)Session["Token"];

            // Check if the user is authed
            if (tok == null)
            {
                Page.Session["CurrentTheme"] = (Theme) new Theme(title, logo, css);
                Response.Write("{\"status\":NO_TOKEN}");
            } // Check if wf is null
            else if (wf == null)
            {
                Page.Session["CurrentTheme"] = (Theme) new Theme(title, logo, css);
                Response.Write("{\"status\":NO_WF}");
            }
            else
            {
                try
                {
                    // Trying to save the Theme. title, logo and css are not required.
                    // If passed null the system will use defaults
                    Security.SetThemeResult opResult = wf.SetTheme(new Theme(title, logo, css));
                    // Retrive the result status
                    SetThemeResult.Result status = opResult.getStatus();

                    Response.Write("{\"status\":\"" + status.ToString() + "\"}");
                    Page.Session["CurrentTheme"] = null;
                }
                catch (Exception ex)
                {
                    Response.Write("{\"status\":ERROR_EXCEPTION, errorContent:" + ex.ToString() + "}");
                }
            }


            Response.End();
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["deleteImg"] != null)
            {
                Response.Expires = -1; //required to keep the page from being cached on the client's browser
                Response.Clear();
                Response.ContentType           = "text/plain";
                Page.Session["TE_currentLogo"] = null;
                Response.Write("");
                Response.End();
            }
            else
            {
                string script = string.Empty;
                Bitmap img    = null;


                // Taking the uploaded files
                HttpFileCollection uploads = Request.Files;



                if (uploads.Count > 0 && uploads[0] != null && uploads[0].ContentLength > 0)
                {
                    try
                    {
                        img = new Bitmap(uploads[0].InputStream);
                    }
                    catch (ArgumentException)
                    {
                        script = string.Format(SCRIPT_TEMPLATE, "The uploaded file is not a valid image file.", "false");
                    }
                }

                else
                {
                    script = string.Format(SCRIPT_TEMPLATE, "Please specify a valid file.", "false");
                }

                if (string.IsNullOrEmpty(script))
                {
                    //Uploaded file is valid, now we can do whatever we like to do, copying it file system,
                    //saving it in db etc.

                    //Your Logic goes here

                    int  newHeight = img.Height;
                    int  newWidth  = img.Width;
                    bool resize    = false;


                    img = (Bitmap)FixedSize(img, MAX_WIDTH, MAX_HEIGHT);

                    /*
                     * if (img.Height > MAX_HEIGHT )
                     * {
                     *     resize = true;
                     *     newHeight = MAX_HEIGHT;
                     * }
                     *
                     * if (img.Width > MAX_WIDTH)
                     * {
                     *     resize = true;
                     *     newWidth = MAX_WIDTH;
                     * }
                     */
                    if (resize)
                    {
                        img = (Bitmap)img.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), System.IntPtr.Zero);
                    }



                    Security.IToken tok = (Security.IToken)Session["Token"];
                    if (tok == null)
                    {
                        script = string.Format(SCRIPT_TEMPLATE, "You need to be authed to edit the Theme", "false");
                    }
                    else
                    {
                        try
                        {
                            Page.Session["TE_currentLogo"] = img;

                            script = string.Format(SCRIPT_TEMPLATE, "drawLogo.aspx", "true");
                        }
                        catch (Exception ex)
                        {
                            script = string.Format(SCRIPT_TEMPLATE, ex.Message.ToString(), "false");
                        }
                    }

                    if (string.IsNullOrEmpty(script))
                    {
                        Page.Session["TE_currentLogo"] = img;
                        script = string.Format(SCRIPT_TEMPLATE, "drawLogo.aspx", "true");
                    }
                }

                //Sleeping for 2 seconds, fake delay, You should not it try at home.
                //System.Threading.Thread.Sleep(2 * 1000);

                ClientScript.RegisterStartupScript(this.GetType(), "uploadNotify", script);
            }
        }