public void TestBrand()
        {
            Uri url = new Uri("http://localhost/cmis/atom");
            string path1 = "/brand/1.png";
            DateTime date1 = DateTime.Now;
            string path2 = "/brand/2.png";
            DateTime date2 = DateTime.Now;

            // Create new config file with default values
            Config config = Config.CreateInitialConfig(this.configPath);

            Assert.IsNull(config.Brand);

            config.Brand = new Brand();
            config.Brand.Server = url;
            config.Brand.Files = new List<BrandFile>();
            BrandFile file1 = new BrandFile();
            file1.Path = path1;
            file1.Date = date1;
            BrandFile file2 = new BrandFile();
            file2.Path = path2;
            file2.Date = date2;
            config.Brand.Files.Add(file1);
            config.Brand.Files.Add(file2);
            config.Save();

            config = Config.CreateOrLoadByPath(this.configPath);
            Assert.AreEqual(url.ToString(), config.Brand.Server.ToString());
            Assert.AreEqual(2, config.Brand.Files.Count);
            Assert.AreEqual(path1, config.Brand.Files[0].Path);
            Assert.AreEqual(date1, config.Brand.Files[0].Date);
            Assert.AreEqual(path2, config.Brand.Files[1].Path);
            Assert.AreEqual(date2, config.Brand.Files[1].Date);
        }
Example #2
0
        private void SetupBrand() {
            Config config = ConfigManager.CurrentConfig;

            List<RepoInfo> folders;
            lock (this.repoLock) {
                folders = config.Folders.ToList();
            }

            foreach (RepoInfo folder in folders) {
                List<BrandFile> files = new List<BrandFile>();
                ClientBrand clientBrand = new ClientBrand();
                if (clientBrand.SetupServer(folder.Credentials)) {
                    bool success = true;
                    foreach (string path in clientBrand.PathList) {
                        DateTime date;
                        if (!clientBrand.GetFileDateTime(path, out date)) {
                            success = false;
                            break;
                        }

                        string pathname = Path.Combine(config.GetConfigPath(), this.BrandConfigFolder, path.Substring(1));
                        Directory.CreateDirectory(Path.GetDirectoryName(pathname));
                        try {
                            using (FileStream output = File.OpenWrite(pathname)) {
                                if (!clientBrand.GetFile(path, output)) {
                                    success = false;
                                    break;
                                }
                            }
                        } catch (Exception e) {
                            Logger.Error(string.Format("Fail to update the cilent brand file {0}: {1}", pathname, e));
                            success = false;
                            break;
                        }

                        BrandFile file = new BrandFile();
                        file.Date = date;
                        file.Path = path;
                        files.Add(file);
                    }

                    if (success) {
                        config.Brand = new Brand();
                        config.Brand.Server = folder.Address;
                        config.Brand.Files = files;
                        lock (this.repoLock) {
                            config.Save();
                        }

                        return;
                    }
                }
            }

            config.Brand = null;
            lock (this.repoLock) {
                config.Save();
            }
        }