예제 #1
0
        /**
         * Called when a file has been added to the Navigator.
         * We look to see if is a Translator source file and
         * is source code file. If it is we will automatically
         * add it to the build list.
         */

        private void NavigatorOnFileAdded(FileInfo fi)
        {
            try
            {
                if (IsFileInSourceFolder(fi))
                {
                    var property = cmbSourceTypes.SelectedValue as string;
                    if (property == null)
                    {
                        throw new Exception("No Selected Source Item");
                    }
                    var sourceFileExtensions = ATMLContext.GetProperty(property) as string;
                    if (sourceFileExtensions == null)
                    {
                        throw new Exception(string.Format("Failed to find property [{0}]", property));
                    }
                    if (sourceFileExtensions.Contains(fi.Extension))
                    {
                        if (!HasFileInBuildList(fi))
                        {
                            var si = new TranslationSourceInfo(fi.Name);
                            _sourceFiles.Add(si);
                            //SaveProjectInfo();
                            SetButtonStates();
                            _bindingSource.ResetBindings(false);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                LogManager.SourceError(ATMLTranslator.SOURCE, err);
            }
        }
예제 #2
0
        private void btnImportDocument_Click(object sender, EventArgs e)
        {
            byte[]   content      = { };
            String   fileName     = "";
            String   extension    = "";
            FileInfo fileInfo     = null;
            string   document_uri = (string)ATMLContext.GetProperty("environment.document-location");

            if (FileManager.OpenFile(out content, out fileInfo))
            {
                fileName  = fileInfo.Name;
                extension = fileInfo.Extension;
                var document = new Document();
                document.DocumentContent = content;
                document.name            = fileName;
                document.uuid            = Guid.NewGuid().ToString();
                document.FileInfo        = fileInfo;
                if (document.ItemElementName == DocumentItemChoiceType.Text)
                {
                    document.Item = Encoding.UTF8.GetString(content);
                }
                else
                {
                    document.Item = document_uri + "?uuid=" + document.uuid;
                }
                legalDocumentsControl.Document = document;
            }
        }
예제 #3
0
 public Document(dbDocument document)
 {
     if (document != null)
     {
         ContentType     = document.contentType;
         name            = document.documentName;
         DocumentContent = document.documentContent;
         if (document.documentTypeId != null)
         {
             DocumentType = (dbDocument.DocumentType)document.documentTypeId;
         }
         Description = document.documentDescription;
         uuid        = document.UUID.ToString();
         version     = document.documentVersion;
         if (document.contentType != null && document.contentType.Contains("text"))
         {
             Item            = Encoding.UTF8.GetString(document.documentContent);
             ItemElementName = DocumentItemChoiceType.Text;
         }
         else
         {
             var document_uri = (string)ATMLContext.GetProperty("environment.document-location");
             Item            = document_uri + "?id=" + uuid;
             ItemElementName = DocumentItemChoiceType.URL;
         }
     }
 }
예제 #4
0
 private void rbURL_CheckedChanged(object sender, EventArgs e)
 {
     //edtItem.ScrollBars = ScrollBars.None;
     //edtItem.Multiline = false;
     lblItem.Text = @"URL";
     if (_document != null)
     {
         var document_uri = (string)ATMLContext.GetProperty("environment.document-location");
         edtItem.Text = document_uri + @"?uuid=" + _document.uuid;
         _document.ItemElementName = DocumentItemChoiceType.URL;
     }
 }
예제 #5
0
        private static void SetPropertyValue(TreeNode node)
        {
            Dictionary <string, PropertyOption> options = node.Tag as Dictionary <string, PropertyOption>;

            if (options != null)
            {
                foreach (PropertyOption option in options.Values)
                {
                    ATMLContext.SetProperty(option.Name, option.Value);
                }
            }
        }
예제 #6
0
 private void SaveContext()
 {
     try
     {
         processTreeNodes(optionTree.Nodes);
         ATMLContext.Save();
     }
     catch (Exception e)
     {
         LogManager.Error(e);
     }
 }
예제 #7
0
        private void btnImportDocument_Click(object sender, EventArgs e)
        {
            byte[]   content          = {};
            String   fileName         = "";
            String   extension        = "";
            String   uuid             = null;
            FileInfo fileInfo         = null;
            var      document_uri     = (string)ATMLContext.GetProperty("environment.document-location");
            Document existingDocument = documentControl.Document;

            if (existingDocument != null)
            {
                uuid = existingDocument.uuid;
            }

            if (FileManager.OpenFile(out content, out fileInfo))
            {
                fileName  = fileInfo.Name;
                extension = fileInfo.Extension;

                var document = new Document();
                document.DocumentContent = content;
                document.name            = fileName;
                document.uuid            = string.IsNullOrEmpty(uuid) ? Guid.NewGuid().ToString() : uuid;
                document.FileInfo        = fileInfo;
                document.ContentType     = DocumentManager.GetContentType(extension);
                if (existingDocument != null)
                {
                    document.Description   = existingDocument.Description;
                    document.DocumentType  = existingDocument.DocumentType;
                    document.controlNumber = existingDocument.controlNumber;
                    document.version       = existingDocument.version;
                }
                if (document.ItemElementName == DocumentItemChoiceType.Text)
                {
                    document.Item = Encoding.UTF8.GetString(content);
                }
                else
                {
                    document.Item = document_uri + "?uuid=" + document.uuid;
                }
                documentControl.Document = document;
                if (document.ItemElementName == DocumentItemChoiceType.Text)
                {
                    documentControl.UpdateContent(Encoding.UTF8.GetString(content));
                }
            }
        }
예제 #8
0
        private static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                CreateSplashScreen();

                var worker = new Worker();
                worker.ProgressUpdate += worker_ProgressUpdate;
                _splashScreen.UpdateProgress("Loading Framework");
                var mainFrame = new MainFrame();
                mainFrame.Closing += new System.ComponentModel.CancelEventHandler(mainFrame_Closing);
                _splashScreen.UpdateProgress("Initializing Context");
                ATMLContext.Initialize();
                var tr = new Thread(worker.DoWork);
                tr.Start();
                Application.Run(mainFrame);
            }
            catch (Exception e)
            {
                try
                {
                    Program.SplashScreen.Completed = true;
                    MessageBox.Show(e.Message + Resources.CRLF + e.StackTrace);
                    LogManager.Error(e);
                    //ATMLErrorForm.ShowError(e);
                }
                catch (Exception ee)
                {
                    LogManager.Error(ee);
                }
                Application.Exit();
            }
        }
 private void SetProperties()
 {
     if (targetEditor.Focused)
     {
         testConfigToolStrip.BackColor = (Color)ATMLContext.GetProperty("environment.visual.tool.active.gr2-color", Color.DarkSlateGray);
         testConfigToolStrip.ForeColor = (Color)ATMLContext.GetProperty("environment.visual.tool.active.text-color", Color.White);
         sourceCodeToolStrip.BackColor = Color.WhiteSmoke;
         sourceCodeToolStrip.ForeColor = Color.Black;
     }
     else if (sourceEditor.Focused)
     {
         sourceCodeToolStrip.BackColor = (Color)ATMLContext.GetProperty("environment.visual.tool.active.gr2-color", Color.DarkSlateGray);
         lblSourceFileName.ForeColor   = sourceCodeToolStrip.ForeColor = (Color)ATMLContext.GetProperty("environment.visual.tool.active.text-color", Color.White);
         testConfigToolStrip.BackColor = Color.WhiteSmoke;
         testConfigToolStrip.ForeColor = Color.Black;
     }
     else
     {
         testConfigToolStrip.BackColor = Color.WhiteSmoke;
         testConfigToolStrip.ForeColor = Color.Black;
         sourceCodeToolStrip.BackColor = Color.WhiteSmoke;
         sourceCodeToolStrip.ForeColor = Color.Black;
     }
 }
예제 #10
0
        public void Open(string fileName, string fileExtension, byte[] content)
        {
            _fileExtension = fileExtension;
            _fileName      = fileName;
            _content       = content;

            var encoding = new UTF8Encoding();

            const String sMSG_NOPREVIEW =
                "<h3 style=\"color:red;\" >Preview reader is unavailable for this file type.</h3>";
            const String sMSG_CANNOT_PREVIEW = "<h3 style=\"color:red;\" >Unable to preview this document.</h3>";
            const String sMSG_NO_LOCAL       =
                "<h3 style=\"color:red;\" >You must have a local copy of this file to preview it.</h3>";
            //Need to use active document

            //String extension = fi.Extension.ToLower().Trim();
            var sourceTypes    = (String)ATMLContext.GetProperty("environment.source.filetypes");
            var browserTypes   = (String)ATMLContext.GetProperty("environment.browser.filetypes");
            var supportedTypes = (String)ATMLContext.GetProperty("environment.supported.filetypes");

            try
            {
                //if( string.IsNullOrEmpty( sourceTypes ) || )


                string extension = fileExtension.ToLower();
                if (!supportedTypes.Contains(extension))
                {
                    PreviewHtml(
                        encoding.GetBytes(sMSG_NOPREVIEW + "<br />" + extension +
                                          " file types are not supported at this time."));
                }
                else
                {
                    String tempFileName = fileName;

                    if (sourceTypes.Contains(extension))
                    {
                        sourcePreviewer.ConfigurationManager.Language = extension.Substring(1);
                        PreviewSource(encoding.GetString(content), extension);
                    }
                    else
                    {
                        if (webBrowser.Document != null)
                        {
                            webBrowser.Document.OpenNew(true);
                        }
                        webBrowser.Navigate("about:blank");

                        try
                        {
                            using (new HourGlass())
                            {
                                Guid guid = GetPreviewHandlerGUID(fileName);
                                if (browserTypes.Contains(extension))
                                {
                                    PreviewHtml(tempFileName);
                                }
                                else if (UTRSOfficeUtils.IsInstalled(UTRSOfficeUtils.MSOfficeApplications.Word) &&
                                         UTRSOfficeUtils.IsWordDocument(extension))
                                {
                                    PreviewHtml(UTRSOfficeUtils.OfficeDocToHtml(fileName,
                                                                                UTRSOfficeUtils.MSOfficeApplications
                                                                                .Word));
                                }
                                else if (UTRSOfficeUtils.IsInstalled(UTRSOfficeUtils.MSOfficeApplications.Excel) &&
                                         UTRSOfficeUtils.IsExcelDocument(extension))
                                {
                                    PreviewHtml(UTRSOfficeUtils.OfficeDocToHtml(fileName,
                                                                                UTRSOfficeUtils.MSOfficeApplications
                                                                                .Excel));
                                }
                                else if (UTRSOfficeUtils.IsInstalled(UTRSOfficeUtils.MSOfficeApplications.PowerPoint) &&
                                         UTRSOfficeUtils.IsPowerPointDocument(extension))
                                {
                                    PreviewHtml(UTRSOfficeUtils.OfficeDocToHtml(fileName,
                                                                                UTRSOfficeUtils.MSOfficeApplications
                                                                                .PowerPoint));
                                }
                                else if (guid != Guid.Empty)
                                {
                                    PreView(guid, tempFileName);
                                }
                                else
                                {
                                    PreviewHtml(
                                        encoding.GetBytes(sMSG_NOPREVIEW +
                                                          "<br />Could not find a preview handler for " +
                                                          extension));
                                }
                            }
                        }
                        catch (Exception ee)
                        {
                            LogManager.Error(ee, sMSG_CANNOT_PREVIEW);
                            PreviewHtml(
                                encoding.GetBytes(sMSG_CANNOT_PREVIEW +
                                                  "<br />An error has occurred attempting to preview this document: <br />" +
                                                  ee.Message));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogManager.Error(e, "Failed to open preview for file {0} ", fileName);
                LogManager.Debug(
                    "Error opening Preview. Data Dump:\n File Name: {0}{1}\nSource Types:{2}\nBrowser Types:{3}\nSupported Type:{4}\nStack Trace:\n{5}",
                    fileName, fileExtension, sourceTypes, browserTypes, supportedTypes, e.StackTrace);
            }
            Cursor = Cursors.Default;
        }
예제 #11
0
 private void ATMLNavigationWindow_HelpRequested(object sender, HelpEventArgs hlpevent)
 {
     ATMLContext.ShowHelp(this, "Project Navigator");
 }
예제 #12
0
 private bool LogDebugMessages()
 {
     return((bool)ATMLContext.GetProperty("logging.debug.messages", false));
 }
예제 #13
0
 private bool LogToFile()
 {
     return((bool)ATMLContext.GetProperty("logging.log.file", false));
 }
예제 #14
0
        public void Parse()
        {
            try
            {
                ProjectInfo pi = ProjectManager.ProjectInfo;
                if (pi == null || pi.TranslationInfo == null)
                {
                    throw new TranslationException("Failed to obtain the Translation Configuration");
                }

                bool   isSegmented = pi.TranslationInfo.Segmented;
                string atlasPath   = GetAtlasParserDirectory();
                string projectName = pi.ProjectName;
                string projectId   = pi.Uuid;
                string uutName     = pi.UutName;
                string uutId       = pi.UutId;
                string testStation = pi.ClassName;
                string inputFile   = isSegmented ? pi.TranslationInfo.SourcesAsAstring : pi.TranslationInfo.PrimaryFile;

                if (string.IsNullOrEmpty(testStation))
                {
                    throw new TranslationException("You must select a Test Station in the Translator Configuration.");
                }

                if (string.IsNullOrEmpty(uutId))
                {
                    throw new TranslationException("You must select a UUT.");
                }

                if (string.IsNullOrEmpty(uutName))
                {
                    throw new TranslationException("You must select a UUT.");
                }

                var atlasFile =
                    (String)ATMLContext.GetProperty("translator.atlas.parser.application-file", "catlas2aixml.exe");
                atlasFile = Path.Combine(atlasPath, atlasFile);

                if (!File.Exists(atlasFile))
                {
                    throw new TranslationException(String.Format("Failed to find the ATLAS Parsing Application ({0})", atlasFile));
                }

                //if (_sourceFileInfo == null)
                //    throw new Exception( "The source file is missing." );

                _exeProcess = new Process();
                string xmlPath       = ATMLContext.ProjectTranslatorAixmlPath;
                string projectPath   = Path.Combine(ATMLContext.TESTSET_PATH, ProjectManager.ProjectName);
                string sourcePath    = ATMLContext.ProjectTranslatorSourcePath;
                string aixmlFileName = Path.Combine(xmlPath, projectName + ".aixml.xml");
                LogManager.Debug("Obtained Translator Configuration.");
                //string fileName = _sourceFileInfo.Name;

                if (sourcePath == null)
                {
                    throw new TranslationException("Missing Translator Source Path.");
                }

                var args = new StringBuilder();
                args.Append("\"input_files=").Append(inputFile).Append("\" ");
                args.Append("\"test_station=").Append(testStation).Append("\" ");
                args.Append("\"uut_name=").Append(uutName).Append("\" ");
                args.Append("\"uut_id=").Append(uutId).Append("\" ");
                args.Append("\"project_name=").Append(projectName).Append("\" ");
                args.Append("\"output_directory=").Append(xmlPath).Append("\" ");
                args.Append("\"input_directory=").Append(sourcePath).Append("\" ");
                args.Append("\"console_html=").Append("yes").Append("\" ");
                args.Append("\"proc_hier=").Append("yes").Append("\" ");

                LogManager.Debug("Obtained Parser Arguments.");
                LogManager.Debug("Executing parser \"{0}\" [{1}] on {2}", atlasFile, args.ToString(),
                                 inputFile);
                LogManager.SourceTrace(ATMLTranslator.SOURCE, "Parsing ATLAS Source Files...");

                ProcessStartInfo startInfo = _exeProcess.StartInfo;
                startInfo.CreateNoWindow         = false;
                startInfo.UseShellExecute        = false;
                startInfo.WorkingDirectory       = sourcePath;
                startInfo.FileName               = atlasFile;
                startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                startInfo.Arguments              = args.ToString();
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardInput  = true;
                startInfo.RedirectStandardError  = true;
                startInfo.CreateNoWindow         = true;

                _exeProcess.EnableRaisingEvents = true;
                _exeProcess.OutputDataReceived += exeProcess_OutputDataReceived;
                _exeProcess.ErrorDataReceived  += exeProcess_ErrorDataReceived;
                _exeProcess.Exited += delegate(object sender, EventArgs eventArgs)
                {
                    FileInfo fileInfo = null;
                    if (_exeProcess != null)
                    {
                        int errorCode = _exeProcess.ExitCode;
                        if (errorCode > 0)
                        {
                            LogManager.SourceError(ATMLTranslator.SOURCE,
                                                   "The ATLAS Parser has Failed.");
                        }
                        else
                        {
                            LogManager.SourceInfo(ATMLTranslator.SOURCE,
                                                  "The ATLAS Parser has Successfully Completed.");
                            fileInfo = new FileInfo(aixmlFileName);
                        }
                    }
                    //Always call OnParsed to clear parsing states.
                    OnParsed(fileInfo);
                    _exeProcess.Close();
                };

                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                _exeProcess.Start();

                var sb = new StringBuilder();
                using (StreamReader stdOut = _exeProcess.StandardOutput)
                {
                    do
                    {
                        sb.Append(stdOut.ReadLine());
                    } while (!stdOut.EndOfStream); //Loops until the stream ends
                    LogManager.SourceTrace(ATMLTranslator.SOURCE, sb.ToString());
                }
            }
            catch (TranslationException err)
            {
                OnParsed(null);
                LogManager.SourceError(ATMLTranslator.SOURCE, err.Message);
            }
            catch (Exception err)
            {
                OnParsed(null);
                LogManager.SourceError(ATMLTranslator.SOURCE, err);
            }
            finally
            {
            }
        }
예제 #15
0
        private void ProcessOption(XmlElement parentElement, TreeNode parentTreeNode, Dictionary <String, PropertyOption> options)
        {
            foreach (XmlNode child in parentElement.ChildNodes)
            {
                var element = child as XmlElement;
                if (element != null)
                {
                    if ("option".Equals(child.Name))
                    {
                        string name = element.GetAttribute("name");
                        var    node = new TreeNode(name);
                        node.SelectedImageIndex =
                            node.ImageIndex     = int.Parse(element.GetAttribute("imageId"));
                        if (parentTreeNode == null)
                        {
                            optionTree.Nodes.Add(node);
                        }
                        else
                        {
                            parentTreeNode.Nodes.Add(node);
                        }
                        PropertyOption option = null;
                        if (options.ContainsKey(name))
                        {
                            option = options[name];
                        }
                        else
                        {
                            option = new PropertyOption(name);
                            options.Add(name, option);
                        }
                        try
                        {
                            ProcessOption(element, node, option.Options);
                        }
                        catch (Exception)
                        {
                            int i = 0;
                        }
                    }
                    else if ("controls".Equals(child.Name))
                    {
                        var properties = new Dictionary <string, PropertyOption>();
                        foreach (XmlNode control in element.ChildNodes)
                        {
                            var xmlElement = control as XmlElement;
                            if (xmlElement != null)
                            {
                                string _label       = xmlElement.GetAttribute("label");
                                string _name        = xmlElement.GetAttribute("name");
                                string _default     = xmlElement.GetAttribute("default");
                                string _class       = xmlElement.GetAttribute("class");
                                string _description = xmlElement.GetAttribute("description");
                                string _category    = xmlElement.GetAttribute("category");
                                object _value       = ATMLContext.GetProperty(_name);

                                if (!string.IsNullOrEmpty(_class))
                                {
                                    if (_value == null)
                                    {
                                        _value = "String".Equals(_class)
                                                ? _default
                                                : "double".Equals(_class)
                                                ? double.Parse(_default)
                                                : "int".Equals(_class)
                                                ? int.Parse(_default)
                                                : "Int32".Equals(_class)
                                                ? Int32.Parse(_default)
                                                : "Boolean".Equals(_class)
                                                ? "1" == _default
                                                : "Color".Equals(_class)
                                                ? ColorTranslator.FromHtml(_default)
                                                : Activator.CreateInstance(Type.GetType(_class));
                                    }
                                    PropertyOption option = null;
                                    if (options.ContainsKey(_name))
                                    {
                                        option = options[_name];
                                    }
                                    else
                                    {
                                        option             = new PropertyOption(_name);
                                        option.Description = _description;
                                        option.Category    = _category;
                                        option.Label       = _label;
                                        options.Add(_name, option);
                                    }
                                    option.Value = _value;
                                    properties.Add(_name, option);
                                }
                            }
                        }
                        if (parentTreeNode != null)
                        {
                            parentTreeNode.Tag = properties;
                        }
                    }
                }
            }
        }
예제 #16
0
 private void ATMLForm_HelpRequested(object sender, HelpEventArgs hlpevent)
 {
     ATMLContext.ShowHelp(this, Text);
 }