private void LogValidationMessage(ValidationMessage message)
        {
            var messageSourceLineNumbers = this.OutputSourceLineNumber;

            if (!String.IsNullOrEmpty(message.Table) && !String.IsNullOrEmpty(message.Column) && message.PrimaryKeys != null)
            {
                messageSourceLineNumbers = this.GetSourceLineNumbers(message.Table, message.PrimaryKeys);
            }

            switch (message.Type)
            {
            case ValidationMessageType.InternalFailure:
            case ValidationMessageType.Error:
                this.Messaging.Write(ErrorMessages.ValidationError(messageSourceLineNumbers, message.IceName, message.Description));
                break;

            case ValidationMessageType.Warning:
                this.Messaging.Write(WarningMessages.ValidationWarning(messageSourceLineNumbers, message.IceName, message.Description));
                break;

            case ValidationMessageType.Info:
                this.Messaging.Write(VerboseMessages.ValidationInfo(message.IceName, message.Description));
                break;

            default:
                throw new WixException(ErrorMessages.InvalidValidatorMessageType(message.Type.ToString()));
            }
        }
Ejemplo n.º 2
0
    public void AddMessage(MessageType messageType, string message)
    {
        var userMessage = new UserMessage
        {
            MessageType = messageType,
            Message     = message
        };

        switch (messageType)
        {
        case MessageType.Information:
            InformationMessages.Add(userMessage);
            break;

        case MessageType.Success:
            SuccessMessages.Add(userMessage);
            break;

        case MessageType.Error:
            ErrorMessages.Add(userMessage);
            break;

        case MessageType.Warning:
            WarningMessages.Add(userMessage);
            break;
        }
    }
Ejemplo n.º 3
0
        /// <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, IMessaging 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.Write(WarningMessages.AccessDeniedForSettingAttributes(null, filePath));
                }
            }
        }
Ejemplo n.º 4
0
 public void LogWarning(string data)
 {
     Warnings++;
     Messages.Enqueue(data);
     WarningMessages.Enqueue(data);
     DumpMessage("WARN ", data);
 }
        public void Execute()
        {
            var componentGuidConditions = new Dictionary <string, bool>();

            foreach (var componentSymbol in this.Section.Symbols.OfType <ComponentSymbol>())
            {
                // We don't care about unmanaged components and if there's a * GUID remaining,
                // there's already an error that prevented it from being replaced with a real GUID.
                if (!String.IsNullOrEmpty(componentSymbol.ComponentId) && "*" != componentSymbol.ComponentId)
                {
                    var thisComponentHasCondition   = !String.IsNullOrEmpty(componentSymbol.Condition);
                    var allComponentsHaveConditions = thisComponentHasCondition;

                    if (componentGuidConditions.TryGetValue(componentSymbol.ComponentId, out var alreadyCheckedCondition))
                    {
                        allComponentsHaveConditions = thisComponentHasCondition && alreadyCheckedCondition;

                        if (allComponentsHaveConditions)
                        {
                            this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(componentSymbol.SourceLineNumbers, componentSymbol.Id.Id, componentSymbol.ComponentId));
                        }
                        else
                        {
                            this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(componentSymbol.SourceLineNumbers, componentSymbol.Id.Id, componentSymbol.ComponentId));
                        }
                    }

                    componentGuidConditions[componentSymbol.ComponentId] = allComponentsHaveConditions;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get an identifier attribute value and displays an error for an illegal identifier value.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
        /// <param name="attribute">The attribute containing the value to get.</param>
        /// <param name="messageHandler">A delegate that receives error messages.</param>
        /// <returns>The attribute's identifier value or a special value if an error occurred.</returns>
        internal static string GetAttributeIdentifierValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute)
        {
            string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly);

            if (Common.IsIdentifier(value))
            {
                if (72 < value.Length)
                {
                    messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }

                return(value);
            }
            else
            {
                if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal))
                {
                    messaging.Write(ErrorMessages.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
                else
                {
                    messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }

                return(String.Empty);
            }
        }
