Exemplo n.º 1
0
        public Token[] Tokenize()
        {
            var tokens = new List <Token>();

            List <ITokenIdentifier> identifiers = new List <ITokenIdentifier>();

            identifiers.AddRange(SymbolIdentifier.SymbolIdentifiers());
            identifiers.Add(new StringIdentifier(CheckName, TokenType.Name));
            identifiers.Add(new StringIdentifier(CheckNumber, TokenType.Number));

            int  charIndex           = 0;
            bool identificationEnded = true;

            do
            {
                currentChar         = _source[charIndex];
                identificationEnded = true;

                foreach (var identifier in identifiers)
                {
                    if (identifier.IsIdentificationEnded() != true)
                    {
                        identifier.Next(currentChar);
                    }
                }

                foreach (var identifier in identifiers)
                {
                    if (identifier.IsIdentificationEnded() != true)
                    {
                        identificationEnded = false;
                    }
                }

                if (identificationEnded)
                {
                    foreach (var identifier in identifiers)
                    {
                        if (identifier.IsIdentifided())
                        {
                            tokens.Add(identifier.GetIdentifiedToken());
                            if (identifier is StringIdentifier)
                            {
                                charIndex--;
                            }
                        }
                        identifier.Reset();
                    }
                }

                charIndex++;
            } while (currentChar != '\0');

            foreach (var identifier in identifiers)
            {
                if (identifier.IsIdentifided())
                {
                    tokens.Add(identifier.GetIdentifiedToken());
                }
                identifier.Reset();
            }

            Console.WriteLine($"End Tokenizetion, {tokens.Count} tokens was found.");
            return(tokens.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers debug symbols with the package database.
        /// </summary>
        /// <param name="packageInfo">Metadata of the package to register.</param>
        /// <param name="database">Database to register to.</param>
        /// <param name="userId">ID of the user uploading the package.</param>
        /// <param name="symbolFileNames">Mapping of symbol id to symbol virtual identifiers.</param>
        /// <param name="cancellationToken">Token used to cancel the asynchronous operation.</param>
        /// <returns>Symbol registration result.</returns>
        public async Task <RegisterSymbolResult> RegisterSymbolsAsync(ParsedPackageInfo packageInfo, SlimGetContext database, string userId, IDictionary <SymbolIdentifier, string> symbolFileNames, CancellationToken cancellationToken)
        {
            var pkginfo = packageInfo.Info;
            var pkg     = database.Packages.FirstOrDefault(x => x.IdLowercase == pkginfo.IdLowercase);

            if (pkg == null)
            {
                return(RegisterPackageResult.DoesNotExist);
            }

            if (pkg.OwnerId != userId)
            {
                return(RegisterPackageResult.OwnerMismatch);
            }

            if (pkg.Id != pkginfo.Id)
            {
                return(RegisterPackageResult.IdMismatch);
            }

            var pkgv = database.PackageVersions.FirstOrDefault(x => x.PackageId == pkginfo.Id && x.Version == pkginfo.NormalizedVersion);

            if (pkgv == null)
            {
                return(RegisterPackageResult.DoesNotExist);
            }

            var dbsymbols = database.PackageSymbols
                            .Where(x => x.PackageId == pkginfo.Id && x.PackageVersion == pkginfo.NormalizedVersion)
                            .GroupBy(x => x.Identifier)
                            .ToDictionary(x => x.Key, x => x);

            var regids = new Dictionary <SymbolIdentifier, string>();

            foreach (var bin in packageInfo.Binaries.OfType <ParsedIndexedBinarySymbols>())
            {
                var identifier = new SymbolIdentifier(bin.Identifier, bin.Age, bin.Kind);
                if (!dbsymbols.TryGetValue(bin.Identifier, out var dbsymbolg) || !symbolFileNames.TryGetValue(identifier, out var fnsymbol))
                {
                    continue;
                }

                var fx       = bin.Framework.GetFrameworkString();
                var dbsymbol = dbsymbolg.FirstOrDefault(x => x.Framework == fx);
                if (dbsymbol == null)
                {
                    continue;
                }

                if (dbsymbol.Filename != null)
                {
                    return(RegisterPackageResult.DuplicateSymbols);
                }

                regids[identifier] = bin.Entry;
                dbsymbol.Name      = bin.Name;
                dbsymbol.Filename  = fnsymbol;
                database.PackageSymbols.Update(dbsymbol);
            }

            await database.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(regids);
        }