当前位置: 首页>>代码示例>>C#>>正文


C# IMessageHandler.OnMessage方法代码示例

本文整理汇总了C#中IMessageHandler.OnMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageHandler.OnMessage方法的具体用法?C# IMessageHandler.OnMessage怎么用?C# IMessageHandler.OnMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessageHandler的用法示例。


在下文中一共展示了IMessageHandler.OnMessage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToIdtDefinition

        /// <summary>
        /// Returns the table in a format usable in IDT files.
        /// </summary>
        /// <param name="keepAddedColumns">Whether to keep columns added in a transform.</param>
        /// <returns>null if OutputTable is unreal, or string with tab delimited field values otherwise</returns>
        internal void ToIdtDefinition(StreamWriter writer, IMessageHandler messageHandler, bool keepAddedColumns)
        {
            string rowString = String.Empty;
            byte[] rowBytes = {};
            // Create a new encoding that replaces characters with question marks, and doesn't throw, used in case of errors
            Encoding convertEncoding = Encoding.GetEncoding(writer.Encoding.CodePage);

            if (this.tableDefinition.IsUnreal)
            {
                return;
            }

            if (TableDefinition.MaxColumnsInRealTable < this.tableDefinition.Columns.Count)
            {
                throw new WixException(WixErrors.TooManyColumnsInRealTable(this.tableDefinition.Name, this.tableDefinition.Columns.Count, TableDefinition.MaxColumnsInRealTable));
            }

            // tack on the table header, and flush before we start writing bytes directly to the stream
            writer.Write(this.tableDefinition.ToIdtDefinition(keepAddedColumns));
            writer.Flush();

            BufferedStream buffStream = new BufferedStream(writer.BaseStream);

            foreach (Row row in this.rows)
            {
                rowString = row.ToIdtDefinition(keepAddedColumns);

                try
                {
                    // GetBytes will throw an exception if any character doesn't match our current encoding
                    rowBytes = writer.Encoding.GetBytes(rowString);
                }
                catch (EncoderFallbackException)
                {
                    rowBytes = convertEncoding.GetBytes(rowString);

                    messageHandler.OnMessage(WixErrors.InvalidStringForCodepage(row.SourceLineNumbers, Convert.ToString(writer.Encoding.WindowsCodePage, CultureInfo.InvariantCulture)));
                }

                buffStream.Write(rowBytes, 0, rowBytes.Length);
            }

            buffStream.Flush();
        }
开发者ID:zooba,项目名称:wix3,代码行数:49,代码来源:Table.cs

