예제 #1
0
        public static BUCommon.AccountList BuildAccounts()
        {
            string file = "b2app.accounts.xml";

            file = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), file);

            var acctlst = new BUCommon.AccountList();

            acctlst.load(file);

            file = "b2app.filecache.xml";
            file = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), file);
            BUCommon.FileCache fc = new BUCommon.FileCache();

            if (File.Exists(file))
            {
                fc.load(file);
            }

            acctlst.filecache = fc;

            foreach (var a in acctlst)
            {
                Load(acctlst, a);
            }

            return(acctlst);
        }
예제 #2
0
        public override int run(BUCommon.AccountList accounts)
        {
            var acct = _getAcct(accounts, _opts.account);
            var cmd  = new BackupLib.commands.FileList
            {
                account     = acct
                , cache     = accounts.filecache
                , versions  = _opts.versions
                , useRemote = _opts.useremote
                , pathRE    = _opts.filter
            };

            var containers = accounts.filecache.containers
                             .Where(x => x.accountID == acct.id && x.name == _opts.container)
                             .ToList();

            Console.WriteLine("Account: {0}", acct.name);
            foreach (var c in containers)
            {
                cmd.container = c;
                var files = cmd.run();

                Console.WriteLine();
                Console.WriteLine("Container: {0}", c.name);
                foreach (var f in files.OrderBy(x => x.path))
                {
                    Console.WriteLine("{0}, {1}", f.uploaded, f.path);
                }
            }

            return(0);
        }
예제 #3
0
        protected CopyLoc _parseLoc(BUCommon.AccountList accts, string loc)
        {
            CopyLoc l = new CopyLoc();

            if (System.IO.Directory.Exists(loc))
            {
                l.cont = new BUCommon.Container {
                    accountID = 0, id = loc, name = loc, type = "LOCAL"
                };
            }
            else
            {
                var parts = loc.Split(':');
                if (parts != null && parts.Length > 1)
                {
                    if (parts[0].Length == 1)
                    {
                        return(l);
                    }

                    var acct = accts.accounts.Where(x => x.name == parts[0]).FirstOrDefault();
                    if (acct != null)
                    {
                        var cont = accts.filecache.containers.Where(x => x.accountID == acct.id && x.name == parts[1]).FirstOrDefault();

                        if (cont != null)
                        {
                            l.acct = acct; l.cont = cont;
                        }
                    }
                }
            }

            return(l);
        }
예제 #4
0
        public void B2UploadTest()
        {
            BUCommon.AccountList accts = BackupLib.AccountBuilder.BuildAccounts();
            var acct = accts.accounts.FirstOrDefault();

            Assert.AreEqual("CommB2.Connection", acct.svcName);
            acct.service.authorize();

            var cont = acct.service.getContainers().FirstOrDefault();

            Assert.IsNotNull(cont);
            string srcfile = "c:\\tmp\\photos\\2016\\1231-newyears\\DSC06562.ARW";
            var    ff      = new BUCommon.FreezeFile {
                path = "2016/1231-newyears/DSC06562.ARW"
            };

            var rsa     = BackupLib.KeyLoader.LoadRSAKey("c:\\tmp\\id_rsa_1_pub");
            var fe      = new BackupLib.FileEncrypt(rsa);
            var fs      = ff.readStream("c:\\tmp\\photos");
            var encstrm = fe.encrypt(fs);
            var sha1    = System.Security.Cryptography.SHA1Cng.Create();

            var res = sha1.ComputeHash(encstrm);

            encstrm.Seek(0, System.IO.SeekOrigin.Begin);

            DateTime now = DateTime.Now;
            var      td  = acct.service.threadStart();

            acct.service.uploadFile(td, cont, ff, encstrm, null);
            acct.service.threadStop(td);
            Assert.AreEqual(2017, ff.uploaded.Year);
            Assert.AreEqual(now.Month, ff.uploaded.Month);
            Assert.AreEqual(now.Day, ff.uploaded.Day);
        }
