Пример #1
0
        public void GetAndProcessPage()
        {
            if (String.IsNullOrEmpty(resellerCid) ||
                adAuthorizationToken == null ||
                saAuthorizationToken == null)
            {
                throw new ArgumentException("Call Initialize() before processing");
            }

            int      retryAfter = 60;                     // seconds  - Make a new call after this interval
            TimeSpan abortAfter = new TimeSpan(0, 10, 0); // stop waiting after this interval

            DateTime start = DateTime.Now;

            do
            {
                StreamPageResponse subscriptionPage = Stream.GetStreamPage(resellerCid, saAuthorizationToken.AccessToken);
                foreach (var subscriptionEvent in subscriptionPage.items)
                {
                    CSPStreamEvent streamEvent = new CSPStreamEvent(subscriptionEvent);
                    lastCSPEventTime = streamEvent.EventDate;

                    Console.WriteLine("Entry: " + streamEvent.SubscriptionEventType);
                    localManager.WriteCSPStreamEvent(streamEvent);
                }

                // event not found - mark page as read
                Stream.MarkStreamPageComplete(subscriptionPage.links.completion.href, subscriptionPage.links.completion.method, saAuthorizationToken.AccessToken);

                Console.WriteLine("sleeping");
                Thread.Sleep(retryAfter * 1000);
            } while (DateTime.Now < start + abortAfter);
        }
		public void GetAndProcessPage()
		{
			if (String.IsNullOrEmpty(resellerCid) ||
					adAuthorizationToken == null ||
					saAuthorizationToken == null)
			{
				throw new ArgumentException("Call Initialize() before processing");
			}

			int retryAfter = 60;   // seconds  - Make a new call after this interval
			TimeSpan abortAfter = new TimeSpan(0, 10, 0);  // stop waiting after this interval

			DateTime start = DateTime.Now;

			do
			{
				StreamPageResponse subscriptionPage = Stream.GetStreamPage(resellerCid, saAuthorizationToken.AccessToken);
				foreach (var subscriptionEvent in subscriptionPage.items)
				{
					CSPStreamEvent streamEvent = new CSPStreamEvent(subscriptionEvent);
					lastCSPEventTime = streamEvent.EventDate;

					Console.WriteLine("Entry: " + streamEvent.SubscriptionEventType);
					localManager.WriteCSPStreamEvent(streamEvent);
				}

				// event not found - mark page as read
				Stream.MarkStreamPageComplete(subscriptionPage.links.completion.href, subscriptionPage.links.completion.method, saAuthorizationToken.AccessToken);

				Console.WriteLine("sleeping");
				Thread.Sleep(retryAfter * 1000);
			} while (DateTime.Now < start + abortAfter);

		}
 public void WriteCSPStreamEvent(CSPStreamEvent cspEvent)
 {
     using (var sw = new StreamWriter(logFile, true))
         using (var csv = new CsvWriter(sw))
         {
             csv.WriteRecord(cspEvent);
         }
 }
		public void WriteCSPStreamEvent(CSPStreamEvent cspEvent)
		{
			using (var sw = new StreamWriter(logFile, true))
			using (var csv = new CsvWriter(sw))
			{
				csv.WriteRecord(cspEvent);
			}

		}