GetContentDescriptionRecord() публичный Метод

Gets the current content description record (CDR) provided by the config server. Optionally accepts an old CDR hash in order to determine if a new CDR should be downloaded or not. The old CDR hash is a SHA-1 hash of the entire CDR payload.
public GetContentDescriptionRecord ( byte oldCDRHash = null ) : byte[]
oldCDRHash byte An optional CDR hash.
Результат byte[]
Пример #1
0
        public static void Update()
        {
            Console.Write( "Updating CDR..." );

            byte[] cdr = GetCdr();
            byte[] cdrHash = GetHash( cdr );

            foreach ( var configServer in ServerCache.ConfigServers )
            {
                try
                {
                    ConfigServerClient csClient = new ConfigServerClient();
                    csClient.Connect( configServer );

                    byte[] tempCdr = csClient.GetContentDescriptionRecord( cdrHash );

                    if ( tempCdr == null )
                        continue;

                    if ( tempCdr.Length == 0 )
                        break;

                    cdr = tempCdr;
                    File.WriteAllBytes( BLOB_FILENAME, tempCdr );

                    break;
                }
                catch ( Exception )
                {
                    Console.WriteLine( "Warning: Unable to download CDR from config server {0}", configServer );
                }
            }

            if ( cdr == null )
            {
                Console.WriteLine( "Error: Unable to download CDR!" );
                return;
            }


            using ( var reader = BlobTypedReader<CDR>.Create( new MemoryStream( cdr ) ) )
            {
                reader.Process();

                cdrObj = reader.Target;
            }

            Console.WriteLine( " Done!" );
        }
Пример #2
0
        public static void Update()
        {
            typeof(CDRManager).Info("Updating CDR...");

            CDRConfig.Settings config = CDRConfig.Instance;

            string filename = ConfigurationManager.AppSettings["cdrFilename"] ?? CDR_FILENAME;
            filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);

            string directory = Path.GetDirectoryName(filename);
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var hasCachedCDR = File.Exists(filename);

            if (DateTime.Now > config.CDRCacheTime || !hasCachedCDR)
            {
                byte[] cdrHash = hasCachedCDR ? config.CDRHash : null;

                foreach (var configServer in config.ConfigServers)
                {
                    try
                    {
                        ConfigServerClient csClient = new ConfigServerClient();
                        csClient.Connect(configServer);

                        byte[] tempCdr = csClient.GetContentDescriptionRecord(cdrHash);

                        if (tempCdr == null)
                            continue;

                        if (tempCdr.Length == 0)
                            break;

                        using (MemoryStream ms = new MemoryStream(tempCdr))
                        using (BlobReader reader = BlobReader.CreateFrom(ms))
                            cdrObj = (CDR)BlobTypedReader.Deserialize(reader, typeof(CDR));

                        using (FileStream fs = File.Open(filename, FileMode.Create))
                        using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Compress))
                            ProtoBuf.Serializer.Serialize<CDR>(ds, cdrObj);

                        using (SHA1Managed sha = new SHA1Managed())
                        {
                            config.CDRHash = sha.ComputeHash(tempCdr);
                        }
                        config.CDRCacheTime = DateTime.Now.AddMinutes(30);
                        CDRConfig.Save();
                        break;
                    }
                    catch (Exception ex)
                    {
                        typeof(CDRManager).Error(ex, string.Format("Warning: Unable to download CDR from config server {0}", configServer));
                    }
                }

                if (cdrObj != null)
                {
                    typeof(CDRManager).Info("Done");
                }
                else if (!File.Exists(filename))
                {
                    typeof(CDRManager).Error("Unable to download CDR");
                }
            }
            else
            {
                typeof(CDRManager).Info("Load cached copy");
                using (FileStream fs = File.Open(filename, FileMode.Open))
                using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Decompress))
                    cdrObj = ProtoBuf.Serializer.Deserialize<CDR>(ds);

                typeof(CDRManager).Info("Done");
            }
        }
Пример #3
0
        public static void Update()
        {
            Console.Write( "Updating CDR..." );

            var hasCachedCDR = File.Exists(CDR_FILENAME);

            if (DateTime.Now > ConfigCache.Instance.CDRCacheTime || !hasCachedCDR)
            {
                byte[] cdrHash = hasCachedCDR ? ConfigCache.Instance.CDRHash : null;

                foreach (var configServer in ServerCache.ConfigServers)
                {
                    try
                    {
                        ConfigServerClient csClient = new ConfigServerClient();
                        csClient.Connect(configServer);

                        byte[] tempCdr = csClient.GetContentDescriptionRecord(cdrHash);

                        if (tempCdr == null)
                            continue;

                        if (tempCdr.Length == 0)
                            break;

                        using (MemoryStream ms = new MemoryStream(tempCdr))
                        using (BlobReader reader = BlobReader.CreateFrom(ms))
                            cdrObj = (CDR)BlobTypedReader.Deserialize(reader, typeof(CDR));

                        using (FileStream fs = File.Open(CDR_FILENAME, FileMode.Create))
                        using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Compress))
                            ProtoBuf.Serializer.Serialize<CDR>(ds, cdrObj);

                        ConfigCache.Instance.CDRHash = SHAHash(tempCdr);
                        ConfigCache.Instance.CDRCacheTime = DateTime.Now.AddMinutes(30);
                        ConfigCache.Instance.Save(ConfigCache.CONFIG_FILENAME);
                        break;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Warning: Unable to download CDR from config server {0}: {1}", configServer, e.Message);
                    }
                }

                if(cdrObj != null)
                {
                    Console.WriteLine(" Done!");
                    return;
                }
                else if (!File.Exists(CDR_FILENAME))
                {
                    Console.WriteLine("Error: Unable to download CDR!");
                    return;
                }
            }

            using (FileStream fs = File.Open(CDR_FILENAME, FileMode.Open))
            using (DeflateStream ds = new DeflateStream(fs, CompressionMode.Decompress))
                cdrObj = ProtoBuf.Serializer.Deserialize<CDR>(ds);

            Console.WriteLine(" Done!");
        }