Ejemplo n.º 1
0
        public void SaveEntry(DiscoveryCacheEntry entry)
        {
            DirectoryInfo infrastructureScopeDirectory = new DirectoryInfo(Path.Combine(_CacheFolder.FullName, entry.InfrastructureScopeName));

            if (!infrastructureScopeDirectory.Exists)
            {
                infrastructureScopeDirectory.Create();
            }

            string serializedEntry    = JsonConvert.SerializeObject(entry);
            string targetFileFullName = Path.Combine(infrastructureScopeDirectory.FullName, entry.ContractFullName + ".v" + entry.ContractMajorVersion.ToString());

            File.WriteAllText(targetFileFullName, serializedEntry, Encoding.UTF8);
        }
Ejemplo n.º 2
0
        public DiscoveryCacheEntry[] LoadAllEntries()
        {
            List <DiscoveryCacheEntry> allEntries = new List <DiscoveryCacheEntry>();

            foreach (DirectoryInfo infrastructureScopeDirectory in _CacheFolder.GetDirectories())
            {
                string infrastructureScopeName = infrastructureScopeDirectory.Name;

                foreach (FileInfo file in infrastructureScopeDirectory.GetFiles("*.*"))
                {
                    string contractFullName = Path.GetFileNameWithoutExtension(file.Name);

                    Int32 contractMajorVersion = -1;
                    if (Int32.TryParse(Path.GetExtension(file.Name).Substring(1), out contractMajorVersion))
                    {
                        string serializedEntry = File.ReadAllText(file.FullName, Encoding.UTF8);
                        DiscoveryCacheEntry deserializedEntry = JsonConvert.DeserializeObject <DiscoveryCacheEntry>(serializedEntry);
                        allEntries.Add(deserializedEntry);
                    }
                }
            }

            return(allEntries.ToArray());
        }
Ejemplo n.º 3
0
        public bool TryLoadEntry(string contractFullName, int contractMajorVersion, string infrastructureScopeName, ref DiscoveryCacheEntry loadedEntry)
        {
            DirectoryInfo infrastructureScopeDirectory = new DirectoryInfo(Path.Combine(_CacheFolder.FullName, infrastructureScopeName));

            if (!infrastructureScopeDirectory.Exists)
            {
                return(false);
            }

            string expectedFileFullName = Path.Combine(infrastructureScopeDirectory.FullName, contractFullName + ".v" + contractMajorVersion.ToString());

            if (!File.Exists(expectedFileFullName))
            {
                return(false);
            }

            string serializedEntry = File.ReadAllText(expectedFileFullName, Encoding.UTF8);

            loadedEntry = JsonConvert.DeserializeObject <DiscoveryCacheEntry>(serializedEntry);

            return(true);
        }