Exemple #1
0
        private Google.Apis.Drive.v3.Data.File GetFile(IPackage package)
        {
            var files = DriveHelper.GetFiles(driveService, "properties has { key='" + PropertyModPackName + "' and value='" + PropertyReposityoryRoot + "' } and name='" + package.Id + "'");

            if (files.Count > 0)
            {
                return(files[0]);
            }
            return(null);
        }
Exemple #2
0
        public Stream GetPackage(IPackage package)
        {
            var file = GetFile(package);

            if (file == null)
            {
                return(null);
            }

            return(DriveHelper.DownloadFile(driveService, file.Id));
        }
Exemple #3
0
        public void RemovePackage(IPackage package)
        {
            var file = GetFile(package);

            if (file == null)
            {
                return;
            }

            DriveHelper.DeleteFile(driveService, file.Id);
        }
Exemple #4
0
        private void GetOrCreateModPackDirectory()
        {
            var list = DriveHelper.GetFiles(driveService, "mimeType = 'application/vnd.google-apps.folder' and 'root' in parents and trashed=false and properties has { key='" + PropertyModPackName + "' and value='" + PropertyReposityoryRoot + "'}");

            if (list.Count() == 0)
            {
                googleModRoot = DriveHelper.CreateDirectory(driveService, PropertyReposityoryRoot, "root", new Dictionary <string, string> {
                    { PropertyModPackName, PropertyReposityoryRoot }
                });
            }
            else
            {
                googleModRoot = list[0];
            }
        }
Exemple #5
0
        public void AddPackage(IPackage package, Stream packageStream)
        {
            if (GetFile(package) != null)
            {
                RemovePackage(package);
            }

            var properties = new Dictionary <string, string>()
            {
                { PropertyModPackName, PropertyReposityoryRoot },
                { PropertyVersion, package.Version }
            };


            using (packageStream)
            {
                DriveHelper.UploadFile(driveService, packageStream, package.Id, package.Description, googleModRoot.Id, properties);
            }
        }
Exemple #6
0
        public IEnumerable <IPackage> GetPackages()
        {
            var propertiesSearch = "properties has { key='" + PropertyModPackName + "' and value='" + PropertyReposityoryRoot + "'} and mimeType != 'application/vnd.google-apps.folder'";

            return(DriveHelper.GetFiles(driveService, propertiesSearch).Select(f => GetPackageFromFile(f)));
        }
Exemple #7
0
 public DriveRepository(string keyFile)
 {
     driveService = DriveHelper.Authenticate(keyFile);
     GetOrCreateModPackDirectory();
 }