protected void btnSign_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        switch (SigningMode)
        {
        case SignMode.AdHoc:
            try
            {
                string szSigB64     = hdnSigData.Value.Substring(szDataURLPrefix.Length);
                byte[] rgbSignature = Convert.FromBase64CharArray(szSigB64.ToCharArray(), 0, szSigB64.Length);

                if (rgbSignature.Length > 10000)     // this may not be compressed (e.g., from Android) - compress it.
                {
                    using (Stream st = new MemoryStream(rgbSignature))
                    {
                        using (Stream stDst = new MemoryStream())
                        {
                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(st))
                            {
                                image.Save(stDst, System.Drawing.Imaging.ImageFormat.Png);
                                rgbSignature   = new byte[stDst.Length];
                                stDst.Position = 0;
                                stDst.Read(rgbSignature, 0, (int)stDst.Length);
                            }
                        }
                    }
                }

                Flight.SignFlightAdHoc(txtCFIName.Text, txtCFIEmail.Text, txtCFICertificate.Text, dropDateCFIExpiration.Date, txtComments.Text, rgbSignature);
            }
            catch (MyFlightbookException ex)
            {
                lblErr.Text = ex.Message;
                return;
            }
            break;

        case SignMode.Authenticated:
            try
            {
                string szError = String.Empty;

                bool needProfileRefresh = !CFIProfile.CanSignFlights(out szError);
                if (needProfileRefresh)
                {
                    CFIProfile.Certificate           = txtCFICertificate.Text;
                    CFIProfile.CertificateExpiration = dropDateCFIExpiration.Date;
                }

                // Do ANOTHER check to see if you can sign - setting these above may have fixed the problem.
                if (!CFIProfile.CanSignFlights(out szError))
                {
                    lblErr.Text = szError;
                    return;
                }

                // If we are here, then we were successful - update the profile if it needed it
                if (needProfileRefresh)
                {
                    CFIProfile.FCommit();
                }

                // Prepare for signing
                Flight.SignFlight(CFIProfile.UserName, txtComments.Text);

                Response.Cookies[szKeyCookieCopy].Value   = ckCopyFlight.Checked.ToString();
                Response.Cookies[szKeyCookieCopy].Expires = DateTime.Now.AddYears(10);

                // Copy the flight to the CFI's logbook if needed.
                // We modify a new copy of the flight; this avoids modifying this.Flight, but ensures we get every property
                if (ckCopyFlight.Checked)
                {
                    CopyToInstructor(Flight.Clone());
                }
            }
            catch (MyFlightbookException ex)
            {
                lblErr.Text = ex.Message;
                return;
            }
            catch (MyFlightbookValidationException ex)
            {
                lblErr.Text = ex.Message;
                return;
            }
            break;
        }

        if (SigningFinished != null)
        {
            SigningFinished(sender, e);
        }
    }
示例#2
0
    protected void btnSign_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        switch (SigningMode)
        {
        case SignMode.AdHoc:
        {
            byte[] rgSig = mfbScribbleSignature.Base64Data();
            if (rgSig != null)
            {
                Flight.SignFlightAdHoc(txtCFIName.Text, txtCFIEmail.Text, txtCFICertificate.Text, dropDateCFIExpiration.Date, txtComments.Text, rgSig);
            }
            else
            {
                return;
            }
        }
        break;

        case SignMode.Authenticated:
            try
            {
                string szError = String.Empty;

                bool needProfileRefresh = !CFIProfile.CanSignFlights(out szError);
                if (needProfileRefresh)
                {
                    CFIProfile.Certificate           = txtCFICertificate.Text;
                    CFIProfile.CertificateExpiration = dropDateCFIExpiration.Date;
                }

                // Do ANOTHER check to see if you can sign - setting these above may have fixed the problem.
                if (!CFIProfile.CanSignFlights(out szError))
                {
                    lblErr.Text = szError;
                    return;
                }

                // If we are here, then we were successful - update the profile if it needed it
                if (needProfileRefresh)
                {
                    CFIProfile.FCommit();
                }

                // Prepare for signing
                Flight.SignFlight(CFIProfile.UserName, txtComments.Text);

                Response.Cookies[szKeyCookieCopy].Value   = ckCopyFlight.Checked.ToString();
                Response.Cookies[szKeyCookieCopy].Expires = DateTime.Now.AddYears(10);

                // Copy the flight to the CFI's logbook if needed.
                // We modify a new copy of the flight; this avoids modifying this.Flight, but ensures we get every property
                if (ckCopyFlight.Checked)
                {
                    CopyToInstructor(Flight.Clone());
                }
            }
            catch (MyFlightbookException ex)
            {
                lblErr.Text = ex.Message;
                return;
            }
            catch (MyFlightbookValidationException ex)
            {
                lblErr.Text = ex.Message;
                return;
            }
            break;
        }

        if (SigningFinished != null)
        {
            SigningFinished(sender, e);
        }
    }
        protected bool SignFlight()
        {
            if (!Page.IsValid)
            {
                return(false);
            }

            try
            {
                bool fIsGroundOrATP = ckATP.Checked || Flight.IsGroundOnly;

                switch (SigningMode)
                {
                case SignMode.AdHoc:
                {
                    byte[] rgSig = mfbScribbleSignature.Base64Data();
                    if (rgSig != null)
                    {
                        Flight.SignFlightAdHoc(txtCFIName.Text, txtCFIEmail.Text, txtCFICertificate.Text, dropDateCFIExpiration.Date, SigningComments, rgSig, ckSignSICEndorsement.Checked || fIsGroundOrATP);
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;

                case SignMode.Authenticated:
                    string szError = String.Empty;

                    bool needProfileRefresh = !CFIProfile.CanSignFlights(out szError, Flight.IsGroundOnly);
                    if (needProfileRefresh)
                    {
                        CFIProfile.Certificate           = txtCFICertificate.Text;
                        CFIProfile.CertificateExpiration = dropDateCFIExpiration.Date;
                    }

                    // Do ANOTHER check to see if you can sign - setting these above may have fixed the problem.
                    if (!CFIProfile.CanSignFlights(out szError, fIsGroundOrATP))
                    {
                        lblErr.Text = szError;
                        return(false);
                    }

                    // If we are here, then we were successful - update the profile if it needed it
                    if (needProfileRefresh)
                    {
                        CFIProfile.FCommit();
                    }

                    // Prepare for signing
                    Flight.SignFlightAuthenticated(CFIProfile.UserName, SigningComments, fIsGroundOrATP);

                    // Copy the flight to the CFI's logbook if needed.
                    // We modify a new copy of the flight; this avoids modifying this.Flight, but ensures we get every property
                    if (ckCopyFlight.Checked)
                    {
                        // Issue #593 Load any telemetry, if necessary
                        LogbookEntry le = new LogbookEntry(Flight.FlightID, Flight.User, LogbookEntryCore.LoadTelemetryOption.LoadAll);
                        Flight.FlightData = le.FlightData;
                        Flight.CopyToInstructor(CFIProfile.UserName, SigningComments);
                    }

                    Response.Cookies[szKeyCookieCopy].Value   = ckCopyFlight.Checked.ToString(CultureInfo.InvariantCulture);
                    Response.Cookies[szKeyCookieCopy].Expires = DateTime.Now.AddYears(10);
                    break;
                }
            }
            catch (MyFlightbookException ex)
            {
                lblErr.Text = ex.Message;
                return(false);
            }
            catch (MyFlightbookValidationException ex)
            {
                lblErr.Text = ex.Message;
                return(false);
            }

            return(true);
        }