private void processSAV(PKM[] data, List <StringInstruction> Filters, List <StringInstruction> Instructions)
        {
            len = err = ctr = 0;
            for (int i = 0; i < data.Length; i++)
            {
                var pkm = data[i];
                if (!pkm.Valid)
                {
                    b.ReportProgress(i);
                    continue;
                }

                ModifyResult r = ProcessPKM(pkm, Filters, Instructions);
                if (r != ModifyResult.Invalid)
                {
                    len++;
                }
                if (r == ModifyResult.Error)
                {
                    err++;
                }
                if (r == ModifyResult.Modified)
                {
                    if (pkm.Species != 0)
                    {
                        pkm.RefreshChecksum();
                    }
                    ctr++;
                }

                b.ReportProgress(i);
            }

            Main.SAV.BoxData = data;
        }
Exemple #2
0
        private bool ProcessPKM(PKM pkm, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!pkm.Valid || pkm.Locked)
            {
                len++;
                var reason = pkm.Locked ? "Locked." : "Not Valid.";
                Debug.WriteLine($"{MsgBEModifyFailBlocked} {reason}");
                return(false);
            }

            ModifyResult r = TryModifyPKM(pkm, Filters, Instructions);

            if (r != ModifyResult.Invalid)
            {
                len++;
            }
            if (r == ModifyResult.Error)
            {
                err++;
            }
            if (r != ModifyResult.Modified)
            {
                return(false);
            }
            if (pkm.Species <= 0)
            {
                return(false);
            }

            pkm.RefreshChecksum();
            ctr++;
            return(true);
        }
Exemple #3
0
        private bool processPKM(PKM pkm, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!pkm.Valid || pkm.Locked)
            {
                return(false);
            }

            ModifyResult r = tryModifyPKM(pkm, Filters, Instructions);

            if (r != ModifyResult.Invalid)
            {
                len++;
            }
            if (r == ModifyResult.Error)
            {
                err++;
            }
            if (r != ModifyResult.Modified)
            {
                return(false);
            }
            if (pkm.Species <= 0)
            {
                return(false);
            }

            pkm.RefreshChecksum();
            ctr++;
            return(true);
        }
Exemple #4
0
        private void processFolder(string[] files, List <StringInstruction> Filters, List <StringInstruction> Instructions, string destPath)
        {
            len = err = ctr = 0;
            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];
                if (!PKX.getIsPKM(new FileInfo(file).Length))
                {
                    b.ReportProgress(i);
                    continue;
                }

                byte[]       data = File.ReadAllBytes(file);
                var          pkm  = PKMConverter.getPKMfromBytes(data);
                ModifyResult r    = ProcessPKM(pkm, Filters, Instructions);
                if (r != ModifyResult.Invalid)
                {
                    len++;
                }
                if (r == ModifyResult.Error)
                {
                    err++;
                }
                if (r == ModifyResult.Modified)
                {
                    if (pkm.Species > 0)
                    {
                        ctr++;
                        File.WriteAllBytes(Path.Combine(destPath, Path.GetFileName(file)), pkm.DecryptedBoxData);
                    }
                }

                b.ReportProgress(i);
            }
        }
Exemple #5
0
        private bool ProcessPKM(PKM pkm, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!pkm.Valid || pkm.Locked)
            {
                len++;
                Debug.WriteLine("Skipped a pkm due to disallowed input: " + (pkm.Locked ? "Locked." : "Not Valid."));
                return(false);
            }

            ModifyResult r = TryModifyPKM(pkm, Filters, Instructions);

            if (r != ModifyResult.Invalid)
            {
                len++;
            }
            if (r == ModifyResult.Error)
            {
                err++;
            }
            if (r != ModifyResult.Modified)
            {
                return(false);
            }
            if (pkm.Species <= 0)
            {
                return(false);
            }

            pkm.RefreshChecksum();
            ctr++;
            return(true);
        }
Exemple #6
0
        private void processSAV(PKM[] data, List <StringInstruction> Filters, List <StringInstruction> Instructions)
        {
            len = err = ctr = 0;
            for (int i = 0; i < data.Length; i++)
            {
                var          pkm = data[i];
                ModifyResult r   = ProcessPKM(pkm, Filters, Instructions);
                if (r != ModifyResult.Invalid)
                {
                    len++;
                }
                if (r == ModifyResult.Error)
                {
                    err++;
                }
                if (r == ModifyResult.Modified)
                {
                    ctr++;
                }

                b.ReportProgress(i);
            }

            Main.SAV.BoxData = data;
        }