Ejemplo n.º 7
0
        private void WriteBurnManifestContainerAttributes(XmlTextWriter writer, string executableName, WixBundleContainerSymbol container)
        {
            writer.WriteAttributeString("Id", container.Id.Id);
            writer.WriteAttributeString("FileSize", container.Size.Value.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("Hash", container.Hash);

            if (ContainerType.Detached == container.Type)
            {
                string resolvedUrl = this.ResolveUrl(container.DownloadUrl, null, null, container.Id.Id, container.Name);
                if (!String.IsNullOrEmpty(resolvedUrl))
                {
                    writer.WriteAttributeString("DownloadUrl", resolvedUrl);
                }
                else if (!String.IsNullOrEmpty(container.DownloadUrl))
                {
                    writer.WriteAttributeString("DownloadUrl", container.DownloadUrl);
                }

                writer.WriteAttributeString("FilePath", container.Name);
            }
            else if (ContainerType.Attached == container.Type)
            {
                if (!String.IsNullOrEmpty(container.DownloadUrl))
                {
                    this.Messaging.Write(WarningMessages.DownloadUrlNotSupportedForAttachedContainers(container.SourceLineNumbers, container.Id.Id));
                }

                writer.WriteAttributeString("FilePath", executableName); // attached containers use the name of the bundle since they are attached to the executable.
                writer.WriteAttributeString("AttachedIndex", container.AttachedContainerIndex.Value.ToString(CultureInfo.InvariantCulture));
                writer.WriteAttributeString("Attached", "yes");
                writer.WriteAttributeString("Primary", "yes");
            }
        }
Ejemplo n.º 8
0
        private void ResolveBundleInstallScope(IntermediateSection section, WixBundleSymbol bundleSymbol, IEnumerable <PackageFacade> facades)
        {
            var dependencySymbolsById = section.Symbols.OfType <WixDependencyProviderSymbol>().ToDictionary(t => t.Id.Id);

            foreach (var facade in facades)
            {
                if (bundleSymbol.PerMachine && YesNoDefaultType.No == facade.PackageSymbol.PerMachine)
                {
                    this.Messaging.Write(VerboseMessages.SwitchingToPerUserPackage(facade.PackageSymbol.SourceLineNumbers, facade.PackageId));

                    bundleSymbol.Attributes &= ~WixBundleAttributes.PerMachine;
                    break;
                }
            }

            foreach (var facade in facades)
            {
                // Update package scope from bundle scope if default.
                if (YesNoDefaultType.Default == facade.PackageSymbol.PerMachine)
                {
                    facade.PackageSymbol.PerMachine = bundleSymbol.PerMachine ? YesNoDefaultType.Yes : YesNoDefaultType.No;
                }

                // We will only register packages in the same scope as the bundle. Warn if any packages with providers
                // are in a different scope and not permanent (permanents typically don't need a ref-count).
                if (!bundleSymbol.PerMachine &&
                    YesNoDefaultType.Yes == facade.PackageSymbol.PerMachine &&
                    !facade.PackageSymbol.Permanent &&
                    dependencySymbolsById.ContainsKey(facade.PackageId))
                {
                    this.Messaging.Write(WarningMessages.NoPerMachineDependencies(facade.PackageSymbol.SourceLineNumbers, facade.PackageId));
                }
            }
        }
Ejemplo n.º 9
0
        public Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute)
        {
            var access = AccessModifier.Public;
            var value  = Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, EmptyRule.CanBeEmpty);

            var match = ParseHelper.LegalIdentifierWithAccess.Match(value);

            if (!match.Success)
            {
                return(null);
            }
            else if (match.Groups["access"].Success)
            {
                access = (AccessModifier)Enum.Parse(typeof(AccessModifier), match.Groups["access"].Value, true);
            }

            value = match.Groups["id"].Value;

            if (Common.IsIdentifier(value) && 72 < value.Length)
            {
                this.Messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
            }

            return(new Identifier(value, access));
        }
Ejemplo n.º 10
0
 public void Warn(string message)
 {
     lock (WarningMessages)
     {
         WarningMessages.Add(message);
     }
 }
