public async Task <IActionResult> GetPendingAsync(string clientId)
        {
            IReadOnlyList <IClientDisclaimer> clienPendingDisclaimers = await _clientDisclaimerService.GetPendingAsync(clientId);

            var disclaimers = new List <IDisclaimer>();

            foreach (IClientDisclaimer clientDisclaimer in clienPendingDisclaimers)
            {
                IDisclaimer disclaimer = await _disclaimerService.FindAsync(clientDisclaimer.DisclaimerId);

                if (disclaimer != null)
                {
                    disclaimers.Add(disclaimer);
                }
            }

            if (disclaimers.Any())
            {
                var disclaimersContext = disclaimers.Select(e => new { e.Id, e.Name, e.LykkeEntityId, e.StartDate, e.Type }).ToJson();
                _log.Info($"disclaimers list for client: {disclaimersContext}", context: clientId);
            }

            var model = Mapper.Map <List <DisclaimerModel> >(disclaimers);

            return(Ok(model));
        }
        public async Task ApproveAsync(string clientId, string disclaimerId)
        {
            IDisclaimer disclaimer = await _redisService.GetDisclaimerAsync(disclaimerId);

            if (disclaimer == null)
            {
                throw new DisclaimerNotFoundException(disclaimerId);
            }

            var clientDisclaimer = new ClientDisclaimer
            {
                ClientId     = clientId,
                DisclaimerId = disclaimerId,
                Approved     = true,
                ApprovedDate = DateTime.UtcNow
            };

            var tasks = new List <Task>
            {
                _clientDisclaimerRepository.InsertOrReplaceAsync(clientDisclaimer),
                _redisService.AddClientDisclaimerAsync(clientDisclaimer)
            };

            await Task.WhenAll(tasks);

            _log.Info("Client disclaimer approved", new { clientId, disclaimerId });
        }
コード例 #3
0
 public async Task UpdateAsync(IDisclaimer disclaimer)
 {
     await _storage.MergeAsync(GetPartitionKey(disclaimer.LykkeEntityId), GetRowKey(disclaimer.Id), entity =>
     {
         Mapper.Map(disclaimer, entity);
         return(entity);
     });
 }
        private async Task <bool> CheckDisclaimerAsync(string clientId, string lykkeEntityId, DisclaimerType type)
        {
            IDisclaimer requiresApprovalDisclaimer = (await _redisService.GetDisclaimersAsync())
                                                     .Where(x => x.LykkeEntityId == lykkeEntityId)
                                                     .Where(o => o.Type == type)
                                                     .Where(o => o.StartDate < DateTime.UtcNow)
                                                     .OrderByDescending(p => p.StartDate)
                                                     .FirstOrDefault();

            if (requiresApprovalDisclaimer == null)
            {
                return(false);
            }

            IReadOnlyList <IClientDisclaimer> clientDisclaimers = await _redisService.GetClientDisclaimersAsync(clientId);

            HashSet <string> approvedDisclaimers = clientDisclaimers
                                                   .Where(o => o.Approved)
                                                   .Select(o => o.DisclaimerId)
                                                   .ToHashSet();

            List <Task> tasks;

            if (approvedDisclaimers.Contains(requiresApprovalDisclaimer.Id))
            {
                if (requiresApprovalDisclaimer.ShowOnEachAction)
                {
                    tasks = new List <Task>
                    {
                        _clientDisclaimerRepository.DeleteAsync(clientId, requiresApprovalDisclaimer.Id),
                        _redisService.DeleteClientDisclaimerAsync(clientId, requiresApprovalDisclaimer.Id)
                    };

                    await Task.WhenAll(tasks);
                }

                return(false);
            }

            var clientDisclaimer = new ClientDisclaimer
            {
                ClientId     = clientId,
                DisclaimerId = requiresApprovalDisclaimer.Id,
                ApprovedDate = DateTime.UtcNow
            };

            tasks = new List <Task>
            {
                _clientDisclaimerRepository.InsertOrReplaceAsync(clientDisclaimer),
                _redisService.AddClientDisclaimerAsync(clientDisclaimer)
            };

            await Task.WhenAll(tasks);

            _log.Info("Client pending disclaimer added", new  { clientId, requiresApprovalDisclaimer.Id });

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IDisclaimer page)
        {
            // X:\jsc.svn\examples\javascript\Test\TestUTF8GetStringPerformance\TestUTF8GetStringPerformance\Application.cs

            #region go
            Action<string> go =
                async source =>
                {
                    // show login

                    #region layout
                    var layout = new Login();

                    // loaded app will expect id's, restore em
                    layout.Login.id = "Login";

                    var newbody = layout.body;
                    var oldbody = Native.document.body;

                    // switch layouts

                    Native.document.body.parentNode.replaceChild(
                        newbody,
                        oldbody
                    );
                    #endregion


                    // how did we get the source?
                    //var app = new x(layout);

                    await new IHTMLScript
                    {
                        src = new Blob(
                            new[] { source }
                            ).ToObjectURL().SetInternalScriptApplicationSource()
                    };
                };
            #endregion

            page.Continue.onclick +=
                async delegate
                {
                    page.Continue.disabled = true;

                    var source = await typeof(x);

                    // we can now Activate it?
                    //Activator.CreateInstance(typeof(x));

                    // invoke as state?
                    go(source.source);
                };

        }
        public async Task <IActionResult> GetAsync(string lykkeEntityId, string disclaimerId)
        {
            IDisclaimer disclaimer = await _disclaimerService.GetAsync(lykkeEntityId, disclaimerId);

            if (disclaimer == null)
            {
                return(NotFound());
            }

            var model = Mapper.Map <DisclaimerModel>(disclaimer);

            return(Ok(model));
        }