Exemple #7
0
        private static ModifyResult TryModifyPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            Type    pkm  = PKM.GetType();
            PKMInfo info = new PKMInfo(PKM);

            ModifyResult result = ModifyResult.Error;

            foreach (var cmd in Filters)
            {
                try
                {
                    if (IsPKMFiltered(pkm, cmd, info, out result))
                    {
                        return(result); // why it was filtered out
                    }
                }
                catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }

            foreach (var cmd in Instructions)
            {
                try
                {
                    result = SetPKMProperty(PKM, info, cmd);
                }
                catch { Debug.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return(result);
        }
Exemple #8
0
        private static ModifyResult ProcessPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            Type pkm = PKM.GetType();

            foreach (var cmd in Filters)
            {
                try
                {
                    if (!pkm.HasProperty(cmd.PropertyName))
                    {
                        return(ModifyResult.Filtered);
                    }
                    if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
                    {
                        return(ModifyResult.Filtered);
                    }
                }
                catch
                {
                    Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    return(ModifyResult.Filtered);
                }
            }

            ModifyResult result = ModifyResult.Error;

            foreach (var cmd in Instructions)
            {
                try
                {
                    if (cmd.PropertyValue == CONST_RAND && (cmd.PropertyName == "PID" || cmd.PropertyName == "EncryptionConstant"))
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString());
                    }
                    else if (cmd.PropertyValue == CONST_SHINY && cmd.PropertyName == "PID")
                    {
                        PKM.setShinyPID();
                    }
                    else if (cmd.PropertyValue == "0" && cmd.PropertyName == "Species")
                    {
                        PKM.Data = new byte[PKM.Data.Length];
                    }
                    else
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue);
                    }

                    result = ModifyResult.Modified;
                }
                catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return(result);
        }
Exemple #9
0
        public ModifyResult Update(int personId, PersonAttribute attribute)
        {
            Arena.Core.Person person = new Arena.Core.Person(personId);
            var modifyResult         = new ModifyResult();

            try {
                Core.Attribute coreAttribute = null;
                if (attribute.AttributeID > 0)
                {
                    coreAttribute = person.Attributes.FindByID(attribute.AttributeID);
                    if (coreAttribute == null)
                    {
                        coreAttribute = new Core.PersonAttribute(attribute.AttributeID);
                        person.Attributes.Add(coreAttribute);
                    }
                }
                else
                {
                    modifyResult.Successful   = "False";
                    modifyResult.ErrorMessage = "Attribute ID is required.";
                    return(modifyResult);
                }
                if (!coreAttribute.Allowed(Security.OperationType.Edit,
                                           Arena.Core.ArenaContext.Current.User, person))
                {
                    modifyResult.Successful   = "False";
                    modifyResult.ErrorMessage = "Permission denied to edit attribute.";
                    return(modifyResult);
                }

                coreAttribute.AttributeName = attribute.AttributeName;
                if (coreAttribute.AttributeType == Enums.DataType.String)
                {
                    coreAttribute.StringValue = attribute.StringValue;
                }
                if (coreAttribute.AttributeType == Enums.DataType.DateTime)
                {
                    coreAttribute.DateValue = attribute.DateValue.GetValueOrDefault();
                }
                if (coreAttribute.AttributeType == Enums.DataType.Decimal)
                {
                    coreAttribute.DecimalValue = attribute.DecimalValue.GetValueOrDefault();
                }
                if (coreAttribute.AttributeType == Enums.DataType.Int)
                {
                    coreAttribute.IntValue = attribute.IntValue.GetValueOrDefault();
                }
                person.SaveAttributes(Arena.Core.ArenaContext.Current.Organization.OrganizationID,
                                      Arena.Core.ArenaContext.Current.User.Identity.Name);
                modifyResult.Successful = "True";
            } catch (Exception e)            {
                modifyResult.Successful   = "False";
                modifyResult.ErrorMessage = e.Message;
            }

            return(modifyResult);
        }
        public ModifyResult Update(int personId, PersonAttribute attribute)
        {
            Arena.Core.Person person = new Arena.Core.Person(personId);
            var modifyResult = new ModifyResult();
            try {
                Core.Attribute coreAttribute = null;
                if (attribute.AttributeID > 0)
                {
                    coreAttribute = person.Attributes.FindByID(attribute.AttributeID);
                    if (coreAttribute == null)
                    {
                        coreAttribute = new Core.PersonAttribute(attribute.AttributeID);
                        person.Attributes.Add(coreAttribute);
                    }
                }
                else
                {
                    modifyResult.Successful = "False";
                    modifyResult.ErrorMessage = "Attribute ID is required.";
                    return modifyResult;
                }
                if (!coreAttribute.Allowed(Security.OperationType.Edit,
                    Arena.Core.ArenaContext.Current.User, person))
                {
                    modifyResult.Successful = "False";
                    modifyResult.ErrorMessage = "Permission denied to edit attribute.";
                    return modifyResult;
                }

                coreAttribute.AttributeName = attribute.AttributeName;
                if (coreAttribute.AttributeType == Enums.DataType.String)
                {
                    coreAttribute.StringValue = attribute.StringValue;
                }
                if (coreAttribute.AttributeType == Enums.DataType.DateTime)
                {
                    coreAttribute.DateValue = attribute.DateValue.GetValueOrDefault();
                }
                if (coreAttribute.AttributeType == Enums.DataType.Decimal)
                {
                    coreAttribute.DecimalValue = attribute.DecimalValue.GetValueOrDefault();
                }
                if (coreAttribute.AttributeType == Enums.DataType.Int)
                {
                    coreAttribute.IntValue = attribute.IntValue.GetValueOrDefault();
                }
                person.SaveAttributes(Arena.Core.ArenaContext.Current.Organization.OrganizationID,
                    Arena.Core.ArenaContext.Current.User.Identity.Name);
                modifyResult.Successful = "True";
            } catch (Exception e)            {
                modifyResult.Successful = "False";
                modifyResult.ErrorMessage = e.Message;
            }

            return modifyResult;
        }
