XML Comments - How to comment multiple reasons for an exception? - exception

Here's an example:
public void DoSomething(String param1, String param2)
{
if (param1 == null) throw new ArgumentNullException("param1");
if (param2 == null) throw new ArgumentNullException("param2");
}
2 different reasons for an ArgumentNullException. MSDNs String.Format Example shows 2 different reasons for the FormatException. So, is it done this way:
/// <exception cref="ArgumentNullException">
/// <paramref name="param1"/> is null.
/// </exception>
/// <exception cref="ArgumentNullException">
/// <paramref name="param2"/> is null.
/// </exception>
or some other way?
/// <exception cref="ArgumentNullException">
/// Some other way to show the 2 reasons with an "-or-" between them.
/// </exception>

If you think each of the rows of the docs as being one <exception cref=...> </exception>, then logically the correct way to do it is using your second alternative:
/// <exception cref="ArgumentNullException">
/// <p><paramref name="param1"/> is null. </p>
/// <p>- or - </p>
/// <p><paramref name="param2"/> is null. </p>
/// </exception>
You can use 'p' elements to denote the lines.

Related

BottomAppBar hides part of the TransportControls of a full window MediaElement

When a MediaElement switches to FullWindow mode, the internal FullWindowMediaRoot becomes its temporary host. When visible, FullWindowMediaRoot sits on top of the normal RootScrollViewer, i.e. it is displayed as an overlay over the current page, which is the expected behaviour.
My problem was with the BottomAppBar. Its host is the internal PopupRoot, which unfortunately sits on top of the FullWindowMediaRoot. So when I use a BottomAppBar on a page that allows a user to switch a MediaElement to FullWindow, the user cannot use the MediaElement's controls since these elements are almost completely hidden by the still visible BottomAppBar.
I have pulled my hair out over this problem for nearly a day and have found a solution that works for me. If someone has a better answer, I would be grateful for sharing. Until then, I am documenting my current working solution below for anyone running into the same issue.
My solution uses a class implementing IValueConverter, which raises an event whenever the IsFullWindow property of a MediaElement changes value.
The page initialiser adds an event handler to the converter's FullWindowStateChanged event:
this.isFullWindowConverter.FullWindowStateChanged += this.OnFullWindowStateChanged;
and handles it like this:
/// <summary>
/// Handles the FullWindowStateChanged event of IsFullWindowConverter by adjusting the visibility of the BottomAppBar to the full window
/// state of this page's MediaElement.
/// </summary>
/// <param name="sender">The instance of IsFullWindowConverter raising the event.</param>
/// <param name="e">The parameter is not used.</param>
private void OnFullWindowStateChanged(object sender, EventArgs e)
{
this.BottomAppBar.Visibility = ((IsFullWindowConverter)sender).IsFullWindow ? Visibility.Collapsed : Visibility.Visible;
}
Here the converter class:
namespace Filmit.Win
{
using System;
using Windows.UI.Xaml.Data;
/// <summary>
/// This converter raises an event when the IsFullWindow property of a MediaElement has changed. The converter is added to the resources of the page that hosts the MediaElement:
/// <code><local:IsFullWindowConverter x:Key="isFullWindowConverter" x:Name="isFullWindowConverter"/></code>
/// This converter resource is then bound to the IsFullWindow property of a MediaElement, solely for the event raising effects of the ConvertBack method this converter.
/// The actual value of the IsFullWindow property is returned as is.
/// <code><MediaElement IsFullWindow="{Binding RelativeSource={RelativeSource Self}, Path=IsFullWindow, Converter={StaticResource isFullWindowConverter}, Mode=TwoWay}"></code>
/// The subscriber to the FullWindowStateChanged event checks the IsFullWindow property to get the current full window state of the MediaElement.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1603:DocumentationMustContainValidXml", Justification = "XAML Page.Resources declaration.")]
public class IsFullWindowConverter : IValueConverter
{
/// <summary>
/// Raises the FullWindowStateChanged event. Subscribers check the IsFullWindow property to get the current full windows state.
/// </summary>
public event EventHandler<EventArgs> FullWindowStateChanged = null;
/// <summary>
/// Gets a value indicating whether the mode of the MediaElement is FullWindow.
/// </summary>
public bool IsFullWindow { get; private set; }
/// <summary>
/// Required implementation of IValueConverter.Convert, returning the passed in boolean object as a bool.
/// </summary>
/// <param name="value">The boolean object.</param>
/// <param name="targetType">The expected target type.</param>
/// <param name="parameter">The parameter is not used.</param>
/// <param name="language">The parameter is not used.</param>
/// <returns>The passed in boolean object as a bool.</returns>
public object Convert(object value, Type targetType, object parameter, string language)
{
bool? isFullWindow = value as bool?;
this.IsFullWindow = isFullWindow.HasValue ? isFullWindow.Value : false;
return this.IsFullWindow;
}
/// <summary>
/// This implementation of IValueConverter.ConvertBack is called when the IsFullWindow property of the MediaElement has changed its value.
/// It raises the FullWindowStateChanged event and returns the passed in boolean object as a bool.
/// </summary>
/// <param name="value">The boolean object.</param>
/// <param name="targetType">The expected target type.</param>
/// <param name="parameter">The parameter is not used.</param>
/// <param name="language">The parameter is not used.</param>
/// <returns>The passed in boolean object as a bool.</returns>
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
bool? isFullWindow = value as bool?;
this.IsFullWindow = isFullWindow.HasValue ? isFullWindow.Value : false;
if (this.FullWindowStateChanged != null)
{
this.FullWindowStateChanged(this, new EventArgs());
}
return this.IsFullWindow;
}
}
}
If you are creating a UWP app, I think you can put a AppBar in the Grid, and locate it to the bottom of the page. And this will solve your porblem too. But if you are working on a windows 8.1 app, this method will not work.
XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<MediaElement x:Name="MyMedia" Source="Assets/Sofia Jannok-Liekkas.wma" AreTransportControlsEnabled="True" />
<AppBar VerticalAlignment="Bottom">
<CommandBar>
<CommandBar.Content>
<Grid/>
</CommandBar.Content>
<AppBarButton Icon="Accept" Label="appbarbutton"/>
<AppBarButton Icon="Cancel" Label="appbarbutton"/>
<AppBarButton Content="Maximize" VerticalAlignment="Center" HorizontalAlignment="Center" Click="maximize"/>
</CommandBar>
</AppBar>
</Grid>
C#:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
public void maximize(object sender, RoutedEventArgs e)
{
MyMedia.IsFullWindow = !MyMedia.IsFullWindow;
}
}
Any way, your solution will solve the problem. Thank you for sharing.

