/// <summary>
        /// Creates an image with the given text and font and returns a response object.
        /// Text will be all on one line and will not be wider than 800 pixels or higher than 150 pixels.
        /// Do not pass null for text. Passing null for font will result in a generic Sans Serif, 10pt font.
        /// </summary>
        public static EwfResponse CreateImageFromText(string text, Font font)
        {
            return(EwfResponse.Create(
                       TewlContrib.ContentTypes.Png,
                       new EwfResponseBodyCreator(
                           stream => {
                font = font ?? new Font(FontFamily.GenericSansSerif, 10);

                const int startingBitmapWidth = 800;
                const int startingBitmapHeight = 150;

                var b = new Bitmap(startingBitmapWidth, startingBitmapHeight);
                var g = Graphics.FromImage(b);
                g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
                g.Clear(Color.White);

                // Find the size of the text we're drawing
                var stringFormat = new StringFormat();
                stringFormat.SetMeasurableCharacterRanges(new[] { new CharacterRange(0, text.Length) });
                var textRegion = g.MeasureCharacterRanges(text, font, new Rectangle(0, 0, startingBitmapWidth, startingBitmapHeight), stringFormat).Single();

                // Draw the text, crop our image to size, make transparent and save to stream.
                g.DrawString(text, font, Brushes.Black, new PointF());
                var finalImage = b.Clone(textRegion.GetBounds(g), b.PixelFormat);
                finalImage.MakeTransparent(Color.White);
                finalImage.Save(stream, ImageFormat.Png);
            })));
        }
示例#2
0
 protected override EwfSafeRequestHandler getOrHead() =>
 new EwfSafeResponseWriter(
     EwfResponse.CreateFromAspNetResponse(
         aspNetResponse => ExternalFunctionalityStatics.ExternalSamlProvider.WriteLogInResponse(
             aspNetResponse,
             identityProvider.EntityId,
             identityProvider == AuthenticationStatics.GetUserLastIdentityProvider(),
             ReturnUrl)));
示例#3
0
        protected override void loadData()
        {
            var pb =
                PostBack.CreateFull(
                    actionGetter:
                    () =>
                    new PostBackAction(
                        new SecondaryResponse(
                            () =>
                            EwfResponse.Create(
                                ContentTypes.ApplicationZip,
                                new EwfResponseBodyCreator(createAndZipSystem),
                                fileNameCreator: () => "{0}.zip".FormatWith(systemShortName.Value)))));

            FormState.ExecuteWithDataModificationsAndDefaultAction(
                pb.ToCollection(),
                () => {
                ph.AddControlsReturnThis(
                    FormItemBlock.CreateFormItemTable(
                        formItems: new[]
                {
                    FormItem.Create(
                        "System name",
                        new EwfTextBox(""),
                        validationGetter: control => new EwfValidation(
                            (pbv, validator) => {
                        systemName.Value = validator.GetString(
                            new ValidationErrorHandler("system name"),
                            control.GetPostBackValue(pbv),
                            false,
                            50);
                        if (systemName.Value != systemName.Value.RemoveNonAlphanumericCharacters(preserveWhiteSpace: true))
                        {
                            validator.NoteErrorAndAddMessage("The system name must consist of only alphanumeric characters and white space.");
                        }
                        systemShortName.Value = systemName.Value.EnglishToPascal();
                    })),
                    FormItem.Create(
                        "Base namespace",
                        new EwfTextBox(""),
                        validationGetter: control => new EwfValidation(
                            (pbv, validator) => {
                        baseNamespace.Value = validator.GetString(
                            new ValidationErrorHandler("base namespace"),
                            control.GetPostBackValue(pbv),
                            false,
                            50);
                        if (baseNamespace.Value != EwlStatics.GetCSharpIdentifier(baseNamespace.Value))
                        {
                            validator.NoteErrorAndAddMessage("The base namespace must be a valid C# identifier.");
                        }
                    }))
                }));
            });

            EwfUiStatics.SetContentFootActions(new ActionButtonSetup("Create System", new PostBackButton(pb)));
        }
 protected override EwfSafeRequestHandler getOrHead() =>
 new EwfSafeResponseWriter(
     EwfResponse.Create(
         "application/samlmetadata+xml",
         new EwfResponseBodyCreator(
             ( Stream stream ) => {
     using (var writer = XmlWriter.Create(stream, new XmlWriterSettings {
         Indent = true
     }))
         ExternalFunctionalityStatics.ExternalSamlProvider.GetMetadata().OwnerDocument.Save(writer);
 })));