コード例 #7
0
 public static HashEntry[] ToHashEntries(this IDisclaimer disclaimer)
 {
     return(new[]
     {
         new HashEntry(nameof(Disclaimer.Id), disclaimer.Id),
         new HashEntry(nameof(Disclaimer.LykkeEntityId), disclaimer.LykkeEntityId ?? string.Empty),
         new HashEntry(nameof(Disclaimer.Type), disclaimer.Type.ToString() ?? string.Empty),
         new HashEntry(nameof(Disclaimer.Name), disclaimer.Name ?? string.Empty),
         new HashEntry(nameof(Disclaimer.Text), disclaimer.Text ?? string.Empty),
         new HashEntry(nameof(Disclaimer.StartDate), disclaimer.StartDate.ToString(DateFormat)),
         new HashEntry(nameof(Disclaimer.ShowOnEachAction), disclaimer.ShowOnEachAction.ToString())
     });
 }
コード例 #8
0
        public async Task <IDisclaimer> InsertAsync(IDisclaimer disclaimer)
        {
            var entity = new DisclaimerEntity(GetPartitionKey(disclaimer.LykkeEntityId), GetRowKey());

            Mapper.Map(disclaimer, entity);

            await _storage.InsertAsync(entity);

            var index = AzureIndex.Create(GetDisclaimerIdIndexPartitionKey(entity.RowKey),
                                          GetDisclaimerIdIndexRowKey(), entity);

            await _disclaimerIdIndexStorage.InsertAsync(index);

            return(Mapper.Map <Disclaimer>(entity));
        }
コード例 #9
0
        public async Task <IDisclaimer> AddAsync(IDisclaimer disclaimer)
        {
            ILykkeEntity lykkeEntity = await _redisService.GetLykkeEntityAsync(disclaimer.LykkeEntityId);

            if (lykkeEntity == null)
            {
                throw new LykkeEntityNotFoundException(disclaimer.LykkeEntityId);
            }

            IDisclaimer createdDisclaimer = await _disclaimerRepository.InsertAsync(disclaimer);

            await _redisService.AddDisclaimerAsync(createdDisclaimer);

            _log.Info("Lykke entity disclaimer added", disclaimer);

            return(createdDisclaimer);
        }
