Ejemplo n.º 1
0
        public override bool AddAppVersion(string appguid, string appversion)
        {
            if (!KnownApps.Select(ka => ka.guid).Contains(appguid))
            {
                return(false);
            }

            if (KnownApps.Single(ka => ka.guid == appguid).versions.Select(av => av.version).Contains(appversion))
            {
                return(false);
            }

            using (var redis_ver = _client.As <RedisAppVersion>())
                using (var redis_app = _client.As <RedisApp>())
                {
                    RedisAppVersion new_version = new RedisAppVersion {
                        Id            = redis_app.GetNextSequence(), version = appversion,
                        url_locations = new List <string>(new string[] { _config.RootUrl + "files/" + appguid + "/" + appversion + "/" })
                    };
                    redis_ver.Store(new_version);
                    RedisApp current_app = redis_app.GetById(_cached.Single(kvp => kvp.Value.guid == appguid).Key);
                    if (current_app.version_ids == null)
                    {
                        current_app.version_ids = new List <long>();
                    }
                    current_app.version_ids.Add(new_version.Id);
                    redis_app.Store(current_app);
                    _cached = null; _cached_version_keys = null;
                }

            return(true);
        }
Ejemplo n.º 2
0
        public override bool AddAppVersionFile(string appguid, string appversion, IFile[] files)
        {
            if (!KnownApps.Select(ka => ka.guid).Contains(appguid))
            {
                return(false);
            }

            if (!KnownApps.Single(ka => ka.guid == appguid).versions.Select(av => av.version).Contains(appversion))
            {
                return(false);
            }

            var targetDir = new FileInfo(Path.Combine(_config.RootDirectory, appguid + "/" + appversion));

            if (!Directory.Exists(targetDir.FullName))
            {
                Directory.CreateDirectory(targetDir.FullName);
            }

            using (var redis_version = _client.As <RedisAppVersion>())
            {
                RedisAppVersion this_version = redis_version.GetById(_cached_version_keys[appguid][appversion]);
                foreach (IFile file in files)
                {
                    string sha1hash = Convert.ToBase64String(hasher.ComputeHash(file.InputStream));
                    file.InputStream.Seek(0, SeekOrigin.Begin);
                    if (this_version.package == null)
                    {
                        this_version.package = new List <AppPackage>();
                    }
                    this_version.package.Add(new AppPackage {
                        size = (uint)file.ContentLength, name = file.FileName, required = true, hash = sha1hash
                    });
                    file.SaveTo(Path.Combine(targetDir.FullName, file.FileName));
                }
                redis_version.Store(this_version);
                _cached = null; _cached_version_keys = null;
            }

            return(true);
        }
Ejemplo n.º 3
0
        public override bool SetAppDefaultVersion(string appguid, string appversion)
        {
            if (!KnownApps.Select(ka => ka.guid).Contains(appguid))
            {
                return(false);
            }

            if (!KnownApps.Single(ka => ka.guid == appguid).versions.Select(av => av.version).Contains(appversion))
            {
                return(false);
            }

            using (var redis_ver = _client.As <RedisAppVersion>())
                using (var redis_app = _client.As <RedisApp>())
                {
                    RedisApp        this_app     = redis_app.GetById(_cached.Single(kvp => kvp.Value.guid == appguid).Key);
                    RedisAppVersion this_version = redis_ver.GetById(_cached_version_keys[appguid][appversion]);
                    this_app.current_id = this_version.Id;
                    redis_app.Store(this_app);
                    _cached = null; _cached_version_keys = null;
                }
            return(true);
        }
Ejemplo n.º 4
0
        private void AddDemoApps()
        {
            RedisApp omaha, chrome;

            using (var redis_app = _client.As <RedisApp>())
            {
                using (var redis_version = _client.As <RedisAppVersion>())
                {
                    RedisAppVersion omaha_version = new RedisAppVersion
                    {
                        Id            = redis_version.GetNextSequence(),
                        version       = "1.3.23.0",
                        url_locations = new List <string>(new string[] { "http://localhost/omaha" }),
                        package       = new List <AppPackage>(
                            new AppPackage[] {
                            new AppPackage {
                                hash = "9813058901hjklh0wre", name = "OmahaClient.exe", required = true, size = 42
                            }
                        })
                    };
                    RedisAppVersion chrome_version = new RedisAppVersion
                    {
                        Id            = redis_version.GetNextSequence(),
                        version       = "13.0.782.112",
                        url_locations = new List <string>(new string[] { "http://localhost/chrome" }),
                        package       = new List <AppPackage>(
                            new AppPackage[] {
                            new AppPackage {
                                hash = "012349jkgxc90asdhfjk99", name = "chrome_installer.exe", required = true, size = 42
                            }
                        }),
                        actions = new List <AppAction>(new AppAction[] {
                            new AppAction {
                                on_event = "install", arguments = "--do-not-launch-chrome", run = "chrome_installer.exe"
                            },
                            new AppAction {
                                on_event = "postinstall", version = "13.0.782.112", on_success = "exitsilentlyonlaunchcmd"
                            }
                        })
                    };

                    redis_version.Store(omaha_version);
                    redis_version.Store(chrome_version);

                    List <RedisAppVersion> vs = redis_version.GetAll().ToList();


                    omaha = new RedisApp
                    {
                        Id          = redis_app.GetNextSequence(),
                        name        = "Omaha",
                        guid        = "{430FD4D0-B729-4F61-AA34-91526481799D}",
                        version_ids = new List <long> {
                            omaha_version.Id
                        },
                        current_id = omaha_version.Id
                    };

                    chrome = new RedisApp
                    {
                        Id          = redis_app.GetNextSequence(),
                        name        = "Chrome",
                        guid        = "{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}",
                        version_ids = new List <long> {
                            chrome_version.Id
                        },
                        current_id = chrome_version.Id
                    };
                }
                redis_app.Store(omaha);
                redis_app.Store(chrome);

                List <RedisApp> avs = redis_app.GetAll().ToList();
            }
        }