Category: "Programming"
Custom ASP.NET Identity MVC 5 - Part 1
I am working a new version of AdvGen CMS. I found the ApplicationUserManager has to use their Entity Framework. I cannot just build our own ApplicationUserManager to switch a different ORM layer. You have to build your own IUserStore like this:
public class AdvGenUserStroe : IUserStore
-->
And then build your own ApplicationUserManager which is using this custom user store.
This is the only way to have a Custom ASP.NET Identity in MVC 5
WPF: How to access a control in style
Source:Open Clip Art Using Under Public Domain Attribution
I got a control in style template at one of my custom controls, Like this:
<Style TargetType="{x:Type advgenControls:CollapsibleControl}" x:Key="LeftPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type advgenControls:CollapsibleControl}">
<Grid>
<ContentPresenter x:Name="PART_ContentPresenter"/>
<ResizeGrip Grid.Row="1" HorizontalAlignment="Stretch" Width="Auto" Height="Auto" HorizontalContentAlignment="Right" Margin="0,0,2,2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I just want to call that "PART_ContentPresenter". But that is xaml living in resources.
That is easy I can use GetTemplateChild("PART_ContentPresenter" ) and call at the OnApplyTemplate(). Please remember don't use it at OnInitialized(EventArgs e). At that time, styles has not loaded yet, you get a null object.:
Code
public override void OnApplyTemplate() | |
{ | |
base.OnApplyTemplate(); | |
if (this.IsInitialized) | |
{ | |
ContentPresenter cp = GetTemplateChild("PART_ContentPresenter" ) as ContentPresenter; | |
if(sections.Count >0){ | |
cp.Content = sections[0]; | |
} | |
} | |
} |
WPF Error:cannot set name attribute value '{control}'
Source:Open Clip Art Using Under Public Domain Attribution
I found the wpf user control cannot have any child has a name attribute, such as:
<advgenControls:CollapsibleControl> <TreeView x:Name="treeView" Style="{StaticResource MainLeftPanel}" /></advgenControls:CollapsibleControl>
It will have the error like this:
Cannot set Name attribute value 'treeView' on element 'TreeView'. 'TreeView' is under the scope of element 'CollapsibleControl', which already had a name registered when it was defined in another scope. Line 93 Position 5. (MC3093) - D:\Projects\AdvGenContact\AdvGenContact\AdvGenContact.WPF\MainWindow.xaml:93,5
I did a research on internet, I even tried some suggestions in internet, it doesn't work at all. I found that is no way to do that. I believe that is because User Control is not for that purpose. The user control is to hold some repeatable content across the applications. For example, I got a status bar which it need to place all every window in my application. Then I should create a user control for my own status bar and place into every window. In my case mentioned above, I wish to build a collapsible panel which has a different content in each window, even I will reuse that in other project. User Control is not my best. I should find an existing control to override. In this case, I should use HeaderItemsControl.
Note that: when I finish this control, I will put on my open source probject, AdvGen Contact Manager.
Running SQL Backup in .Net
If you are using SQL Express, you have sql agent to do the backup for you. The only way is using T-SQL in a application code to do that.
I have a C# library to do and winfrom application to do the scheduled task as the example, click here to buy it. That is only AUD$3! It can save you few hours of programming, That is very easy, just like the example below
Code
AdvGenSQLBackup backup = new AdvGenSQLBackup(); | |
backup.DBName = txtDBName.Text; | |
backup.Server = txtServerName.Text; | |
backup.UserName = txtUserName.Text; | |
backup.Password = txtPassword.Text; | |
backup.File = txtFile.Text; | |
backup.Run(); |
Moreover, you can use it in your web application. Then your web application can generate a backup file to your users for downloading.That is very useful.
Visual Studio 2013 and MVC5
I just installed Visual Studio 2013. Moreover, I started to build a MVC 5 project. That is great, it is integrated with Bootstrap and css less by default. The web application is fully responsive, works well in Tablet and Mobile too. In addition, MVC5 can support "~". such as src="~/Images/a.png" in img tag. We don't need to use Url.Content(~/Images/a.png"). It makes coding faster. I love these improvement. There is only one down side, Visual Studio 2013 ate much more CPU and Memory. It runs very slow in 8GB RAM and 2nd Generation Core i7 2Ghz laptop.