コード例 #10
0
        public async Task UpdateAsync(IDisclaimer disclaimer)
        {
            IDisclaimer existingDisclaimer = await _redisService.GetDisclaimerAsync(disclaimer.Id);

            if (existingDisclaimer == null)
            {
                throw new DisclaimerNotFoundException(disclaimer.Id);
            }

            var tasks = new List <Task>
            {
                _disclaimerRepository.UpdateAsync(disclaimer),
                _redisService.AddDisclaimerAsync(disclaimer)
            };

            await Task.WhenAll(tasks);

            _log.Info("Lykke entity disclaimer updated", disclaimer);
        }
        public async Task <IActionResult> GetApprovedAsync(string clientId)
        {
            IReadOnlyList <IClientDisclaimer> clienApprovedDisclaimers =
                await _clientDisclaimerService.GetApprovedAsync(clientId);

            var model = new List <ClientDisclaimerModel>();

            foreach (IClientDisclaimer clientDisclaimer in clienApprovedDisclaimers)
            {
                IDisclaimer disclaimer = await _disclaimerService.FindAsync(clientDisclaimer.DisclaimerId);

                if (disclaimer == null)
                {
                    continue;
                }

                var clientDisclaimerModel = Mapper.Map <ClientDisclaimerModel>(disclaimer);
                clientDisclaimerModel.ApprovedDate = clientDisclaimer.ApprovedDate;

                model.Add(clientDisclaimerModel);
            }

            return(Ok(model));
        }
コード例 #12
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IDisclaimer page)
        {

            #region go
            Action<HistoryScope<InternalScriptApplicationSource>> go =
                //async 
                     scope =>
                     {
                         var source = scope.state;

                         // show login

                         #region layout
                         var layout = new Login();

                         // loaded app will expect id's, restore em
                         layout.Login.id = "Login";

                         var newbody = layout.body;
                         var oldbody = Native.document.body;

                         // switch layouts

                         Native.document.body.parentNode.replaceChild(
                             newbody,
                             oldbody
                         );
                         #endregion


                         // how did we get the source?
                         //var app = new x(layout);

                         //await 

                         //new IHTMLScript { src = new Blob(source).ToObjectURL().SetInternalScriptApplicationSource() }.AttachToHead();
                         source.eval();

                         //var src = new Blob(source).ToObjectURL().SetInternalScriptApplicationSource();
                         ////await new IHTMLScript { src = src };
                         //Native.window.eval(source);

                         // now what?
                     };
            #endregion



            #region onclick
            page.Continue.onclick +=
                async delegate
                {
                    page.Continue.disabled = true;




                    var source = await typeof(x);

                    // we can now Activate it?
                    //Activator.CreateInstance(typeof(x));

                    //go.ToHistoricAction()(source);
                    //go.Invoke(source, XHistory.HistoricEvent.pushState);



                    Native.window.history.replaceState(source, go);

                    //go.ToHistoricAction()
                    // or reload?
                    //Native.document.location.reload();
                };
            #endregion


            //           HistoryExtensions onpopstate { state = [object Object], e = { state = 2 }, history = { state = 2 }, Count = 1 }
            //did we just move forward?



            new IHTMLButton { innerText = "replaceState", id = "replaceState" }.AttachToDocument().WhenClicked(
                          btn =>
                          {
                              Native.window.history.replaceState(
                                  new { replaceState = "world", btn.id },
                                  scope =>
                                  {
                                      ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = true;

                                      Native.document.title = "zz " + new { scope.state.replaceState };

                                  }
                              );
                          }
                      );

            #region options
            new IHTMLButton { innerText = "pushState1", id = "pushState1" }.AttachToDocument().WhenClicked(
                btn =>
                {

                    Native.window.history.pushState(
                        new { pushState = "world1", btn.id },
                        async scope =>
                        {
                            ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = true;
                            Native.document.title = "zz " + new { scope.state.pushState };
                            var x = new { Native.document.body.style.backgroundColor };
                            Native.document.body.style.backgroundColor = "yellow";

                            await scope;
                            //scope.TaskCompletionSource.Task.ContinueWithResult(
                            //    delegate
                            //    {

                            Native.document.body.style.backgroundColor = x.backgroundColor;

                            ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = false;
                            Native.document.title = "zz!";
                            //    }
                            //);
                        }
                    );
                }
            );


            new IHTMLButton { innerText = "pushState2", id = "pushState2" }.AttachToDocument().WhenClicked(
                btn =>
                {

                    Native.window.history.pushState(
                        new { pushState = "world2", btn.id },
                        async scope =>
                        {
                            ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = true;
                            Native.document.title = "zz " + new { scope.state.pushState };

                            var x = new { Native.document.body.style.backgroundColor };
                            Native.document.body.style.backgroundColor = "green";

                            await scope;


                            Native.document.body.style.backgroundColor = x.backgroundColor;

                            ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = false;
                            Native.document.title = "zz!";
                        }
                    );
                }
            );
            #endregion



            // first time:
            // Application onpopstate { e = { state =  }, history = { state =  } }


            // after replaceState and reload
            // Application onpopstate { e = { state =  }, history = { state = [object Object] } }


        }
