Example #1
0
        public bool LoadMetaDataServer()
        {
            if (!File.Exists(FQFilename))
            {
                return(false);
            }

            try
            {
                TextReader mdtr = new StreamReader(FQFilename);
                string     json = mdtr.ReadToEnd();
                mdtr.Close();

                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LocalMetaDataServer));
                LocalMetaDataServer        ts  = (LocalMetaDataServer)ser.ReadObject(ms);
                keytable = ts.keytable;
                mdtable  = ts.mdtable;
                return(true);
            }
            // catch (Exception e)
            catch
            {
                Console.WriteLine("Failed to load metadata file: " + FQFilename);
                // Console.WriteLine("{0} Exception caught.", e);
                return(false);
            }
        }
Example #2
0
        public bool deleteStream(FqStreamID streamId, CallerInfo Ci, string mdserveraddress = null)
        {
            Logger log       = new Logger();
            string BaseDir   = Path.GetFullPath((null != Ci.workingDir) ? Ci.workingDir : Directory.GetCurrentDirectory());
            string targetDir = BaseDir + "/" + streamId.ToString();

            // string address = ConfigurationManager.AppSettings.Get("MDServerAddress");
            // string address = "http://homelab-vm.cloudapp.net:23456/MetaDataServer/";

            string address = mdserveraddress;

            MetaDataService.IMetaDataService clnt = null;
            if (address != null)
            {
                BasicHttpBinding binding = new BasicHttpBinding();
                ChannelFactory <MetaDataService.IMetaDataService> factory = new ChannelFactory <MetaDataService.IMetaDataService>(binding, address);
                clnt = factory.CreateChannel();
            }

            Dictionary <int, MetaDataService.AccountInfo> accounts = null;
            string containerName; ISync synchronizerForDelete;

            if (address != null)
            {
                try
                {
                    MetaDataService.FQStreamID stream = new MetaDataService.FQStreamID();
                    stream.HomeId   = streamId.HomeId;
                    stream.AppId    = streamId.AppId;
                    stream.StreamId = streamId.StreamId;
                    accounts        = clnt.GetAllAccounts(stream);

                    if (accounts == null)
                    {
                        // no stream of this name on the metadata server
                        return(false);
                    }

                    // TODO: Authentication for this update call
                    clnt.RemoveAllInfo(stream);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception caught {0}", e);
                    return(false);
                }


                foreach (MetaDataService.AccountInfo account in accounts.Values)
                {
                    Boom(targetDir + "/" + account.num);
                    containerName         = streamId.ToString().Replace('/', '-').ToLower() + "-" + account.num;
                    synchronizerForDelete = CreateSyncForAccount(account, containerName, log);
                    synchronizerForDelete.Delete();
                }

                containerName         = streamId.ToString().Replace('/', '-').ToLower();//account info for meta stream = that of seg 0. strange?
                synchronizerForDelete = CreateSyncForAccount(accounts.ElementAt(0).Value, containerName, log);
                synchronizerForDelete.Delete();
            }
            else
            {
                LocalMetaDataServer localMdServer = new LocalMetaDataServer(targetDir + "/" + MetaStream <StrKey, StrValue> .StreamMDFileName, log);
                localMdServer.LoadMetaDataServer();

                Dictionary <int, AccountInfo> tmp = localMdServer.GetAllAccounts(new FQStreamID(streamId.HomeId, streamId.AppId, streamId.StreamId));

                if (tmp != null)
                {
                    MetaDataService.AccountInfo ai         = null;
                    MetaDataService.AccountInfo segment0Ai = null;
                    foreach (AccountInfo account in tmp.Values)
                    {
                        Boom(targetDir + "/" + account.num);
                        containerName         = streamId.ToString().Replace('/', '-').ToLower() + "-" + account.num;
                        ai                    = new MetaDataService.AccountInfo();
                        ai.accountKey         = account.accountKey;
                        ai.accountName        = account.accountName;
                        ai.location           = account.location;
                        ai.keyVersion         = account.keyVersion;
                        ai.num                = account.num;
                        synchronizerForDelete = CreateSyncForAccount(ai, containerName, log);
                        if (synchronizerForDelete != null)
                        {
                            synchronizerForDelete.Delete();
                        }
                        if (segment0Ai == null)
                        {
                            segment0Ai = ai;
                        }
                    }
                    containerName         = streamId.ToString().Replace('/', '-').ToLower();// TODO account info for meta stream = that of seg 0? something is wrong.
                    synchronizerForDelete = CreateSyncForAccount(segment0Ai, containerName, log);
                    if (synchronizerForDelete != null)
                    {
                        synchronizerForDelete.Delete();
                    }
                }
            }

            Boom(targetDir);
            return(true);
        }