Exemple #11
0
        /// <summary>
        /// Tries to modify the <see cref="PKMInfo"/>.
        /// </summary>
        /// <param name="pk">Command Filter</param>
        /// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
        /// <param name="modifications">Modifications to perform on the <see cref="pk"/>.</param>
        /// <returns>Result of the attempted modification.</returns>
        internal static ModifyResult TryModifyPKM(PKM pk, IEnumerable <StringInstruction> filters, IEnumerable <StringInstruction> modifications)
        {
            if (!pk.ChecksumValid || pk.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            PKMInfo info = new PKMInfo(pk);
            var     pi   = Props[Array.IndexOf(Types, pk.GetType())];

            foreach (var cmd in filters)
            {
                try
                {
                    if (!IsFilterMatch(cmd, info, pi))
                    {
                        return(ModifyResult.Filtered);
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                // Swallow any error because this can be malformed user input.
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    Debug.WriteLine(MsgBEModifyFailCompare + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue);
                    return(ModifyResult.Error);
                }
            }

            ModifyResult result = ModifyResult.Modified;
            foreach (var cmd in modifications)
            {
                try
                {
                    var tmp = SetPKMProperty(cmd, info, pi);
                    if (tmp != ModifyResult.Modified)
                    {
                        result = tmp;
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                // Swallow any error because this can be malformed user input.
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    Debug.WriteLine(MsgBEModifyFail + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue);
                }
            }
            return(result);
        }
Exemple #12
0
        public override ModifyResult Modify(Item item, IEnumerable <StringInstruction> filters, IEnumerable <StringInstruction> modifications)
        {
            var pi = Reflect.Props[Array.IndexOf(Reflect.Types, item.GetType())];

            foreach (var cmd in filters)
            {
                try
                {
                    if (!IsFilterMatch(cmd, item, pi))
                    {
                        return(ModifyResult.Filtered);
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                // Swallow any error because this can be malformed user input.
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    Debug.WriteLine($"Failed to compare: {ex.Message} - {cmd.PropertyName} {cmd.PropertyValue}");
                    return(ModifyResult.Error);
                }
            }

            ModifyResult result = ModifyResult.Modified;
            foreach (var cmd in modifications)
            {
                try
                {
                    var tmp = SetProperty(cmd, item, pi);
                    if (tmp != ModifyResult.Modified)
                    {
                        result = tmp;
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                // Swallow any error because this can be malformed user input.
                catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    Debug.WriteLine($"Failed to modify: {ex.Message} - {cmd.PropertyName} {cmd.PropertyValue}");
                }
            }
            return(result);
        }
Exemple #13
0
        /// <summary>
        /// Tries to modify the <see cref="PKMInfo"/>.
        /// </summary>
        /// <param name="pkm">Command Filter</param>
        /// <param name="filters">Filters which must be satisfied prior to any modifications being made.</param>
        /// <param name="modifications">Modifications to perform on the <see cref="pkm"/>.</param>
        /// <returns>Result of the attempted modification.</returns>
        internal static ModifyResult TryModifyPKM(PKM pkm, IEnumerable <StringInstruction> filters, IEnumerable <StringInstruction> modifications)
        {
            if (!pkm.ChecksumValid || pkm.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            PKMInfo info = new PKMInfo(pkm);
            var     pi   = Props[Array.IndexOf(Types, pkm.GetType())];

            foreach (var cmd in filters)
            {
                try
                {
                    if (!IsFilterMatch(cmd, info, pi))
                    {
                        return(ModifyResult.Filtered);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(MsgBEModifyFailCompare + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue);
                    return(ModifyResult.Error);
                }
            }

            ModifyResult result = ModifyResult.Modified;

            foreach (var cmd in modifications)
            {
                try
                {
                    var tmp = SetPKMProperty(cmd, info, pi);
                    if (result != ModifyResult.Modified)
                    {
                        result = tmp;
                    }
                }
                catch (Exception ex) { Debug.WriteLine(MsgBEModifyFail + " " + ex.Message, cmd.PropertyName, cmd.PropertyValue); }
            }
            return(result);
        }
Exemple #14
0
        public async Task SubMentionAsync(int Index)
        {
            ModifyResult res = Global.SubTagHandler.ModifyMentions(Context.Channel.Id, Index - 1, Context.User.Id);

            switch (res)
            {
            case ModifyResult.NoSubtagsInChannel:
            case ModifyResult.OutOfRange:
                await Context.Channel.SendMessageAsync(GetEntry("NoTags"));

                break;

            case ModifyResult.Added:
                await Context.Channel.SendMessageAsync(GetEntry("Added"));

                break;

            case ModifyResult.Removed:
                await Context.Channel.SendMessageAsync(GetEntry("Removed"));

                break;
            }
        }
        /// <summary>
        /// Create/Update actually shares the same method
        /// </summary>        
        /// <param name="auth">The authorization service contract object</param>
        /// <returns></returns>
        private ModifyResult CreateOrUpdate(OAuthAuthorization auth)
        {
            var modifyResult = new ModifyResult();
            if (auth.ClientId == 0)
            {
                modifyResult.Successful = "False";
                modifyResult.ErrorMessage = "ClientId must be set";
                return modifyResult;
            }

            if (auth.LoginId == null && auth.LoginId == "")
            {
                modifyResult.Successful = "False";
                modifyResult.ErrorMessage = "LoginId must be set";
                return modifyResult;
            }

            Arena.Custom.SECC.OAuth.Authorization dbAuth;

            if (auth.AuthorizationId > 0)
            {
                dbAuth = new Arena.Custom.SECC.OAuth.Authorization(auth.AuthorizationId);
            }
            else
            {
                dbAuth = new Arena.Custom.SECC.OAuth.Authorization();
            }

            try
            {
                dbAuth.Active = auth.Active;
                dbAuth.ClientId = auth.ClientId;
                dbAuth.LoginId = auth.LoginId;
                if (auth.ScopeId > 0)
                {
                    dbAuth.ScopeId = auth.ScopeId;
                }
                else if(auth.ScopeIdentifier != null)
                {
                    var scope = new Arena.Custom.SECC.OAuth.Scope(auth.ScopeIdentifier);
                    if (scope != null)
                    {
                        dbAuth.ScopeId = scope.ScopeId;
                    }
                    else {
                        modifyResult.Successful = "False";
                        modifyResult.ErrorMessage = "ScopeId or ScopeIdentifier is required";
                        return modifyResult;
                    }
                }
                else
                {
                    modifyResult.Successful = "False";
                    modifyResult.ErrorMessage = "ScopeId or ScopeIdentifier is required";
                    return modifyResult;
                }

                if (!dbAuth.Allowed(Security.OperationType.Edit,
                    Arena.Core.ArenaContext.Current.User))
                {
                    modifyResult.Successful = "False";

                    StackFrame frame = new StackFrame(1);
                    modifyResult.ErrorMessage = "Permission denied to " + frame.GetMethod().Name.ToLower() + " authorization.";
                    return modifyResult;
                }

                dbAuth.Save();

                modifyResult.Successful = "True";
            }
            catch (Exception e)
            {
                modifyResult.Successful = "False";
                modifyResult.ErrorMessage = e.Message;
            }

            return modifyResult;
        }
Exemple #16
0
        /// <summary>
        /// Create/Update actually shares the same method
        /// </summary>
        /// <param name="auth">The authorization service contract object</param>
        /// <returns></returns>
        private ModifyResult CreateOrUpdate(OAuthAuthorization auth)
        {
            var modifyResult = new ModifyResult();

            if (auth.ClientId == 0)
            {
                modifyResult.Successful   = "False";
                modifyResult.ErrorMessage = "ClientId must be set";
                return(modifyResult);
            }

            if (auth.LoginId == null && auth.LoginId == "")
            {
                modifyResult.Successful   = "False";
                modifyResult.ErrorMessage = "LoginId must be set";
                return(modifyResult);
            }

            Arena.Custom.SECC.OAuth.Authorization dbAuth;

            if (auth.AuthorizationId > 0)
            {
                dbAuth = new Arena.Custom.SECC.OAuth.Authorization(auth.AuthorizationId);
            }
            else
            {
                dbAuth = new Arena.Custom.SECC.OAuth.Authorization();
            }

            try
            {
                dbAuth.Active   = auth.Active;
                dbAuth.ClientId = auth.ClientId;
                dbAuth.LoginId  = auth.LoginId;
                if (auth.ScopeId > 0)
                {
                    dbAuth.ScopeId = auth.ScopeId;
                }
                else if (auth.ScopeIdentifier != null)
                {
                    var scope = new Arena.Custom.SECC.OAuth.Scope(auth.ScopeIdentifier);
                    if (scope != null)
                    {
                        dbAuth.ScopeId = scope.ScopeId;
                    }
                    else
                    {
                        modifyResult.Successful   = "False";
                        modifyResult.ErrorMessage = "ScopeId or ScopeIdentifier is required";
                        return(modifyResult);
                    }
                }
                else
                {
                    modifyResult.Successful   = "False";
                    modifyResult.ErrorMessage = "ScopeId or ScopeIdentifier is required";
                    return(modifyResult);
                }

                if (!dbAuth.Allowed(Security.OperationType.Edit,
                                    Arena.Core.ArenaContext.Current.User))
                {
                    modifyResult.Successful = "False";

                    StackFrame frame = new StackFrame(1);
                    modifyResult.ErrorMessage = "Permission denied to " + frame.GetMethod().Name.ToLower() + " authorization.";
                    return(modifyResult);
                }

                dbAuth.Save();

                modifyResult.Successful = "True";
            }
            catch (Exception e)
            {
                modifyResult.Successful   = "False";
                modifyResult.ErrorMessage = e.Message;
            }

            return(modifyResult);
        }
Exemple #17
0
 private static bool IsPKMFiltered(Type pkm, StringInstruction cmd, PKMInfo info, out ModifyResult result)
 {
     result = ModifyResult.Error;
     if (cmd.PropertyName == PROP_LEGAL)
     {
         if (!bool.TryParse(cmd.PropertyValue, out bool legal))
         {
             return(true);
         }
         if (legal == info.Legal == cmd.Evaluator)
         {
             return(false);
         }
         result = ModifyResult.Filtered;
         return(true);
     }
     if (!pkm.HasPropertyAll(cmd.PropertyName) ||
         pkm.IsValueEqual(info.pkm, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
     {
         result = ModifyResult.Filtered;
         return(true);
     }
     return(false);
 }
Exemple #18
0
        public ModifyResult Create(Person person)
        {
            var modifyResult = new ModifyResult();

            // We have a minimum set of data required
            if (person.LastName == null || person.LastName.Length < 2)
            {
                ModifyValidationResult result = new ModifyValidationResult();
                result.Key = "ShortLastName";
                result.Message = "Last name must be at least 2 characters";
                modifyResult.ValidationResults.Add(result);
            }
            if (person.FirstName == null || person.FirstName.Length < 2)
            {
                ModifyValidationResult result = new ModifyValidationResult();
                result.Key = "ShortFirstName";
                result.Message = "First name must be at least 2 characters";
                modifyResult.ValidationResults.Add(result);
            }
            if (person.BirthDate == null
                && person.HomePhone == null
                && person.FirstActiveEmail == null)
            {
                ModifyValidationResult result = new ModifyValidationResult();
                result.Key = "NotEnoughInfo";
                result.Message = "At least one of the following fields is required: Birth Date, Home Phone, or Email Adress";
                modifyResult.ValidationResults.Add(result);
            }

            if (modifyResult.ValidationResults.Count > 0)
            {
                modifyResult.Successful = "False";
                return modifyResult;
            }
            try {
                PersonMatch pm = new PersonMatch();
                pm.FirstName = person.FirstName;
                pm.LastName = person.LastName;
                pm.Email = person.FirstActiveEmail;
                pm.HomePhone = person.HomePhone;

                if (person.Addresses.Count > 0) {
                    pm.Address.Street = person.Addresses.FirstOrDefault().StreetLine1;
                    pm.Address.City = person.Addresses.FirstOrDefault().City;
                    pm.Address.State = person.Addresses.FirstOrDefault().State;
                    pm.Address.PostalCode = person.Addresses.FirstOrDefault().PostalCode;
                }
                Core.Person corePerson = pm.MatchOrCreateArenaPerson();
                if (corePerson != null)
                {
                    modifyResult.Successful = "True";
                    modifyResult.Link = String.Format("cust/secc/person/{0}", corePerson.PersonID);
                }
            }
            catch (Exception e)
            {
                modifyResult.Successful = "False";
                modifyResult.ErrorMessage = e.Message;
            }
            return modifyResult;
        }
        public Arena.Services.Contracts.ModifyResult ImIn(Contracts.ImIn imIn)
        {
            ModifyResult result = new ModifyResult();

            result.Successful = true.ToString();
            result.Link       = "/person/1234";

            // First Name
            if (String.IsNullOrEmpty(imIn.FirstName))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "FirstNameMissing", Message = "First Name is required."
                });
                result.Link = null;
            }

            // Last Name
            if (String.IsNullOrEmpty(imIn.LastName))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "LastNameMissing", Message = "Last Name is required."
                });
                result.Link = null;
            }

            // DOB
            if (imIn.DateOfBirth == null || imIn.DateOfBirth == default(DateTime))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "DOBMissingOrInvalid", Message = "Date of Birth required and must be valid."
                });
                result.Link = null;
            }

            // Phone Number
            if (String.IsNullOrEmpty(imIn.PhoneNumber))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "PhoneNumberMissing", Message = "Phone Number is required."
                });
                result.Link = null;
            }
            else
            {
                // Match the phone number format
                if (!Regex.Match(imIn.PhoneNumber, @"^(\([2-9]\d\d\)|[2-9]\d\d) ?[-.,]? ?[2-9]\d\d ?[-.,]? ?\d{4}$").Success)
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "PhoneNumberInvalid", Message = "Phone Number format is invalid: (502) 253-8000"
                    });
                    result.Link = null;
                }
            }

            // Email
            if (!String.IsNullOrEmpty(imIn.Email))
            {
                // No more required email

                /*    result.Successful = false.ToString();
                 *  result.ValidationResults.Add(new ModifyValidationResult() { Key = "EmailMissing", Message = "Email is required." });
                 *  result.Link = null;
                 * }
                 * else
                 * {*/
                // Match the email format
                if (!Regex.Match(imIn.Email, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").Success)
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "EmailInvalid", Message = "Email format is invalid: [email protected]"
                    });
                    result.Link = null;
                }
            }


            // Phone Type
            Lookup phoneType = new Lookup();
            // Get all the phone number types
            LookupCollection lc = new LookupCollection();

            lc.LoadByType(38);
            String activeTypes = lc.Where(e => e.Active).Select(e => e.Value).Aggregate((current, next) => current + ", " + next);

            if (String.IsNullOrEmpty(imIn.PhoneType))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "PhoneTypeInvalid", Message = "Phone type is invalid (" + activeTypes + ")"
                });
                result.Link = null;
            }
            else
            {
                phoneType = lc.Where(e => e.Value == imIn.PhoneType).FirstOrDefault();

                if (phoneType == null)
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "PhoneTypeInvalid", Message = "Phone type is invalid (" + activeTypes + ")"
                    });
                    result.Link = null;
                }
            }

            // Validate the campus
            if (String.IsNullOrEmpty(imIn.Campus))
            {
                result.Successful = false.ToString();
                result.ValidationResults.Add(new ModifyValidationResult()
                {
                    Key = "CampusInvalid", Message = "Campus is required."
                });
                result.Link = null;
            }



            if (result.Successful == true.ToString())
            {
                Arena.Custom.SECC.Common.Data.Person.ImIn imInTarget = new Arena.Custom.SECC.Common.Data.Person.ImIn();
                AutoMapper.Mapper.CreateMap <Contracts.ImIn, Arena.Custom.SECC.Common.Data.Person.ImIn>();
                AutoMapper.Mapper.Map <Contracts.ImIn, Arena.Custom.SECC.Common.Data.Person.ImIn>(imIn, imInTarget);
                Arena.Custom.SECC.Common.Util.ImIn imInUtil = new Arena.Custom.SECC.Common.Util.ImIn();
                if (!imInUtil.process(imInTarget))
                {
                    result.Successful = false.ToString();
                    result.ValidationResults.Add(new ModifyValidationResult()
                    {
                        Key = "ImInGeneralError", Message = "Something went wrong processing the I'm In request."
                    });
                }
            }

            return(result);
        }