示例2: FindEntrySectionAndLoadSymbols

        /// <summary>
        /// Finds the entry section and loads the symbols from an array of intermediates.
        /// </summary>
        /// <param name="allowIdenticalRows">Flag specifying whether identical rows are allowed or not.</param>
        /// <param name="messageHandler">Message handler object to route all errors through.</param>
        /// <param name="expectedOutputType">Expected entry output type, based on output file extension provided to the linker.</param>
        /// <param name="entrySection">Located entry section.</param>
        /// <param name="allSymbols">Collection of symbols loaded.</param>
        internal void FindEntrySectionAndLoadSymbols(
            bool allowIdenticalRows,
            IMessageHandler messageHandler,
            OutputType expectedOutputType,
            out Section entrySection,
            out SymbolCollection allSymbols)
        {
            entrySection = null;
            allSymbols = new SymbolCollection();

            string outputExtension = Output.GetExtension(expectedOutputType);
            SectionType expectedEntrySectionType;
            try
            {
                expectedEntrySectionType = (SectionType)Enum.Parse(typeof(SectionType), expectedOutputType.ToString());
            }
            catch (ArgumentException)
            {
                expectedEntrySectionType = SectionType.Unknown;
            }

            foreach (Section section in this.collection.Keys)
            {
                if (SectionType.Product == section.Type || SectionType.Module == section.Type || SectionType.PatchCreation == section.Type || SectionType.Patch == section.Type || SectionType.Bundle == section.Type)
                {
                    if (SectionType.Unknown != expectedEntrySectionType && section.Type != expectedEntrySectionType)
                    {
                        messageHandler.OnMessage(WixWarnings.UnexpectedEntrySection(section.SourceLineNumbers, section.Type.ToString(), expectedEntrySectionType.ToString(), outputExtension));
                    }

                    if (null == entrySection)
                    {
                        entrySection = section;
                    }
                    else
                    {
                        messageHandler.OnMessage(WixErrors.MultipleEntrySections(entrySection.SourceLineNumbers, entrySection.Id, section.Id));
                        messageHandler.OnMessage(WixErrors.MultipleEntrySections2(section.SourceLineNumbers));
                    }
                }

                foreach (Symbol symbol in section.GetSymbols(messageHandler))
                {
                    try
                    {
                        Symbol existingSymbol = allSymbols[symbol.Name];
                        if (null == existingSymbol)
                        {
                            allSymbols.Add(symbol);
                        }
                        else if (allowIdenticalRows && existingSymbol.Row.IsIdentical(symbol.Row))
                        {
                            messageHandler.OnMessage(WixWarnings.IdenticalRowWarning(symbol.Row.SourceLineNumbers, existingSymbol.Name));
                            messageHandler.OnMessage(WixWarnings.IdenticalRowWarning2(existingSymbol.Row.SourceLineNumbers));
                        }
                        else
                        {
                            allSymbols.AddDuplicate(symbol);
                        }
                    }
                    catch (DuplicateSymbolsException)
                    {
                        // if there is already a duplicate symbol, just
                        // another to the list, don't bother trying to
                        // see if there are any identical symbols
                        allSymbols.AddDuplicate(symbol);
                    }
                }
            }
        }
开发者ID:bullshock29,项目名称:Wix3.6Toolset,代码行数:78,代码来源:SectionCollection.cs

