SelectEvaluator() public static method

public static SelectEvaluator ( int myUniqueID ) : ServerEvaluator,
myUniqueID int
return ServerEvaluator,
Exemplo n.º 1
0
    public static void ServerUploadEvaluator()
    {
        try {
            ChronojumpServer myServer = new ChronojumpServer();
            LogB.Information(myServer.ConnectDatabase());

            ServerEvaluator myEval = SqliteServer.SelectEvaluator(1);

            bool success = false;
            int  evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID"));
            if (evalSID == Constants.ServerUndefinedID)
            {
                string idCode = myServer.UploadEvaluator(myEval);
                myEval.Code = Util.FetchName(idCode);

                myEval.Update(false);

                evalSID = Util.FetchID(idCode);
                SqlitePreferences.Update("evaluatorServerID", evalSID.ToString(), false);
                success = true;
            }
            else
            {
                success = myServer.EditEvaluator(myEval, evalSID);
            }

            if (success)
            {
                new DialogMessage(Constants.MessageTypes.INFO,
                                  string.Format(Catalog.GetString("Successfully Uploaded evaluator with ID: {0}"), evalSID));
            }
            else
            {
                new DialogMessage(Constants.MessageTypes.WARNING,
                                  string.Format(Catalog.GetString("Evaluator {0} has not been correctly uploaded. Maybe codes doesn't match."), evalSID));
            }

            LogB.Information(myServer.DisConnectDatabase());
        } catch {
            new DialogMessage(Constants.MessageTypes.WARNING, Constants.ServerOffline);
        }
    }
    public bool EditEvaluator(ServerEvaluator clientEval, int evalSID)
    {
        Console.WriteLine("edit. eval string: " + clientEval.ToString());

        ServerEvaluator serverEval = SqliteServer.SelectEvaluator(evalSID);

        //serveEval.Code is password
        //clientEval.Code is hash
        bool matches = BCrypt.CheckPassword(serverEval.Code, clientEval.Code);

        if (matches)
        {
            //put the uniqueID that corresponds in server
            clientEval.UniqueID = evalSID;

            //put the pass code instead of the client password hash
            clientEval.Code = serverEval.Code;

            clientEval.Update(false);             //do update
            return(true);
        }

        return(false);
    }