Exemple #20
0
        /// <summary>
        /// Returns the message for the given
        /// custom content modification result.
        /// </summary>
        /// <param name="resCode">Modification Result Code</param>
        /// <returns>Message for display</returns>
        public static string GetResultName(ModifyResult resCode)
        {
            switch (resCode)
            {
            case ModifyResult.kFailed:
                return("Failed");

            case ModifyResult.kCriticalSystemFailed:
                return("Critical System Failed");

            case ModifyResult.kCacheEntryCorrupted:
                return("Cache Entry Corrupted");

            case ModifyResult.kCASSimImportFailed:
                return("CAS Sim Import Failed");

            case ModifyResult.kReadOnlyMode:
                return("Read Only Mode");

            case ModifyResult.kFileNotExist:
                return("File Does Not Exist");

            case ModifyResult.kCanNotOpenFile:
                return("Can't Open File");

            case ModifyResult.kCanNotOpenPackage:
                return("Can't Open Package");

            case ModifyResult.kPackageCorrupted:
                return("Package Corrupted");

            case ModifyResult.kMissingManifest:
                return("Missing Manifest");

            case ModifyResult.kPackageNotFound:
                return("Package Not Found");

            case ModifyResult.kHasDependents:
                return("Has Dependents");

            case ModifyResult.kRequiresMissingEP:
                return("Requires Missing Expansion Pack");

            case ModifyResult.kRequiresGameUpdate:
                return("Requires Game Update");

            case ModifyResult.kRequiresMissingPaidObject:
                return("Requires Missing Paid Object");

            case ModifyResult.kWorldAlreadyInstalled:
                return("World Already Installed");

            case ModifyResult.kPackageAlreadyInstalled:
                return("Package Already Installed");

            case ModifyResult.kSuccess:
                if (gGameUtils == null || gGameUtils.GetCommandLineSwitch("ccuninstall") == null)
                {
                    return("Success");
                }
                return("Successfully Uninstalled");

            case ModifyResult.kNeedsRestart:
                return("Needs Restart");

            case ModifyResult.kMissingDependency:
                return("Missing Dependancy");

            case ModifyResult.kMissingPaidContent:
                return("Missing Paid Content");

            case ModifyResult.kMissingEPDependency:
                return("Missing Expansion Pack Dependency");
            }
            return("Unknown Error");
        }
