예제 #1
0
        internal CouchContinuousChanges(DreamMessage aMessage, CouchChangeDelegate aCallback)
        {
            if (aMessage == null)
            {
                throw new ArgumentNullException("aMessage");
            }
            if (aCallback == null)
            {
                throw new ArgumentNullException("aCallback");
            }

            theReader = new AsyncStreamReader(aMessage.ToStream(), (x, y) => {
                if (!String.IsNullOrEmpty(y.Line))
                {
                    CouchChangeResult result = theSerializer.Deserialize(y.Line);
                    aCallback(this, result);
                }
            });
        }
예제 #2
0
		private void OnChanged(object sender, CouchChangeResult<JDocument> aChange){
			SetSequence(aChange.Sequence);
			JToken jtoken;

			aChange.Doc.TryGetValue("otype", out jtoken);
			if(jtoken == null)
				return;
			switch (jtoken.Value<string>())
			{
				case "score":
					if (ScoreChanged != null)
					{
						ScoreChanged(this, new EventArgs<IScore> { Item = new JScore(aChange.Doc) });
					}
					break;
				case "play":
					if (PlayChanged != null)
					{
						PlayChanged(this, new EventArgs<IPlay> { Item = new JPlay(aChange.Doc) });
					}
					break;
				case "source":
					if (SourceChanged != null)
					{
						 SourceChanged(this, new EventArgs<ISource> { Item = new JSource(aChange.Doc) });
					}
					break;
				case "sourcePage":
					if (SourcePageChanged != null)
					{
						SourcePageChanged(this, new EventArgs<ISourcePage> { Item = new JSourcePage(aChange.Doc) });
					}
					break;
			}
			
		}
예제 #3
0
        private void OnContactChanged(CouchChangeResult aChangeResult)
        {
            //add to the list of changes
            Items.Add(aChangeResult);

            //record the sequence number of the change so when we run the application we
            //tell that we only need changes > this number.
            //(Otherwise you get a change message for every doc in the db at the startup)
            SetSequence(aChangeResult.Sequence);

            //verifiy type of change announced so we know if we need to refresh a contact
            if (aChangeResult.Id.StartsWith("_design"))
                return;

            if (aChangeResult.Deleted)
            {
                OnContactDeleted(aChangeResult.Id);
            }
            else
            {
                Console.WriteLine("Retrieving last version of {0}",aChangeResult.Id);
                //get the latest version of this document
                theDatabase.GetDocument(aChangeResult.Id, new Result<Contact>()).WhenDone(
                    a => BeginInvoke((MethodInvoker)(() => OnContactChanged(a))),
                    ErrorManagement.ProcessException
                    );
            }
        }