Example #1
0
        private void WriteToPackageList(Func <FileStream> packageListOpenStream, Action <PackageList> actionToPerformOnPackageList)
        {
            FileStream fileStream;
            bool       fileExists = true;

            try
            {
                fileStream = packageListOpenStream.Invoke();
            }
            catch (FileNotFoundException)
            {
                string packageListFileName = GetPackageListFilePath();
                fileStream = File.Open(packageListFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
                fileExists = false;
            }

            using (fileStream)
            {
                PackageList packageList;
                if (fileExists)
                {
                    packageList = LoadPackageList(fileStream);
                }
                else
                {
                    packageList = PackageList.CreateNewPackageList();
                }

                actionToPerformOnPackageList.Invoke(packageList);
                fileStream.SetLength(0);
                packageList.Save(fileStream);
            }
        }
Example #2
0
        private PackageList LoadPackageList(FileStream fileStream)
        {
            PackageList packageList;

            try
            {
                packageList = PackageList.Load(fileStream, packageListMigrations);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"Reading of package list from '{fileStream.Name}' failed: {e.Message}", e);
            }

            return(packageList);
        }
Example #3
0
        internal IPackageInfo GetSinglePackageInfo(string packageId, ListMode listMode)
        {
            try
            {
                using (FileStream fileStream = OpenPackageListForReadOperation())
                {
                    PackageList packageList = LoadPackageList(fileStream);

                    IPackageInfo packageInfo = packageList.FetchSinglePackageListInfo(packageId, listMode);

                    return(packageInfo);
                }
            }
            catch (FileNotFoundException)
            {
                return(null);
            }
        }
Example #4
0
        // TODO For MatchMode.All the searchPattern is useless
        public IReadOnlyCollection <IPackageInfo> GetPackageInfo(string searchPattern, ListMode listMode, MatchMode matchMode)
        {
            try
            {
                using (FileStream fileStream = OpenPackageListForReadOperation())
                {
                    PackageList packageList = LoadPackageList(fileStream);

                    var packageInfos = packageList.FetchPackageListInfo(searchPattern, listMode, matchMode);

                    return(packageInfos);
                }
            }
            catch (FileNotFoundException)
            {
                return(null);
            }
        }