_04_GuessTheNumberTurnTheTables.FileSystemDatabase.Read C# (CSharp) Method

Read() public method

public Read ( int key ) : byte[]>.Dictionary
key int
return byte[]>.Dictionary
        public Dictionary<string, byte[]> Read(int key)
        {
            lock (this.GetType()) {
                var objDir = Path.Combine (this.directory, key.ToString ());
                if (!Directory.Exists (objDir)) {
                    return null;
                }
                var result = new Dictionary<string, byte[]> ();
                foreach (var fileName in Directory.EnumerateFiles(objDir)) {
                    var fieldName = Path.GetFileName (fileName);
                    result [fieldName] = File.ReadAllBytes (fileName);
                }
                return result;
            }
        }

Usage Example

示例#1
0
        public static Session Load(FileSystemDatabase fsd, int key)
        {
            var toLoad = fsd.Read(key);

            if (toLoad == null)
            {
                return(null);
            }
            var result = new Session();

            result.Id = key;
            if (toLoad.ContainsKey(ShovelVmStateName))
            {
                result.ShovelVmState = toLoad [ShovelVmStateName];
            }
            if (toLoad.ContainsKey(ShovelVmBytecodeName))
            {
                result.ShovelVmBytecode = toLoad [ShovelVmBytecodeName];
            }
            if (toLoad.ContainsKey(ShovelVmSourcesName))
            {
                result.ShovelVmSources = Encoding.UTF8.GetString(toLoad [ShovelVmSourcesName]);
            }
            if (toLoad.ContainsKey(PageContentName))
            {
                result.PageContent.Append(Encoding.UTF8.GetString(toLoad [PageContentName]));
            }
            if (toLoad.ContainsKey(ReadStateName))
            {
                result.ReadState = (ReadStates)BitConverter.ToInt32(toLoad [ReadStateName], 0);
            }
            return(result);
        }
All Usage Examples Of _04_GuessTheNumberTurnTheTables.FileSystemDatabase::Read