Ejemplo n.º 1
0
        public void Run()
        {
            InnerWriter = new LineWriter(new StringWriter());
            Load();
            Convert();
            if (RootNodeTypeName == null)
            {
                RootNodeType     = Classes.First();
                RootNodeTypeName = Classes.First().Name;
            }
            else
            {
                RootNodeType = GetClass(RootNodeTypeName);
            }
            Usings.ForEach(t => WriteLine("using {0};", t));
            WriteLine("namespace {0}", Namespace);
            BeginBlock();

            foreach (var ce in Classes)
            {
                GenerateClass(ce);
            }
            if (GenerateEnum)
            {
                GenerateEnumDecl();
            }
            GenerateVisitorInterfaces();
            EndBlock();
            Output = ((StringWriter)InnerWriter.InnerWriter).GetStringBuilder().ToString();
            if (OutputFilename.IsNotNullOrEmpty())
            {
                File.WriteAllText(OutputFilename, Output);
            }
        }
Ejemplo n.º 2
0
        ///////////////////////
        // Private

        private void ProcessOutFilename(HqlTokenProcessor processor)
        {
            if (OutputFilename == null || OutputFilename.Length == 0)
            {
                throw new Exception("Output filename cannot be empty");
            }
            if (OutputFilename.Contains("{"))
            {
                _output = new HqlOutput(OutputFilename, this);

                int currloc  = 0;
                int startloc = 0;
                for (; ;)
                {
                    bool FoundEndBrace = false;
                    currloc = OutputFilename.IndexOf('{', startloc);
                    if (currloc < 0 || currloc >= OutputFilename.Length)
                    {
                        break;
                    }
                    startloc = currloc;
                    string innerField = String.Empty;
                    for (currloc++; currloc < OutputFilename.Length; currloc++)
                    {
                        if (OutputFilename[currloc] == '}')
                        {
                            // this means that in the string was {} because there is no gap between them for characters
                            if (startloc + 1 == currloc)
                            {
                                throw new Exception(String.Format("Cannot have an empty field in OUTPUT name of |{0}|", OutputFilename));
                            }

                            startloc      = currloc;
                            FoundEndBrace = true;
                            break;
                        }
                        innerField += OutputFilename[currloc];
                    }
                    if (!FoundEndBrace)
                    {
                        throw new Exception(String.Format("Need a closing brace in filename |{0}|", OutputFilename));
                    }

                    HqlTokenProcessor newProcessor = new HqlTokenProcessor(innerField, processor);
                    newProcessor.MoveNextToken();
                    HqlToken token = newProcessor.GetToken();
                    if (token.WordType == HqlWordType.UNKNOWN)
                    {
                        newProcessor.CheckForTokenReference(ref token);
                    }
                    if (token.WordType != HqlWordType.FIELD && token.WordType != HqlWordType.SCALAR)
                    {
                        throw new Exception("Info in braces is not a field");
                    }
                    token.Field.FieldRename = innerField; // set the original name of the field for the {replace}
                    _output.FieldGroup.AddField(token.Field);
                }
            }
        }