Exemple #21
0
        private static ModifyResult tryModifyPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            Type    pkm  = PKM.GetType();
            PKMInfo info = new PKMInfo(PKM);

            foreach (var cmd in Filters)
            {
                try
                {
                    if (cmd.PropertyName == PROP_LEGAL)
                    {
                        bool legal;
                        if (!bool.TryParse(cmd.PropertyValue, out legal))
                        {
                            return(ModifyResult.Error);
                        }
                        if (legal == info.Legal == cmd.Evaluator)
                        {
                            continue;
                        }
                        return(ModifyResult.Filtered);
                    }
                    if (!pkm.HasProperty(cmd.PropertyName))
                    {
                        return(ModifyResult.Filtered);
                    }
                    if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
                    {
                        return(ModifyResult.Filtered);
                    }
                }
                catch
                {
                    Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    return(ModifyResult.Filtered);
                }
            }

            ModifyResult result = ModifyResult.Error;

            foreach (var cmd in Instructions)
            {
                try
                {
                    if (cmd.PropertyValue == CONST_SUGGEST)
                    {
                        result = setSuggestedProperty(PKM, cmd, info)
                            ? ModifyResult.Modified
                            : ModifyResult.Error;
                    }
                    else
                    {
                        setProperty(PKM, cmd);
                        result = ModifyResult.Modified;
                    }
                }
                catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return(result);
        }
