/// <summary> /// Adds the metrics class fetch methods. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddMetricsClassFetchMethods(StringBuilder assemblyCode, IProcessDefinition process) { }
/// <summary> /// Generates the load security properties. /// </summary> /// <param name="process">The process.</param> /// <returns>System.String.</returns> private string generateLoadSecurityProperties(IProcessDefinition process) { var list = new List<string> { string.Format( @" if (!CanReadProperty(""{0}"")) accessDeniedList.Add(""{0}"");", Constants.DerivedProcessDisplayNameColumnName) }; foreach (var field in process.RootTable.FieldList.Where(x => !x.IsHidden && x.IncludeInList && x.ColumnType != ColumnTypes.MultiReference)) { if (field.ColumnName == Constants.IdColumnName || field.ColumnName == Constants.CurrentStateColumnName || field.ColumnName == Constants.DerivedProcessColumnName) continue; var prop = string.Format(@" if (!CanReadProperty(""{0}"")) accessDeniedList.Add(""{0}"");", field.ColumnName); list.Add(prop); } foreach (var field in process.RootTable.FieldList.Where(f => !f.IsHidden && f.IncludeInList && f.ColumnType == ColumnTypes.MultiReference)) list.Add(string.Format( @" if (!CanReadProperty(""{0}"")) accessDeniedList.Add(""{0}""); ", field.ColumnName)); if (process.HasBaseClass) list.Add(string.Format(@" BaseInfo.SetInheritanceContext(this); var baseAccessDeniedList = BaseInfo.CalculateAccessDeniedList(reader); foreach (var s in baseAccessDeniedList) accessDeniedList.Add(s); ")); return string.Join(Environment.NewLine, list); }
/// <summary> /// Adds the URL call definition. /// </summary> /// <param name="assemblyCode"> /// The assembly code. /// </param> /// <param name="process"> /// The process. /// </param> /// <param name="callDefinition"> /// The call definition. /// </param> /// <param name="variableCollection"> /// The variable collection. /// </param> /// <returns> /// The <see cref="VariableInfo"/>. /// </returns> private VariableInfo AddUrlCallDefinition( StringBuilder assemblyCode, IProcessDefinition process, IntegrationServiceCallDefinition callDefinition, VariableCollection variableCollection) { var callSettings = (IntegrationServiceUrlCallDefinition)callDefinition.CallSettings; var variableInfo = variableCollection.NewVariable(); var variableName = variableInfo.Name; assemblyCode.AppendFormat( @" var {0} = new Cebos.Veyron.SharedTypes.Integration.UrlCallDefinition(); {0}.Name = {1}; {0}.CallLocation = Cebos.Veyron.SharedTypes.UrlServiceCallLocation.{2}; {0}.HttpMethod = Cebos.Veyron.SharedTypes.UrlServiceCallMethod.{3}; {0}.Guid = System.Guid.Parse({4}); {0}.ProcessDisplayName = {5};", variableName, callDefinition.Name.ToLiteral(), callSettings.CallLocation, callSettings.HttpMethod, callDefinition.Guid.ToString().ToLiteral(), process.DisplayName.ToLiteral()); if (!string.IsNullOrEmpty(callSettings.AddressExpression)) { var script = ExpressionService.PrepareScriptFromXml(callSettings.AddressExpression); assemblyCode.AppendFormat(@" {0}.AddressExpression = item => Cebos.Veyron.SharedTypes.SafeTypeConverter.Convert<string>({1});", variableName, script); } foreach (var parameterDefinition in callSettings.Parameters) { var parameterVariable = AddUrlCallParameterDefinition(assemblyCode, parameterDefinition, variableCollection); assemblyCode.AppendFormat(@" {0}.ParameterDefinitions.Add({1}); ", variableName, parameterVariable.Name); } foreach (var rule in callDefinition.Rules) { assemblyCode.AppendFormat(@" {0}.Rules.Add({1}Metadata.RuleManager.GetRule(new System.Guid(""{2}""))); ", variableName, process.Name, rule.Guid); } return variableInfo; }
private void AddMethodDefinition(StringBuilder assemblyCode, IProcessDefinition process, IntegrationServiceMethodDefinition method) { assemblyCode.AppendFormat(@" private static Cebos.Veyron.SharedTypes.Integration.IntegrationServiceMethodDefinition Get{0}Definition() {{ var methodDefinition = new Cebos.Veyron.SharedTypes.Integration.IntegrationServiceMethodDefinition(); methodDefinition.ProcessName = {1}; ", method.Name, process.Name.ToLiteral()); var parameterExpressionScripts = ExpressionService.PrepareScriptForMultipleDestinations(method.ParametersMapping, null); var variableCollection = new VariableCollection(); foreach (var fieldMapping in method.DestinationFields) { var mappingVariable = AddFieldMapping(assemblyCode, fieldMapping, parameterExpressionScripts, variableCollection); assemblyCode.AppendFormat(@" methodDefinition.ParameterMappings.Add({0}); ", mappingVariable.Name); } if (!string.IsNullOrEmpty(method.ResultType)) { assemblyCode.AppendFormat(@" methodDefinition.ResultType = typeof(@{0}); ", method.ResultType); } if (method.ResultMapping != null) { var resultExpressionScripts = ExpressionService.PrepareScriptForMultipleDestinations(method.ResultMappingExpression, null); var mappingVariable = AddFieldMapping(assemblyCode, method.ResultMapping, resultExpressionScripts, variableCollection); assemblyCode.AppendFormat(@" methodDefinition.ResultMapping = {0}; ", mappingVariable.Name); } assemblyCode.AppendFormat(@" return methodDefinition; }} "); }
private string GetSoapExtensionAttribute(IProcessDefinition process, IntegrationServiceDefinition service) { return string.Format( "[Cebos.Veyron.SharedTypes.Integration.LogIntegrationEventExtensionAttribute({0}, {1})]", process.DisplayName.ToLiteral(), service.ServiceName.ToLiteral()); }
/// <summary> /// Generates the process data trigger. /// </summary> /// <param name="assemblyCode"> /// The assembly code. /// </param> /// <param name="process"> /// The process. /// </param> /// <param name="trigger"> /// The trigger. /// </param> /// <param name="variableIndex"> /// The variable index. /// </param> private void GenerateProcessDataTrigger(StringBuilder assemblyCode, IProcessDefinition process, DataTriggerDefinition trigger, ref int variableIndex) { assemblyCode.AppendLine(@" fields = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerFieldMapping>(); "); if (!string.IsNullOrWhiteSpace(trigger.ModificationMapping)) { var expressionScripts = ExpressionService.PrepareScriptForMultipleDestinations(trigger.ModificationMapping, new object()); foreach (var fieldMapping in trigger.FieldMappings) { var variableName = AddDataTriggerFieldMapping(assemblyCode, fieldMapping, expressionScripts, ref variableIndex); assemblyCode.AppendFormat(@" fields.Add({0});", variableName); } } assemblyCode.AppendLine(@" listFields = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerListFieldMapping>(); "); foreach (var fieldMapping in trigger.ListFieldMappings.Where(IsValid)) { assemblyCode.AppendLine(@" subfields = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerFieldMapping>();"); if (!string.IsNullOrEmpty(fieldMapping.ModificationMapping)) { var expressionScripts = ExpressionService.PrepareScriptForMultipleDestinations(fieldMapping.ModificationMapping, new object()); foreach (var childMapping in fieldMapping.FieldMappings) { var variableName = AddDataTriggerFieldMapping(assemblyCode, childMapping, expressionScripts, ref variableIndex); assemblyCode.AppendFormat(@" subfields.Add({0});", variableName); } } if (IsLinkOrUnlink(fieldMapping.ModificationType)) { var sourceDataProcessName = fieldMapping.SourceDataProcessName; var sourceDataFilterDefinition = fieldMapping.SourceDataFilterDefinition; if (!string.IsNullOrEmpty(sourceDataFilterDefinition) && sourceDataProcessName == process.Name) { sourceDataFilterDefinition = TranslateFilterDefinition(sourceDataFilterDefinition, process); } assemblyCode.AppendFormat( @" listFields.Add(new Cebos.Veyron.SharedTypes.DataTriggerListFieldMapping({0}, {1}, {2}, Cebos.Veyron.SharedTypes.DataTriggerModificationType.{3}, subfields));", sourceDataProcessName.ToLiteral(), sourceDataFilterDefinition.ToLiteral(), fieldMapping.DestinationFieldSystemName.ToLiteral(), fieldMapping.ModificationType); } else { assemblyCode.AppendLine(@" dataSources = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggers.FieldMappingDataSourceDefinition>();"); foreach (var dataSource in fieldMapping.DataSources) { assemblyCode.AppendFormat( @" dataSources.Add(new Cebos.Veyron.SharedTypes.DataTriggers.FieldMappingDataSourceDefinition({0}, {1}, {2}, {3}, {4}, {5}));", dataSource.Name.ToLiteral(), process.Name.ToLiteral(), dataSource.PropertyPath.ToLiteral(), dataSource.IncludeNewItems.ToLiteral(), dataSource.IncludeOldItems.ToLiteral(), dataSource.IncludeRemovedItems.ToLiteral()); } assemblyCode.AppendFormat( @" listFields.Add(new Cebos.Veyron.SharedTypes.DataTriggerListFieldMapping(dataSources, {0}, Cebos.Veyron.SharedTypes.DataTriggerModificationType.{1}, subfields));", fieldMapping.DestinationFieldSystemName.ToLiteral(), fieldMapping.ModificationType); } } assemblyCode.AppendLine(@" rules = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.IActionRule>(); "); foreach (var rule in trigger.Rules.Where(r => r.IsActive)) { assemblyCode.AppendFormat(CultureInfo.InvariantCulture, @" rules.Add({0}Metadata.RuleManager.GetRule(new System.Guid(""{1}"")));", process.Name, rule.Guid); } var filterDefinition = trigger.FilterDefinition; if (!string.IsNullOrEmpty(filterDefinition) && trigger.ProcessToModifySystemName == process.Name) filterDefinition = TranslateFilterDefinition(filterDefinition, process); assemblyCode.AppendFormat( @" dataTriggers.Add(new Cebos.Veyron.SharedTypes.DataTriggerDefinition( {0}, System.Guid.Parse(""{1}""), {2}, {3}, Cebos.Veyron.SharedTypes.DataTriggerModificationType.{4}, rules, new Cebos.Veyron.SharedTypes.DataTriggerMap(fields, listFields))); ", trigger.Name.ToLiteral(), trigger.Guid, trigger.ProcessToModifySystemName.ToLiteral(), filterDefinition.ToLiteral(), trigger.ModificationType); }
/// <summary> /// Adds the integration classes. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddIntegrationClasses(StringBuilder assemblyCode, IProcessDefinition process) { foreach (var service in process.IntegrationServices) { AddIntegrationServiceClass(assemblyCode, process, service); } AddIntegrationServiceCallsManagerClass(assemblyCode, process); }
/// <summary> /// Generates the load properties. /// </summary> /// <param name="process">The process.</param> /// <returns>System.String.</returns> protected virtual string GenerateLoadProperties(IProcessDefinition process) { var result = new StringBuilder(); if (process.HasBaseClass) { result.AppendFormat(@"BaseInfo.SetInheritanceContext(this); BaseInfo.ReadData(reader, columns);"); } return result.ToString(); #region Commented //var list = new List<string> // { // string.Format("\t\t\tLoadProperty({0}Property, reader.GetDBValue<int>(\"{0}\", 0));", Constants.IdColumnName), // string.Format("\t\t\tLoadProperty({0}Property, reader.GetDBValue<string>(\"{0}\", string.Empty));", Constants.DerivedProcessColumnName) // }; //if (process.HasBaseClass) // list.Add(string.Format("\t\t\tLoadProperty({0}Property, reader.GetDBValue<int>(\"{0}\", 0));", Constants.BaseIdColumnName)); //if (process.IsStateEnabled) // list.Add(string.Format("\t\t\tLoadProperty({0}Property, reader.GetDBValue<string>(\"{0}\", string.Empty));", Constants.CurrentStateColumnName)); //if (process.IsVersioningEnabled) //{ // var field = process.RootTable.FieldList.FirstOrDefault(x => x.ColumnName.Equals(Constants.VersionNumber)); // if (field != null && field.IncludeInList) // list.Add(string.Format("\t\t\tif (reader.HasColumn(\"{0}\")) LoadProperty({0}Property, reader.GetDBValue(\"{0}\", string.Empty));", Constants.VersionNumber)); // field = process.RootTable.FieldList.FirstOrDefault(x => x.ColumnName.Equals(Constants.VersionDate)); // if (field != null && field.IncludeInList) // list.Add(string.Format("\t\t\tif (reader.HasColumn(\"{0}\")) LoadProperty({0}Property, reader.GetDBValue(\"{0}\", DateTime.MinValue));", Constants.VersionDate)); //} // foreach (var field in process.RootTable.FieldList.Where(x => x.IsRuntimeAvailable && x.IncludeInSearchResults && x.ColumnType != ColumnTypes.MultiReference)) // { // if (field.ColumnName == Constants.IdColumnName || // field.ColumnName == Constants.CurrentStateColumnName || // field.ColumnName == Constants.DerivedProcessColumnName || // field.ColumnName == Constants.VersionNumber || // field.ColumnName == Constants.VersionDate) // continue; // string code = null; // var type = GetCSharpType(process.RootTable, field, true, isInfoClass: true); // var defaultValue = type.ToLowerInvariant().Equals("string") ? "string.Empty" : GetDefaultValue(field, true); // var prop = string.Format(@" // LoadProperty({0}Property, reader.GetDBValue<{2}>(""{0}"", {1})); //", field.ColumnName, defaultValue, type); // // condition '!string.IsNullOrEmpty(field.Section))' is needed to always allow the CR on process __State // // if necessary, can be replaced by something like field.Name != "State" // // all fields created by the user, should be in condition 'reader.HasColumn' // if ((field.IsRef && !string.IsNullOrEmpty(field.Section)) || field.IsReverseRef) // { // code = string.Format(@" // if (reader.HasColumn(""{0}"")) // {{ // {1} // }}", field.ColumnName, prop); // } // list.Add(code ?? prop); // } /*foreach (var crf in process.RootTable.FieldList.Where(f => f.ColumnType == ColumnTypes.Reference && f.IncludeInSearchResults)) { var s = string.Format(@" LoadProperty({0}IdProperty, reader.GetDBValue<int>(""{0}Id"", 0));", crf.ColumnName); if (!string.IsNullOrEmpty(crf.Section)) list.Add(string.Format(@" if (reader.HasColumn(""{0}Id"")) {{ {1} }}", crf.ColumnName, s)); else list.Add(s); }*/ #endregion /*foreach (var crf in process.RootTable.FieldList.Where(f => f.ColumnType == ColumnTypes.MultiReference && f.IncludeInSearchResults)) { var s = string.Format(@" LoadProperty({0}{1}Property, reader.GetDBValue<string>(""{2}_{0}{1}"", null));", crf.ColumnName, Constants.MultipleIdsCrossRefPropertyInfoClass, process.Name); if (!string.IsNullOrEmpty(crf.Section)) list.Add(string.Format(@" if (reader.HasColumn(""{3}_{0}{1}"")) {{ {2} }}", crf.ColumnName, Constants.MultipleIdsCrossRefPropertyInfoClass, s, process.Name)); else list.Add(s); } foreach (var field in process.RootTable.FieldList.Where(f => f.IsRuntimeAvailable && f.IncludeInSearchResults && f.ColumnType == ColumnTypes.MultiReference)) { var type = GetCSharpType(process.RootTable, field, true, isInfoClass: true); var defaultValue = type.ToLowerInvariant().Equals("string") ? "string.Empty" : GetDefaultValue(field, true); list.Add(string.Format( @" if (reader.HasColumn(""{3}"")) LoadProperty({0}Property, reader.GetDBValue<{2}>(""{3}"", {1}){4}); ", field.ColumnName, defaultValue, type, , defaultValue.Equals("string.Empty") ? ".HtmlDecode()" : string.Empty)); } if (process.HasBaseClass) list.Add(string.Format(@" BaseInfo.SetInheritanceContext(this); BaseInfo.ReadData(reader);")); return string.Join(Environment.NewLine, list);*/ }
/// <summary> /// Gets the synchronize class. /// </summary> /// <param name="syncProcess">The synchronize process.</param> /// <param name="process">The process.</param> /// <returns>System.String.</returns> private string GetSyncClass(SyncProcessDefinition syncProcess, IProcessDefinition process) { var sb = new StringBuilder(); sb.AppendFormat( @" [Serializable] [ExportAsProcessSynchronizer({0}, {1})] public class {2} : IProcessSynchronizer {{ {3} ", process.Name.ToLiteral(), syncProcess.Name.ToLiteral(), GetSynchronizerClassName(syncProcess), GetSyncProviderItemClass(syncProcess)); sb.AppendFormat( @" private static readonly IDataProvider _dataProvider; private static readonly ISchedule[] _schedules; private static readonly SynchronizationMap _synchronizationMap; static {0}() {{ {1} {2} {6} }} public string Name {{ get {{ return {3}; }} }} public string ProcessName {{ get {{ return {5}; }} }} public System.Guid Guid {{ get {{ return new System.Guid(""{4}""); }} }} public Cebos.Veyron.SharedTypes.ESyncAction Action {{ get {{ return Cebos.Veyron.SharedTypes.ESyncAction.{7}; }} }} public IDataProvider DataProvider {{ get {{ return _dataProvider; }} }} public ISchedule[] Schedules {{ get {{ return _schedules; }} }} public ISynchronizationMap SynchronizationMap {{ get {{ return _synchronizationMap; }} }} ", GetSynchronizerClassName(syncProcess), GetSyncDataProvider(syncProcess), GetSyncSchedules(syncProcess), syncProcess.Name.ToLiteral(), syncProcess.Guid, process.Name.ToLiteral(), GetSynchronizationMap(process, syncProcess), syncProcess.Action); sb.AppendFormat( @" public _ProviderItem CreateDynamicItem(ProviderItem item) {{ return new _ProviderItem(item); }} ISyncDynamicItem IProcessSynchronizer.CreateDynamicItem(ProviderItem item) {{ return CreateDynamicItem(item); }} private readonly IValueCalculator _valueCalculator = new _ValueCalculator(); public IValueCalculator ValueCalculator {{ get {{ return _valueCalculator; }} }} "); var expressionScripts = !string.IsNullOrEmpty(syncProcess.MapDesigner) ? ExpressionService.PrepareScriptForMultipleDestinations( syncProcess.MapDesigner, null) : new Dictionary<string, string>(); sb.AppendFormat( @" public class _ValueCalculator : ValueCalculatorBase {{ public override bool TryGetValue(IDynamicObject providerItem, string mappingKey, out object result) {{ switch (mappingKey) {{ "); foreach (var pair in expressionScripts) { sb.AppendFormat( @" case {0}: result = {1}; return true; ", pair.Key.ToLiteral(), pair.Value); } sb.AppendFormat( @" default: result = null; return false; }} }} "); sb.AppendFormat( @" public override bool ContainsKey(string mappingKey) {{ var keys = new string[] {{ {0} }}; return keys.Contains(mappingKey); }} }} ", string.Join(", ", expressionScripts.Keys.Select(s => s.ToLiteral()))); sb.AppendFormat(@" }} "); return sb.ToString(); }
/// <summary> /// Adds the deep copy class. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddDeepCopyClass(StringBuilder assemblyCode, IProcessDefinition process) { var idsInput = string.Join(",", process.RootTable.FieldList.Where(x => x.DeepCopy && x.ReferenceProcess != null).Select(x => string.Format("IEnumerable<int> {0}ids", x.ColumnName))); var idsAss = string.Join(",", process.RootTable.FieldList.Where(x => x.DeepCopy && x.ReferenceProcess != null).Select(x => string.Format("{0}Ids = new MobileList<int>({0}ids)", x.ColumnName))); var idsChk = string.Join(Environment.NewLine + " && " + Environment.NewLine, process.RootTable.FieldList.Where(x => x.DeepCopy && x.ReferenceProcess != null) .Select(x => string.Format(@"{0}Ids.Select(id => DataPortal.Fetch<Dynamic{1}.{1}EditRetriever>(new DetailCriteria(id, true, true) {{ ProcessViewGuid = null, ProcessViewChangedFields = null }}).{1}Edit).All(proc => proc.IsValid)", x.ColumnName, x.ReferenceProcess.SystemName))); assemblyCode.AppendFormat(@" [Serializable] public class CheckCopy : MefCommandBase<CheckCopy> {{ public static bool ExecuteCheck({0}) {{ var cmd = new CheckCopy {{{1}}}; return DataPortal.Execute(cmd).Result; }} ", idsInput, idsAss); foreach (var field in process.RootTable.FieldList.Where(x => x.DeepCopy && x.ReferenceProcess != null)) { assemblyCode.AppendFormat(@" public static readonly PropertyInfo<MobileList<int>> {0}IdsProperty = RegisterProperty<MobileList<int>>(c => c.{0}Ids); public MobileList<int> {0}Ids {{ get {{ return ReadProperty({0}IdsProperty); }} private set {{ LoadProperty({0}IdsProperty, value); }} }} ", field.ColumnName); } assemblyCode.AppendFormat(@" public static readonly PropertyInfo<bool> ResultProperty = RegisterProperty<bool>(c => c.Result); public bool Result {{ get {{ return ReadProperty(ResultProperty); }} private set {{ LoadProperty(ResultProperty, value); }} }} protected override void DataPortal_Execute() {{ Result = {0}; }} }} ", idsChk); }
/// <summary> /// Adds the E sync classes. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddESyncClasses(StringBuilder assemblyCode, IProcessDefinition process) { foreach (var syncProcess in process.SyncProcesses) assemblyCode.AppendLine(GetSyncClass(syncProcess, process)); }
/// <summary> /// Logs the source code. /// </summary> /// <param name="sourceCode">The source code.</param> /// <param name="process">The process.</param> protected override void LogSourceCode(string sourceCode, IProcessDefinition process) { process.ServerCode = sourceCode; }
/// <summary> /// Adds the KPI class fetch methods. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddKpiClassFetchMethods(StringBuilder assemblyCode, IProcessDefinition process) { assemblyCode.AppendFormat(@" private bool skip; private void RunFetcher(KpiAggregateCriteria criteria) {{ StatusQueryCommand.SetStatus(criteria.Guid, ""Starting work...""); ApplicationContext.User = criteria.Identity; var kpi = KpiList.FirstOrDefault(x => x.Guid == criteria.KpiGuid); if (kpi == null) {{ return; }} LoadProperty(IdProperty, kpi.Id); LoadProperty(NameProperty, kpi.Name); LoadProperty(GuidProperty, kpi.Guid); LoadProperty(FavorableDirectionProperty, kpi.FavorableDirection); LoadProperty(TargetValueProperty, kpi.TargetValue); LoadProperty(YellowValueProperty, kpi.YellowValue); LoadProperty(YellowIconURLProperty, kpi.YellowIconURL); LoadProperty(YellowIconIDProperty, kpi.YellowIconID); LoadProperty(GreenValueProperty, kpi.GreenValue); LoadProperty(GreenIconURLProperty, kpi.GreenIconURL); LoadProperty(GreenIconIDProperty, kpi.GreenIconID); LoadProperty(RedIconURLProperty, kpi.RedIconURL); LoadProperty(RedIconIDProperty, kpi.RedIconID); var metric = {0}MetricInfo.MetricList.FirstOrDefault(x => x.Guid == kpi.MetricGuid); if (metric == null) {{ return; }} LoadItems(kpi, metric, criteria); if (!skip) StatusQueryCommand.SetStatus(criteria.Guid, ""Completed"", 0, -1, true, this); }} private void DataPortal_Fetch(KpiAggregateCriteria criteria) {{ criteria.Identity = ApplicationContext.User; if (!criteria.RunInBackground) {{ RunFetcher(criteria); return; }} var bw = new BackgroundWorker(); DoWorkEventHandler runFetcherAction = (o, e) => RunFetcher(criteria); RunWorkerCompletedEventHandler runWOrkerComplitedHandler = null; runWOrkerComplitedHandler = (s, e) => {{ bw.DoWork -= runFetcherAction; bw.RunWorkerCompleted -= runWOrkerComplitedHandler; bw.Dispose(); }}; bw.DoWork += runFetcherAction; bw.RunWorkerCompleted += runWOrkerComplitedHandler; bw.RunWorkerAsync(); }} private void LoadItems(IKpi kpi, IMetric metric, KpiAggregateCriteria criteria) {{ var filter = kpi.FilterDefinition; var colList = new List<string>(); if (!string.IsNullOrEmpty(metric.MetricFieldSystemName)) {{ colList.Add(metric.MetricFieldSystemName); }} if (!string.IsNullOrEmpty(metric.GroupFieldOneSystemName)) {{ colList.Add(metric.GroupFieldOneSystemName); }} if (!string.IsNullOrEmpty(metric.GroupFieldTwoSystemName)) {{ colList.Add(metric.GroupFieldTwoSystemName); }} if (!string.IsNullOrEmpty(metric.GroupFieldThreeSystemName)) {{ colList.Add(metric.GroupFieldThreeSystemName); }} if (!string.IsNullOrEmpty(metric.GroupFieldFourSystemName)) {{ colList.Add(metric.GroupFieldFourSystemName); }} var sectest = {0}List.Get{0}List(new PagedCriteria {{ PageNumber = 0, PageSize = 1, FilterDefinition = filter, NotCalculateAccessDeniedList = false, LimitResultColumns = true, ResultColumns = new MobileList<string>(colList) }}).FirstOrDefault<IInfoClass>(); var blockedFields = new System.Collections.Generic.HashSet<string>(); if (sectest != null) {{ foreach (var fieldName in GetBlockedFields(sectest, colList)) blockedFields.Add(fieldName); }} if (blockedFields.Count > 0) {{ StatusQueryCommand.SetStatus(criteria.Guid, ""Completed"", 0, -1, true, new MobileList<string>(colList.Where(blockedFields.Contains))); skip = true; return; }} var list = {0}List.Get{0}List(new PagedCriteria {{ PageNumber = 0, PageSize = 50000, FilterDefinition = filter, NotCalculateAccessDeniedList = true, LimitResultColumns = true, ResultColumns = new MobileList<string>(colList) }}); foreach (var fieldName in list.Cast<{0}Info>().SelectMany(x => GetBlockedFields(x, colList))) blockedFields.Add(fieldName); var fullList = new List<double> {{ AggregateKPI(list, metric) }}; var infCount = list.Count<IInfoClass>(); var i = 0; while (infCount > 0 && infCount % 50000 == 0) {{ i++; list = {0}List.Get{0}List(new PagedCriteria {{ PageNumber = i, PageSize = 50000, FilterDefinition = filter, NotCalculateAccessDeniedList = true, LimitResultColumns = true, ResultColumns = new MobileList<string>(colList) }}); foreach (var fieldName in list.Cast<{0}Info>().SelectMany(x => GetBlockedFields(x, colList))) blockedFields.Add(fieldName); fullList.Add(AggregateKPI(list, metric)); infCount += list.Count<IInfoClass>(); if (!list.Any<IInfoClass>()) break; }} if (blockedFields.Count > 0) {{ StatusQueryCommand.SetStatus(criteria.Guid, ""Completed"", 0, -1, true, new MobileList<string>(colList.Where(blockedFields.Contains))); skip = true; return; }} CalculateKPI(fullList, metric, infCount); }} private double AggregateKPI(IInfoList items, IMetric metric) {{ double kpiCurrentValue = 0; if (items.Count > 0) {{ switch (metric.SummaryType) {{ case SummaryTypes.Avg: kpiCurrentValue = items.Cast<object>().Sum(item => metric.MetricField(item)); break; case SummaryTypes.Count: kpiCurrentValue = items.Count; break; case SummaryTypes.Max: kpiCurrentValue = (from object item in items select metric.MetricField(item)).Max(); break; case SummaryTypes.Min: kpiCurrentValue = (from object item in items select metric.MetricField(item)).Min(); break; case SummaryTypes.Sum: kpiCurrentValue += items.Cast<object>().Sum(item => metric.MetricField(item)); break; }} }} return kpiCurrentValue; }} private void CalculateKPI(List<double> items, IMetric metric, int countElements) {{ double kpiCurrentValue = 0; if (items.Count > 0) {{ switch (metric.SummaryType) {{ case SummaryTypes.Avg: kpiCurrentValue = items.Sum() / countElements; break; case SummaryTypes.Count: kpiCurrentValue = items.Sum(); break; case SummaryTypes.Max: kpiCurrentValue = items.Max(); break; case SummaryTypes.Min: kpiCurrentValue = items.Min(); break; case SummaryTypes.Sum: kpiCurrentValue += items.Sum(); break; }} }} CurrentValue = kpiCurrentValue; CurrentIconURL = string.Empty; CurrentIconID = null; if (FavorableDirection == FavorableDirections.Down) {{ if (CurrentValue <= GreenValue) {{ CurrentIconURL = GreenIconURL; CurrentIconID = GreenIconID; }} else if (CurrentValue > GreenValue && CurrentValue <= YellowValue) {{ CurrentIconURL = YellowIconURL; CurrentIconID = YellowIconID; }} else {{ CurrentIconURL = RedIconURL; CurrentIconID = RedIconID; }} }} else {{ if (CurrentValue <= GreenValue) {{ CurrentIconURL = RedIconURL; CurrentIconID = RedIconID; }} else if (CurrentValue > GreenValue && CurrentValue <= YellowValue) {{ CurrentIconURL = YellowIconURL; CurrentIconID = YellowIconID; }} else {{ CurrentIconURL = GreenIconURL; CurrentIconID = GreenIconID; }} }} }} private System.Collections.Generic.IEnumerable<string> GetBlockedFields(Cebos.Veyron.SharedTypes.IInfoClass item, System.Collections.Generic.IEnumerable<string> fieldsToCheck) {{ foreach (var fieldName in fieldsToCheck) {{ var property = item.GetPropertyByName(fieldName); if (property == null) continue; if (!item.CanReadPropertyByName(property.Name)) yield return property.Name; }} }} ", process.Name); }
/// <summary> /// Adds the KPI class factory methods. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddKpiClassFactoryMethods(StringBuilder assemblyCode, IProcessDefinition process) { assemblyCode.AppendFormat(@" public static {0}KpiInfo Get{0}KpiInfo(Guid kpiGuid) {{ return DataPortal.Fetch<{0}KpiInfo>(kpiGuid); }} public static {0}KpiInfo GetGadgetAggregateList(KpiAggregateCriteria criteria) {{ return DataPortal.Fetch<{0}KpiInfo>(criteria); }} ", process.Name); }
/// <summary> /// Adds the execute data triggers. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddExecuteDataTriggers(StringBuilder assemblyCode, IProcessDefinition process) { assemblyCode.AppendFormat( @" private System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggers.IDataTrigger> GetTriggersToExecute({0}Edit item, {0}Edit oldItem) {{ var result = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggers.IDataTrigger>(); foreach (var triggerDefinition in {0}TriggersInfo.DataTriggers) if (triggerDefinition.CanExecute(item, oldItem)) {{ var trigger = DataTriggerFactory.CreateDataTrigger({1}, triggerDefinition); result.Add(trigger); }} return result; }} private void ExecuteTriggersBeforeUpdate( System.Collections.Generic.IEnumerable<Cebos.Veyron.SharedTypes.DataTriggers.IDataTrigger> triggers, {0}Edit item, {0}Edit oldItem) {{ foreach (var trigger in triggers) trigger.BeforeItemUpdate(item, oldItem); }} private void ExecuteTriggersAfterUpdate( System.Collections.Generic.IEnumerable<Cebos.Veyron.SharedTypes.DataTriggers.IDataTrigger> triggers, {0}Edit item, {0}Edit oldItem) {{ foreach (var trigger in triggers) trigger.AfterItemUpdate(item, oldItem); }} ", process.Name, process.Name.ToLiteral()); }
/// <summary> /// Gets the table field. /// </summary> /// <param name="process">The process.</param> /// <param name="fieldName">Name of the field.</param> /// <returns>TableFieldDefinition.</returns> private static TableFieldDefinition GetTableField(IProcessDefinition process, string fieldName) { TableFieldDefinition tableField = null; var currentProcess = process; while (currentProcess != null) { tableField = currentProcess.RootTable.FieldList.FirstOrDefault(f => f.ColumnName == fieldName); if (tableField != null) break; currentProcess = currentProcess.BaseProcess; } return tableField; }
/// <summary> /// Adds the data triggers classes. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> /// <exception cref="System.NotSupportedException"></exception> protected override void AddDataTriggersClasses(StringBuilder assemblyCode, IProcessDefinition process) { assemblyCode.AppendFormat( @" public class {0}TriggersInfo {{ private static readonly Cebos.Veyron.SharedTypes.DataTriggerDefinition[] _dataTriggers; public static Cebos.Veyron.SharedTypes.DataTriggerDefinition[] DataTriggers {{ get {{ return _dataTriggers; }} }} static {0}TriggersInfo() {{ System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerFieldMapping> fields; System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerFieldMapping> subfields; System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerListFieldMapping> listFields; Func<IDynamicObject, IDynamicObject, bool> ruleExpression; System.Collections.Generic.List<Cebos.Veyron.SharedTypes.IActionRule> rules; System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggers.FieldMappingDataSourceDefinition> dataSources; System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggers.StoredProcedureParameterDefinition> storedProcedureParameters; var dataTriggers = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggerDefinition>(); ", process.Name); var variableIndex = 0; foreach (var trigger in process.DataTriggers.OrderBy(t => t.Name)) { switch (trigger.TriggerType) { case DataTriggerTypes.Process: GenerateProcessDataTrigger(assemblyCode, process, trigger, ref variableIndex); break; case DataTriggerTypes.StoredProcedure: GenerateStoredProcedureDataTrigger(assemblyCode, process, trigger); break; default: throw new NotSupportedException(string.Format("Trigger type \"{0}\" is not supported.", trigger.TriggerType)); } } assemblyCode.AppendLine(@" _dataTriggers = dataTriggers.ToArray(); } } "); }
/// <summary> /// Gets the synchronization map. /// </summary> /// <param name="process">The process.</param> /// <param name="syncProcess">The synchronize process.</param> /// <returns>System.String.</returns> private string GetSynchronizationMap(IProcessDefinition process, SyncProcessDefinition syncProcess) { var result = new StringBuilder(); result.AppendFormat( @" _synchronizationMap = new SynchronizationMap(); "); foreach (var destinationField in syncProcess.DestinationFields) { if (destinationField.SystemName == Constants.Version) { result.Append(GetAddVersionFields(process, destinationField)); continue; } if (destinationField.SystemName == Constants.CurrentStateColumnName) { result.Append(GetAddCurrentStateField(process, destinationField)); continue; } var tableField = GetTableField(process, destinationField.SystemName); if (tableField == null) continue; if (tableField.IsRef) { result.Append(GetAddCrossReferenceField(process, tableField, destinationField)); continue; } result.Append(GetAddGenericField(process, tableField, destinationField)); } return result.ToString(); }
/// <summary> /// Generates the stored procedure data trigger. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> /// <param name="trigger">The trigger.</param> private void GenerateStoredProcedureDataTrigger(StringBuilder assemblyCode, IProcessDefinition process, DataTriggerDefinition trigger) { assemblyCode.AppendFormat(@" storedProcedureParameters = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.DataTriggers.StoredProcedureParameterDefinition>(); "); foreach (var parameter in trigger.StoredProcedureParameters) { var parameterValue = "null"; if (!string.IsNullOrEmpty(parameter.Expression)) { parameterValue = string.Format(@"item => {{ return {0}; }}", ExpressionService.PrepareScriptFromXml(parameter.Expression)); } assemblyCode.AppendFormat(@" storedProcedureParameters.Add(new Cebos.Veyron.SharedTypes.DataTriggers.StoredProcedureParameterDefinition({0}, Cebos.Veyron.SharedTypes.DbDataType.{1}, {2})); ", parameter.Name.ToLiteral(), parameter.DataType.ToString(), parameterValue); } assemblyCode.AppendLine(@" rules = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.IActionRule>(); "); foreach (var rule in trigger.Rules.Where(r=>r.IsActive)) { assemblyCode.AppendFormat(CultureInfo.InvariantCulture, @" rules.Add({0}Metadata.RuleManager.GetRule(new System.Guid(""{1}"")));", process.Name, rule.Guid); } assemblyCode.AppendFormat(@" dataTriggers.Add(new Cebos.Veyron.SharedTypes.DataTriggerDefinition( {0}, System.Guid.Parse(""{1}""), {2}, rules, storedProcedureParameters)); ", trigger.Name.ToLiteral(), trigger.Guid, trigger.StoredProcedureName.ToLiteral()); }
/// <summary> /// Gets the add cross reference field. /// </summary> /// <param name="process">The process.</param> /// <param name="tableField">The table field.</param> /// <param name="field">The field.</param> /// <returns>System.String.</returns> private string GetAddCrossReferenceField(IProcessDefinition process, TableFieldDefinition tableField, SyncProcessDestinationField field) { if (!field.Subfields.Any(sf => sf.IsKey && !string.IsNullOrEmpty(sf.MappedTo))) return string.Empty; var result = new StringBuilder(); result.AppendFormat( @" _synchronizationMap.SynchronizedFields.Add({0}); ", GetCrossReferenceFieldDefinition(field)); return result.ToString(); }
/// <summary> /// Adds the integration service class. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> /// <param name="service">The service.</param> private void AddIntegrationServiceClass(StringBuilder assemblyCode, IProcessDefinition process, IntegrationServiceDefinition service) { assemblyCode.AppendFormat(@" [System.Web.Services.WebServiceAttribute(Namespace = {1})] public class @{0} : System.Web.Services.WebService {{ private Cebos.Veyron.SharedTypes.Integration.IIntegrationServiceMethodFactory _methodFactory; private Cebos.Veyron.SharedTypes.Integration.IIntegrationServiceMethodFactory MethodFactory {{ get {{ return _methodFactory ?? (_methodFactory = Cebos.Veyron.SharedTypes.MEF.Ioc.GetExportedValue<Cebos.Veyron.SharedTypes.Integration.IIntegrationServiceMethodFactory>()); }} }} private Cebos.Veyron.SharedTypes.Logging.ILogger _logger; private Cebos.Veyron.SharedTypes.Logging.ILogger Logger {{ get {{ return _logger ?? (_logger = Cebos.Veyron.SharedTypes.MEF.Ioc.GetExportedValue<Cebos.Veyron.SharedTypes.Logging.ILogger>()); }} }} public Cebos.Veyron.SharedTypes.Integration.CredentialsHeader Credentials; private void CheckCredentials(string username, string password) {{ if (Credentials == null || Credentials.Username != username || Credentials.Password != password) throw new System.Security.SecurityException(""Authentication failed.""); }} ", service.ServiceName, service.Namespace.ToLiteral()); foreach (var type in service.Types) AddIntegrationServiceType(assemblyCode, type); foreach (var method in service.Methods) { AddIntegrationServiceMethodRequestType(assemblyCode, method); } foreach (var method in service.Methods) { assemblyCode.AppendFormat(@" private Cebos.Veyron.SharedTypes.Integration.IIntegrationServiceMethod _{0}Method; private Cebos.Veyron.SharedTypes.Integration.IIntegrationServiceMethod {0}Method {{ get {{ return _{0}Method ?? (_{0}Method = MethodFactory.CreateMethod(Get{0}Definition())); }} }} ", method.Name); AddMethodDefinition(assemblyCode, process, method); AddIntegrationServiceInternalMethod(assemblyCode, method); AddIntegrationServiceGenericMethod(assemblyCode, process, service, method); if (method.CanInsert) AddIntegrationServiceActionSpecificMethod(assemblyCode, process, service, method, ActionType.Insert); if (method.CanUpdate) AddIntegrationServiceActionSpecificMethod(assemblyCode, process, service, method, ActionType.Update); if (method.CanInsertOrUpdate) AddIntegrationServiceActionSpecificMethod(assemblyCode, process, service, method, ActionType.InsertOrUpdate); if (method.CanRemove) AddIntegrationServiceActionSpecificMethod(assemblyCode, process, service, method, ActionType.Remove); if (method.CanSelect) AddIntegrationServiceActionSpecificMethod(assemblyCode, process, service, method, ActionType.Select); } assemblyCode.AppendFormat(@" }} "); }
/// <summary> /// Gets the add version fields. /// </summary> /// <param name="process">The process.</param> /// <param name="field">The field.</param> /// <returns>System.String.</returns> private string GetAddVersionFields(IProcessDefinition process, SyncProcessDestinationField field) { var result = new StringBuilder(); if (!process.IsVersioningEnabled) return string.Empty; var versionDateField = field.Subfields.FirstOrDefault(x => x.SystemName == Constants.VersionDate); var versionNumberField = field.Subfields.FirstOrDefault(x => x.SystemName == Constants.VersionNumber); var versionMasterField = field.Subfields.FirstOrDefault(x => x.SystemName == Constants.VersionMaster); if (versionDateField != null && !string.IsNullOrEmpty(versionDateField.MappedTo)) result.AppendFormat( @" _synchronizationMap.SynchronizedFields.Add({0}); ", GetGenericFieldDefinition(versionDateField)); if (versionNumberField != null && !string.IsNullOrEmpty(versionNumberField.MappedTo)) result.AppendFormat( @" _synchronizationMap.SynchronizedFields.Add({0}); ", GetGenericFieldDefinition(versionNumberField)); if (versionMasterField != null && versionMasterField.Subfields.Any(f => f.IsKey && !string.IsNullOrEmpty(f.MappedTo))) result.AppendFormat( @" _synchronizationMap.SynchronizedFields.Add({0}); ", GetVersionMasterFieldDefinition(versionMasterField)); return result.ToString(); }
/// <summary> /// Adds the integration service generic method. /// </summary> /// <param name="assemblyCode"> /// The assembly code. /// </param> /// <param name="process"> /// The process. /// </param> /// <param name="service"> /// The service. /// </param> /// <param name="method"> /// The method. /// </param> private void AddIntegrationServiceGenericMethod( StringBuilder assemblyCode, IProcessDefinition process, IntegrationServiceDefinition service, IntegrationServiceMethodDefinition method) { var parametersString = new StringBuilder("Cebos.Veyron.SharedTypes.Integration.ActionType action"); var callParametersString = new StringBuilder("action"); if (method.Parameters.Any()) { parametersString.AppendFormat(", {0}", GetMethodParameters(method)); callParametersString.AppendFormat(", {0}", GetMethodCallParameters(method)); } assemblyCode.AppendFormat( @" [System.Web.Services.WebMethodAttribute] [System.Web.Services.Protocols.SoapHeaderAttribute(""Credentials"")] {3} {4} public {5} @{0}({1}) {{ var result = {0}Internal({2}); ", method.Name, parametersString, callParametersString, GetSoapDocumentMethodAttribute(method), GetSoapExtensionAttribute(process, service), GetIntegrationServiceMethodReturnType(method)); AddIntegrationServiceMethodReturn(assemblyCode, method); assemblyCode.AppendFormat(@" }} "); }
/// <summary> /// Gets the add current state field. /// </summary> /// <param name="process">The process.</param> /// <param name="field">The field.</param> /// <returns>System.String.</returns> private string GetAddCurrentStateField(IProcessDefinition process, SyncProcessDestinationField field) { var result = new StringBuilder(); if (!process.IsStateEnabled || string.IsNullOrEmpty(field.MappedTo)) return string.Empty; result.AppendFormat( @" _synchronizationMap.SynchronizedFields.Add({0});", GetGenericFieldDefinition(field)); return result.ToString(); }
/// <summary> /// Adds the integration service calls manager class. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> private void AddIntegrationServiceCallsManagerClass(StringBuilder assemblyCode, IProcessDefinition process) { assemblyCode.AppendFormat(@" public sealed class IntegrationServiceCallsManager : Cebos.Veyron.SharedTypes.Integration.ServiceCallsManagerBase {{ private IntegrationServiceCallsManager() {{ }} public override string ProcessDisplayName {{ get {{ return {0}; }} }} private static System.Lazy<IntegrationServiceCallsManager> _instance = new System.Lazy<IntegrationServiceCallsManager>(CreateInstance); public static IntegrationServiceCallsManager Instance {{ get {{ return _instance.Value; }} }} private static IntegrationServiceCallsManager CreateInstance() {{ var instance = new IntegrationServiceCallsManager(); Cebos.Veyron.SharedTypes.MEF.Ioc.SatisfyImportsOnce(instance); var callDefinitions = new System.Collections.Generic.List<Cebos.Veyron.SharedTypes.Integration.IServiceCallDefinition>(); ", process.DisplayName.ToLiteral()); var variableCollection = new VariableCollection(); foreach (var callDefinition in process.IntegrationServiceCallDefinitions) { if (callDefinition.CallSettings is IntegrationServiceWebMethodCallDefinition) { var variableInfo = AddWebMethodCallDefinition(assemblyCode, process, callDefinition, variableCollection); assemblyCode.AppendFormat(@" callDefinitions.Add({0}); ", variableInfo.Name); continue; } if (callDefinition.CallSettings is IntegrationServiceUrlCallDefinition) { var variableInfo = AddUrlCallDefinition(assemblyCode, process, callDefinition, variableCollection); assemblyCode.AppendFormat(@" callDefinitions.Add({0}); ", variableInfo.Name); continue; } } assemblyCode.AppendFormat(@" instance.Initialize(callDefinitions); return instance; }} }} "); }
/// <summary> /// Adds the process views classes. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddProcessViewsClasses(StringBuilder assemblyCode, IProcessDefinition process) { base.AddProcessViewsClasses(assemblyCode, process); CallExtensions<IServerAssemblyGeneratorExtension>(process.Name, e => e.OnAfterAddProcessViewClasses(assemblyCode, process, this)); }
/// <summary> /// Adds the web method call definition. /// </summary> /// <param name="assemblyCode"> /// The assembly code. /// </param> /// <param name="process"> /// The process. /// </param> /// <param name="callDefinition"> /// The call definition. /// </param> /// <param name="variableCollection"> /// The variable collection. /// </param> /// <returns> /// The <see cref="VariableInfo"/>. /// </returns> private VariableInfo AddWebMethodCallDefinition( StringBuilder assemblyCode, IProcessDefinition process, IntegrationServiceCallDefinition callDefinition, VariableCollection variableCollection) { var callSettings = (IntegrationServiceWebMethodCallDefinition)callDefinition.CallSettings; var variableInfo = variableCollection.NewVariable(); var variableName = variableInfo.Name; var soapHeaderMappings = ExpressionService.PrepareScriptsForDestinationNode( callSettings.ParametersMapping, Constants.WebMethodCallSoapHeadersExpressionName); var parameterMappings = ExpressionService.PrepareScriptsForDestinationNode( callSettings.ParametersMapping, Constants.WebMethodCallMethodParametersExpressionName); assemblyCode.AppendFormat( @" var {0} = new Cebos.Veyron.SharedTypes.Integration.WebMethodCallDefinition(); {0}.Name = {1}; {0}.Guid = System.Guid.Parse({2}); {0}.ContractTypeName = {3}; {0}.MethodName = {4}; {0}.ServiceDescriptionId = {5}; {0}.ProcessName = {6}; {0}.ProcessDisplayName = {7}; {0}.Username = {8}; {0}.Password = {9}; {0}.EndpointConfiguration = {10}; ", variableName, callDefinition.Name.ToLiteral(), callDefinition.Guid.ToString().ToLiteral(), callSettings.ContractTypeName.ToLiteral(), callSettings.MethodName.ToLiteral(), callSettings.ServiceDescriptionId.ToLiteral(), process.Name.ToLiteral(), process.DisplayName.ToLiteral(), callSettings.Username.ToLiteral(), callSettings.Password.ToLiteral(), callSettings.EndpointConfiguration.ToLiteral()); foreach (var header in callSettings.SoapHeaders) { var headerVariable = AddWebMethodCallHeaderDefinition(assemblyCode, header, soapHeaderMappings, variableCollection); assemblyCode.AppendFormat(@" {0}.HeaderMappings.Add({1}); ", variableName, headerVariable.Name); } foreach (var parameter in callSettings.Parameters) { var parameterVariable = AddWebMethodCallParameterDefinition(assemblyCode, parameter, parameterMappings, variableCollection); assemblyCode.AppendFormat(@" {0}.ParameterMappings.Add({1}); ", variableName, parameterVariable.Name); } foreach (var rule in callDefinition.Rules) { assemblyCode.AppendFormat(@" {0}.Rules.Add({1}Metadata.RuleManager.GetRule(new System.Guid(""{2}"")));", variableName, process.Name, rule.Guid); } var resultMappings = ExpressionService.PrepareScriptForMultipleDestinations(callSettings.ResultMapping, null); foreach (var fieldMapping in callSettings.DestinationFields) { var resultMappingVariable = AddFieldMapping(assemblyCode, fieldMapping, resultMappings, variableCollection); assemblyCode.AppendFormat(@" {0}.ResultMappings.Add({1}); ", variableName, resultMappingVariable.Name); } return variableInfo; }
/// <summary> /// Gets the property attributes. /// </summary> /// <param name="process">The process.</param> /// <param name="field">The field.</param> /// <param name="isInfoClass">if set to <c>true</c> [is info class].</param> /// <param name="isEditableProxyClass">if set to <c>true</c> [is proxy class].</param> /// <returns>System.String.</returns> protected override string GetPropertyAttributes(IProcessDefinition process, TableFieldDefinition field, bool isInfoClass, bool isEditableProxyClass = false) { var sb = new StringBuilder(base.GetPropertyAttributes(process, field, isInfoClass)); if (isInfoClass) sb.AppendLine("[DataMember]"); return sb.ToString(); }
/// <summary> /// Adds the dependency information supplier class. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddDependencyInfoSupplierClass(StringBuilder assemblyCode, IProcessDefinition process) { var uniqueDependencies = new List<ExpressionDependency>(); var foundDepedencies = new HashSet<string>(); foreach (var dependency in process.ExpressionDependencies) { if (foundDepedencies.Contains(dependency.FullPath)) continue; uniqueDependencies.Add(dependency); foundDepedencies.Add(dependency.FullPath); } if (uniqueDependencies.Count == 0) return; assemblyCode.AppendFormat(@" public class DependencyInfoSupplier : Cebos.Veyron.SharedTypes.ExpressionDependencies.IDependencyInfoSupplier {{ public string ProcessName {{ get {{ return {0}; }} }} ", process.Name.ToLiteral()); assemblyCode.AppendFormat(@" public System.Collections.Generic.IEnumerable<int> GetAffectedItems(string processName, int itemId) {{ var result = new System.Collections.Generic.List<int>(); "); for (var i = 0; i < uniqueDependencies.Count; ++i) { var dependency = uniqueDependencies[i]; assemblyCode.AppendFormat(@" if (processName == {0}) result.AddRange(GetAffectedItems{1}(itemId)); ", dependency.ProcessName.ToLiteral(), i); } assemblyCode.AppendFormat(@" return result; }} "); assemblyCode.AppendFormat(@" public System.Collections.Generic.IEnumerable<int> GetAffectedItems( string processName, int itemId, System.Collections.Generic.ICollection<string> changedFields) {{ var result = new System.Collections.Generic.List<int>(); "); for (var i = 0; i < uniqueDependencies.Count; ++i) { var dependency = uniqueDependencies[i]; if (!string.IsNullOrEmpty(dependency.FieldName)) assemblyCode.AppendFormat(@" if (processName == {0} && changedFields.Contains({1}))", dependency.ProcessName.ToLiteral(), dependency.FieldName.ToLiteral()); else assemblyCode.AppendFormat(@" if (processName == {0})", dependency.ProcessName.ToLiteral()); assemblyCode.AppendFormat(@" result.AddRange(GetAffectedItems{0}(itemId)); ", i); } assemblyCode.AppendFormat(@" return result; }} "); for (var i = 0; i < uniqueDependencies.Count; ++i) AddGetAffectedItemsMethod(assemblyCode, uniqueDependencies[i], i); assemblyCode.AppendFormat(@" }}"); }
/// <summary> /// Adds the metrics class factory methods. /// </summary> /// <param name="assemblyCode">The assembly code.</param> /// <param name="process">The process.</param> protected override void AddMetricsClassFactoryMethods(StringBuilder assemblyCode, IProcessDefinition process) { assemblyCode.AppendFormat(@" public static {0}MetricInfo Get{0}MetricInfo(Guid metricGuid) {{ return DataPortal.Fetch<{0}MetricInfo>(metricGuid); }} ", process.Name); }