Esempio n. 1
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!");
        }
Esempio n. 2
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!" );
        }
Esempio n. 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!");
        }