tag:blogger.com,1999:blog-5815225841505895052024-02-20T20:26:42.288+01:00Techie thingsA blog about .NET development and software architecture.Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.comBlogger99125tag:blogger.com,1999:blog-581522584150589505.post-90812949536213819242015-09-04T17:02:00.002+02:002015-09-04T17:02:50.015+02:00VS Code: Multiple build tasks with multiple solutionsThere are multiple solution files in the same folder in our current solution.
<br />
You can find the <i>tasks.json</i> file below to build these solutions separately.<br />
You can run the task by<br />
<br />
<ol>
<li>pressing CTRL+SHIFT+P</li>
<li>selecting Run Task</li>
<li>choosing the appropriate option</li>
</ol>
<br />
<script src="https://gist.github.com/artur02/14db3f6071b44c4f4a74.js"></script>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-21531309083432436162015-06-15T17:03:00.000+02:002015-06-15T17:03:18.731+02:00MVC6 SecretManagerI tried to install ASP.NET MVC6 Secret Manager package with DNVM 1.0.0-beta4. It failed with:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">Unable to locate SecretManager >= 1.0.0-beta4-10173</span></blockquote>
There is an easy fix: you can remove the last part of the version identifier.<br />
<br />
<ol>
<li>Open project.json file</li>
<li>Change version to </li>
</ol>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">"dependencies": {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> "SecretManager": "<b style="background-color: yellow;">1.0.0-beta4-*</b>"</span><br />
<span style="font-family: Courier New, Courier, monospace;"> },</span></blockquote>
<b>Files to be changed:</b><br />
<table><tbody>
<tr> <td>Package path:</td><td><code>%UserProfile%\.dnx\packages\SecretManager\1.0.0-beta4\app\project.json</code></td></tr>
<tr> <td>Cache path:</td><td><code>%UserProfile%\.dnx\bin\packages\SecretManager\1.0.0-beta4\app\project.json</code></td></tr>
</tbody></table>
Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-30726577552924380602015-06-10T11:59:00.001+02:002015-06-10T12:09:56.665+02:00RouteValueDictionaryI got an error recently when I enable DonutCache donutHole-based caching for a RenderAction:<br />
<blockquote class="tr_bq">
Type 'System.String[]' with data contract name 'ArrayOfstring:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.</blockquote>
It seems RouteValueDictionary cannot manage IEnumerable or String[] as a parameter. The solution is simple, it's a well-known issue:<br />
<blockquote class="tr_bq">
<a href="http://stackoverflow.com/questions/19960420/adding-array-of-complex-types-to-routevaluedictionary">http://stackoverflow.com/questions/19960420/adding-array-of-complex-types-to-routevaluedictionary</a></blockquote>
<br />
So this is how you can use the extension method:<br />
<blockquote class="tr_bq">
<blockquote class="tr_bq">
Html.RenderAction(</blockquote>
<blockquote class="tr_bq">
<i>ActionName</i>,</blockquote>
</blockquote>
<blockquote class="tr_bq">
<blockquote class="tr_bq">
<i>ControllerName</i>,</blockquote>
<blockquote class="tr_bq">
new RouteValueDictionary(new </blockquote>
<blockquote class="tr_bq">
{ <i>usual properties here</i> }));</blockquote>
</blockquote>
<br />
<br />
<blockquote class="tr_bq">
<blockquote class="tr_bq">
</blockquote>
</blockquote>
Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-75016064546549165592014-05-15T15:42:00.001+02:002014-05-15T15:43:57.767+02:00Partial apply in C#<p>Partial apply by <a href="http://en.wikipedia.org/wiki/Partial_application" target="_blank">Wikipedia</a>:</p> <blockquote> <p>In <a href="http://en.wikipedia.org/wiki/Computer_science" target="_blank">computer science</a>, <b>partial application</b> (or <b>partial function application</b>) refers to the process of fixing a number of arguments to a function, producing another function of smaller <a href="http://en.wikipedia.org/wiki/Arity" target="_blank">arity</a>. Given a function <img alt="\scriptstyle f \colon (X \times Y \times Z) \to N " src="http://upload.wikimedia.org/math/4/3/a/43a45f58c8f35707c396444463e2ef24.png">, we might fix (or 'bind') the first argument, producing a function of type <img alt=" \scriptstyle\text{partial}(f) \colon (Y \times Z) \to N " src="http://upload.wikimedia.org/math/1/d/5/1d54867424707e76c6f46bf426fc193e.png">. Evaluation of this function might be represented as <img alt="f_{partial}(2, 3)" src="http://upload.wikimedia.org/math/1/5/0/150d132974fd1c1b21b6503567e108eb.png">. Note that the result of partial function application in this case is a function that takes two arguments.</p></blockquote> <p>In short, that means you define (bind) some of the possible arguments and leave some to be filled in later (free).</p> <h3>Scala</h3><pre class="prettyprint">def sum(a:Int, b:Int, c:Int):Int = a+b+c //> sum: (a: Int, b: Int, c: Int)Int
sum(1,2,3) //> res11: Int = 6
def sum1 = sum(1, _:Int, _:Int) //> sum1: => (Int, Int) => Int
sum1(2,3) //> res12: Int = 6
def sum2 = sum(_:Int, 2, _:Int) //> sum2: => (Int, Int) => Int
sum2(1,3) //> res13: Int = 6
</pre>
<p><em>sum1</em> binds the first parameter but the other two parameters are free. As you can see from the result it gets translated to a lambda with two parameters.</p>
<p><em>sum2</em> binds the second parameter. The result is the same, a lambda with two parameters.</p>
<h3>C# </h3>
<p>C# has no built-in operator for applying a function, so we have to write the lambdas directly.</p><pre class="prettyprint">readonly Func<int , int int,> sum = (x, y, z) => x + y + z;
[Fact]
public void Sum()
{
var result = sum(1, 2, 3);
Assert.Equal(6, result);
}
[Fact]
public void Sum_PartialApply_FirstParam()
{
Func<int , int int,> sum1 = (y, z) => sum(1, y, z);
var result = sum1(2, 3);
Assert.Equal(6, result);
}
[Fact]
public void Sum_PartialApply_SecondParam()
{
Func<int , int int,> sum2 = (x, z) => sum(x, 2, z);
var result = sum2(1, 3);
Assert.Equal(6, result);
}
</pre> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com1tag:blogger.com,1999:blog-581522584150589505.post-35899167941735481792014-05-14T15:57:00.001+02:002014-05-14T15:59:01.039+02:00Loan pattern in C#<p>There is a pattern is Scala called loan pattern. You open a resource, “loan” the resource to another function, and the loaner closes the resource.</p> <h3>Scala</h3> <p>This function expects a file a function. When it's called it creates the resource, executes the function and closes the resource.</p><pre class="prettyprint">def withPrintWriter(file: File, op: PrintWriter => Unit) {
val writer = new PrintWriter(file)
try {
op(writer)
} finally {
writer.close()
}
}
</pre>
<p>This is how it's called:</p><pre class="prettyprint">withPrintWriter(
new File("date.txt"),
writer => writer.println(new java.util.Date)
)
</pre>
<h3>C#</h3>
<p>Now I extended the definition with currying:</p><pre class="prettyprint">readonly Func<string string func ,><func><streamreader ,>, string>> openFile =
path =>
handler =>
{
var reader = new StreamReader(path);
try
{
return handler(reader);
}
finally
{
reader.Close();
Console.WriteLine("Stream closed");
}
};
</pre>
<p>Here are two examples on calling the function above:</p><pre class="prettyprint">readonly Func<streamreader , string> readAllLines = input => input.ReadToEnd();
readonly Func<streamreader , string> readSingleLine = input => input.ReadLine();
[Fact]
public void LoanPattern_AllText()
{
var result = openFile("TextFile1.txt")(readAllLines);
Assert.Equal("This is the test content.\r\nThis is a second line.", result);
}
[Fact]
public void LoanPattern_ReadSingleLine()
{
var result = openFile("TextFile1.txt")(readSingleLine);
Assert.Equal("This is the test content.", result);
}
</pre>
<h3>Result</h3>
<p>Now the code calling the function (openFile) is much simpler and there is no need for error handling in the caller. Furthermore thanks to currying, even the resource name can be bound in the constructor, hiding the resource initialization as well.</p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-90657735644291340122014-05-08T15:08:00.001+02:002014-05-08T16:53:39.126+02:00Currying in Scala and C#<p>Currying is an interesting and powerful functional programming concept. Interestingly currying can be used in C# as well.</p><h3>The usual approach</h3><p>Let's define a simple add function that sums two numbers in <strong>C#</strong>:</p><pre class="prettyprint">[Fact]
public void SimpleAdd_AsInlineFunction_WithLambda()
{
Func<int, int, int> add = (x, y) => x + y;
var result = add(5, 7);
Assert.Equal(12, result);
}
</pre><p>The same in <strong>Scala</strong>:</p><pre class="prettyprint">def add(x:Int,y:Int) = x+y //> add: (x: Int, y: Int)Int
add(5,7) //> res0: Int = 12
</pre>Or with lambda: <pre class="prettyprint">def add_lambda = (x:Int,y:Int) => x+y //> add_lambda: => (Int, Int) => Int
add_lambda(5,7) //> res1: Int = 12
</pre><h3>Currying</h3><p>Now Implement the same function in <strong>C#</strong>, but this time with currying:</p><pre class="prettyprint">[Fact]
public void CurryingAdd()
{
Func<int, Func<int, int>> add = x => y => x + y;
var result = add(5)(7);
Assert.Equal(12, result);
}
</pre><p>In <strong>Scala</strong>:</p><pre class="prettyprint">def add_lambda_currying(x:Int) = (y:Int) => x+y //> add_lambda_currying: (x: Int)Int => Int
add_lambda_currying(5)(7) //> res2: Int = 12
</pre><p>With simplified Scala syntax:</p><pre class="prettyprint">def add_currying(x:Int)(y:Int): Int = x+y //> add_currying: (x: Int)(y: Int)Int
add_currying(5)(7) //> res3: Int = 12
</pre><h3>Partial apply</h3><p>Now let’s suppose I want to bind the first parameter to a concrete value (bound) but I want to keep the second parameter unbounded (free).</p><p>This is the way in C#:</p><pre class="prettyprint">[Fact]
public void CurryingAdd_Add5()
{
Func<int int , func><int ,>> add = x => y => x + y;
var add5 = add(5);
var result1 = add5(7);
Assert.Equal(12, result1);
var result2 = add5(122);
Assert.Equal(127, result2);
}
</pre><p>The same idea in Scala:</p><pre class="prettyprint">def add5_lambda_currying = add_lambda_currying(5) //> add5_lambda_currying: => Int => Int
add5_lambda_currying(7) //> res3: Int = 12
def add5_currying = add_currying(5) _ //> add5_currying: => Int => Int
add5_currying(7) //> res5: Int = 12
</pre><p>In case of the <em>add5_currying</em> example please notice the underscore (_) at the end of the expression. That means partial apply and indicates that I don’t want to bind the second parameter. There is no need for such indicator with lambda syntax.</p>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-56175256702345932082014-02-07T10:58:00.000+01:002014-05-08T15:50:43.104+02:00Functional C# - insight by PythonPython has many powerful functions. I realized there are many similar functions available in .NET. <br />
<br />
Enumerable.Aggregate<br />
<table border="1"><thead>
<tr> <th>Function</th> <th>Description</th> <th>.NET</th> </tr>
</thead><tbody>
<tr> <td><a href="http://docs.python.org/2/library/functions.html#zip" target="_blank">zip</a></td> <td>Pairs iterables element by element:<br />
<br />
<pre class="prettyprint">* x = [1, 2, 3]
* y = [4, 5, 6]
* zipped = zip(x, y)
* zipped
[(1, 4), (2, 5), (3, 6)]
</pre><br />
</td> <td><a href="http://msdn.microsoft.com/en-us/library/dd267698(v=vs.110).aspx"><b>Enumerable.Zip</b></a><br />
<br />
<pre class="prettyprint">int[] numbers = { 1, 2, 3, 4 };
string[] words = { "one", "two", "three" };
var numbersAndWords =
numbers.Zip(words, (first, second) => first + " " + second);
foreach (var item in numbersAndWords)
Console.WriteLine(item);
// 1 one
// 2 two
// 3 three
</pre><br />
</td> </tr>
<tr> <td><a href="http://docs.python.org/2/library/functions.html#reduce" target="_blank">reduce</a></td> <td>Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value. For example, <pre class="prettyprint">reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])</pre>calculates <pre class="prettyprint">((((1+2)+3)+4)+5)</pre>. </td><td><a href="http://msdn.microsoft.com/en-us/library/bb548651(v=vs.110).aspx"><b>Enumerable.Aggregate</b></a><br />
<br />
<pre class="prettyprint">string sentence = "the quick brown fox jumps over the lazy dog";
// Split the string into individual words.
string[] words = sentence.Split(' ');
// Prepend each word to the beginning of the
// new sentence to reverse the word order.
string reversed = words.Aggregate((workingSentence, next) =>
next + " " + workingSentence);
// dog lazy the over jumps fox brown quick the
</pre></td> </tr>
<tr><td><a href="http://docs.python.org/2/library/functions.html#filter">filter</a></td><td>Construct a list from those elements of iterable for which function returns true.<br />
<br />
<pre class="prettyprint">filter(lambda x: x%2, range(10))
result: 1 3 5 7 9</pre></td><td><a href="http://msdn.microsoft.com/en-us/library/bb534803(v=vs.110).aspx"><b>Enumerable.Where</b></a><br />
<pre class="prettyprint">List<string> fruits =
new List<string> { "apple", "passionfruit", "banana", "mango",
"orange", "blueberry", "grape", "strawberry" };
IEnumerable<string> query = fruits.Where(fruit => fruit.Length < 6);
/*
This code produces the following output:
apple
mango
grape
*/
</string></string></string></pre></td></tr>
</tbody></table>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-46038649363416986542013-11-11T12:53:00.000+01:002013-11-11T12:53:55.608+01:00Pragmatism<h2>
My background</h2>
I'm a .NET, mainly C# programmer. Nowadays I focus on web applications. I usually work on enterprise-grade applications.<br />
<br />
I came across Python a year ago on a training session. I was shocked by the syntax but I felt the power of the language and the toolset.<br />
<h2>
Pragmatism</h2>
I think I need to define what is pragmatism for me in the context of software engineering: when a customer has a business problem, your responsibility as an engineer is to choose the proper tools to fulfil the real needs of this customer.<br />
<h3>
Pragmatic tools</h3>
A <b>tool </b>can be a language, a framework, a design or architectural pattern.<br />
<h3>
Business domain</h3>
The <b>real need</b> means a customer usually can't express the whole problem to the team (or even mislead the the team with half or missing information) so the developer (or analyst) needs to dig deep into the business problem and understand the domain before the actual coding gets started.<br />
<h2>
Pragmatic programming</h2>
<div>
The first thing is to understand the business domain. A developer has to constantly check the requirements against the customer's ideas and the business domain to make sure there is no misunderstanding. It also applies to the QA (tester) personnel as well. Only the joint work of the analysts, developers and QAs (regarding only the development team) can ensure the success of the implementation considering the business domain and real needs.</div>
<div>
<br /></div>
<div>
The pragmatic programmer does not stick to the favorite language (e.g. C#) she knows:</div>
<div>
<ul>
<li><b>C#</b> is a good choice for GUI, especially with <a href="http://msdn.microsoft.com/en-us/library/aa970268(v=vs.110).aspx" target="_blank"><b>WPF</b> </a>and Windows in mind. On the other hand <b><a href="http://python.org/about/" target="_blank">Python </a></b>can be a better choice for log analysis, mathematical modeling and statistical processing (considering NumPy, SciPy and Pandas). </li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx" target="_blank"><b>WCF</b> </a>(as an XML web service) is powerful for enterprise-grade service implementations but <b><a href="http://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank">REST </a></b>can be a better choice for thin APIs with mobile clients.</li>
<li><b><a href="http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx" target="_blank">WCF </a></b>is a powerful end-point provider but <b><a href="http://nodejs.org/" target="_blank">node.js</a></b> can be a better choice if you have an AJAX-heavy web application with some kind of model-based JS framework. In case of node.js you don't need to transform your data from a static-typed language to a dynamic language. Less layers, less transformation, less technology and tooling. </li>
<li><b><a href="http://www.asp.net/mvc" target="_blank">ASP.NET MVC</a></b> is an easy-to-learn and thin layer for web application development. I like it, but I know <b><a href="http://rubyonrails.org/" target="_blank">Ruby on Rails</a></b> or even <b><a href="https://www.djangoproject.com/" target="_blank">Django (Python)</a></b> can be as powerful or even more powerful for your particular task.</li>
<li><b><a href="http://msdn.microsoft.com/en-us/data/ef.aspx" target="_blank">Entity Framework</a></b> is powerful with its own limitations, but sometimes it worths going back to the basics with direct <b><a href="http://msdn.microsoft.com/en-us/library/vstudio/h43ks021(v=vs.100).aspx" target="_blank">ADO.NET</a></b> calls. Or does it? Consider <b><a href="https://code.google.com/p/dapper-dot-net/" target="_blank">Dapper</a>, <a href="http://ormlite.com/" target="_blank">OrmLite</a></b> and such.</li>
<li><b>Object-oriented</b> programming is well-understood but <b>functional </b>elements can make the code more robust and easier to manage.</li>
<li>Defensive programming with <b>guards </b>is useful but what about <b>code contracts</b> (even the Microsoft implementation or in general)?</li>
<li><b><a href="https://www.scrum.org/Resources/What-is-Scrum" target="_blank">Scrum </a></b>is good and has proved, but how can I adapt it to the current customer? Or shouldn't I choose <b><a href="http://en.wikipedia.org/wiki/Kanban_(development)" target="_blank">Kanban</a></b>? Or Scrumban? Do I need to integrate with an existing project management 'system'? Anyway, do I need to choose an <a href="http://agilemanifesto.org/principles.html" target="_blank"><b>agile </b>methodology</a> at all (yes, it should be prefered :) )?</li>
</ul>
<div>
There are always alternatives and the engineer's job should be choosing the right mix of these alternatives.</div>
</div>
Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-46433885645699282472013-04-17T15:27:00.000+02:002014-05-08T16:48:53.088+02:00Unit testing a Powershell CommandletI chose to write Powershell commandlets in C#. I created a class library (DLL) project and inherited a class from <i>Cmdlet </i>base class. I created a snapin class derived from <i>PSSnapIn </i>to be able to install my commandlets from powershell.<br />
<div><br />
</div><h2>Unit testing</h2><h3>Writing a unit test</h3><pre class="prettyprint">[TestClass]
public class UnitTest1
{
private static RunspaceConfiguration config;
private static Runspace runspace;
private static Pipeline pipe;
private static Command command;
[ClassInitialize]
public static void TestFixtureSetup(TestContext context)
{
config = RunspaceConfiguration.Create();
PSSnapInException warning;
config.AddPSSnapIn("SnapinName", out warning);
runspace = RunspaceFactory.CreateRunspace(config);
runspace.Open();
}
[ClassCleanup]
public static void TestFixtureTeardown()
{
runspace.Close();
}
[TestInitialize]
public void Setup()
{
pipe = runspace.CreatePipeline();
command = new Command("CommandName");
pipe.Commands.Add(command);
}
[TestMethod]
public void TestMethod1()
{
command.Parameters.Add(new CommandParameter("ParameterName", "Value"));
var psObject = pipe.Invoke();
}
}
</pre><h3>Snapin couldn't be found</h3><div>I wrote a unit test against one of my commands but it couldn't find my snapin, I got the following exception:</div><div>System.Management.Automation.PSArgumentException: System.Management.Automation.PSArgumentException: The Windows PowerShell snap-in '...' is not installed on this computer..</div><div><br />
</div><div>I could use my snapin from Powershell command line.</div><div><br />
</div><h4>Solution</h4><div>Add the following lines as post-build events:</div><div><blockquote class="tr_bq"><span style="font-family: Courier New, Courier, monospace;">c:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe $(TargetPath)</span><br />
<span style="font-family: Courier New, Courier, monospace;">c:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe $(TargetPath)</span></blockquote></div><div><br />
</div><div>Both 32-bit and 64-bit installation will happen this way.</div><h4>Cause</h4><div>Visual Studio 2012 is a 32-bit process. I registered with 64-bit install util only. Now I register both versions.</div>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-12605685129751157222013-04-15T16:21:00.000+02:002014-05-08T16:50:32.274+02:00XAML Resource LoadingVisual Studio 2012 kept locking my .DLLs. It happened mostly after starting a debugger session. I could trace back the problem to a <i>GetManifestResourceStream()</i> call.<br />
<br />
<h2>Solution</h2>This is my solution that seems to be working:<br />
<br />
<pre class="prettyprint">public Stream GetResourceStreamByType(Type type, string resourceName)
{
var location = Assembly.GetAssembly(type).Location;
var assemblyBytes = File.ReadAllBytes(location);
var appDomain = AppDomain.CreateDomain("Resource domain");
var assembly = appDomain.Load(assemblyBytes);
return assembly.GetManifestResourceStream(resourceName);
}
public BitmapImage GetBitmapByType(Type type, string resourceName)
{
var bmp = new BitmapImage();
using (var source = GetResourceStreamByType(type, resourceName))
{
bmp.BeginInit();
bmp.StreamSource = source;
bmp.EndInit();
}
return bmp;
}
</pre><h2>Reasons</h2><div>Loading the resource by calling the <i>GetManifestResourceStream()</i> on the current assembly loads the assembly into the debugger's app domain which is Visual Studio in this case. Reading the bytes and loading them manually prevents this behavior.</div><div><br />
</div><div>I couldn't reload the form again after loading the resources this way so I had to create a separate app domain as well. Without separate app domain the assembly was already loaded and the reloading didn't happen with an error message like '<b>does not have a resource identified by the URI</b>'.</div>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-89667666663188112112012-09-04T13:02:00.001+02:002014-05-08T16:51:29.317+02:00Ember–Handlebars.helpers in Windows 8 Metro<p>I tried to use Ember.js Handlebars helper <font face="Consolas"><em>{{action}}</em></font> in a Windows 8 Metro (Windows Store) application. The data marker attribute appeared, but the function was never called.</p><p>I managed to find the <strong>root cause</strong>: Ember.js uses <font face="Consolas"><em>jQuery.ready()</em></font> for initialization. </p><h2>Solution</h2><p>Change</p><pre class="prettyprint">waitForDOMContentLoaded: function() {
this.deferReadiness();
var self = this;
this.$().ready(function() {
self.advanceReadiness();
});
},
</pre><p>to</p><pre class="prettyprint">waitForDOMContentLoaded: function() {
this.deferReadiness();
var self = this;
WinJS.Application.addEventListener("ready", function () {
self.advanceReadiness();
});
},
</pre>and comment out 2 lines as shown below: <pre class="prettyprint">advanceReadiness: function() {
this._readinessDeferrals--;
//if (this._readinessDeferrals === 0) {
Ember.run.once(this, this.didBecomeReady);
//}
},
</pre><p>Now you will use the Metro infrastructure for events.</p>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-32672426848986899482012-09-02T20:10:00.001+02:002014-05-08T16:52:16.654+02:00Handlebars and Ember templating in Window 8 Metro<p><a href="http://handlebarsjs.com/" target="_blank">Handlebars</a> uses script blocks for template markup. E.g.</p><pre class="prettyprint"><script type="text/x-handlebars" data-template-name="say-hello">
Hello, <b>{{MyApp.name}}</b>
</script></pre><p>Unfortunately the Metro JavaScript engine removes the <font face="Consolas"><em>data-template-name</em></font> attribute from the script tag, so this method can’t be used for templating.</p><p>As JS files are available locally for execution, the template files can be stored in separate HTML files and can be parsed from code. The implementation is simple:</p><pre class="prettyprint">
Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(path).done(function(folder) {
var search = folder.createFileQuery(Windows.Storage.Search.CommonFileQuery.orderByName);
search.getFilesAsync().done(function (res) {
res.forEach(function (file) {
var template;
Windows.Storage.FileIO.readTextAsync(file).then(function(fileContent) {
var template = Ember.Handlebars.compile(fileContent);
Ember.TEMPLATES[file.displayName] = template;
[…]
</pre><p>I omitted the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211867.aspx" target="_blank">async promises</a> from the code for readability, but the code won’t work without them.</p><p>The code above </p><ol><li>reads all the files from a folder<br />
<li>compiles the template<br />
<li>stores the compiled template as an Ember template</li><br />
</ol><p>Now <strong>Ember.js</strong> and <strong>Handlebars.js</strong> are fully functional, even <font face="Consolas"><em>Ember.View</em></font> can be used with <font face="Consolas"><em>view.append()</em></font>.</p>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-22726830211817320592012-09-01T12:55:00.001+02:002012-09-01T12:55:00.595+02:00Digital TV Experience<p>I have some experience with a Samsung <a href="http://en.wikipedia.org/wiki/Smart_TV" target="_blank">smart TV</a> I will summarize here.</p> <h2>TV</h2> <p>I have access to <strong>analog TV signal</strong>, and I must tell you this is not what a digital TV was made for. It’s acceptable, but </p> <ul> <li>the image is not sharp, thanks to the low resolution</li> <li>the aspect ratio of the picture (aka picture size) changes among channels, or even between programs</li> <li>the TV tries to enhance the quality of the image (e.g. sharpens the edges at still images), and sometimes that can be annoying</li> <li>no electronic program guide (EPG)</li></ul> <p>I tried to receive <a href="http://en.wikipedia.org/wiki/DVB-T" target="_blank">DVB-T signal</a> but I couldn’t. Just a few channels with long breaks in receiving. Though the image quality was wonderful and I got EPG.</p> <h2>Teletext</h2> <p><a href="http://en.wikipedia.org/wiki/Teletext" target="_blank">Teletext</a> comes with the channels supporting this technology. It is the shadow of the analog era. Digital TVs try to enhance this technology:</p> <ul> <li>store pages in memory, no need to wait for paging</li> <li>more txt display modes</li></ul> <p>Don’t expect too much from this.</p> <h2>Multimedia</h2> <p>Digital TVs support a standard protocol (<a href="http://en.wikipedia.org/wiki/DLNA" target="_blank">DLNA</a>) for receiving multimedia streams from other devices. Just put the two devices onto the same subnet of your LAN (use the same router with cable or Wi-Fi) and the two devices will see each other. In my case I run a Samsung AllShare DLNA server on my desktop computer and</p> <ul> <li>I can select the movie I want to play from the TV’s menu</li> <li>I can start playing the movie on my TV pressing a button on my computer using AllShare or Windows Media Player.</li></ul> <p><a href="http://en.wikipedia.org/wiki/Smartphone" target="_blank">Smartphones</a> have the same capabilities. Moreover</p> <ul> <li>I can start playing a movie on the TV from my computer pressing a button on my smart phone</li> <li>I can control the TV from the smart phone as a TV remote (needs special app on your phone)</li></ul> <p>You can by a <a href="http://en.wikipedia.org/wiki/Network-attached_storage" target="_blank">NAS</a> with DLNA support and you will have an always online media server without noisy fans.</p> <h2>HDMI</h2> <p>Connecting a <a href="http://en.wikipedia.org/wiki/HDMI" target="_blank">HDMI</a> cable to the TV and the computer, means the computer’s desktop can be displayed on the TV, in excellent quality.</p> <p>Even the sound can be redirected to the TV’s speakers or sound system. Just open the sound playback devices and set the TV as the default sound device.</p> <p>If your TV supports <a href="http://www.hdmi.org/manufacturer/hdmi_1_4/hec.aspx" target="_blank">HDMI Ethernet channel</a>, you can use your TV as a(n Internet) router for multimedia device (blue-ray player etc.).</p> <h2>Smart features</h2> <p>I have access to a Samsung smart TV. It has an Internet browser and apps can be downloaded from a store. There are some useful apps like online radio and TV channel guide, but the most useful app is the Internet browser. It has Flash support and loads most of the websites I tried to visit.</p> <p>For better experience I suggest you to buy a wireless keyboard and mouse. There are multimedia keyboards combining these devices into a small device just like a game controller. </p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-15440520898941234772012-08-31T16:21:00.001+02:002012-08-31T16:21:41.038+02:00Require JS with Win 8 Metro interface<p><a href="http://requirejs.org" target="_blank">Require.js</a> works with Windows 8 Metro-style (Windows Store) applications. </p> <h2>Page scripts</h2> <p>There is a JavaScript file for each HTML page files. You cannot wrap this .js file into a require function. The page events (e.g. the ready event) won’t be called. </p> <p>You can place a require call into the event handler function and that works.</p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-22026846278920028492012-04-12T11:14:00.001+02:002012-04-12T11:15:17.026+02:00Git: create a tag on a (remote) branch<p>You can create a tag on the local branch and you must push the tag to the remote.</p> <h2>Command line</h2> <p><font face="Consolas">> git tag …</font></p> <p><font face="Consolas">> git push --tags</font></p> <h2>TortoiseGit</h2> <ol> <li>Create tag</li> <ol> <li>set tag name</li> <li>set tag/branch/version</li> <li>enter message</li></ol> <li>Sync/Push</li> <ol> <li>Select <strong>Push tags </strong>instead of Push button in the dropdown</li></ol></ol> <h2>Git Extensions</h2> <ol> <li><strong>Browse</strong></li> <li>Right click on the commit log you want to tag</li> <li>Select <strong>Create new tag</strong></li> <li>Enter data</li> <li>Push</li> <ol> <li>Select <strong>Push tags </strong>tab</li></ol></ol> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-38788680073712690902012-02-10T17:21:00.001+01:002012-02-10T17:21:44.053+01:00Hate JavaScript?<p>Do you hate JavaScript? Well, I have bad news. There are still no alternatives in the web browsers.</p> <p>I develop ASP.NET (MVC) –based web applications, and I must use JavaScript. What’s the big difference between the modern web applications and websites from a few years ago? Well, the server-side/client-side ratio. A few years ago I was happy coding on server-side.<strong> I did as much as I could do in C#, in ASP.NET</strong>. I did learn JavaScript but I avoided it as much as I could (so I never knew it well enough).</p> <p>Now you can’t avoid JavaScript anymore. More and more code is on client-side. More and more business logic and architectural challenges are on client-side, right in the browser. <strong>I’ve written database-like features and even messaging systems</strong> in JavaScript. That challenge reminds me the early days of other languages. Missing features, missing language support, missing best practices, missing design patterns. Pure greenfield tasks.</p> <p>How well do you speak JavaScript? A few years ago it was enough to understand how to define a function and some variables. Learn how <a href="http://en.wikipedia.org/wiki/Document_Object_Model" target="_blank">DOM</a> works. How different DOMs work. That’s not a small thing if you did it well. But did we <strong>write good, quality code with low bug ratio and good manageability</strong>? I’d say no.</p> <p>A few years later there came the <strong><a href="http://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank">object-oriented</a> world</strong> to JavaScript. We, I personally, had to learn the idea behind <a href="http://en.wikipedia.org/wiki/Prototype-based_programming" target="_blank">prototype-based</a> languages. That’s a hard step with a ‘real’ object-oriented (Java, C#, C++) mindset. How can I implement inheritance? How can I hide data? How can I achieve polymorphism? Tough questions. Luckily along came design patterns. There are even a few books on the topic in JavaScript. Still, it’s not easy. I personally can recite 4-5 inheritance patterns. There are at least 2 data hiding patterns I can recall right now. </p> <p>Well, many options, with their own drawbacks. It’s not easy to choose, e.g. at the beginning of a new project. <strong>There is no universal solution. There is no good solution</strong>. You have to consider the tasks you have to do with your object model and the knowledge level of the colleagues. Usually the later is harder. <strong>How much knowledge people have about JavaScript</strong> in e.g. Java/C# world? As much as they get along the projects. They teach each other. To good and bed. What I saw in the last years, mostly obsolete and sometimes bad. Not easy to show them the current trends and solutions. Or may I say, contemporary engineering practices. People can, and usually are, be very proud of their coding style, quality, cleverness, etc. How can they be so neglect on these in an other language, e.g. JavaScript?</p> <p>Now there are <strong>frameworks</strong> for DOM manipulation (<a href="http://jquery.com/" target="_blank">jQuery</a>, <a href="http://dojotoolkit.org/" target="_blank">dojo</a>, <a href="http://developer.yahoo.com/yui/" target="_blank">YUI</a>), for common tasks (<a href="http://documentcloud.github.com/underscore/" target="_blank">Underscore</a>, <a href="http://developer.yahoo.com/yui/" target="_blank">YUI</a>, <a href="http://code.google.com/closure/" target="_blank">Closure</a>), and there are architectural frameworks (<a href="http://knockoutjs.com/" target="_blank">Knockout</a>, <a href="http://documentcloud.github.com/backbone/" target="_blank">Backbone</a>) as well. As you can see, they are fractured and you must use different frameworks for different tasks. You should choose well because it’s very very hard to change frameworks, and you have to watch out for compatibility. <strong>Framework version changes</strong> represent huge risk in the lifetime of a project. Even a minor version change can render your web application totally useless. So test heavily.</p> <p>No we have two ways. <strong>Full manual testing</strong> with a lot of humans. Or follow the ‘new’ trend and use some kind of <strong>automated test frameworks</strong> (<a href="http://seleniumhq.org/" target="_blank">Selenium</a>, <a href="http://watir.com/" target="_blank">Watir</a>). If they work the way you think. If it’s not more time to maintain your tests than execute them manually.</p> <p>The same applies to <strong>unit tests</strong>. There are various frameworks in different flavors (<a href="http://xunit.codeplex.com/" target="_blank">xUnit</a>, <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank">BDD</a>, etc.) with different capabilities and APIs. Some live long, some live short. Choose well. Update regularly. Follow the news, trends.</p> <p>Well, I chose a unit testing framework. Now I should test my code. How? It produces HTML into the DOM and calculates things according to different business rules – in the same function. Well, good luck. <strong>Try separating your business logic from visual stuff</strong>. Rings the bell? <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" target="_blank">MVC</a>? <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">MVVM</a>? Well, I’d say <a href="http://knockoutjs.com/" target="_blank">Knockout</a> and <a href="http://documentcloud.github.com/backbone/" target="_blank">Backbone</a>. I’d say use (revealing) module pattern for your view model and your rendering as well. Separate them. Use a framework, e.g. <a href="http://requirejs.org/" target="_blank">Require.js</a>. If you do it good, you can even get rid of the inheritance and other OO problems. Now you can test your business logic separated from the UI.</p> <p>Next problem: I have a <strong>dynamic <a href="http://en.wikipedia.org/wiki/Ajax_(programming)" target="_blank">AJAX</a> (AJAJ - Asynchronous Javascript and JSON) application calling back to the server</strong>. That’s not good. Let’s <a href="http://xunitpatterns.com/Test%20Spy.html" target="_blank">spy</a>. Let’s <a href="http://xunitpatterns.com/Test%20Stub.html" target="_blank">stub</a>. Let’s <a href="http://xunitpatterns.com/Mock%20Object.html" target="_blank">mock</a>. Find a framework, I chose <a href="http://sinonjs.org/" target="_blank">Sinon</a>. </p> <p>So, let’s summarize. I do my job well if I know functions, variables, OO patterns, DOM frameworks, task frameworks, architectural frameworks, testing frameworks, module patterns, JavaScript mocking frameworks. Is that enough?</p> <p>I have bed news. <strong>We in the web world develop applications like C++ coders develop applications for <a href="http://en.wikipedia.org/wiki/Microsoft_Windows" target="_blank">Windows</a>, <a href="http://en.wikipedia.org/wiki/Linux" target="_blank">Linux</a>, <a href="http://en.wikipedia.org/wiki/Berkeley_Software_Distribution" target="_blank">BSD</a>… at the same time with the same code base</strong>. Instead of OSs, we have browsers and JavaScript standard versions. Now we have mobile devices as well, with different kind of browsers. So keep up, learn and write code in JavaScript. It’s better to learn and understand it than hope for surviving it. <strong>The next few years are about JavaScript and the Web</strong>. Get used to it, accept it. <strong>Do it as good as you do your job on server-side.</strong></p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-25467091979459518372012-01-19T09:24:00.001+01:002012-01-19T09:24:35.036+01:00jQuery div vs native doc fragment<p>I assumed creating a div with jQuery takes more time compared to native document fragment creation. Surprise, I was wrong. I’ve created a test page on JSPerf at <a title="http://jsperf.com/jquery-vs-documentfragment" href="http://jsperf.com/jquery-vs-documentfragment">http://jsperf.com/jquery-vs-documentfragment</a>. Simply put, the speed depends on the browser.</p> <p><a title="jQuery div vs native document fragment performance" href="http://i63.photobucket.com/albums/h134/artur02/Blog/69c8d554.png" target="_blank"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/69c8d554.png" width="615" height="310"></a></p> <p><strong>Verdict</strong>: Use document fragment in all browsers except Internet Explorer. In general, use document fragment:</p><pre><code>document.createDocumentFragment();</code></pre> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-32776497848288318912011-11-14T13:11:00.001+01:002011-11-14T13:11:42.872+01:00Less CSS and IIS 7<p>In case you are using <a href="http://lesscss.org/">Less CSS</a> to generate CSS markups, IIS won’t find your <strong>.less</strong> files by default. You will get a <strong>404 Not Found</strong> error. The problem is the missing MIME type.</p> <p>The solution is simple, just register the MIME type for .less in web.config:</p> <pre><system.webServer><br /> <staticContent><br /> <mimeMap fileExtension=".less" mimeType="text/css"/><br /> </staticContent><br /></system.webServer></pre> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-50639863281753518882011-09-18T20:47:00.001+02:002011-09-19T18:40:56.259+02:00ASP.NET MVC Internals 3: Controller structureControllers implement the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.icontroller.aspx" target="_blank"><strong>IController</strong></a> interface:<br />
<pre class="brush: csharp; gutter: false; toolbar: false;">public interface IController
{
void Execute(RequestContext requestContext);
}</pre><a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controllerbase.aspx" target="_blank"><strong>ControllerBase</strong></a> abstract class implements the <em>IController</em> interface:<br />
<pre class="brush: csharp; gutter: false; toolbar: false; collapse: true;">public abstract class ControllerBase : MarshalByRefObject, IController
{
private TempDataDictionary _tempDataDictionary;
private bool _validateRequest = true;
private IDictionary<string, ValueProviderResult> _valueProvider;
private ViewDataDictionary _viewDataDictionary;
public ControllerContext ControllerContext {
get;
set;
}
public TempDataDictionary TempData {
get {
if (_tempDataDictionary == null) {
_tempDataDictionary = new TempDataDictionary();
}
return _tempDataDictionary;
}
set {
_tempDataDictionary = value;
}
}
public bool ValidateRequest {
get {
return _validateRequest;
}
set {
_validateRequest = value;
}
}
public IDictionary<string, ValueProviderResult> ValueProvider {
get {
if (_valueProvider == null) {
_valueProvider = new ValueProviderDictionary(ControllerContext);
}
return _valueProvider;
}
set {
_valueProvider = value;
}
}
public ViewDataDictionary ViewData {
get {
if (_viewDataDictionary == null) {
_viewDataDictionary = new ViewDataDictionary();
}
return _viewDataDictionary;
}
set {
_viewDataDictionary = value;
}
}
protected virtual void Execute(RequestContext requestContext) {
if (requestContext == null) {
throw new ArgumentNullException("requestContext");
}
Initialize(requestContext);
ExecuteCore();
}
protected abstract void ExecuteCore();
protected virtual void Initialize(RequestContext requestContext) {
ControllerContext = new ControllerContext(requestContext, this);
}
[...]
}</pre><a name='more'></a><br />
The <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.aspx" target="_blank"><strong>Controller</strong></a> class derives from <em>ControllerBase</em> abstract class:<br />
<pre class="brush: csharp; gutter: false; toolbar: false; collapse: true; highlight: [121];">public abstract class Controller : ControllerBase, IActionFilter, IAuthorizationFilter, IDisposable, IExceptionFilter, IResultFilter {
private IActionInvoker _actionInvoker;
private ModelBinderDictionary _binders;
private RouteCollection _routeCollection;
private ITempDataProvider _tempDataProvider;
public IActionInvoker ActionInvoker {
get {
if (_actionInvoker == null) {
_actionInvoker = new ControllerActionInvoker();
}
return _actionInvoker;
}
set {
_actionInvoker = value;
}
}
protected internal ModelBinderDictionary Binders {
get {
if (_binders == null) {
_binders = ModelBinders.Binders;
}
return _binders;
}
set {
_binders = value;
}
}
public HttpContextBase HttpContext {
get {
return ControllerContext == null ? null : ControllerContext.HttpContext;
}
}
public ModelStateDictionary ModelState {
get {
return ViewData.ModelState;
}
}
public HttpRequestBase Request {
get {
return HttpContext == null ? null : HttpContext.Request;
}
}
public HttpResponseBase Response {
get {
return HttpContext == null ? null : HttpContext.Response;
}
}
internal RouteCollection RouteCollection {
get {
if (_routeCollection == null) {
_routeCollection = RouteTable.Routes;
}
return _routeCollection;
}
set {
_routeCollection = value;
}
}
public RouteData RouteData {
get {
return ControllerContext == null ? null : ControllerContext.RouteData;
}
}
public HttpServerUtilityBase Server {
get {
return HttpContext == null ? null : HttpContext.Server;
}
}
public HttpSessionStateBase Session {
get {
return HttpContext == null ? null : HttpContext.Session;
}
}
public ITempDataProvider TempDataProvider {
get {
if (_tempDataProvider == null) {
_tempDataProvider = new SessionStateTempDataProvider();
}
return _tempDataProvider;
}
set {
_tempDataProvider = value;
}
}
public UrlHelper Url {
get;
set;
}
public IPrincipal User {
get {
return HttpContext == null ? null : HttpContext.User;
}
}
[...]
protected internal virtual ContentResult Content(string content, string contentType, Encoding contentEncoding) {
return new ContentResult {
Content = content,
ContentType = contentType,
ContentEncoding = contentEncoding
};
}
[...]
protected override void ExecuteCore() {
TempData.Load(ControllerContext, TempDataProvider);
try {
string actionName = RouteData.GetRequiredString("action");
if (!ActionInvoker.InvokeAction(ControllerContext, actionName)) {
HandleUnknownAction(actionName);
}
}
finally {
TempData.Save(ControllerContext, TempDataProvider);
}
}
[...]
protected internal virtual FilePathResult File(string fileName, string contentType, string fileDownloadName) {
return new FilePathResult(fileName, contentType) { FileDownloadName = fileDownloadName };
}
protected virtual void HandleUnknownAction(string actionName) {
throw new HttpException(404, String.Format(CultureInfo.CurrentUICulture,
MvcResources.Controller_UnknownAction, actionName, GetType().FullName));
}
protected internal virtual JavaScriptResult JavaScript(string script) {
return new JavaScriptResult { Script = script };
}
[...]
protected internal virtual JsonResult Json(object data, string contentType, Encoding contentEncoding) {
return new JsonResult {
Data = data,
ContentType = contentType,
ContentEncoding = contentEncoding
};
}
protected override void Initialize(RequestContext requestContext) {
base.Initialize(requestContext);
Url = new UrlHelper(requestContext);
}
protected virtual void OnActionExecuting(ActionExecutingContext filterContext) {
}
protected virtual void OnActionExecuted(ActionExecutedContext filterContext) {
}
protected virtual void OnAuthorization(AuthorizationContext filterContext) {
}
protected virtual void OnException(ExceptionContext filterContext) {
}
protected virtual void OnResultExecuted(ResultExecutedContext filterContext) {
}
protected virtual void OnResultExecuting(ResultExecutingContext filterContext) {
}
[...]
protected internal PartialViewResult PartialView(string viewName) {
return PartialView(viewName, null /* model */);
}
protected internal virtual PartialViewResult PartialView(string viewName, object model) {
if (model != null) {
ViewData.Model = model;
}
return new PartialViewResult {
ViewName = viewName,
ViewData = ViewData,
TempData = TempData
};
}
protected internal virtual RedirectResult Redirect(string url) {
[...]
return new RedirectResult(url);
}
protected internal RedirectToRouteResult RedirectToAction(string actionName) {
return RedirectToAction(actionName, (RouteValueDictionary)null);
}
[...]
protected internal virtual RedirectToRouteResult RedirectToAction(string actionName, string controllerName, RouteValueDictionary routeValues) {
RouteValueDictionary mergedRouteValues;
if (RouteData == null) {
mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, null, routeValues, true /* includeImplicitMvcValues */);
}
else {
mergedRouteValues = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, RouteData.Values, routeValues, true /* includeImplicitMvcValues */);
}
return new RedirectToRouteResult(mergedRouteValues);
}
[...]
protected internal RedirectToRouteResult RedirectToRoute(string routeName) {
return RedirectToRoute(routeName, (RouteValueDictionary)null);
}
[...]
protected internal bool TryUpdateModel<TModel>(TModel model) where TModel : class {
return TryUpdateModel(model, null, null, null, ValueProvider);
}
[...]
protected internal bool TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties, IDictionary<string, ValueProviderResult> valueProvider) where TModel : class {
[...]
Predicate<string> propertyFilter = propertyName => BindAttribute.IsPropertyAllowed(propertyName, includeProperties, excludeProperties);
IModelBinder binder = Binders.GetBinder(typeof(TModel));
ModelBindingContext bindingContext = new ModelBindingContext() {
Model = model,
ModelName = prefix,
ModelState = ModelState,
ModelType = typeof(TModel),
PropertyFilter = propertyFilter,
ValueProvider = valueProvider
};
binder.BindModel(ControllerContext, bindingContext);
return ModelState.IsValid;
}
protected internal void UpdateModel<TModel>(TModel model) where TModel : class {
UpdateModel(model, null, null, null, ValueProvider);
}
[...]
protected internal void UpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties, IDictionary<string, ValueProviderResult> valueProvider) where TModel : class {
bool success = TryUpdateModel(model, prefix, includeProperties, excludeProperties, valueProvider);
if (!success) {
string message = String.Format(CultureInfo.CurrentUICulture, MvcResources.Controller_UpdateModel_UpdateUnsuccessful,
typeof(TModel).FullName);
throw new InvalidOperationException(message);
}
}
protected internal ViewResult View() {
return View(null /* viewName */, null /* masterName */, null /* model */);
}
protected internal ViewResult View(object model) {
return View(null /* viewName */, null /* masterName */, model);
}
protected internal ViewResult View(string viewName) {
return View(viewName, null /* masterName */, null /* model */);
}
protected internal ViewResult View(string viewName, string masterName) {
return View(viewName, masterName, null /* model */);
}
protected internal ViewResult View(string viewName, object model) {
return View(viewName, null /* masterName */, model);
}
protected internal virtual ViewResult View(string viewName, string masterName, object model) {
if (model != null) {
ViewData.Model = model;
}
return new ViewResult {
ViewName = viewName,
MasterName = masterName,
ViewData = ViewData,
TempData = TempData
};
}
protected internal ViewResult View(IView view) {
return View(view, null /* model */);
}
protected internal virtual ViewResult View(IView view, object model) {
if (model != null) {
ViewData.Model = model;
}
return new ViewResult {
View = view,
ViewData = ViewData,
TempData = TempData
};
}
#region IActionFilter Members
void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) {
OnActionExecuting(filterContext);
}
void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) {
OnActionExecuted(filterContext);
}
#endregion
#region IAuthorizationFilter Members
void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext) {
OnAuthorization(filterContext);
}
#endregion
#region IExceptionFilter Members
void IExceptionFilter.OnException(ExceptionContext filterContext) {
OnException(filterContext);
}
#endregion
#region IResultFilter Members
void IResultFilter.OnResultExecuting(ResultExecutingContext filterContext) {
OnResultExecuting(filterContext);
}
void IResultFilter.OnResultExecuted(ResultExecutedContext filterContext) {
OnResultExecuted(filterContext);
}
#endregion
}</pre>The Controller class implements the <em>ExecuteCore()</em> function. It sets the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.tempdatadictionary.aspx" target="_blank"><em>TempData</em></a> to make it available during the action method execution. The method reads the action name from the <em>RouteData</em> and calls the action method, identified by the recently read name, using the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iactioninvoker.aspx" target="_blank"><em>ActionInvoker.InvokeAction()</em></a> method. <br />
All the usually used helper methods such as <a href="http://msdn.microsoft.com/en-us/library/dd460331.aspx" target="_blank"><em>View()</em></a>, <a href="http://msdn.microsoft.com/en-us/library/dd470933.aspx" target="_blank"><em>UpdateModel()</em></a>, <a href="http://msdn.microsoft.com/en-us/library/dd492492.aspx" target="_blank"><em>File()</em></a>, <a href="http://msdn.microsoft.com/en-us/library/dd504936.aspx" target="_blank"><em>Json()</em></a> are defined by the Controller class. <br />
<a href="http://s63.photobucket.com/albums/h134/artur02/Blog/?action=view&current=d37cdc78.png" target="_blank"><img alt="ASP.NET MCV: Controller inheritance" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/th_d37cdc78.png" /></a><br />
Link: <a href="http://artur02.googlecode.com/svn/trunk/AspNetMvc/RequestPipeline/Controller.png" target="_blank">ASP.NET MVC – Controller inheritance</a>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-45398596159614248932011-09-17T18:42:00.001+02:002011-09-19T18:47:24.558+02:00ASP.NET MVC Internals 2: ControllerThe <em><strong>MvcHandler</strong></em> class processes an HTTP request. The routing framework calls its <em>ProcessRequest()</em> function in case of an incoming request matching an MVC route.<br />
<pre class="brush: csharp; toolbar: false;">public class MvcHandler : IHttpHandler, IRequiresSessionState
{
[...]
protected internal virtual void ProcessRequest(HttpContextBase httpContext)
{
AddVersionHeader(httpContext);
// Get the controller type
string controllerName = RequestContext.RouteData.GetRequiredString(&quot;controller&quot;);
// Instantiate the controller and call Execute
IControllerFactory factory = ControllerBuilder.GetControllerFactory();
IController controller = factory.CreateController(RequestContext, controllerName);
if (controller == null) {
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentUICulture,
MvcResources.ControllerBuilder_FactoryReturnedNull,
factory.GetType(),
controllerName));
}
try {
controller.Execute(RequestContext);
}
finally {
factory.ReleaseController(controller);
}
}
[...]
}</pre><p>Firstly it reads the controller name from the routing data and after that it creates a controller by the name read before. Finally it calls the <em>Execute</em> method of the controller to run the controller’s code.<br />
<br />
<a name='more'></a><br />
<br />
The <em><strong>ControllerBuilder</strong></em> is a factory for creating the controller instance. </p><pre class="brush: csharp; toolbar: false; highlight: [8];">public class ControllerBuilder
{
[...]
private Func<IControllerFactory> _factoryThunk;
public ControllerBuilder()
{
SetControllerFactory(new DefaultControllerFactory() {
ControllerBuilder = this
});
}
[...]
public IControllerFactory GetControllerFactory() {
IControllerFactory controllerFactoryInstance = _factoryThunk();
return controllerFactoryInstance;
}
public void SetControllerFactory(IControllerFactory controllerFactory)
{
if (controllerFactory == null) {
throw new ArgumentNullException("controllerFactory");
}
_factoryThunk = () => controllerFactory;
}
[...]
}</pre>The constructor of the class at line 8 calls the <em>SetControllerFactory</em> method with a <em>DefaultControllerFactory</em> instance. Thus the <em><strong>DefaultControllerFactory</strong></em> class will look up and call the controller with the name provided by the <em>RouteData</em>.<br />
<pre class="brush: csharp; gutter: false; toolbar: false;">public class DefaultControllerFactory : IControllerFactory
{
private IBuildManager _buildManager;
private ControllerBuilder _controllerBuilder;
private ControllerTypeCache _instanceControllerTypeCache;
private static ControllerTypeCache _staticControllerTypeCache = new ControllerTypeCache();
[...]
public virtual IController CreateController(RequestContext requestContext, string controllerName)
{
[...]
RequestContext = requestContext;
Type controllerType = GetControllerType(controllerName);
IController controller = GetControllerInstance(controllerType);
return controller;
}
protected internal virtual IController GetControllerInstance(Type controllerType)
{
[...]
try {
return (IController)Activator.CreateInstance(controllerType);
}
catch (Exception ex) {
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentUICulture,
MvcResources.DefaultControllerFactory_ErrorCreatingController,
controllerType),
ex);
}
}
protected internal virtual Type GetControllerType(string controllerName)
{
[...]
// first search in the current route's namespace collection
object routeNamespacesObj;
Type match;
[...]
// then search in the application's default namespace collection
[...]
// if all else fails, search every namespace
return GetControllerTypeWithinNamespaces(controllerName, null /* namespaces */);
}
private Type GetControllerTypeWithinNamespaces(string controllerName, HashSet<string> namespaces)
{
// Once the master list of controllers has been created we can quickly index into it
ControllerTypeCache.EnsureInitialized(BuildManager);
IList<Type> matchingTypes = ControllerTypeCache.GetControllerTypes(controllerName, namespaces);
switch (matchingTypes.Count) {
case 0:
// no matching types
return null;
case 1:
// single matching type
return matchingTypes[0];
default:
// multiple matching types
// we need to generate an exception containing all the controller types
StringBuilder sb = new StringBuilder();
foreach (Type matchedType in matchingTypes) {
sb.AppendLine();
sb.Append(matchedType.FullName);
}
throw new InvalidOperationException([...]);
}
}
}</pre>As soon as the <em>DefaultControllerFactory.CreateController</em> function, it finds the type of the controller by its name and creates an instance after that. The framework uses the <em><strong>ControllerTypeCache</strong></em> class to find the controller types. <br />
<pre class="brush: csharp; gutter: false; toolbar: false;">internal sealed class ControllerTypeCache
{
[...]
public void EnsureInitialized(IBuildManager buildManager)
{
if (_cache == null) {
lock (_lockObj) {
if (_cache == null) {
List<Type> controllerTypes = GetAllControllerTypes(buildManager);
[...]
}
}
}
}
private static List<Type> GetAllControllerTypes(IBuildManager buildManager)
{
// Go through all assemblies referenced by the application and search for
// controllers and controller factories.
List<Type> controllerTypes = new List<Type>();
ICollection assemblies = buildManager.GetReferencedAssemblies();
foreach (Assembly assembly in assemblies) {
Type[] typesInAsm;
try {
typesInAsm = assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex) {
typesInAsm = ex.Types;
}
controllerTypes.AddRange(typesInAsm.Where(IsControllerType));
}
return controllerTypes;
}
[...]
internal static bool IsControllerType(Type t) {
return
t != null &&
t.IsPublic &&
t.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase) &&
!t.IsAbstract &&
typeof(IController).IsAssignableFrom(t);
}
}</pre>The <em>ControllerTypeCache.EnsureInitialized</em> (called by <em>DefaultControllerFactory.GetControllerTypeWithinNamespaces</em>) uses the <a href="http://msdn.microsoft.com/en-us/library/system.web.compilation.buildmanager.aspx" target="_blank">BuildManager</a> class (in MVC, wrapped by <em>BuildManagerWrapper</em> that implements the internal <em>IBuildManager</em> interface) to find the available assemblies. The <em>ControllerTypeCache.GetAllControllerTypes</em> returns the controller types referenced by the project. A class is a controller type if the class is<br />
<ul><li>public </li>
<li>its name ends with “Controller”, casing is ignored </li>
<li>the type is not abstract </li>
<li>the type “implements” (can be assigned to) the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.icontroller.aspx" target="_blank">IController</a> interface. </li>
</ul>Finally the <em>DefaultControllerFactory.GetControllerInstance</em> creates the instance for the Type using <a href="http://msdn.microsoft.com/en-us/library/wccyzw83.aspx" target="_blank"><em>Activator.CreateInstance()</em></a> method. Now we have the controller instance to work with.<br />
The <em>MvcHandler.ProcessRequest()</em> calls the <em>controller.Execute()</em> to run the controller code.<br />
<a href="http://s63.photobucket.com/albums/h134/artur02/Blog/?action=view&current=80d84305.png" target="_blank"><img alt="ASP.NET MVC Finding Controller" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/th_80d84305.png" /></a> <br />
Link: <a href="http://i63.photobucket.com/albums/h134/artur02/Blog/80d84305.png" target="_blank">ASP.NET MVC – Finding the controller</a>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-27155340657695804032011-09-15T10:11:00.001+02:002011-09-17T20:14:43.597+02:00ASP.NET MVC Internals 1: Bootstrapping<p>The topic of this article is the ASP.NET MVC bootstrapping process.</p><p>Everything starts in <strong>Global.asax</strong>:</p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:795f1de5-a86c-43dd-b1b2-1ff40b358afe" class="wlWriterEditableSmartContent"><pre class="brush: c#;gutter:false;toolbar:false;">public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}</pre></div><p>This code initializes the ASP.NET Routing framework. The MapRoute() function is an extension method, defined in <strong>RouteCollectionExtensions.cs</strong>. It’s code is simple:</p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:984baf9e-d0f4-4ab5-8eec-0df8ecacf521" class="wlWriterEditableSmartContent"><pre class="brush: c#;toolbar:false;">public static Route MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) {
if (routes == null) {
throw new ArgumentNullException("routes");
}
if (url == null) {
throw new ArgumentNullException("url");
}
Route route = new Route(url, new MvcRouteHandler()) {
Defaults = new RouteValueDictionary(defaults),
Constraints = new RouteValueDictionary(constraints)
};
if ((namespaces != null) && (namespaces.Length > 0)) {
route.DataTokens = new RouteValueDictionary();
route.DataTokens["Namespaces"] = namespaces;
}
routes.Add(name, route);
return route;
}</pre></div><p>Simply creates a route with an MvcRouteHandler at line 9. ASP.NET MVC registers this routing handler to catch the routing requests (<strong>MvcRouteHandler.cs</strong>):</p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:dc078b00-3c45-4e1d-944a-151f58006284" class="wlWriterEditableSmartContent"><pre class="brush: c#;gutter:false;toolbar:false;">namespace System.Web.Mvc {
using System.Web.Routing;
public class MvcRouteHandler : IRouteHandler {
protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext) {
return new MvcHandler(requestContext);
}
#region IRouteHandler Members
IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext) {
return GetHttpHandler(requestContext);
}
#endregion
}
}</pre></div><p>This code registers the MvcHandler class (<strong>MvcHandler.cs</strong>) for handling MVC routing requests:</p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:e22c9dd9-8d14-48ee-ac83-7183e35a997f" class="wlWriterEditableSmartContent"><pre class="brush: c#;gutter:false;toolbar:false;">public class MvcHandler : IHttpHandler, IRequiresSessionState
{ [...] }</pre></div><p>The class implements the <a href="http://msdn.microsoft.com/en-us/library/7ezc17x8.aspx" target="_blank">IHttpHandler</a> interface from System.Web.dll to be able to ‘synchronously process HTTP Web requests using custom HTTP handlers’. This interface has only one method: </p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b7435f46-307c-478a-848b-0268d0674fb1" class="wlWriterEditableSmartContent"><pre class="brush: c#;gutter:false;toolbar:false;">void ProcessRequest(httpContext context)</pre></div><p>The implementation of this method will handle the HTTP request. It builds up the MVC infrastructure and calls the appropriate classes (in transitive way) to select the controller, find the action method and do all the related functionality.</p><p><a href="http://s63.photobucket.com/albums/h134/artur02/Blog/?action=view&current=f63d836e.png" target="_blank"><img src="http://i63.photobucket.com/albums/h134/artur02/Blog/th_f63d836e.png" border="0" alt="Photobucket" ></a><br />
</p><p>Link: <a href="http://i63.photobucket.com/albums/h134/artur02/Blog/f63d836e.png" target="_blank">ASP.MET MVC Bootstrapping process</a></p>Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-91387919094108804562010-12-12T18:34:00.001+01:002010-12-12T18:34:37.813+01:00jQuery and DOM dimension measurement<p>I had to rewrite a code that used standard DOM functions (like offsetWidth) to jQuery functions (like outerWidth). <br />This is a simple document visually summarizing the differences.</p> <p>Link: <a href="http://code.google.com/p/artur02/source/browse/trunk/docs/jQueryHtmlHeight/jQueryHtmlHeight.docx?r=10" target="_blank">jQuery HMTL with height cheat sheet (DOCX)</a> <br />Link: <a href="http://code.google.com/p/artur02/source/browse/trunk/docs/jQueryHtmlHeight/jQueryHtmlHeight.pdf?r=10" target="_blank">jQuery HMTL with height cheat sheet (PDF)</a></p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-41578400891211603632010-11-22T21:54:00.001+01:002010-11-22T21:54:10.764+01:00WaitableTimer in C++<p>This is an example code for calling a <strong>waitable timer</strong>. This is a good way to wait for a timer event without using CPU (thread blocks). There is a small <strong>trick in the code</strong>. It’s hard to create a FILETIME properly so I create a SYSTEMTIME (and set it according to my needs), convert it to FILETIME, finally I cast that to LARGE_INTEGER* (to fulfill the needs of SetWaitableTimer).</p> <p>I set the timer to <strong>autoreset</strong>, so it will restart counting after firing the event (counts again and again). The first event (“CALLED”) occurs after 3 secs, the subsequent events occur after 2 secs.</p> <p>The <strong>WaitForSingleObject</strong> blocks until a timer event is fired. I break the loop after 5 events, stop the timer and delete the timer handle.</p> <h3>stdafx.h</h3> <div id="codeSnippetWrapper"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #cc6633">#pragma</span> <span style="color: #cc6633">once</span><br /><br /><span style="color: #cc6633">#include</span> <span style="color: #006080">"targetver.h"</span><br /><br /><span style="color: #cc6633">#include</span> <stdio.h><br /><span style="color: #cc6633">#include</span> <tchar.h><br /><span style="color: #cc6633">#include</span> <iostream><br /><span style="color: #cc6633">#include</span> <Windows.h><br /><br /><span style="color: #0000ff">using</span> <span style="color: #0000ff">namespace</span> std;</pre>
<br /></div>
<h3>WaitableTimer.cpp</h3>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #cc6633">#include</span> <span style="color: #006080">"stdafx.h"</span><br /><br /><span style="color: #0000ff">int</span> _tmain(<span style="color: #0000ff">int</span> argc, _TCHAR* argv[])<br />{<br /> <span style="color: #0000ff">int</span> count = 0; <span style="color: #008000">// Iteration counter</span><br /><br /> HANDLE hTimer = NULL; <span style="color: #008000">// WaitableTimer handle</span><br /> hTimer = CreateWaitableTimer( <span style="color: #008000">// Create waitable timer</span><br /> NULL,<br /> <span style="color: #0000ff">FALSE</span>, <span style="color: #008000">// Autoreset --> timer restarts counting after event fired</span><br /> NULL);<br /><br /> SYSTEMTIME time; <span style="color: #008000">// System time structure</span><br /> GetSystemTime(&time); <span style="color: #008000">// Curren time</span><br /> time.wSecond += 3; <span style="color: #008000">// Wait 3 sec</span><br /><br /> FILETIME ftime; <span style="color: #008000">// File time (expected by SetWaitableTimer)</span><br /> SystemTimeToFileTime(&time, &ftime); <span style="color: #008000">// Convert system to file time</span><br /><br /><br /> <span style="color: #0000ff">if</span>(!SetWaitableTimer( <span style="color: #008000">// Set waitable timer</span><br /> hTimer, <span style="color: #008000">// Timer handle</span><br /> <span style="color: #0000ff">reinterpret_cast</span><LARGE_INTEGER*>(&ftime), <span style="color: #008000">// Convert file time to large integer</span><br /> 2000, <span style="color: #008000">// Period time, fire again after 2 sec</span><br /> NULL,<br /> NULL,<br /> 0))<br /> {<br /> cout << <span style="color: #006080">"SetWaitableTimer failed"</span> << GetLastError() << endl;<br /> };<br /><br /> <br /> <span style="color: #0000ff">while</span>(WaitForSingleObject(hTimer, 5000) == WAIT_OBJECT_0){ <span style="color: #008000">// Wait for timer event</span><br /> cout << <span style="color: #006080">"CALLED "</span> << ++count << endl;<br /> <span style="color: #0000ff">if</span>(count+1 > 5){ <span style="color: #008000">// Exit after 5 events</span><br /> <span style="color: #0000ff">break</span>;<br /> }<br /> }<br /> <br /> CancelWaitableTimer(hTimer); <span style="color: #008000">// Stop timer</span><br /> CloseHandle(hTimer); <span style="color: #008000">// Delete handle</span><br /><br /> <span style="color: #0000ff">return</span> 0;<br />}</pre>
<br /></div>
<p><strong>See source code</strong>: <a href="http://code.google.com/p/artur02/source/browse/trunk/CPP/WaitableTimer/WaitableTimer.cpp">http://code.google.com/p/artur02/source/browse/trunk/CPP/WaitableTimer/WaitableTimer.cpp</a></p>
<p>Waitable timer objects: <a href="http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms687012(VS.85).aspx</a>
<br />CreateWaitableTimer function: <a href="http://msdn.microsoft.com/en-us/library/ms682492(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms682492(v=VS.85).aspx</a>
<br />SetWaitableTimer function: <a href="http://msdn.microsoft.com/en-us/library/ms686289(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms686289(v=VS.85).aspx</a>
<br />Systemtime structure: <a href="http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx</a>
<br />Usage example: <a href="http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/ms687008(v=VS.85).aspx</a></p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0tag:blogger.com,1999:blog-581522584150589505.post-23366339394228521022010-11-06T12:03:00.001+01:002010-11-06T12:03:51.585+01:00Perforce file exclusion<p>There are file types and folders I don’t want to see in a source control repository. These are user-specific settings, temporary folders and binaries. There is a simple client-side way to exclude these files and folders. Just add the following lines to your workspace definition:</p> <table border="1" cellspacing="0" cellpadding="2" width="598"><tbody> <tr> <td valign="top" width="363"><strong>Pattern</strong></td> <td valign="top" width="233"><strong>Description</strong></td> </tr> <tr> <td valign="top" width="363"> <pre>-//depot/.../*.suo //WORKSPACE/.../*.suo</pre>
</td>
<td valign="top" width="233">Solution user options file.</td>
</tr>
<tr>
<td valign="top" width="363">
<pre>-//depot/.../bin/... //WORKSPACE/.../bin/...</pre>
</td>
<td valign="top" width="233">Generated binaries.</td>
</tr>
<tr>
<td valign="top" width="363">
<pre>-//depot/.../obj/... //WORKSPACE/.../obj/...</pre>
</td>
<td valign="top" width="233">Object files.</td>
</tr>
<tr>
<td valign="top" width="363">
<pre>-//depot/.../*.user //WORKSPACE/.../*.user</pre>
</td>
<td valign="top" width="233">User settings. Can contain useful information, e.g. startup parameters.</td>
</tr>
</tbody></table> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com1tag:blogger.com,1999:blog-581522584150589505.post-50845357581287526322010-11-06T11:51:00.001+01:002010-11-06T11:52:28.100+01:00CV Tag Cloud<p><a href="http://www.wordle.net/show/wrdl/2686570/CV" target="_blank"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" border="0" src="http://i63.photobucket.com/albums/h134/artur02/Blog/6466b550.png" /></a></p> <p>The tag cloud of my CV. Can be viewed in full size: <a href="http://www.wordle.net/show/wrdl/2686570/CV">http://www.wordle.net/show/wrdl/2686570/CV</a></p> Anonymoushttp://www.blogger.com/profile/06980674445694201967noreply@blogger.com0