/// <summary> /// Executes a printing operation using a specific <see cref="PrintingQueue"/> and action. /// </summary> /// <param name="queue">The printing queue to use. Must not be null.</param> /// <param name="printAction">The printing action. Must not be null.</param> public static void Print(PrintingQueue queue, PrintDelegate printAction) { Assertions.AssertNotNull(queue, "queue"); Assertions.AssertNotNull(printAction, "printAction"); if (!queue.IsValid) { Logger.Instance.LogFormat(LogType.Warning, typeof(GdiPrinter), Resources.GdiPrinterPrintingQueueIsNotValid, queue.Name); return; } PrintDocument doc = new PrintDocument(); if (!queue.IsDefaultPrinter) { doc.PrinterSettings.PrinterName = queue.GetPrinterName(); } int desiredCopyCount = queue.CopyCount; int maxSupportedCopyCount = doc.PrinterSettings.MaximumCopies; int requiredPrintIterations = 1; if (desiredCopyCount <= maxSupportedCopyCount && !queue.UseAlternativeCopyingMethod) { doc.PrinterSettings.Copies = (short)desiredCopyCount; } else { //Check of the user has requested using this way of printing copies! if (!queue.UseAlternativeCopyingMethod) { // It appears that some printers don't support the CopyCount-feature (notably Microsoft XPS Writer or perhaps PDF-Writers in general?). // In this case we simply repeat printing until we have reached our copy count. Logger.Instance.LogFormat(LogType.Warning, typeof(GdiPrinter), Resources.UsedPrinterDoesNotSupportThatMuchCopies, maxSupportedCopyCount, desiredCopyCount); } requiredPrintIterations = desiredCopyCount; } for (int i = 0; i < requiredPrintIterations; i++) { Logger.Instance.LogFormat(LogType.Trace, typeof(GdiPrinter), Resources.PrintIterationStart, i + 1, requiredPrintIterations); PrintTask task = new PrintTask(); try { task.Print(doc, printAction); } catch (Exception ex) { Logger.Instance.LogFormat(LogType.Error, typeof(GdiPrinter), Resources.GdiPrinterPrintTaskException); Logger.Instance.LogException(typeof(GdiPrinter), ex); } Logger.Instance.LogFormat(LogType.Trace, typeof(GdiPrinter), Resources.PrintIterationEnd); } }
/// <summary> /// Returns the <see cref="Binding"/> that will be used for the service of the given type. /// </summary> /// <param name="contractType">The service contract type (must be an interface) to get the binding for.</param> /// <returns></returns> public static Binding GetBindingForContractType(Type contractType) { Assertions.AssertNotNull(contractType, "contractType"); if (!_bindingCache.ContainsKey(contractType)) { _bindingCache[contractType] = FindBindingForContractType(contractType); } return(_bindingCache[contractType]); }
/// <summary> /// Initializes a new instance of the <see cref="JobManager"/> class. /// </summary> /// <param name="serviceProvider">The service provider used for retrieving server-side services.</param> public JobManager(IServiceProvider serviceProvider) : this() { Assertions.AssertNotNull(serviceProvider, "serviceProvider"); _serviceProvider = serviceProvider; _settingsService = _serviceProvider.GetService <ISettingsServiceInternal>(); _settingsService.SettingChanged += SettingsService_OnSettingChanged; }
private static ErrorReport CreateErrorReportInternal(ErrorReport report) { Assertions.AssertNotNull(report, "report"); report.Timestamp = DateTime.UtcNow; StoreErrorReport(report); return(report); }
/// <summary> /// Initializes a new instance of the <see cref="AlarmWorkflowEngine"/> class. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="serviceProvider"></param> /// <param name="settings"></param> public AlarmWorkflowEngine(Configuration configuration, IServiceProvider serviceProvider, ISettingsServiceInternal settings) : this() { Assertions.AssertNotNull(configuration, "configuration"); Assertions.AssertNotNull(serviceProvider, "serviceProvider"); Assertions.AssertNotNull(settings, "settings"); _configuration = configuration; _serviceProvider = serviceProvider; _settingsService = settings; }
/// <summary> /// Initializes a new instance of the <see cref="SettingItem"/> class. /// </summary> /// <param name="identifier">The identifier that this setting is associated with.</param> /// <param name="name">The name of this setting.</param> /// <param name="defaultValue">The default value of this setting.</param> /// <param name="type">The type of the setting.</param> internal SettingItem(string identifier, string name, string defaultValue, Type type) : this() { Assertions.AssertNotEmpty(identifier, "identifier"); Assertions.AssertNotEmpty(name, "name"); Assertions.AssertNotNull(type, "type"); this.Identifier = identifier; this.Name = name; this.SettingType = type; _defaultValueSerialized = defaultValue; }
/// <summary> /// Traverses the property graph of an object and sets a certain property to a given value. /// </summary> /// <param name="graph">The object graph to use. Must not be null.</param> /// <param name="expression">The expression of the property to set. Must not be empty.</param> /// <param name="value">The value to set.</param> /// <exception cref="T:MissingFieldException">A certain property in the expression was not found.</exception> /// <exception cref="T:ExpressionNotSupportedException">The expression was not supported.</exception> public static void SetValueFromExpression(object graph, string expression, object value) { Assertions.AssertNotNull(graph, "graph"); Assertions.AssertNotEmpty(expression, "expression"); PropertyInfo property = null; object target = null; GetPropertyFromExpression(graph, expression, true, out property, out target); property.SetValue(target, value, null); }
/// <summary> /// Traverses the property graph of an object and returns the value of a certain property. /// </summary> /// <param name="graph">The object graph to use. Must not be null.</param> /// <param name="expression">The expression of the property to set. Must not be empty.</param> /// <returns>The value of the property.</returns> /// <exception cref="T:MissingFieldException">A certain property in the expression was not found.</exception> /// <exception cref="T:ExpressionNotSupportedException">The expression was not supported.</exception> public static object GetValueFromExpression(object graph, string expression) { Assertions.AssertNotNull(graph, "graph"); Assertions.AssertNotEmpty(expression, "expression"); PropertyInfo property = null; object target = null; GetPropertyFromExpression(graph, expression, true, out property, out target); return(property.GetValue(target, null)); }
internal ResourceViewModel(OperationResource resource, EmkResource emkResource) : base() { Assertions.AssertNotNull(resource, "resource"); this.Resource = resource; _emkResource = emkResource; if (_emkResource != null) { LoadIconAsync(); } }
/// <summary> /// Initializes this service after being added to the service manager. /// </summary> /// <param name="serviceProvider">The service provider to set.</param> public void Initialize(IServiceProvider serviceProvider) { Assertions.AssertNotNull(serviceProvider, "serviceProvider"); if (IsInitialized) { return; } ServiceProvider = serviceProvider; InitializeOverride(); IsInitialized = true; }
SettingItem ISettingsServiceInternal.GetSetting(SettingKey key) { Assertions.AssertNotNull(key, "key"); SettingItem item = _settings.GetSetting(key.Identifier, key.Name); lock (SyncRoot) { ApplySettingValue(key.Identifier, key.Name, item); } return(item); }
/// <summary> /// Creates a service connection to the callback service behind the specified service interface. /// Please prefer <see cref="M:GetServiceWrapper{T}()"/> method! /// See documentation for further information. /// </summary> /// <remarks>Use this method only if you need to keep a connection to a service open longer than possible with <see cref="M:GetServiceWrapper{T}()"/>. /// When finished with the work (or it is safe to release the instance), make a call to <see cref="M:CloseServiceInstance(object)"/> to safely close and dispose the service connection.</remarks> /// <typeparam name="T">The service interface type.</typeparam> /// <param name="callbackObject">The object representing the callback to use. Must not be null.</param> /// <returns>A service connection to the service behind the specified service interface.</returns> public static T GetCallbackServiceInstance <T>(object callbackObject) where T : class, IExposedService { AssertContractTypeCorrect(typeof(T)); Assertions.AssertNotNull(callbackObject, "callbackObject"); Binding binding = ServiceBindingCache.GetBindingForContractType(typeof(T)); DuplexChannelFactory <T> d = new DuplexChannelFactory <T>(callbackObject, binding, GetEndpointAddress(typeof(T), binding)); T channel = d.CreateChannel(); channel.Ping(); return(channel); }
/// <summary> /// Creates the database context for a connection to the specified server. /// </summary> /// <typeparam name="T">The ObjectContext type to create.</typeparam> /// <param name="options">The options to use for connection.</param> /// <returns>The created database context (derived from <see cref="ObjectContext"/>).</returns> public static T CreateContext <T>(ContextCreationOptions options) where T : ObjectContext { Assertions.AssertNotNull(options, "options"); string connectionString = string.Format(ConnectionStringTemplate, options.EdmxPath, options.HostName, options.Port, options.UserId, options.Password, options.DatabaseName); return((T)Activator.CreateInstance(typeof(T), connectionString)); }
void IFileCache.StoreFile(string path, Stream content) { Assertions.AssertNotEmpty(path, "path"); Assertions.AssertNotNull(content, "content"); string absPath = GetAbsolutePath(GetStringHash(path)); EnsureCacheDirectoryExists(); using (FileStream destination = new FileStream(absPath, FileMode.Create, FileAccess.Write)) { content.CopyTo(destination); } }
/// <summary> /// Creates the <see cref="EndpointAddress"/> appropriate for the given contract type. /// </summary> /// <param name="contractType">The type representing the WCF-service contract to get the endpoint address for.</param> /// <param name="binding">The binding that is used.</param> /// <returns>The <see cref="EndpointAddress"/> appropriate for the given contract type.</returns> public static EndpointAddress GetEndpointAddress(Type contractType, Binding binding) { Assertions.AssertNotNull(contractType, "contractType"); Assertions.AssertNotNull(binding, "binding"); AssertContractTypeCorrect(contractType); string serviceName = contractType.Name.Remove(0, 1); return(new EndpointAddress(string.Format("{0}://{1}:{2}/{3}/{4}", binding.Scheme, EndPointResolver.GetServerAddress().ToString(), GetPortForBinding(binding), ServicesPath, serviceName.ToLowerInvariant()))); }
/// <summary> /// Returns an array containing the names of all properties in the specified type, including children. /// </summary> /// <param name="type">The type to get all properties from. Must not be null.</param> /// <param name="disallowedPropertyNames">An array containing the names of the properties that shall be ignored in the result.</param> /// <param name="requireCanWrite">Whether or not only writeable properties are returned.</param> /// <returns>An array containing the names of all properties in the specified type, including children.</returns> public static string[] GetPropertyNames(Type type, string[] disallowedPropertyNames, bool requireCanWrite) { Assertions.AssertNotNull(type, "type"); if (disallowedPropertyNames == null) { disallowedPropertyNames = new string[0]; } List <string> propertiesTemp = new List <string>(); FillAllowedProperties(type, "", disallowedPropertyNames, requireCanWrite, propertiesTemp); propertiesTemp.Sort(); return(propertiesTemp.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionDetail"/> class. /// </summary> /// <param name="exception">The exception object. Must not be null.</param> internal ExceptionDetail(Exception exception) : this() { Assertions.AssertNotNull(exception, "exception"); this.Type = exception.GetType().AssemblyQualifiedName; this.Message = exception.Message; this.Source = exception.Source; this.StackTrace = exception.StackTrace; if (exception.InnerException != null) { this.InnerException = new ExceptionDetail(exception.InnerException); } }
/// <summary> /// Un-wires all previously wired up commands (by <see cref="WireupRelayCommands(object)"/>) so they can be garbage-collected. /// </summary> /// <param name="instance">The instance with wired-up commands.</param> public static void UnwireRelayCommands(object instance) { Assertions.AssertNotNull(instance, "instance"); foreach (PropertyInfo property in instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => p.PropertyType == typeof(ICommand))) { RelayCommand value = property.GetValue(instance, null) as RelayCommand; if (value == null) { continue; } property.SetValue(instance, null, null); } }
/// <summary> /// Creates a new FaultException with our fault details based on an existing exception. /// </summary> /// <param name="exception">The exception to wrap.</param> /// <returns></returns> public static FaultException <AlarmWorkflowFaultDetails> CreateFault(Exception exception) { Assertions.AssertNotNull(exception, "exception"); if (exception is FaultException <AlarmWorkflowFaultDetails> ) { return((FaultException <AlarmWorkflowFaultDetails>)exception); } FaultReason reason = new FaultReason(exception.Message); FaultCode code = new FaultCode("(No code)"); AlarmWorkflowFaultDetails detail = new AlarmWorkflowFaultDetails(exception); return(new FaultException <AlarmWorkflowFaultDetails>(detail, reason, code)); }
void ISettingsServiceInternal.SetSettings(IEnumerable <KeyValuePair <SettingKey, SettingItem> > values) { Assertions.AssertNotNull(values, "values"); IEnumerable <SettingKey> savedSettings = null; lock (SyncRoot) { savedSettings = SaveSettings(values); } if (savedSettings != null && savedSettings.Any()) { OnSettingChanged(new SettingChangedEventArgs(savedSettings)); } }
/// <summary> /// Manually closes the specified service instance. This method is a counterpart to GetServiceInstance(). /// </summary> /// <param name="serviceInstance">The service instance to close.</param> public static void CloseServiceInstance(object serviceInstance) { Assertions.AssertNotNull(serviceInstance, "serviceInstance"); ICommunicationObject obj = serviceInstance as ICommunicationObject; if (obj == null) { throw new ArgumentException(Properties.Resources.ServiceFactoryInstanceIsNotAServiceObject); } // Pessimistic: Don't continue if this object is faulted (don't throw an exception here) if (obj.State == CommunicationState.Faulted) { return; } obj.Close(); }
/// <summary> /// Traverses the property graph of an object and sets a certain property to a given value. /// </summary> /// <param name="graph">The object graph to use. Must not be null.</param> /// <param name="expression">The expression of the property to set. Must not be empty.</param> /// <param name="value">The value to set.</param> /// <returns>Whether or not the value could be set. If this returns <c>false</c>, then the expression led to a nonexistent property.</returns> public static bool TrySetValueFromExpression(object graph, string expression, object value) { Assertions.AssertNotNull(graph, "graph"); Assertions.AssertNotEmpty(expression, "expression"); PropertyInfo property = null; object target = null; bool success = GetPropertyFromExpression(graph, expression, false, out property, out target); if (!success) { value = null; return(false); } property.SetValue(target, value, null); return(true); }
SettingItem ISettingsServiceInternal.GetSetting(SettingKey key) { try { Assertions.AssertNotNull(key, "key"); SettingItem item = _settings.GetSetting(key.Identifier, key.Name); lock (SyncRoot) { ApplySettingValue(key.Identifier, key.Name, item); } return(item); } catch (Exception ex) { throw AlarmWorkflowFaultDetails.CreateFault(ex); } }
void ISettingsServiceInternal.SetSettings(IEnumerable <KeyValuePair <SettingKey, SettingItem> > values) { try { Assertions.AssertNotNull(values, "values"); IEnumerable <SettingKey> savedSettings = null; lock (SyncRoot) { savedSettings = SaveSettings(values); } if (savedSettings != null && savedSettings.Any()) { OnSettingChanged(new SettingChangedEventArgs(savedSettings)); } } catch (Exception ex) { throw AlarmWorkflowFaultDetails.CreateFault(ex); } }
/// <summary> /// Parses a string that tells how to format an object using macros within curly braces. /// </summary> /// <param name="graph">The object graph to use. Must not be null.</param> /// <param name="format">The format string, using the property values in curly braces (expressions), like {Property}. Must not be empty.</param> /// <returns>The formatted string.</returns> public virtual string ToString(TInput graph, string format) { Assertions.AssertNotNull(graph, "graph"); Assertions.AssertNotEmpty(format, "format"); StringBuilder sb = new StringBuilder(format); if (Options.HasFlag(ObjectFormatterOptions.RemoveNewlines)) { sb.Replace("\n", " "); sb.Replace(Environment.NewLine, " "); } foreach (string macro in GetMacros(format)) { string expression = macro.Substring(1, macro.Length - 2); string value = ProcessMacro(graph, macro, expression); sb.Replace(macro, value); } return(sb.ToString()); }
public async Task Test() { Assertions.AssertNotNull(_node1); Assertions.AssertNotNull(_node2); Assertions.AssertNotNull(_subNode); }
/// <summary> /// Creates a new instance of a ResourceItem. /// </summary> /// <param name="emkResource">The <see cref="EmkResource"/>. Must not be null!</param> public ResourceItem(EmkResource emkResource) { Assertions.AssertNotNull(emkResource, "emkResource"); EmkResourceItem = emkResource; }
/// <summary> /// Examines every resource that is contained in this collection and returns a boolean value if at least /// one resource matches the given <see cref="OperationResource"/>. /// See documentation for further information. /// </summary> /// <remarks>Any given <see cref="EmkResource"/> is only considered if it has its IsActive-flag set to true.</remarks> /// <param name="resource">The <see cref="OperationResource"/> to check. Must not be null.</param> /// <returns>A boolean value indicating whether or not at least one resource matches the given <see cref="OperationResource"/>.</returns> public bool ContainsMatch(OperationResource resource) { Assertions.AssertNotNull(resource, "resource"); return(Items.Any(item => item.IsActive && item.IsMatch(resource))); }
/// <summary> /// Automatically wires up relay commands. /// Performs this operation by searching for public properties of type "ICommand" and for methods which have "PROPERTYNAME_Execute" or "PROPERTYNAME_CanExecute". /// </summary> /// <param name="instance">The instance to wire up.</param> public static void WireupRelayCommands(object instance) { Assertions.AssertNotNull(instance, "instance"); WireupRelayCommands(instance.GetType(), instance); }
/// <summary> /// Initializes a new instance of the <see cref="ErrorReport"/> class. /// </summary> /// <param name="exception">The exception object to base this error report on. Must not be null.</param> public ErrorReport(Exception exception) : this() { Assertions.AssertNotNull(exception, "exception"); this.Exception = new ExceptionDetail(exception); }