예제 #1
0
 /// <summary>
 /// Forward the sub console window output to the message output
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
 {
     if (_output != null)
     {
         _output.WriteLine(e.Data);
     }
 }
예제 #2
0
        public byte[] CreateRibbon(Target element, string resourceName)
        {
            string localizedRibbonXmlFilename = null;

            CleanupFiles.Clear();

            RibbonCompiler compiler = new RibbonCompiler(this);

            try
            {
                // use the following format to specify localization info {Resource:key}
                localizedRibbonXmlFilename = LocalizeRibbon(element);
                string ribbonDll = null;
                byte[] result;

                RibbonCompileResult compileResult = compiler.Compile(localizedRibbonXmlFilename, resourceName);
                if (compileResult == RibbonCompileResult.Ok)
                {
                    ribbonDll = compiler.RibbonDll;
                    result    = File.ReadAllBytes(ribbonDll);
                }
                else
                {
                    Util.LogMessage("Error: " + compileResult.ToString());
                    result = new byte[0];
                }
                for (int i = 0; i < compiler.Messages.Count; i++)
                {
                    if (!string.IsNullOrEmpty(compiler.Messages[i]))
                    {
                        _output.WriteLine(compiler.Messages[i]);
                    }
                }
                Util.LogMessage("Manager.CreateRibbon returns {0} bytes for file '{1}'", result.Length, ribbonDll);
                return(result);
            }
            catch (Exception ex)
            {
                for (int i = 0; i < compiler.Messages.Count; i++)
                {
                    if (!string.IsNullOrEmpty(compiler.Messages[i]))
                    {
                        _output.WriteLine(compiler.Messages[i]);
                    }
                }
                Util.LogError(ex);
                throw;
            }
            finally
            {
                Cleanup();
                if (localizedRibbonXmlFilename != null)
                {
                    string firstExtensionExcluded = Path.GetFileNameWithoutExtension(localizedRibbonXmlFilename);
                    string dotCulture             = Path.GetExtension(firstExtensionExcluded);
                    if (!string.IsNullOrEmpty(dotCulture) && dotCulture.Equals(".default", StringComparison.OrdinalIgnoreCase))
                    {
                        string defaultH = Path.ChangeExtension(localizedRibbonXmlFilename, ".h");
                        if (File.Exists(defaultH))
                        {
                            string neutralHFile = Path.Combine(Path.GetDirectoryName(localizedRibbonXmlFilename), Path.ChangeExtension(firstExtensionExcluded, ".h"));
                            File.Delete(neutralHFile);
                            File.Move(defaultH, neutralHFile); // rename *.default.h to *.h
                        }
                        string defaultRes = Path.ChangeExtension(localizedRibbonXmlFilename, ".res");
                        if (File.Exists(defaultRes))
                        {
                            string neutralResFile = Path.Combine(Path.GetDirectoryName(localizedRibbonXmlFilename), Path.ChangeExtension(firstExtensionExcluded, ".res"));
                            File.Delete(neutralResFile);
                            File.Move(defaultRes, neutralResFile); // rename *.default.res to *.res
                        }
                    }
                }
            }
        }