예제 #1
0
        private List<Pair> TransformKVSPairs(SD.Pair[] pairs)
        {
            List<Pair> retPairs = new List<Pair>(pairs.Count());
            Pair pair;
            foreach(SD.Pair p in pairs)
            {
                pair = new Pair();

                pair.Key = p.Key;
                pair.Value = p.Value;

                retPairs.Add(pair);
            }

            return retPairs;
        }
예제 #2
0
        //IBroker
        public void StorePair(Pair p)
        {
            //getting message context with the client name
            MessageProperties msgProp = OperationContext.Current.IncomingMessageProperties;
            ContextMessageProperty ctxProperty = msgProp[ContextMessageProperty.Name] as ContextMessageProperty;
            string clientName = "";
            if (ctxProperty.Context.ContainsKey("clientName"))
            {
                 clientName = ctxProperty.Context["clientName"];
            }
            if(clientName == "")
                throw new FaultException("ERROR - Client Name not set.");

            if(m_servers.Count <= 0)
                throw new FaultException("ERROR - System is down.");

            ClientKey ck = new ClientKey(clientName, p.Key);
            if (m_serverPairs.ContainsKey(ck))
                throw new FaultException("ERROR - Duplicated key: " + p.Key);

            String address = GetKVS();
            KVSClient kvs = new KVSClient("KVSService", address);
            try
            {
                kvs.StorePair(ck, p.Value);
            }catch(EndpointNotFoundException)
            {
                DeregisterServer(address);
                StorePair(p);
            }

            m_serverPairs.TryAdd(ck, address);//add the key and the server to the list
            if (!m_servers.ContainsKey(clientName))
                m_users.Add(clientName);

            //Console.WriteLine("Pair Stored in server: " + m_currId);
        }