Exemple #22
0
        /// <summary>
        /// Return the localized message for the given
        /// custom content modification result.
        /// </summary>
        /// <param name="resCode">Modification Result Code</param>
        /// <returns>Localized message for display</returns>
        /// <remarks>
        /// Copied from <see cref="M:Sims3.UI.BaseContentModify.GetResName(System.UInt32)"/>
        /// </remarks>
        public static string GetResultMessage(ModifyResult resCode)
        {
            switch (resCode)
            {
            case ModifyResult.kFailed:
                return(LocalizeString("Ui/Caption/Install:Failed"));

            case ModifyResult.kCriticalSystemFailed:
            case ModifyResult.kCacheEntryCorrupted:
                return(LocalizeString("Ui/Caption/Install:CriticalSystemFailed"));

            case ModifyResult.kCASSimImportFailed:
                return(LocalizeString("Ui/Caption/Install:CASSimImportFailed"));

            case ModifyResult.kReadOnlyMode:
                return(LocalizeString("Ui/Caption/Install:ReadOnlyMode"));

            case ModifyResult.kFileNotExist:
                return(LocalizeString("Ui/Caption/Install:FileNotExist"));

            case ModifyResult.kCanNotOpenFile:
                return(LocalizeString("Ui/Caption/Install:CanNotOpenFile"));

            case ModifyResult.kCanNotOpenPackage:
                return(LocalizeString("Ui/Caption/Install:CanNotOpenPackage"));

            case ModifyResult.kPackageCorrupted:
            case ModifyResult.kMissingManifest:
                return(LocalizeString("Ui/Caption/Install:PackageCorrupted"));

            case ModifyResult.kPackageNotFound:
                return(LocalizeString("Ui/Caption/Install:PackageNotFound"));

            case ModifyResult.kHasDependents:
                return(LocalizeString("Ui/Caption/Install:HasDependents"));

            case ModifyResult.kRequiresMissingEP:
                return(LocalizeString("Ui/Caption/Install:RequiresMissingEP"));

            case ModifyResult.kRequiresGameUpdate:
                return(LocalizeString("Ui/Caption/Install:RequiresGameUpdate"));

            case ModifyResult.kRequiresMissingPaidObject:
                return(LocalizeString("Ui/Caption/Install:RequiresMissingPaidObject"));

            case ModifyResult.kWorldAlreadyInstalled:
            case ModifyResult.kPackageAlreadyInstalled:
                return(LocalizeString("Ui/Caption/Install:PackageAlreadyInstalled"));

            case ModifyResult.kSuccess:
                if (gGameUtils == null || gGameUtils.GetCommandLineSwitch("ccuninstall") == null)
                {
                    return(LocalizeString("Ui/Caption/Install:Success"));
                }
                return(LocalizeString("Ui/Caption/Install:UninstallSuccess"));

            case ModifyResult.kNeedsRestart:
                return(LocalizeString("Ui/Caption/Install:NeedsRestart"));

            case ModifyResult.kMissingDependency:
                return(LocalizeString("Ui/Caption/Install:MissingDependancy"));

            case ModifyResult.kMissingPaidContent:
                return(LocalizeString("Ui/Caption/Install:MissingPaidContent"));

            case ModifyResult.kMissingEPDependency:
                return(LocalizeString("Ui/Caption/Install:MissingEPDependency"));
            }
            return(LocalizeString("Ui/Caption/Install:UnknownError"));
        }
        private static ModifyResult ProcessPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions)
        {
            if (!PKM.ChecksumValid || PKM.Species == 0)
            {
                return(ModifyResult.Invalid);
            }

            Type pkm = PKM.GetType();

            foreach (var cmd in Filters)
            {
                try
                {
                    if (!pkm.HasProperty(cmd.PropertyName))
                    {
                        return(ModifyResult.Filtered);
                    }
                    if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator)
                    {
                        return(ModifyResult.Filtered);
                    }
                }
                catch
                {
                    Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}.");
                    return(ModifyResult.Filtered);
                }
            }

            ModifyResult result = ModifyResult.Error;

            foreach (var cmd in Instructions)
            {
                try
                {
                    if (cmd.PropertyName == "MetDate")
                    {
                        PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    }
                    else if (cmd.PropertyName == "EggMetDate")
                    {
                        PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    }
                    else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == CONST_RAND)
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString());
                    }
                    else if (cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_RAND)
                    {
                        PKM.setPIDGender(PKM.Gender);
                    }
                    else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == "PID")
                    {
                        PKM.EncryptionConstant = PKM.PID;
                    }
                    else if (cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_SHINY)
                    {
                        PKM.setShinyPID();
                    }
                    else if (cmd.PropertyName == "Species" && cmd.PropertyValue == "0")
                    {
                        PKM.Data = new byte[PKM.Data.Length];
                    }
                    else
                    {
                        ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue);
                    }

                    result = ModifyResult.Modified;
                }
                catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); }
            }
            return(result);
        }
