Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367 Scattered Code – Page 2 – Just another opsAI site

Mapping database objects to models – the Lambda way

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

Updated with statements that can be executed or deferred. // Example models public class SomeModel { public int Id { get; set; } public string Name { get; set; } public List Items { get; set; } } public class SomeOtherModel { public int Id { get; set; } public string Text { get; set; } } //Expression mapper - not executed public Expr<Func> Map_SomeTable_SomeModel_Expr() { return x => new SomeModel { Id = x.Id, Name = x.Name, Items = db.SomeOtherTable.Where(y => y.SomeTableId == x.Id).Select(Map_SomeOtherTable_SomeOtherModel_Expr()).ToList() } } //Function mapper -...

Localization in c#

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

Localization in C# is very straightforward. C# comes with Resource files, which are great because they can be easily translated, and C# can switch between them automatically.   First, add a new Resource File to your project. In my case, I called it SiteFields.resx. This will be the default language file, which in this case is English.   Next, we create a Localized Display Name Attribute, so we can leverage our ViewModels properly, instead of relying on text. public class LocalizedDisplayNameAttribute : DisplayNameAttribute { public LocalizedDisplayNameAttribute(string resourceId) : base(GetMessageFromResource(resourceId)) {...

Domain Routes and using subdomains in MVC as routes

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

I came across this when trying to build a website that takes advantage of sub domains in a MVC project. You can route subdomains in MVC to a particular controller, and specific actions.   In order to do this, you must make your website listen directly on the IP Address, and point a wildcard A record for all subdomains. In IIS 7, under Bindings, add a binding for http or https, set the IP to the dedicated IP for the site, and leave the Host name empty.   In your...

Accessing indesign server from C# via COM

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

I've done quite a bit of searching on InDesign Server, and according to the people at Adobe, C# isn't "dynamic" enough for use with their API. But obviously, they were looking at Java documentation mislabeled C# or at some very old books. Anyway, a lot of things in their documentation are misleading, so I will attempt to get you started on the right path to using InDesign Server CS6 from C# via COM objects.   First thing I did was install the trial, which needs to be activated before the...

C# Thumbnail

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

In this tutorial I'll share how I create a c# thumbnail for each photo on our websites, and keep track of how many different sizes I need to use, while keeping images small for efficient load time, and efficient for server load. I will attach the Thumbnailer class at the end of the post. The thumbnailer can handle fixed width & height risize/crop, proportional resizing, width & height constraint resizing. The Thumbnailer can be used directly as an IHttpHandler or as a helper class for for another handler in your...

jQuery DataTables with dynamic datasource refresh

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

jQuery Datatables is one of the best libraries I've used and supports just an incredible amount of features, however, I found it difficult to change the data source since it's created dynamically from other elements on the page (dropdown, date fields), so I came up with destroying and re-creating the table.   First, we import the library and create the Table, with the header columns defined. <table class="display datatable" id="example"> <thead> <tr> <th>Email</th> <th>Name</th> <th>Office</th> </tr> </thead> </table>   Next, I have a few data filters on the page Last...

C# Serializable Dictionary

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

The Dictionary class included in C# isn't serializable, so you can use the following Serializable Dictionary whenever you need to serialize your objects [Serializable] public class SerializableDictionary : Dictionary, IXmlSerializable, ISerializable { #region Private Properties protected XmlSerializer ValueSerializer { get { return _valueSerializer ?? (_valueSerializer = new XmlSerializer(typeof(TVal))); } } private XmlSerializer KeySerializer { get { return _keySerializer ?? (_keySerializer = new XmlSerializer(typeof(TKey))); } } #endregion #region Private Members private XmlSerializer _keySerializer; private XmlSerializer _valueSerializer; #endregion #region Constructors public SerializableDictionary() { } public SerializableDictionary(IDictionary dictionary) : base(dictionary) { } public...

Compiling code on the fly in C#

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

Compile and run code created on the fly from a string or file. Compiler c = new Compiler(); StreamReader reader = new StreamReader(/*Path to my source file, optional*/); string compilationsource = reader.ReadToEnd(); //read from file or create on-the-fly CodeContainer result = new CodeContainer(); result.CompiledAssembly = c.Compile(compilationsource); result.SourceCode = compilationsource; result.Execute("MyMethod", new object[] { MyClass }); //Send in any parameters you need A lot more functionality than presented above is possible. To make this possible, you'll need the following Compiler class using System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Generic;...

C# CSV files

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

This NuGet package I found calle CSVHelper, lets you create an object representation of a CSV file, to read and write CSV files with ease, and use linq on them.   You first need to get CsvHelper from NuGet Add a reference to the libraries you got using CsvHelper; using CsvHelper.Configuration;   Create a Model to match the CSV file. You can reference columns by Index or Name (You can only reference by name if the CSV file contains a header) using System; using System.Collections.Generic; using System.Linq; using System.Text; using...

C# Reflection

Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1174 Warning: Invalid argument supplied for foreach() in D:\home\site\wwwroot\wp-includes\translations.php on line 1367

C# Reflection copy every property of a class to another class with the same properties.   Let's say you have to copy all the values of the properties of a class to another (maybe larger) class, but there's no inheritance between them. You can achieve this using reflection very simply. foreach (var prop in item.GetType().GetProperties()) { var p2 = outputModel.GetType().GetProperty(prop.Name); p2.SetValue(outputModel, prop.GetValue(item, null), null); }