public void UploadEvent(object sender, MobileEventArgs args)
        {
            DateTime tokenTime = getTimeFromToken(args.token);
            int rmbNo = getRmbNoFromToken(args.token);
            if (tokenTime.AddMinutes(EXPIRE_MINUTES) <= DateTime.Now)
            {
                _view.Expire();
                int RID = _rmbs.Where(a => a.RMBNo==rmbNo).SingleOrDefault().RID;
                LogThis(RID, 0, "Attempt to upload receipt with expired token: "+args.token + " to rmb #"+getRmbNoFromToken(args.token)+", line #"+getLineNoFromToken(args.token)+", time: "+getTimeFromToken(args.token).ToShortTimeString());
                return;
            }
            int lineNo = getLineNoFromToken(args.token);

            AP_Staff_Rmb rmb = null;
            AP_Staff_RmbLine line = null;
            try {
                rmb = _rmbs.Where(a => a.SpareField4==args.token).Single();
                if (rmb.RMBNo != rmbNo) throw new Exception();
                line = _lines.Where(a => a.RmbLineNo == lineNo && a.RmbNo == rmbNo).Single();
            }
            catch { }
            try // Upload
            {
                // initialize folder/permissions
                int recnum;
                try { recnum = _images.Where(a => a.RmbLineNo == lineNo && a.RMBNo == rmbNo).Select(a => a.RecNum).Max() + 1; }
                catch
                {
                    // The above will fail for new lines.  This statement should catch those
                    try { recnum = _images.Where(a => a.RmbLineNo == null && a.RMBNo == rmbNo).Select(a => a.RecNum).Max() + 1; }
                    catch { recnum = 1; }
                }
                IFileInfo file;
                string strUrl = "";
                if (_testing)
                {
                    file = new DotNetNuke.Services.FileSystem.FileInfo() { FileId = -1 };
                }
                else
                {
                    PortalSettings PS = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
                    Filesystem.ensureFolderExists(PS.PortalId);
                    IFolderInfo imageFolder = Filesystem.getImageFolder(rmb.UserId, PS.PortalId);
                    Filesystem.checkFolderPermissions(PS.PortalId, imageFolder, rmb.UserId, null);  //no approvers list sent because it is an async function
                    string filename = "R" + rmbNo.ToString()+"L"+(lineNo<0?"New":lineNo.ToString()) + "Rec" + recnum.ToString() + ".png";
                    // save file to DNN database
                    string base64Data = Regex.Match(_view.ImageData, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
                    byte[] image_data = Convert.FromBase64String(base64Data);
                    //byte[] image_data = _view.ImageFile;
                    //_view.ImageUrl= "data:image/png;base64," + Convert.ToBase64String(image_data);
                    if (image_data == null || image_data.Length == 0) return;
                    MemoryStream image_stream = resizeImage(image_data);
                    file = FileManager.Instance.AddFile(imageFolder, filename, image_stream, false); //true is for overwrite
                    string URL = FileManager.Instance.GetUrl(file);
                    string strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
                    strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, URL);
                }
                // link file to image
                AP_Staff_RmbLine_File image = new AP_Staff_RmbLine_File() { RMBNo = rmbNo, RecNum = recnum, FileId = file.FileId };
                if (lineNo >= 0) image.RmbLineNo = lineNo; //A null RmbLineNo indicates that the line hasn't been saved yet
                image.URL = strUrl;
                StaffRmbDataContext d = new StaffRmbDataContext();
                d.AP_Staff_RmbLine_Files.InsertOnSubmit(image);
                d.SubmitChanges();
                LogThis(rmb.RID, 2, "Receipt image uploaded via mobile page");
                _view.Message = "Image uploaded.";
            }
            catch (Exception ex)
            {
                LogThis(rmb.RID, 4, "Error saving receipt image via mobile page " + ex.Message + ex.StackTrace);
                _view.Message = "Image Upload Failed";
            }
        }
 protected void Upload(object sender, EventArgs e)
 {
     fuCamera.Visible = false; //prevent autolaunching
     pnlShutter.Visible = false; //prevent re-clicking
     imgPreview.ImageUrl = image_data.Value;
     MobileEventArgs args = new MobileEventArgs() { token = StaffRmbFunctions.urlDecode(this.Page.Request.QueryString["id"]) };
     try { if (UploadEvent != null) UploadEvent(this, args); }
     catch { Message = "Upload Failed with token:" + StaffRmbFunctions.urlDecode(this.Page.Request.QueryString["id"]); }
 }
 public void InitializeEvent(object sender, MobileEventArgs args)
 {
     AP_Staff_Rmb rmb = null;
     try {
         rmb = _rmbs.Where(a => a.SpareField4 == args.token).Single();
         _view.RID = rmb.RID.ToString("D5");
     }
     catch
     {
         _view.RID = "unknown";
         _view.Message = "The correct Reimbursement could not be found.";
         LogThis(-1, 0, "Rmb with token:" + args.token + "(rmb #"+getRmbNoFromToken(args.token)+") was not located");
         return;
     }
     DateTime expireTime = getTimeFromToken(args.token).AddMinutes(EXPIRE_MINUTES);
     _view.RemainingTime = (expireTime - DateTime.Now);
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.Page.IsPostBack)
     {
         MobileEventArgs args = new MobileEventArgs() { token = StaffRmbFunctions.urlDecode(this.Page.Request.QueryString["id"]) };
         try { if (InitializeEvent != null) InitializeEvent(this, args); }
         catch { Message = "Error displaying mobile page"; }
     }
     else
     {
         Message = hfMessage.Value;
         if (!string.IsNullOrEmpty(hfMessage.Value)) divOverlay.Style.Remove("display");
         pnlShutter.Visible = (hfShutterState.Value != "hidden");
     }
 }