Example #1
0
        /// <summary>
        /// Read the settings file and inflate an object with the stored information.
        /// </summary>
        /// <param name="settings">Reference to the ServerSettings object which would be filled.</param>
        /// <returns>False if there was an error during the write task.</returns>
        public static Error.ErrorType ReadSettings(out ServerSettings settings)
        {
            Error.ErrorType success = Error.ErrorType.Ok;
            StreamReader    settingsStreamReader;
            XmlSerializer   settingsSerializer;
            XmlTextReader   settingsReader;

            settings = null;
            try
            {
                settingsStreamReader       = new StreamReader(KSPM.Globals.KSPMGlobals.Globals.IOFilePath + ServerSettings.SettingsFilename, System.Text.UTF8Encoding.UTF8);
                settingsReader             = new XmlTextReader(settingsStreamReader);
                settingsSerializer         = new XmlSerializer(typeof(ServerSettings));
                settings                   = (ServerSettings)settingsSerializer.Deserialize(settingsReader);
                settings.connectionsBackog = ServerSettings.ServerConnectionsBacklog;
            }
            catch (InvalidOperationException)
            {
                ServerSettings.DefaultSettings(out settings);
                success = ServerSettings.WriteSettings(ref settings);
            }
            catch (DirectoryNotFoundException ex)
            {
                success = Error.ErrorType.IODirectoryNotFound;
                KSPM.Globals.KSPMGlobals.Globals.Log.WriteTo(ex.Message);
            }
            catch (FileNotFoundException)
            {
                ServerSettings.DefaultSettings(out settings);
                success = ServerSettings.WriteSettings(ref settings);
            }
            return(success);
        }
Example #2
0
        /// <summary>
        /// Write the settings object into a Xml file using the UTF8 encoding.
        /// </summary>
        /// <param name="settings">Reference to the ServerSettings object</param>
        /// <returns>False if there was an error such as if the reference is set to a null.</returns>
        public static Error.ErrorType WriteSettings(ref ServerSettings settings)
        {
            Error.ErrorType success = Error.ErrorType.Ok;
            XmlTextWriter   settingsWriter;
            XmlSerializer   settingsSerializer;

            if (settings == null)
            {
                ServerSettings.DefaultSettings(out settings);
            }
            try
            {
                settingsWriter            = new XmlTextWriter(KSPM.Globals.KSPMGlobals.Globals.IOFilePath + ServerSettings.SettingsFilename, System.Text.UTF8Encoding.UTF8);
                settingsWriter.Formatting = Formatting.Indented;
                settingsSerializer        = new XmlSerializer(typeof(ServerSettings));
                settingsSerializer.Serialize(settingsWriter, settings);
                settingsWriter.Close();
            }
            catch (InvalidOperationException ex)
            {
                success = Error.ErrorType.IOFileCanNotBeWritten;
                KSPM.Globals.KSPMGlobals.Globals.Log.WriteTo(ex.Message);
            }
            catch (DirectoryNotFoundException)
            {
                success = Error.ErrorType.IODirectoryNotFound;
            }
            return(success);
        }
Example #3
0
        public async Task ShouldRollbackTransactionAfterFailureCommandExecution()
        {
            var invalidExecutionError = new Error.ErrorType("INVALID_EXECUTION", "Invalid execution").Build();
            var behavior = new TransactionalCommandsBehavior <Command, Result <int> >(_transactionProviderMock.Object, _transactionalBehaviorValidator);
            await behavior.Handle(new Command(), CancellationToken.None, () => Task.FromResult(Result.Fail <int>(invalidExecutionError)));

            _transactionProviderMock.Verify(provider => provider.RollbackTransactionAsync(), Times.Once);
        }
Example #4
0
        /**
         * Appends the specified Error to the end of this list.
         *
         * @param err	Error to be inserted.
         *
         * @return
         */
        public int Add(
            Error err)
        {
            this.maxSeverity = err.Type > this.maxSeverity ? err.Type : this.maxSeverity;
            this.errNumbers.Add(err.Id);

            if (err.FormField != null) {
                this.errFormFields.Add(err.FormField);
            }

            return base.Add(err);
        }