Ejemplo n.º 3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var cancelButton = Template.FindName("CancelButton", this) as ImageButton;
            var fileButton = Template.FindName("FileButton", this) as ImageButton;
            var folderButton = Template.FindName("FolderButton", this) as ImageButton;
            var detailsButton = Template.FindName("DetailsButton", this) as ImageButton;
            var copyMenu = Template.FindName("CopyMenuItem", this) as ImageMenuItem;
            var copyImageMenu = Template.FindName("CopyImageMenuItem", this) as ImageMenuItem;
            var copyFilenameMenu = Template.FindName("CopyFilenameMenuItem", this) as ImageMenuItem;
            var copyFolderMenu = Template.FindName("CopyFolderMenuItem", this) as ImageMenuItem;

            if (cancelButton != null)
                cancelButton.Click += (s, a) => RaiseCancelClickedEvent();

            //Open file.
            if (fileButton != null)
                fileButton.Click += (s, a) =>
                {
                    RaiseOpenFileClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && File.Exists(OutputFilename))
                            Process.Start(OutputFilename);
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Open File", "Error while openning the file", ex.Message);
                    }
                };

            //Open folder.
            if (folderButton != null)
                folderButton.Click += (s, a) =>
                {
                    RaiseExploreFolderClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && Directory.Exists(OutputPath))
                            Process.Start("explorer.exe", $"/select,\"{OutputFilename}\"");
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Explore Folder", "Error while openning the folder", ex.Message);
                    }
                };

            //Details. Usually when something wrong happens.
            if (detailsButton != null)
                detailsButton.Click += (s, a) =>
                {
                    if (Exception != null)
                    {
                        var viewer = new ExceptionViewer(Exception);
                        viewer.ShowDialog();
                    }  
                };

            //Copy (as image and text).
            if (copyMenu != null)
                copyMenu.Click += (s, a) => 
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        var data = new DataObject();
                        data.SetImage(OutputFilename.SourceFrom());
                        data.SetText(OutputFilename, TextDataFormat.Text);
                        data.SetFileDropList(new StringCollection { OutputFilename });

                        Clipboard.SetDataObject(data, true);
                    }
                };

            //Copy as image.
            if (copyImageMenu != null)
                copyImageMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                        Clipboard.SetImage(OutputFilename.SourceFrom());
                };

            //Copy full path.
            if (copyFilenameMenu != null)
                copyFilenameMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                        Clipboard.SetText(OutputFilename);
                };

            //Copy folder path.
            if (copyFolderMenu != null)
                copyFolderMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputPath))
                        Clipboard.SetText(OutputPath);
                };
        }
Ejemplo n.º 4
0
 OutputFilename           = EnsureValidExtensionInFilename(OutputFilename, OutputFormat);
Ejemplo n.º 5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var cancelButton     = Template.FindName("CancelButton", this) as ImageButton;
            var fileButton       = Template.FindName("FileButton", this) as ImageButton;
            var folderButton     = Template.FindName("FolderButton", this) as ImageButton;
            var detailsButton    = Template.FindName("DetailsButton", this) as ImageButton;
            var copyMenu         = Template.FindName("CopyMenuItem", this) as ImageMenuItem;
            var copyImageMenu    = Template.FindName("CopyImageMenuItem", this) as ImageMenuItem;
            var copyFilenameMenu = Template.FindName("CopyFilenameMenuItem", this) as ImageMenuItem;
            var copyFolderMenu   = Template.FindName("CopyFolderMenuItem", this) as ImageMenuItem;

            if (cancelButton != null)
            {
                cancelButton.Click += (s, a) => RaiseCancelClickedEvent();
            }

            if (fileButton != null)
            {
                fileButton.Click += (s, a) =>
                {
                    RaiseOpenFileClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && File.Exists(OutputFilename))
                        {
                            Process.Start(OutputFilename);
                        }
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Open File", "Error while openning the file", ex.Message);
                    }
                }
            }
            ;

            if (folderButton != null)
            {
                folderButton.Click += (s, a) =>
                {
                    RaiseExploreFolderClickedEvent();

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(OutputFilename) && Directory.Exists(OutputPath))
                        {
                            Process.Start("explorer.exe", $"/select,\"{OutputFilename}\"");
                        }
                    }
                    catch (Exception ex)
                    {
                        Dialog.Ok("Explore Folder", "Error while openning the folder", ex.Message);
                    }
                }
            }
            ;

            if (detailsButton != null)
            {
                detailsButton.Click += (s, a) =>
                {
                    if (Exception != null)
                    {
                        var viewer = new ExceptionViewer(Exception);
                        viewer.ShowDialog();
                    }
                }
            }
            ;

            if (copyMenu != null)
            {
                copyMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetFileDropList(new StringCollection {
                            OutputFilename
                        });
                    }
                }
            }
            ;

            if (copyImageMenu != null)
            {
                copyImageMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetImage(OutputFilename.SourceFrom());
                    }
                }
            }
            ;

            if (copyFilenameMenu != null)
            {
                copyFilenameMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputFilename))
                    {
                        Clipboard.SetText(OutputFilename);
                    }
                }
            }
            ;

            if (copyFolderMenu != null)
            {
                copyFolderMenu.Click += (s, a) =>
                {
                    if (!string.IsNullOrWhiteSpace(OutputPath))
                    {
                        Clipboard.SetText(OutputPath);
                    }
                }
            }
            ;
        }