I need create XML comment for return value of method Login. This method returns object type
of Result. This object contains session id if login was successful and if login was unsuccessful contains error message.
I don’t know how decribe this in XML comment.
/// <summary>
/// Login to server
/// </summary>
/// <param name="name">Name of user</param>
/// <param name="password">User password</param>
/// <returns>
/// This method return object type of Result<Account>
/// If login was successful contains sessions
/// If login was unsuccessful contains error
/// </returns>
Result<Account> Login(string name, string password);
/// <summary>
/// Return value of method
/// </summary>
/// <typeparam name="T">Type of return value</typeparam>
public class Result<T>
{
/// <summary>
/// Return message
/// </summary>
public string ResultMessage { get; set; }
/// <summary>
/// Return value
/// </summary>
public T ReturnValue { get; set; }
}
public class Account
{
public string Name{get;set;}
public string Password {get;set;}
public string Session {get;set;
}
Thank you for advices.
You would use:
/// ...
/// This method returns an object of type <see cref="Result{Account}"/>.
/// ...
See cref Attribute.
This is the line that the error is showing on:
public IOAuth2ServiceProvider<IElance> ElanceServiceProvider { get; set; }
It's showing the error on the IElance Type on that line, but here's the interface:
public interface IElance : IApiBinding
{
/// <summary>
/// Search all jobs, list jobs associated with an employee or a freelancer, and retrieve information for a specific job.
/// </summary>
IJobOperations JobOperations { get; }
/// <summary>
/// Access all messages, users, messages, and Work View™ data associated with an Elance Workroom.
/// </summary>
IWorkRoomOperations WorkroomOperations { get; }
/// <summary>
/// View all of the information associated with an employee or a freelancer.
/// </summary>
IProfileOperations ProfileOperations { get; }
/// <summary>
/// View detailed information on freelancers, and retrieve a list of all freelancers employed by an employer.
/// </summary>
IFreelancerOperations FreelancerOperations { get; }
/// <summary>
/// List Elance groups, and retrieve lists of members and jobs belonging to a group.
/// </summary>
IGroupOperations GroupOperations { get; }
/// <summary>
/// Obtain ancillary Elance information, such as the current list of all job categories.
/// </summary>
IUtilityOperations UtilityOperations { get; }
}
I can't for the life of me figure out why it's telling me this. Am I missing something obvious? I would greatly appreciate any direction on this error.
This is probably caused by IApiBinding or one of its base interfaces not being public. Another possibility is that one of the types used by the interface members is not public.
I'm setting parameters for a report that I'm showing in ReportViewer control, and the parameters are setting properly and the report is running with the proper parameters, however the actual controls that provide the report criteria at the top of the ReportViewer are not selected. Why aren't the proper items selected in the criteria, even when the report is properly running with the criteria that I set?
ReportParameter month = new ReportParameter("month", "September 2011");
SsrsReportInfo reportInfo = new SsrsReportInfo("Summary", "http://server/ReportServer/", "/MyFolder/Summary", month);
this.reportViewer1.ServerReport.ReportPath = reportInfo.ReportPath;
this.reportViewer1.ServerReport.ReportServerUrl = new Uri(reportInfo.ReportServerUrl);
if (reportInfo.Parameters != null)
{
this.reportViewer1.ServerReport.SetParameters(reportInfo.Parameters);
}
this.reportViewer1.RefreshReport();
Here's the code for the reportInfo class:
/// <summary>
/// SSRS report information for report viewer.
/// </summary>
public class SsrsReportInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
/// </summary>
/// <param name="reportName">Name of the report.</param>
/// <param name="reportServerUrl">The report server URL.</param>
/// <param name="reportPath">The report path.</param>
public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath)
: this(reportName, reportServerUrl, reportPath, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
/// </summary>
/// <param name="reportName">Name of the report.</param>
/// <param name="reportServerUrl">The report server URL.</param>
/// <param name="reportPath">The report path.</param>
/// <param name="reportParameters">The report parameters.</param>
public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath, params ReportParameter[] reportParameters)
{
this.ReportName = reportName;
this.ReportServerUrl = reportServerUrl;
this.ReportPath = reportPath;
this.Parameters = reportParameters;
}
/// <summary>
/// Gets or sets the name of the report.
/// </summary>
/// <value>The name of the report.</value>
public string ReportName
{
get;
set;
}
/// <summary>
/// Gets or sets the report server URL.
/// </summary>
/// <value>The report server URL.</value>
public string ReportServerUrl
{
get;
set;
}
/// <summary>
/// Gets or sets the report path.
/// </summary>
/// <value>The report path.</value>
public string ReportPath
{
get;
set;
}
/// <summary>
/// Gets or sets the parameters.
/// </summary>
/// <value>The parameters.</value>
public ReportParameter[] Parameters
{
get;
set;
}
}
Thanks,
Mark
I've figured out the issue here. I had the code setting the path, url, parameters and refreshing the report within a Form constructor. I moved it into the Form.Load event and it works fine now. Reports still run properly, but now the parameters are properly set also within the criteria portion on the top of the ReportViewer.
I had the same usage shown here: http://technet.microsoft.com/es-es/library/aa337089(SQL.90).aspx, however noticed that they did it in the Form.Load event, and I tried that, and it worked. I could probably do it in the ReportViewer.Load event also, the reason for this is probably that the controls aren't drawn up on screen yet before setting the values.
Ello all,
In my custom activity, when I drop an activity into the WorkflowItemPresenter, save and compile, my activity suddenly disappears and I have no freakin clue why. I'm probably making some noob mistake somewhere but, I'm not seeing it. I've gone back and made sure my code complies fine and deleted and re-added my assembly containing the custom activity on the off chance it might just be a fluke. After which when I attempt to compile from the project referencing my custom activity. It runs but throws an ArgumentNullException. I've tried passing it bools, conditionals and just about anthing else it would take all ending with the same result. Any suggestions on troubleshooting ideas to try in this case or obvious stuff missing?
Here is my reference to my condition ActivityFunc <bool> Condition.
<sap:WorkflowItemPresenter
HintText="Add Trigger conditional activities here"
Item="{Binding Path=ModelItem.Condition.Handler}"
Height="40"
/>
Here is my reference to the child I want to schedule after the condition returns true public ActivityAction Child.
<sap:WorkflowItemPresenter
HintText="Add activies that happen on trigger firing"
Item="{Binding Path=ModelItem.Child.Handler}"
Height="40"/>
Here is my Custom activity
[Designer(typeof(TriggerDesigner)),
Description("Creates a Trigger for use by trigger conditionals"), ToolboxCategory(ToolboxCategoryAttribute.Trigger),
ToolboxBitmap(typeof(Shaolin.Activities.ToolboxIconAttribute), "ToolboxIcons.CreateImportContext")]
public sealed class Trigger : NativeActivity
{
/// <summary>
/// The initial Condition that determines if the trigger should be scheduled
/// </summary>
/// <value>The condition.</value>
public ActivityFunc<bool> Condition { get; set; }
/// <summary>
/// The resulting action that is scheduled if the Condition is true
/// </summary>
/// <value>The child.</value>
public ActivityAction Child { get; set; }
/// <summary>
/// Gets or sets the value holding whether or not the trigger matches the condition
/// </summary>
/// <value>The type of the match.</value>
public MatchType MatchType{ get; set; }
/// <summary>
/// Perform evaluation of Condition; if is true then schedules Child
/// </summary>
/// <param name="context">The execution context in which the activity executes.</param>
protected override void Execute(NativeActivityContext context)
{
context.ScheduleFunc<bool>(this.Condition, new CompletionCallback<bool>(OnConditionComplete));
}
/// <summary>
/// Called from Execute when Condition evaluates to true.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="instance">The instance.</param>
/// <param name="result">if set to <c>true</c> [result].</param>
public void OnConditionComplete(NativeActivityContext context, ActivityInstance instance, bool result)
{
//check if Condition evaluation returns true
if (result)
{
//If so then schedule child Activity
context.ScheduleAction(Child);
}
}
}
}
Hello person with the same IP as me.
ModelItem.Condition is null. Your binding fails, therefore, but with little fanfare which makes this situation hard to figure out.
You need to implement IActivityTemplateFactory and configure your activity in the Create method:
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
return new Trigger
{
DisplayName = "lol trigger",
Condition = new ActivityFunc<bool>(),
Child = new ActivityAction(),
MatchType = MatchType.Lol
};
}
What cool functionality and methods do you add to your ASP.net BasePage : System.Web.UI.Page classes?
Examples
Here's something I use for authentication, and I'd like to hear your opinions on this:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
// Authentication code omitted... Essentially same as below.
if (_RequiresAuthentication && !(IsAuthorized))
{
RespondForbidden("You do not have permissions to view this page.", UnauthorizedRedirect);
return;
}
}
// This function is overridden in each page subclass and fitted to each page's
// own authorization requirements.
// This also allows cascading authorization checks,
// e.g: User has permission to view page? No - base.IsAuthorized - Is user an admin?
protected virtual bool IsAuthorized
{
get { return true; }
}
My BasePage class contains an instance of this class:
public class StatusCodeResponse {
public StatusCodeResponse(HttpContext context) {
this._context = context;
}
/// <summary>
/// Responds with a specified status code, and if specified - transfers to a page.
/// </summary>
private void RespondStatusCode(HttpContext context, System.Net.HttpStatusCode status, string message, string transfer)
{
if (string.IsNullOrEmpty(transfer))
{
throw new HttpException((int)status, message);
}
context.Response.StatusCode = (int)status;
context.Response.StatusDescription = message;
context.Server.Transfer(transfer);
}
public void RespondForbidden(string message, string transfer)
{
RespondStatusCode(this._context, System.Net.HttpStatusCode.Forbidden, message, transfer);
}
// And a few more like these...
}
As a side note, this could be accomplished using extension methods for the HttpResponse object.
And another method I find quite handy for parsing querystring int arguments:
public bool ParseId(string field, out int result)
{
return (int.TryParse(Request.QueryString[field], out result) && result > 0);
}
Session related stuff, some complex object in the BasePage that maps to a session, and expose it as a property.
Doing stuff like filling a crumble pad object.
But most important: do not make your basepage into some helper class. Don't add stuff like ParseId(), that's just ridiculous.
Also, based on the first post: make stuff like IsAuthorized abstract. This way you don't create giant security holes if someone forgets that there is some virtual method.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace MySite
{
/// <summary>
/// Base class with properties for meta tags for content pages
/// http://www.codeproject.com/KB/aspnet/PageTags.aspx
/// http://weblogs.asp.net/scottgu/archive/2005/08/02/421405.aspx
/// </summary>
public partial class BasePage : System.Web.UI.Page
{
private string keywords;
private string description;
/// <SUMMARY>
/// Gets or sets the Meta Keywords tag for the page
/// </SUMMARY>
public string Meta_Keywords
{
get
{
return keywords;
}
set
{
// Strip out any excessive white-space, newlines and linefeeds
keywords = Regex.Replace(value, "\\s+", " ");
}
}
/// <SUMMARY>
/// Gets or sets the Meta Description tag for the page
/// </SUMMARY>
public string Meta_Description
{
get
{
return description;
}
set
{
// Strip out any excessive white-space, newlines and linefeeds
description = Regex.Replace(value, "\\s+", " ");
}
}
// Constructor
// Add an event handler to Init event for the control
// so we can execute code when a server control (page)
// that inherits from this base class is initialized.
public BasePage()
{
Init += new EventHandler(BasePage_Init);
}
// Whenever a page that uses this base class is initialized,
// add meta keywords and descriptions if available
void BasePage_Init(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(Meta_Keywords))
{
HtmlMeta tag = new HtmlMeta();
tag.Name = "keywords";
tag.Content = Meta_Keywords;
Header.Controls.Add(tag);
}
if (!String.IsNullOrEmpty(Meta_Description))
{
HtmlMeta tag = new HtmlMeta();
tag.Name = "description";
tag.Content = Meta_Description;
Header.Controls.Add(tag);
}
}
}
}
Along with the metadata already mentioned (mostly obsolete in ASP.NET 4.0 with the new Page.MetaDescription and Page.MetaKeywords properties), I've also had methods to add other header links to my page such as specific ones for adding page specific CSS, or things like cannonical links, RSS links, etc:
/// <overloads>
/// Adds a CSS link to the page. Useful when you don't have access to the
/// HeadContent ContentPlaceHolder. This method has 4 overloads.
/// </overloads>
/// <summary>
/// Adds a CSS link.
/// </summary>
/// <param name="pathToCss">The path to CSS file.</param>
public void AddCss(string pathToCss) {
AddCss(pathToCss, string.Empty);
}
/// <summary>
/// Adds a CSS link in a specific position.
/// </summary>
/// <param name="pathToCss">The path to CSS.</param>
/// <param name="position">The postion.</param>
public void AddCss(string pathToCss, int? position) {
AddCss(pathToCss, string.Empty, position);
}
/// <summary>
/// Adds a CSS link to the page with a specific media type.
/// </summary>
/// <param name="pathToCss">The path to CSS file.</param>
/// <param name="media">The media type this stylesheet relates to.</param>
public void AddCss(string pathToCss, string media) {
AddHeaderLink(pathToCss, "text/css", "Stylesheet", media, null);
}
/// <summary>
/// Adds a CSS link to the page with a specific media type in a specific
/// position.
/// </summary>
/// <param name="pathToCss">The path to CSS.</param>
/// <param name="media">The media.</param>
/// <param name="position">The postion.</param>
public void AddCss(string pathToCss, string media, int? position) {
AddHeaderLink(pathToCss, "text/css", "Stylesheet", media, position);
}
/// <overloads>
/// Adds a general header link. Useful when you don't have access to the
/// HeadContent ContentPlaceHolder. This method has 3 overloads.
/// </overloads>
/// <summary>
/// Adds a general header link.
/// </summary>
/// <param name="href">The path to the resource.</param>
/// <param name="type">The type of the resource.</param>
public void AddHeaderLink(string href, string type) {
AddHeaderLink(href, type, string.Empty, string.Empty, null);
}
/// <summary>
/// Adds a general header link.
/// </summary>
/// <param name="href">The path to the resource.</param>
/// <param name="type">The type of the resource.</param>
/// <param name="rel">The relation of the resource to the page.</param>
public void AddHeaderLink(string href, string type, string rel) {
AddHeaderLink(href, type, rel, string.Empty, null);
}
/// <summary>
/// Adds a general header link.
/// </summary>
/// <param name="href">The path to the resource.</param>
/// <param name="type">The type of the resource.</param>
/// <param name="rel">The relation of the resource to the page.</param>
/// <param name="media">The media target of the link.</param>
public void AddHeaderLink(string href, string type, string rel, string media)
{
AddHeaderLink(href, type, rel, media, null);
}
/// <summary>
/// Adds a general header link.
/// </summary>
/// <param name="href">The path to the resource.</param>
/// <param name="type">The type of the resource.</param>
/// <param name="rel">The relation of the resource to the page.</param>
/// <param name="media">The media target of the link.</param>
/// <param name="position">The postion in the control order - leave as null
/// to append to the end.</param>
public void AddHeaderLink(string href, string type, string rel, string media,
int? position) {
var link = new HtmlLink { Href = href };
if (0 != type.Length) {
link.Attributes.Add(HtmlTextWriterAttribute.Type.ToString().ToLower(),
type);
}
if (0 != rel.Length) {
link.Attributes.Add(HtmlTextWriterAttribute.Rel.ToString().ToLower(),
rel);
}
if (0 != media.Length) {
link.Attributes.Add("media", media);
}
if (null == position || -1 == position) {
Page.Header.Controls.Add(link);
}
else
{
Page.Header.Controls.AddAt((int)position, link);
}
}
Culture initialization by overriding InitializeCulture() method (set culture and ui culture from cookie or DB).
Some of my applications are brandable, then here I do some "branding" stuff too.
I use this methot and thanks for yours,
/// <summary>
/// Displays the alert.
/// </summary>
/// <param name="message">The message to display.</param>
protected virtual void DisplayAlert(string message)
{
ClientScript.RegisterStartupScript(
GetType(),
Guid.NewGuid().ToString(),
string.Format("alert('{0}');", message.Replace("'", #"\'")),
true
);
}
/// <summary>
/// Finds the control recursive.
/// </summary>
/// <param name="id">The id.</param>
/// <returns>control</returns>
protected virtual Control FindControlRecursive(string id)
{
return FindControlRecursive(id, this);
}
/// <summary>
/// Finds the control recursive.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="parent">The parent.</param>
/// <returns>control</returns>
protected virtual Control FindControlRecursive(string id, Control parent)
{
if (string.Compare(parent.ID, id, true) == 0)
return parent;
foreach (Control child in parent.Controls)
{
Control match = FindControlRecursive(id, child);
if (match != null)
return match;
}
return null;
}
Putting authorization code in a base page is generally not a good idea. The problem is, what happens if you forget to derive a page that needs authorization from the base page? You will have a security hole.
It's much better to use an HttpModule, so that you can intercept requests for all pages, and make sure users are authorized even before the HttpHandler has a chance to run.
Also, as others have said, and in keeping with OO principles, it's better to only have methods in your base page that actually relate to the Page itself. If they don't reference "this," they should probably be in a helper class -- or perhaps be extension methods.
I inherit from System.Web.UI.Page when I need certain properties and every page. This is good for aweb application that implements a login. In the membership pages I use my own base class to get access to Properties like UserID, UserName etc. These properties wrap Session Variables
Here are some examples (sans code) that I use a custom base class for:
Adding a page filter (e.g. replace "{theme}" with "~/App_Theme/[currentTheme]"),
Adding a Property and handling for Auto Titling pages based upon Site Map,
Registering specialized logging (could probably be redone via different means),
Adding methods for generalized input(Form/Querystring) validation, with blanket redirector: AddRequiredInput("WidgetID", PageInputType.QueryString, typeof(string)),
Site Map Helpers, allowing for things like changing a static "Edit Class" into something context related like "Edit Fall '10 Science 101"
ViewState Helpers, allowing me to register variable on the page to a name and have it automatically populate that variable from the viewstate or a default, and save the value back out to the viewstate at the end of the request.
Custom 404 Redirector, where I can pass an exception or message (or both) and it will go to a page I have predefined to nicely display and log it.
I personally like #5 the most because a) updating the SiteMap is ugly and I prefer not to have clutter the page, making it more readable, b) It makes the SiteMap much more user friendly.
,
Please refer Getting page specific info in ASP.Net Base Page
public abstract string AppSettingsRolesName { get; }
List<string> authorizedRoles = new List<string>((ConfigurationManager.AppSettings[AppSettingsRolesName]).Split(','))
if (!authorizedRoles.Contains(userRole))
{
Response.Redirect("UnauthorizedPage.aspx");
}
In derived Page
public override string AppSettingsRolesName
{
get { return "LogsScreenRoles"; }
}