Beispiel #1
0
        public Client(SQLServerConnector sqlServerConnector, SQLiteConnector sqLiteConnector, Enum connectivityState)
        {
            if ((ConnectivityState)connectivityState == ConnectivityState.Offline)
            {
                _isOnline = false;
            }
            else
            {
                _isOnline = true;
            }

            //bool? firstTimeClient = sqLiteConnector.IsNotEmpty(tableName: "Client");

            bool firstTimeClient = false;

            if (_isOnline)
            {
                if (firstTimeClient == true)
                {
                    _clientID   = sqlServerConnector.GetNewClientId();
                    _clientName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

                    //BUG _clientPublicIP = "publicIP"; _clientPrivateIP = "privateIP";

                    //write to sqlite all data singleton
                    _cronExpression = sqlServerConnector.GetValidCronExpr();

                    sqlServerConnector.ExecuteInsertQuery("INSERT INTO ....");
                    sqLiteConnector.ExecuteInsertQuery("INSERT INTO ....");
                }
                else if (firstTimeClient == false)
                {
                    //laaater : update IPs if they're different write them to sqlite and server?

                    SetClientFromSqlite(sqLiteConnector);
                }

                IsSet = true;
            }
            else
            {
                if (firstTimeClient == true)
                {
                    IsSet     = false;
                    _clientID = -1;

                    //BUG _clientPrivateIP = _clientPublicIP = "Not Connected";


                    //...
                    //
                }
                else
                {
                    //instantiante from sqlite
                    SetClientFromSqlite(sqLiteConnector);
                    IsSet = true;
                }
            }
        }
        public DatabaseDirectory(int clientID)
        {
            _clientID          = clientID;
            SqlServerConnector =
                new SQLServerConnector(@"Data Source=DESKTOP-DJONOS6\SQLEXPRESS;Initial Catalog=PFE;Integrated Security=True;Connection Timeout = 5");

            SqlLiteConnector =
                new SQLiteConnector(@"Data source = ..\..\localSqlite\localDatabase.db;Version=3;");
        }
Beispiel #3
0
        private void SetClientFromSqlite(SQLiteConnector sqLiteConnector)
        {
            var clientRow = sqLiteConnector.ExecuteSelectQuery("SELECT * FROM Client").Rows[0];

            this._clientID   = Convert.ToInt32(clientRow["id_client"]);
            this._clientName = clientRow["host_name"].ToString();

            //int id_schedule = Convert.ToInt32(clientRow["id_schedule"]);

            var scheduleRow = sqLiteConnector.ExecuteSelectQuery("SELECT * FROM Schedule").Rows[0];

            this._cronExpression = scheduleRow["cron_expr"].ToString();
            this._hour           = Convert.ToInt32(scheduleRow["hour"]);
            this._minute         = Convert.ToInt32(scheduleRow["minutes"]);
        }
Beispiel #4
0
        public void InitializeEngine(FormInterface formInterface)
        {
            _formInterface   = formInterface;
            _sqLiteConnector = new SQLiteConnector(_sqLiteConnString);
            _formInterface   = formInterface;



            _timeManager = new SyncTimeManager();
            _timeManager.Init(this);



            SetConnectivityState();
            DatabaseDirectory.SetConnectors(_sqlServerConnector, _sqLiteConnector);


            _formInterface.SetCorrStatus((ConnectivityState)_connectivityStateEnum);

            //_client = new Client(_sqlServerConnector, _sqLiteConnector, _connectivityStateEnum);


            //Debug:
            _client = new Client(_sqlServerConnector, _sqLiteConnector, _connectivityStateEnum);
            _timeManager.RescheduleFromCronExpr(_client._cronExpression);

            if ((ConnectivityState)_connectivityStateEnum == ConnectivityState.Offline)
            {
                if (_client.IsSet)
                {
                    //start last set schedule by client (cronExpr from sqlite)
                    string cronExpr = _client.GetCron();

                    //_timeManager.RescheduleFromCronExpr(cronExpr);
                    _timeManager.StartScheduler(2);

                    //set interface depending on cronExpression
                    _formInterface.SetConfigInterfaceCron(cronExpr);
                }
                else
                {
                    //no sync for him
                }


                //disables interface for changing jobs

                //todo code for tree:
                SetOfflineTree();
                _formInterface.EnableOfflineTree(true);
                _formInterface.EnableOnlineTree(false);

                //throw new Exception("not yet configured");
            }
            else if ((ConnectivityState)_connectivityStateEnum == ConnectivityState.Online)
            {
                //launch job from cronExpr
                string cronExpr = _client.GetCron();
                //_timeManager.RescheduleFromCronExpr(cronExpr);
                _timeManager.StartScheduler(2);

                //Enable formInterface for change of cronEpxr


                //todo code to load tree
                int nonSyncedFiles   = _sqLiteConnector.ExecuteScalarQuery("SELECT COUNT(*) FROM Files WHERE is_synced = 0");
                int nonSyncedFolders = _sqLiteConnector.ExecuteScalarQuery("SELECT COUNT(*) FROM Folders WHERE is_synced = 0");

                if (nonSyncedFolders != 0 || nonSyncedFiles != 0)
                {
                    //formInterface --> disable sqlserver tree and enable sqlite tree
                    _formInterface.EnableOnlineTree(isEnabled: false);
                    _formInterface.EnableOfflineTree(isEnabled: true);

                    SetOnlineTree();
                    SetOfflineTree();

                    //bug prompt to sync and lock database if accepted to sync ??
                }
                else
                {
                    _formInterface.EnableOnlineTree(isEnabled: true);
                    _formInterface.EnableOfflineTree(isEnabled: false);
                    SetOnlineTree();
                }
            }
        }
 public static void SetConnectors(SQLServerConnector sqlServerConnector = null, SQLiteConnector sqlLiteConnector = null)
 {
     DatabaseDirectory.SqlServerConnector = sqlServerConnector;
     DatabaseDirectory.SqlLiteConnector   = sqlLiteConnector;
 }