public TestServices With( IAssetLoader assetLoader = null, IInputManager inputManager = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return(new TestServices( assetLoader: assetLoader ?? AssetLoader, inputManager: inputManager ?? InputManager, layoutManager: layoutManager ?? LayoutManager, platformWrapper: platformWrapper ?? PlatformWrapper, renderInterface: renderInterface ?? RenderInterface, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowImpl: windowImpl ?? WindowImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform)); }
public IStyler GetStyler(String name) { if (stylers.Count == 0) { foreach (StylerElement element in generator.Stylers) { try { Type clazz = System.Type.GetType(element.Class); if (clazz != null) { Object o = System.Activator.CreateInstance(clazz, new Object[] { element.GetOptions() }); if (o is IStyler) { IStyler s = (IStyler)o; stylers.Add(element.Name, s); } else { WriteToLog(element.Name + " does not support the IStyler interface"); } } else { WriteToLog("Could not find class '" + element.Class + "', '" + element.Name + "' will not be added to available stylers."); } } catch (Exception ex) { WriteToLog("Error trying to create styler '" + element.Name + "': " + ex.Message); } } } return((IStyler)stylers[name]); }
public TestServices With( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func <IKeyboardDevice> keyboardDevice = null, IKeyboardNavigationHandler keyboardNavigation = null, Func <IMouseDevice> mouseDevice = null, IRuntimePlatform platform = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IScheduler scheduler = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return(new TestServices( assetLoader: assetLoader ?? AssetLoader, focusManager: focusManager ?? FocusManager, inputManager: inputManager ?? InputManager, keyboardDevice: keyboardDevice ?? KeyboardDevice, keyboardNavigation: keyboardNavigation ?? KeyboardNavigation, mouseDevice: mouseDevice ?? MouseDevice, platform: platform ?? Platform, renderInterface: renderInterface ?? RenderInterface, scheduler: scheduler ?? Scheduler, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowingPlatform: windowingPlatform ?? WindowingPlatform, windowImpl: windowImpl ?? WindowImpl)); }
public TestServices( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func<IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func<Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { AssetLoader = assetLoader; FocusManager = focusManager; InputManager = inputManager; KeyboardDevice = keyboardDevice; LayoutManager = layoutManager; PlatformWrapper = platformWrapper; RenderInterface = renderInterface; StandardCursorFactory = standardCursorFactory; Styler = styler; Theme = theme; ThreadingInterface = threadingInterface; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; }
public TestServices( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func <IKeyboardDevice> keyboardDevice = null, IKeyboardNavigationHandler keyboardNavigation = null, Func <IMouseDevice> mouseDevice = null, IRuntimePlatform platform = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IScheduler scheduler = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { AssetLoader = assetLoader; FocusManager = focusManager; InputManager = inputManager; KeyboardDevice = keyboardDevice; KeyboardNavigation = keyboardNavigation; MouseDevice = mouseDevice; Platform = platform; RenderInterface = renderInterface; Scheduler = scheduler; StandardCursorFactory = standardCursorFactory; Styler = styler; Theme = theme; ThreadingInterface = threadingInterface; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; }
public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager) { FlowLayoutPanel holder = new FlowLayoutPanel { FlowDirection = FlowDirection.TopDown }; CheckBox checkBox = new CheckBox { Text = text[0] }; checkBox.Checked = GetChecked(questionElementManager); checkBox.CheckedChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(checkBox.Checked.ToString()); questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementManagerLeaf, bool calculated) => { if (calculated) { bool check = false; bool.TryParse(elementManagerLeaf.AnswerToString(), out check); checkBox.Checked = check; } }; holder.Controls.Add(styler.StyleElement(checkBox)); questionElementManager.OnActiveChange += (string identifier, bool isActive) => holder.Visible = isActive; holder.Visible = questionElementManager.Active; return(styler.StyleElement(holder)); }
public TestServices With( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func <IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IRuntimePlatform platform = null, IRenderer renderer = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IScheduler scheduler = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return(new TestServices( assetLoader: assetLoader ?? AssetLoader, focusManager: focusManager ?? FocusManager, inputManager: inputManager ?? InputManager, keyboardDevice: keyboardDevice ?? KeyboardDevice, layoutManager: layoutManager ?? LayoutManager, platform: platform ?? Platform, renderer: renderer ?? Renderer, renderInterface: renderInterface ?? RenderInterface, renderLoop: renderLoop ?? RenderLoop, scheduler: scheduler ?? Scheduler, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowingPlatform: windowingPlatform ?? WindowingPlatform)); }
public TestServices( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func <IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IRuntimePlatform platform = null, IRenderer renderer = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IScheduler scheduler = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowingPlatform windowingPlatform = null) { AssetLoader = assetLoader; FocusManager = focusManager; InputManager = inputManager; KeyboardDevice = keyboardDevice; LayoutManager = layoutManager; Platform = platform; Renderer = renderer; RenderInterface = renderInterface; RenderLoop = renderLoop; Scheduler = scheduler; StandardCursorFactory = standardCursorFactory; Styler = styler; Theme = theme; ThreadingInterface = threadingInterface; WindowingPlatform = windowingPlatform; }
public TestServices( IAssetLoader assetLoader = null, IInputManager inputManager = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { AssetLoader = assetLoader; InputManager = inputManager; LayoutManager = layoutManager; PlatformWrapper = platformWrapper; RenderInterface = renderInterface; StandardCursorFactory = standardCursorFactory; Styler = styler; Theme = theme; ThreadingInterface = threadingInterface; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; }
protected override void OnAttachedToVisualTree(IRenderRoot root) { base.OnAttachedToVisualTree(root); IStyler styler = Locator.Current.GetService <IStyler>(); styler.ApplyStyles(this); }
public void SetUp() { di = GetDiContainer(); layouter = RandomEntitiesFactory.GetRandomLayouter(CanvasSideLength, di.Resolve <ITagFactory>()); currentLayout = new List <ITag>(); styler = Substitute.For <IStyler>(); styler.GetStyles(Arg.Any <IDictionary <string, int> >()) .Returns(RandomEntitiesFactory.GetRandomStyledStrings(TagsCount)); }
/// <inheritdoc/> protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); IStyler styler = PerspexLocator.Current.GetService <IStyler>(); if (styler != null) { styler.ApplyStyles(this); } }
public Router(IRepository <State> stateRepo, IRepository <Connection> connectionRepo, IRepository <User> userRepo, IRepository <NavCategory> navCategoryRepo, IRepository <StatusBarItem> statusBarRepo, IRepository <Subscription> subscriptionRepository, IStyler styler) { _stateRepo = stateRepo; _connectionRepo = connectionRepo; _userRepo = userRepo; _navCategoryRepo = navCategoryRepo; _statusBarRepo = statusBarRepo; _subscriptionRepository = subscriptionRepository; _styler = styler; }
public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager) { Button colorPickerButton = new Button { Text = text[0] }; UpdateColor(questionElementManager.AnswerToString()); colorPickerButton.Click += (object sender, EventArgs evenArgs) => ColorPickerButton_Click(questionElementManager); questionElementManager.OnAnswerValueUpdate += AnwerUpdate; questionElementManager.OnActiveChange += (string identifier, bool isActive) => colorPickerButton.Visible = isActive; colorPickerButton.Visible = questionElementManager.Active; return(styler.StyleElement(colorPickerButton)); }
private Control CreateRadioButtons(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager) { FlowLayoutPanel holder = new FlowLayoutPanel { FlowDirection = FlowDirection.TopDown }; foreach (string option in text) { RadioButton radioButton = new RadioButton { Text = option }; radioButton.Checked = questionElementManager.AnswerToString() == option; radioButton.CheckedChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(radioButton.Text); questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementManagerLeaf, bool calculated) => { if (calculated) { radioButton.Checked = elementManagerLeaf.AnswerToString() == option; } }; holder.Controls.Add(styler.StyleElement(radioButton)); } return(holder); }
public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager) { string title = text[0]; string[] answerOptions = AllButFirst(text); FlowLayoutPanel holder = new FlowLayoutPanel { FlowDirection = FlowDirection.TopDown }; Label titleLabel = new Label { Text = title }; Control styledTitleLabel = styler.StyleElement(titleLabel); holder.Controls.Add(styledTitleLabel); Control radioButtons = CreateRadioButtons(styler, answerOptions, questionElementManager); radioButtons = styler.StyleElement(radioButtons); holder.Controls.Add(radioButtons); return(styler.StyleElement(holder)); }
public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager) { NumericUpDown spinner = new NumericUpDown(); Label question = new Label { Text = text[0] }; FlowLayoutPanel holder = new FlowLayoutPanel { FlowDirection = FlowDirection.TopDown }; spinner.ValueChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(spinner.Value.ToString()); questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementManagerLeaf, bool calculated) => { if (calculated) { spinner.Value = decimal.Parse(questionElementManager.AnswerToString()); } }; questionElementManager.OnActiveChange += (string identifier, bool isActive) => holder.Visible = isActive; holder.Visible = questionElementManager.Active; holder.Controls.Add(question); holder.Controls.Add(spinner); return(styler.StyleElement(holder)); }
public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager) { // Create holder FlowLayoutPanel holder = new FlowLayoutPanel { FlowDirection = FlowDirection.TopDown }; holder.Controls.Add(styler.StyleElement(new Label { Text = text[0] })); // Create and style textbox Control textbox = CreateTextBox(questionElementManager); textbox.Text = questionElementManager.AnswerToString(); textbox = styler.StyleElement(textbox); holder.Controls.Add(textbox); // Add events on holder questionElementManager.OnActiveChange += (string identifier, bool isActive) => holder.Visible = isActive; holder.Visible = questionElementManager.Active; return(styler.StyleElement(holder)); }
/// <summary> /// Post-parse validations /// </summary> /// <param name="vd"></param> protected void Validate(ParserValidationDelegate vd) { //TODO: walk through collection to make sure that cross relations are correct. foreach (DatabaseElement database in databases) { foreach (SqlEntityElement sqlentity in database.SqlEntities) { if (sqlentity.GetPrimaryKeyColumns().Count == 0 && (sqlentity.AllowDelete || sqlentity.AllowInsert || sqlentity.AllowUpdate)) { vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any primary key columns defined.")); } if (!sqlentity.HasUpdatableColumns() && sqlentity.GenerateUpdateStoredProcScript) { vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any editable columns and does not have generateupdatestoredprocscript=\"false\" specified.")); } } } // make sure that all columns are represented in entities foreach (EntityElement entity in entities) { if (entity.SqlEntity.Name.Length > 0) { foreach (ColumnElement column in entity.SqlEntity.Columns) { if (!column.Obsolete && EntityElement.FindAnyFieldByColumnName(entities, column.Name) == null && !entity.HasEntityMappedColumn(column)) { vd(ParserValidationArgs.NewWarning("could not find property representing column " + column.Name + " in entity " + entity.Name + ".")); } } } foreach (PropertyElement property in entity.Fields) { // make sure that obsolete columns are not mapped to properties if (property.Column.Obsolete && property.Column.Name.Length > 0) { vd(ParserValidationArgs.NewWarning("property " + property.Name + " in entity " + entity.Name + " is mapped to column " + property.Column.Name + " which is obsolete.")); } // have property descriptions "inherit" from a column if they are not populated if (property.Column.Description.Length > 0 && property.Description.Length == 0) { property.Description = property.Column.Description; } } } // make sure that enum values are unique foreach (EnumElement enumtype in enumtypes) { Hashtable values = new Hashtable(); foreach (EnumValueElement value in enumtype.Values) { if (values.Contains(value.Code)) { vd(ParserValidationArgs.NewError("Enum " + enumtype.Name + " has the code '" + value.Code + "' specified more than once.")); } else { values.Add(value.Code, value.Code); } } } // find and assign types to collections if available (the TypeElement is needed for templates that need to add namespaces) foreach (CollectionElement collection in Collections) { if (types.Contains(collection.Type.Name)) { collection.Type = (TypeElement)types[collection.Type.Name]; } } foreach (TaskElement task in generator.Tasks) { IWriter w = GetWriter(task.Writer); if (w == null) { vd(ParserValidationArgs.NewError("Task specified writer '" + task.Writer + "' that was not defined.")); } // check to make sure the styler exists if it is specified (optional) if (task.Styler.Length > 0) { IStyler s = GetStyler(task.Styler); if (s == null) { vd(ParserValidationArgs.NewError("Task specified styler '" + task.Styler + "' that was not defined.")); } } } }
private void GenerateFile(IParser parser, IElement element, ITask task, Template template) { Timer generateTimer = new Timer(); files++; StringWriter writer = new StringWriter(); VelocityContext vc = new VelocityContext(); foreach (Object key in parser.Tools.Keys) { vc.Put(key.ToString(), parser.Tools[key]); } foreach (Object key in task.Parameters.Keys) { vc.Put(key.ToString(), task.Parameters[key]); } vc.Put("dtgversion", this.GetType().Assembly.FullName); vc.Put("options", parser.Configuration); vc.Put("element", element); vc.Put("elements", task.Elements); vc.Put("task", task); Timer timer = new Timer(); try { timer.Start(); template.Merge(vc, writer); timer.Stop(); mergeTicks += timer.TimeSpan.Ticks; String fileName = task.FileNameFormat.Replace("{removewhitespace(element.Name)}", element.Name.Replace(" ", String.Empty)).Replace("{element.Name}", element.Name); String filePath = GetFilePath(task, element); FileInfo file = new FileInfo(filePath + fileName); String content = writer.ToString(); if (content.Length > 0) { IStyler s = parser.GetStyler(task.Styler); if (s == null) { s = new NoStyler(); } s.File = file.FullName; IWriter w = parser.GetWriter(task.Writer); try { w.BackupFilePath = task.BackupDirectory + "\\" + Path.GetFileNameWithoutExtension(file.Name) + "." + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(file.Name) + "~"; timer.Start(); Boolean changed = w.Write(file, content, s); timer.Stop(); writerTicks += timer.TimeSpan.Ticks; if (changed) { WriteToLog(w.Log); w.Log.Clear(); WriteToLog("generating " + file.FullName); // touch the backup file so the timestamp is later than the newly generated file //FileInfo backupFile = new FileInfo(w.BackupFilePath); //backupFile.LastWriteTime = DateTime.Now; } } catch (Exception ex) { WriteToLog("error generating " + file.FullName + " -- " + ex.Message); } } } catch (Exception ex) { WriteToLog(String.Format("Unhandled exception in generating file for element '{0}' of task '{1}'", element.Name, task.Name)); WriteToLog(ex.ToString()); } generateTimer.Stop(); generateTicks += generateTimer.TimeSpan.Ticks; }
public Window() { IPlatformRenderInterface renderInterface = Locator.Current.GetService <IPlatformRenderInterface>(); this.impl = Locator.Current.GetService <IWindowImpl>(); this.inputManager = Locator.Current.GetService <IInputManager>(); this.LayoutManager = Locator.Current.GetService <ILayoutManager>(); this.renderManager = Locator.Current.GetService <IRenderManager>(); if (renderInterface == null) { throw new InvalidOperationException( "Could not create an interface to the rendering subsystem: maybe no rendering subsystem was initialized?"); } if (this.impl == null) { throw new InvalidOperationException( "Could not create window implementation: maybe no windowing subsystem was initialized?"); } if (this.inputManager == null) { throw new InvalidOperationException( "Could not create input manager: maybe Application.RegisterServices() wasn't called?"); } if (this.LayoutManager == null) { throw new InvalidOperationException( "Could not create layout manager: maybe Application.RegisterServices() wasn't called?"); } if (this.renderManager == null) { throw new InvalidOperationException( "Could not create render manager: maybe Application.RegisterServices() wasn't called?"); } this.impl.SetOwner(this); this.impl.Activated = this.HandleActivated; this.impl.Closed = this.HandleClosed; this.impl.Input = this.HandleInput; this.impl.Paint = this.HandlePaint; this.impl.Resized = this.HandleResized; Size clientSize = this.ClientSize = this.impl.ClientSize; this.dispatcher = Dispatcher.UIThread; this.renderer = renderInterface.CreateRenderer(this.impl.Handle, clientSize.Width, clientSize.Height); this.LayoutManager.Root = this; this.LayoutManager.LayoutNeeded.Subscribe(_ => this.HandleLayoutNeeded()); this.renderManager.RenderNeeded.Subscribe(_ => this.HandleRenderNeeded()); this.GetObservable(TitleProperty).Subscribe(s => this.impl.SetTitle(s)); IStyler styler = Locator.Current.GetService <IStyler>(); styler.ApplyStyles(this); }
public Boolean Write(FileInfo file, String contents, IStyler styler) { // Create the directory if it doesn't exist. if (!file.Directory.Exists) { file.Directory.Create(); } Console.Out.WriteLine("processing file " + file.FullName); MemoryStream stream = new MemoryStream(); StreamWriter sw = new StreamWriter(stream); sw.Write(contents); sw.Flush(); stream.Position = 0; if (!file.Exists) { //CodeUnit unit1 = null; try { //unit1 = new CodeUnit(file.Name, stream, Log, cgOptions); //String mergedContent = unit1.Generate(); String mergedContent = contents; StreamWriter writer = new StreamWriter(file.FullName, false); writer.Write(mergedContent); writer.Close(); DoPostProcessingNew(file.FullName); return(true); } catch (Exception ex) { Console.Out.WriteLine("Error in File Name " + file.Name); Console.Out.WriteLine(ex); Log.Add("Error in File Name " + file.Name + ":" + ex.ToString()); return(false); } } else { //FileStream fs = null; //CodeUnit unit1 = null; //CodeUnit unit2 = null; try { //fs = file.OpenRead(); //unit1 = new CodeUnit(file.Name, fs, Log, cgOptions); //fs.Close(); //fs = null; //unit2 = new CodeUnit(file.Name, stream, Log, cgOptions); //unit1.Merge(unit2); StreamReader sr = file.OpenText(); String exitingContents = sr.ReadToEnd(); sr.Close(); String mergedContent = NRefactoryUtil.Merge(contents, exitingContents); // determine whether anything has actually changed in the file bool fileHasChanged = false; String mergedContentIgnoreWhitespace = mergedContent.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", ""); String exitingContentsIgnoreWhitespace = exitingContents.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", ""); if (mergedContentIgnoreWhitespace != exitingContentsIgnoreWhitespace) { fileHasChanged = true; } if (fileHasChanged) { // only write out if the formatted contents of both are different (avoids the "DTG reformatting" commit messages, at least some of the time) String fixedFormattingExitingContents = NRefactoryUtil.FixSourceFormatting(exitingContents); String fixedFormattingMergedContents = NRefactoryUtil.FixSourceFormatting(mergedContent); if (!fixedFormattingMergedContents.Equals(fixedFormattingExitingContents)) { // make backup if (file.Exists && backupFilePath != "") { FileInfo backup = new FileInfo(backupFilePath); if (!backup.Directory.Exists) { backup.Directory.Create(); } if (File.Exists(backupFilePath) && (File.GetAttributes(backupFilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(backupFilePath, File.GetAttributes(backupFilePath) ^ FileAttributes.ReadOnly); } file.CopyTo(backupFilePath, true); if ((File.GetAttributes(backupFilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(backupFilePath, File.GetAttributes(backupFilePath) ^ FileAttributes.ReadOnly); } } // Style the contents. string styledContent = styler.Style(mergedContent); DoPreProcessingExisting(file.FullName); StreamWriter writer = new StreamWriter(file.FullName, false); writer.Write(styledContent); writer.Close(); return(true); } } } catch (Exception ex) { Console.Out.WriteLine("Error in File Name " + file.Name); Console.Out.WriteLine(ex); Log.Add("Error in File Name " + file.Name + ":" + ex.ToString()); } finally { //if (fs != null) { // fs.Close(); //} } return(false); } }
/// <summary> /// Write contents to /// </summary> /// <param name="fileName">name of file, including full path</param> /// <param name="text">what to write to the file</param> public Boolean Write(FileInfo file, String text, IStyler styler) { // Create the directory if it doesn't exist. if (!file.Directory.Exists) { file.Directory.Create(); } text.Trim(); Boolean changed = false; // Check that either file does not exist or that it has changed // before writing to the file. This is so that the generated file's // timestamp won't change unless the contents have changed. if (file.Exists) { StreamReader fileReader = file.OpenText(); changed = fileReader.ReadToEnd().Equals(text); } else { changed = true; } Boolean isNewFile = false; // Only write to the file if it has changed or does not exist. if (changed) { // make backup if the file exists if (file.Exists && backupFilePath != "") { DoPreProcessingExisting(file.FullName); FileInfo backup = new FileInfo(backupFilePath); if (!backup.Directory.Exists) { backup.Directory.Create(); } if (File.Exists(backupFilePath) && (File.GetAttributes(backupFilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(backupFilePath, File.GetAttributes(backupFilePath) ^ FileAttributes.ReadOnly); } file.CopyTo(backupFilePath, true); if ((File.GetAttributes(backupFilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(backupFilePath, File.GetAttributes(backupFilePath) ^ FileAttributes.ReadOnly); } } else { isNewFile = true; } // Style the contents text = styler.Style(text); // Write the file. StreamWriter writer = new StreamWriter(file.FullName, false); writer.Write(text); writer.Close(); if (isNewFile) { DoPostProcessingNew(file.FullName); } } return(changed); }
public TestServices With( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func<IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func<Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return new TestServices( assetLoader: assetLoader ?? AssetLoader, focusManager: focusManager ?? FocusManager, inputManager: inputManager ?? InputManager, keyboardDevice: keyboardDevice ?? KeyboardDevice, layoutManager: layoutManager ?? LayoutManager, platformWrapper: platformWrapper ?? PlatformWrapper, renderInterface: renderInterface ?? RenderInterface, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowImpl: windowImpl ?? WindowImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform); }
public static void Set(IStyler styler) { _styler = styler; }
/// <summary> /// Helper method to write generated source to file. Directory will be created if it does not already exist. /// </summary> /// <param name="fileName">name of file, including full path</param> /// <param name="text">what to write to the file</param> /// <param name="append">whether or not or overwrite the file or to append to file</param> public Boolean Write(FileInfo file, String text, IStyler styler) { // Create the directory if it doesn't exist. if (!file.Directory.Exists) { file.Directory.Create(); } text.Trim(); Boolean changed = false; StringWriter regions = new StringWriter(); StringWriter current = new StringWriter(); // Check that either file does not exist or that it has changed // before writing to the file. This is so that the generated file's // timestamp won't change unless the contents have changed. if (file.Exists) { StreamReader fileReader = file.OpenText(); Boolean inRegion = false; String fileLine = fileReader.ReadLine(); while (fileLine != null) { current.WriteLine(fileLine); // Check to see if we have entered a region. inRegion = inRegion || fileLine.Trim().StartsWith(RegionTag); // If we are in a region, save the line. if (inRegion) { regions.WriteLine(fileLine); } // Check to see if we have left a region. inRegion = inRegion && !fileLine.Trim().StartsWith(EndRegionTag); // Read the next line from the file. fileLine = fileReader.ReadLine(); } fileReader.Close(); } // compare the current file text with the text that will be written (merging any existing regions if necessary) String output; if (regions.ToString().Length > 0) { output = MergeRegion(text, regions.ToString()); } else { output = text; } // Style the output string styledOutput = styler.Style(output); // determine whether anything has actually changed in the file bool fileHasChanged = false; String mergedContentIgnoreWhitespace = styledOutput.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", ""); String exitingContentsIgnoreWhitespace = current.GetStringBuilder().ToString().Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", ""); if (mergedContentIgnoreWhitespace != exitingContentsIgnoreWhitespace) { fileHasChanged = true; changed = true; } // Only write to the file if it has changed or does not exist. if (fileHasChanged) { Boolean isNewFile = false; // make a backup of the current file if it exists if (file.Exists && backupFilePath != "") { DoPreProcessingExisting(file.FullName); FileInfo backup = new FileInfo(backupFilePath); if (!backup.Directory.Exists) { backup.Directory.Create(); } if (File.Exists(backupFilePath) && (File.GetAttributes(backupFilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(backupFilePath, File.GetAttributes(backupFilePath) ^ FileAttributes.ReadOnly); } file.CopyTo(backupFilePath, true); if ((File.GetAttributes(backupFilePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(backupFilePath, File.GetAttributes(backupFilePath) ^ FileAttributes.ReadOnly); } } else { isNewFile = true; } // write the new file StreamWriter writer = new StreamWriter(file.FullName, false); writer.Write(styledOutput); writer.Close(); if (isNewFile) { DoPostProcessingNew(file.FullName); } } return(changed); }