Error reading Custom Configuration Section: No parameterless constructor defined for this object

Having a horrible time reading a custom configuration section from web.config:
I am using Configuration Section Designer (http://csd.codeplex.com/).
UPDATE:
here is the error I am getting:
System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for SendToTestConfig/sendToTestIndexConfig: No parameterless constructor defined for this object. (C:\TFS\Mainline\Business.Utility.SendToTest\Business.Utility.SendToTest\web.config line 20) ---> System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
Here is my auto-generated configuration section:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Business.Utility.SendToTest.Configuration
{
/// <summary>
/// The SendToTestIndexConfig Configuration Section.
/// </summary>
public partial class SendToTestIndexConfig : global::System.Configuration.ConfigurationSection
{
#region Singleton Instance
/// <summary>
/// The XML name of the SendToTestIndexConfig Configuration Section.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
internal const string SendToTestIndexConfigSectionName = "sendToTestIndexConfig";
/// <summary>
/// Gets the SendToTestIndexConfig instance.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
public static global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig Instance
{
get
{
return ((global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig)(global::System.Configuration.ConfigurationManager.GetSection(global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig.SendToTestIndexConfigSectionName)));
}
}
#endregion
#region Xmlns Property
/// <summary>
/// The XML name of the <see cref="Xmlns"/> property.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
internal const string XmlnsPropertyName = "xmlns";
/// <summary>
/// Gets the XML namespace of this Configuration Section.
/// </summary>
/// <remarks>
/// This property makes sure that if the configuration file contains the XML namespace,
/// the parser doesn't throw an exception because it encounters the unknown "xmlns" attribute.
/// </remarks>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
[global::System.Configuration.ConfigurationPropertyAttribute(global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig.XmlnsPropertyName, IsRequired=false, IsKey=false, IsDefaultCollection=false)]
public string Xmlns
{
get
{
return ((string)(base[global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig.XmlnsPropertyName]));
}
}
#endregion
#region IsReadOnly override
/// <summary>
/// Gets a value indicating whether the element is read-only.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
public override bool IsReadOnly()
{
return false;
}
#endregion
#region appGroups Property
/// <summary>
/// The XML name of the <see cref="appGroups"/> property.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
internal const string appGroupsPropertyName = "appGroups";
/// <summary>
/// Gets or sets the appGroups.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.0.0")]
[global::System.ComponentModel.DescriptionAttribute("The appGroups.")]
[global::System.Configuration.ConfigurationPropertyAttribute(global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig.appGroupsPropertyName, IsRequired=true, IsKey=false, IsDefaultCollection=false)]
public global::Business.Utility.SendToTest.Configuration.AppGroupSettingsCollection appGroups
{
get
{
return ((global::Business.Utility.SendToTest.Configuration.AppGroupSettingsCollection)(base[global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig.appGroupsPropertyName]));
}
set
{
base[global::Business.Utility.SendToTest.Configuration.SendToTestIndexConfig.appGroupsPropertyName] = value;
}
}
#endregion
}
}
namespace Business.Utility.SendToTest.Configuration
{
...
And here is my config file:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="SendToTestConfig" type="System.Configuration.ConfigurationSectionGroup, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<section name="sendToTestIndexConfig" type="Business.Utility.SendToTest.Configuration.SendToTestIndexConfig, Business.Utility.SendToTest.Configuration"/>
</sectionGroup>
etc.
</configSections>
<SendToTestConfig xmlns="Business.Utility.SendToTest.Configuration">
<sendToTestIndexConfig>
<appGroups>
<!-- TODO Change indexFileNamePrefix to desired value-->
<appGroupSettings name="ItemBased" indexFileNamePrefix="S" indexFolderLocation="C:\TFS\Mainline\Business.Utility.SendToTest\Business.Utility.SendToTest" imageFolderLocation="C:\TFS\Mainline\Business.Utility.SendToTest\Business.Utility.SendToTest">
<topicEntries>
<topicEntry topicIDSuffix="DATE" addDuplicateVSAMEntry="true">
<itemSubFields>
<subField index="0" typeName="Date"/>
</itemSubFields>
</topicEntry>
<topicEntry topicIDSuffix="Item" addDuplicateVSAMEntry="true">
<itemSubFields>
<subField index="0" typeName="ItemNumber"/>
</itemSubFields>
</topicEntry>
<topicEntry topicIDSuffix="DESCR">
<itemSubFields>
<subField index="0" typeName="LongDescription"/>
</itemSubFields>
</topicEntry>
</topicEntries>
</appGroupSettings>
</appGroups>
</sendToTestIndexConfig>
</SendToTestConfig>
...
</configuration>
I have tried all of the following, but I keep getting null for the first few config (which I think makes sense), and getting the abovementioned exception for the rest.
//These return null:
SendToTestIndexConfig config = SendToTestIndexConfig.Instance;
//SendToTestIndexConfig config = (SendToTestIndexConfig) ConfigurationManager.GetSection("sendToTestIndexConfig");
//SendToTestIndexConfig configb = (SendToTestIndexConfig)WebConfigurationManager.GetSection("sendToTestIndexConfig");
//SendToTestIndexConfig configc = (SendToTestIndexConfig)WebConfigurationManager.OpenWebConfiguration(null).GetSection("sendToTestIndexConfig");
//SendToTestIndexConfig configd = (SendToTestIndexConfig)WebConfigurationManager.GetWebApplicationSection("sendToTestIndexConfig");
//SendToTestIndexConfig configf = (SendToTestIndexConfig)WebConfigurationManager.GetSection("sendToTestIndexConfig");
////These throw a "parameterless constructor error" on object "SendToTestConfig/sendToTestIndexConfig"
//SendToTestIndexConfig configg = (SendToTestIndexConfig)WebConfigurationManager.GetSection("SendToTestConfig/sendToTestIndexConfig");
//SendToTestIndexConfig configh = (SendToTestIndexConfig)WebConfigurationManager.OpenWebConfiguration(null).GetSection("SendToTestConfig/sendToTestIndexConfig");
//SendToTestIndexConfig configi = (SendToTestIndexConfig)WebConfigurationManager.GetWebApplicationSection("SendToTestConfig/sendToTestIndexConfig");
//SendToTestIndexConfig configj = (SendToTestIndexConfig)WebConfigurationManager.GetSection("SendToTestConfig/sendToTestIndexConfig");
I'm guessing it has something to do with my naming. ConfigurationManager.AppSettings works fine, so I know I have the right web.config.
Actually, the solution to the problem is succinctly stated in an example for the GenericEnumConverter on MSDN. I did the same thing you probably did and explicitly set the [TypeConverter(typeof(GenericEnumConverter))] attrbibute on one of my configuration section properties and got the same error. According to the documentation for GenericEnumConverter linked to above, you do not need to set this attribute in order to use the GenericEnumConverter type converter--it is called implicitly by the framework. Remove that attribute from your configuration property specifications, and this error should disappear and everything should just work.
Here is an example of a configuration section property that uses an Enum:
public enum UsernameFormat
{
DownLevelDomainName,
UsernameOnly,
UserPrincipalName
}
public class WindowsADElement : ConfigurationElement
{
// This property will implicitly use the GenericEnumConverter type converter.
[ConfigurationProperty("usernameFormat", IsRequired=true, DefaultValue=UsernameFormat.UserPrincipalName)]
public UsernameFormat UsernameFormat
{
get { return (UsernameFormat)this["usernameFormat"]; }
set { this["usernameFormat"] = value; }
}
Then, to use it in code:
MyConfigurationSection config = ConfigurationManager.GetSection("myConfigurationSection") as MyConfigurationSection;
UsernameFormat format = config.UsernameLookup.WindowsAD.UsernameFormat;
Hope that helps.
I am not sure if this is the best solution, but I was able to get around the problem. The error was because I was using the GenericEnumTypeConverter class to convert the config strings to the AppGroup and SubFieldTypes enums. I created my own custom TypeConverters, and it solved the problem. Apparently, GenericEnumTypeConverter has no parameterless constructors, requiring the enum type for the constructor. Would love to know if there is a way to use GenericEnumTypeConverter, but this worked for me.
This clued me in on the answer: Configuration Error With Custom Behaviour

Filter content of inherited param comments

I have comments like this:
/// <summary>some summary</summary>
/// <param name="a">
/// <para id="0">Comment 0</para>
/// <para id="1">Comment 1</para>
/// <para id="2">Comment 2</para>
/// </param>
/// <param name="b">
/// <para id="1">Comment 3</para>
/// <para id="0">Comment 4</para>
/// </param>
void InterfaceMethod(int a, int b);
For the implementing method, I'd like to have the same documentation, but without those paragraphs having id="0", using inheritdoc.
How can I author the inheritdoc element?
The uncommon use of the id attributes in this context shall add the flexibility of not being tied to the order of the paragraphs as they appear in the documentation.
I found a solution, but it looks cumbersome.
/// <summary><inheritdoc/></summary>
/// <param name="a"><inheritdoc select="node()[parent::node()[#name='a'] and #id>0]"/></param>
/// <param name="b"><inheritdoc select="node()[parent::node()[#name='b'] and #id>0]"/></param>
public void InterfaceMethod(int a, int b) { }
As it is not possible to use XPath expressions as a filter, the param elements must be repeated.
The expression #id>0 (the > needed to be escaped) now selects the intended paragraphs only.
But what about the other markup?
The nested inheritdoc element will select the content of all param nodes, so we must add a condition on the parent's name attribute.
Finally, the inheritdoc tag within the summary tag will copy the summary. If we placed a inheritdoc on root level, this would again select the param, as described here.

Can I suppress the Restart request message when pushing a WAP provisioning update to a Windows Mobile device?

Our automatic maintenance procedure sends out provisioning updates like this to our devices overnight:
<wap-provisioningdoc>
<characteristic type="SoftwareDisable">
<characteristic type="DisabledSystemFiles">
<parm name="Labyrinth.exe" />
</characteristic>
</characteristic>
</wap-provisioningdoc>
This works fine, apart from it pops up a box asking the user if they want to restart now or later, specifically:
Restart
Recent changes to your device require a
restart. During this process you cannot make
or receive phone calls, including emergency
calls. Restart your device now?
Now Later
This is of course difficult to do because there is no user, just racks and racks of devices sitting there by themselves.
So, is there any way of not popping this message up and just restarting the device automatically? Possibly some registry setting or something?
You can soft reset your device via code.
Just need to p/invoke
public enum SystemPowerStates : uint
{
/// <summary>
/// On state.
/// </summary>
On = 0x00010000,
/// <summary>
/// No power, full off.
/// </summary>
Off = 0x00020000,
/// <summary>
/// Critical off.
/// </summary>
Critical = 0x00040000,
/// <summary>
/// Boot state.
/// </summary>
Boot = 0x00080000,
/// <summary>
/// Idle state.
/// </summary>
Idle = 0x00100000,
/// <summary>
/// Suspend state.
/// </summary>
Suspend = 0x00200000,
/// <summary>
/// Reset state.
/// </summary>
Reset = 0x00800000
}
[DllImport("coredll.dll")]
internal static extern int SetSystemPowerState(string psState, int StateFlags, int Options);
/// <summary>
/// Defines the System power requirement flags
/// </summary>
public enum PowerReqFlags : uint
{
POWER_NAME = 0x00000001,
POWER_FORCE = 0x00001000,
}
And call the function SetSystemPowerState, I use it enclosed in another method.
private static void DeviceReset()
{
SetSystemPowerState(
null,
(int)SystemPowerStates.Reset,
(int)PowerReqFlags.POWER_FORCE);
}

EF 4.1 + Repository + UnitOfWork + Remove Dependency with EF

I have implemented Generic repository which only depends on IUnitOfWork (in Infrastructure.Repositories Library) and also haven't used any references to Entity Framework 4.1 dll. Entity Framework's DbContext wrapped with EFUnitOfWork which is in different class library called Infrastructure.EntityFramework. However, I came across some difficulty with Linq to Entity query that may force me to include direct dependancy with repository and EF 4.1 library.
In one of my class repository I need to use following query with a join. How can I overcome DBContext usage in my repository ?
var result = from cc in ProjectXEFDbContext.CurrentContext().PurchaseOrderLineItemCollection
join bb in GetQuery() on cc.PurchaseOrderId equals bb.Id
where bb.Id == purchaseOrder.Id && cc.Total > 50
select cc;
I made my repositories to expose IQuerables over DbContext. DbContext wrap with UnitOfWork as follows
My Repository base goes like this
/// <summary>
/// Gets the query.
/// </summary>
/// <returns></returns>
public IQueryable<TEntity> GetQuery()
{
return this.UnitOfWork.GetQuery<TEntity>();
}
/// <summary>
/// Loads the type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public IQueryable<T> LoadType<T>() where T : class
{
return this.UnitOfWork.GetQuery<T>();
}
my unit of work implementation goes here
/// <summary>
/// Gets the query.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <returns></returns>
public IQueryable<TEntity> GetQuery<TEntity>() where TEntity:class
{
return this.DbContext.Set<TEntity>();
}
Changes to my query as follows
var result = from cc in GetQuery()
join bb in LoadType<PurchaseOrderLineItem>() on cc.Id equals bb.PurchaseOrderId
where cc.Id == purchaseOrder.Id && bb.Total > 50
select bb;