示例#5
0
        protected override void loadData()
        {
            FormState.ExecuteWithDataModificationsAndDefaultAction(
                PostBack.CreateFull(
                    actionGetter: () => new PostBackAction(
                        new PageReloadBehavior(
                            secondaryResponse: new SecondaryResponse(
                                () => EwfResponse.Create(
                                    ContentTypes.ApplicationZip,
                                    new EwfResponseBodyCreator(createAndZipSystem),
                                    fileNameCreator: () => "{0}.zip".FormatWith(systemShortName.Value))))))
                .ToCollection(),
                () => {
                ph.AddControlsReturnThis(
                    FormItemList.CreateStack(
                        items: new[]
                {
                    systemName.ToTextControl(
                        false,
                        value: "",
                        maxLength: 50,
                        additionalValidationMethod: validator => {
                        if (systemName.Value != systemName.Value.RemoveNonAlphanumericCharacters(preserveWhiteSpace: true))
                        {
                            validator.NoteErrorAndAddMessage("The system name must consist of only alphanumeric characters and white space.");
                        }
                        systemShortName.Value = systemName.Value.EnglishToPascal();
                    })
                    .ToFormItem(label: "System name".ToComponents()),
                    baseNamespace.ToTextControl(
                        false,
                        value: "",
                        maxLength: 50,
                        additionalValidationMethod: validator => {
                        if (baseNamespace.Value != EwlStatics.GetCSharpIdentifier(baseNamespace.Value))
                        {
                            validator.NoteErrorAndAddMessage("The base namespace must be a valid C# identifier.");
                        }
                    })
                    .ToFormItem(label: "Base namespace".ToComponents())
                })
                    .ToCollection()
                    .GetControls());

                EwfUiStatics.SetContentFootActions(new ButtonSetup("Create System").ToCollection());
            });
        }
        protected override EwfResponse post()
        {
            var assertion = ExternalFunctionalityStatics.ExternalSamlProvider.ReadAssertion(HttpContext.Current.Request);

            var identityProvider =
                AuthenticationStatics.SamlIdentityProviders.Single(i => string.Equals(i.EntityId, assertion.identityProvider, StringComparison.Ordinal));
            User user;

            DataAccessState.Current.DisableCache();
            try {
                user = identityProvider.LogInUser(assertion.userName, assertion.attributes);
            }
            finally {
                DataAccessState.Current.ResetCache();
            }

            if (user != null)
            {
                AuthenticationStatics.SetFormsAuthCookieAndUser(user, identityProvider: identityProvider);
            }
            else
            {
                AuthenticationStatics.SetUserLastIdentityProvider(identityProvider);
            }

            try {
                AppRequestState.Instance.CommitDatabaseTransactionsAndExecuteNonTransactionalModificationMethods();
            }
            finally {
                DataAccessState.Current.ResetCache();
            }

            var destinationUrl = new VerifyClientFunctionality(assertion.returnUrl).GetUrl();

            HttpContext.Current.Response.StatusCode = 303;
            return(EwfResponse.Create(
                       ContentTypes.PlainText,
                       new EwfResponseBodyCreator(writer => writer.Write("See Other: {0}".FormatWith(destinationUrl))),
                       additionalHeaderFieldGetter: () => ("Location", destinationUrl).ToCollection()));
        }
示例#7
0
 /// <summary>
 /// Performs an EhModifyDataAndSendFile operation. This is convenient if you want to get the built-in export functionality, but from
 /// an external button rather than an action on this table.
 /// </summary>
 public PostBackAction ExportToExcel()
 {
     return(new PostBackAction(
                new SecondaryResponse(
                    () => EwfResponse.CreateExcelWorkbookResponse(
                        () => caption.Any() ? caption : "Excel export",
                        () => {
         var workbook = new ExcelFileWriter();
         foreach (var rowSetup in rowSetups)
         {
             if (rowSetup.IsHeader)
             {
                 workbook.DefaultWorksheet.AddHeaderToWorksheet(rowSetup.CsvLine.ToArray());
             }
             else
             {
                 workbook.DefaultWorksheet.AddRowToWorksheet(rowSetup.CsvLine.ToArray());
             }
         }
         return workbook;
     }))));
 }
 protected override EwfSafeRequestHandler getOrHead() =>
 new EwfSafeResponseWriter(
     () => EwfResponse.Create(ContentTypes.Xml, new EwfResponseBodyCreator(() => File.ReadAllText(FilePath))),
     EwlStatics.EwlBuildDateTime,
     () => "getSchema" + FileName);