示例3: DeleteTempFiles

        /// <summary>
        /// Cleans up the temp files.
        /// </summary>
        /// <param name="path">The temporary directory to delete.</param>
        /// <param name="messageHandler">The message handler.</param>
        /// <returns>True if all files were deleted, false otherwise.</returns>
        internal static bool DeleteTempFiles(string path, IMessageHandler messageHandler)
        {
            // try three times and give up with a warning if the temp files aren't gone by then
            int retryLimit = 3;
            bool removedReadOnly = false;

            for (int i = 0; i < retryLimit; i++)
            {
                try
                {
                    Directory.Delete(path, true);   // toast the whole temp directory
                    break; // no exception means we got success the first time
                }
                catch (UnauthorizedAccessException)
                {
                    if (!removedReadOnly) // should only need to unmark readonly once - there's no point in doing it again and again
                    {
                        removedReadOnly = true;
                        RecursiveFileAttributes(path, FileAttributes.ReadOnly, false, messageHandler); // toasting will fail if any files are read-only. Try changing them to not be.
                    }
                    else
                    {
                        messageHandler.OnMessage(WixWarnings.AccessDeniedForDeletion(null, path));
                        return false;
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    // if the path doesn't exist, then there is nothing for us to worry about
                    break;
                }
                catch (IOException) // directory in use
                {
                    if (i == (retryLimit - 1)) // last try failed still, give up
                    {
                        messageHandler.OnMessage(WixWarnings.DirectoryInUse(null, path));
                        return false;
                    }
                    System.Threading.Thread.Sleep(300);  // sleep a bit before trying again
                }
            }

            return true;
        }
开发者ID:zooba,项目名称:wix3,代码行数:50,代码来源:Common.cs

示例4: RecursiveFileAttributes

        /// <summary>
        /// Recursively loops through a directory, changing an attribute on all of the underlying files.
        /// An example is to add/remove the ReadOnly flag from each file.
        /// </summary>
        /// <param name="path">The directory path to start deleting from.</param>
        /// <param name="fileAttribute">The FileAttribute to change on each file.</param>
        /// <param name="messageHandler">The message handler.</param>
        /// <param name="markAttribute">If true, add the attribute to each file. If false, remove it.</param>
        private static void RecursiveFileAttributes(string path, FileAttributes fileAttribute, bool markAttribute, IMessageHandler messageHandler)
        {
            foreach (string subDirectory in Directory.GetDirectories(path))
            {
                RecursiveFileAttributes(subDirectory, fileAttribute, markAttribute, messageHandler);
            }

            foreach (string filePath in Directory.GetFiles(path))
            {
                FileAttributes attributes = File.GetAttributes(filePath);
                if (markAttribute)
                {
                    attributes = attributes | fileAttribute; // add to list of attributes
                }
                else if (fileAttribute == (attributes & fileAttribute)) // if attribute set
                {
                    attributes = attributes ^ fileAttribute; // remove from list of attributes
                }

                try
                {
                    File.SetAttributes(filePath, attributes);
                }
                catch (UnauthorizedAccessException)
                {
                    messageHandler.OnMessage(WixWarnings.AccessDeniedForSettingAttributes(null, filePath));
                }
            }
        }
开发者ID:zooba,项目名称:wix3,代码行数:37,代码来源:Common.cs

示例5: GetSymbolForSimpleReference

        /// <summary>
        /// Gets the symbol for a reference.
        /// </summary>
        /// <param name="wixSimpleReferenceRow">Simple references to resolve.</param>
        /// <param name="messageHandler">Message handler to report errors through.</param>
        /// <returns>Symbol if it was found or null if the symbol was not specified.</returns>
        internal Symbol GetSymbolForSimpleReference(WixSimpleReferenceRow wixSimpleReferenceRow, IMessageHandler messageHandler)
        {
            Symbol symbol = null;

            try
            {
                symbol = this[wixSimpleReferenceRow.SymbolicName];
            }
            catch (DuplicateSymbolsException e)
            {
                Hashtable uniqueSourceLineNumbers = new Hashtable();
                Symbol[] duplicateSymbols = e.GetDuplicateSymbols();
                Debug.Assert(1 < duplicateSymbols.Length);

                // index the row source line numbers to determine how many are unique
                foreach (Symbol duplicateSymbol in duplicateSymbols)
                {
                    if (null != duplicateSymbol.Row && null != duplicateSymbol.Row.SourceLineNumbers)
                    {
                        uniqueSourceLineNumbers[duplicateSymbol.Row.SourceLineNumbers] = null;
                    }
                }

                // if only 1 unique source line number was found, switch to the section source line numbers
                // (sections use the file name of the intermediate, library, or extension they came from)
                if (1 >= uniqueSourceLineNumbers.Count)
                {
                    uniqueSourceLineNumbers.Clear();

                    foreach (Symbol duplicateSymbol in duplicateSymbols)
                    {
                        if (null != duplicateSymbol.Section.SourceLineNumbers)
                        {
                            uniqueSourceLineNumbers[duplicateSymbol.Section.SourceLineNumbers] = null;
                        }
                    }
                }

                // display errors for the unique source line numbers
                bool displayedFirstError = false;
                foreach (SourceLineNumberCollection sourceLineNumbers in uniqueSourceLineNumbers.Keys)
                {
                    if (!displayedFirstError)
                    {
                        messageHandler.OnMessage(WixErrors.DuplicateSymbol(sourceLineNumbers, duplicateSymbols[0].Name));
                        displayedFirstError = true;
                    }
                    else
                    {
                        messageHandler.OnMessage(WixErrors.DuplicateSymbol2(sourceLineNumbers));
                    }
                }

                // display an error, even if no source line information was found
                if (!displayedFirstError)
                {
                    messageHandler.OnMessage(WixErrors.DuplicateSymbol(null, duplicateSymbols[0].Name));
                }
            }

            return symbol;
        }
开发者ID:zooba,项目名称:wix3,代码行数:68,代码来源:SymbolCollection.cs

示例6: GetSymbolForReference

        /// <summary>
        /// Gets the symbol for a reference.
        /// </summary>
        /// <param name="section">Section that contains references to resolve.</param>
        /// <param name="reference">References to resolve.</param>
        /// <param name="allSymbols">Collection of all symbols from loaded intermediates.</param>
        /// <param name="referencedSymbols">Collection of all symbols referenced during linking.</param>
        /// <param name="unresolvedReferences">Unresolved references.</param>
        /// <param name="messageHandler">Message handler to report errors through.</param>
        /// <returns>Symbol it it was found or null if the symbol was not specified.</returns>
        internal static Symbol GetSymbolForReference(
			Section section,
			Reference reference,
			SymbolCollection allSymbols,
			StringCollection referencedSymbols,
			ArrayList unresolvedReferences,
			IMessageHandler messageHandler)
        {
            Symbol symbol = null;
            try
            {
                symbol = allSymbols[reference.SymbolicName];
                if (null == symbol)
                {
                    unresolvedReferences.Add(new ReferenceSection(section, reference));
                }
                else
                {
                    // components are indexed in ResolveComplexReferences
                    if (null != symbol.TableName && "Component" != symbol.TableName && !referencedSymbols.Contains(symbol.Name))
                    {
                        referencedSymbols.Add(symbol.Name);
                    }
                }
            }
            catch (DuplicateSymbolsException e)
            {
                Symbol[] symbols = e.GetDuplicateSymbols();
                Debug.Assert(1 < symbols.Length);

                messageHandler.OnMessage(WixErrors.DuplicateSymbol((null != symbols[0].Row ? symbols[0].Row.SourceLineNumbers : null), symbols[0].Name));
                for (int i = 1; i < symbols.Length; ++i)
                {
                    if (null != symbols[i].Row && null != symbols[i].Row.SourceLineNumbers)
                    {
                        messageHandler.OnMessage(WixErrors.DuplicateSymbol2(symbols[i].Row.SourceLineNumbers));
                    }
                }
            }

            return symbol;
        }
开发者ID:sillsdev,项目名称:FwSupportTools,代码行数:52,代码来源:Common.cs

示例7: FindEntrySectionAndLoadSymbols

        /// <summary>
        /// Finds the entry section and loads the symbols from an array of intermediates.
        /// </summary>
        /// <param name="intermediates">Array of intermediates to load symbols for and find entry section.</param>
        /// <param name="allowIdenticalRows">Flag specifying whether identical rows are allowed or not.</param>
        /// <param name="messageHandler">Message handler object to route all errors through.</param>
        /// <param name="entrySection">Located entry section.</param>
        /// <param name="allSymbols">Collection of symbols loaded.</param>
        internal static void FindEntrySectionAndLoadSymbols(
			Intermediate[] intermediates,
			bool allowIdenticalRows,
			IMessageHandler messageHandler,
			out Section entrySection,
			out SymbolCollection allSymbols)
        {
            entrySection = null;
            allSymbols = new SymbolCollection();

            for (int i = 0; i < intermediates.Length; ++i)
            {
                foreach (Section section in intermediates[i].Sections)
                {
                    if (SectionType.Product == section.Type || SectionType.Module == section.Type || SectionType.PatchCreation == section.Type)
                    {
                        if (null == entrySection)
                        {
                            entrySection = section;
                        }
                        else
                        {
                            messageHandler.OnMessage(WixErrors.MultipleEntrySections(SourceLineNumberCollection.FromFileName(entrySection.Intermediate.SourcePath), entrySection.Id, section.Id));
                            messageHandler.OnMessage(WixErrors.MultipleEntrySections2(SourceLineNumberCollection.FromFileName(section.Intermediate.SourcePath)));
                        }
                    }

                    foreach (Symbol symbol in section.GetSymbols(messageHandler))
                    {
                        try
                        {
                            Symbol existingSymbol = allSymbols[symbol.Name];
                            if (null == existingSymbol)
                            {
                                allSymbols.Add(symbol);
                            }
                            else if (allowIdenticalRows && existingSymbol.Row.IsIdentical(symbol.Row))
                            {
                                messageHandler.OnMessage(WixWarnings.IdenticalRowWarning(symbol.Row.SourceLineNumbers, existingSymbol.Name));
                                messageHandler.OnMessage(WixWarnings.IdenticalRowWarning2(existingSymbol.Row.SourceLineNumbers));
                            }
                            else
                            {
                                allSymbols.AddDuplicate(symbol);
                            }
                        }
                        catch (DuplicateSymbolsException)
                        {
                            // if there is already a duplicate symbol, just
                            // another to the list, don't bother trying to
                            // see if there are any identical symbols
                            allSymbols.AddDuplicate(symbol);
                        }
                    }
                }
            }
        }
开发者ID:sillsdev,项目名称:FwSupportTools,代码行数:65,代码来源:Common.cs

示例8: GetSymbols

        /// <summary>
        /// Gets the symbols for this section.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <returns>Collection of symbols for this section.</returns>
        internal SymbolCollection GetSymbols(IMessageHandler messageHandler)
        {
            if (null == this.symbols)
            {
                this.symbols = new SymbolCollection();

                // add a symbol for this section
                if (null != this.id)
                {
                    this.symbols.Add(new Symbol(this, this.type.ToString(), this.id));
                }
                else
                {
                    Debug.Assert(SectionType.Fragment == this.type, "Only Fragment sections can have a null Id.");
                }

                foreach (Table table in this.tables)
                {
                    foreach (Row row in table.Rows)
                    {
                        Symbol symbol = row.Symbol;
                        if (null != symbol)
                        {
                            try
                            {
                                this.symbols.Add(symbol);
                            }
                            catch (ArgumentException)
                            {
                                Symbol existingSymbol = this.symbols[symbol.Name];

                                messageHandler.OnMessage(WixErrors.DuplicateSymbol(existingSymbol.Row.SourceLineNumbers, existingSymbol.Name));
                                messageHandler.OnMessage(WixErrors.DuplicateSymbol2(symbol.Row.SourceLineNumbers));
                            }
                        }
                    }
                }
            }

            return this.symbols;
        }
开发者ID:sillsdev,项目名称:FwSupportTools,代码行数:46,代码来源:Section.cs

示例9: GetSymbols

        /// <summary>
        /// Gets the symbols for this section.
        /// </summary>
        /// <param name="messageHandler">The message handler.</param>
        /// <returns>Collection of symbols for this section.</returns>
        internal SymbolCollection GetSymbols(IMessageHandler messageHandler)
        {
            if (null == this.symbols)
            {
                this.symbols = new SymbolCollection();

                foreach (Table table in this.tables)
                {
                    foreach (Row row in table.Rows)
                    {
                        Symbol symbol = row.Symbol;
                        if (null != symbol)
                        {
                            try
                            {
                                this.symbols.Add(symbol);
                            }
                            catch (ArgumentException)
                            {
                                Symbol existingSymbol = this.symbols[symbol.Name];

                                messageHandler.OnMessage(WixErrors.DuplicateSymbol(existingSymbol.Row.SourceLineNumbers, existingSymbol.Name));

                                if (null != symbol.Row.SourceLineNumbers)
                                {
                                    messageHandler.OnMessage(WixErrors.DuplicateSymbol2(symbol.Row.SourceLineNumbers));
                                }
                            }
                        }
                    }
                }
            }

            return this.symbols;
        }
开发者ID:bullshock29,项目名称:Wix3.6Toolset,代码行数:40,代码来源:Section.cs


注:本文中的IMessageHandler.OnMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。