コード例 #1
0
ファイル: LoginService.cs プロジェクト: wongn27/Recipe
        public bool DoesPasswordMatchHash(string email, string nonHashedPassword)
        {
            var user = context.Users.First(e => e.Email.Equals(email.ToLower()));

            var hashedPassword = StringHasher.Hash(nonHashedPassword);

            return(user.Password.Equals(hashedPassword));
        }
コード例 #2
0
        public void CreateAccount(User user)
        {
            if (HasAccount(user.Email))
            {
                throw new ArgumentException($"The user account with email address {user.Email} exists.");
            }

            if (!IsValidPassword(user.Password))
            {
                throw new Exception("The password provided is not valid. Must be a minimum length of 8 and at least one number!");
            }

            user.Email    = user.Email.ToLower();
            user.Password = StringHasher.Hash(user.Password);

            context.Users.Attach(user);
            context.Users.Add(user);
            context.SaveChanges();
        }
コード例 #3
0
        private void CreateTokenAndItem(object obj, out FullToken fullToken, out Item item)
        {
            Token  token;
            string tokenText;

            switch (Convert.GetTypeCode(obj))
            {
            case TypeCode.Boolean:
            {
                bool asBool = (bool)obj;
                tokenText = asBool ? "true" : "false";
                token     = asBool
                            ? new Token(TokenType.True, 0, tokenText.Length, StringHasher.TrueHash)
                            : new Token(TokenType.False, 0, tokenText.Length, StringHasher.FalseHash);
                item = new Item(ItemType.Value);
            }
            break;

            case TypeCode.Char:
            case TypeCode.String:
            case TypeCode.DateTime:
                tokenText = Convert.ToString(obj, CultureInfo.InvariantCulture);
                token     = new Token(TokenType.String, 0, tokenText.Length, StringHasher.Hash(tokenText));
                item      = new Item(ItemType.Value, tokenText);
                break;

            case TypeCode.Byte:
            case TypeCode.Decimal:
            case TypeCode.Double:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.SByte:
            case TypeCode.Single:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                tokenText = Convert.ToString(obj, CultureInfo.InvariantCulture);
                token     = new Token(TokenType.Number, 0, tokenText.Length, StringHasher.Hash(tokenText));
                item      = new Item(ItemType.Value, Convert.ToDecimal(obj, CultureInfo.InvariantCulture));
                break;

            case TypeCode.DBNull:
            case TypeCode.Empty:
                tokenText = "null";
                token     = new Token(TokenType.Null, 0, tokenText.Length, StringHasher.NullHash);
                item      = new Item(ItemType.Value);
                break;

            default:
            case TypeCode.Object:
            {
                TypeInfo  typeInfo  = this.typeCache.GetTypeInfo(obj.GetType());
                TokenType tokenType = typeInfo.IsArray
                            ? (typeInfo.ElementTypeInfo.IsKeyValuePair ? TokenType.ObjectValue : TokenType.ArrayValue)
                            : (typeInfo.SerializeAsObject ? TokenType.ObjectValue : TokenType.ArrayValue);

                tokenText = string.Empty;
                token     = new Token(tokenType, 0, 0, StringHasher.NullHash);
                item      = (tokenType == TokenType.ArrayValue)
                            ? new Item(ItemType.ArrayStart, (obj is ICollection collection) ? collection.Count : 0)
                            : new Item(ItemType.ObjectStart);
            }
            break;
            }

            fullToken = new FullToken(token, tokenText, 0, 0);
        }
