Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan Van der Haegen janvanderhaegen

View GitHub Profile
@janvanderhaegen
janvanderhaegen / ExpressionCombiner
Created September 5, 2014 19:59
C# code to combine two lambda expressions
View ExpressionCombiner
//Shoutout to MBoros on stackoverflow
public static class ExpressionCombiner {
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> exp, Expression<Func<T, bool>> newExp)
{
// get the visitor
var visitor = new ParameterUpdateVisitor(newExp.Parameters.First(), exp.Parameters.First());
// replace the parameter in the expression just created
newExp = visitor.Visit(newExp) as Expression<Func<T, bool>>;
// now you can and together the two expressions
@janvanderhaegen
janvanderhaegen / LoadOnDemandExtensions.cs
Last active January 19, 2020 05:42
Loading of collections in the desktop client on a 'need to see' basis.
View LoadOnDemandExtensions.cs
using Microsoft.LightSwitch.Client;
using Microsoft.LightSwitch.Details.Client;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;
using Microsoft.LightSwitch.Presentation.Internal;
using Microsoft.LightSwitch.Sdk.Proxy;
using Microsoft.VisualStudio.ExtensibilityHosting;
using System;
using System.Collections.Generic;
@janvanderhaegen
janvanderhaegen / myscreen.lsml.js
Created October 7, 2014 00:57
SP Overlay: CSS
View myscreen.lsml.js
myapp.menuHome.buttonResources_postRender = function (element, contentItem) {
$(element).spOverlay(contentItem, 'Content/Images/TouchIcons/ResourcesLarge.png', { height:170, width:170});
};
myapp.menuHome.buttonDesigns_postRender = function (element, contentItem) {
$(element).spOverlay(contentItem, 'Content/Images/TouchIcons/DesignsLarge.png');
};
myapp.menuHome.buttonProjects_postRender = function (element, contentItem) {
$(element).spOverlay(contentItem, 'Content/Images/TouchIcons/ProjectsLarge.png');
@janvanderhaegen
janvanderhaegen / script.js
Last active May 2, 2018 20:34
Keep your site hot
View script.js
function CheckMySite() {
//Thanks to Sandrino Di Mattia: http://fabriccontroller.net/blog/posts/job-scheduling-in-windows-azure/
warmUpSite("https://mysite.azurewebsites.net/HTMLClient/default.htm");
warmUpSite("https://mysecondsite.azurewebsites.net/HTMLClient/default.htm");
}
function warmUpSite(url) {
var currentdate = new Date();
@janvanderhaegen
janvanderhaegen / ColorBackground
Created January 22, 2014 14:29
Colors the background of a control.
View ColorBackground
public static IEnumerable<IContentItemPresenter> GetAssociatedPresenters(this IContentItem contentItem)
{
var internale = contentItem as IContentItemInternal;
if (internale == null)
return new List<IContentItemPresenter>();
return internale.AssociatedPresenters;
}
public static void SetBackground(this IContentItemPresenter presenter, Color color)
@janvanderhaegen
janvanderhaegen / FindContentItems.cs
Created January 22, 2014 14:25
Finds contentitems for an IEntityProperty
View FindContentItems.cs
public static List<IContentItem> FindContentItems(this IScreenObject screen, IEntityProperty viewModel)
{
IPresentationScreenView screenView = VsExportProviderService
.GetServiceFromCache<IServiceProxy>().ScreenViewService.GetScreenView(screen) as IPresentationScreenView;
if (screenView == null)
{
throw new InvalidOperationException();
}
IContentItem currentView = screenView.ContentItemTree;
View LightSwitch T4 Template
<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Xml.dll" #>
<#@ Assembly Name="System.Xml.Linq.dll" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
@janvanderhaegen
janvanderhaegen / Script.SampleCustomers.sql
Created September 24, 2013 09:05
Inserts a couple of sample customers and orders
View Script.SampleCustomers.sql
SET IDENTITY_INSERT [dbo].[Customers] ON;
MERGE INTO [dbo].[Customers] AS Target
USING (VALUES
(1, 'Beth Massi', 'F', 'Burg 1', '8000', 'Brugge', 'Belgium', 1.00),
(2, 'Chris Rummel', 'M', 'Burg 1', '8000', 'Brugge', 'Belgium', 0.90 ),
(3, 'Matt Evans', 'M', 'Burg 1', '8000', 'Brugge', 'Belgium', 0.80 ),
(4, 'Andy Kung', 'M', 'Burg 1', '8000', 'Brugge', 'Belgium', 0.70 ),
(5, 'Brian Moore', 'M', 'Burg 1', '8000', 'Brugge', 'Belgium', 0.60 ),
(6, 'Matt Sampson', 'F', 'Burg 1', '8000', 'Brugge', 'Belgium', 0.50 ),
@janvanderhaegen
janvanderhaegen / GetScreensFromModelService
Created September 20, 2013 23:40
Get an overview of all screens from the model service.
View GetScreensFromModelService
private static IEnumerable<string> _allScreens;
static BuildingBlockProvider()
{
List<string> screens = new List<string>();
foreach (var screenModel in ServiceProxy.Instance.ModelService.Items.OfType<IScreenDefinition>())
{
if (screenModel.Members.Any(m => m.Attributes.OfType<IIsParameterAttribute>().Any(att => !(att.Parent as IScreenPropertyDefinition).PropertyType.Name.EndsWith("?")))) {
continue;
}
@janvanderhaegen
janvanderhaegen / lightswitch.bing-maps.js
Created August 22, 2013 18:08
JQuery UI Widget for LightSwitch's Bing Map control
View lightswitch.bing-maps.js
/// <reference path="JQuery/jquery-1.6.1.js" />
/// <reference path="JQueryMobile/jquery.mobile-1.0.js" />
/// <reference path="../Libraries/MsLs/msls-1.0.0.js" />
/// <reference path="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0" />
/*
Usage example
myapp.AddEditCustomer.HowDoIGetThere_execute = function (screen) {
$("#addressMap").lightswitchBingMapsControl("getLocationOfUser", $("#directions"));
};