Exemplo n.º 1
0
 public static Guid StringToGuid(string guid)
 {
     if (DatabaseLanguageIsMsSql.Value)
     {
         return(Guid.Parse(guid));
     }
     else if (DatabaseLanguageIsOracle.Value)
     {
         return(new Guid(CsUtility.HexToByteArray(guid)));
     }
     else
     {
         throw new FrameworkException(UnsupportedLanguageError);
     }
 }
Exemplo n.º 2
0
        private ValueOrError <List <string> > ListCachedFiles(string fileGroupName, byte[] sourceHash, IEnumerable <string> requestedExtensions)
        {
            var cachedFilesByExt = ListCachedFiles()
                                   .GetValueOrDefault(fileGroupName)
                                   ?.ToDictionary(file => Path.GetExtension(file));

            if (cachedFilesByExt == null)
            {
                return(ValueOrError.CreateError("File group not cached."));
            }

            string cachedHashFile = cachedFilesByExt.GetValueOrDefault(".hash");

            if (cachedHashFile == null)
            {
                return(ValueOrError.CreateError("Missing hash file."));
            }

            byte[] cachedHash = CsUtility.HexToByteArray(File.ReadAllText(cachedHashFile, Encoding.Default));
            if (cachedHash == null || cachedHash.Length == 0)
            {
                return(ValueOrError.CreateError("Missing hash value."));
            }

            if (!sourceHash.SequenceEqual(cachedHash))
            {
                return(ValueOrError.CreateError("Different hash value."));
            }

            var requestedFiles = new List <string>(requestedExtensions.Count());

            foreach (var extension in requestedExtensions)
            {
                string cachedFile = cachedFilesByExt.GetValueOrDefault(extension);
                if (cachedFile == null)
                {
                    return(ValueOrError.CreateError($"Extension '{extension}' not in cache."));
                }
                requestedFiles.Add(cachedFile);
            }

            return(requestedFiles);
        }
Exemplo n.º 3
0
        /// <param name="sampleSourceFile">Any file from the cached file group, extension will be ignored.</param>
        public byte[] LoadHash(string sampleSourceFile)
        {
            string hashFile = Path.GetFullPath(Path.ChangeExtension(sampleSourceFile, ".hash"));

            return(CsUtility.HexToByteArray(File.ReadAllText(hashFile, Encoding.Default)));
        }