protected void WriteResults(GeneratorResult result) { Directory.CreateDirectory(result.OutputPath); foreach (var delete in result.Deletions) { if (!File.Exists(delete)) { continue; } Log.Debug("Deleting file: {File}", delete); File.Delete(delete); } foreach (var generatorOutput in result.Outputs) { var path = Path.GetFullPath(Path.Combine(result.OutputPath, generatorOutput.FileName)); var folder = Path.GetDirectoryName(path); Directory.CreateDirectory(folder); Log.Information("Writing output {FileName} to: {Path}", generatorOutput.FileName, path); File.WriteAllText(path, contents: generatorOutput.Output.Trim()); } }
protected override IEnumerable<GeneratorResult> Generate() { AtomConfig config = TryLoadAtomConfig(); if (config == null) { yield break; } var sqlConfig = config.Targets.Values.OfType<SqlTargetConfig>().Single(); var csharpConfig = config.Targets.Values.OfType<CSharpTargetConfig>().Single(); var defaults = AtomCreator.LoadDefaults(config.AtomPath); var sqlArgs = new GeneratorArguments<SqlTargetConfig>(sqlConfig, config.AtomPath, defaults); var args = new GeneratorArguments<CSharpTargetConfig>(csharpConfig, config.AtomPath, defaults, sqlArgs.Atoms); var sqlResult = new SqlGenerator().Generate(sqlArgs); sqlResult.OutputPath = sqlConfig.OutputPath; //if (Directory.Exists(sqlResult.OutputPath)) //{ // foreach (var file in Directory.EnumerateFiles(sqlResult.OutputPath, "*.generated.sql", SearchOption.AllDirectories)) // { // sqlResult.Deletions.Add(file); // } //} string redGateFile = Path.Combine(sqlConfig.OutputPath, "RedGateDatabaseInfo.xml"); Log.Information("Looking for redgate database info xml at {RedGateDatabaseInfoXml}", redGateFile); if (sqlResult.DataFiles.Any() && File.Exists(redGateFile)) { Log.Information("Found redgate file, updating..."); var regate = XDocument.Load(uri: redGateFile); var dataFiles = regate.Root.Elements("DataFileSet").First(); var allDataFiles = dataFiles.Elements("DataFile") .Select(n => n.Value).Union(sqlResult.DataFiles, StringComparer.OrdinalIgnoreCase).ToList(); dataFiles.Elements("Count") .First() .Value = allDataFiles.Count().ToString(); Log.Information("DataFiles Count: {DataFileCount}", allDataFiles.Count()); dataFiles.Elements("DataFile").Remove(); dataFiles.Add(allDataFiles.Select(s => new XElement("DataFile", s))); var genResult = new GeneratorResult() { OutputPath = sqlConfig.OutputPath }; genResult.AddOutput("RedGateDatabaseInfo.xml", regate.ToString()); yield return genResult; } yield return sqlResult; if (csharpConfig.Repository != null) { var repoResult = new RepositoryGenerator(sqlResult).Generate(args); repoResult.OutputPath = csharpConfig.Repository.OutputPath; yield return repoResult; } var codeResult = new CodeGenerator().Generate(args); codeResult.OutputPath = csharpConfig.Entities.OutputPath; yield return codeResult; }
public TabItemViewModel(GeneratorResult generatorResult) { GeneratorResult = generatorResult; CopyActiveTabToBuffer = new Command(OnCopyActiveTabToBuffer); }
private IEnumerable<GeneratorResult> FromTargetConfigs(SqlTargetConfig sqlConfig) { var args = new GeneratorArguments<SqlTargetConfig>(sqlConfig, AtomsFolder, AtomCreator.LoadDefaults(AtomsFolder)); var sqlResult = new SqlGenerator().Generate(args); sqlResult.OutputPath = sqlConfig.OutputPath; if (Directory.Exists(sqlResult.OutputPath)) { foreach (var file in Directory.EnumerateFiles(sqlResult.OutputPath, "*.generated.sql", SearchOption.AllDirectories)) { sqlResult.Deletions.Add(file); } } string redGateFile = Path.Combine(sqlConfig.OutputPath, "RedGateDatabaseInfo.xml"); Log.Information("Looking for redgate database info xml at {RedGateDatabaseInfoXml}", redGateFile); if (sqlResult.DataFiles.Any() && File.Exists(redGateFile)) { Log.Information("Found redgate file, updating..."); var regate = XDocument.Load(uri: redGateFile); var dataFiles = regate.Root.Elements("DataFileSet").First(); var allDataFiles = dataFiles.Elements("DataFile") .Select(n => n.Value).Union(sqlResult.DataFiles, StringComparer.OrdinalIgnoreCase).ToList(); dataFiles.Elements("Count") .First() .Value = allDataFiles.Count().ToString(); Log.Information("DataFiles Count: {DataFileCount}", allDataFiles.Count()); dataFiles.Elements("DataFile").Remove(); dataFiles.Add(allDataFiles.Select(s => new XElement("DataFile", s))); var genResult = new GeneratorResult() { OutputPath = _config.OutputPath }; genResult.AddOutput("RedGateDatabaseInfo.xml", regate.ToString()); yield return genResult; } yield return sqlResult; }
/// <summary> /// calculates all offsets for the msc /// </summary> /// <param name="drawDestination">actual drawing area</param> /// <param name="worksheet">worksheet sizes of the drawing area</param> public void CalcOffsets(Graphics drawDestination, Worksheet worksheet) { IEnumerator enumerator; float instanceSpace, // horizontal space for every instance instanceOffset, // x position of the first instance sumMargin=0, // margin summation to affact each instance space xSize, // width of the drawing area without margins ySize; // height of the drawing area without margins CalcProcessMargins(); enumerator = processes.GetEnumerator(); for(uint i=0;i<processes.Count;i++){ //calculate summation of all margins enumerator.MoveNext(); sumMargin +=((Process)enumerator.Current).LeftMargin+((Process)enumerator.Current).RightMargin; } this.mAutoWidth = (sumMargin + processes.Count * 150); if (Output.AutosizeOutputWidth == true){ worksheet.SetWorksheetWidth((int)this.mAutoWidth); } xSize = (worksheet.Width - worksheet.LeftMargin) - worksheet.RightMargin; // calculate width of drawing area ySize = worksheet.GetWorksheetHeight(); // calculate height of drawing area Trace.WriteLine(DateTime.Now.TimeOfDay + " ySize: " + ySize.ToString()); instanceSpace = (xSize-(INLINE_OFFSET*2)-sumMargin)/processes.Count; // calculate the available space for each instance instanceOffset = INLINE_OFFSET+instanceSpace/2 + worksheet.LeftMargin; // calculate the x positon of first instance HeadHeight = headLine.GetHeight(drawDestination, xSize); enumerator.Reset(); sumMargin = 0; for(uint i=0;i<processes.Count;i++){ // calculate the x position of each instance enumerator.MoveNext(); sumMargin +=((Process)enumerator.Current).LeftMargin; ((Process)enumerator.Current).XPos = sumMargin + instanceOffset + i * instanceSpace; sumMargin +=((Process)enumerator.Current).RightMargin; } MSCItem.ItemLayoutSize = new SizeF(instanceSpace,(ySize-this.YProcessOffset)-20); // set the max size of msc items mProcessNameHeight=0; mInstanceNameHeight=0; this.CalcProcessesNameHeight(drawDestination); this.mYProcessName = worksheet.TopMargin + this.GetProcessesDescriptionHeight(drawDestination) + this.HeadHeight; // set the verical position of instance name this.YProcessOffset = this.mYProcessName + mInstanceNameHeight+20; // set the vertical offset for first msc item if (instanceSpace < GEM_MIN_INSTANCE_SPACE) // check min horizontal space for instances this.generatorResult = GeneratorResult.InstanceSpaceToSmall; // diagram can not be drawn else this.generatorResult = GeneratorResult.OK; // insantce horizontal space ok }
/// <summary> /// calculates all offsets and line heights for the msc /// </summary> /// <param name="drawDestination">actual drawing area</param> /// <param name="worksheet">worksheet sizes of the drawing area</param> /// <param name="font">font used in the msc</param> public void CalcLineHights(Graphics drawDestination, Worksheet worksheet, Font font) { IEnumerator enumerator; uint line=0; // msc line counter float instanceSpace, // horizontal space for every instance instanceOffset, // x position of the first instance sumMargin=0, // margin summation to affact each instance space xSize, // width of the drawing area without margins ySize; // height of the drawing area without margins CalcProcessMargins(); enumerator = processes.GetEnumerator(); for(uint i=0;i<processes.Count;i++){ //calculate summation of all margins enumerator.MoveNext(); sumMargin +=((Process)enumerator.Current).LeftMargin+((Process)enumerator.Current).RightMargin; } this.mAutoWidth = (sumMargin + processes.Count * 150); if (Output.AutosizeOutputWidth == true){ worksheet.SetWorksheetWidth((int)this.mAutoWidth); } xSize = (worksheet.Width - worksheet.LeftMargin) - worksheet.RightMargin; // calculate width of drawing area ySize = worksheet.GetWorksheetHeight(); // calculate height of drawing area instanceSpace = (xSize-(INLINE_OFFSET*2)-sumMargin)/processes.Count; // calculate the available space for each instance if (instanceSpace < GEM_MIN_INSTANCE_SPACE){ generatorResult = GeneratorResult.InstanceSpaceToSmall; } else{ generatorResult = GeneratorResult.OK; } instanceOffset = INLINE_OFFSET+instanceSpace/2 + worksheet.LeftMargin; // calculate the x positon of first instance HeadHeight = headLine.GetHeight(drawDestination, xSize); enumerator.Reset(); sumMargin = 0; for(uint i=0;i<processes.Count;i++){ // calculate the x position of each instance enumerator.MoveNext(); sumMargin +=((Process)enumerator.Current).LeftMargin; ((Process)enumerator.Current).XPos = sumMargin + instanceOffset + i * instanceSpace; sumMargin +=((Process)enumerator.Current).RightMargin; } MSCItem.ItemFont = font; MSCItem.ItemLayoutSize = new SizeF(instanceSpace,(ySize-this.YProcessOffset)-20); // set the max size of msc items mProcessNameHeight=0; mInstanceNameHeight=0; this.CalcProcessesNameHeight(drawDestination); this.mYProcessName = worksheet.TopMargin + this.GetProcessesDescriptionHeight(drawDestination) + this.HeadHeight; // set the verical position of instance name this.YProcessOffset = this.mYProcessName + mInstanceNameHeight+20; // set the vertical offset for first msc item if (mLines>0){ mDiagramLines = new DiagramLine[mLines+2]; enumerator = items.GetEnumerator(); for(uint i=0;i<items.Count;i++){ // store the maximum line height of each msc line enumerator.MoveNext(); if (enumerator.Current is State) { float xPosMin = GetInstanceXPos(processes.Count-1); float xPosMax = 0; for(int j=0; j<processes.Count; j++){ if(((State)enumerator.Current).IsUsedProcess(j)){ xPosMin = Math.Min(xPosMin,GetInstanceXPos(j)); xPosMax = Math.Max(xPosMax,GetInstanceXPos(j)); } } mDiagramLines[((State)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((State)enumerator.Current).Line].Height,((State)enumerator.Current).GetHeight(drawDestination,xPosMin,xPosMax)); line = ((State)enumerator.Current).Line; } if (enumerator.Current is MSCEnd) { mDiagramLines[((MSCEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MSCEnd)enumerator.Current).Line].Height,((MSCEnd)enumerator.Current).GetHeight(drawDestination)); line = ((MSCEnd)enumerator.Current).Line; } if (enumerator.Current is MeasureStart) { mDiagramLines[((MeasureStart)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureStart)enumerator.Current).Line].Height,((MeasureStart)enumerator.Current).GetHeight(drawDestination)); line = ((MeasureStart)enumerator.Current).Line; } if (enumerator.Current is MeasureStop) { mDiagramLines[((MeasureStop)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureStop)enumerator.Current).Line].Height,((MeasureStop)enumerator.Current).GetHeight(drawDestination)); line = ((MeasureStop)enumerator.Current).Line; } if (enumerator.Current is MeasureBeginn) { mDiagramLines[((MeasureBeginn)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureBeginn)enumerator.Current).Line].Height,((MeasureBeginn)enumerator.Current).GetHeight(drawDestination)); line = ((MeasureBeginn)enumerator.Current).Line; } if (enumerator.Current is MeasureEnd) { mDiagramLines[((MeasureEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureEnd)enumerator.Current).Line].Height,((MeasureEnd)enumerator.Current).GetHeight(drawDestination)); line = ((MeasureEnd)enumerator.Current).Line; } if (enumerator.Current is TimerBegin) { mDiagramLines[((TimerBegin)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimerBegin)enumerator.Current).Line].Height,((TimerBegin)enumerator.Current).GetHeight(drawDestination)); line = ((TimerBegin)enumerator.Current).Line; } if (enumerator.Current is TimerEnd) { mDiagramLines[((TimerEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimerEnd)enumerator.Current).Line].Height,((TimerEnd)enumerator.Current).GetHeight(drawDestination)); line = ((TimerEnd)enumerator.Current).Line; } if (enumerator.Current is TimeoutBegin) { mDiagramLines[((TimeoutBegin)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeoutBegin)enumerator.Current).Line].Height,((TimeoutBegin)enumerator.Current).GetHeight(drawDestination)); line = ((TimeoutBegin)enumerator.Current).Line; } if (enumerator.Current is TimeoutEnd) { mDiagramLines[((TimeoutEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeoutEnd)enumerator.Current).Line].Height,((TimeoutEnd)enumerator.Current).GetHeight(drawDestination)); line = ((TimeoutEnd)enumerator.Current).Line; } if (enumerator.Current is TimeoutStop) { mDiagramLines[((TimeoutStop)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeoutStop)enumerator.Current).Line].Height,((TimeoutStop)enumerator.Current).GetHeight(drawDestination)); line = ((TimeoutStop)enumerator.Current).Line; } if (enumerator.Current is TimeOut) { mDiagramLines[((TimeOut)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeOut)enumerator.Current).Line].Height,((TimeOut)enumerator.Current).GetHeight(drawDestination)); line = ((TimeOut)enumerator.Current).Line; } if (enumerator.Current is StopTimer) { mDiagramLines[((StopTimer)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((StopTimer)enumerator.Current).Line].Height,((StopTimer)enumerator.Current).GetHeight(drawDestination)); line = ((StopTimer)enumerator.Current).Line; } if (enumerator.Current is SetTimer) { mDiagramLines[((SetTimer)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((SetTimer)enumerator.Current).Line].Height,((SetTimer)enumerator.Current).GetHeight(drawDestination)); line = ((SetTimer)enumerator.Current).Line; } if (enumerator.Current is Comment) { if (((Comment)enumerator.Current).Position == CommentPos.OverAll){ mDiagramLines[((Comment)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Comment)enumerator.Current).Line].Height,((Comment)enumerator.Current).GetHeight(drawDestination,GetInstanceXPos(((Comment) enumerator.Current).Process), GetInstanceXPos(0),GetInstanceXPos(processes.Count-1), MSC.LeftMargin + ((Process)processes[0]).LeftRand, MSC.RightMargin + ((Process)processes[processes.Count-1]).RightRand)); } else{ mDiagramLines[((Comment)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Comment)enumerator.Current).Line].Height,((Comment)enumerator.Current).GetHeight(drawDestination,GetInstanceXPos(((Comment) enumerator.Current).Process), worksheet.LeftMargin,worksheet.Width-worksheet.RightMargin, MSC.LeftMargin + ((Process)processes[0]).LeftRand, MSC.RightMargin + ((Process)processes[processes.Count-1]).RightRand)); } line = ((Comment)enumerator.Current).Line; } if (enumerator.Current is LineComment) { mDiagramLines[((LineComment)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((LineComment)enumerator.Current).Line].Height,((LineComment)enumerator.Current).GetHeight(drawDestination)); line = ((LineComment)enumerator.Current).Line; } if (enumerator.Current is Task) { mDiagramLines[((Task)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Task)enumerator.Current).Line].Height,((Task)enumerator.Current).GetHeight(drawDestination)); line = ((Task)enumerator.Current).Line; } if (enumerator.Current is mscElements.Message) { mDiagramLines[((mscElements.Message)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((mscElements.Message)enumerator.Current).Line].Height,((mscElements.Message)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((mscElements.Message)enumerator.Current).MessageSource), GetInstanceXPos(((mscElements.Message)enumerator.Current).MessageDestination))); line = ((mscElements.Message)enumerator.Current).Line; } if (enumerator.Current is Mark) { mDiagramLines[((Mark)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Mark)enumerator.Current).Line].Height,((Mark)enumerator.Current).GetHeight(drawDestination)); line = ((Mark)enumerator.Current).Line; } if (enumerator.Current is FoundMessage) { mDiagramLines[((FoundMessage)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((FoundMessage)enumerator.Current).Line].Height,((FoundMessage)enumerator.Current).GetHeight(drawDestination)); line = ((FoundMessage)enumerator.Current).Line; } if (enumerator.Current is LostMessage) { mDiagramLines[((LostMessage)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((LostMessage)enumerator.Current).Line].Height,((LostMessage)enumerator.Current).GetHeight(drawDestination)); line = ((LostMessage)enumerator.Current).Line; } if (enumerator.Current is ProcessStop) { mDiagramLines[((ProcessStop)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((ProcessStop)enumerator.Current).Line].Height,((ProcessStop)enumerator.Current).GetHeight(drawDestination)); line = ((ProcessStop)enumerator.Current).Line; } if (enumerator.Current is ProcessCreate) { mDiagramLines[((ProcessCreate)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((ProcessCreate)enumerator.Current).Line].Height,((ProcessCreate)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((ProcessCreate)enumerator.Current).Source), GetInstanceXPos(((ProcessCreate)enumerator.Current).Destination))); line = ((ProcessCreate)enumerator.Current).Line; } if (enumerator.Current is ProcessRegion) { mDiagramLines[((ProcessRegion)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((ProcessRegion)enumerator.Current).Line].Height,((ProcessRegion)enumerator.Current).GetHeight(drawDestination)); line = ((ProcessRegion)enumerator.Current).Line; } if (enumerator.Current is Reference) { mDiagramLines[((Reference)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Reference)enumerator.Current).Line].Height,((Reference)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((Reference)enumerator.Current).ProcessBeginn), GetInstanceXPos(((Reference)enumerator.Current).ProcessEnd))); line = ((Reference)enumerator.Current).Line; } if (enumerator.Current is InLineBeginn) { mDiagramLines[((InLineBeginn)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineBeginn)enumerator.Current).Line].Height,((InLineBeginn)enumerator.Current).GetHeight(drawDestination)); line = ((InLineBeginn)enumerator.Current).Line; } if (enumerator.Current is InLineEnd) { mDiagramLines[((InLineEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineEnd)enumerator.Current).Line].Height,((InLineEnd)enumerator.Current).GetHeight(drawDestination)); line = ((InLineEnd)enumerator.Current).Line; } if (enumerator.Current is InLineSeparator) { mDiagramLines[((InLineSeparator)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineSeparator)enumerator.Current).Line].Height,((InLineSeparator)enumerator.Current).GetHeight(drawDestination)); line = ((InLineSeparator)enumerator.Current).Line; } if (enumerator.Current is InLineText) { mDiagramLines[((InLineText)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineText)enumerator.Current).Line].Height,((InLineText)enumerator.Current).GetHeight(drawDestination, ((Process)processes[((InLineText)enumerator.Current).ProcessBeginn]).LeftRand)); line = ((InLineText)enumerator.Current).Line; } if (enumerator.Current is MessageBegin) { mDiagramLines[((MessageBegin)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MessageBegin)enumerator.Current).Line].Height,((MessageBegin)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((MessageBegin)enumerator.Current).MessageSource), GetInstanceXPos(((MessageBegin)enumerator.Current).MessageDestination))); line = ((MessageBegin)enumerator.Current).Line; } if (enumerator.Current is MessageEnd) { mDiagramLines[((MessageEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MessageEnd)enumerator.Current).Line].Height,((MessageEnd)enumerator.Current).GetHeight(drawDestination)); line = ((MessageEnd)enumerator.Current).Line; } if (enumerator.Current is NewPage) { mDiagramLines[((NewPage)enumerator.Current).Line].Height = ((NewPage)enumerator.Current).GetHeight(); line = ((NewPage)enumerator.Current).Line; } } } if (instanceSpace < GEM_MIN_INSTANCE_SPACE) this.generatorResult = GeneratorResult.InstanceSpaceToSmall; else this.generatorResult = GeneratorResult.OK; }
/// <summary> /// draws an acception on the drawing area /// </summary> /// <param name="drawDestination">drawin area</param> /// <param name="result">acception of generating proces</param> /// <returns>nothing</returns> private void DrawError(Graphics drawDestination, GeneratorResult result) { Icon icon1 = new Icon(SystemIcons.Exclamation, 12, 12); RectangleF textBox = new RectangleF(40, 10, 300, 300); StringFormat stringFormat = new StringFormat(); switch(result){ case GeneratorResult.InstanceSpaceToSmall: drawDestination.DrawIcon(icon1,10,10); drawDestination.DrawString("Die Breite des Diagramms ist nicht ausreichend zum Darstellen aller Instanzen",new Font("Arial",10),Brushes.Black,textBox,stringFormat); break; } }