Example #5
0
 public override Error.ErrorType Punch(ref Socket client, string ip, int port)
 {
     Error.ErrorType error = Error.ErrorType.Ok;
     try
     {
         this.currentStatus = NATStatus.Connecting;
         ///Due to an specific Berkeley socket description which regards that a connectionless socket does not support to call sendTo on an already connected socket.
         /// So to avoid that Socket errorcode (10056) the Socket.Connect method is only called when it is not using a connectionless protocol.
         if (client.ProtocolType != ProtocolType.Udp)
         {
             client.Connect(ip, port);
         }
         this.currentStatus = NATStatus.Connected;
     }
     catch (System.Exception ex)
     {
         if (ex.GetType().Equals(typeof(SocketException)))
         {
             if (((SocketException)ex).ErrorCode == 10048)
             {
                 error = Error.ErrorType.NATAdrressInUse;
                 this.currentStatus = NATStatus.AddresInUse;
             }
         }
         else
         {
             //KSPM.Globals.KSPMGlobals.Globals.Log.WriteTo(ex.Message);
             error = Error.ErrorType.ClientUnableToConnect;
             this.currentStatus = NATStatus.Error;
         }
         if (client != null)
         {
             client.Close();
         }
     }
     return(error);
 }
        //DELETE, PUT
        protected IActionResult NoContentOrUnprocessableEntityOrNotFound(Result result, Error.ErrorType notFoundErrorType)
        {
            if (result.IsSuccess)
            {
                return(NoContent());
            }

            if (result.ViolatesOnly(notFoundErrorType))
            {
                return(NotFound());
            }

            return(UnprocessableEntity(result.Error));
        }
        //DELETE, PUT
        protected async Task <IActionResult> NoContentOrUnprocessableEntityOrNotFound <TCommand>(Result <TCommand> commandFactoryResult, Error.ErrorType notFoundErrorType)
            where TCommand : IRequest <Result>
        {
            var result = await commandFactoryResult
                         .OnSuccess(async query => await Mediator.Send(query));

            return(NoContentOrUnprocessableEntityOrNotFound(result, notFoundErrorType));
        }
Example #8
0
        /**
         * Appends the Error for the given ID to the list.
         *
         * @param id	ID of the Error to be inserted.
         *
         * @return		.
         */
        public int Add(
            long id)
        {
            Error err = null;
            int results = -1;

            try {
                err = this.getError(id);
                this.maxSeverity = (err.Type > this.maxSeverity) ? err.Type : this.maxSeverity;
                this.errNumbers.Add(id);
                this.errFormFields.Add(err.FormField);
                results = base.Add(err);
            } catch (Exception ex) {
                LogManager.GetCurrentClassLogger().Error(
                    errorMessage => errorMessage("ErrorList: Add (id): "), ex);
            }
            return results;
        }
Example #9
0
        public void AddItems(
            ErrorList list)
        {
            if (list != null) {
                try {
                    for (int i = 0; i < list.Count; i++) {
                        Error err = (Error) list[i];

                        this.maxSeverity = err.Type > this.maxSeverity ? err.Type : this.maxSeverity;
                        this.errNumbers.Add(err.Id);
                        this.errFormFields.Add(err.FormField);
                        base.Add(err);
                    }
                } catch (Exception ex) {
                    LogManager.GetCurrentClassLogger().Error(
                        errorMessage => errorMessage("ErrorList: AddItems: "), ex);
                }
            }
        }
Example #10
0
 public void errorOccured(string message, Error.ErrorType errorType)
 {
     m_errors.Add(new Error(message, errorType, 0, 0));
 }
Example #11
0
 public void errorOccured(string message, Error.ErrorType errorType, int lineNr, int linePosition)
 {
     m_errors.Add(new Error(message, errorType, lineNr, linePosition));
 }