Search

just show me the code

Saturday, January 31, 2009

xml membership

credit to Atrem XmlProviders download their code from codeplex

   54     <membership defaultProvider="XmlMembershipProvider">
   55       <providers>
   56         <clear/>
   57         <add applicationName="SampleWebsite" 
   58              name="XmlMembershipProvider" 
   59              type="Artem.Web.Security.XmlMembershipProvider" 
   60              minRequiredPasswordLength="1"
minRequiredNonAlphanumericCharacters="0"
   61              requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
   62              passwordFormat="Hashed"/>
   63       </providers>
   64     </membership>
   77     <roleManager enabled="true" cacheRolesInCookie="true" 
defaultProvider
="XmlRoleProvider">
   78       <providers>
   79         <clear/>
   80         <add applicationName="SampleWebsite" name="XmlRoleProvider" 
type
="Artem.Web.Security.XmlRoleProvider"/>
   81       </providers>
   82     </roleManager> 
   83     <profile enabled="true" defaultProvider="XmlProfileProvider">
   84       <providers>
   85         <clear/>
   86         <add applicationName="SampleWebsite" name="XmlProfileProvider"
type="Artem.Web.Security.XmlProfileProvider"/>
   87       </providers>
   88       <properties>
   89         <group name="Person">
   90           <add name="FirstName" type="String"/>
   91           <add name="LastName" type="String"/>
   92           <add name="Years" type="Int32"/>
   93         </group>
   94         <add name="PageCursor" type="String"/>
   95         <add name="Counter" type="Int32" defaultValue="0"/>
   96       </properties>
   97     </profile>

Friday, January 30, 2009

Better menu control

sitemap.xml
    1 <?xml version="1.0" encoding="utf-8" ?>
    2 <siteMap> 
    3   <siteMapNode title="Welcome" url="~/Login/Login.aspx" />
    4   <siteMapNode title="Talent" url="~/Admin/TalentPage2.aspx" />
    5   <siteMapNode title="Profile" url="~/User/Profile.aspx" />
    6   <siteMapNode title="Events" url="~/Admin/Events2.aspx" />
    7   <siteMapNode title="Contact" url="~/Login/Contact.aspx" />
    8   <siteMapNode title="Download" url="~/User/Downloads.aspx" />
    9   <siteMapNode title="Responses" url="~/SuperAdmin/ResponseView.aspx" /> 
   10 </siteMap>

Main.Master
  110 <div id="navigation" class="right rclear">
  111     <div id="menu-container" class="right">
  112         <ul id="menu">
  113             <asp:Repeater ID="Repeater1" runat="server" DataSourceID="XmlDataSource1">
  114                 <ItemTemplate>
  115                     <li runat="server" id="item" class="item" 
  116                         visible='<%# this.CanNavigate(Eval("url"))  %>'>
  117                         <asp:HyperLink ID="hl" runat="server" 
  118                             NavigateUrl='<%# Eval("url") %>' 
  119                             Text='<%# Eval("title") %>' />
  120                     </li>
  121                 </ItemTemplate>
  122             </asp:Repeater>
  123         </ul>
  124     </div>
  125 </div>
...
  138 <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
  139     DataFile="~/Master/siteMap.xml" ></asp:XmlDataSource>



Main.Master.cs
   21 protected bool CanNavigate(object o)
   22 { 
   23     string url = o.ToString();
   24     IPrincipal p = HttpContext.Current.User;
   25     bool bReturn = UrlAuthorizationModule.CheckUrlAccessForPrincipal(url, p, "get");
   26     if (Talent.IsAdminOrBetter(p) && url.EndsWith("Profile.aspx"))
   27     {
   28         bReturn = false;
   29     }
   30     if (p.Identity.IsAuthenticated && url.EndsWith("Login.aspx"))
   31     {
   32         bReturn = false;
   33     }
   34     return bReturn; 
   35 }


credit to this stackoverflow post for the jquery script that will set the 'active' menu item class

Main.Master
   59 <script type="text/javascript"> 
   60     $(document).ready(function() {
   61         markActiveLink() 
   62     }); 
   63     function markActiveLink() { 
   64         //Look through all the links in the menu
   65        $("li.item a").filter(function() { 
   66           //Take the current URL and split it into chunks at each slash
   67           var currentURL = window.location.toString().split("/"); 
   68           //return true if the bit after the last slash is the current page name
   69           return $(this).attr("href") == currentURL[currentURL.length-1]; 
   70         //when the filter function is done, you're left with the links that match.
   71         }).addClass("active"); 
   72         //Afterwards, look back through the links. If none of them were marked,
   73         //mark your default one.
   74         if ($("li.item a").hasClass("active") == false) {
   75             $("li.item:nth-child(1) a").addClass("active");
   76         }
   77     }
   78 </script>

looks like this in then end when logged in as an admin



Thursday, January 29, 2009

