Ejemplo n.º 1
0
        private static string GetFromZip(string nameOfFileToCheck, string zipPath)
        {
            ZipFile.ExtractToDirectory(zipPath, Path.GetDirectoryName(zipPath));
            var files = Directory.GetFiles(Path.GetDirectoryName(zipPath), "*", SearchOption.AllDirectories).Where(f => !f.Equals(zipPath, StringComparison.InvariantCultureIgnoreCase)).ToList();

            foreach (string file in files)
            {
                if (Path.GetFileName(file).Equals(nameOfFileToCheck, StringComparison.InvariantCultureIgnoreCase))
                {
                    {
                        return(TelimenaVersionReader.Read(file, VersionTypes.FileVersion));
                    }
                }
            }

            foreach (string file in files)
            {
                try
                {
                    string version = TelimenaVersionReader.ReadEmbeddedAssemblyVersion(new FileInfo(file)
                                                                                       , nameOfFileToCheck, VersionTypes.FileVersion);
                    if (!string.IsNullOrEmpty(version))
                    {
                        return(version);
                    }
                }
                catch
                {
                    //oh well
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task <string> GetEmbeddedAssemblyVersion(Stream stream, string expectedFileName, string expectedAssemblyName, bool expectSingleFile)
        {
            stream.Position = 0;
            string tempFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            using (Stream file = File.Create(tempFilePath))
            {
                await stream.CopyToAsync(file).ConfigureAwait(false);
            }

            string unzippedPath = this.GetUnzippedPath(tempFilePath, expectedFileName, expectSingleFile);

            var version = TelimenaVersionReader.ReadEmbeddedAssemblyVersion(new FileInfo(unzippedPath), expectedAssemblyName, VersionTypes.FileVersion);

            if (string.IsNullOrEmpty(version))
            {
                throw new InvalidOperationException("Cannot extract version info from uploaded file");
            }

            return(version);
        }