private IMerge FindMatchingMerge(INode node) { IMerge result = null; int level = 0; INode nextNode = node.Successors.FirstOrDefault(); while (nextNode != null && !(nextNode is IFinal)) { if (nextNode is IDecision) { level++; } else if (nextNode is IMerge) { if (level == 0) { result = nextNode as IMerge; break; } else { level--; } } nextNode = nextNode.Successors.FirstOrDefault(); } return(result); }
public CodeGenerator(ITemplateEngine templateEngine, IPackageFeed packageFeed, IMerge merge, FileMerge fileMerge, ILogger <CodeGenerator> logger) { _templateEngine = templateEngine; _packageFeed = packageFeed; _merge = merge; _fileMerge = fileMerge; _logger = logger; }
protected virtual void BuildTreeFromGraph(TreeNodeViewModel <INode> parentNode, IEnumerable <INode> nodes) { foreach (var node in nodes) { if (node is IFork) { IJoin matchingJoin = FindMatchingJoin(node); if (matchingJoin == null) { throw new Exception(Resources.DefaultWorkflowViewModelBuilder_ErrorNoMatchingForkOrJoin); } matchingJoin.ParentObject = parentNode; } if (node is IDecision) { IMerge matchingMerge = FindMatchingMerge(node); if (matchingMerge == null) { throw new Exception(Resources.DefaultWorkflowViewModelBuilder_NoMatchingMerge); } matchingMerge.ParentObject = parentNode; } if (node is IJoin) { if (node.ParentObject == null) { throw new Exception(Resources.DefaultWorkflowViewModelBuilder_ErrorOrphanJoin); } this.BuildTreeFromGraph((TreeNodeViewModel <INode>)node.ParentObject, node.Successors); } else if (node is IMerge) { if (node.ParentObject == null) { throw new Exception(Resources.DefaultWorkflowViewModelBuilder_ErrorOrphanMerge); } this.BuildTreeFromGraph((TreeNodeViewModel <INode>)node.ParentObject, node.Successors); } else if (!(node is IFinal)) { var childViewModel = this.GetNodeViewModel(node); childViewModel.ParentNode = parentNode.ParentNode != null && !(parentNode.Model is IFork) && !(parentNode.Model is IDecision) ? parentNode.ParentNode : parentNode; this.BuildTreeFromGraph(childViewModel, node.Successors); } } }
public PresentationController(ISongRepository songRepository, IConvertPresentation pptxToZipConverter, IMerge powerPointMerger, IFileAndFolderPathsCreator fileAndFolderPath, IPresentationRepository presentationRepository, IGetValue valueRetrieval, IGoogleSlides googleSlides) { _powerPointMerger = powerPointMerger; _songRepository = songRepository; _pptxToZipConverter = pptxToZipConverter; _fileAndFolderPath = fileAndFolderPath; _presentationRepository = presentationRepository; _valueRetrieval = valueRetrieval; _googleSlides = googleSlides; }
string GetCmdSummary(CmdStore cs, CmdData data, Branch branch) { if (data.CmdName == nameof(NameCmdLine)) { return(NameCmdLine.GetCommandLine(data)); } if (data.CmdName == nameof(ICreateBranch)) { string name = (data as ICreateBranch).Name; uint cc = (data as ICreateBranch).CommandCount; string result = $"branch {name} {cc}"; if (!name.Equals(branch.Name)) { result += $" (now called {branch.Name})"; } return(result); } if (data.CmdName == nameof(IMerge)) { IMerge m = (data as IMerge); string result = "merge "; Guid fromId = m.FromId; Branch fromBranch = cs.FindBranch(fromId); if (ReferenceEquals(fromBranch, branch.Parent)) { result += ".."; } else { result += fromBranch.Name; } result += $" [{m.MinCmd},{m.MaxCmd}]"; return(result); } return(data.CmdName); }
// 根据生成的类,把json转成protobuf private static void ExportExcelProtobuf(ConfigType configType, string protoName, string relativeDir) { string dir = GetProtoDir(configType, relativeDir); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } Assembly ass = GetAssembly(configType); Type type = ass.GetType($"ET.{protoName}Category"); Type subType = ass.GetType($"ET.{protoName}"); Serializer.NonGeneric.PrepareSerializer(type); Serializer.NonGeneric.PrepareSerializer(subType); IMerge final = Activator.CreateInstance(type) as IMerge; string p = Path.Combine(string.Format(jsonDir, configType, relativeDir)); string[] ss = Directory.GetFiles(p, $"{protoName}_*.txt"); List <string> jsonPaths = ss.ToList(); jsonPaths.Add(Path.Combine(string.Format(jsonDir, configType, relativeDir), $"{protoName}.txt")); jsonPaths.Sort(); jsonPaths.Reverse(); foreach (string jsonPath in jsonPaths) { string json = File.ReadAllText(jsonPath); object deserialize = BsonSerializer.Deserialize(json, type); final.Merge(deserialize); } string path = Path.Combine(dir, $"{protoName}Category.bytes"); using FileStream file = File.Create(path); Serializer.Serialize(file, final); }
public static IMerge <T> MergePath <T>(this IMerge <T> @this, T path) where T : class, new() { @this.Merge(path); return(@this); }
/// <summary> /// Saves command data relating to this branch. /// </summary> /// <param name="data">The data to be written.</param> /// <exception cref="ApplicationException">Attempt to save new data /// to a branch imported from a remote store.</exception> /// <exception cref="ArgumentException">The supplied data does not /// have a sequence number that comes at the end of this branch. /// </exception> /// <remarks> /// This method can be used only to append data to a branch was created /// as part of the local store. As well as saving the command data, it /// will mutate the AC metadata for the branch. /// <para/> /// TODO: At the present time, a merge from a child branch will also /// mutate the AC metadata for the child. This is bad because the /// child could be a remote, but it would be wise to disallow any /// attempt to mutate anything relating to a remote branch. /// </remarks> public void SaveData(CmdData data) { // Make some last-minute checks (these should have been done already) if (IsRemote) { throw new ApplicationException("Attempt to mutate remote branch"); } if (Info.IsCompleted) { throw new ApplicationException("Attempt to mutate a completed branch"); } // The data must come at the end of the current branch if (data.Sequence != Info.CommandCount) { throw new ArgumentException( $"Unexpected command sequence {data.Sequence} " + $"(should be {Info.CommandCount})"); } // Persist the command data Store.WriteData(this, data); // And remember it as part of this branch Commands.Add(data); // If the command is being appended to the current branch, // ensure it's also included in the stream (the command may // not be in the current branch because we may be creating // a new branch) // TODO: The Stream might not be defined when creating a new store if (this.Equals(Store.Current)) { Store.Stream?.Cmds.AddLast(new Cmd(this, data)); } // Update the AC file to reflect the latest command Info.CommandCount = data.Sequence + 1; Info.UpdatedAt = data.CreatedAt; // Update the appropriate merge count if we've just done a merge if (data.CmdName == nameof(IMerge)) { IMerge m = (data as IMerge); Guid fromId = m.FromId; uint numCmd = m.MaxCmd + 1; if (fromId.Equals(Info.ParentId)) { // Increment the number of merges from the parent this.Info.CommandDiscount++; // Just done a merge from the parent (this is the child, // now matches the parent) this.Info.RefreshCount = Parent.Info.CommandCount; // Record the number of times that the parent has already merged // from the child (if at all) uint parentDiscount = 0; if (Parent.Info.LastMerge.TryGetValue(this.Id, out MergeInfo mi)) { parentDiscount = mi.ParentDiscount; } this.Info.RefreshDiscount = parentDiscount; } else { // Merge is from a child. Branch child = Children.FirstOrDefault(x => x.Id.Equals(fromId)); if (child == null) { throw new ApplicationException($"Cannot locate child {fromId}"); } // The child doesn't need to consider the merge that the parent has done, // so increment the number of parent commands the child can ignore if (Info.LastMerge.TryGetValue(fromId, out MergeInfo mi)) { Info.LastMerge[fromId] = new MergeInfo(numCmd, child.Info.CommandDiscount, mi.ParentDiscount + 1); } else { Info.LastMerge.Add(fromId, new MergeInfo(numCmd, child.Info.CommandDiscount, 1)); } } // Reload the stream // TODO: Doing it from scratch is perhaps a bit heavy-handed, // is there a more efficient way to do it? Store.Stream = CreateStream(); } // Save the mutated branch metadata Store.SaveBranchInfo(this); }
public FileMerge(IMerge merge) { _merge = merge; }