Ejemplo n.º 1
0
        private static Dictionary <string, NapackFile> ParseNapackFiles(string rootDirectory, string directory)
        {
            Dictionary <string, NapackFile> filesFound = new Dictionary <string, NapackFile>();

            foreach (string subdirectory in Directory.GetDirectories(directory))
            {
                foreach (KeyValuePair <string, NapackFile> file in UploadOperation.ParseNapackFiles(rootDirectory, subdirectory))
                {
                    filesFound.Add(file.Key, file.Value);
                }
            }

            // Read all the files in a directory level asynchronously.
            Dictionary <string, Task <string> > fileReadTasks = new Dictionary <string, Task <string> >();

            foreach (string file in Directory.GetFiles(directory))
            {
                fileReadTasks.Add(PathUtilities.GetRelativePath(rootDirectory, file), Task.Run(() => File.ReadAllText(file)));
            }

            Task.WhenAll(fileReadTasks.Select(kvp => kvp.Value)).GetAwaiter().GetResult();

            foreach (KeyValuePair <string, string> pathAndContents in fileReadTasks.ToDictionary(task => task.Key, task => task.Value.Result))
            {
                // If the file starts with '// MSBuildType = TYPE', use TYPE instead. TODO this is kinda hacky and should be improved.
                string contentType = NapackFile.CompileType;
                if (pathAndContents.Value.StartsWith(NapackFile.BuildTypeHeader))
                {
                    int firstNewline = pathAndContents.Value.IndexOf("\n");
                    contentType = pathAndContents.Value.Substring(NapackFile.BuildTypeHeader.Length, firstNewline - NapackFile.BuildTypeHeader.Length);
                }

                filesFound.Add(pathAndContents.Key, new NapackFile()
                {
                    MsbuildType = contentType,
                    Contents    = pathAndContents.Value
                });
            }

            return(filesFound);
        }
Ejemplo n.º 2
0
        private async Task CreateOrUpdateNapackAsync(string packageName, NapackLocalDescriptor napackDescriptor, UserSecret userSecret, NapackServerClient client)
        {
            string rootDirectory = Path.GetFullPath(Path.GetDirectoryName(this.PackageFile));
            Dictionary <string, NapackFile> files = UploadOperation.ParseNapackFiles(rootDirectory, rootDirectory);

            files.Remove(Path.GetFileName(this.PackageFile));

            bool packageExists = await client.ContainsNapack(packageName).ConfigureAwait(false);

            if (!packageExists)
            {
                await this.CreateNapackPackageAsync(packageName, napackDescriptor, files, userSecret, client).ConfigureAwait(false);
            }
            else
            {
                // This is a new version creation operation.
                VersionDescriptor version = await client.UpdatePackageAsync(packageName, this.CreateNapackVersion(napackDescriptor, files), userSecret).ConfigureAwait(false);

                NapackClient.Log($"Updated the {packageName} package to version {version.Major}.{version.Minor}.{version.Patch}");
            }
        }