Exemple #24
0
        public ModifyResult Create(Person person)
        {
            var modifyResult = new ModifyResult();

            // We have a minimum set of data required
            if (person.LastName == null || person.LastName.Length < 2)
            {
                ModifyValidationResult result = new ModifyValidationResult();
                result.Key     = "ShortLastName";
                result.Message = "Last name must be at least 2 characters";
                modifyResult.ValidationResults.Add(result);
            }
            if (person.FirstName == null || person.FirstName.Length < 2)
            {
                ModifyValidationResult result = new ModifyValidationResult();
                result.Key     = "ShortFirstName";
                result.Message = "First name must be at least 2 characters";
                modifyResult.ValidationResults.Add(result);
            }
            if (person.BirthDate == null &&
                person.HomePhone == null &&
                person.FirstActiveEmail == null)
            {
                ModifyValidationResult result = new ModifyValidationResult();
                result.Key     = "NotEnoughInfo";
                result.Message = "At least one of the following fields is required: Birth Date, Home Phone, or Email Adress";
                modifyResult.ValidationResults.Add(result);
            }

            if (modifyResult.ValidationResults.Count > 0)
            {
                modifyResult.Successful = "False";
                return(modifyResult);
            }
            try {
                PersonMatch pm = new PersonMatch();
                pm.FirstName = person.FirstName;
                pm.LastName  = person.LastName;
                pm.Email     = person.FirstActiveEmail;
                pm.HomePhone = person.HomePhone;

                if (person.Addresses.Count > 0)
                {
                    pm.Address.Street     = person.Addresses.FirstOrDefault().StreetLine1;
                    pm.Address.City       = person.Addresses.FirstOrDefault().City;
                    pm.Address.State      = person.Addresses.FirstOrDefault().State;
                    pm.Address.PostalCode = person.Addresses.FirstOrDefault().PostalCode;
                }
                Core.Person corePerson = pm.MatchOrCreateArenaPerson();
                if (corePerson != null)
                {
                    modifyResult.Successful = "True";
                    modifyResult.Link       = String.Format("cust/secc/person/{0}", corePerson.PersonID);
                }
            }
            catch (Exception e)
            {
                modifyResult.Successful   = "False";
                modifyResult.ErrorMessage = e.Message;
            }
            return(modifyResult);
        }