Ejemplo n.º 11
0
        public string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards, bool allowRelative)
        {
            if (null == attribute)
            {
                throw new ArgumentNullException("attribute");
            }

            var value = this.GetAttributeValue(sourceLineNumbers, attribute);

            if (0 < value.Length)
            {
                if (!this.IsValidLongFilename(value, allowWildcards, allowRelative) && !this.IsValidLocIdentifier(value))
                {
                    if (allowRelative)
                    {
                        this.Messaging.Write(ErrorMessages.IllegalRelativeLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                    }
                    else
                    {
                        this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                    }
                }
                else if (allowRelative)
                {
                    value = this.GetCanonicalRelativePath(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value);
                }
                else if (CompilerCore.IsAmbiguousFilename(value))
                {
                    this.Messaging.Write(WarningMessages.AmbiguousFileOrDirectoryName(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
            }

            return(value);
        }
        public void Execute()
        {
            var bundleFilename = Path.GetFileName(this.OutputPath);

            // Copy the burn.exe to a writable location then mark it to be moved to its final build location.

            var stubPlatform = this.BundleSymbol.Platform.ToString();
            var stubFile     = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), stubPlatform, "burn.exe");

            if (stubPlatform != "X86")
            {
                this.Messaging.Write(WarningMessages.ExperimentalBundlePlatform(stubPlatform));
            }

            var bundleTempPath = Path.Combine(this.IntermediateFolder, bundleFilename);

            this.Messaging.Write(VerboseMessages.GeneratingBundle(bundleTempPath, stubFile));

            if ("setup.exe".Equals(bundleFilename, StringComparison.OrdinalIgnoreCase))
            {
                this.Messaging.Write(ErrorMessages.InsecureBundleFilename(bundleFilename));
            }

            this.Transfer = this.BackendHelper.CreateFileTransfer(bundleTempPath, this.OutputPath, true, this.BundleSymbol.SourceLineNumbers);

            File.Copy(stubFile, bundleTempPath, true);
            File.SetAttributes(bundleTempPath, FileAttributes.Normal);

            var windowsAssemblyVersion = GetWindowsAssemblyVersion(this.BundleSymbol);

            var applicationManifestData = GenerateApplicationManifest(this.BundleSymbol, this.BootstrapperApplicationDllSymbol, this.OutputPath, windowsAssemblyVersion);

            UpdateBurnResources(bundleTempPath, this.OutputPath, this.BundleSymbol, windowsAssemblyVersion, applicationManifestData);

            // Update the .wixburn section to point to at the UX and attached container(s) then attach the containers
            // if they should be attached.
            using (var writer = BurnWriter.Open(this.Messaging, bundleTempPath))
            {
                var burnStubFile = new FileInfo(bundleTempPath);
                writer.InitializeBundleSectionData(burnStubFile.Length, this.BundleSymbol.BundleId);

                // Always attach the UX container first
                writer.AppendContainer(this.UXContainer.WorkingPath, BurnWriter.Container.UX);

                // Now append all other attached containers
                foreach (var container in this.Containers)
                {
                    if (ContainerType.Attached == container.Type)
                    {
                        // The container was only created if it had payloads.
                        if (!String.IsNullOrEmpty(container.WorkingPath) && BurnConstants.BurnUXContainerName != container.Id.Id)
                        {
                            writer.AppendContainer(container.WorkingPath, BurnWriter.Container.Attached);
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public override void Warning(int id, object message, Exception exception)
 {
     WarningMessages.Add(new LogMessage
     {
         Id        = id,
         Message   = message,
         Exception = exception
     });
 }
        private void ReportGuidCollisions(HashSet <string> guidCollisions, Dictionary <string, List <ComponentSymbol> > componentGuidConditions)
        {
            Dictionary <string, FileSymbol> fileSymbolsById = null;

            foreach (var guid in guidCollisions)
            {
                var collidingComponents         = componentGuidConditions[guid];
                var allComponentsHaveConditions = collidingComponents.All(c => !String.IsNullOrEmpty(c.Condition));

                foreach (var componentSymbol in collidingComponents)
                {
                    string path;
                    string type;

                    if (componentSymbol.KeyPathType == ComponentKeyPathType.File)
                    {
                        if (fileSymbolsById is null)
                        {
                            fileSymbolsById = this.Section.Symbols.OfType <FileSymbol>().ToDictionary(t => t.Id.Id);
                        }

                        path = fileSymbolsById.TryGetValue(componentSymbol.KeyPath, out var fileSymbol) ? fileSymbol.Source.Path : componentSymbol.KeyPath;
                        type = "source path";
                    }
                    else if (componentSymbol.KeyPathType == ComponentKeyPathType.Registry)
                    {
                        if (this.RegistrySymbolsById is null)
                        {
                            this.RegistrySymbolsById = this.Section.Symbols.OfType <RegistrySymbol>().ToDictionary(t => t.Id.Id);
                        }

                        path = this.RegistrySymbolsById.TryGetValue(componentSymbol.KeyPath, out var registrySymbol) ? String.Concat(registrySymbol.Key, "\\", registrySymbol.Name) : componentSymbol.KeyPath;
                        type = "registry path";
                    }
                    else
                    {
                        if (this.TargetPathsByDirectoryId is null)
                        {
                            this.TargetPathsByDirectoryId = this.ResolveDirectoryTargetPaths();
                        }

                        path = this.PathResolver.GetCanonicalDirectoryPath(this.TargetPathsByDirectoryId, componentIdGenSeeds: null, componentSymbol.DirectoryRef, this.Platform);
                        type = "directory";
                    }

                    if (allComponentsHaveConditions)
                    {
                        this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(componentSymbol.SourceLineNumbers, componentSymbol.Id.Id, componentSymbol.ComponentId, type, path));
                    }
                    else
                    {
                        this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(componentSymbol.SourceLineNumbers, componentSymbol.Id.Id, componentSymbol.ComponentId, type, path));
                    }
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Logs a message from the <see cref="Validator"/>.
        /// </summary>
        /// <param name="message">A <see cref="String"/> of tab-delmited tokens
        /// in the validation message.</param>
        /// <param name="action">The name of the action to which the message
        /// belongs.</param>
        /// <exception cref="ArgumentNullException">The message cannot be null.
        /// </exception>
        /// <exception cref="WixException">The message does not contain four (4)
        /// or more tab-delimited tokens.</exception>
        /// <remarks>
        /// <para><paramref name="message"/> a tab-delimited set of tokens,
        /// formatted according to Windows Installer guidelines for ICE
        /// message. The following table lists what each token by index
        /// should mean.</para>
        /// <para><paramref name="action"/> a name that represents the ICE
        /// action that was executed (e.g. 'ICE08').</para>
        /// <list type="table">
        /// <listheader>
        ///     <term>Index</term>
        ///     <description>Description</description>
        /// </listheader>
        /// <item>
        ///     <term>0</term>
        ///     <description>Name of the ICE.</description>
        /// </item>
        /// <item>
        ///     <term>1</term>
        ///     <description>Message type. See the following list.</description>
        /// </item>
        /// <item>
        ///     <term>2</term>
        ///     <description>Detailed description.</description>
        /// </item>
        /// <item>
        ///     <term>3</term>
        ///     <description>Help URL or location.</description>
        /// </item>
        /// <item>
        ///     <term>4</term>
        ///     <description>Table name.</description>
        /// </item>
        /// <item>
        ///     <term>5</term>
        ///     <description>Column name.</description>
        /// </item>
        /// <item>
        ///     <term>6</term>
        ///     <description>This and remaining fields are primary keys
        ///     to identify a row.</description>
        /// </item>
        /// </list>
        /// <para>The message types are one of the following value.</para>
        /// <list type="table">
        /// <listheader>
        ///     <term>Value</term>
        ///     <description>Message Type</description>
        /// </listheader>
        /// <item>
        ///     <term>0</term>
        ///     <description>Failure message reporting the failure of the
        ///     ICE custom action.</description>
        /// </item>
        /// <item>
        ///     <term>1</term>
        ///     <description>Error message reporting database authoring that
        ///     case incorrect behavior.</description>
        /// </item>
        /// <item>
        ///     <term>2</term>
        ///     <description>Warning message reporting database authoring that
        ///     causes incorrect behavior in certain cases. Warnings can also
        ///     report unexpected side-effects of database authoring.
        ///     </description>
        /// </item>
        /// <item>
        ///     <term>3</term>
        ///     <description>Informational message.</description>
        /// </item>
        /// </list>
        /// </remarks>
        public virtual void Log(string message, string action)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            string[] messageParts = message.Split('\t');
            if (3 > messageParts.Length)
            {
                if (null == action)
                {
                    throw new WixException(ErrorMessages.UnexpectedExternalUIMessage(message));
                }
                else
                {
                    throw new WixException(ErrorMessages.UnexpectedExternalUIMessage(message, action));
                }
            }

            SourceLineNumber messageSourceLineNumbers = null;

            if (6 < messageParts.Length)
            {
                string[] primaryKeys = new string[messageParts.Length - 6];

                Array.Copy(messageParts, 6, primaryKeys, 0, primaryKeys.Length);

                messageSourceLineNumbers = this.GetSourceLineNumbers(messageParts[4], primaryKeys);
            }
            else // use the file name as the source line information
            {
                messageSourceLineNumbers = this.sourceLineNumbers;
            }

            switch (messageParts[1])
            {
            case "0":
            case "1":
                this.messaging.Write(ErrorMessages.ValidationError(messageSourceLineNumbers, messageParts[0], messageParts[2]));
                break;

            case "2":
                this.messaging.Write(WarningMessages.ValidationWarning(messageSourceLineNumbers, messageParts[0], messageParts[2]));
                break;

            case "3":
                this.messaging.Write(VerboseMessages.ValidationInfo(messageParts[0], messageParts[2]));
                break;

            default:
                throw new WixException(ErrorMessages.InvalidValidatorMessageType(messageParts[1]));
            }
        }
Ejemplo n.º 16
0
        public Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute)
        {
            var access = AccessModifier.Global;
            var value  = Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, EmptyRule.CanBeEmpty);

            var separator = value.IndexOf(' ');

            if (separator > 0)
            {
                var prefix = value.Substring(0, separator);
                switch (prefix)
                {
                case "global":
                case "public":
                case "package":
                    access = AccessModifier.Global;
                    break;

                case "internal":
                case "library":
                    access = AccessModifier.Library;
                    break;

                case "file":
                case "protected":
                    access = AccessModifier.File;
                    break;

                case "private":
                case "fragment":
                case "section":
                    access = AccessModifier.Section;
                    break;

                default:
                    return(null);
                }

                value = value.Substring(separator + 1).Trim();
            }

            if (!Common.IsIdentifier(value))
            {
                this.Messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                return(null);
            }
            else if (72 < value.Length)
            {
                this.Messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
            }

            return(new Identifier(access, value));
        }
Ejemplo n.º 17
0
        public void CloneMessages <R>(ApiResult <R> source)
        {
            foreach (var item in source.ErrorMessages)
            {
                AddErrorMessage(item);
            }

            foreach (var warningitem in source.WarningMessages)
            {
                WarningMessages.Add(warningitem);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the source line information (if available) for a row by its table name and primary key.
        /// </summary>
        /// <param name="tableName">The table name of the row.</param>
        /// <param name="primaryKeys">The primary keys of the row.</param>
        /// <returns>The source line number information if found; null otherwise.</returns>
        protected SourceLineNumber GetSourceLineNumbers(string tableName, string[] primaryKeys)
        {
            // source line information only exists if an output file was supplied
            if (null != this.output)
            {
                // index the source line information if it hasn't been indexed already
                if (null == this.indexedSourceLineNumbers)
                {
                    this.indexedSourceLineNumbers = new Hashtable();

                    // index each real table
                    foreach (Table table in this.output.Tables)
                    {
                        // skip unreal tables
                        if (table.Definition.Unreal)
                        {
                            continue;
                        }

                        // index each row
                        foreach (Row row in table.Rows)
                        {
                            // skip rows that don't contain source line information
                            if (null == row.SourceLineNumbers)
                            {
                                continue;
                            }

                            // index the row using its table name and primary key
                            string primaryKey = row.GetPrimaryKey(';');
                            if (null != primaryKey)
                            {
                                string key = String.Concat(table.Name, ":", primaryKey);

                                if (this.indexedSourceLineNumbers.ContainsKey(key))
                                {
                                    this.messaging.Write(WarningMessages.DuplicatePrimaryKey(row.SourceLineNumbers, primaryKey, table.Name));
                                }
                                else
                                {
                                    this.indexedSourceLineNumbers.Add(key, row.SourceLineNumbers);
                                }
                            }
                        }
                    }
                }

                return((SourceLineNumber)this.indexedSourceLineNumbers[String.Concat(tableName, ":", String.Join(";", primaryKeys))]);
            }

            // use the file name as the source line information
            return(this.sourceLineNumbers);
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> OnPostAsync(string?returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(Email);

                if (user != null)
                {
                    var suspendedDays = user.checkSuspended();
                    if (suspendedDays > 0)
                    {
                        ModelState.AddModelError(string.Empty, WarningMessages.SuspendedAccount);
                        ModelState.AddModelError(string.Empty, WarningMessages.SuspendedDaysLeft(suspendedDays));
                        return(Page());
                    }
                }

                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout,
                // set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Email,
                                                                      Password, RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new
                    {
                        ReturnUrl = returnUrl,
                        RememberMe = RememberMe
                    }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, WarningMessages.InvalidLoginAttempt);
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        private int CalculateCabbingThreadCount()
        {
            var cabbingThreadCount = Environment.ProcessorCount;

            if (cabbingThreadCount <= 0)
            {
                cabbingThreadCount = 1; // reset to 1 when the environment variable is invalid.

                this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), cabbingThreadCount.ToString()));
            }

            return(cabbingThreadCount);
        }
Ejemplo n.º 21
0
        private void WriteBurnManifestPayloadAttributes(XmlTextWriter writer, WixBundlePayloadSymbol payload, bool embeddedOnly, Dictionary <string, WixBundlePayloadSymbol> allPayloads)
        {
            Debug.Assert(!embeddedOnly || PackagingType.Embedded == payload.Packaging);

            writer.WriteAttributeString("Id", payload.Id.Id);
            writer.WriteAttributeString("FilePath", payload.Name);
            writer.WriteAttributeString("FileSize", payload.FileSize.Value.ToString(CultureInfo.InvariantCulture));
            writer.WriteAttributeString("Hash", payload.Hash);

            if (payload.LayoutOnly)
            {
                writer.WriteAttributeString("LayoutOnly", "yes");
            }

            switch (payload.Packaging)
            {
            case PackagingType.Embedded:     // this means it's in a container.
                if (!String.IsNullOrEmpty(payload.DownloadUrl))
                {
                    this.Messaging.Write(WarningMessages.DownloadUrlNotSupportedForEmbeddedPayloads(payload.SourceLineNumbers, payload.Id.Id));
                }

                writer.WriteAttributeString("Packaging", "embedded");
                writer.WriteAttributeString("SourcePath", payload.EmbeddedId);

                if (BurnConstants.BurnUXContainerName != payload.ContainerRef)
                {
                    writer.WriteAttributeString("Container", payload.ContainerRef);
                }
                break;

            case PackagingType.External:
                var packageId   = payload.ParentPackagePayloadRef;
                var parentUrl   = payload.ParentPackagePayloadRef == null ? null : allPayloads[payload.ParentPackagePayloadRef].DownloadUrl;
                var resolvedUrl = this.ResolveUrl(payload.DownloadUrl, parentUrl, packageId, payload.Id.Id, payload.Name);
                if (!String.IsNullOrEmpty(resolvedUrl))
                {
                    writer.WriteAttributeString("DownloadUrl", resolvedUrl);
                }
                else if (!String.IsNullOrEmpty(payload.DownloadUrl))
                {
                    writer.WriteAttributeString("DownloadUrl", payload.DownloadUrl);
                }

                writer.WriteAttributeString("Packaging", "external");
                writer.WriteAttributeString("SourcePath", payload.Name);
                break;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        public int Run(IServiceProvider serviceProvider, IMessageListener listener, string[] args)
        {
            var messaging = serviceProvider.GetService <IMessaging>();

            messaging.SetListener(listener);

            try
            {
                var unparsed = this.ParseCommandLineAndLoadExtensions(serviceProvider, messaging, args);

                if (!messaging.EncounteredError)
                {
                    if (this.commandLine.ShowLogo)
                    {
                        AppCommon.DisplayToolHeader();
                    }

                    if (this.commandLine.ShowHelp)
                    {
                        PrintHelp();
                        AppCommon.DisplayToolFooter();
                    }
                    else
                    {
                        foreach (string arg in unparsed)
                        {
                            messaging.Write(WarningMessages.UnsupportedCommandLineArgument(arg));
                        }

                        this.Bind(serviceProvider, messaging);
                    }
                }
            }
            catch (WixException we)
            {
                messaging.Write(we.Error);
            }
            catch (Exception e)
            {
                messaging.Write(ErrorMessages.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }

            return(messaging.LastErrorNumber);
        }
Ejemplo n.º 23
0
        // **********

        // **********
        public virtual void AddWarningMessage(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            message = message.Fix();

            if (WarningMessages.Contains(message))
            {
                return;
            }

            WarningMessages.Add(message);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Set an MsiAssemblyName row.  If it was directly authored, override the value, otherwise
        /// create a new row.
        /// </summary>
        /// <param name="assemblyNameSymbols">MsiAssemblyName table.</param>
        /// <param name="facade">FileFacade containing the assembly read for the MsiAssemblyName row.</param>
        /// <param name="name">MsiAssemblyName name.</param>
        /// <param name="value">MsiAssemblyName value.</param>
        private void SetMsiAssemblyName(Dictionary <string, MsiAssemblyNameSymbol> assemblyNameSymbols, FileFacade facade, string name, string value)
        {
            // check for null value (this can occur when grabbing the file version from an assembly without one)
            if (String.IsNullOrEmpty(value))
            {
                this.Messaging.Write(WarningMessages.NullMsiAssemblyNameValue(facade.SourceLineNumber, facade.ComponentRef, name));
            }
            else
            {
                // if the assembly will be GAC'd and the name in the file table doesn't match the name in the MsiAssemblyName table, error because the install will fail.
                if ("name" == name && AssemblyType.DotNetAssembly == facade.AssemblyType &&
                    String.IsNullOrEmpty(facade.AssemblyApplicationFileRef) &&
                    !String.Equals(Path.GetFileNameWithoutExtension(facade.FileName), value, StringComparison.OrdinalIgnoreCase))
                {
                    this.Messaging.Write(ErrorMessages.GACAssemblyIdentityWarning(facade.SourceLineNumber, Path.GetFileNameWithoutExtension(facade.FileName), value));
                }

                // override directly authored value
                var lookup = String.Concat(facade.ComponentRef, "/", name);
                if (!assemblyNameSymbols.TryGetValue(lookup, out var assemblyNameSymbol))
                {
                    assemblyNameSymbol = this.Section.AddSymbol(new MsiAssemblyNameSymbol(facade.SourceLineNumber, new Identifier(AccessModifier.Section, facade.ComponentRef, name))
                    {
                        ComponentRef = facade.ComponentRef,
                        Name         = name,
                        Value        = value,
                    });

                    if (null == facade.AssemblyNames)
                    {
                        facade.AssemblyNames = new List <MsiAssemblyNameSymbol>();
                    }

                    facade.AssemblyNames.Add(assemblyNameSymbol);

                    assemblyNameSymbols.Add(assemblyNameSymbol.Id.Id, assemblyNameSymbol);
                }

                assemblyNameSymbol.Value = value;

                if (this.VariableCache != null)
                {
                    var key = String.Format(CultureInfo.InvariantCulture, "assembly{0}.{1}", name, facade.Id).ToLowerInvariant();
                    this.VariableCache[key] = value;
                }
            }
        }
        /// <summary>
        /// This should be call before doing final storage, will reduce the size of
        /// unused fields
        /// </summary>
        public void SetEmptyValueToNull()
        {
            foreach (var err in ErrorMessages)
            {
                err.SetEmptyValueToNull();
            }


            if (String.IsNullOrEmpty(MediaItemId))
            {
                MediaItemId = null;
            }

            if (String.IsNullOrEmpty(MessageId))
            {
                MessageId = null;
            }
            if (!Log.Any())
            {
                Log = null;
            }
            if (!OutputCommands.Any())
            {
                OutputCommands = null;
            }
            if (!OutgoingMessages.Any())
            {
                OutgoingMessages = null;
            }
            if (!ErrorMessages.Any())
            {
                ErrorMessages = null;
            }
            if (!InfoMessages.Any())
            {
                InfoMessages = null;
            }
            if (!WarningMessages.Any())
            {
                WarningMessages = null;
            }
            if (Envelope.SetEmptyValueToNull())
            {
                Envelope = null;
            }
        }
Ejemplo n.º 26
0
        public LanguageCompilationMessage AddWarningMessage(string description, int absolutePos)
        {
            if (LogWarningMessages == false)
            {
                return(null);
            }

            var location = Project.ActiveCodeUnit.TranslateCharacterLocation(absolutePos);

            var msg = new LanguageCompilationMessage(Project, location, description);

            WarningMessages.Add(msg);

            this.ReportWarning("Warning", msg.ToString());

            return(msg);
        }
Ejemplo n.º 27
0
        /// <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, IMessaging 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.Write(WarningMessages.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.Write(WarningMessages.DirectoryInUse(null, path));
                        return(false);
                    }

                    System.Threading.Thread.Sleep(300);  // sleep a bit before trying again
                }
            }

            return(true);
        }
Ejemplo n.º 28
0
        public void AddVariable(IPreprocessContext context, string name, string value, bool showWarning)
        {
            var currentValue = this.GetVariableValue(context, "var", name);

            if (null == currentValue)
            {
                context.Variables.Add(name, value);
            }
            else
            {
                if (showWarning && value != currentValue)
                {
                    this.Messaging.Write(WarningMessages.VariableDeclarationCollision(context.CurrentSourceLineNumber, name, value, currentValue));
                }

                context.Variables[name] = value;
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Parses an ignore modularization element.
        /// </summary>
        /// <param name="node">XmlNode on an IgnoreModulatization element.</param>
        private void ParseIgnoreModularizationElement(XElement node)
        {
            var    sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
            string name = null;

            this.Core.Write(WarningMessages.DeprecatedIgnoreModularizationElement(sourceLineNumbers));

            foreach (var attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Name":
                        name = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
                        break;

                    case "Type":
                        // this is actually not used
                        break;

                    default:
                        this.Core.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionAttribute(node, attrib);
                }
            }

            if (null == name)
            {
                this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name"));
            }

            this.Core.ParseForExtensionElements(node);

            if (!this.Core.EncounteredError)
            {
                this.Core.AddSymbol(new WixSuppressModularizationSymbol(sourceLineNumbers, new Identifier(AccessModifier.Private, name)));
            }
        }
        /// <summary>
        /// Set an MsiAssemblyName row.  If it was directly authored, override the value, otherwise
        /// create a new row.
        /// </summary>
        /// <param name="assemblyNameTuples">MsiAssemblyName table.</param>
        /// <param name="file">FileFacade containing the assembly read for the MsiAssemblyName row.</param>
        /// <param name="name">MsiAssemblyName name.</param>
        /// <param name="value">MsiAssemblyName value.</param>
        private void SetMsiAssemblyName(Dictionary <string, MsiAssemblyNameTuple> assemblyNameTuples, FileFacade file, string name, string value)
        {
            // check for null value (this can occur when grabbing the file version from an assembly without one)
            if (String.IsNullOrEmpty(value))
            {
                this.Messaging.Write(WarningMessages.NullMsiAssemblyNameValue(file.File.SourceLineNumbers, file.File.Component_, name));
            }
            else
            {
                // if the assembly will be GAC'd and the name in the file table doesn't match the name in the MsiAssemblyName table, error because the install will fail.
                if ("name" == name && FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType &&
                    String.IsNullOrEmpty(file.WixFile.File_AssemblyApplication) &&
                    !String.Equals(Path.GetFileNameWithoutExtension(file.File.LongFileName), value, StringComparison.OrdinalIgnoreCase))
                {
                    this.Messaging.Write(ErrorMessages.GACAssemblyIdentityWarning(file.File.SourceLineNumbers, Path.GetFileNameWithoutExtension(file.File.LongFileName), value));
                }

                // override directly authored value
                var lookup = String.Concat(file.File.Component_, "/", name);
                if (!assemblyNameTuples.TryGetValue(lookup, out var assemblyNameRow))
                {
                    assemblyNameRow            = new MsiAssemblyNameTuple(file.File.SourceLineNumbers);
                    assemblyNameRow.Component_ = file.File.Component_;
                    assemblyNameRow.Name       = name;
                    assemblyNameRow.Value      = value;

                    if (null == file.AssemblyNames)
                    {
                        file.AssemblyNames = new List <MsiAssemblyNameTuple>();
                    }

                    file.AssemblyNames.Add(assemblyNameRow);
                    this.Section.Tuples.Add(assemblyNameRow);
                }

                assemblyNameRow.Value = value;

                if (this.VariableCache != null)
                {
                    var key = String.Format(CultureInfo.InvariantCulture, "assembly{0}.{1}", name, file.File.File).ToLowerInvariant();
                    this.VariableCache[key] = value;
                }
            }
        }