GIT: perform LF normalization

This commit is contained in:
Gary Sharp
2013-02-28 17:15:46 +11:00
parent 989f08a24d
commit 7d9be5620d
729 changed files with 300734 additions and 300712 deletions
@@ -1,27 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Expressions.Parser.antlr;
namespace Disco.BI.Expressions
{
public class EvaluateExpressionParseException
{
public string Expression { get; set; }
public int PositionRow { get; set; }
public int PositionColumn { get; set; }
public string Message { get; set; }
internal static EvaluateExpressionParseException FromRecognitionException(RecognitionException e, string Expression)
{
return new EvaluateExpressionParseException()
{
Expression = Expression,
Message = e.Message,
PositionRow = e.getLine(),
PositionColumn = e.getColumn()
};
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Expressions.Parser.antlr;
namespace Disco.BI.Expressions
{
public class EvaluateExpressionParseException
{
public string Expression { get; set; }
public int PositionRow { get; set; }
public int PositionColumn { get; set; }
public string Message { get; set; }
internal static EvaluateExpressionParseException FromRecognitionException(RecognitionException e, string Expression)
{
return new EvaluateExpressionParseException()
{
Expression = Expression,
Message = e.Message,
PositionRow = e.getLine(),
PositionColumn = e.getColumn()
};
}
}
}
@@ -1,84 +1,84 @@
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using Spring.Expressions.Parser.antlr;
namespace Disco.BI.Expressions
{
public class EvaluateExpressionPart : IExpressionPart
{
private Spring.Expressions.IExpression _Expression;
private RecognitionException _ExpressionParseException;
private EvaluateExpressionParseException _EvaluateParseException;
public string RawSource { get; set; }
public string Source { get; set; }
public bool ErrorsAllowed { get; set; }
public bool IsDynamic { get { return true; } set { return; } }
public EvaluateExpressionParseException ParseException
{
get
{
if (_ExpressionParseException == null)
return null;
else
if (_EvaluateParseException == null)
_EvaluateParseException = EvaluateExpressionParseException.FromRecognitionException(_ExpressionParseException, this.Source);
return _EvaluateParseException;
}
}
public bool ParseError
{
get { return (_ExpressionParseException != null); }
}
public string ParseErrorMessage
{
get
{
if (ParseError)
return ParseException.Message;
else
return null;
}
}
public EvaluateExpressionPart(string Source)
{
this.RawSource = Source;
if (Source.StartsWith("{") && Source.EndsWith("}"))
Source = Source.Substring(1, Source.Length - 2);
if (Source[0] == '~')
{
this.ErrorsAllowed = true;
this.Source = Source.Substring(1);
}
else
{
this.ErrorsAllowed = false;
this.Source = Source;
}
try
{
this._Expression = Spring.Expressions.Expression.Parse(this.Source);
}
catch (RecognitionException ex)
{
this._ExpressionParseException = ex;
}
}
object IExpressionPart.Evaluate(object ExpressionContext, System.Collections.IDictionary Variables)
{
if (this._ExpressionParseException == null)
{
return this._Expression.GetValue(ExpressionContext, Variables);
}
throw this._ExpressionParseException;
}
}
}
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using Spring.Expressions.Parser.antlr;
namespace Disco.BI.Expressions
{
public class EvaluateExpressionPart : IExpressionPart
{
private Spring.Expressions.IExpression _Expression;
private RecognitionException _ExpressionParseException;
private EvaluateExpressionParseException _EvaluateParseException;
public string RawSource { get; set; }
public string Source { get; set; }
public bool ErrorsAllowed { get; set; }
public bool IsDynamic { get { return true; } set { return; } }
public EvaluateExpressionParseException ParseException
{
get
{
if (_ExpressionParseException == null)
return null;
else
if (_EvaluateParseException == null)
_EvaluateParseException = EvaluateExpressionParseException.FromRecognitionException(_ExpressionParseException, this.Source);
return _EvaluateParseException;
}
}
public bool ParseError
{
get { return (_ExpressionParseException != null); }
}
public string ParseErrorMessage
{
get
{
if (ParseError)
return ParseException.Message;
else
return null;
}
}
public EvaluateExpressionPart(string Source)
{
this.RawSource = Source;
if (Source.StartsWith("{") && Source.EndsWith("}"))
Source = Source.Substring(1, Source.Length - 2);
if (Source[0] == '~')
{
this.ErrorsAllowed = true;
this.Source = Source.Substring(1);
}
else
{
this.ErrorsAllowed = false;
this.Source = Source;
}
try
{
this._Expression = Spring.Expressions.Expression.Parse(this.Source);
}
catch (RecognitionException ex)
{
this._ExpressionParseException = ex;
}
}
object IExpressionPart.Evaluate(object ExpressionContext, System.Collections.IDictionary Variables)
{
if (this._ExpressionParseException == null)
{
return this._Expression.GetValue(ExpressionContext, Variables);
}
throw this._ExpressionParseException;
}
}
}
+259 -259
View File
@@ -1,259 +1,259 @@
using Disco.Data.Repository;
using Disco.Models.BI.DocumentTemplates;
using Disco.Models.Repository;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using Disco.Models.BI.Expressions;
namespace Disco.BI.Expressions
{
public sealed class Expression : System.Collections.Generic.List<IExpressionPart>
{
public string Name { get; private set; }
public string Source { get; private set; }
public bool IsDynamic { get; private set; }
public int Ordinal { get; private set; }
private Expression(string Name, string Source, int Ordinal)
{
this.Name = Name;
this.Source = Source;
this.Ordinal = Ordinal;
}
public static void InitializeExpressions()
{
Spring.Core.TypeResolution.TypeRegistry.RegisterType("DataExt", typeof(Extensions.DataExt));
Spring.Core.TypeResolution.TypeRegistry.RegisterType("UserExt", typeof(Extensions.UserExt));
Spring.Core.TypeResolution.TypeRegistry.RegisterType("DeviceExt", typeof(Extensions.DeviceExt));
Spring.Core.TypeResolution.TypeRegistry.RegisterType("ImageExt", typeof(Extensions.ImageExt));
}
public T EvaluateFirst<T>(object ExpressionContext, System.Collections.IDictionary Variables)
{
T result = default(T);
if (this.Count > 0)
{
try
{
object expressionResult = this[0].Evaluate(ExpressionContext, Variables);
if (expressionResult != null)
{
if (expressionResult is T)
{
result = (T)expressionResult;
}
else
{
throw new InvalidOperationException("Expression returned an invalid type");
}
}
}
catch (System.Exception ex)
{
throw new InvalidOperationException("Expression evaluation resulted in an error", ex);
}
}
return result;
}
public Tuple<string, bool, object> Evaluate(object ExpressionContext, System.Collections.IDictionary Variables)
{
System.Text.StringBuilder resultValue = new System.Text.StringBuilder();
object resultObject = null;
bool resultError = false;
foreach (var expressionPart in this)
{
try
{
object partValue = expressionPart.Evaluate(ExpressionContext, Variables);
if (partValue != null)
{
// Check for Result Objects
if (partValue is IImageExpressionResult)
resultObject = partValue;
else
resultValue.Append(partValue.ToString());
}
}
catch (System.Exception ex)
{
if (!expressionPart.ErrorsAllowed)
{
resultValue.Append("## ERROR # ");
resultValue.Append(ex.Message);
resultValue.Append(" ##");
resultError = true;
}
}
}
return new Tuple<string, bool, object>(resultValue.ToString(), resultError, resultObject);
}
public static Expression TokenizeSingleDynamic(string Name, string ExpressionSource, int Ordinal)
{
Expression e = new Expression(Name, ExpressionSource, Ordinal);
if (ExpressionSource != null && !string.IsNullOrWhiteSpace(ExpressionSource))
e.Add(new EvaluateExpressionPart(ExpressionSource));
e.IsDynamic = true;
return e;
}
public static Expression Tokenize(string Name, string ExpressionSource, int Ordinal)
{
Expression e = new Expression(Name, ExpressionSource, Ordinal);
if (!ExpressionSource.Contains("{") || !ExpressionSource.Contains("}"))
{
e.Add(new TextExpressionPart(ExpressionSource));
}
else
{
System.Text.StringBuilder token = new System.Text.StringBuilder();
bool tokenEval = false;
int tokenEvalDepth = 0;
foreach (char c in ExpressionSource)
{
switch (c)
{
case '{':
{
if (!tokenEval)
{
if (token.Length > 0)
{
e.Add(new TextExpressionPart(token.ToString()));
token = new System.Text.StringBuilder();
}
tokenEval = true;
tokenEvalDepth = 0;
}
tokenEvalDepth++;
token.Append(c);
break;
}
case '}':
{
token.Append(c);
if (tokenEval)
{
tokenEvalDepth--;
if (tokenEvalDepth <= 0)
{
if (token.Length != 2 && (token.Length != 3 || token[1] != '@'))
{
e.Add(new EvaluateExpressionPart(token.ToString()));
e.IsDynamic = true;
token = new System.Text.StringBuilder();
}
tokenEval = false;
}
}
break;
}
default:
{
token.Append(c);
break;
}
}
}
if (token.Length > 0)
{
e.Add(new TextExpressionPart(token.ToString()));
}
}
return e;
}
public static IDictionary StandardVariables(DocumentTemplate AttachmentType, DiscoDataContext DataContext, User User, System.DateTime TimeStamp, DocumentState DocumentState)
{
return new Hashtable
{
{
"DataContext",
DataContext
},
{
"User",
User
},
{
"TimeStamp",
TimeStamp
},
{
"AttachmentType",
AttachmentType
},
{
"State",
DocumentState
}
};
}
public static Dictionary<string, string> StandardVariableTypes()
{
return new Dictionary<string, string>
{
{
"#DataContext",
typeof(DiscoDataContext).AssemblyQualifiedName
},
{
"#User",
typeof(User).AssemblyQualifiedName
},
{
"#TimeStamp",
typeof(System.DateTime).AssemblyQualifiedName
},
{
"#AttachmentType",
typeof(DocumentTemplate).AssemblyQualifiedName
},
{
"#State",
typeof(DocumentState).AssemblyQualifiedName
}
};
}
public static Dictionary<string, string> ExtensionLibraryTypes()
{
return new Dictionary<string, string>
{
{
"DataExt",
typeof(Extensions.DataExt).AssemblyQualifiedName
},
{
"DeviceExt",
typeof(Extensions.DeviceExt).AssemblyQualifiedName
},
{
"ImageExt",
typeof(Extensions.ImageExt).AssemblyQualifiedName
},
{
"UserExt",
typeof(Extensions.UserExt).AssemblyQualifiedName
}
};
}
}
}
using Disco.Data.Repository;
using Disco.Models.BI.DocumentTemplates;
using Disco.Models.Repository;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using Disco.Models.BI.Expressions;
namespace Disco.BI.Expressions
{
public sealed class Expression : System.Collections.Generic.List<IExpressionPart>
{
public string Name { get; private set; }
public string Source { get; private set; }
public bool IsDynamic { get; private set; }
public int Ordinal { get; private set; }
private Expression(string Name, string Source, int Ordinal)
{
this.Name = Name;
this.Source = Source;
this.Ordinal = Ordinal;
}
public static void InitializeExpressions()
{
Spring.Core.TypeResolution.TypeRegistry.RegisterType("DataExt", typeof(Extensions.DataExt));
Spring.Core.TypeResolution.TypeRegistry.RegisterType("UserExt", typeof(Extensions.UserExt));
Spring.Core.TypeResolution.TypeRegistry.RegisterType("DeviceExt", typeof(Extensions.DeviceExt));
Spring.Core.TypeResolution.TypeRegistry.RegisterType("ImageExt", typeof(Extensions.ImageExt));
}
public T EvaluateFirst<T>(object ExpressionContext, System.Collections.IDictionary Variables)
{
T result = default(T);
if (this.Count > 0)
{
try
{
object expressionResult = this[0].Evaluate(ExpressionContext, Variables);
if (expressionResult != null)
{
if (expressionResult is T)
{
result = (T)expressionResult;
}
else
{
throw new InvalidOperationException("Expression returned an invalid type");
}
}
}
catch (System.Exception ex)
{
throw new InvalidOperationException("Expression evaluation resulted in an error", ex);
}
}
return result;
}
public Tuple<string, bool, object> Evaluate(object ExpressionContext, System.Collections.IDictionary Variables)
{
System.Text.StringBuilder resultValue = new System.Text.StringBuilder();
object resultObject = null;
bool resultError = false;
foreach (var expressionPart in this)
{
try
{
object partValue = expressionPart.Evaluate(ExpressionContext, Variables);
if (partValue != null)
{
// Check for Result Objects
if (partValue is IImageExpressionResult)
resultObject = partValue;
else
resultValue.Append(partValue.ToString());
}
}
catch (System.Exception ex)
{
if (!expressionPart.ErrorsAllowed)
{
resultValue.Append("## ERROR # ");
resultValue.Append(ex.Message);
resultValue.Append(" ##");
resultError = true;
}
}
}
return new Tuple<string, bool, object>(resultValue.ToString(), resultError, resultObject);
}
public static Expression TokenizeSingleDynamic(string Name, string ExpressionSource, int Ordinal)
{
Expression e = new Expression(Name, ExpressionSource, Ordinal);
if (ExpressionSource != null && !string.IsNullOrWhiteSpace(ExpressionSource))
e.Add(new EvaluateExpressionPart(ExpressionSource));
e.IsDynamic = true;
return e;
}
public static Expression Tokenize(string Name, string ExpressionSource, int Ordinal)
{
Expression e = new Expression(Name, ExpressionSource, Ordinal);
if (!ExpressionSource.Contains("{") || !ExpressionSource.Contains("}"))
{
e.Add(new TextExpressionPart(ExpressionSource));
}
else
{
System.Text.StringBuilder token = new System.Text.StringBuilder();
bool tokenEval = false;
int tokenEvalDepth = 0;
foreach (char c in ExpressionSource)
{
switch (c)
{
case '{':
{
if (!tokenEval)
{
if (token.Length > 0)
{
e.Add(new TextExpressionPart(token.ToString()));
token = new System.Text.StringBuilder();
}
tokenEval = true;
tokenEvalDepth = 0;
}
tokenEvalDepth++;
token.Append(c);
break;
}
case '}':
{
token.Append(c);
if (tokenEval)
{
tokenEvalDepth--;
if (tokenEvalDepth <= 0)
{
if (token.Length != 2 && (token.Length != 3 || token[1] != '@'))
{
e.Add(new EvaluateExpressionPart(token.ToString()));
e.IsDynamic = true;
token = new System.Text.StringBuilder();
}
tokenEval = false;
}
}
break;
}
default:
{
token.Append(c);
break;
}
}
}
if (token.Length > 0)
{
e.Add(new TextExpressionPart(token.ToString()));
}
}
return e;
}
public static IDictionary StandardVariables(DocumentTemplate AttachmentType, DiscoDataContext DataContext, User User, System.DateTime TimeStamp, DocumentState DocumentState)
{
return new Hashtable
{
{
"DataContext",
DataContext
},
{
"User",
User
},
{
"TimeStamp",
TimeStamp
},
{
"AttachmentType",
AttachmentType
},
{
"State",
DocumentState
}
};
}
public static Dictionary<string, string> StandardVariableTypes()
{
return new Dictionary<string, string>
{
{
"#DataContext",
typeof(DiscoDataContext).AssemblyQualifiedName
},
{
"#User",
typeof(User).AssemblyQualifiedName
},
{
"#TimeStamp",
typeof(System.DateTime).AssemblyQualifiedName
},
{
"#AttachmentType",
typeof(DocumentTemplate).AssemblyQualifiedName
},
{
"#State",
typeof(DocumentState).AssemblyQualifiedName
}
};
}
public static Dictionary<string, string> ExtensionLibraryTypes()
{
return new Dictionary<string, string>
{
{
"DataExt",
typeof(Extensions.DataExt).AssemblyQualifiedName
},
{
"DeviceExt",
typeof(Extensions.DeviceExt).AssemblyQualifiedName
},
{
"ImageExt",
typeof(Extensions.ImageExt).AssemblyQualifiedName
},
{
"UserExt",
typeof(Extensions.UserExt).AssemblyQualifiedName
}
};
}
}
}
+103 -103
View File
@@ -1,103 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
namespace Disco.BI.Expressions
{
public static class ExpressionCache
{
private static ConcurrentDictionary<string, ConcurrentDictionary<string, Expression>> _Cache = new ConcurrentDictionary<string, ConcurrentDictionary<string, Expression>>();
public delegate Expression CreateValueDelegate();
public static ConcurrentDictionary<string, Expression> GetModule(string Module, bool Create = false)
{
ConcurrentDictionary<string, Expression> moduleCache;
if (_Cache.TryGetValue(Module, out moduleCache))
return moduleCache;
else
{
if (Create)
{
moduleCache = new ConcurrentDictionary<string, Expression>();
_Cache.TryAdd(Module, moduleCache);
return moduleCache;
}
else
return null;
}
}
private static Expression GetModuleValue(string Module, string Key, CreateValueDelegate CreateValue)
{
ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, (CreateValue != null));
if (moduleCache != null)
{
Expression expression;
if (moduleCache.TryGetValue(Key, out expression))
{
return expression;
}
if (CreateValue != null)
{
expression = CreateValue();
Expression oldExpression;
if (moduleCache.TryGetValue(Key, out oldExpression))
moduleCache.TryUpdate(Key, expression, oldExpression);
else
moduleCache.TryAdd(Key, expression);
return expression;
}
}
return null;
}
public static Expression GetValue(string Module, string Key, CreateValueDelegate CreateValue)
{
return GetModuleValue(Module, Key, CreateValue);
}
public static Expression GetValue(string Module, string Key)
{
return GetModuleValue(Module, Key, null);
}
public static bool InvalidModule(string Module)
{
ConcurrentDictionary<string, Expression> moduleCache;
return _Cache.TryRemove(Module, out moduleCache);
}
public static bool InvalidateKey(string Module, string Key)
{
Expression expression;
ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, false);
if (moduleCache != null)
{
bool removeResult = moduleCache.TryRemove(Key, out expression);
if (moduleCache.Count == 0)
InvalidModule(Module);
return removeResult;
}
else
return false;
}
public static bool SetValue(string Module, string Key, Expression Expression)
{
ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, true);
if (moduleCache.ContainsKey(Key))
{
Expression oldExpression;
if (moduleCache.TryGetValue(Key, out oldExpression))
{
return moduleCache.TryUpdate(Key, Expression, oldExpression);
}
}
return moduleCache.TryAdd(Key, Expression);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
namespace Disco.BI.Expressions
{
public static class ExpressionCache
{
private static ConcurrentDictionary<string, ConcurrentDictionary<string, Expression>> _Cache = new ConcurrentDictionary<string, ConcurrentDictionary<string, Expression>>();
public delegate Expression CreateValueDelegate();
public static ConcurrentDictionary<string, Expression> GetModule(string Module, bool Create = false)
{
ConcurrentDictionary<string, Expression> moduleCache;
if (_Cache.TryGetValue(Module, out moduleCache))
return moduleCache;
else
{
if (Create)
{
moduleCache = new ConcurrentDictionary<string, Expression>();
_Cache.TryAdd(Module, moduleCache);
return moduleCache;
}
else
return null;
}
}
private static Expression GetModuleValue(string Module, string Key, CreateValueDelegate CreateValue)
{
ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, (CreateValue != null));
if (moduleCache != null)
{
Expression expression;
if (moduleCache.TryGetValue(Key, out expression))
{
return expression;
}
if (CreateValue != null)
{
expression = CreateValue();
Expression oldExpression;
if (moduleCache.TryGetValue(Key, out oldExpression))
moduleCache.TryUpdate(Key, expression, oldExpression);
else
moduleCache.TryAdd(Key, expression);
return expression;
}
}
return null;
}
public static Expression GetValue(string Module, string Key, CreateValueDelegate CreateValue)
{
return GetModuleValue(Module, Key, CreateValue);
}
public static Expression GetValue(string Module, string Key)
{
return GetModuleValue(Module, Key, null);
}
public static bool InvalidModule(string Module)
{
ConcurrentDictionary<string, Expression> moduleCache;
return _Cache.TryRemove(Module, out moduleCache);
}
public static bool InvalidateKey(string Module, string Key)
{
Expression expression;
ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, false);
if (moduleCache != null)
{
bool removeResult = moduleCache.TryRemove(Key, out expression);
if (moduleCache.Count == 0)
InvalidModule(Module);
return removeResult;
}
else
return false;
}
public static bool SetValue(string Module, string Key, Expression Expression)
{
ConcurrentDictionary<string, Expression> moduleCache = GetModule(Module, true);
if (moduleCache.ContainsKey(Key))
{
Expression oldExpression;
if (moduleCache.TryGetValue(Key, out oldExpression))
{
return moduleCache.TryUpdate(Key, Expression, oldExpression);
}
}
return moduleCache.TryAdd(Key, Expression);
}
}
}
@@ -1,43 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Services.Tasks;
using Disco.Data.Repository;
using Quartz;
using Disco.BI.Extensions;
using System.Diagnostics;
namespace Disco.BI.Expressions
{
public class ExpressionCachePreloadTask : ScheduledTask
{
public override string TaskName { get { return "Expression Cache - Preload Task"; } }
public override bool SingleInstanceTask { get { return true; } }
public override bool CancelInitiallySupported { get { return false; } }
public override void InitalizeScheduledTask(DiscoDataContext dbContext)
{
// Run in Background 1 Second after Scheduled (on App Startup)
TriggerBuilder triggerBuilder = TriggerBuilder.Create().StartAt(new DateTimeOffset(DateTime.Now).AddSeconds(5));
this.ScheduleTask(triggerBuilder);
}
protected override void ExecuteTask()
{
// Cache Document Template Filter Expressions
using (DiscoDataContext dbContext = new DiscoDataContext())
{
foreach (var documentTemplate in dbContext.DocumentTemplates.Where(dt => dt.FilterExpression != null && dt.FilterExpression != string.Empty))
{
if (!string.IsNullOrWhiteSpace(documentTemplate.FilterExpression))
documentTemplate.FilterExpressionFromCache();
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Services.Tasks;
using Disco.Data.Repository;
using Quartz;
using Disco.BI.Extensions;
using System.Diagnostics;
namespace Disco.BI.Expressions
{
public class ExpressionCachePreloadTask : ScheduledTask
{
public override string TaskName { get { return "Expression Cache - Preload Task"; } }
public override bool SingleInstanceTask { get { return true; } }
public override bool CancelInitiallySupported { get { return false; } }
public override void InitalizeScheduledTask(DiscoDataContext dbContext)
{
// Run in Background 1 Second after Scheduled (on App Startup)
TriggerBuilder triggerBuilder = TriggerBuilder.Create().StartAt(new DateTimeOffset(DateTime.Now).AddSeconds(5));
this.ScheduleTask(triggerBuilder);
}
protected override void ExecuteTask()
{
// Cache Document Template Filter Expressions
using (DiscoDataContext dbContext = new DiscoDataContext())
{
foreach (var documentTemplate in dbContext.DocumentTemplates.Where(dt => dt.FilterExpression != null && dt.FilterExpression != string.Empty))
{
if (!string.IsNullOrWhiteSpace(documentTemplate.FilterExpression))
documentTemplate.FilterExpressionFromCache();
}
}
}
}
}
@@ -1,58 +1,58 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Disco.BI.Expressions
{
public class ExpressionTypeDescriptor
{
public string ExpressionType { get; set; }
public string Name { get; set; }
public List<ExpressionTypeMemberDescriptor> Members { get; set; }
public static ExpressionTypeDescriptor Build(System.Type t, bool StaticDeclaredMembersOnly = true)
{
ExpressionTypeDescriptor i = new ExpressionTypeDescriptor
{
ExpressionType = t.AssemblyQualifiedName,
Name = t.Name
};
i.Members = new System.Collections.Generic.List<ExpressionTypeMemberDescriptor>();
System.Reflection.MemberInfo[] members;
if (StaticDeclaredMembersOnly)
members = t.GetMembers(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
else
members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);
for (int j = 0; j < members.Length; j++)
{
System.Reflection.MemberInfo member = members[j];
if (member is System.Reflection.PropertyInfo)
{
System.Reflection.PropertyInfo pi = (System.Reflection.PropertyInfo)member;
if (!pi.IsSpecialName && pi.CanRead)
{
i.Members.Add(ExpressionTypeMemberDescriptor.Build(pi));
}
}
if (member is System.Reflection.MethodInfo)
{
System.Reflection.MethodInfo mi2 = (System.Reflection.MethodInfo)member;
if (!mi2.IsSpecialName)
{
i.Members.Add(ExpressionTypeMemberDescriptor.Build(mi2));
}
}
}
i.Members = (
from mi in i.Members
orderby mi.Name
select mi).ToList();
return i;
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Disco.BI.Expressions
{
public class ExpressionTypeDescriptor
{
public string ExpressionType { get; set; }
public string Name { get; set; }
public List<ExpressionTypeMemberDescriptor> Members { get; set; }
public static ExpressionTypeDescriptor Build(System.Type t, bool StaticDeclaredMembersOnly = true)
{
ExpressionTypeDescriptor i = new ExpressionTypeDescriptor
{
ExpressionType = t.AssemblyQualifiedName,
Name = t.Name
};
i.Members = new System.Collections.Generic.List<ExpressionTypeMemberDescriptor>();
System.Reflection.MemberInfo[] members;
if (StaticDeclaredMembersOnly)
members = t.GetMembers(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
else
members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);
for (int j = 0; j < members.Length; j++)
{
System.Reflection.MemberInfo member = members[j];
if (member is System.Reflection.PropertyInfo)
{
System.Reflection.PropertyInfo pi = (System.Reflection.PropertyInfo)member;
if (!pi.IsSpecialName && pi.CanRead)
{
i.Members.Add(ExpressionTypeMemberDescriptor.Build(pi));
}
}
if (member is System.Reflection.MethodInfo)
{
System.Reflection.MethodInfo mi2 = (System.Reflection.MethodInfo)member;
if (!mi2.IsSpecialName)
{
i.Members.Add(ExpressionTypeMemberDescriptor.Build(mi2));
}
}
}
i.Members = (
from mi in i.Members
orderby mi.Name
select mi).ToList();
return i;
}
}
}
@@ -1,61 +1,61 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Disco.BI.Expressions
{
public class ExpressionTypeMemberDescriptor
{
public const string FunctionKind = "function";
public const string PropertyKind = "property";
public const string ParameterKind = "parameter";
public string Kind {get;set;}
public string Name {get;set;}
public string ReturnType {get;set;}
public string ReturnExpressionType{get;set;}
public List<ExpressionTypeMemberDescriptor> Parameters{get;set;}
public static ExpressionTypeMemberDescriptor Build(System.Reflection.MethodInfo m)
{
ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor
{
Kind = "function",
Name = m.Name,
ReturnType = m.ReturnType.Name,
ReturnExpressionType = m.ReturnType.AssemblyQualifiedName
};
md.Parameters = (
from mdp in m.GetParameters()
select ExpressionTypeMemberDescriptor.Build(mdp)).ToList<ExpressionTypeMemberDescriptor>();
return md;
}
public static ExpressionTypeMemberDescriptor Build(System.Reflection.PropertyInfo p)
{
ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor
{
Kind = "property",
Name = p.Name,
ReturnType = p.PropertyType.Name,
ReturnExpressionType = p.PropertyType.AssemblyQualifiedName
};
md.Parameters = (
from mdp in p.GetIndexParameters()
select ExpressionTypeMemberDescriptor.Build(mdp)).ToList<ExpressionTypeMemberDescriptor>();
return md;
}
public static ExpressionTypeMemberDescriptor Build(System.Reflection.ParameterInfo pi)
{
return new ExpressionTypeMemberDescriptor
{
Kind = "parameter",
Name = pi.Name,
ReturnType = pi.ParameterType.Name,
ReturnExpressionType = pi.ParameterType.AssemblyQualifiedName
};
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Disco.BI.Expressions
{
public class ExpressionTypeMemberDescriptor
{
public const string FunctionKind = "function";
public const string PropertyKind = "property";
public const string ParameterKind = "parameter";
public string Kind {get;set;}
public string Name {get;set;}
public string ReturnType {get;set;}
public string ReturnExpressionType{get;set;}
public List<ExpressionTypeMemberDescriptor> Parameters{get;set;}
public static ExpressionTypeMemberDescriptor Build(System.Reflection.MethodInfo m)
{
ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor
{
Kind = "function",
Name = m.Name,
ReturnType = m.ReturnType.Name,
ReturnExpressionType = m.ReturnType.AssemblyQualifiedName
};
md.Parameters = (
from mdp in m.GetParameters()
select ExpressionTypeMemberDescriptor.Build(mdp)).ToList<ExpressionTypeMemberDescriptor>();
return md;
}
public static ExpressionTypeMemberDescriptor Build(System.Reflection.PropertyInfo p)
{
ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor
{
Kind = "property",
Name = p.Name,
ReturnType = p.PropertyType.Name,
ReturnExpressionType = p.PropertyType.AssemblyQualifiedName
};
md.Parameters = (
from mdp in p.GetIndexParameters()
select ExpressionTypeMemberDescriptor.Build(mdp)).ToList<ExpressionTypeMemberDescriptor>();
return md;
}
public static ExpressionTypeMemberDescriptor Build(System.Reflection.ParameterInfo pi)
{
return new ExpressionTypeMemberDescriptor
{
Kind = "parameter",
Name = pi.Name,
ReturnType = pi.ParameterType.Name,
ReturnExpressionType = pi.ParameterType.AssemblyQualifiedName
};
}
}
}
+176 -176
View File
@@ -1,176 +1,176 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Data.Odbc;
namespace Disco.BI.Expressions.Extensions
{
public static class DataExt
{
#region SqlClient
private static SqlConnection BuildSqlConnection(string Server, string Database, string Username, string Password)
{
SqlConnectionStringBuilder dbConnectionStringBuilder = new SqlConnectionStringBuilder();
dbConnectionStringBuilder.ApplicationName = "Disco";
dbConnectionStringBuilder.DataSource = Server;
dbConnectionStringBuilder.InitialCatalog = Database;
dbConnectionStringBuilder.MultipleActiveResultSets = true;
dbConnectionStringBuilder.PersistSecurityInfo = true;
if (Username == null || Password == null)
dbConnectionStringBuilder.IntegratedSecurity = true;
else
{
dbConnectionStringBuilder.UserID = Username;
dbConnectionStringBuilder.Password = Password;
}
return new SqlConnection(dbConnectionStringBuilder.ConnectionString);
}
private static void BuildSqlParameters(SqlCommand dbCommand, Hashtable SqlParameters)
{
if (SqlParameters != null)
{
foreach (var sqlParameterKey in SqlParameters.Keys)
{
string key = sqlParameterKey.ToString();
if (!key.StartsWith("@"))
key = string.Concat("@", key);
dbCommand.Parameters.AddWithValue(key, SqlParameters[sqlParameterKey]);
}
}
}
public static DataTable QuerySqlDatabase(string Server, string Database, string Username, string Password, string SqlQuery, Hashtable SqlParameters)
{
using (SqlConnection dbConnection = BuildSqlConnection(Server, Database, Username, Password))
{
using (SqlCommand dbCommand = new SqlCommand(SqlQuery, dbConnection))
{
BuildSqlParameters(dbCommand, SqlParameters);
using (SqlDataAdapter dbAdapter = new SqlDataAdapter(dbCommand))
{
var dbTable = new DataTable();
dbAdapter.Fill(dbTable);
return dbTable;
}
}
}
}
public static DataTable QuerySqlDatabase(string Server, string Database, string SqlQuery, Hashtable SqlParameters)
{
return QuerySqlDatabase(Server, Database, null, null, SqlQuery, SqlParameters);
}
public static DataTable QuerySqlDatabase(string Server, string Database, string SqlQuery)
{
return QuerySqlDatabase(Server, Database, null, null, SqlQuery, null);
}
public static object QuerySqlDatabaseScalar(string Server, string Database, string Username, string Password, string SqlQuery, Hashtable SqlParameters)
{
using (SqlConnection dbConnection = BuildSqlConnection(Server, Database, Username, Password))
{
using (SqlCommand dbCommand = new SqlCommand(SqlQuery, dbConnection))
{
BuildSqlParameters(dbCommand, SqlParameters);
try
{
dbConnection.Open();
return dbCommand.ExecuteScalar();
}
catch (Exception)
{
throw;
}
finally
{
dbConnection.Close();
}
}
}
}
public static object QuerySqlDatabaseScalar(string Server, string Database, string SqlQuery, Hashtable SqlParameters)
{
return QuerySqlDatabaseScalar(Server, Database, null, null, SqlQuery, SqlParameters);
}
public static object QuerySqlDatabaseScalar(string Server, string Database, string SqlQuery)
{
return QuerySqlDatabaseScalar(Server, Database, null, null, SqlQuery, null);
}
#endregion
#region ODBC
private static OdbcConnection BuildOdbcConnection(string ConnectionString)
{
return new OdbcConnection(ConnectionString);
}
private static void BuildOdbcParameters(OdbcCommand dbCommand, Hashtable OdbcParameters)
{
if (OdbcParameters != null)
{
foreach (var odbcParameterKey in OdbcParameters.Keys)
{
string key = odbcParameterKey.ToString();
dbCommand.Parameters.AddWithValue(key, OdbcParameters[odbcParameterKey]);
}
}
}
public static DataTable QueryOdbcDatabase(string ConnectionString, string OdbcQuery, Hashtable OdbcParameters)
{
using (OdbcConnection dbConnection = BuildOdbcConnection(ConnectionString))
{
using (OdbcCommand dbCommand = new OdbcCommand(OdbcQuery, dbConnection))
{
BuildOdbcParameters(dbCommand, OdbcParameters);
using (OdbcDataAdapter dbAdapter = new OdbcDataAdapter(dbCommand))
{
var dbTable = new DataTable();
dbAdapter.Fill(dbTable);
return dbTable;
}
}
}
}
public static DataTable QueryOdbcDatabase(string ConnectionString, string OdbcQuery)
{
return QueryOdbcDatabase(ConnectionString, OdbcQuery, null);
}
public static object QueryOdbcDatabaseScalar(string ConnectionString, string OdbcQuery, Hashtable OdbcParameters)
{
using (OdbcConnection dbConnection = BuildOdbcConnection(ConnectionString))
{
using (OdbcCommand dbCommand = new OdbcCommand(OdbcQuery, dbConnection))
{
BuildOdbcParameters(dbCommand, OdbcParameters);
try
{
dbConnection.Open();
return dbCommand.ExecuteScalar();
}
catch (Exception)
{
throw;
}
finally
{
dbConnection.Close();
}
}
}
}
public static object QueryOdbcDatabaseScalar(string ConnectionString, string OdbcQuery)
{
return QueryOdbcDatabaseScalar(ConnectionString, OdbcQuery, null);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Data.Odbc;
namespace Disco.BI.Expressions.Extensions
{
public static class DataExt
{
#region SqlClient
private static SqlConnection BuildSqlConnection(string Server, string Database, string Username, string Password)
{
SqlConnectionStringBuilder dbConnectionStringBuilder = new SqlConnectionStringBuilder();
dbConnectionStringBuilder.ApplicationName = "Disco";
dbConnectionStringBuilder.DataSource = Server;
dbConnectionStringBuilder.InitialCatalog = Database;
dbConnectionStringBuilder.MultipleActiveResultSets = true;
dbConnectionStringBuilder.PersistSecurityInfo = true;
if (Username == null || Password == null)
dbConnectionStringBuilder.IntegratedSecurity = true;
else
{
dbConnectionStringBuilder.UserID = Username;
dbConnectionStringBuilder.Password = Password;
}
return new SqlConnection(dbConnectionStringBuilder.ConnectionString);
}
private static void BuildSqlParameters(SqlCommand dbCommand, Hashtable SqlParameters)
{
if (SqlParameters != null)
{
foreach (var sqlParameterKey in SqlParameters.Keys)
{
string key = sqlParameterKey.ToString();
if (!key.StartsWith("@"))
key = string.Concat("@", key);
dbCommand.Parameters.AddWithValue(key, SqlParameters[sqlParameterKey]);
}
}
}
public static DataTable QuerySqlDatabase(string Server, string Database, string Username, string Password, string SqlQuery, Hashtable SqlParameters)
{
using (SqlConnection dbConnection = BuildSqlConnection(Server, Database, Username, Password))
{
using (SqlCommand dbCommand = new SqlCommand(SqlQuery, dbConnection))
{
BuildSqlParameters(dbCommand, SqlParameters);
using (SqlDataAdapter dbAdapter = new SqlDataAdapter(dbCommand))
{
var dbTable = new DataTable();
dbAdapter.Fill(dbTable);
return dbTable;
}
}
}
}
public static DataTable QuerySqlDatabase(string Server, string Database, string SqlQuery, Hashtable SqlParameters)
{
return QuerySqlDatabase(Server, Database, null, null, SqlQuery, SqlParameters);
}
public static DataTable QuerySqlDatabase(string Server, string Database, string SqlQuery)
{
return QuerySqlDatabase(Server, Database, null, null, SqlQuery, null);
}
public static object QuerySqlDatabaseScalar(string Server, string Database, string Username, string Password, string SqlQuery, Hashtable SqlParameters)
{
using (SqlConnection dbConnection = BuildSqlConnection(Server, Database, Username, Password))
{
using (SqlCommand dbCommand = new SqlCommand(SqlQuery, dbConnection))
{
BuildSqlParameters(dbCommand, SqlParameters);
try
{
dbConnection.Open();
return dbCommand.ExecuteScalar();
}
catch (Exception)
{
throw;
}
finally
{
dbConnection.Close();
}
}
}
}
public static object QuerySqlDatabaseScalar(string Server, string Database, string SqlQuery, Hashtable SqlParameters)
{
return QuerySqlDatabaseScalar(Server, Database, null, null, SqlQuery, SqlParameters);
}
public static object QuerySqlDatabaseScalar(string Server, string Database, string SqlQuery)
{
return QuerySqlDatabaseScalar(Server, Database, null, null, SqlQuery, null);
}
#endregion
#region ODBC
private static OdbcConnection BuildOdbcConnection(string ConnectionString)
{
return new OdbcConnection(ConnectionString);
}
private static void BuildOdbcParameters(OdbcCommand dbCommand, Hashtable OdbcParameters)
{
if (OdbcParameters != null)
{
foreach (var odbcParameterKey in OdbcParameters.Keys)
{
string key = odbcParameterKey.ToString();
dbCommand.Parameters.AddWithValue(key, OdbcParameters[odbcParameterKey]);
}
}
}
public static DataTable QueryOdbcDatabase(string ConnectionString, string OdbcQuery, Hashtable OdbcParameters)
{
using (OdbcConnection dbConnection = BuildOdbcConnection(ConnectionString))
{
using (OdbcCommand dbCommand = new OdbcCommand(OdbcQuery, dbConnection))
{
BuildOdbcParameters(dbCommand, OdbcParameters);
using (OdbcDataAdapter dbAdapter = new OdbcDataAdapter(dbCommand))
{
var dbTable = new DataTable();
dbAdapter.Fill(dbTable);
return dbTable;
}
}
}
}
public static DataTable QueryOdbcDatabase(string ConnectionString, string OdbcQuery)
{
return QueryOdbcDatabase(ConnectionString, OdbcQuery, null);
}
public static object QueryOdbcDatabaseScalar(string ConnectionString, string OdbcQuery, Hashtable OdbcParameters)
{
using (OdbcConnection dbConnection = BuildOdbcConnection(ConnectionString))
{
using (OdbcCommand dbCommand = new OdbcCommand(OdbcQuery, dbConnection))
{
BuildOdbcParameters(dbCommand, OdbcParameters);
try
{
dbConnection.Open();
return dbCommand.ExecuteScalar();
}
catch (Exception)
{
throw;
}
finally
{
dbConnection.Close();
}
}
}
}
public static object QueryOdbcDatabaseScalar(string ConnectionString, string OdbcQuery)
{
return QueryOdbcDatabaseScalar(ConnectionString, OdbcQuery, null);
}
#endregion
}
}
+51 -51
View File
@@ -1,51 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.BI.Interop.ActiveDirectory;
namespace Disco.BI.Expressions.Extensions
{
public static class DeviceExt
{
public static object GetActiveDirectoryObjectValue(Device Device, string PropertyName, int Index = 0)
{
var adMachineAccount = Device.ActiveDirectoryAccount(PropertyName);
if (adMachineAccount != null)
return adMachineAccount.GetPropertyValue(PropertyName, Index);
else
return null;
}
public static string GetActiveDirectoryStringValue(Device Device, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(Device, PropertyName, Index);
string stringValue = objectValue as string;
if (stringValue == null && objectValue != null)
stringValue = objectValue.ToString();
return stringValue;
}
public static int GetActiveDirectoryIntegerValue(Device Device, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(Device, PropertyName, Index);
if (objectValue == null)
return default(int);
else
{
int intValue;
try
{
intValue = (int)Convert.ChangeType(objectValue, typeof(int));
}
catch (Exception)
{
throw;
}
return intValue;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.BI.Interop.ActiveDirectory;
namespace Disco.BI.Expressions.Extensions
{
public static class DeviceExt
{
public static object GetActiveDirectoryObjectValue(Device Device, string PropertyName, int Index = 0)
{
var adMachineAccount = Device.ActiveDirectoryAccount(PropertyName);
if (adMachineAccount != null)
return adMachineAccount.GetPropertyValue(PropertyName, Index);
else
return null;
}
public static string GetActiveDirectoryStringValue(Device Device, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(Device, PropertyName, Index);
string stringValue = objectValue as string;
if (stringValue == null && objectValue != null)
stringValue = objectValue.ToString();
return stringValue;
}
public static int GetActiveDirectoryIntegerValue(Device Device, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(Device, PropertyName, Index);
if (objectValue == null)
return default(int);
else
{
int intValue;
try
{
intValue = (int)Convert.ChangeType(objectValue, typeof(int));
}
catch (Exception)
{
throw;
}
return intValue;
}
}
}
}
+140 -140
View File
@@ -1,140 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.BI.Expressions;
using Disco.BI.Expressions.Extensions.ImageResultImplementations;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.Data.Repository;
using System.Collections;
using System.IO;
using System.Drawing;
namespace Disco.BI.Expressions.Extensions
{
public static class ImageExt
{
public static FileImageExpressionResult ImageFromFile(string AbsoluteFilePath)
{
return new FileImageExpressionResult(AbsoluteFilePath);
}
public static FileImageExpressionResult ImageFromDataStoreFile(string RelativeFilePath)
{
var configCache = new Disco.Data.Configuration.ConfigurationContext(null);
string DataStoreLocation = configCache.DataStoreLocation;
string AbsoluteFilePath = System.IO.Path.Combine(DataStoreLocation, RelativeFilePath);
return new FileImageExpressionResult(AbsoluteFilePath);
}
public static FileImageExpressionResult JobAttachmentFirstImage(Job Job, DiscoDataContext dbContext)
{
var attachment = Job.JobAttachments.FirstOrDefault(ja => ja.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase));
if (attachment != null)
{
var filename = attachment.RepositoryFilename(dbContext);
return new FileImageExpressionResult(filename);
}
else
return null;
}
public static FileImageExpressionResult JobAttachmentLastImage(Job Job, DiscoDataContext dbContext)
{
var attachment = Job.JobAttachments.LastOrDefault(ja => ja.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase));
if (attachment != null)
{
var filename = attachment.RepositoryFilename(dbContext);
return new FileImageExpressionResult(filename);
}
else
return null;
}
public static FileImageExpressionResult JobAttachmentImage(JobAttachment JobAttachment, DiscoDataContext dbContext)
{
if (JobAttachment == null)
throw new ArgumentNullException("JobAttachment");
if (!JobAttachment.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase))
throw new ArgumentException("Invalid Image MimeType for Attachment");
var filename = JobAttachment.RepositoryFilename(dbContext);
return new FileImageExpressionResult(filename);
}
public static FileMontageImageExpressionResult JobAttachmentImageMontage(Job Job, DiscoDataContext dbContext)
{
if (Job == null)
throw new ArgumentNullException("Job");
if (Job.JobAttachments == null)
throw new ArgumentException("Job.JobAttachments is null", "Job");
var attachments = Job.JobAttachments.Where(a => a.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase)).ToList();
if (attachments.Count > 0)
{
var attachmentFilepaths = attachments.Select(a => a.RepositoryFilename(dbContext)).ToList();
return new FileMontageImageExpressionResult(attachmentFilepaths);
}
else
return null;
}
public static FileMontageImageExpressionResult JobAttachmentsImageMontage(ArrayList JobAttachments, DiscoDataContext dbContext)
{
if (JobAttachments == null)
throw new ArgumentNullException("JobAttachments");
var attachments = JobAttachments.Cast<JobAttachment>().Where(a => a.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase)).ToList();
if (attachments.Count > 0)
{
var attachmentFilepaths = attachments.Select(a => a.RepositoryFilename(dbContext)).ToList();
return new FileMontageImageExpressionResult(attachmentFilepaths);
}
else
return null;
}
public static BitmapImageExpressionResult ImageFromStream(Stream ImageStream)
{
if (ImageStream == null)
throw new ArgumentNullException("ImageStream");
return new BitmapImageExpressionResult(Bitmap.FromStream(ImageStream));
}
public static BitmapImageExpressionResult ImageFromByteArray(byte[] ImageByteArray)
{
if (ImageByteArray == null)
throw new ArgumentNullException("ImageByteArray");
return new BitmapImageExpressionResult(Bitmap.FromStream(new MemoryStream(ImageByteArray)));
}
public static BitmapImageExpressionResult DeviceModelImage(DeviceModel DeviceModel)
{
if (DeviceModel == null)
throw new ArgumentNullException("DeviceModel");
using (Stream deviceModelImage = DeviceModel.Image())
{
if (deviceModelImage == null)
return null;
else
return ImageFromStream(deviceModelImage);
}
//if (DeviceModel.Image == null || DeviceModel.Image.Length == 0)
// return null;
//return ImageFromByteArray(DeviceModel.Image);
}
public static BitmapImageExpressionResult OrganisationLogo()
{
var configCache = new Disco.Data.Configuration.ConfigurationContext(null);
BitmapImageExpressionResult result;
using (var orgLogo = configCache.OrganisationLogo)
{
result = ImageFromStream(orgLogo);
}
result.LosslessFormat = true;
return result;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.BI.Expressions;
using Disco.BI.Expressions.Extensions.ImageResultImplementations;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.Data.Repository;
using System.Collections;
using System.IO;
using System.Drawing;
namespace Disco.BI.Expressions.Extensions
{
public static class ImageExt
{
public static FileImageExpressionResult ImageFromFile(string AbsoluteFilePath)
{
return new FileImageExpressionResult(AbsoluteFilePath);
}
public static FileImageExpressionResult ImageFromDataStoreFile(string RelativeFilePath)
{
var configCache = new Disco.Data.Configuration.ConfigurationContext(null);
string DataStoreLocation = configCache.DataStoreLocation;
string AbsoluteFilePath = System.IO.Path.Combine(DataStoreLocation, RelativeFilePath);
return new FileImageExpressionResult(AbsoluteFilePath);
}
public static FileImageExpressionResult JobAttachmentFirstImage(Job Job, DiscoDataContext dbContext)
{
var attachment = Job.JobAttachments.FirstOrDefault(ja => ja.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase));
if (attachment != null)
{
var filename = attachment.RepositoryFilename(dbContext);
return new FileImageExpressionResult(filename);
}
else
return null;
}
public static FileImageExpressionResult JobAttachmentLastImage(Job Job, DiscoDataContext dbContext)
{
var attachment = Job.JobAttachments.LastOrDefault(ja => ja.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase));
if (attachment != null)
{
var filename = attachment.RepositoryFilename(dbContext);
return new FileImageExpressionResult(filename);
}
else
return null;
}
public static FileImageExpressionResult JobAttachmentImage(JobAttachment JobAttachment, DiscoDataContext dbContext)
{
if (JobAttachment == null)
throw new ArgumentNullException("JobAttachment");
if (!JobAttachment.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase))
throw new ArgumentException("Invalid Image MimeType for Attachment");
var filename = JobAttachment.RepositoryFilename(dbContext);
return new FileImageExpressionResult(filename);
}
public static FileMontageImageExpressionResult JobAttachmentImageMontage(Job Job, DiscoDataContext dbContext)
{
if (Job == null)
throw new ArgumentNullException("Job");
if (Job.JobAttachments == null)
throw new ArgumentException("Job.JobAttachments is null", "Job");
var attachments = Job.JobAttachments.Where(a => a.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase)).ToList();
if (attachments.Count > 0)
{
var attachmentFilepaths = attachments.Select(a => a.RepositoryFilename(dbContext)).ToList();
return new FileMontageImageExpressionResult(attachmentFilepaths);
}
else
return null;
}
public static FileMontageImageExpressionResult JobAttachmentsImageMontage(ArrayList JobAttachments, DiscoDataContext dbContext)
{
if (JobAttachments == null)
throw new ArgumentNullException("JobAttachments");
var attachments = JobAttachments.Cast<JobAttachment>().Where(a => a.MimeType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase)).ToList();
if (attachments.Count > 0)
{
var attachmentFilepaths = attachments.Select(a => a.RepositoryFilename(dbContext)).ToList();
return new FileMontageImageExpressionResult(attachmentFilepaths);
}
else
return null;
}
public static BitmapImageExpressionResult ImageFromStream(Stream ImageStream)
{
if (ImageStream == null)
throw new ArgumentNullException("ImageStream");
return new BitmapImageExpressionResult(Bitmap.FromStream(ImageStream));
}
public static BitmapImageExpressionResult ImageFromByteArray(byte[] ImageByteArray)
{
if (ImageByteArray == null)
throw new ArgumentNullException("ImageByteArray");
return new BitmapImageExpressionResult(Bitmap.FromStream(new MemoryStream(ImageByteArray)));
}
public static BitmapImageExpressionResult DeviceModelImage(DeviceModel DeviceModel)
{
if (DeviceModel == null)
throw new ArgumentNullException("DeviceModel");
using (Stream deviceModelImage = DeviceModel.Image())
{
if (deviceModelImage == null)
return null;
else
return ImageFromStream(deviceModelImage);
}
//if (DeviceModel.Image == null || DeviceModel.Image.Length == 0)
// return null;
//return ImageFromByteArray(DeviceModel.Image);
}
public static BitmapImageExpressionResult OrganisationLogo()
{
var configCache = new Disco.Data.Configuration.ConfigurationContext(null);
BitmapImageExpressionResult result;
using (var orgLogo = configCache.OrganisationLogo)
{
result = ImageFromStream(orgLogo);
}
result.LosslessFormat = true;
return result;
}
}
}
@@ -1,70 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.BI.Expressions;
using System.IO;
using System.Drawing;
using Disco.BI.Extensions;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public abstract class BaseImageExpressionResult : IImageExpressionResult
{
public byte Quality { get; set; }
public bool LosslessFormat { get; set; }
public bool ShowField { get; set; }
public string BackgroundColour { get; set; }
public bool BackgroundPreferTransparent { get; set; }
public BaseImageExpressionResult()
{
this.LosslessFormat = false;
this.Quality = 90;
this.ShowField = false;
this.BackgroundPreferTransparent = true;
}
public abstract Stream GetImage(int Width, int Height);
protected Stream RenderImage(Image SourceImage, int Width, int Height)
{
if (SourceImage == null)
throw new ArgumentNullException("SourceImage");
if (Width <= 0)
throw new ArgumentOutOfRangeException("Width", "Width must be > 0");
if (Height <= 0)
throw new ArgumentOutOfRangeException("Height", "Height must be > 0");
Brush backgroundBrush = null;
if (!LosslessFormat || !BackgroundPreferTransparent)
{
if (string.IsNullOrEmpty(this.BackgroundColour))
backgroundBrush = Brushes.White;
else
backgroundBrush = new SolidBrush(ColorTranslator.FromHtml(this.BackgroundColour));
}
using (Image resizedImage = SourceImage.ResizeImage(Width, Height, backgroundBrush))
{
return OutputImage(resizedImage);
}
}
protected Stream OutputImage(Image SourceImage)
{
MemoryStream imageStream = new MemoryStream();
if (LosslessFormat)
{ // Lossless Format - PNG
SourceImage.SavePng(imageStream);
}
else
{ // Lossy Format - JPG
byte quality = Math.Min((byte)100, Math.Max((byte)1, this.Quality));
SourceImage.SaveJpg(quality, imageStream);
}
imageStream.Position = 0;
return imageStream;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.BI.Expressions;
using System.IO;
using System.Drawing;
using Disco.BI.Extensions;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public abstract class BaseImageExpressionResult : IImageExpressionResult
{
public byte Quality { get; set; }
public bool LosslessFormat { get; set; }
public bool ShowField { get; set; }
public string BackgroundColour { get; set; }
public bool BackgroundPreferTransparent { get; set; }
public BaseImageExpressionResult()
{
this.LosslessFormat = false;
this.Quality = 90;
this.ShowField = false;
this.BackgroundPreferTransparent = true;
}
public abstract Stream GetImage(int Width, int Height);
protected Stream RenderImage(Image SourceImage, int Width, int Height)
{
if (SourceImage == null)
throw new ArgumentNullException("SourceImage");
if (Width <= 0)
throw new ArgumentOutOfRangeException("Width", "Width must be > 0");
if (Height <= 0)
throw new ArgumentOutOfRangeException("Height", "Height must be > 0");
Brush backgroundBrush = null;
if (!LosslessFormat || !BackgroundPreferTransparent)
{
if (string.IsNullOrEmpty(this.BackgroundColour))
backgroundBrush = Brushes.White;
else
backgroundBrush = new SolidBrush(ColorTranslator.FromHtml(this.BackgroundColour));
}
using (Image resizedImage = SourceImage.ResizeImage(Width, Height, backgroundBrush))
{
return OutputImage(resizedImage);
}
}
protected Stream OutputImage(Image SourceImage)
{
MemoryStream imageStream = new MemoryStream();
if (LosslessFormat)
{ // Lossless Format - PNG
SourceImage.SavePng(imageStream);
}
else
{ // Lossy Format - JPG
byte quality = Math.Min((byte)100, Math.Max((byte)1, this.Quality));
SourceImage.SaveJpg(quality, imageStream);
}
imageStream.Position = 0;
return imageStream;
}
}
}
@@ -1,27 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public class BitmapImageExpressionResult : BaseImageExpressionResult
{
public Image Image { get; set; }
public BitmapImageExpressionResult(Image Image)
{
if (Image == null)
throw new ArgumentNullException("Image");
this.Image = Image;
}
public override Stream GetImage(int Width, int Height)
{
return this.RenderImage(this.Image, Width, Height);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public class BitmapImageExpressionResult : BaseImageExpressionResult
{
public Image Image { get; set; }
public BitmapImageExpressionResult(Image Image)
{
if (Image == null)
throw new ArgumentNullException("Image");
this.Image = Image;
}
public override Stream GetImage(int Width, int Height)
{
return this.RenderImage(this.Image, Width, Height);
}
}
}
@@ -1,32 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public class FileImageExpressionResult : BaseImageExpressionResult
{
public string AbsoluteFilePath { get; set; }
public FileImageExpressionResult(string AbsoluteFilePath)
{
if (string.IsNullOrWhiteSpace(AbsoluteFilePath))
throw new ArgumentNullException("AbsoluteFilePath");
if (!File.Exists(AbsoluteFilePath))
throw new FileNotFoundException("Image not found", AbsoluteFilePath);
this.AbsoluteFilePath = AbsoluteFilePath;
}
public override Stream GetImage(int Width, int Height)
{
using (Image SourceImage = Bitmap.FromFile(this.AbsoluteFilePath))
{
return this.RenderImage(SourceImage, Width, Height);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public class FileImageExpressionResult : BaseImageExpressionResult
{
public string AbsoluteFilePath { get; set; }
public FileImageExpressionResult(string AbsoluteFilePath)
{
if (string.IsNullOrWhiteSpace(AbsoluteFilePath))
throw new ArgumentNullException("AbsoluteFilePath");
if (!File.Exists(AbsoluteFilePath))
throw new FileNotFoundException("Image not found", AbsoluteFilePath);
this.AbsoluteFilePath = AbsoluteFilePath;
}
public override Stream GetImage(int Width, int Height)
{
using (Image SourceImage = Bitmap.FromFile(this.AbsoluteFilePath))
{
return this.RenderImage(SourceImage, Width, Height);
}
}
}
}
@@ -1,181 +1,181 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using Disco.BI.Extensions;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public class FileMontageImageExpressionResult : BaseImageExpressionResult
{
public List<string> AbsoluteFilePaths { get; set; }
public bool MontageHorizontalLayout { get; set; }
public bool MontageVerticalLayout { get; set; }
public bool MontageTableLayout { get; set; }
public int Padding { get; set; }
public FileMontageImageExpressionResult(List<string> AbsoluteFilePaths)
{
if (AbsoluteFilePaths == null)
throw new ArgumentNullException("AbsoluteFilePaths");
if (AbsoluteFilePaths.Count == 0)
throw new ArgumentException("AbsoluteFilePaths is empty", "AbsoluteFilePaths");
this.AbsoluteFilePaths = AbsoluteFilePaths;
this.MontageTableLayout = true;
this.Padding = 4;
}
public override Stream GetImage(int Width, int Height)
{
List<Image> Images = new List<Image>();
try
{
// Load Images
foreach (string imageFilePath in this.AbsoluteFilePaths)
Images.Add(Bitmap.FromFile(imageFilePath));
// Build Montage
using (Bitmap montageImage = new Bitmap(Width, Height))
{
using (Graphics montageGraphics = Graphics.FromImage(montageImage))
{
montageGraphics.CompositingQuality = CompositingQuality.HighQuality;
montageGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
montageGraphics.SmoothingMode = SmoothingMode.HighQuality;
// Draw Background
if (!LosslessFormat || !BackgroundPreferTransparent)
{
Brush backgroundBrush = Brushes.White;
if (!string.IsNullOrEmpty(this.BackgroundColour))
backgroundBrush = new SolidBrush(ColorTranslator.FromHtml(this.BackgroundColour));
montageGraphics.FillRectangle(backgroundBrush, montageGraphics.VisibleClipBounds);
}
if (this.MontageHorizontalLayout)
DoHorizontalLayout(Images, montageGraphics);
else
if (this.MontageVerticalLayout)
DoVirticalLayout(Images, montageGraphics);
else
DoTableLayout(Images, montageGraphics);
}
return this.OutputImage(montageImage);
}
}
catch (Exception) { throw; }
finally
{
// Dispose of any Images
if (Images != null)
foreach (Image i in Images)
i.Dispose();
}
}
private void DoHorizontalLayout(List<Image> Images, Graphics MontageGraphics)
{
float imageScale;
float imagePosition = 0;
int imagesWidthTotal = Images.Sum(i => i.Width);
int imagesHeightMax = Images.Max(i => i.Height);
int imagesPadding = ((Images.Count - 1) * this.Padding);
imageScale = (float)(MontageGraphics.VisibleClipBounds.Width - imagesPadding) / (float)imagesWidthTotal;
if ((MontageGraphics.VisibleClipBounds.Height / (float)imagesHeightMax) < imageScale)
imageScale = (float)MontageGraphics.VisibleClipBounds.Height / (float)imagesHeightMax;
foreach (Image image in Images)
{
MontageGraphics.DrawImageResized(image, imageScale, imagePosition, 0);
imagePosition += (imageScale * image.Width) + this.Padding;
}
}
private void DoVirticalLayout(List<Image> Images, Graphics MontageGraphics)
{
float imageScale;
float imagePosition = 0;
int imagesWidthMax = Images.Max(i => i.Width);
int imagesHeightTotal = Images.Sum(i => i.Height);
int imagesPadding = ((Images.Count - 1) * this.Padding);
imageScale = (float)(MontageGraphics.VisibleClipBounds.Height - imagesPadding) / (float)imagesHeightTotal;
if ((MontageGraphics.VisibleClipBounds.Width / (float)imagesWidthMax) < imageScale)
imageScale = (float)MontageGraphics.VisibleClipBounds.Width / (float)imagesWidthMax;
foreach (Image image in Images)
{
MontageGraphics.DrawImageResized(image, imageScale, 0, imagePosition);
imagePosition += (imageScale * image.Height) + this.Padding;
}
}
private void DoTableLayout(List<Image> Images, Graphics MontageGraphics)
{
var stageSize = MontageGraphics.VisibleClipBounds.Size.ToSize();
var itemAverageSize = new SizeF(Images.Average(i => (float)i.Size.Width), Images.Average(i => (float)i.Size.Height));
var calculatedLayout = CalculateColumnCount(stageSize, itemAverageSize, Images.Count);
SizeF cellSize = new SizeF((MontageGraphics.VisibleClipBounds.Width - ((calculatedLayout.Item1 - 1) * this.Padding)) / calculatedLayout.Item1,
(MontageGraphics.VisibleClipBounds.Height - ((calculatedLayout.Item2 - 1) * this.Padding)) / calculatedLayout.Item2);
int imageIndex = 0;
for (int rowIndex = 0; rowIndex < calculatedLayout.Item2; rowIndex++)
{
for (int columnIndex = 0; columnIndex < calculatedLayout.Item1; columnIndex++)
{
if (imageIndex < Images.Count)
{
var image = Images[imageIndex];
var cellPoint = new PointF((cellSize.Width * columnIndex) + (this.Padding * columnIndex), (cellSize.Height * rowIndex) + (this.Padding * rowIndex));
MontageGraphics.Clip = new Region(new RectangleF(cellPoint, cellSize));
MontageGraphics.DrawImageResized(image);
imageIndex++;
}
else
break;
}
}
}
private Tuple<int, int, double> CalculateColumnCount(Size StageSize, SizeF ItemAverageSize, int ItemCount)
{
double? bestUsedSpace = null;
int bestColumnCount = 1;
int bestRowCount = 1;
double bestItemRatio = 1;
for (int columnCount = 1; columnCount <= ItemCount; columnCount++)
{
int rowCount = (int)Math.Ceiling((double)ItemCount / (double)columnCount);
int requiredWidthPadding = (columnCount - 1) * this.Padding;
int requiredHeightPadding = (rowCount - 1) * this.Padding;
Size usableStageSize = new Size(StageSize.Width - requiredWidthPadding, StageSize.Height - requiredHeightPadding);
double stageWidthRatio = (float)usableStageSize.Width / (float)usableStageSize.Height;
double stageHeightRatio = (float)usableStageSize.Height / (float)usableStageSize.Width;
int requiredWidth = (int)Math.Ceiling(ItemAverageSize.Width * columnCount);
int requiredHeight = (int)Math.Ceiling(ItemAverageSize.Height * rowCount);
int usedSpace = requiredWidth * requiredHeight;
int stageArea = Math.Max((requiredWidth * (int)Math.Ceiling(requiredWidth * stageHeightRatio)),
(requiredHeight * (int)Math.Ceiling(requiredHeight * stageWidthRatio)));
double usedStageSpace = (double)usedSpace / stageArea;
if (bestUsedSpace == null || bestUsedSpace < usedStageSpace)
{
bestUsedSpace = usedStageSpace;
bestColumnCount = columnCount;
bestRowCount = rowCount;
bestItemRatio = Math.Min((double)usableStageSize.Width / (double)requiredWidth, (double)usableStageSize.Height / (double)requiredHeight);
}
}
return new Tuple<int, int, double>(bestColumnCount, bestRowCount, bestItemRatio);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using Disco.BI.Extensions;
namespace Disco.BI.Expressions.Extensions.ImageResultImplementations
{
public class FileMontageImageExpressionResult : BaseImageExpressionResult
{
public List<string> AbsoluteFilePaths { get; set; }
public bool MontageHorizontalLayout { get; set; }
public bool MontageVerticalLayout { get; set; }
public bool MontageTableLayout { get; set; }
public int Padding { get; set; }
public FileMontageImageExpressionResult(List<string> AbsoluteFilePaths)
{
if (AbsoluteFilePaths == null)
throw new ArgumentNullException("AbsoluteFilePaths");
if (AbsoluteFilePaths.Count == 0)
throw new ArgumentException("AbsoluteFilePaths is empty", "AbsoluteFilePaths");
this.AbsoluteFilePaths = AbsoluteFilePaths;
this.MontageTableLayout = true;
this.Padding = 4;
}
public override Stream GetImage(int Width, int Height)
{
List<Image> Images = new List<Image>();
try
{
// Load Images
foreach (string imageFilePath in this.AbsoluteFilePaths)
Images.Add(Bitmap.FromFile(imageFilePath));
// Build Montage
using (Bitmap montageImage = new Bitmap(Width, Height))
{
using (Graphics montageGraphics = Graphics.FromImage(montageImage))
{
montageGraphics.CompositingQuality = CompositingQuality.HighQuality;
montageGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
montageGraphics.SmoothingMode = SmoothingMode.HighQuality;
// Draw Background
if (!LosslessFormat || !BackgroundPreferTransparent)
{
Brush backgroundBrush = Brushes.White;
if (!string.IsNullOrEmpty(this.BackgroundColour))
backgroundBrush = new SolidBrush(ColorTranslator.FromHtml(this.BackgroundColour));
montageGraphics.FillRectangle(backgroundBrush, montageGraphics.VisibleClipBounds);
}
if (this.MontageHorizontalLayout)
DoHorizontalLayout(Images, montageGraphics);
else
if (this.MontageVerticalLayout)
DoVirticalLayout(Images, montageGraphics);
else
DoTableLayout(Images, montageGraphics);
}
return this.OutputImage(montageImage);
}
}
catch (Exception) { throw; }
finally
{
// Dispose of any Images
if (Images != null)
foreach (Image i in Images)
i.Dispose();
}
}
private void DoHorizontalLayout(List<Image> Images, Graphics MontageGraphics)
{
float imageScale;
float imagePosition = 0;
int imagesWidthTotal = Images.Sum(i => i.Width);
int imagesHeightMax = Images.Max(i => i.Height);
int imagesPadding = ((Images.Count - 1) * this.Padding);
imageScale = (float)(MontageGraphics.VisibleClipBounds.Width - imagesPadding) / (float)imagesWidthTotal;
if ((MontageGraphics.VisibleClipBounds.Height / (float)imagesHeightMax) < imageScale)
imageScale = (float)MontageGraphics.VisibleClipBounds.Height / (float)imagesHeightMax;
foreach (Image image in Images)
{
MontageGraphics.DrawImageResized(image, imageScale, imagePosition, 0);
imagePosition += (imageScale * image.Width) + this.Padding;
}
}
private void DoVirticalLayout(List<Image> Images, Graphics MontageGraphics)
{
float imageScale;
float imagePosition = 0;
int imagesWidthMax = Images.Max(i => i.Width);
int imagesHeightTotal = Images.Sum(i => i.Height);
int imagesPadding = ((Images.Count - 1) * this.Padding);
imageScale = (float)(MontageGraphics.VisibleClipBounds.Height - imagesPadding) / (float)imagesHeightTotal;
if ((MontageGraphics.VisibleClipBounds.Width / (float)imagesWidthMax) < imageScale)
imageScale = (float)MontageGraphics.VisibleClipBounds.Width / (float)imagesWidthMax;
foreach (Image image in Images)
{
MontageGraphics.DrawImageResized(image, imageScale, 0, imagePosition);
imagePosition += (imageScale * image.Height) + this.Padding;
}
}
private void DoTableLayout(List<Image> Images, Graphics MontageGraphics)
{
var stageSize = MontageGraphics.VisibleClipBounds.Size.ToSize();
var itemAverageSize = new SizeF(Images.Average(i => (float)i.Size.Width), Images.Average(i => (float)i.Size.Height));
var calculatedLayout = CalculateColumnCount(stageSize, itemAverageSize, Images.Count);
SizeF cellSize = new SizeF((MontageGraphics.VisibleClipBounds.Width - ((calculatedLayout.Item1 - 1) * this.Padding)) / calculatedLayout.Item1,
(MontageGraphics.VisibleClipBounds.Height - ((calculatedLayout.Item2 - 1) * this.Padding)) / calculatedLayout.Item2);
int imageIndex = 0;
for (int rowIndex = 0; rowIndex < calculatedLayout.Item2; rowIndex++)
{
for (int columnIndex = 0; columnIndex < calculatedLayout.Item1; columnIndex++)
{
if (imageIndex < Images.Count)
{
var image = Images[imageIndex];
var cellPoint = new PointF((cellSize.Width * columnIndex) + (this.Padding * columnIndex), (cellSize.Height * rowIndex) + (this.Padding * rowIndex));
MontageGraphics.Clip = new Region(new RectangleF(cellPoint, cellSize));
MontageGraphics.DrawImageResized(image);
imageIndex++;
}
else
break;
}
}
}
private Tuple<int, int, double> CalculateColumnCount(Size StageSize, SizeF ItemAverageSize, int ItemCount)
{
double? bestUsedSpace = null;
int bestColumnCount = 1;
int bestRowCount = 1;
double bestItemRatio = 1;
for (int columnCount = 1; columnCount <= ItemCount; columnCount++)
{
int rowCount = (int)Math.Ceiling((double)ItemCount / (double)columnCount);
int requiredWidthPadding = (columnCount - 1) * this.Padding;
int requiredHeightPadding = (rowCount - 1) * this.Padding;
Size usableStageSize = new Size(StageSize.Width - requiredWidthPadding, StageSize.Height - requiredHeightPadding);
double stageWidthRatio = (float)usableStageSize.Width / (float)usableStageSize.Height;
double stageHeightRatio = (float)usableStageSize.Height / (float)usableStageSize.Width;
int requiredWidth = (int)Math.Ceiling(ItemAverageSize.Width * columnCount);
int requiredHeight = (int)Math.Ceiling(ItemAverageSize.Height * rowCount);
int usedSpace = requiredWidth * requiredHeight;
int stageArea = Math.Max((requiredWidth * (int)Math.Ceiling(requiredWidth * stageHeightRatio)),
(requiredHeight * (int)Math.Ceiling(requiredHeight * stageWidthRatio)));
double usedStageSpace = (double)usedSpace / stageArea;
if (bestUsedSpace == null || bestUsedSpace < usedStageSpace)
{
bestUsedSpace = usedStageSpace;
bestColumnCount = columnCount;
bestRowCount = rowCount;
bestItemRatio = Math.Min((double)usableStageSize.Width / (double)requiredWidth, (double)usableStageSize.Height / (double)requiredHeight);
}
}
return new Tuple<int, int, double>(bestColumnCount, bestRowCount, bestItemRatio);
}
}
}
+51 -51
View File
@@ -1,51 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.BI.Interop.ActiveDirectory;
namespace Disco.BI.Expressions.Extensions
{
public static class UserExt
{
public static object GetActiveDirectoryObjectValue(User User, string PropertyName, int Index = 0)
{
var adUserAccount = User.ActiveDirectoryAccount(PropertyName);
if (adUserAccount != null)
return adUserAccount.GetPropertyValue(PropertyName, Index);
else
return null;
}
public static string GetActiveDirectoryStringValue(User User, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(User, PropertyName, Index);
string stringValue = objectValue as string;
if (stringValue == null && objectValue != null)
stringValue = objectValue.ToString();
return stringValue;
}
public static int GetActiveDirectoryIntegerValue(User User, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(User, PropertyName, Index);
if (objectValue == null)
return default(int);
else
{
int intValue;
try
{
intValue = (int)Convert.ChangeType(objectValue, typeof(int));
}
catch (Exception)
{
throw;
}
return intValue;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.BI.Interop.ActiveDirectory;
namespace Disco.BI.Expressions.Extensions
{
public static class UserExt
{
public static object GetActiveDirectoryObjectValue(User User, string PropertyName, int Index = 0)
{
var adUserAccount = User.ActiveDirectoryAccount(PropertyName);
if (adUserAccount != null)
return adUserAccount.GetPropertyValue(PropertyName, Index);
else
return null;
}
public static string GetActiveDirectoryStringValue(User User, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(User, PropertyName, Index);
string stringValue = objectValue as string;
if (stringValue == null && objectValue != null)
stringValue = objectValue.ToString();
return stringValue;
}
public static int GetActiveDirectoryIntegerValue(User User, string PropertyName, int Index = 0)
{
var objectValue = GetActiveDirectoryObjectValue(User, PropertyName, Index);
if (objectValue == null)
return default(int);
else
{
int intValue;
try
{
intValue = (int)Convert.ChangeType(objectValue, typeof(int));
}
catch (Exception)
{
throw;
}
return intValue;
}
}
}
}
+16 -16
View File
@@ -1,16 +1,16 @@
using System;
using System.Collections;
namespace Disco.BI.Expressions
{
public interface IExpressionPart
{
string RawSource { get; set; }
string Source { get; set; }
bool ErrorsAllowed { get; set; }
bool ParseError { get; }
string ParseErrorMessage { get; }
bool IsDynamic { get; set; }
object Evaluate(object ExpressionContext, System.Collections.IDictionary Variables);
}
}
using System;
using System.Collections;
namespace Disco.BI.Expressions
{
public interface IExpressionPart
{
string RawSource { get; set; }
string Source { get; set; }
bool ErrorsAllowed { get; set; }
bool ParseError { get; }
string ParseErrorMessage { get; }
bool IsDynamic { get; set; }
object Evaluate(object ExpressionContext, System.Collections.IDictionary Variables);
}
}
+74 -74
View File
@@ -1,74 +1,74 @@
using System;
using System.Collections;
namespace Disco.BI.Expressions
{
public class TextExpressionPart : IExpressionPart
{
private string _Source;
bool IExpressionPart.ErrorsAllowed
{
get
{
return false;
}
set
{
return;
}
}
string IExpressionPart.Source
{
get
{
return this._Source;
}
set
{
return;
}
}
string IExpressionPart.RawSource
{
get
{
return this._Source;
}
set
{
return;
}
}
bool IExpressionPart.IsDynamic
{
get
{
return false;
}
set
{
return;
}
}
public bool ParseError
{
get { return false; }
}
public string ParseErrorMessage
{
get { return null; }
}
public TextExpressionPart(string Source)
{
this._Source = Source;
}
object IExpressionPart.Evaluate(object ExpressionContext, System.Collections.IDictionary Variables)
{
return this._Source;
}
}
}
using System;
using System.Collections;
namespace Disco.BI.Expressions
{
public class TextExpressionPart : IExpressionPart
{
private string _Source;
bool IExpressionPart.ErrorsAllowed
{
get
{
return false;
}
set
{
return;
}
}
string IExpressionPart.Source
{
get
{
return this._Source;
}
set
{
return;
}
}
string IExpressionPart.RawSource
{
get
{
return this._Source;
}
set
{
return;
}
}
bool IExpressionPart.IsDynamic
{
get
{
return false;
}
set
{
return;
}
}
public bool ParseError
{
get { return false; }
}
public string ParseErrorMessage
{
get { return null; }
}
public TextExpressionPart(string Source)
{
this._Source = Source;
}
object IExpressionPart.Evaluate(object ExpressionContext, System.Collections.IDictionary Variables)
{
return this._Source;
}
}
}