Exemple #1
0
        public void Push(PackageContainerRepoItem item, string fullPath)
        {
            // access
            if (item == null || !fullPath.HasContent())
            {
                return;
            }

            // make a COPY (flexible in types)
            var jsonCopy = JsonConvert.SerializeObject(item);
            var itemCopy = JsonConvert.DeserializeObject <PackageContainerRepoItem>(jsonCopy);

            if (itemCopy == null)
            {
                return;
            }

            // record new location
            itemCopy.Location = fullPath;

            // check, if already in
            PackageContainerRepoItem foundItem = null;

            foreach (var it in EnumerateItems())
            {
                if (it?.Location?.Trim().ToLower() == fullPath.Trim().ToLower())
                {
                    foundItem = it;
                    break;
                }
            }

            // if so, delete it
            if (foundItem != null)
            {
                this.Remove(foundItem);
            }

            // add at top
            FileMap.Insert(0, itemCopy);
            itemCopy.ContainerList = this;

            // if to large, crop
            if (FileMap.Count > MaxItems)
            {
                FileMap.Remove(FileMap.Last());
            }
        }