public EntityHelp(Type type, CultureInfo culture, EntityHelpEntity entity) { Type = type; Culture = culture; Info = HelpGenerator.GetEntityHelp(type); Properties = PropertyRoute.GenerateRoutes(type) .ToDictionary( pp => pp, pp => new PropertyHelp(pp, HelpGenerator.GetPropertyHelp(pp))); var allOperations = HelpLogic.CachedOperationsHelp(); Operations = OperationLogic.GetAllOperationInfos(type).Select(oi=>allOperations.GetOrThrow(oi.OperationSymbol)).ToDictionary(a=>a.OperationSymbol); var allQueries = HelpLogic.CachedQueriesHelp(); Queries = HelpLogic.TypeToQuery.Value.TryGetC(this.Type).EmptyIfNull().Select(a=>allQueries.GetOrThrow(a)).ToDictionary(qh => qh.QueryName); if (entity != null) { HasEntity = true; Description = entity.Description; foreach (var tranProp in entity.Properties) { Properties.GetOrThrow(tranProp.Property.ToPropertyRoute()).UserDescription = tranProp.Description; } foreach (var transOper in entity.Operations) { Operations.GetOrThrow(transOper.Operation).UserDescription = transOper.Description; } } Entity = new Lazy<EntityHelpEntity>(() => HelpLogic.GlobalContext(() => { if (entity == null) entity = new EntityHelpEntity { Culture = this.Culture.ToCultureInfoEntity(), Type = this.Type.ToTypeEntity(), }; entity.Properties.AddRange( PropertyRouteLogic.RetrieveOrGenerateProperties(this.Type.ToTypeEntity()) .Except(entity.Properties.Select(a => a.Property)) .Select(pr => new PropertyRouteHelpEntity { Property = pr, Description = null, })); entity.Operations.AddRange(this.Operations.Values.Select(o => o.Entity.Value).ToList()); entity.Queries.AddRange(this.Queries.Values.Select(a => a.Entity.Value).ToList()); return entity; })); }
public static SqlPreCommand?ImportRulesScript(XDocument doc, bool interactive) { Replacements replacements = new Replacements { Interactive = interactive }; Dictionary <string, Lite <RoleEntity> > rolesDic = roles.Value.ToDictionary(a => a.ToString() !); Dictionary <string, XElement> rolesXml = doc.Root !.Element("Roles") !.Elements("Role").ToDictionary(x => x.Attribute("Name") !.Value); replacements.AskForReplacements(rolesXml.Keys.ToHashSet(), rolesDic.Keys.ToHashSet(), "Roles"); rolesDic = replacements.ApplyReplacementsToNew(rolesDic, "Roles"); try { var xmlOnly = rolesXml.Keys.Except(rolesDic.Keys).ToList(); if (xmlOnly.Any()) { throw new InvalidOperationException("roles {0} not found on the database".FormatWith(xmlOnly.ToString(", "))); } foreach (var kvp in rolesXml) { var r = rolesDic.GetOrThrow(kvp.Key); var current = GetMergeStrategy(r); var should = kvp.Value.Attribute("MergeStrategy")?.Let(t => t.Value.ToEnum <MergeStrategy>()) ?? MergeStrategy.Union; if (current != should) { throw new InvalidOperationException("Merge strategy of {0} is {1} in the database but is {2} in the file".FormatWith(r, current, should)); } EnumerableExtensions.JoinStrict( roles.Value.RelatedTo(r), kvp.Value.Attribute("Contains") !.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries), sr => sr.ToString() !, s => rolesDic.GetOrThrow(s).ToString() !, (sr, s) => 0, "subRoles of {0}".FormatWith(r)); } } catch (InvalidOperationException ex) { throw new InvalidRoleGraphException("The role graph does not match:\r\n" + ex.Message); } var dbOnlyWarnings = rolesDic.Keys.Except(rolesXml.Keys).Select(n => new SqlPreCommandSimple("-- Alien role {0} not configured!!".FormatWith(n)) ).Combine(Spacing.Simple); SqlPreCommand?result = ImportFromXml.GetInvocationListTyped() .Select(inv => inv(doc.Root, rolesDic, replacements)).Combine(Spacing.Triple); if (replacements.Values.Any(a => a.Any())) { SafeConsole.WriteLineColor(ConsoleColor.Red, "There are renames! Remember to export after executing the script"); } if (result == null && dbOnlyWarnings == null) { return(null); } return(SqlPreCommand.Combine(Spacing.Triple, new SqlPreCommandSimple("-- BEGIN AUTH SYNC SCRIPT"), Connector.Current.SqlBuilder.UseDatabase(), dbOnlyWarnings, result, new SqlPreCommandSimple("-- END AUTH SYNC SCRIPT"))); }
protected internal virtual List <FrameworkElement> ButtonBar_GetButtonBarElement(object entity, EntityButtonContext ctx) { Entity ident = entity as Entity; if (ident == null) { return(null); } Type type = ident.GetType(); var operations = (from oi in OperationInfos(type) where oi.IsEntityOperation && (oi.CanBeNew.Value || !ident.IsNew) let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol) let eoc = newEntityOperationContext.GetInvoker(os?.OverridenType ?? type)(ident, oi, ctx, os) where (os != null && os.HasIsVisible) ? os.OnIsVisible(eoc) : ctx.ShowOperations select eoc).ToList(); if (operations.Any(eoc => eoc.OperationInfo.HasCanExecute == true)) { Dictionary <OperationSymbol, string> canExecutes = Server.Return((IOperationServer os) => os.GetCanExecuteAll(ident)); foreach (var eoc in operations) { var ce = canExecutes.TryGetC(eoc.OperationInfo.OperationSymbol); if (ce != null && ce.HasText()) { eoc.CanExecute = ce; } } } List <FrameworkElement> buttons = new List <FrameworkElement>(); Dictionary <EntityOperationGroup, ToolBarButton> groups = new Dictionary <EntityOperationGroup, ToolBarButton>(); Dictionary <EntityOperationGroup, List <FrameworkElement> > groupButtons = new Dictionary <EntityOperationGroup, List <FrameworkElement> >(); foreach (var eoc in operations) { if (eoc.OperationInfo.OperationType == OperationType.ConstructorFrom && (eoc.OperationSettings == null || !eoc.OperationSettings.AvoidMoveToSearchControl)) { if (EntityOperationToolBarButton.MoveToSearchControls(eoc)) { continue; } } EntityOperationGroup group = GetDefaultGroup(eoc); if (group != null) { var list = groupButtons.GetOrCreate(group, () => { var tbb = EntityOperationToolBarButton.CreateGroupContainer(group); groups.Add(group, tbb); buttons.Add(tbb); return(new List <FrameworkElement>()); }); list.Add(EntityOperationToolBarButton.NewMenuItem(eoc, group)); } else { buttons.Add(EntityOperationToolBarButton.NewToolbarButton(eoc)); } } foreach (var gr in groups) { var cm = gr.Value.ContextMenu; foreach (var b in groupButtons.GetOrThrow(gr.Key).OrderBy(Common.GetOrder)) { cm.Items.Add(b); } } return(buttons.ToList()); }
public static ActionResult DownloadFileResult(RuntimeInfo runtimeInfo) { return(FileDownloadResult.GetOrThrow(runtimeInfo.EntityType)(runtimeInfo)); }
public static PredictDictionary GetInputsFromParentKeys(this PredictorPredictContext ctx, Dictionary <QueryToken, object?> parentKeyValues, PredictionOptions?options = null) { if (!ctx.Predictor.MainQuery.GroupResults) { var kvp = parentKeyValues.SingleEx(); if (kvp.Key.FullKey() != "Entity") { throw new InvalidOperationException("only Entity expected"); } var filters = new List <Filter> { new FilterCondition(kvp.Key, FilterOperation.EqualTo, kvp.Value) }; return(ctx.FromFilters(filters, options).SingleEx()); } else { var filters = ctx.Predictor.MainQuery.Columns .Select(a => a.Token.Token) .Where(t => !(t is AggregateToken)) .Select(t => (Filter) new FilterCondition(t, FilterOperation.EqualTo, parentKeyValues.GetOrThrow(t))) .ToList(); return(ctx.FromFilters(filters, options).SingleEx()); } }
public static void StartRunningProcesses() { if (running) { throw new InvalidOperationException("ProcessLogic is running"); } using (ExecutionContext.SuppressFlow()) Task.Factory.StartNew(() => { var database = Schema.Current.Table(typeof(ProcessEntity)).Name.Schema?.Database; SystemEventLogLogic.Log("Start ProcessRunner"); ExceptionEntity?exception = null; using (AuthLogic.Disable()) { try { running = true; (from p in Database.Query <ProcessEntity>() where p.IsMine() && (p.State == ProcessState.Executing || p.State == ProcessState.Suspending || p.State == ProcessState.Suspended) || p.IsShared() && p.State == ProcessState.Suspended select p).SetAsQueued(); CancelNewProcesses = new CancellationTokenSource(); autoResetEvent.Set(); timerNextExecution = new Timer(ob => WakeUp("TimerNextExecution", null), // main timer null, Timeout.Infinite, Timeout.Infinite); if (!CacheLogic.WithSqlDependency) { timerPeriodic = new Timer(ob => WakeUp("TimerPeriodic", null), null, PoolingPeriodMilliseconds, PoolingPeriodMilliseconds); } while (autoResetEvent.WaitOne()) { if (CancelNewProcesses.IsCancellationRequested) { return; } using (HeavyProfiler.Log("PWL", () => "Process Runner")) { (from p in Database.Query <ProcessEntity>() where p.State == ProcessState.Planned && p.PlannedDate <= Clock.Now select p).SetAsQueued(); var list = Database.Query <ProcessEntity>() .Where(p => p.IsMine() || p.IsShared()) .Where(p => p.State == ProcessState.Planned) .Select(p => p.PlannedDate) .ToListWakeup("Planned dependency"); SetNextPannedExecution(list.Min()); lock (executing) { int remaining = MaxDegreeOfParallelism - executing.Count; if (remaining > 0) { retry: var queued = Database.Query <ProcessEntity>() .Where(p => p.State == ProcessState.Queued) .Where(p => p.IsMine() || p.IsShared()) .Select(a => new { Process = a.ToLite(), a.QueuedDate, a.MachineName }) .ToListWakeup("Planned dependency"); var afordable = queued .OrderByDescending(p => p.MachineName == Environment.MachineName) .OrderBy(a => a.QueuedDate) .Take(remaining).ToList(); var taken = afordable.Where(p => p.MachineName == ProcessEntity.None).Select(a => a.Process).ToList(); if (taken.Any()) { using (var tr = Transaction.ForceNew()) { Database.Query <ProcessEntity>() .Where(p => taken.Contains(p.ToLite()) && p.MachineName == ProcessEntity.None) .UnsafeUpdate() .Set(p => p.MachineName, p => Environment.MachineName) .Set(p => p.ApplicationName, p => Schema.Current.ApplicationName) .Execute(); tr.Commit(); } goto retry; } foreach (var pair in afordable) { ProcessEntity pro = pair.Process !.RetrieveAndRemember(); IProcessAlgorithm algorithm = ProcessLogic.GetProcessAlgorithm(pro.Algorithm); ExecutingProcess executingProcess = new ExecutingProcess(algorithm, pro); executing.Add(pro.ToLite(), executingProcess); executingProcess.TakeForThisMachine(); using (ExecutionContext.SuppressFlow()) Task.Run(() => { try { executingProcess.Execute(); } catch (Exception ex) { try { ex.LogException(edn => { edn.ControllerName = "ProcessWorker"; edn.ActionName = executingProcess.CurrentProcess.ToLite().Key(); }); } catch { } } finally { lock (executing) { executing.Remove(pro.ToLite()); WakeUp("Process ended", null); } } }); } var suspending = Database.Query <ProcessEntity>() .Where(p => p.State == ProcessState.Suspending) .Where(p => p.IsMine()) .Select(a => a.ToLite()) .ToListWakeup("Suspending dependency"); foreach (var s in suspending) { ExecutingProcess execProc = executing.GetOrThrow(s); if (execProc.CurrentProcess.State != ProcessState.Finished) { execProc.CurrentProcess = s.RetrieveAndRemember(); execProc.CancelationSource.Cancel(); } } } } } } } catch (ThreadAbortException) { //Ignore } catch (Exception e) { try { exception = e.LogException(edn => { edn.ControllerName = "ProcessWorker"; edn.ActionName = "MainLoop"; }); } catch { } } finally { lock (executing) executing.Clear(); SystemEventLogLogic.Log("Stop ProcessRunner", exception); running = false; } } }, TaskCreationOptions.LongRunning); }
public static bool IsAuthorized(Lite <Entity> lite) { return(IsAuthorizedDictionary.GetOrThrow(lite.EntityType)(lite)); }
public EntityHelp(Type type, CultureInfo culture, EntityHelpEntity entity) { Type = type; Culture = culture; Info = HelpGenerator.GetEntityHelp(type); Properties = PropertyRoute.GenerateRoutes(type) .ToDictionary( pp => pp, pp => new PropertyHelp(pp, HelpGenerator.GetPropertyHelp(pp))); var allOperations = HelpLogic.CachedOperationsHelp(); Operations = OperationLogic.GetAllOperationInfos(type).Select(oi => allOperations.GetOrThrow(oi.OperationSymbol)).ToDictionary(a => a.OperationSymbol); var allQueries = HelpLogic.CachedQueriesHelp(); Queries = HelpLogic.TypeToQuery.Value.TryGetC(this.Type).EmptyIfNull().Select(a => allQueries.GetOrThrow(a)).ToDictionary(qh => qh.QueryName); if (entity != null) { HasEntity = true; Description = entity.Description; foreach (var tranProp in entity.Properties) { Properties.GetOrThrow(tranProp.Property.ToPropertyRoute()).UserDescription = tranProp.Description; } foreach (var transOper in entity.Operations) { Operations.GetOrThrow(transOper.Operation).UserDescription = transOper.Description; } } Entity = new Lazy <EntityHelpEntity>(() => HelpLogic.GlobalContext(() => { if (entity == null) { entity = new EntityHelpEntity { Culture = this.Culture.ToCultureInfoEntity(), Type = this.Type.ToTypeEntity(), } } ; entity.Properties.AddRange( PropertyRouteLogic.RetrieveOrGenerateProperties(this.Type.ToTypeEntity()) .Except(entity.Properties.Select(a => a.Property)) .Select(pr => new PropertyRouteHelpEmbedded { Property = pr, Description = null, })); entity.Operations.AddRange(this.Operations.Values.Select(o => o.Entity.Value).ToList()); entity.Queries.AddRange(this.Queries.Values.Select(a => a.Entity.Value).ToList()); return(entity); })); }
IEnumerable <EmailFromEmbedded> GetFrom() { if (template.From != null) { if (template.From.Token != null) { ResultColumn owner = dicTokenColumn.GetOrThrow(template.From.Token.Token); var groups = currentRows.GroupBy(r => (EmailOwnerData)r[owner] !).ToList(); var groupsWithEmail = groups.Where(a => a.Key.Email.HasText()).ToList(); if (groupsWithEmail.IsEmpty()) { switch (template.From.WhenNone) { case WhenNoneFromBehaviour.ThrowException: if (groups.Count() == 0) { throw new InvalidOperationException($"Impossible to send {this.template} because From Token ({template.From.Token}) returned no result"); } else { throw new InvalidOperationException($"Impossible to send {this.template} because From Token ({template.From.Token}) returned results without Email addresses"); } case WhenNoneFromBehaviour.NoMessage: yield break; case WhenNoneFromBehaviour.DefaultFrom: if (smtpConfig != null && smtpConfig.DefaultFrom != null) { yield return(smtpConfig.DefaultFrom.Clone()); } else { throw new InvalidOperationException("Not Default From found"); } break; default: throw new UnexpectedValueException(template.From.WhenNone); } } else { if (template.From.WhenMany == WhenManyFromBehaviour.FistResult) { groupsWithEmail = groupsWithEmail.Take(1).ToList(); } foreach (var gr in groupsWithEmail) { var old = currentRows; currentRows = gr; yield return(new EmailFromEmbedded(gr.Key)); currentRows = old; } } } else { yield return(new EmailFromEmbedded { EmailOwner = null, EmailAddress = template.From.EmailAddress !, DisplayName = template.From.DisplayName, AzureUserId = template.From.AzureUserId, });
public string?ValidateEncodingProperty(PredictorEntity predictor, PredictorSubQueryEntity?subQuery, PredictorColumnEncodingSymbol encoding, PredictorColumnUsage usage, QueryTokenEmbedded token) { return(Encodings.GetOrThrow(encoding).ValidateEncodingProperty(predictor, subQuery, encoding, usage, token)); }
IEnumerable <EmailAddressEmbedded> GetFrom() { if (template.From != null) { if (template.From.Token != null) { ResultColumn owner = dicTokenColumn.GetOrThrow(template.From.Token.Token); if (!template.SendDifferentMessages) { yield return(new EmailAddressEmbedded(currentRows.Select(r => (EmailOwnerData)r[owner]).Distinct().SingleEx())); } else { var groups = currentRows.GroupBy(r => (EmailOwnerData)r[owner]); if (groups.Count() == 1 && groups.Single().Key?.Owner == null) { yield break; } else { foreach (var gr in groups) { var old = currentRows; currentRows = gr; yield return(new EmailAddressEmbedded(gr.Key)); currentRows = old; } } } } else { yield return(new EmailAddressEmbedded(new EmailOwnerData { CultureInfo = null, Email = template.From.EmailAddress, DisplayName = template.From.DisplayName, })); } } else { if (smtpConfig != null && smtpConfig.DefaultFrom != null) { yield return(smtpConfig.DefaultFrom.Clone()); } else { SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; yield return(new EmailAddressEmbedded { EmailAddress = smtpSection.From }); } } }
public static void SynchronizeRoles(XDocument doc) { Table table = Schema.Current.Table(typeof(RoleEntity)); TableMList relationalTable = table.TablesMList().Single(); Dictionary <string, XElement> rolesXml = doc.Root.Element("Roles").Elements("Role").ToDictionary(x => x.Attribute("Name").Value); { Dictionary <string, RoleEntity> rolesDic = Database.Query <RoleEntity>().ToDictionary(a => a.ToString()); Replacements replacements = new Replacements(); replacements.AskForReplacements(rolesDic.Keys.ToHashSet(), rolesXml.Keys.ToHashSet(), "Roles"); rolesDic = replacements.ApplyReplacementsToOld(rolesDic, "Roles"); Console.WriteLine("Part 1: Syncronize roles without relationships"); var roleInsertsDeletes = Synchronizer.SynchronizeScript(Spacing.Double, rolesXml, rolesDic, createNew: (name, xelement) => table.InsertSqlSync(new RoleEntity { Name = name }, includeCollections: false), removeOld: (name, role) => SqlPreCommand.Combine(Spacing.Simple, new SqlPreCommandSimple("DELETE {0} WHERE {1} = {2} --{3}" .FormatWith(relationalTable.Name, ((IColumn)relationalTable.Field).Name.SqlEscape(), role.Id, role.Name)), table.DeleteSqlSync(role)), mergeBoth: (name, xElement, role) => { var oldName = role.Name; role.Name = name; role.MergeStrategy = xElement.Attribute("MergeStrategy")?.Let(t => t.Value.ToEnum <MergeStrategy>()) ?? MergeStrategy.Union; return(table.UpdateSqlSync(role, includeCollections: false, comment: oldName)); }); if (roleInsertsDeletes != null) { SqlPreCommand.Combine(Spacing.Triple, new SqlPreCommandSimple("-- BEGIN ROLE SYNC SCRIPT"), new SqlPreCommandSimple("use {0}".FormatWith(Connector.Current.DatabaseName())), roleInsertsDeletes, new SqlPreCommandSimple("-- END ROLE SYNC SCRIPT")).OpenSqlFileRetry(); Console.WriteLine("Press [Enter] when executed..."); Console.ReadLine(); } else { SafeConsole.WriteLineColor(ConsoleColor.Green, "Already syncronized"); } } { Console.WriteLine("Part 2: Syncronize roles relationships"); Dictionary <string, RoleEntity> rolesDic = Database.Query <RoleEntity>().ToDictionary(a => a.ToString()); var roleRelationships = Synchronizer.SynchronizeScript(Spacing.Double, rolesXml, rolesDic, createNew: (name, xelement) => { throw new InvalidOperationException("No new roles should be at this stage. Did you execute the script?"); }, removeOld: (name, role) => { throw new InvalidOperationException("No old roles should be at this stage. Did you execute the script?"); }, mergeBoth: (name, xElement, role) => { var should = xElement.Attribute("Contains").Value.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries); var current = role.Roles.Select(a => a.ToString()); if (should.OrderBy().SequenceEqual(current.OrderBy())) { return(null); } role.Roles = should.Select(rs => rolesDic.GetOrThrow(rs).ToLite()).ToMList(); return(table.UpdateSqlSync(role)); }); if (roleRelationships != null) { SqlPreCommand.Combine(Spacing.Triple, new SqlPreCommandSimple("-- BEGIN ROLE SYNC SCRIPT"), new SqlPreCommandSimple("use {0}".FormatWith(Connector.Current.DatabaseName())), roleRelationships, new SqlPreCommandSimple("-- END ROLE SYNC SCRIPT")).OpenSqlFileRetry(); Console.WriteLine("Press [Enter] when executed..."); Console.ReadLine(); } else { SafeConsole.WriteLineColor(ConsoleColor.Green, "Already syncronized"); } } }
public IEnumerable <EmailMessageEntity> CreateEmailMessageInternal() { ExecuteQuery(); foreach (EmailAddressEmbedded from in GetFrom()) { foreach (List <EmailOwnerRecipientData> recipients in GetRecipients()) { CultureInfo ci = recipients.Where(a => a.Kind == EmailRecipientKind.To).Select(a => a.OwnerData.CultureInfo).FirstOrDefault()?.ToCultureInfo() ?? EmailLogic.Configuration.DefaultCulture.ToCultureInfo(); EmailMessageEntity email = new EmailMessageEntity { Target = entity?.ToLite() ?? (this.model !.UntypedEntity as Entity)?.ToLite(), Recipients = recipients.Select(r => new EmailRecipientEmbedded(r.OwnerData) { Kind = r.Kind }).ToMList(), From = from, IsBodyHtml = template.IsBodyHtml, EditableMessage = template.EditableMessage, Template = template.ToLite(), Attachments = template.Attachments.SelectMany(g => EmailTemplateLogic.GenerateAttachment.Invoke(g, new EmailTemplateLogic.GenerateAttachmentContext(this.qd, template, dicTokenColumn, currentRows, ci) { ModelType = template.Model?.ToType(), Model = model, Entity = entity, })).ToMList() }; EmailTemplateMessageEmbedded message = template.GetCultureMessage(ci) ?? template.GetCultureMessage(EmailLogic.Configuration.DefaultCulture.ToCultureInfo()); if (message == null) { throw new InvalidOperationException("Message {0} does not have a message for CultureInfo {1} (or Default)".FormatWith(template, ci)); } using (CultureInfoUtils.ChangeBothCultures(ci)) { email.Subject = SubjectNode(message).Print( new TextTemplateParameters(entity, ci, dicTokenColumn, currentRows) { IsHtml = false, Model = model }); email.Body = TextNode(message).Print( new TextTemplateParameters(entity, ci, dicTokenColumn, currentRows) { IsHtml = template.IsBodyHtml, Model = model, }); } yield return(email); } } } TextTemplateParser.BlockNode TextNode(EmailTemplateMessageEmbedded message) { if (message.TextParsedNode == null) { string body = message.Text; if (template.MasterTemplate != null) { var emt = template.MasterTemplate.RetrieveAndRemember(); var emtm = emt.GetCultureMessage(message.CultureInfo.ToCultureInfo()) ?? emt.GetCultureMessage(EmailLogic.Configuration.DefaultCulture.ToCultureInfo()); if (emtm != null) { body = EmailMasterTemplateEntity.MasterTemplateContentRegex.Replace(emtm.Text, m => body); } } message.TextParsedNode = TextTemplateParser.Parse(body, qd, template.Model?.ToType()); } return((TextTemplateParser.BlockNode)message.TextParsedNode); } TextTemplateParser.BlockNode SubjectNode(EmailTemplateMessageEmbedded message) { if (message.SubjectParsedNode == null) { message.SubjectParsedNode = TextTemplateParser.Parse(message.Subject, qd, template.Model?.ToType()); } return((TextTemplateParser.BlockNode)message.SubjectParsedNode); } IEnumerable <EmailAddressEmbedded> GetFrom() { if (template.From != null) { if (template.From.Token != null) { ResultColumn owner = dicTokenColumn.GetOrThrow(template.From.Token.Token); if (!template.SendDifferentMessages) { yield return(new EmailAddressEmbedded(currentRows.Select(r => (EmailOwnerData)r[owner] !).Distinct().SingleEx())); } else { var groups = currentRows.GroupBy(r => (EmailOwnerData)r[owner] !); if (groups.Count() == 1 && groups.Single().Key?.Owner == null) { yield break; } else { foreach (var gr in groups) { var old = currentRows; currentRows = gr; yield return(new EmailAddressEmbedded(gr.Key)); currentRows = old; } } } } else { yield return(new EmailAddressEmbedded(new EmailOwnerData { CultureInfo = null, Email = template.From.EmailAddress !, DisplayName = template.From.DisplayName, }));
public static Vector4 GetColor(string palette, Palette.Shade shade = Palette.Shade.PURE) => palettes.GetOrThrow(palette, "Palettes").GetColor(shade);
public static bool GetAllowed(OperationSymbol operationSymbol, bool inUserInterface) { var allowed = authorizedOperations.GetOrThrow(operationSymbol); return(allowed == OperationAllowed.Allow || allowed == OperationAllowed.DBOnly && !inUserInterface); }
public override void Execute() { #line 8 "..\..\Translation\Views\ViewInstance.cshtml" CultureInfo culture = ViewBag.Culture; Type type = ViewBag.Type; ViewBag.Title = TranslationMessage.View0In1.NiceToString().FormatWith(type.NiceName(), culture == null ? TranslationMessage.AllLanguages.NiceToString() : culture.DisplayName); Dictionary <LocalizedInstanceKey, string> master = ViewBag.Master; var cultures = TranslationLogic.CurrentCultureInfos(TranslatedInstanceLogic.DefaultCulture); Func <CultureInfo, bool> editCulture = c => culture == null || culture.Name == c.Name; var filter = (string)ViewBag.Filter; var all = string.IsNullOrEmpty(filter); Func <LocalizedInstanceKey, bool> filtered = li => all || li.RowId.ToString() == filter || li.Instance.Id.ToString() == filter || li.Route.PropertyString().Contains(filter, StringComparison.InvariantCultureIgnoreCase) || master.GetOrThrow(li).Contains(filter, StringComparison.InvariantCultureIgnoreCase) || cultures.Any(ci => (Model.TryGetC(ci)?.TryGetC(li)?.TranslatedText ?? "").Contains(filter, StringComparison.InvariantCultureIgnoreCase)); #line default #line hidden WriteLiteral("\r\n"); #line 31 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.ScriptCss("~/Translation/Content/Translation.css")); #line default #line hidden WriteLiteral("\r\n\r\n\r\n\r\n<h2>"); #line 35 "..\..\Translation\Views\ViewInstance.cshtml" Write(ViewBag.Title); #line default #line hidden WriteLiteral("</h2>\r\n\r\n<div>\r\n"); #line 38 "..\..\Translation\Views\ViewInstance.cshtml" #line default #line hidden #line 38 "..\..\Translation\Views\ViewInstance.cshtml" using (Html.BeginForm("View", "TranslatedInstance", FormMethod.Get)) { #line default #line hidden #line 40 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.Hidden("type")); #line default #line hidden #line 40 "..\..\Translation\Views\ViewInstance.cshtml" #line default #line hidden #line 41 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.Hidden("culture")); #line default #line hidden #line 41 "..\..\Translation\Views\ViewInstance.cshtml" #line default #line hidden #line 42 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.TextBox("filter", filter)); #line default #line hidden #line 42 "..\..\Translation\Views\ViewInstance.cshtml" ; #line default #line hidden WriteLiteral(" <input"); WriteLiteral(" type=\"hidden\""); WriteLiteral(" name=\"searchPressed\""); WriteLiteral(" value=\"true\""); WriteLiteral(" />\r\n"); WriteLiteral(" <input"); WriteLiteral(" type=\"submit\""); WriteAttribute("value", Tuple.Create(" value=\"", 1786), Tuple.Create("\"", 1835) #line 45 "..\..\Translation\Views\ViewInstance.cshtml" , Tuple.Create(Tuple.Create("", 1794), Tuple.Create <System.Object, System.Int32>(TranslationMessage.Search.NiceToString() #line default #line hidden , 1794), false) ); WriteLiteral(" />\r\n"); #line 46 "..\..\Translation\Views\ViewInstance.cshtml" } #line default #line hidden WriteLiteral("</div>\r\n\r\n"); #line 49 "..\..\Translation\Views\ViewInstance.cshtml" if (Model == null) { #line default #line hidden WriteLiteral(" <em>"); #line 51 "..\..\Translation\Views\ViewInstance.cshtml" Write(TranslationMessage.PressSearchForResults.NiceToString()); #line default #line hidden WriteLiteral("</em>\r\n"); #line 52 "..\..\Translation\Views\ViewInstance.cshtml" } else if (Model.IsEmpty()) { #line default #line hidden WriteLiteral(" <strong>"); #line 55 "..\..\Translation\Views\ViewInstance.cshtml" Write(TranslationMessage.NoResultsFound.NiceToString()); #line default #line hidden WriteLiteral("</strong>\r\n"); #line 56 "..\..\Translation\Views\ViewInstance.cshtml" } else { using (Html.BeginForm((TranslatedInstanceController c) => c.SaveView(Signum.Engine.Basics.TypeLogic.GetCleanName(type), culture == null ? null : culture.Name, filter))) { #line default #line hidden WriteLiteral(" <table"); WriteLiteral(" id=\"results\""); WriteLiteral(" style=\"width: 100%; margin: 0px\""); WriteLiteral(" class=\"st\""); WriteLiteral(">\r\n"); #line 62 "..\..\Translation\Views\ViewInstance.cshtml" #line default #line hidden #line 62 "..\..\Translation\Views\ViewInstance.cshtml" foreach (var instance in master.Keys.Where(li => master.GetOrThrow(li).HasText()).Where(filtered).GroupBy(a => a.Instance).OrderBy(a => a.Key.Id)) { #line default #line hidden WriteLiteral(" <thead>\r\n <tr>\r\n <th"); WriteLiteral(" class=\"leftCell\""); WriteLiteral(">"); #line 66 "..\..\Translation\Views\ViewInstance.cshtml" Write(TranslationMessage.Instance.NiceToString()); #line default #line hidden WriteLiteral("</th>\r\n <th"); WriteLiteral(" class=\"titleCell\""); WriteLiteral(">"); #line 67 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.Href(Navigator.NavigateRoute(instance.Key), instance.Key.ToString())); #line default #line hidden WriteLiteral("</th>\r\n </tr>\r\n </thead>\r\n"); #line 70 "..\..\Translation\Views\ViewInstance.cshtml" foreach (LocalizedInstanceKey key in instance.OrderBy(a => a.Route.ToString())) { var propertyString = key.Route.PropertyString().Replace("/", "[" + key.RowId + "]."); #line default #line hidden WriteLiteral(" <tr>\r\n <th"); WriteLiteral(" class=\"leftCell\""); WriteLiteral(">\r\n"); WriteLiteral(" "); #line 76 "..\..\Translation\Views\ViewInstance.cshtml" Write(TranslationMessage.Property.NiceToString()); #line default #line hidden WriteLiteral("\r\n </th>\r\n <th>"); #line 78 "..\..\Translation\Views\ViewInstance.cshtml" Write(propertyString); #line default #line hidden WriteLiteral("</th>\r\n </tr>\r\n"); #line 80 "..\..\Translation\Views\ViewInstance.cshtml" foreach (var ci in cultures) { var formName = ci.Name + "#" + key.Instance.Key() + "#" + propertyString; if (ci.Name == TranslatedInstanceLogic.DefaultCulture.Name) { #line default #line hidden WriteLiteral(" <tr>\r\n <td"); WriteLiteral(" class=\"leftCell\""); WriteLiteral("><em>"); #line 88 "..\..\Translation\Views\ViewInstance.cshtml" Write(TranslatedInstanceLogic.DefaultCulture); #line default #line hidden WriteLiteral("</em></td>\r\n <td"); WriteLiteral(" class=\"monospaceCell\""); WriteLiteral(">\r\n"); #line 90 "..\..\Translation\Views\ViewInstance.cshtml" #line default #line hidden #line 90 "..\..\Translation\Views\ViewInstance.cshtml" if (TranslatedInstanceLogic.RouteType(key.Route).Value == TranslateableRouteType.Html) { #line default #line hidden WriteLiteral(" <pre>"); #line 92 "..\..\Translation\Views\ViewInstance.cshtml" Write(master[key]); #line default #line hidden WriteLiteral("</pre>\r\n"); #line 93 "..\..\Translation\Views\ViewInstance.cshtml" } else { #line default #line hidden #line 96 "..\..\Translation\Views\ViewInstance.cshtml" Write(master[key]); #line default #line hidden #line 96 "..\..\Translation\Views\ViewInstance.cshtml" } #line default #line hidden WriteLiteral(" "); #line 98 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.TextArea(formName, master[key], new { style = "display:none" })); #line default #line hidden WriteLiteral("\r\n </td>\r\n </tr>\r\n"); #line 101 "..\..\Translation\Views\ViewInstance.cshtml" } else { TranslatedInstanceEntity trans = Model.TryGetC(ci)?.TryGetC(key); if (trans != null && editCulture(ci)) { #line default #line hidden WriteLiteral(" <tr>\r\n <td"); WriteLiteral(" class=\"leftCell\""); WriteLiteral(">"); #line 109 "..\..\Translation\Views\ViewInstance.cshtml" Write(ci.Name); #line default #line hidden WriteLiteral(" Diff</td>\r\n <td"); WriteLiteral(" class=\"monospaceCell\""); WriteLiteral(">\r\n <pre>"); #line 111 "..\..\Translation\Views\ViewInstance.cshtml" Write(Signum.Web.Translation.TranslationClient.Diff(trans.OriginalText, trans.TranslatedText)); #line default #line hidden WriteLiteral("</pre>\r\n </td>\r\n " + " </tr>\r\n"); #line 114 "..\..\Translation\Views\ViewInstance.cshtml" } if (trans != null || editCulture(ci)) { #line default #line hidden WriteLiteral(" <tr>\r\n <td"); WriteLiteral(" class=\"leftCell\""); WriteLiteral(">"); #line 121 "..\..\Translation\Views\ViewInstance.cshtml" Write(ci.Name); #line default #line hidden WriteLiteral("</td>\r\n <td"); WriteLiteral(" class=\"monospaceCell\""); WriteLiteral(">\r\n"); #line 123 "..\..\Translation\Views\ViewInstance.cshtml" #line default #line hidden #line 123 "..\..\Translation\Views\ViewInstance.cshtml" if (editCulture(ci)) { #line default #line hidden #line 125 "..\..\Translation\Views\ViewInstance.cshtml" Write(Html.TextArea(formName, trans?.TranslatedText, new { style = "width:90%;" })); #line default #line hidden #line 125 "..\..\Translation\Views\ViewInstance.cshtml" } else if (TranslatedInstanceLogic.RouteType(key.Route).Value == TranslateableRouteType.Html) { #line default #line hidden WriteLiteral(" <pre>"); #line 129 "..\..\Translation\Views\ViewInstance.cshtml" Write(trans.TranslatedText); #line default #line hidden WriteLiteral("</pre>\r\n"); #line 130 "..\..\Translation\Views\ViewInstance.cshtml" } else { #line default #line hidden #line 133 "..\..\Translation\Views\ViewInstance.cshtml" Write(trans.TranslatedText); #line default #line hidden #line 133 "..\..\Translation\Views\ViewInstance.cshtml" } #line default #line hidden WriteLiteral(" </td>\r\n </tr>\r" + "\n"); #line 137 "..\..\Translation\Views\ViewInstance.cshtml" } } } } } #line default #line hidden WriteLiteral(" </table>\r\n"); WriteLiteral(" <input"); WriteLiteral(" type=\"submit\""); WriteAttribute("value", Tuple.Create(" value=\"", 6410), Tuple.Create("\"", 6457) #line 144 "..\..\Translation\Views\ViewInstance.cshtml" , Tuple.Create(Tuple.Create("", 6418), Tuple.Create <System.Object, System.Int32>(TranslationMessage.Save.NiceToString() #line default #line hidden , 6418), false) ); WriteLiteral(" />\r\n"); #line 145 "..\..\Translation\Views\ViewInstance.cshtml" } } #line default #line hidden WriteLiteral("\r\n\r\n<script>\r\n $(function () {\r\n"); WriteLiteral(" "); #line 151 "..\..\Translation\Views\ViewInstance.cshtml" Write(Signum.Web.Translation.TranslationClient.Module["fixTextAreas"]()); #line default #line hidden WriteLiteral("\r\n });\r\n</script>\r\n"); }
public static ModifiableEntity Convert(this ModelConverterSymbol converterSymbol, ModifiableEntity entity) { return(Converters.GetOrThrow(converterSymbol)(entity)); }
public static string GetCode(this ChartColumnType columnType) { return(codes.GetOrThrow(columnType)); }
public virtual void AbortExport(Lite <DisconnectedExportEntity> stat) { runningExports.GetOrThrow(stat).CancelationSource.Cancel(); }
internal LaneBuilder GetLaneBuilder(Lite <WorkflowLaneEntity> l) { return(lanes.GetOrThrow(l)); }
public static IFile ConstructFile(Type type, UploadedFileData data) { return(FileConstructors.GetOrThrow(type)(data)); }
public DynamicQueryBucket GetQuery(object queryName) { AssertQueryAllowed(queryName, false); return(queries.GetOrThrow(queryName)); }
public static IFileTypeAlgorithm GetAlgorithm(this FileTypeSymbol fileType) { return(FileTypes.GetOrThrow(fileType)); }
public static byte[] CreateReport(this WordTemplateEntity template, ModifiableEntity model = null, ISystemWordTemplate systemWordTemplate = null, bool avoidConversion = false) { WordTemplatePermission.GenerateReport.AssertAuthorized(); Entity entity = null; if (template.SystemWordTemplate != null) { if (systemWordTemplate == null) { systemWordTemplate = SystemWordTemplateLogic.CreateDefaultSystemWordTemplate(template.SystemWordTemplate, model); } else if (template.SystemWordTemplate.ToType() != systemWordTemplate.GetType()) { throw new ArgumentException("systemWordTemplate should be a {0} instead of {1}".FormatWith(template.SystemWordTemplate.FullClassName, systemWordTemplate.GetType().FullName)); } } else { entity = model as Entity ?? throw new InvalidOperationException("Model should be an Entity"); } using (template.DisableAuthorization ? ExecutionMode.Global() : null) using (CultureInfoUtils.ChangeBothCultures(template.Culture.ToCultureInfo())) { QueryDescription qd = DynamicQueryManager.Current.QueryDescription(template.Query.ToQueryName()); var array = template.ProcessOpenXmlPackage(document => { Dump(document, "0.Original.txt"); var parser = new TemplateParser(document, qd, template.SystemWordTemplate.ToType(), template); parser.ParseDocument(); Dump(document, "1.Match.txt"); parser.CreateNodes(); Dump(document, "2.BaseNode.txt"); parser.AssertClean(); if (parser.Errors.Any()) { throw new InvalidOperationException("Error in template {0}:\r\n".FormatWith(template) + parser.Errors.ToString(e => e.Message, "\r\n")); } var renderer = new TemplateRenderer(document, qd, entity, template.Culture.ToCultureInfo(), systemWordTemplate, template); renderer.MakeQuery(); renderer.RenderNodes(); Dump(document, "3.Replaced.txt"); renderer.AssertClean(); FixDocument(document); Dump(document, "4.Fixed.txt"); if (template.WordTransformer != null) { Transformers.GetOrThrow(template.WordTransformer)(new WordContext { Template = template, Entity = entity, SystemWordTemplate = systemWordTemplate }, document); } }); if (!avoidConversion && template.WordConverter != null) { array = Converters.GetOrThrow(template.WordConverter)(new WordContext { Template = template, Entity = entity, SystemWordTemplate = systemWordTemplate }, array); } return(array); } }
Dictionary <Lite <RoleEntity>, RoleAllowedCache> NewCache() { using (AuthLogic.Disable()) using (new EntityCache(EntityCacheType.ForceNewSealed)) { List <Lite <RoleEntity> > roles = AuthLogic.RolesInOrder().ToList(); var rules = Database.Query <RuleTypeEntity>().ToList(); var errors = GraphExplorer.FullIntegrityCheck(GraphExplorer.FromRoots(rules)); if (errors != null) { throw new IntegrityCheckException(errors); } Dictionary <Lite <RoleEntity>, Dictionary <Type, TypeAllowedAndConditions> > realRules = rules.AgGroupToDictionary(ru => ru.Role, gr => gr .SelectCatch(ru => KeyValuePair.Create(TypeLogic.EntityToType.GetOrThrow(ru.Resource), ru.ToTypeAllowedAndConditions())) .ToDictionaryEx()); Dictionary <Lite <RoleEntity>, RoleAllowedCache> newRules = new Dictionary <Lite <RoleEntity>, RoleAllowedCache>(); foreach (var role in roles) { var related = AuthLogic.RelatedTo(role); newRules.Add(role, new RoleAllowedCache(role, merger, related.Select(r => newRules.GetOrThrow(r)).ToList(), realRules.TryGetC(role))); } return(newRules); } }
public static SqlPreCommand SynchronizeTablesScript(Replacements replacements) { Schema s = Schema.Current; Dictionary <string, ITable> model = s.GetDatabaseTables().Where(t => !s.IsExternalDatabase(t.Name.Schema.Database)).ToDictionaryEx(a => a.Name.ToString(), "schema tables"); HashSet <SchemaName> modelSchemas = model.Values.Select(a => a.Name.Schema).Where(a => !SqlBuilder.SystemSchemas.Contains(a.Name)).ToHashSet(); Dictionary <string, DiffTable> database = DefaultGetDatabaseDescription(s.DatabaseNames()); HashSet <SchemaName> databaseSchemas = DefaultGetSchemas(s.DatabaseNames()); SimplifyDiffTables?.Invoke(database); replacements.AskForReplacements(database.Keys.ToHashSet(), model.Keys.ToHashSet(), Replacements.KeyTables); database = replacements.ApplyReplacementsToOld(database, Replacements.KeyTables); Dictionary <ITable, Dictionary <string, Index> > modelIndices = model.Values .ToDictionary(t => t, t => t.GeneratAllIndexes().ToDictionaryEx(a => a.IndexName, "Indexes for {0}".FormatWith(t.Name))); //To --> From Dictionary <ObjectName, ObjectName> copyDataFrom = new Dictionary <ObjectName, ObjectName>(); //A -> A_temp Dictionary <ObjectName, ObjectName> preRenames = new Dictionary <ObjectName, ObjectName>(); model.JoinDictionaryForeach(database, (tn, tab, diff) => { var key = Replacements.KeyColumnsForTable(tn); replacements.AskForReplacements(diff.Columns.Keys.ToHashSet(), tab.Columns.Keys.ToHashSet(), key); diff.Columns = replacements.ApplyReplacementsToOld(diff.Columns, key); diff.Indices = ApplyIndexAutoReplacements(diff, tab, modelIndices[tab]); var diffPk = diff.Columns.TryGetC(tab.PrimaryKey.Name); if (diffPk != null && tab.PrimaryKey.Identity != diffPk.Identity) { if (tab.Name.Equals(diff.Name)) { var tempName = new ObjectName(diff.Name.Schema, diff.Name.Name + "_old"); preRenames.Add(diff.Name, tempName); copyDataFrom.Add(tab.Name, tempName); if (replacements.Interactive) { SafeConsole.WriteLineColor(ConsoleColor.Yellow, $@"Column {diffPk.Name} in {diff.Name} is now Identity={tab.PrimaryKey.Identity}."); Console.WriteLine($@"Changing a Primary Key is not supported by SQL Server so the script will...: 1. Rename {diff.Name} table to {tempName} 2. Create a new table {diff.Name} 3. Copy data from {tempName} to {tab.Name}. 4. Drop {tempName} "); } } else { copyDataFrom.Add(tab.Name, diff.Name); if (replacements.Interactive) { SafeConsole.WriteLineColor(ConsoleColor.Yellow, $@"Column {diffPk.Name} in {diff.Name} is now Identity={tab.PrimaryKey.Identity}."); Console.WriteLine($@"Changing a Primary Key is not supported by SQL Server so the script will...: 1. Create a new table {tab.Name} 2. Copy data from {diff.Name} to {tab.Name}. 3. Drop {diff.Name} "); } } } }); var columnsByFKTarget = database.Values.SelectMany(a => a.Columns.Values).Where(a => a.ForeignKey != null).GroupToDictionary(a => a.ForeignKey.TargetTable); foreach (var pr in preRenames) { var diff = database[pr.Key.ToString()]; diff.Name = pr.Value; foreach (var col in columnsByFKTarget.TryGetC(pr.Key).EmptyIfNull()) { col.ForeignKey.TargetTable = pr.Value; } database.Add(pr.Value.ToString(), diff); database.Remove(pr.Key.ToString()); } Func <ObjectName, ObjectName> ChangeName = (ObjectName objectName) => { string name = replacements.Apply(Replacements.KeyTables, objectName.ToString()); return(model.TryGetC(name)?.Name ?? objectName); }; Func <ObjectName, SqlPreCommand> DeleteAllForeignKey = tableName => { var dropFks = (from t in database.Values from c in t.Columns.Values where c.ForeignKey != null && c.ForeignKey.TargetTable.Equals(tableName) select SqlBuilder.AlterTableDropConstraint(t.Name, c.ForeignKey.Name)).Combine(Spacing.Simple); if (dropFks == null) { return(null); } return(SqlPreCommand.Combine(Spacing.Simple, new SqlPreCommandSimple("---In order to remove the PK of " + tableName.Name), dropFks)); }; using (replacements.WithReplacedDatabaseName()) { SqlPreCommand preRenameTables = preRenames.Select(a => SqlBuilder.RenameTable(a.Key, a.Value.Name)).Combine(Spacing.Double); if (preRenameTables != null) { preRenameTables.GoAfter = true; } SqlPreCommand createSchemas = Synchronizer.SynchronizeScriptReplacing(replacements, "Schemas", modelSchemas.ToDictionary(a => a.ToString()), databaseSchemas.ToDictionary(a => a.ToString()), (_, newSN) => SqlBuilder.CreateSchema(newSN), null, (_, newSN, oldSN) => newSN.Equals(oldSN) ? null : SqlBuilder.CreateSchema(newSN), Spacing.Double); //use database without replacements to just remove indexes SqlPreCommand dropStatistics = Synchronizer.SynchronizeScript(model, database, null, (tn, dif) => SqlBuilder.DropStatistics(tn, dif.Stats), (tn, tab, dif) => { var removedColums = dif.Columns.Keys.Except(tab.Columns.Keys).ToHashSet(); return(SqlBuilder.DropStatistics(tn, dif.Stats.Where(a => a.Columns.Any(removedColums.Contains)).ToList())); }, Spacing.Double); SqlPreCommand dropIndices = Synchronizer.SynchronizeScript(model, database, null, (tn, dif) => dif.Indices.Values.Where(ix => !ix.IsPrimary).Select(ix => SqlBuilder.DropIndex(dif.Name, ix)).Combine(Spacing.Simple), (tn, tab, dif) => { Dictionary <string, Index> modelIxs = modelIndices[tab]; var removedColums = dif.Columns.Keys.Except(tab.Columns.Keys).ToHashSet(); var changes = Synchronizer.SynchronizeScript(modelIxs, dif.Indices, null, (i, dix) => dix.Columns.Any(removedColums.Contains) || dix.IsControlledIndex ? SqlBuilder.DropIndex(dif.Name, dix) : null, (i, mix, dix) => !dix.IndexEquals(dif, mix) ? SqlPreCommand.Combine(Spacing.Double, dix.IsPrimary ? DeleteAllForeignKey(dif.Name) : null, SqlBuilder.DropIndex(dif.Name, dix)) : null, Spacing.Simple); return(changes); }, Spacing.Double); SqlPreCommand dropForeignKeys = Synchronizer.SynchronizeScript( model, database, null, (tn, dif) => dif.Columns.Values.Select(c => c.ForeignKey != null ? SqlBuilder.AlterTableDropConstraint(dif.Name, c.ForeignKey.Name) : null) .Concat(dif.MultiForeignKeys.Select(fk => SqlBuilder.AlterTableDropConstraint(dif.Name, fk.Name))).Combine(Spacing.Simple), (tn, tab, dif) => SqlPreCommand.Combine(Spacing.Simple, Synchronizer.SynchronizeScript( tab.Columns, dif.Columns, null, (cn, colDb) => colDb.ForeignKey != null ? SqlBuilder.AlterTableDropConstraint(dif.Name, colDb.ForeignKey.Name) : null, (cn, colModel, colDb) => colDb.ForeignKey == null ? null : colModel.ReferenceTable == null || colModel.AvoidForeignKey || !colModel.ReferenceTable.Name.Equals(ChangeName(colDb.ForeignKey.TargetTable)) ? SqlBuilder.AlterTableDropConstraint(dif.Name, colDb.ForeignKey.Name) : null, Spacing.Simple), dif.MultiForeignKeys.Select(fk => SqlBuilder.AlterTableDropConstraint(dif.Name, fk.Name)).Combine(Spacing.Simple)), Spacing.Double); SqlPreCommand preRenamePks = preRenames.Select(a => SqlBuilder.DropPrimaryKeyConstraint(a.Value)).Combine(Spacing.Double); SqlPreCommand tables = Synchronizer.SynchronizeScript( model, database, (tn, tab) => SqlPreCommand.Combine(Spacing.Double, SqlBuilder.CreateTableSql(tab), copyDataFrom.ContainsKey(tab.Name) ? CopyData(tab, database.GetOrThrow(copyDataFrom.GetOrThrow(tab.Name).ToString()), replacements).Do(a => a.GoBefore = true) : null ), (tn, dif) => SqlBuilder.DropTable(dif.Name), (tn, tab, dif) => SqlPreCommand.Combine(Spacing.Simple, !object.Equals(dif.Name, tab.Name) ? SqlBuilder.RenameOrMove(dif, tab) : null, Synchronizer.SynchronizeScript( tab.Columns, dif.Columns, (cn, tabCol) => SqlPreCommand.Combine(Spacing.Simple, tabCol.PrimaryKey && dif.PrimaryKeyName != null ? SqlBuilder.DropPrimaryKeyConstraint(tab.Name) : null, AlterTableAddColumnDefault(tab, tabCol, replacements)), (cn, difCol) => SqlPreCommand.Combine(Spacing.Simple, difCol.Default != null ? SqlBuilder.DropDefaultConstraint(tab.Name, difCol.Name) : null, SqlBuilder.AlterTableDropColumn(tab, cn)), (cn, tabCol, difCol) => SqlPreCommand.Combine(Spacing.Simple, difCol.Name == tabCol.Name ? null : SqlBuilder.RenameColumn(tab, difCol.Name, tabCol.Name), difCol.ColumnEquals(tabCol, ignorePrimaryKey: true) ? null : SqlPreCommand.Combine(Spacing.Simple, tabCol.PrimaryKey && !difCol.PrimaryKey && dif.PrimaryKeyName != null ? SqlBuilder.DropPrimaryKeyConstraint(tab.Name) : null, SqlBuilder.AlterTableAlterColumn(tab, tabCol), tabCol.SqlDbType == SqlDbType.NVarChar && difCol.SqlDbType == SqlDbType.NChar ? SqlBuilder.UpdateTrim(tab, tabCol) : null), difCol.DefaultEquals(tabCol) ? null : SqlPreCommand.Combine(Spacing.Simple, difCol.Default != null ? SqlBuilder.DropDefaultConstraint(tab.Name, tabCol.Name) : null, tabCol.Default != null ? SqlBuilder.AddDefaultConstraint(tab.Name, tabCol.Name, tabCol.Default, tabCol.SqlDbType) : null), UpdateByFkChange(tn, difCol, tabCol, ChangeName, copyDataFrom)), Spacing.Simple)), Spacing.Double); if (tables != null) { tables.GoAfter = true; } var tableReplacements = replacements.TryGetC(Replacements.KeyTables); if (tableReplacements != null) { replacements[Replacements.KeyTablesInverse] = tableReplacements.Inverse(); } SqlPreCommand syncEnums; try { syncEnums = SynchronizeEnumsScript(replacements); } catch (Exception e) { syncEnums = new SqlPreCommandSimple("-- Exception synchronizing enums: " + e.Message); } SqlPreCommand addForeingKeys = Synchronizer.SynchronizeScript( model, database, (tn, tab) => SqlBuilder.AlterTableForeignKeys(tab), null, (tn, tab, dif) => Synchronizer.SynchronizeScript( tab.Columns, dif.Columns, (cn, colModel) => colModel.ReferenceTable == null || colModel.AvoidForeignKey ? null : SqlBuilder.AlterTableAddConstraintForeignKey(tab, colModel.Name, colModel.ReferenceTable), null, (cn, colModel, coldb) => { if (colModel.ReferenceTable == null || colModel.AvoidForeignKey) { return(null); } if (coldb.ForeignKey == null || !colModel.ReferenceTable.Name.Equals(ChangeName(coldb.ForeignKey.TargetTable))) { return(SqlBuilder.AlterTableAddConstraintForeignKey(tab, colModel.Name, colModel.ReferenceTable)); } var name = SqlBuilder.ForeignKeyName(tab.Name.Name, colModel.Name); return(SqlPreCommand.Combine(Spacing.Simple, name != coldb.ForeignKey.Name.Name ? SqlBuilder.RenameForeignKey(coldb.ForeignKey.Name, name) : null, (coldb.ForeignKey.IsDisabled || coldb.ForeignKey.IsNotTrusted) && !replacements.SchemaOnly ? SqlBuilder.EnableForeignKey(tab.Name, name) : null)); }, Spacing.Simple), Spacing.Double); bool?createMissingFreeIndexes = null; SqlPreCommand addIndices = Synchronizer.SynchronizeScript(model, database, (tn, tab) => modelIndices[tab].Values.Where(a => !(a is PrimaryClusteredIndex)).Select(SqlBuilder.CreateIndex).Combine(Spacing.Simple), null, (tn, tab, dif) => { var columnReplacements = replacements.TryGetC(Replacements.KeyColumnsForTable(tn)); Func <IColumn, bool> isNew = c => !dif.Columns.ContainsKey(columnReplacements?.TryGetC(c.Name) ?? c.Name); Dictionary <string, Index> modelIxs = modelIndices[tab]; var controlledIndexes = Synchronizer.SynchronizeScript(modelIxs, dif.Indices, (i, mix) => mix is UniqueIndex || mix.Columns.Any(isNew) || SafeConsole.Ask(ref createMissingFreeIndexes, "Create missing non-unique index {0} in {1}?".FormatWith(mix.IndexName, tab.Name)) ? SqlBuilder.CreateIndex(mix) : null, null, (i, mix, dix) => !dix.IndexEquals(dif, mix) ? SqlBuilder.CreateIndex(mix) : mix.IndexName != dix.IndexName ? SqlBuilder.RenameIndex(tab, dix.IndexName, mix.IndexName) : null, Spacing.Simple); return(SqlPreCommand.Combine(Spacing.Simple, controlledIndexes)); }, Spacing.Double); SqlPreCommand dropSchemas = Synchronizer.SynchronizeScriptReplacing(replacements, "Schemas", modelSchemas.ToDictionary(a => a.ToString()), databaseSchemas.ToDictionary(a => a.ToString()), null, (_, oldSN) => DropSchema(oldSN) ? SqlBuilder.DropSchema(oldSN) : null, (_, newSN, oldSN) => newSN.Equals(oldSN) ? null : SqlBuilder.DropSchema(oldSN), Spacing.Double); return(SqlPreCommand.Combine(Spacing.Triple, preRenameTables, createSchemas, dropStatistics, dropIndices, dropForeignKeys, preRenamePks, tables, syncEnums, addForeingKeys, addIndices, dropSchemas)); } }
public static IProcessAlgorithm GetProcessAlgorithm(ProcessAlgorithmSymbol processAlgorithm) { return(registeredProcesses.GetOrThrow(processAlgorithm, "The process algorithm {0} is not registered")); }
public static void FadeIn(float t, string key, ICancellee cT, Action cb) { main.sr.sprite = images.GetOrThrow(key, "Endcards"); main.RunRIEnumerator(main._FadeIn(t, cT, cb)); }
bool?Necessary(S state, int index) { return(dictionary.GetOrThrow(state, "State {0} not registered in StateValidator")[index]); }
public List <string> Validate(Action <WorkflowGatewayEntity, WorkflowGatewayDirection> changeDirection) { List <string> errors = new List <string>(); if (Events.Count(a => a.Value.Type.IsStart()) == 0) { errors.Add(WorkflowValidationMessage.SomeStartEventIsRequired.NiceToString()); } if (Workflow.MainEntityStrategy != WorkflowMainEntityStrategy.CreateNew) { if (Events.Count(a => a.Value.Type == WorkflowEventType.Start) == 0) { errors.Add(WorkflowValidationMessage.NormalStartEventIsRequiredWhenThe0Are1Or2.NiceToString( Workflow.MainEntityStrategy.GetType().NiceName(), WorkflowMainEntityStrategy.SelectByUser.NiceToString(), WorkflowMainEntityStrategy.Both.NiceToString())); } } if (Events.Count(a => a.Value.Type == WorkflowEventType.Start) > 1) { errors.Add(WorkflowValidationMessage.MultipleStartEventsAreNotAllowed.NiceToString()); } var finishEventCount = Events.Count(a => a.Value.Type.IsFinish()); if (finishEventCount == 0) { errors.Add(WorkflowValidationMessage.FinishEventIsRequired.NiceToString()); } Events.Values.ToList().ForEach(e => { var fanIn = PreviousGraph.RelatedTo(e).Count; var fanOut = NextGraph.RelatedTo(e).Count; if (e.Type.IsStart()) { if (fanIn > 0) { errors.Add(WorkflowValidationMessage._0HasInputs.NiceToString(e)); } if (fanOut == 0) { errors.Add(WorkflowValidationMessage._0HasNoOutputs.NiceToString(e)); } if (fanOut > 1) { errors.Add(WorkflowValidationMessage._0HasMultipleOutputs.NiceToString(e)); } if (fanOut == 1) { var nextConn = NextGraph.RelatedTo(e).Single().Value; if (e.Type == WorkflowEventType.Start && !(nextConn.To is WorkflowActivityEntity)) { errors.Add(WorkflowValidationMessage.StartEventNextNodeShouldBeAnActivity.NiceToString()); } } } if (e.Type.IsFinish()) { if (fanIn == 0) { errors.Add(WorkflowValidationMessage._0HasNoInputs.NiceToString(e)); } if (fanOut > 0) { errors.Add(WorkflowValidationMessage._0HasOutputs.NiceToString(e)); } } if (e.Type.IsTimerStart()) { var schedule = e.ScheduledTask(); if (schedule == null) { errors.Add(WorkflowValidationMessage._0IsTimerStartAndSchedulerIsMandatory.NiceToString(e)); } var wet = e.WorkflowEventTask(); if (wet == null) { errors.Add(WorkflowValidationMessage._0IsTimerStartAndTaskIsMandatory.NiceToString(e)); } else if (wet.TriggeredOn != TriggeredOn.Always) { if (wet.Condition?.Script == null || !wet.Condition.Script.Trim().HasText()) { errors.Add(WorkflowValidationMessage._0IsConditionalStartAndTaskConditionIsMandatory.NiceToString(e)); } } } }); Gateways.Values.ToList().ForEach(g => { var fanIn = PreviousGraph.RelatedTo(g).Count; var fanOut = NextGraph.RelatedTo(g).Count; if (fanIn == 0) { errors.Add(WorkflowValidationMessage._0HasNoInputs.NiceToString(g)); } if (fanOut == 0) { errors.Add(WorkflowValidationMessage._0HasNoOutputs.NiceToString(g)); } if (fanIn == 1 && fanOut == 1) { errors.Add(WorkflowValidationMessage._0HasJustOneInputAndOneOutput.NiceToString(g)); } var newDirection = fanOut == 1 ? WorkflowGatewayDirection.Join : WorkflowGatewayDirection.Split; if (g.Direction != newDirection) { changeDirection(g, newDirection); } if (g.Direction == WorkflowGatewayDirection.Split) { if (g.Type == WorkflowGatewayType.Exclusive || g.Type == WorkflowGatewayType.Inclusive) { if (NextGraph.RelatedTo(g).OrderByDescending(a => a.Value.Order).Any(c => c.Value.DecisonResult != null)) { List <WorkflowActivityEntity> previousActivities = new List <WorkflowActivityEntity>(); PreviousGraph.DepthExploreConnections(g, (prev, conn, next) => { if (next is WorkflowActivityEntity a) { previousActivities.Add(a); return(false); } return(true); }); foreach (var act in previousActivities.Where(a => a.Type != WorkflowActivityType.Decision)) { errors.Add(WorkflowValidationMessage.Activity0ShouldBeDecision.NiceToString(act)); } } } if (g.Type == WorkflowGatewayType.Exclusive && NextGraph.RelatedTo(g).OrderByDescending(a => a.Value.Order).Skip(1).Any(c => c.Value.DecisonResult == null && c.Value.Condition == null)) { errors.Add(WorkflowValidationMessage.Gateway0ShouldHasConditionOrDecisionOnEachOutputExceptTheLast.NiceToString(g)); } if (g.Type == WorkflowGatewayType.Inclusive && NextGraph.RelatedTo(g).Any(c => c.Value.DecisonResult == null && c.Value.Condition == null)) { errors.Add(WorkflowValidationMessage.Gateway0ShouldHasConditionOnEachOutput.NiceToString(g)); } } }); var starts = Events.Values.Where(a => a.Type.IsStart()).ToList(); TrackId = starts.ToDictionary(a => (IWorkflowNodeEntity)a, a => 0); TrackCreatedBy = new Dictionary <int, WorkflowGatewayEntity> { { 0, null } }; ParallelWorkflowPairs = new Dictionary <WorkflowGatewayEntity, WorkflowGatewayEntity>(); starts.ForEach(st => NextGraph.BreadthExploreConnections(st, (prev, conn, next) => { var prevTrackId = TrackId.GetOrThrow(prev); int newTrackId; if (IsParallelGateway(prev, WorkflowGatewayDirection.Split)) { if (IsParallelGateway(next, WorkflowGatewayDirection.Join)) { newTrackId = prevTrackId; } else { newTrackId = TrackCreatedBy.Count + 1; TrackCreatedBy.Add(newTrackId, (WorkflowGatewayEntity)prev); } } else { if (IsParallelGateway(next, WorkflowGatewayDirection.Join)) { var split = TrackCreatedBy.TryGetC(prevTrackId); if (split == null) { errors.Add(WorkflowValidationMessage._0CanNotBeConnectedToAParallelJoinBecauseHasNoPreviousParallelSplit.NiceToString(prev)); return(false); } ParallelWorkflowPairs[split] = (WorkflowGatewayEntity)next; newTrackId = TrackId.GetOrThrow(split); } else { newTrackId = prevTrackId; } } if (TrackId.ContainsKey(next)) { if (TrackId[next] != newTrackId) { errors.Add(WorkflowValidationMessage._0Track1CanNotBeConnectedTo2Track3InsteadOfTrack4.NiceToString(prev, prevTrackId, next, TrackId[next], newTrackId)); } return(false); } else { TrackId[next] = newTrackId; return(true); } }) ); Action <WorkflowActivityEntity, IWorkflowTransitionTo> ValidateTransition = (WorkflowActivityEntity wa, IWorkflowTransitionTo item) => { var activity0CanNotXTo1Because2 = (item is WorkflowJumpEmbedded || item is WorkflowScriptPartEmbedded) ? WorkflowValidationMessage.Activity0CanNotJumpTo1Because2 : WorkflowValidationMessage.Activity0CanNotTimeoutTo1Because2; var to = item.To is Lite <WorkflowActivityEntity>?(IWorkflowNodeEntity)Activities.TryGetC((Lite <WorkflowActivityEntity>)item.To) : item.To is Lite <WorkflowGatewayEntity>?(IWorkflowNodeEntity)Gateways.TryGetC((Lite <WorkflowGatewayEntity>)item.To) : item.To is Lite <WorkflowEventEntity>?(IWorkflowNodeEntity)Events.TryGetC((Lite <WorkflowEventEntity>)item.To) : null; if (to == null) { errors.Add(activity0CanNotXTo1Because2.NiceToString(wa, item.To, WorkflowValidationMessage.IsNotInWorkflow.NiceToString())); } if (to is WorkflowEventEntity && ((WorkflowEventEntity)to).Type.IsStart()) { errors.Add(activity0CanNotXTo1Because2.NiceToString(wa, item.To, WorkflowValidationMessage.IsStart.NiceToString())); } if (to is WorkflowActivityEntity && to == wa) { errors.Add(activity0CanNotXTo1Because2.NiceToString(wa, item.To, WorkflowValidationMessage.IsSelfJumping.NiceToString())); } if (TrackId.GetOrThrow(to) != TrackId.GetOrThrow(wa)) { errors.Add(activity0CanNotXTo1Because2.NiceToString(wa, item.To, WorkflowValidationMessage.IsInDifferentParallelTrack.NiceToString())); } }; foreach (var wa in Activities.Values) { var fanIn = PreviousGraph.RelatedTo(wa).Count; var fanOut = NextGraph.RelatedTo(wa).Count; if (fanIn == 0) { errors.Add(WorkflowValidationMessage._0HasNoInputs.NiceToString(wa)); } if (fanOut == 0) { errors.Add(WorkflowValidationMessage._0HasNoOutputs.NiceToString(wa)); } if (fanOut > 1) { errors.Add(WorkflowValidationMessage._0HasMultipleOutputs.NiceToString(wa)); } if (fanOut == 1 && wa.Type == WorkflowActivityType.Decision) { var nextConn = NextGraph.RelatedTo(wa).Single().Value; if (!(nextConn.To is WorkflowGatewayEntity) || ((WorkflowGatewayEntity)nextConn.To).Type == WorkflowGatewayType.Parallel) { errors.Add(WorkflowValidationMessage.Activity0WithDecisionTypeShouldGoToAnExclusiveOrInclusiveGateways.NiceToString(wa)); } } if (wa.Reject != null) { var prevs = PreviousGraph.IndirectlyRelatedTo(wa, kvp => !(kvp.Key is WorkflowActivityEntity)); if (prevs.Any(a => a is WorkflowEventEntity && ((WorkflowEventEntity)a).Type.IsStart())) { errors.Add(WorkflowValidationMessage.Activity0CanNotRejectToStart.NiceToString(wa)); } if (prevs.Any(a => IsParallelGateway(a))) { errors.Add(WorkflowValidationMessage.Activity0CanNotRejectToParallelGateway.NiceToString(wa)); } } if (wa.Timeout != null) { ValidateTransition(wa, wa.Timeout); } if (wa.Script != null) { ValidateTransition(wa, wa.Script); } foreach (var item in wa.Jumps) { ValidateTransition(wa, item); } } if (errors.HasItems()) { this.TrackCreatedBy = null; this.TrackId = null; this.ParallelWorkflowPairs = null; } return(errors); }
public QueryHelp(object queryName, CultureInfo ci, QueryHelpEntity entity) { QueryName = queryName; Culture = ci; Info = HelpGenerator.GetQueryHelp(DynamicQueryManager.Current.GetQuery(queryName).Core.Value); Columns = DynamicQueryManager.Current.GetQuery(queryName).Core.Value.StaticColumns.ToDictionary( cf => cf.Name, cf => new QueryColumnHelp(cf, cf.DisplayName(), HelpGenerator.GetQueryColumnHelp(cf))); if (entity != null) { HasEntity = true; UserDescription = entity.Description; foreach (var tranColumn in entity.Columns) { Columns.GetOrThrow(tranColumn.ColumnName).UserDescription = tranColumn.Description; } } Entity = new Lazy<QueryHelpEntity>(() => HelpLogic.GlobalContext(() => { if (entity == null) entity = new QueryHelpEntity { Culture = this.Culture.ToCultureInfoEntity(), Query = QueryLogic.GetQueryEntity(this.QueryName), }; entity.Columns.AddRange( DynamicQueryManager.Current.GetQuery(this.QueryName).Core.Value.StaticColumns.Select(a => a.Name) .Except(entity.Columns.Select(a => a.ColumnName)) .Select(pr => new QueryColumnHelpEntity { ColumnName = pr, Description = null, })); return entity; })); }
public void Validate(List <WorkflowIssue> issuesContainer, Action <WorkflowGatewayEntity, WorkflowGatewayDirection> changeDirection) { List <WorkflowIssue> issues = issuesContainer; if (Events.Count(a => a.Value.Type.IsStart()) == 0) { issues.AddError(null, WorkflowValidationMessage.SomeStartEventIsRequired.NiceToString()); } if (Workflow.MainEntityStrategies.Any(a => a == WorkflowMainEntityStrategy.SelectByUser || a == WorkflowMainEntityStrategy.Clone)) { if (Events.Count(a => a.Value.Type == WorkflowEventType.Start) == 0) { issues.AddError(null, WorkflowValidationMessage.NormalStartEventIsRequiredWhenThe0Are1Or2.NiceToString( Workflow.MainEntityStrategies.GetType().NiceName(), WorkflowMainEntityStrategy.SelectByUser.NiceToString(), WorkflowMainEntityStrategy.Clone.NiceToString())); } } if (Events.Count(a => a.Value.Type == WorkflowEventType.Start) > 1) { foreach (var e in Events.Where(a => a.Value.Type == WorkflowEventType.Start)) { issues.AddError(e.Value, WorkflowValidationMessage.MultipleStartEventsAreNotAllowed.NiceToString()); } } var finishEventCount = Events.Count(a => a.Value.Type.IsFinish()); if (finishEventCount == 0) { issues.AddError(null, WorkflowValidationMessage.FinishEventIsRequired.NiceToString()); } Events.Values.ToList().ForEach(e => { var fanIn = PreviousConnections(e).Count(); var fanOut = NextConnections(e).Count(); if (e.Type.IsStart()) { if (fanIn > 0) { issues.AddError(e, WorkflowValidationMessage._0HasInputs.NiceToString(e)); } if (fanOut == 0) { issues.AddError(e, WorkflowValidationMessage._0HasNoOutputs.NiceToString(e)); } if (fanOut > 1) { issues.AddError(e, WorkflowValidationMessage._0HasMultipleOutputs.NiceToString(e)); } if (fanOut == 1) { var nextConn = NextConnections(e).SingleEx(); if (e.Type == WorkflowEventType.Start && !(nextConn.To is WorkflowActivityEntity)) { issues.AddError(e, WorkflowValidationMessage.StartEventNextNodeShouldBeAnActivity.NiceToString()); } } } if (e.Type.IsFinish()) { if (fanIn == 0) { issues.AddError(e, WorkflowValidationMessage._0HasNoInputs.NiceToString(e)); } if (fanOut > 0) { issues.AddError(e, WorkflowValidationMessage._0HasOutputs.NiceToString(e)); } } if (e.Type.IsScheduledStart()) { var schedule = e.ScheduledTask(); if (schedule == null) { issues.AddError(e, WorkflowValidationMessage._0IsTimerStartAndSchedulerIsMandatory.NiceToString(e)); } var wet = e.WorkflowEventTask(); if (wet == null) { issues.AddError(e, WorkflowValidationMessage._0IsTimerStartAndTaskIsMandatory.NiceToString(e)); } else if (wet.TriggeredOn != TriggeredOn.Always) { if (wet.Condition?.Script == null || !wet.Condition.Script.Trim().HasText()) { issues.AddError(e, WorkflowValidationMessage._0IsConditionalStartAndTaskConditionIsMandatory.NiceToString(e)); } } } if (e.Type.IsTimer()) { var boundaryOutput = NextConnections(e).Only(); if (boundaryOutput == null || boundaryOutput.Type != ConnectionType.Normal) { if (e.Type == WorkflowEventType.IntermediateTimer) { issues.AddError(e, WorkflowValidationMessage.IntermediateTimer0ShouldHaveOneOutputOfType1.NiceToString(e, ConnectionType.Normal.NiceToString())); } else { var parentActivity = Activities.Values.Where(a => a.BoundaryTimers.Contains(e)).SingleEx(); issues.AddError(e, WorkflowValidationMessage.BoundaryTimer0OfActivity1ShouldHaveExactlyOneConnectionOfType2.NiceToString(e, parentActivity, ConnectionType.Normal.NiceToString())); } } if (e.Type == WorkflowEventType.IntermediateTimer && !e.Name.HasText()) { issues.AddError(e, WorkflowValidationMessage.IntermediateTimer0ShouldHaveName.NiceToString(e)); } } }); Gateways.Values.ToList().ForEach(g => { var fanIn = PreviousConnections(g).Count(); var fanOut = NextConnections(g).Count(); if (fanIn == 0) { issues.AddError(g, WorkflowValidationMessage._0HasNoInputs.NiceToString(g)); } if (fanOut == 0) { issues.AddError(g, WorkflowValidationMessage._0HasNoOutputs.NiceToString(g)); } if (fanIn == 1 && fanOut == 1) { issues.AddError(g, WorkflowValidationMessage._0HasJustOneInputAndOneOutput.NiceToString(g)); } var newDirection = fanOut == 1 ? WorkflowGatewayDirection.Join : WorkflowGatewayDirection.Split; if (g.Direction != newDirection) { changeDirection(g, newDirection); } if (g.Direction == WorkflowGatewayDirection.Split) { if (g.Type == WorkflowGatewayType.Exclusive || g.Type == WorkflowGatewayType.Inclusive) { if (NextConnections(g).Any(c => IsDecision(c.Type))) { List <WorkflowActivityEntity> previousActivities = new List <WorkflowActivityEntity>(); PreviousGraph.DepthExploreConnections(g, (prev, conn, next) => { if (next is WorkflowActivityEntity a) { previousActivities.Add(a); return(false); } return(true); }); foreach (var act in previousActivities.Where(a => a.Type != WorkflowActivityType.Decision)) { issues.AddError(act, WorkflowValidationMessage.Activity0ShouldBeDecision.NiceToString(act)); } } } switch (g.Type) { case WorkflowGatewayType.Exclusive: if (NextConnections(g).OrderByDescending(a => a.Order).Skip(1).Any(c => c.Type == ConnectionType.Normal && c.Condition == null)) { issues.AddError(g, WorkflowValidationMessage.Gateway0ShouldHasConditionOrDecisionOnEachOutputExceptTheLast.NiceToString(g)); } break; case WorkflowGatewayType.Inclusive: if (NextConnections(g).Count(c => c.Type == ConnectionType.Normal && c.Condition == null) != 1) { issues.AddError(g, WorkflowValidationMessage.InclusiveGateway0ShouldHaveOneConnectionWithoutCondition.NiceToString(g)); } break; case WorkflowGatewayType.Parallel: if (NextConnections(g).Count() == 0) { issues.AddError(g, WorkflowValidationMessage.ParallelSplit0ShouldHaveAtLeastOneConnection.NiceToString(g)); } if (NextConnections(g).Any(a => a.Type != ConnectionType.Normal || a.Condition != null)) { issues.AddError(g, WorkflowValidationMessage.ParallelSplit0ShouldHaveOnlyNormalConnectionsWithoutConditions.NiceToString(g)); } break; default: break; } } }); var starts = Events.Values.Where(a => a.Type.IsStart()).ToList(); TrackId = starts.ToDictionary(a => (IWorkflowNodeEntity)a, a => 0); TrackCreatedBy = new Dictionary <int, IWorkflowNodeEntity> { { 0, null ! } }; Queue <IWorkflowNodeEntity> queue = new Queue <IWorkflowNodeEntity>(); queue.EnqueueRange(starts); while (queue.Count > 0) { IWorkflowNodeEntity node = queue.Dequeue(); var nextConns = NextConnections(node).ToList(); //Clone; if (node is WorkflowActivityEntity wa && wa.BoundaryTimers.Any()) { foreach (var bt in wa.BoundaryTimers) { nextConns.AddRange(NextConnections(bt)); } } foreach (var con in nextConns) { if (ContinueExplore(node, con, con.To)) { queue.Enqueue(con.To); } } } bool ContinueExplore(IWorkflowNodeEntity prev, WorkflowConnectionEntity conn, IWorkflowNodeEntity next) { var prevTrackId = TrackId.GetOrThrow(prev); int newTrackId; if (IsParallelGateway(prev, WorkflowGatewayDirection.Split)) { if (IsParallelGateway(next, WorkflowGatewayDirection.Join)) { newTrackId = prevTrackId; } else { newTrackId = TrackCreatedBy.Count + 1; TrackCreatedBy.Add(newTrackId, (WorkflowGatewayEntity)prev); } } else if (prev is WorkflowActivityEntity act && act.BoundaryTimers.Any(bt => bt.Type == WorkflowEventType.BoundaryForkTimer)) { if (IsParallelGateway(next, WorkflowGatewayDirection.Join)) { newTrackId = prevTrackId; } else { if (conn.From is WorkflowEventEntity ev && ev.Type == WorkflowEventType.BoundaryForkTimer) { newTrackId = TrackCreatedBy.Count + 1; TrackCreatedBy.Add(newTrackId, act); }