Ejemplo n.º 1
0
    public static Hash128 GetHash128(this AssetLoadInfo info)
    {
        StreamHasher hasher = new StreamHasher();

        HashingHelpers.WriteHashData(info, hasher.Writer);
        return(hasher.GetHash());
    }
Ejemplo n.º 2
0
    public static Hash128 GetHash128(this WriteCommand cmd)
    {
        StreamHasher hasher = new StreamHasher();

        HashingHelpers.WriteHashData(cmd, hasher.Writer);
        return(hasher.GetHash());
    }
Ejemplo n.º 3
0
            protected override ValidationResult IsValid(object value, ValidationContext validationContext)
            {
                HttpPostedFileBase file = value as HttpPostedFileBase;

                if (value != null)
                {
                    // Check the filename before doing the
                    // expensive hash check
                    if (!Regex.IsMatch(file.FileName, _r))
                    {
                        var errorMessage = FormatErrorMessage(validationContext.DisplayName +
                                                              ". This name is not consistent with ShopKeep's for this type of import.");
                        return(new ValidationResult(errorMessage));
                    }
                    else
                    {
                        // The name is valid. Now we check the hash.
                        // Compute the hash.
                        string hash = StreamHasher.ComputeHash(file.InputStream);

                        // Store the hash on the model if a property was given.
                        if (_p != null)
                        {
                            var m = validationContext.ObjectInstance;
                            m.GetType().GetProperty(_p).SetValue(m, hash);
                        }

                        // Check that the file is unique
                        if (!Import.IsUniqueContentHash(hash))
                        {
                            // It isn't
                            var errorMessage = FormatErrorMessage(validationContext.DisplayName +
                                                                  ". This file has already been uploaded.");
                            return(new ValidationResult(errorMessage));
                        }
                    }
                }

                // The file checks out
                return(ValidationResult.Success);
            }