static void SerializeTriggerExecutionOrder <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                                   MegaloScriptModel model, ref int triggerIndex)
            where TDoc : class
            where TCursor : class
        {
            if (model.TagElementStreamSerializeFlags.EmbedObjects())
            {
                var id_resolving_ctxt = new TriggerIndexNameResolvingContext(model);
                var id_resolver       = TriggerIndexNameResolvingContext.IdResolver;
                var name_resolver     = TriggerIndexNameResolvingContext.NameResolver;

                s.StreamCursorIdAsString(ref triggerIndex, id_resolving_ctxt, id_resolver, name_resolver);
            }
            else
            {
                s.StreamCursor(ref triggerIndex);

                if (model.Triggers.SlotIsFreeOrInvalidIndex(triggerIndex))
                {
                    var ex = new System.IO.InvalidDataException(string.Format(
                                                                    "Couldn't define execution order for invalid trigger index {0}", triggerIndex));
                    s.ThrowReadException(ex);
                }
            }

            if (!model.Triggers[triggerIndex].TriggerType.IsUpdatedOnGameTick())
            {
                var ex = new System.IO.InvalidDataException(string.Format(
                                                                "Trigger '{0}' can't have its execution explicitly ordered",
                                                                triggerIndex.ToString()
                                                                ));
                s.ThrowReadException(ex);
            }
        }
예제 #2
0
        void IReplayService.SetReplayData(object replayData)
        {
            if (!(replayData is CapturedSettingsData networkData) &&
                !CapturedSettingsData.TryDeserialize(replayData, out networkData))
            {
                var inner = new System.IO.InvalidDataException($"Failed to deserialize data into `{nameof(CapturedSettingsData)}`.");
                throw new ArgumentException(inner.Message, nameof(replayData), inner);
            }

            SetReplayData(networkData);
        }
예제 #3
0
        internal void ValidateListCount(System.Collections.IList list, string listName
                                        , IO.ICanThrowReadExceptionsWithExtraDetails readExceptionThrower)
        {
            if (list.Count > MaxCount)
            {
                var ex = new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo,
                                                                          "{0} exceeded its maximum number of elements; {1} > {2}", listName, list.Count, MaxCount));

                readExceptionThrower.ThrowReadExeception(ex);
            }
        }
 public static void ValidateToken(Token token)
 {
     if (token is null)
     {
         throw new ArgumentNullException(nameof(token));
     }
     if (string.IsNullOrEmpty(token.Value))
     {
         var innerException = new System.IO.InvalidDataException("Empty tokens are invalid.");
         throw new ArgumentException(innerException.Message, nameof(token), innerException);
     }
 }
예제 #5
0
        public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            using (s.EnterOwnerBookmark(this))
            {
                s.StreamableElements("String", mStringReferences,
                                     this, _me => new LocaleStringTableReference(_me.mEngineLanguageTable));
            }

            if (Count > Capacity)
            {
                var ex = new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo,
                                                                          "Serialized multilingual string table with {0} strings, which exceeds its maximum of {1}",
                                                                          Count, kInfo.MaxCount));

                if (s.IsReading)
                {
                    s.ThrowReadException(ex);
                }
                else if (s.IsWriting)
                {
                    throw ex;
                }
            }

            if (s.IsReading)
            {
                if (kInfo.CodeNameEntries)
                {
                    Exception code_names_ex = SerializePostprocessCodeNames();
                    if (code_names_ex != null)
                    {
                        s.ThrowReadException(code_names_ex);
                    }
                }
            }
        }
예제 #6
0
        internal static Exception CreateException(AccountError err, string msg)
        {
            Log.Info(LogTag, "Got Error " + err + " throwing Exception with msg " + msg);
            Exception exp;

            switch (err)
            {
            case AccountError.InvalidParameter:
            {
                exp = new ArgumentException(msg + " Invalid Parameters Provided");
                break;
            }

            case AccountError.OutOfMemory:
            {
                exp = new OutOfMemoryException(msg + " Out Of Memory");
                break;
            }

            case AccountError.InvalidOperation:
            {
                exp = new InvalidOperationException(msg + " Inavlid operation");
                break;
            }

            case AccountError.NoData:
            {
                exp = new InvalidOperationException(msg + " Empty Data");
                break;
            }

            case AccountError.PermissionDenied:
            {
                exp = new UnauthorizedAccessException(msg + " Permission Denied");
                break;
            }

            case AccountError.DBFailed:
            {
                exp = new InvalidOperationException(msg + " DataBase Failed");
                break;
            }

            case AccountError.DBBusy:
            {
                exp = new InvalidOperationException(msg + " DataBase Busy");
                break;
            }

            case AccountError.QuerySyntaxError:
            {
                exp = new InvalidOperationException(msg + " Network Error");
                break;
            }

            case AccountError.XMLFileNotFound:
            {
                exp = new System.IO.FileNotFoundException(msg + " XML File not found");
                break;
            }

            case AccountError.XMLParseFailed:
            {
                exp = new System.IO.InvalidDataException(msg + " XML parse error");
                break;
            }

            default:
            {
                exp = new InvalidOperationException(err + " " + msg);
                break;
            }
            }

            return(exp);
        }