コード例 #1
0
 protected SampleRepository(ZipFile archive)
 {
     this.archive = archive;
     if (archive.ContainsEntry("index.xml"))
     {
         index = ((ICollection <SampleDesc>)IndexSerializer.Deserialize(archive["index.xml"].OpenReader())).ToDictionary(sd => sd.ID, sd => sd);
     }
 }
コード例 #2
0
ファイル: samples.cs プロジェクト: ziaullah47/xamarin-android
 protected SampleRepository(ZipArchive archive)
 {
     this.archive = archive;
     if (archive.ContainsEntry("index.xml"))
     {
         using (var stream = new MemoryStream()) {
             archive.First(e => e.FullName.Equals("index.xml", StringComparison.OrdinalIgnoreCase)).Extract(stream);
             stream.Position = 0;
             index           = ((ICollection <SampleDesc>)IndexSerializer.Deserialize(stream)).ToDictionary(sd => sd.ID, sd => sd);
         }
     }
 }
コード例 #3
0
        private static int Info(InfoOptions options)
        {
            if (!options.Validate())
            {
                return(1);
            }

            Index index = IndexSerializer.Deserialize(options.IndexFile);

            PrintSummary(index, options.IndexFile);
            return(0);
        }
コード例 #4
0
        public void Deserialize()
        {
            string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            string filePath = Path.Combine(
                homePath,
                "repos",
                "mjcheetham",
                "git",
                ".git",
                "index");

            byte[] inputBytes = File.ReadAllBytes(filePath);
            using var inputStream = new MemoryStream(inputBytes);
            Index index = IndexSerializer.Deserialize(inputStream);

            using var outputStream = new MemoryStream();
            IndexSerializer.Serialize(index, outputStream);
            byte[] outputBytes = outputStream.ToArray();

            Assert.Equal(inputBytes, outputBytes);
        }
コード例 #5
0
        private static int List(ListOptions options)
        {
            if (!options.Validate())
            {
                return(1);
            }

            Index index = IndexSerializer.Deserialize(options.IndexFile);

            // Apply entry filters
            IEnumerable <IndexEntry> entriesQuery = index.Entries;

            if (!string.IsNullOrWhiteSpace(options.Path))
            {
                entriesQuery = entriesQuery.Where(
                    x => x.Path.StartsWith(options.Path, options.IgnoreCase, CultureInfo.InvariantCulture)
                    );
            }

            if (options.SkipWorktree)
            {
                entriesQuery = entriesQuery.Where(x => x.SkipWorktree);
            }
            else if (options.NoSkipWorktree)
            {
                entriesQuery = entriesQuery.Where(x => !x.SkipWorktree);
            }

            IList <IndexEntry> entries = entriesQuery.ToList();

            // Compute column widths
            int         maxWidth = Math.Max(Console.WindowWidth, 120);
            ISet <uint> uids     = new HashSet <uint>();
            ISet <uint> gids     = new HashSet <uint>();
            long        maxSize  = 0;

            foreach (IndexEntry entry in entries)
            {
                uids.Add(entry.Status.UserId);
                gids.Add(entry.Status.GroupId);
                maxSize = Math.Max(entry.Status.Size, maxSize);
            }

            int maxUserLen  = 1;
            int maxGroupLen = 1;

            if (entries.Count > 0)
            {
                if (options.NumericUidGid)
                {
                    maxUserLen  = uids.Max().ToString().Length;
                    maxGroupLen = gids.Max().ToString().Length;
                }
                else
                {
                    maxUserLen  = uids.Select(GetUserName).Max(x => x.Length);
                    maxGroupLen = gids.Select(GetGroupName).Max(x => x.Length);
                }
            }

            int    maxSizeLen   = maxSize.ToString().Length;
            string columnFormat = "{0} {1} {2} " +
                                  $"{{3,-{maxUserLen}}} {{4,-{maxGroupLen}}} {{5,{maxSizeLen}}} " +
                                  "{6,2} {7:MMM} {7:HH:mm} {8} ";

            // Print count
            Console.WriteLine("total {0}", entries.Count);

            // Print entries
            foreach (IndexEntry entry in entries)
            {
                PrintEntry(entry, columnFormat, options.CTime, options.NumericUidGid, maxWidth);
            }

            return(0);
        }