Example #1
0
        public void Execute(SubmitTurnCommandParam parameter)
        {
            this.Result = new SubmitTurnResult();

            if (!CanExecute(parameter))
            {
                return;
            }

            IWebCommunitcation cmd = m_Resolver.GetInstance <IWebCommunitcation>();

            GetGamesPlayersCommandResult gameresult;
            Game     foundGame;
            FileInfo file;

            GetObjects(parameter, out foundGame, out gameresult, out file);

            AuthenticateCommandResult auth = m_Resolver.GetInstance <AuthenticateCommandResult>();


            this.Result = cmd.UploadGame(file, auth.AuthID, foundGame.CurrentTurn.TurnId).Result;

            IOSSetting setting = this.m_Resolver.GetInstance <IOSSetting>();

            Archive archive = new Archive(setting);

            archive.MoveToArchive(file, foundGame.GameId);
            archive.KeepArchivedFiles(parameter.ArchivedFiles, foundGame.GameId);
        }
Example #2
0
        public bool CanExecute(SubmitTurnCommandParam parameter)
        {
            GetGamesPlayersCommandResult gameresult;
            Game     foundGame = null;
            FileInfo fileToUpload;

            GetObjects(parameter, out foundGame, out gameresult, out fileToUpload);

            if (null == foundGame || null == fileToUpload)
            {
                return(false);
            }

            string hashWhenItWasSaved = null;

            if (null == parameter.UseThisFileToUpload)
            {
                if (gameresult.TryGetHash(foundGame.GameId, out hashWhenItWasSaved))
                {
                    string hashNow = Helper.GetHashCode(File.ReadAllBytes(fileToUpload.FullName));
                    if ((string.Equals(hashWhenItWasSaved, hashNow, StringComparison.InvariantCulture)) && (null != hashWhenItWasSaved))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (!File.Exists(parameter.UseThisFileToUpload.FullName))
                {
                    return(false);
                }
            }

            AuthenticateCommandResult auth = m_Resolver.GetInstance <AuthenticateCommandResult>();

            if ((null == auth) || (!auth.Authenticated))
            {
                return(false);
            }

            return(true);
        }