Fail a Build when your Test Fails

Fail a Build when your Test Fails
ref: http://blogs.msdn.com/aaronhallberg/archive/2007/11/05/how-to-fail-a-build-when-tests-fail.aspx

Why
When a team build compiles with no errors, it is a success. If the test fail it gets marked as partially successful. Most would rather a failed test to mark the build as Failed.


Step1: Change your Target
The following code should be pasted into the bottom of your Team Build poject file and edited as necessary.

  252   <Target Name="AfterTest"> 
  253     <!-- Refresh the build properties. -->
  254     <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  255       BuildUri="$(BuildUri)"
  256       Condition=" '$(IsDesktopBuild)' != 'true' ">
  257       <Output TaskParameter="TestSuccess" PropertyName="TestSuccess" />
  258     </GetBuildProperties>
  259
  260     <!-- Set CompilationStatus to Failed if TestSuccess is false. -->
  261     <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  262       BuildUri="$(BuildUri)"
  263       CompilationStatus="Failed"
  264       Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' "  >
  265     </SetBuildProperties>
  266   </Target>

UPDATE
------------------------
http://drycode.blogspot.com/2009/04/tfs-fail-build-when-unit-test-fails.html


Tuesday, January 27, 2009

add paramaters to object data source dynamicaly


   45 <asp:ObjectDataSource ID="odsXxxxx" runat="server"
   46     SelectMethod="GetXxxxx" 
   47     TypeName="Xxxxx.Xxxxx.Web.ObjectDataSource.XxxxxOds" 
   48     InsertMethod="InsertXxxxx0" onselecting="odsXxxxx_Selecting" 
   49     oninserting="odsXxxxx_Inserting" oninserted="odsXxxxx_Inserted"  >
   50     <InsertParameters>
   51         <asp:Parameter Name="UserName" Type="String" />
   52         <asp:Parameter Name="UserPassword" Type="String" />
   53         <asp:Parameter Name="Email" Type="String" />
   54         <asp:Parameter Name="UserId" Type="String" /> 
   55         <asp:Parameter Direction="Output" Name="XxxxxId" Type="Int32" />
   56     </InsertParameters>
   57     <SelectParameters>
   58         <asp:Parameter Name="XxxxxId" Type="Int32" />
   59     </SelectParameters>
   60 </asp:ObjectDataSource>


Code Behind:

   47         protected void odsXxxxx_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
   48         {
   49             this.XxxxxId = Convert.ToInt32(e.OutputParameters["XxxxxId"]);
   50             Response.Redirect("~/User/ProfileAdd1.aspx?XxxxxId=" + this.XxxxxId.ToString() );
   51         }

   38         protected void odsXxxxx_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
   39         {
   40             MembershipUser u = Membership.GetUser(this.CreateUserWizard1.UserName); 
   41             e.InputParameters["UserId"] = u.ProviderUserKey.ToString();  
   42             e.InputParameters["UserName"] = u.UserName;
   43             e.InputParameters["UserPassword"] = "";
   44             e.InputParameters["Email"] = u.Email;   
   45         }

Ods.cs file:

   55         public void InsertXxxxx0(string UserName, string UserPassword, string Email, string UserId, out int XxxxxId)
   56         {
   57             //UserName, UserPassword, Email
   58             Xxxxx t = new Xxxxx();
   59             t.UserName = UserName;
   60             t.Email = Email;
   61             t.UserId = new Guid(UserId);
   62             _service.SaveTalent(t);
   63             XxxxxId =  t.Id;
   64         }

Tuesday, January 20, 2009

Auto deploy a TFS build


  
  228   <Target Name="AfterDropBuild">
  229     <CreateProperty Value="\\webdev1\Domains\Xxx_Xxxx_XxxxxXxxxx">
  230       <Output
  231         TaskParameter="Value"
  232         PropertyName="WebPreviewDropLocation"/>
  233     </CreateProperty>
  234     <CreateItem
  235         Include="$(DropLocation)\$(BuildNumber)\Release\_PublishedWebsites\Xxxx.XxxxXxxxx.Web\**\*">
  236       <Output
  237          TaskParameter ="Include"
  238          ItemName ="MyDropFiles"/>
  239     </CreateItem>
  240
  241     <RemoveDir Directories="$(WebPreviewDropLocation)"
  242                Condition="'$(BuildBreak)'!='true'" />
  243     <MakeDir Directories="$(WebPreviewDropLocation)"
  244              Condition="'$(BuildBreak)'!='true'" /> 
  245    <Copy
  246       SourceFiles="@(MyDropFiles)"
  247       DestinationFiles="@(MyDropFiles->'$(WebPreviewDropLocation)\%(RecursiveDir)%(Filename)%(Extension)')" 
  248       Condition="'$(BuildBreak)'!='true'" />
  249   </Target>

Friday, January 16, 2009

SOLID Principles with Uncle Bob


