private bool ConnectToHQ()
        {
            if (_client == null)
            {
                _client = new NetworkClient(_config.ServerAddress, _config.ServerReplicationPort);
            }
            // authenticate and get branch config
            ReplicationPacket p = createpacket();

            p.command = "getbranchconfig";

            ReturnPacket ret = (ReturnPacket)_client.Send(p);

            if (ret.OK)
            {
                ClientWhatWhenConfig c = (ClientWhatWhenConfig)ret.Data;

                _clientConfig.what = c.what;

                _clientConfig.isConfigured = true;

                if (_clientConfig.whencron != c.whencron)
                {
                    _cron.Stop();
                    _clientConfig.whencron = c.whencron;
                    _cron = new CronDaemon();
                    _cron.AddJob(_clientConfig.whencron, Replicate);
                }

                SaveConfig();
            }
            return(ret.OK);
        }
        private ClientWhatWhenConfig GetBranchConfig(string branchname)
        {
            WhatItem ret = _config.What.Find((WhatItem w) => { return(w.Name.ToLower() == branchname.ToLower()); });

            if (ret == null)
            {
                ret = _config.What.Find((WhatItem w) => { return(w.Name.ToLower() == "default"); });
            }

            ClientWhatWhenConfig c = new ClientWhatWhenConfig();

            c.what    = ret;
            var where = _config.Where.Find(w => { return(w.BranchName.ToLower() == branchname.ToLower()); });
            if (where != null)
            {
                c.whencron = where.When;
            }
            else
            {
                c.whencron = "* * * * *";
            }

            return(c);
        }
        private ClientWhatWhenConfig GetBranchConfig(string branchname)
        {
            WhatItem ret = _config.What.Find((WhatItem w) => { return w.Name.ToLower() == branchname.ToLower(); });

            if (ret == null)
                ret = _config.What.Find((WhatItem w) => { return w.Name.ToLower() == "default"; });

            ClientWhatWhenConfig c = new ClientWhatWhenConfig();
            c.what = ret;
            var where = _config.Where.Find(w => { return w.BranchName.ToLower() == branchname.ToLower(); });
            if (where != null)
                c.whencron = where.When;
            else
                c.whencron = "* * * * *";

            return c;
        }