コード例 #13
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IDisclaimer page)
        {

            #region go
            Action<string> go =
                async source =>
                {
                    // show login

                    #region layout
                    var layout = new Login();

                    // loaded app will expect id's, restore em
                    layout.Login.id = "Login";

                    var newbody = layout.body;
                    var oldbody = Native.document.body;

                    // switch layouts

                    Native.document.body.parentNode.replaceChild(
                        newbody,
                        oldbody
                    );
                    #endregion


                    // how did we get the source?
                    //var app = new x(layout);

                    await new IHTMLScript { src = new Blob(source).ToObjectURL().SetInternalScriptApplicationSource() };
                };
            #endregion

            #region onclick
            page.Continue.onclick +=
                async delegate
                {
                    page.Continue.disabled = true;

                    var source = await typeof(x);

                    // we can now Activate it?
                    //Activator.CreateInstance(typeof(x));


                    Native.window.history.replaceState(
                        data: new { source },
                        title: default(string),
                        url: default(string)
                    );

                    // invoke as state?
                    //go(source);

                    Native.document.location.reload();
                };
            #endregion


            // first time:
            // Application onpopstate { e = { state =  }, history = { state =  } }


            // after replaceState and reload
            // Application onpopstate { e = { state =  }, history = { state = [object Object] } }

            #region onpopstate
            Native.window.onpopstate +=
                 e =>
                 {
                     Console.WriteLine("Application onpopstate " + new
                     {

                         e = new { e.state },
                         history = new { Native.window.history.state }

                     });

                     if (Native.window.history.state == null)
                         return;

                     dynamic state = Native.window.history.state;

                     string source = state.source;

                     page.Continue.disabled = true;

                     //Could not load type 'ctor>b__6>d__17' from assembly 'WorkerInsideSecondaryApplicationWithStateReplace.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
                     // script: error JSC1000: No implementation found for this native method, please implement [System.Threading.Tasks.Task.ContinueWith(System.Action`1[[System.Threading.Tasks.Task, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]])]

                     Task.Delay(700).GetAwaiter().OnCompleted(
                         delegate
                         {
                             go(source);

                         }
                     );

                 };
            #endregion

        }