예제 #5
0
        public override int run(BUCommon.AccountList accounts)
        {
            var account = _getAcct(accounts, _opts.account);
            var cont    = accounts.filecache.containers
                          .Where(x => x.accountID == account.id && x.name == _opts.container)
                          .ToList();

            var cmd = new BackupLib.commands.Sync
            {
                account     = account
                , cache     = accounts.filecache
                , container = cont.FirstOrDefault()
                , progress  = _printDiff
                , excepts   = _printExcept

                , noAction   = _opts.dryrun
                , keyFile    = _opts.keyfile
                , pathRoot   = _opts.pathroot
                , useRemote  = _opts.useremote
                , privateKey = _opts.privateKey
                , filterRE   = _opts.filterre
                , excludeRE  = _opts.excludere
                , maxTasks   = _opts.maxTasks
                , checksum   = _opts.cksum
            };

            Console.WriteLine("Account: {0}", account.name);
            Console.WriteLine("Container: {0}", cmd.container.name);

            cmd.run();

            return(0);
        }
예제 #6
0
 protected BUCommon.Account _getAcct(BUCommon.AccountList accts, string account)
 {
     BUCommon.Account acct = null;
     if (!string.IsNullOrWhiteSpace(account))
     {
         acct = accts.Where(x => x.name == account).FirstOrDefault();
     }
     return(acct);
 }
예제 #7
0
        public override int run(BUCommon.AccountList accts)
        {
            Console.WriteLine("Accounts:");

            foreach (var acc in accts)
            {
                Console.WriteLine("{0} - {1} ({2})", acc.name, acc.svcName, acc.connStr);
            }

            return(0);
        }
예제 #8
0
        public static void Save(BUCommon.AccountList accounts)
        {
            string file = "b2app.accounts.xml";

            file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), file);
            accounts.save(file);

            file = "b2app.filecache.xml";
            file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), file);
            accounts.filecache.save(file);
        }
예제 #9
0
        public static void Save(BUCommon.AccountList accounts)
        {
            string file = "b2app.accounts.xml";

            file = Path.Combine(BUCommon.ConfigPaths.Prefix, file);
            accounts.save(file);

            file = "b2app.filecache.json";
            file = Path.Combine(BUCommon.ConfigPaths.Prefix, file);
            accounts.filecache.save(file);
        }
예제 #10
0
        public override int run(BUCommon.AccountList accounts)
        {
            var acct = _getAcct(accounts, _acctname);

            Console.WriteLine("account: {0}", acct.name);
            (new BackupLib.commands.Authorize
            {
                account = acct
                , accounts = accounts
            }).run();

            return(0);
        }
예제 #11
0
    public override int run(BUCommon.AccountList accounts)
    {
      var src = _parseLoc(accounts, _opts.source);
      var dest = _parseLoc(accounts, _opts.dest);

      if (src.cont == null) { return _err("ERROR - source is unknown: {0}", _opts.source); }
      if (dest.cont == null) { return _err("ERROR - dest is unknown: {0}", _opts.dest); }

      if (src.acct == null && dest.acct == null)
        { return _err("ERROR - use copy instead of this program (both are local)."); }
      
      if (src.acct != null && dest.acct != null)
        { return _err("ERROR - remote to remote copying is not yet supported."); }

      /* these options should be mutually exclusive. */
      if (dest.acct != null)
        {
          var crm = new BackupLib.commands.CopyRemote
              {
                  cache=accounts.filecache
                  , account=dest.acct
                  , container=dest.cont
                  , pathRoot=src.cont.id

                  , progress= _printDiff

                  , fileRE=_opts.filterRE
                  , key=_opts.key
                  , noAction=_opts.dryrun
              };
          crm.run();
        }

      if (src.acct != null && !string.IsNullOrWhiteSpace(_opts.filterRE))
        {
          var cl = new BackupLib.commands.CopyLocal 
            { 
              account=src.acct
              , destPath=dest.cont.id
              , filterre = _opts.filterRE
              , key=_opts.key
              , noAction=_opts.dryrun
              , progress= _printDiff
              , errors = _printExcept
            };
          cl.run();
        }
      
      return 0;
    }
