Exemplo n.º 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var pushContext = new PushContext(ChannelName, ServiceName, AllowedDomains, Dispatcher);

            _viewTransitions.Transition();

            base.OnNavigatedTo(e);
        }
Exemplo n.º 2
0
        public void Start(PushRuntimeSettings limitations)
        {
            poller = Task.Run(async() =>
            {
                using (var repo = new Repository($"../../../../{endpointName}", null))
                {
                    while (!tokenSource.IsCancellationRequested)
                    {
                        PullOptions options = new PullOptions
                        {
                            FetchOptions = new FetchOptions
                            {
                                CredentialsProvider = (url, usernameFromUrl, types) =>
                                                      new UsernamePasswordCredentials
                                {
                                    Username = "******",
                                    Password = "******"
                                }
                            }
                        };
                        repo.Network.Pull(new Signature("daniel", "daniel", new DateTimeOffset(DateTime.Now)),
                                          options);

                        foreach (var commit in repo.Commits)
                        {
                            if (!alreadyPushedCommits.Contains(commit.Id.Sha))
                            {
                                using (var stream = new MemoryStream())
                                    using (var writer = new StreamWriter(stream))
                                    {
                                        var headers = commit.Message
                                                      .Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
                                                      .Select(
                                            kvp => kvp.Split(new[] { " = " }, StringSplitOptions.RemoveEmptyEntries))
                                                      .Select(kvp => new { Key = kvp[0], Value = kvp[1] })
                                                      .ToDictionary(x => x.Key, x => x.Value);

                                        var treeEntry = commit.Tree.FirstOrDefault(x => x.Name.EndsWith(".payload"));
                                        if (treeEntry != null)
                                        {
                                            await writer.WriteAsync(File.ReadAllText(treeEntry.Path)).ConfigureAwait(false);
                                        }

                                        await stream.FlushAsync().ConfigureAwait(false);
                                        stream.Position = 0;

                                        var pushContext = new PushContext(commit.Id.Sha, headers, stream,
                                                                          new NoOpTransaction(), new ContextBag(null));
                                        await pipe(pushContext);
                                        alreadyPushedCommits.Add(commit.Id.Sha);
                                    }
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 3
0
    async Task ProcessFile(DirectoryBasedTransaction transaction, string messageId)
    {
        try
        {
            string[] message  = File.ReadAllLines(transaction.FileToProcess);
            var      bodyPath = message.First();
            var      json     = string.Join("", message.Skip(1));
            Dictionary <string, string> headers = HeaderSerializer.DeSerialize(json);

            string ttbrString;

            if (headers.TryGetValue(Headers.TimeToBeReceived, out ttbrString))
            {
                var ttbr = TimeSpan.Parse(ttbrString);
                //file.move preserves create time
                var sentTime = File.GetCreationTimeUtc(transaction.FileToProcess);

                if (sentTime + ttbr < DateTime.UtcNow)
                {
                    transaction.Commit();
                    return;
                }
            }
            var tokenSource = new CancellationTokenSource();

            using (var bodyStream = new FileStream(bodyPath, FileMode.Open))
            {
                var context = new ContextBag();
                context.Set(transaction);

                var pushContext = new PushContext(messageId, headers, bodyStream, transaction, tokenSource, context);
                await pipeline(pushContext)
                .ConfigureAwait(false);
            }

            if (tokenSource.IsCancellationRequested)
            {
                transaction.Rollback();
                return;
            }

            transaction.Commit();
        }
        catch (Exception)
        {
            transaction.Rollback();
        }
    }
Exemplo n.º 4
0
 public PushController(PushContext db, IOptions <Settings> settings)
 {
     this.pusher   = new WebPushClient();
     this.db       = db;
     this.settings = settings.Value;
 }
Exemplo n.º 5
0
 // Code to execute when the application is launching (eg, from Start)
 // This code will not execute when the application is reactivated
 private void ApplicationLaunching(object sender, LaunchingEventArgs e)
 {
     try
     {
         _pushContext = new PushContext(Channelname, Servicename, AllowedDomains);
     }
     catch (InvalidOperationException)
     {
         _pushContext = PushContext.Current;
     }
     _pushContext.Error += OnPushContextError;
 }
Exemplo n.º 6
0
		// Code to execute when the application is activated (brought to foreground)
		// This code will not execute when the application is first launched
		private void ApplicationActivated(object sender, ActivatedEventArgs e)
		{
			_pushContext = PushContext.Current ?? new PushContext(Channelname, Servicename, AllowedDomains);
			_pushContext.Error += OnPushContextError;
		}
 public NotificationRepository(PushContext pushContext)
 {
     this.pushContext = pushContext;
 }
Exemplo n.º 8
0
 public TokenRepository(PushContext pushContext)
 {
     this.pushContext = pushContext;
 }
    async Task ProcessFile(DirectoryBasedTransaction transaction, string messageId)
    {
        try
        {
            string[] message = File.ReadAllLines(transaction.FileToProcess);
            string bodyPath = message.First();
            string json = string.Join("", message.Skip(1));
            Dictionary<string, string> headers = HeaderSerializer.DeSerialize(json);

            string ttbrString;

            if (headers.TryGetValue(Headers.TimeToBeReceived, out ttbrString))
            {
                TimeSpan ttbr = TimeSpan.Parse(ttbrString);
                //file.move preserves create time
                DateTime sentTime = File.GetCreationTimeUtc(transaction.FileToProcess);

                if (sentTime + ttbr < DateTime.UtcNow)
                {
                    transaction.Commit();
                    return;
                }
            }
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            using (FileStream bodyStream = new FileStream(bodyPath, FileMode.Open))
            {
                ContextBag context = new ContextBag();
                context.Set(transaction);

                PushContext pushContext = new PushContext(messageId, headers, bodyStream, transaction, tokenSource, context);
                await pipeline(pushContext).ConfigureAwait(false);
            }

            if (tokenSource.IsCancellationRequested)
            {
                transaction.Rollback();
                return;
            }

            transaction.Commit();
        }
        catch (Exception)
        {
            transaction.Rollback();
        }
    }
 public AppRepository(PushContext pushContext)
 {
     this.pushContext = pushContext;
 }