コード例 #4
0
        public override bool Compile(GameAssetType gameAsset, Uri baseUri, BinaryAsset asset, XmlNode node, GameDefinition game,
                                     string trace, ref int position, out string ErrorDescription)
        {
            foreach (BaseEntryType entry in gameAsset.Runtime.Entries)
            {
                if (entry.id == "Channels")
                {
                    continue;
                }
                if (!entry.Compile(baseUri, asset, node, game, "W3DAnimation", ref position, out ErrorDescription))
                {
                    return(false);
                }
            }
            uint numFrames                 = uint.Parse(node.Attributes.GetNamedItem("NumFrames").Value);
            uint timecodedHash             = StringHasher.Hash("AnimationChannelTimecoded");
            List <BinaryAsset> channelList = new List <BinaryAsset>();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name == "Channels")
                {
                    foreach (XmlNode channelNode in childNode)
                    {
                        if (channelNode.Name == "ChannelScalar" || channelNode.Name == "ChannelQuaternion")
                        {
                            BinaryAsset channelAsset = new BinaryAsset(36);
                            int         subPosition  = 0;
                            FileHelper.SetUInt(timecodedHash, subPosition, channelAsset.Content);
                            subPosition += 4;
                            string   value          = channelNode.Attributes.GetNamedItem("Type").Value;
                            string[] enumValueNames = typeof(AnimationChannelType).GetEnumNames();
                            for (int idx = 0; idx < enumValueNames.Length; ++idx)
                            {
                                if (enumValueNames[idx] == value)
                                {
                                    FileHelper.SetInt(idx, subPosition, channelAsset.Content);
                                    break;
                                }
                            }
                            subPosition += 4;
                            FileHelper.SetUInt(numFrames, subPosition, channelAsset.Content);
                            subPosition += 4;
                            int vectorLenPosition = subPosition;
                            subPosition += 4;
                            FileHelper.SetUShort(ushort.Parse(channelNode.Attributes.GetNamedItem("Pivot").Value), subPosition, channelAsset.Content);
                            subPosition += 4;
                            uint firstFrame = uint.Parse(channelNode.Attributes.GetNamedItem("FirstFrame").Value);
                            if (channelNode.Name == "ChannelScalar")
                            {
                                FileHelper.SetUInt(1, vectorLenPosition, channelAsset.Content);
                                FileHelper.SetUInt(numFrames, subPosition, channelAsset.Content);
                                subPosition += 4;
                                BinaryAsset frameAndBinaryFlagList = null;
                                int         sageUnsignedShortCount = 2 - ((int)numFrames & 1);
                                if (sageUnsignedShortCount == 2)
                                {
                                    frameAndBinaryFlagList = new BinaryAsset((int)numFrames << 1);
                                }
                                else
                                {
                                    frameAndBinaryFlagList = new BinaryAsset(((int)numFrames + sageUnsignedShortCount) << 1);
                                }
                                channelAsset.SubAssets.Add(subPosition, frameAndBinaryFlagList);
                                subPosition += 4;
                                for (ushort idx = 0; idx < numFrames; ++idx)
                                {
                                    FileHelper.SetUShort(idx, idx << 1, frameAndBinaryFlagList.Content);
                                }
                                FileHelper.SetUInt(numFrames, subPosition, channelAsset.Content);
                                subPosition += 4;
                                BinaryAsset valuesList = new BinaryAsset((int)numFrames << 2);
                                channelAsset.SubAssets.Add(subPosition, valuesList);
                                int index         = 0;
                                int frame         = int.Parse(channelNode.Attributes.GetNamedItem("FirstFrame").Value);
                                int framePosition = 0;
                                foreach (XmlNode frameNode in channelNode.ChildNodes)
                                {
                                    if (frameNode.Name == "Frame")
                                    {
                                        if (index < firstFrame)
                                        {
                                            ++index;
                                            continue;
                                        }
                                        FileHelper.SetFloat(float.Parse(frameNode.InnerText, NumberFormatInfo.InvariantInfo), framePosition, valuesList.Content);
                                        framePosition += 4;
                                        ++index;
                                        if (index - firstFrame == numFrames)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                FileHelper.SetUInt(4, vectorLenPosition, channelAsset.Content);
                                FileHelper.SetUInt(numFrames, subPosition, channelAsset.Content);
                                subPosition += 4;
                                BinaryAsset frameAndBinaryFlagList = null;
                                int         sageUnsignedShortCount = 2 - ((int)numFrames & 1);
                                if (sageUnsignedShortCount == 2)
                                {
                                    frameAndBinaryFlagList = new BinaryAsset((int)numFrames << 1);
                                }
                                else
                                {
                                    frameAndBinaryFlagList = new BinaryAsset(((int)numFrames + sageUnsignedShortCount) << 1);
                                }
                                channelAsset.SubAssets.Add(subPosition, frameAndBinaryFlagList);
                                subPosition += 4;
                                for (ushort idx = 0; idx < numFrames; ++idx)
                                {
                                    FileHelper.SetUShort(idx, idx << 1, frameAndBinaryFlagList.Content);
                                }
                                FileHelper.SetUInt(numFrames << 2, subPosition, channelAsset.Content);
                                subPosition += 4;
                                BinaryAsset valuesList = new BinaryAsset((int)numFrames << 4);
                                channelAsset.SubAssets.Add(subPosition, valuesList);
                                int index         = 0;
                                int framePosition = 0;
                                int frame         = int.Parse(channelNode.Attributes.GetNamedItem("FirstFrame").Value);
                                foreach (XmlNode frameNode in channelNode.ChildNodes)
                                {
                                    if (frameNode.Name == "Frame")
                                    {
                                        if (index < firstFrame)
                                        {
                                            ++index;
                                            continue;
                                        }
                                        FileHelper.SetFloat(float.Parse(frameNode.Attributes.GetNamedItem("X").Value, NumberFormatInfo.InvariantInfo), framePosition, valuesList.Content);
                                        framePosition += 4;
                                        FileHelper.SetFloat(float.Parse(frameNode.Attributes.GetNamedItem("Y").Value, NumberFormatInfo.InvariantInfo), framePosition, valuesList.Content);
                                        framePosition += 4;
                                        FileHelper.SetFloat(float.Parse(frameNode.Attributes.GetNamedItem("Z").Value, NumberFormatInfo.InvariantInfo), framePosition, valuesList.Content);
                                        framePosition += 4;
                                        FileHelper.SetFloat(float.Parse(frameNode.Attributes.GetNamedItem("W").Value, NumberFormatInfo.InvariantInfo), framePosition, valuesList.Content);
                                        framePosition += 4;
                                        ++index;
                                        if (index - firstFrame == numFrames)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            channelList.Add(channelAsset);
                        }
                    }
                    break;
                }
            }
            BinaryAsset choiceAsset = new BinaryAsset(channelList.Count << 2);

            FileHelper.SetInt(channelList.Count, position, asset.Content);
            position += 4;
            asset.SubAssets.Add(position, choiceAsset);
            int choicePosition = 0;

            foreach (BinaryAsset choice in channelList)
            {
                choiceAsset.SubAssets.Add(choicePosition, choice);
                choicePosition += 4;
            }
            ErrorDescription = string.Empty;
            return(true);
        }
コード例 #5
0
        public override bool Compile(GameAssetType gameAsset, Uri baseUri, BinaryAsset asset, XmlNode node, GameDefinition game,
                                     string trace, ref int position, out string ErrorDescription)
        {
            XmlNode subNode = node.Attributes.GetNamedItem("Hierarchy");
            string  value   = null;

            if (subNode != null)
            {
                value = subNode.Value;
            }
            else
            {
                value = string.Empty;
            }
            if (value != string.Empty)
            {
                string[] name = value.Split(':');
                if (name.Length == 1)
                {
                    asset.AssetImports.Add(position, new uint[] { StringHasher.Hash("W3DHierarchy"), StringHasher.Hash(name[0].ToLowerInvariant()) });
                }
                else
                {
                    asset.AssetImports.Add(position, new uint[] { StringHasher.Hash(name[0]), StringHasher.Hash(name[1].ToLowerInvariant()) });
                }
            }
            position += 4;
            List <XmlNode> subObjectNodes = new List <XmlNode>();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name == "SubObject")
                {
                    subObjectNodes.Add(childNode);
                }
            }
            FileHelper.SetInt(subObjectNodes.Count, position, asset.Content);
            position += 4;
            BinaryAsset subObjectAsset = new BinaryAsset(0x10 * subObjectNodes.Count);

            asset.SubAssets.Add(position, subObjectAsset);
            int subPosition = 0;

            foreach (XmlNode childNode in subObjectNodes)
            {
                SAGE.Types.SageUnsignedInt suint = new Types.SageUnsignedInt(childNode.Attributes.GetNamedItem("BoneIndex").Value);
                FileHelper.SetUInt(suint.Value, subPosition, subObjectAsset.Content);
                subPosition += 4;
                subNode      = null;
                subNode      = childNode.Attributes.GetNamedItem("SubObjectID");
                if (subNode != null)
                {
                    value = subNode.Value;
                }
                else
                {
                    value = string.Empty;
                }
                if (value == string.Empty)
                {
                    subPosition += 8;
                }
                else
                {
                    int stringLength = value.Length;
                    FileHelper.SetInt(stringLength, subPosition, subObjectAsset.Content);
                    subPosition  += 4;
                    stringLength += 4 - (stringLength & 3);
                    BinaryAsset stringAsset = new BinaryAsset(stringLength);
                    FileHelper.SetString(value, 0, stringAsset.Content);
                    subObjectAsset.SubAssets.Add(subPosition, stringAsset);
                    subPosition += 4;
                }
                foreach (XmlNode renderObjectNode in childNode.ChildNodes)
                {
                    if (renderObjectNode.Name == "RenderObject")
                    {
                        foreach (XmlNode referenceNode in renderObjectNode.ChildNodes)
                        {
                            if (referenceNode.Name == "Mesh")
                            {
                                value = referenceNode.InnerText;
                                string[] name = value.Split(':');
                                if (name.Length == 1)
                                {
                                    subObjectAsset.AssetImports.Add(subPosition, new uint[] { StringHasher.Hash("W3DMesh"), StringHasher.Hash(name[0].ToLowerInvariant()) });
                                }
                                else
                                {
                                    subObjectAsset.AssetImports.Add(subPosition, new uint[] { StringHasher.Hash(name[0]), StringHasher.Hash(name[1].ToLowerInvariant()) });
                                }
                                break;
                            }
                            else if (referenceNode.Name == "CollisionBox")
                            {
                                value = referenceNode.InnerText;
                                string[] name = value.Split(':');
                                if (name.Length == 1)
                                {
                                    subObjectAsset.AssetImports.Add(subPosition, new uint[] { StringHasher.Hash("W3DCollisionBox"), StringHasher.Hash(name[0].ToLowerInvariant()) });
                                }
                                else
                                {
                                    subObjectAsset.AssetImports.Add(subPosition, new uint[] { StringHasher.Hash(name[0]), StringHasher.Hash(name[1].ToLowerInvariant()) });
                                }
                                break;
                            }
                        }
                        break;
                    }
                }
                subPosition += 4;
            }
            ErrorDescription = string.Empty;
            return(true);
        }