예제 #12
0
        public void B2ContainerListTest()
        {
            BUCommon.AccountList accts = BackupLib.AccountBuilder.BuildAccounts();
            var acct = accts.accounts.FirstOrDefault();

            Assert.IsNotNull(acct);
            Assert.AreEqual("CommB2.Connection", acct.svcName);

            Assert.IsNotNull(acct.service);
            //acct.service.open();

            var conts = acct.service.getContainers();

            Assert.IsNotNull(conts);
        }
예제 #13
0
        public void B2ContainerListTest()
        {
            BUCommon.AccountList accts = BackupLib.AccountBuilder.BuildAccounts();
            var acct = accts.accounts.FirstOrDefault();

            Assert.That(acct, Is.Not.Null);
            Assert.That(acct.svcName, Is.EqualTo("CommB2.Connection"));

            Assert.That(acct.service, Is.Not.Null);
            //acct.service.open();

            var conts = acct.service.getContainers();

            Assert.That(conts, Is.Not.Null);
        }
예제 #14
0
        public static void Load(BUCommon.AccountList accounts, BUCommon.Account account)
        {
            Func <BUCommon.IFileSvc> svc = null;

            if (_SvcMapping.TryGetValue(account.svcName, out svc))
            {
                account.service           = svc();
                account.service.account   = account;
                account.service.fileCache = accounts.filecache;
                account.service.setParams(account.connStr);
            }
            else
            {
                account.service = null;
            }
        }
예제 #15
0
        protected BUCommon.AccountList _makeSvc()
        {
            var acct = new BUCommon.Account();

            acct.connStr = @"c:\tmp\b2test";
            acct.svcName = "BackupLib.LocalService";
            acct.id      = 1;
            acct.name    = "localtest";
            var acctlst = new BUCommon.AccountList();

            acctlst.filecache = BUCommon.FileCache.Load(@"c:\tmp\b2test\cache_sync.json");

            System.IO.Directory.CreateDirectory(@"c:\tmp\b2test\cont1");

            BackupLib.AccountBuilder.Load(acctlst, acct);
            acctlst.Add(acct);

            return(acctlst);
        }
예제 #16
0
        public override int run(BUCommon.AccountList accounts)
        {
            var acct  = _getAcct(accounts, _acct);
            var conts = new BackupLib.commands.Containers {
                account = acct, cache = accounts.filecache
            };

            conts.run();

            var cs = accounts.filecache.getContainers(acct.id);

            Console.WriteLine("Account: {0}", acct.name);
            foreach (var c in cs)
            {
                Console.WriteLine("{0} - {1}", c.name, c.type);
            }

            return(0);
        }
예제 #17
0
        public static BUCommon.AccountList BuildAccounts()
        {
            string file = "b2app.accounts.xml";

            file = System.IO.Path.Combine(BUCommon.ConfigPaths.Prefix, file);

            var acctlst = new BUCommon.AccountList();

            acctlst.load(file);

            file = "b2app.filecache";
            file = System.IO.Path.Combine(BUCommon.ConfigPaths.Prefix, file);
            BUCommon.FileCache fc = null;
            if (System.IO.File.Exists(file + ".json"))
            {
                fc = BUCommon.FileCache.Load(file + ".json");
            }
            else
            {
                if (System.IO.File.Exists(file + ".xml"))
                {
                    fc = BUCommon.FileCache.Load(file + ".xml");
                    fc.save(file + ".json");
                }
                else
                {
                    fc = BUCommon.FileCache.Load(file + ".json");
                }
            }

            acctlst.filecache = fc;

            foreach (var a in acctlst)
            {
                Load(acctlst, a);
            }

            return(acctlst);
        }
예제 #18
0
 public abstract int run(BUCommon.AccountList accts);
예제 #19
0
 protected void _loadAccounts()
 {
     _accts = BackupLib.AccountBuilder.BuildAccounts();
 }