Scott talks to Uncle Bob about the the SOLID Principles of Object Oriented Design. This one is an easy listen! http://www.hanselminutes.com/default.aspx?showID=163
S.O.L.I.D.
  • Single responsibility principle,
  • Open/closed principle,
  • Liskov substitution principle,
  • Interface segregation principle, and
  • Dependency inversion principle
other links :
http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
http://www.lostechies.com/blogs/chad_myers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx

Thursday, January 15, 2009

starter master page

thanks to 456bereastreet
here is the final look

    5 <html xmlns="http://www.w3.org/1999/xhtml" >
    6 <head runat="server">
    7
    8     <style type="text/css">    body,
    9         html {
   10             margin:0;
   11             padding:0;
   12             background:#a7a09a;
   13             color:#000;
   14         }
   15         body {
   16             min-width:750px;
   17         }
   18         #wrap {
   19             background:#99c;
   20             margin:0 auto;
   21             width:750px;
   22         }
   23         #header {
   24             background:#ddd;
   25         }
   26         #header h1 {
   27             padding:5px;
   28             margin:0;
   29         }
   30         #nav {
   31             background:#c99;
   32             padding:5px;
   33         }
   34         #nav ul{
   35             margin:0;
   36             padding:0;
   37             list-style:none;
   38         }
   39         #nav li{
   40             display:inline;
   41             margin:0;
   42             padding:0;
   43         }
   44         #main {
   45             background:#9c9;
   46             float:left;
   47             width:500px;
   48         }
   49         #main h2, #main h3, #main p {
   50             padding:0 10px;
   51         }
   52         #sidebar {
   53             background:#99c;
   54             float:right;
   55             width:240px;
   56         }
   57         #sidebar ul {
   58             margin-bottom:0;
   59         }
   60         #sidebar h3, #sidebar p {
   61             padding:0 10px 0 0;
   62         }
   63         #footer {
   64             background:#cc9;
   65             clear:both;
   66         }
   67         #footer p {
   68             padding:5px;
   69             margin:0;
   70         }
   71
   72     </style>
   73     <asp:ContentPlaceHolder ID="head" runat="server">
   74     </asp:ContentPlaceHolder>
   75 </head>
   76 <body>
   77     <form id="form1" runat="server">
   78         <div id="wrap">
   79             <div id="header"><h1>Simple 2 column CSS layout, final layout</h1></div>
   80             <div id="nav">
   81                 <ul>
   82                     <li><a href="#">Option 1</a></li>
   83                     <li><a href="#">Option 2</a></li>
   84                     <li><a href="#">Option 3</a></li>
   85
   86                     <li><a href="#">Option 4</a></li>
   87                     <li><a href="#">Option 5</a></li>
   88                 </ul>
   89             </div>    
   90             <div id="main">         
   91                 <h2>Column 1</h2> 
   92                 <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
   93                 </asp:ContentPlaceHolder>  
   94             </div>
   95             <div id="sidebar">
   96                 <h3>Column 2</h3>
   97                 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris vel magna.</p>
   98                 <ul>
   99                     <li><a href="#">Link 1</a></li>
  100                     <li><a href="#">Link 2</a></li>
  101
  102                     <li><a href="#">Link 3</a></li>
  103                     <li><a href="#">Link 4</a></li>
  104                     <li><a href="#">Link 5</a></li>
  105                     <li><a href="#">Link 6</a></li>
  106                 </ul>
  107             </div> 
  108
  109             <div id="footer">        
  110                 <p>Footer</p>
  111
  112             </div>
  113         </div> 
  114     </form>
  115 </body>
  116 </html>

Wednesday, January 7, 2009

Asp.net Connection Strings

web.config
   21   <connectionStrings configSource="Database.config"/>



Database.config

    1 <connectionStrings>
    2   <clear/> 
    3   <add name="xxxx.xxxx.ConnectionString"
    4        connectionString="Server=xxxx;Initial Catalog=xxxx;Integrated Security=True;"
    5        providerName="System.Data.SqlClient" /> 
    6   <add name="xxxx.xxxx.Membership.ConnectionString"
    7        connectionString="Server=xxxxx;Initial Catalog=xxxx;Integrated Security=True;"
    8        providerName="System.Data.SqlClient" /> 
    9 </connectionStrings>



Database.config with user and password:
    1 <connectionStrings>
    2   <clear/>
    3
    4   <add name="xxxx.xxxx.ConnectionString"
    5        connectionString="Server=xxxx;Initial Catalog=xxxx;User=xxx;Password=xxx;"
    6        providerName="System.Data.SqlClient" /> 
    7   <add name="xxx.xxxx.Membership.ConnectionString"
    8        connectionString="Server=xxx;Initial Catalog=xxx;User=xxx;Password=xxx;"
    9        providerName="System.Data.SqlClient" />
   20 </connectionStrings>

Contributors