public static TextPackageDefinition ParseOne(string Line)
        {
            var ret = default(TextPackageDefinition);

            var Match = Regex.Match(Line);

            if (Match.Success)
            {
                try {
                    var pret = new TextPackageDefinition();
                    pret.SHA1 = Match.Groups[SHA].Value;

                    pret.FileName = Match.Groups[FILENAME].Value;

                    if (long.TryParse(Match.Groups[SIZE].Value, out var PFileSize))
                    {
                        pret.FileSize = PFileSize;
                    }

                    if (int.TryParse(Match.Groups[STAGINGPERCENTAGE].Value, out var PStagingPercentage))
                    {
                        pret.StagingPercentage = PStagingPercentage;
                    }

                    ret = pret;
                } catch (Exception ex) {
                    ex.Ignore();
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
 public abstract Task <Stream> AcquirePackageStream(TextPackageDefinition Entry);
        public static async Task <Package> AcquirePackage(this PackageRepository This, TextPackageDefinition Entry, Location Environment = null)
        {
            Environment = Environment ?? Location.Current;

            var Success   = false;
            var ret       = default(Package);
            var Exception = default(Exception);

            try {
                var Stream = await This.AcquirePackageStream(Entry)
                             .DefaultAwait()
                ;

                ret = Package.FromPath(Environment.TempFolder, System.IO.Path.GetExtension(Entry.FileName));
                using (var FS = System.IO.File.OpenWrite(ret.FileName)) {
                    Stream.CopyTo(FS);
                }

                var Expected = Entry.SHA1;
                var Actual   = ret.SHA1();

                if (!String.Equals(Expected, Actual, StringComparison.InvariantCultureIgnoreCase))
                {
                    throw new InvalidSHA1Exception(Expected, Actual);
                }
                Success = true;
            } catch (Exception ex) {
                Exception = ex;
                Success   = false;
            }

            if (!Success)
            {
                ret?.Dispose();
                ret = null;
            }

            if (Exception != null)
            {
                throw Exception;
            }


            return(ret);
        }