コード例 #14
0
        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IDisclaimer page)
        {

            #region go
            Action<string> go =
                //async 
                     source =>
                     {
                         // show login

                         #region layout
                         var layout = new Login();

                         // loaded app will expect id's, restore em
                         layout.Login.id = "Login";

                         var newbody = layout.body;
                         var oldbody = Native.document.body;

                         // switch layouts

                         Native.document.body.parentNode.replaceChild(
                             newbody,
                             oldbody
                         );
                         #endregion


                         // how did we get the source?
                         //var app = new x(layout);

                         //await 

                         //new IHTMLScript { src = new Blob(source).ToObjectURL().SetInternalScriptApplicationSource() }.AttachToHead();

                         var src = new Blob(source).ToObjectURL().SetInternalScriptApplicationSource();
                         //await new IHTMLScript { src = src };
                         Native.window.eval(source);

                         // now what?
                     };
            #endregion

            #region onclick
            page.Continue.onclick +=
                async delegate
                {
                    page.Continue.disabled = true;

                    if (go.Target != null)
                        if (go.Target != Native.self)
                            throw new InvalidOperationException("we can only continue with global methods for now... " + new { go.Target });

                    var MethodToken = ((__MethodInfo)go.Method).MethodToken;


                    var source = await typeof(x);

                    // we can now Activate it?
                    //Activator.CreateInstance(typeof(x));


                    Native.window.history.replaceState(
                        new
                        {
                            Native.window.history.state,

                            hint = "typeof(x)",

                            // arguments:

                            invoke = new { function = MethodToken, arguments = new[] { source } }
                        }
                    );

                    // invoke as state?
                    //go(source);

                    // or reload?
                    Native.document.location.reload();
                };
            #endregion


            // first time:
            // Application onpopstate { e = { state =  }, history = { state =  } }


            // after replaceState and reload
            // Application onpopstate { e = { state =  }, history = { state = [object Object] } }

            #region onpopstate
            Native.window.onpopstate +=
                 e =>
                 {

                     #region x
                     var x = new Stack<Func<Task<object>>>();

                     Action<object> y = null;

                     y = xstate =>
                     {
                         if (xstate == null)
                             return;

                         dynamic state = xstate;

                         // if there is parent, we have to restore that first?

                         string hint = state.hint;

                         dynamic invoke = state.invoke;

                         string MethodToken = invoke.function;
                         object arguments = invoke.arguments;

                         x.Push(
                             delegate
                             {
                                 var z = new TaskCompletionSource<object>();
                                 var sw = new Stopwatch();
                                 sw.Start();

                                 if (!Expando.Of(Native.self).Contains(MethodToken))
                                 {
                                     //{ hint = typeof(y) } missing { MethodToken = CAAABoz2jD6nJMVTcci_a_bQ }


                                     Console.WriteLine(new { hint } + " missing " + new { MethodToken });

                                     //Could not load type 'ctor>b__6>d__17' from assembly 'WorkerInsideSecondaryApplicationWithStateReplace.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
                                     // script: error JSC1000: No implementation found for this native method, please implement [System.Threading.Tasks.Task.ContinueWith(System.Action`1[[System.Threading.Tasks.Task, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]])]
                                 }


                                 IFunction.ByName(MethodToken).ContinueWithResult(
                                     f =>
                                     {
                                         // { hint = typeof(y) } ok { MethodToken = CQAABoz2jD6nJMVTcci_a_bQ, ElapsedMilliseconds = 171 }
                                         Console.WriteLine(new { hint } + " ok " + new { MethodToken, sw.ElapsedMilliseconds });

                                         f.apply(null, args: (object[])arguments);
                                         //go(source);

                                         z.SetResult(null);
                                     }
                                 );

                                 return z.Task;
                             }
                         );

                         object parent = state.state;
                         y(parent);
                     };


                     y(Native.window.history.state);
                     #endregion


                     Console.WriteLine(
                         "Application onpopstate " + new
                         {
                             e = new { e.state },
                             history = new { Native.window.history.state }
                         }
                        + "\n steps to resume this state: " + new { x.Count }
                     );

                     //steps to resume this state: { Count = 1 }


                     Action all = async delegate
                     {
                         while (x.Count > 0)
                         {
                             await x.Pop()();
                         }

                     };

                     all();
                 };
            #endregion

        }