Inheritance: CmisSync.Lib.ClientBrandBase
Example #1
0
        private static string FindImagePathname(string folder, string filename) {
            ClientBrand brand = new ClientBrand();
            foreach (string path in brand.PathList) {
                if (Path.GetFileName(path) == filename) {
                    string pathname = Path.Combine(folder, path.Substring(1));
                    if (File.Exists(pathname)) {
                        return pathname;
                    } else {
                        return null;
                    }
                }
            }

            return null;
        }
Example #2
0
        private static string FindImagePathname(string folder, string filename)
        {
            ClientBrand brand = new ClientBrand();

            foreach (string path in brand.PathList)
            {
                if (Path.GetFileName(path) == filename)
                {
                    string pathname = Path.Combine(folder, path.Substring(1));
                    if (File.Exists(pathname))
                    {
                        return(pathname);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(null);
        }
Example #3
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();
            }
        }
Example #4
0
        private bool CheckBrand(bool checkFiles)
        {
            Config config = ConfigManager.CurrentConfig;

            if (config.Brand == null || config.Brand.Server == null)
            {
                return(false);
            }

            ClientBrand clientBrand = new ClientBrand();

            foreach (string path in clientBrand.PathList)
            {
                if (!File.Exists(Path.Combine(config.GetConfigPath(), this.BrandConfigFolder, path.Substring(1))))
                {
                    return(false);
                }
            }

            List <RepoInfo> folders;

            lock (this.repoLock) {
                folders = config.Folders.ToList();
            }

            foreach (RepoInfo folder in folders)
            {
                if (folder.Address.ToString() != config.Brand.Server.ToString())
                {
                    continue;
                }

                if (!checkFiles)
                {
                    return(true);
                }

                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;
                        }

                        BrandFile file = config.Brand.Files.Find((BrandFile current) => { return(current.Path == path); });
                        if (file == null || file.Date != date)
                        {
                            success = false;
                            break;
                        }
                    }

                    if (success)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #5
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();
            }
        }
Example #6
0
        private bool CheckBrand(bool checkFiles) {
            Config config = ConfigManager.CurrentConfig;
            if (config.Brand == null || config.Brand.Server == null) {
                return false;
            }

            ClientBrand clientBrand = new ClientBrand();
            foreach (string path in clientBrand.PathList) {
                if (!File.Exists(Path.Combine(config.GetConfigPath(), this.BrandConfigFolder, path.Substring(1)))) {
                    return false;
                }
            }

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

            foreach (RepoInfo folder in folders) {
                if (folder.Address.ToString() != config.Brand.Server.ToString()) {
                    continue;
                }

                if (!checkFiles) {
                    return true;
                }

                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;
                        }

                        BrandFile file = config.Brand.Files.Find((BrandFile current) => { return current.Path == path; });
                        if (file == null || file.Date != date) {
                            success = false;
                            break;
                        }
                    }

                    if (success) {
                        return true;
                    }
                }
            }

            return false;
        }