Пример #1
0
 private void EnsureOperationAllowed(Operations operation, IBasket basket, IVisit visit)
 {
     if (!IsOperationAllowed(User, operation, basket, visit))
     {
         throw new UnauthorizedAccessException($"User is not allowed to perform '{operation}'");
     }
 }
Пример #2
0
 public void ForeachClient(IVisit visitor)
 {
     foreach (Client client in m_clientList)
     {
         visitor.Visit(client);
     }
 }
Пример #3
0
 public void GetRightClient(IVisit visitor, int place_number)
 {
     foreach (Client element in m_clientList)
     {
         visitor.VisitToGet(element, place_number);
     }
 }
Пример #4
0
 public static VisitViewModel ToModel(this IVisit visit)
 {
     return(new VisitViewModel
     {
         ArmId = visit.ArmId,
         Code = visit.Code,
         CreatedBy = visit.CreatedBy,
         CreatedOn = visit.CreatedOn,
         Directions = visit.Directions,
         Id = visit.Id,
         IsActive = visit.IsActive,
         Name = visit.Name,
         SortOrder = visit.SortOrder,
         Status = visit.Status,
         StudyId = visit.Arm.StudyId,
         UpdatedBy = visit.UpdatedBy,
         UpdatedOn = visit.UpdatedOn,
         VisitTypeId = visit.VisitTypeId,
         CanMove = visit.CanMove,
         CanRepeat = visit.CanRepeat,
         HasChild = visit.HasChild,
         ParentVisitId = visit.ParentVisitId,
         IsBaseVisit = visit.IsBaseVisit,
         FormsCount = visit.VisitForms.Count,
         ArmName = visit.Arm.Name,
         ParentVisitName = visit.ParentVisit != null ? visit.ParentVisit.Name : ""
     });
 }
Пример #5
0
 public void VisitEachClientAndSort(IVisit visitor)
 {
     foreach (Client element in m_clientList)
     {
         visitor.VisitWithSort(element);
     }
 }
        public Task AddResultAsync(IPostBasket <Types.MatingEvent, string> basket, IVisit visit)
        {
            // get what we need out of the basket so that a response can be generated
            var male   = basket.DescentPayload.Male;
            var female = basket.DescentPayload.Female;
            var date   = basket.DescentPayload.Date;

            // we're going to patch the male and female, so there is a record of them mating
            var modifiedProps = new Dictionary <string, object> {
                { nameof(Types.Frog.DateLastMated), date }
            };

            var patchMaleBasket = new PatchBasket <int, Types.Frog, int>(
                new PatchRequest <int, Types.Frog>(new Delta <int, Types.Frog>(male.Id, modifiedProps)), basket);

            var patchFemaleBaset = new PatchBasket <int, Types.Frog, int>(
                new PatchRequest <int, Types.Frog>(new Delta <int, Types.Frog>(female.Id, modifiedProps)), basket);

            // generate some children for the male and female
            var tadpoleBaskets = GenerateTadpoles(basket, female, male, date);

            Task.WaitAll(_frogMine.SendAsync(patchMaleBasket), _frogMine.SendAsync(patchFemaleBaset));

            var tadpoleCount = tadpoleBaskets.Select(t => t.AscentPayload).Count();

            // the result of this operation is a string
            basket.AscentPayload = $"[{date:d}] {male.Name} and {female.Name} had {tadpoleCount} children";

            return(Task.CompletedTask);
        }
Пример #7
0
        /// <summary>
        /// After a "Post" request has been processed and the response basket has ascended to here
        /// any cached collection which is now invalid (i.e. does not contain the object but now should)
        /// is removed from the cache
        /// </summary>
        /// <param name="basket">The response</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task AscendFromAsync(IPostBasket <T, TId> basket, IVisit visit)
        {
            // always remove items from cache on way back up, otherwise another thread
            // may repopulate the cache before the decent is complete
            Cache.RemoveCollection();

            return(Task.CompletedTask);
        }
Пример #8
0
            public Task AddResultAsync(IBasket <int, Frog> basket, IVisit visit)
            {
                basket.AscentPayload = new Frog {
                    Id = basket.DescentPayload, Name = "Frank", DateOfBirth = DateTime.Today
                };

                return(Task.CompletedTask);
            }
Пример #9
0
        /// <summary>
        /// After a "Get Collection" request has been processed and the basket with the requested objects has ascended
        /// to here the objects will be placed in the cache.
        /// </summary>
        /// <param name="basket">The response</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task AscendFromAsync(IGetCollectionBasket <T> basket, IVisit visit)
        {
            if (basket?.AscentPayload != null && basket.DescentPayload.GetAll)
            {
                Cache.StoreCollection(basket.AscentPayload);
            }

            return(Task.CompletedTask);
        }
Пример #10
0
        /// <summary>
        /// After a "Get" request has been processed and the basket with the requested object has ascended
        /// to here the object will be placed in the cache.
        /// </summary>
        /// <param name="basket">The response</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task AscendFromAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket.AscentPayload != null)
            {
                Cache.Store(basket.DescentPayload, basket.AscentPayload);
            }

            return(Task.CompletedTask);
        }
Пример #11
0
 public IPresentation Presentate(IVisit visit)
 {
     return new VisitPresentation
                {
                    //OnlineImageUrl = _onlineImageProvider.GetOnlineImageUrl(visit.User.UserName),
                    DisplayName = visit.User1.GetDisplayName(),
                    ProfileUrl = visit.User1.GetProfileUrl(),
                    VisitDate = visit.Created.ToFormattedString()
                };
 }
Пример #12
0
        public Task AddResultAsync(IGetSingleBasket <Types.PairSelection> basket, IVisit visit)
        {
            var date = basket?.DescentPayload?.Filter?.Terms?.FirstOrDefault(
                t => t.PropertyName == nameof(Types.PairSelection.Date))?.Value as DateTime?;

            if (date == null)
            {
                throw new ArgumentException($"Expected filter on '{nameof(Types.PairSelection.Date)}'");
            }

            // only consider males which haven't mated in the past 3 months
            var maleFilter = new Filter <Types.Frog>(new[]
            {
                new FilterTerm(nameof(Types.Frog.IsMale), FilterOperators.Equal, true),
                new FilterTerm(nameof(Types.Frog.DateLastMated), FilterOperators.LessThan, date.Value.AddMonths(-3))
            });

            // ... and the same for females
            var femaleFilter = new Filter <Types.Frog>(new[]
            {
                new FilterTerm(nameof(Types.Frog.IsMale), FilterOperators.Equal, false),
                new FilterTerm(nameof(Types.Frog.DateLastMated), FilterOperators.LessThan, date.Value.AddMonths(-3))
            });

            // Try and find a suitable pair.
            // In a real application you would most likely have a single efficient DB query.  Here I just want to
            // demonstrate operating across different mines.
            // Note that the main basket is pased into these "child" baskets.  This is optional however doing this allows
            // for the baskets to be linked together when exporting tracing information (see FileTraceExporter)
            var getMaleBasket =
                new GetCollectionBasket <Types.Frog>(new GetCollectionRequest <Types.Frog>(maleFilter, 1, 0), basket);
            var getMaleTask = _frogMine.SendAsync(getMaleBasket);

            var getFemaleBasket =
                new GetCollectionBasket <Types.Frog>(new GetCollectionRequest <Types.Frog>(femaleFilter, 1, 0), basket);
            var getFemaleTask = _frogMine.SendAsync(getFemaleBasket);

            Task.WaitAll(getMaleTask, getFemaleTask);

            Types.Frog male = null;
            if (getMaleBasket.AscentPayload.Length > 0)
            {
                male = getMaleBasket.AscentPayload[0];
            }

            Types.Frog female = null;
            if (getFemaleBasket.AscentPayload.Length > 0)
            {
                female = getFemaleBasket.AscentPayload[0];
            }

            basket.AscentPayload = new Types.PairSelection(male, female, date.Value);

            return(Task.CompletedTask);
        }
Пример #13
0
        public Task AddResultAsync(IGetBasket <int, AltFrog> basket, IVisit visit)
        {
            basket.AscentPayload = new AltFrog
            {
                FrogId          = basket.DescentPayload,
                FrogName        = "Kermit",
                FrogDateOfBirth = DateTime.Today.AddDays(-30)
            };

            return(Task.CompletedTask);
        }
Пример #14
0
        public Task AddResultAsync(IGetSingleBasket <Frog> basket, IVisit visit)
        {
            basket.AscentPayload = new Frog
            {
                Id          = 465,
                Name        = "Kermit",
                DateOfBirth = DateTime.Today.AddDays(-30)
            };

            return(Task.CompletedTask);
        }
Пример #15
0
        /// <summary>
        /// After a "Delete" request has been processed and the response basket has ascended to here
        /// any cached object and collection which is now invalid is removed from the cache
        /// </summary>
        /// <param name="basket">The response</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task AscendFromAsync(IDeleteBasket <TId> basket, IVisit visit)
        {
            // always remote items from cache on way back up, otherwise another thread
            // may repopulate the cache before the decent is complete
            if (basket.DescentPayload != null)
            {
                Cache.RemoveCollection();
                Cache.Remove(basket.DescentPayload);
            }

            return(Task.CompletedTask);
        }
Пример #16
0
            public Task DescendToAsync(IBasket <int, Frog> basket, IVisit visit)
            {
                basket.AscentPayload = new Frog
                {
                    Id          = basket.DescentPayload,
                    Name        = "Early Frog",
                    DateOfBirth = DateTime.Today.AddDays(-1)
                };
                basket.ReplaceNote(new ReturnNote());

                return(Task.CompletedTask);
            }
Пример #17
0
        /// <summary>
        /// When processing a "Get" request the cache will be checked to see if the requested object is there.
        /// If it is then the cached object and a <see cref="ReturnNote"/> will be added to the basket
        /// and this will cause the shaft to pull the basket back up again, saving on the basket having to decend further
        /// down the shaft.
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task DescendToAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket.DescentPayload != null)
            {
                if (Cache.TryGet(basket.DescentPayload, out var obj))
                {
                    basket.AscentPayload = obj;
                    basket.ReplaceNote(new ReturnNote());
                }
            }

            return(Task.CompletedTask);
        }
Пример #18
0
        /// <summary>
        /// Deletes a collection of T's from the database and sets the baskets AscentPayload to the number of records affected
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IDeleteCollectionBasket <T, int> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetDeleteDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            basket.AscentPayload = await DbInterface.ExecuteNonQueryAsync(statement).ConfigureAwait(false);
        }
Пример #19
0
        /// <summary>
        /// When processing a "Get Collection" request the cache will be checked to see if the requested objects are there.
        /// If they are then the cached objects and a <see cref="ReturnNote"/> will be added to the basket
        /// and this will cause the shaft to pull the basket back up again, saving on the basket having to decend further
        /// down the shaft.
        /// </summary>
        /// <param name="basket">The request</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public Task DescendToAsync(IGetCollectionBasket <T> basket, IVisit visit)
        {
            if (basket?.DescentPayload != null && basket.DescentPayload.GetAll)
            {
                if (Cache.TryGetCollection(out var objs))
                {
                    basket.AscentPayload = objs;
                    basket.ReplaceNote(new ReturnNote());
                }
            }

            return(Task.CompletedTask);
        }
Пример #20
0
 protected virtual void SortedRTreeWalk(Item p, IVisit <T> v)
 {
     if (p.rSon != null)
     {
         SortedRTreeWalk(p.rSon, v);
     }
     v.visit(p.info);
     Console.WriteLine("-");
     if (p.lSon != null)
     {
         SortedRTreeWalk(p.lSon, v);
     }
 }
Пример #21
0
        /// <summary>
        /// вывод дерева. внутренняя функция
        /// </summary>
        /// <param name="p">вершина</param>
        /// <param name="v">интерфейс посещения вершины</param>

        protected virtual void SortedLeftTreeWalk_out(Item p, IVisit <T> v)
        {
            if (p.lSon != null)
            {
                SortedLeftTreeWalk_out(p.lSon, v);
            }
            if (v is Walk <T> )
            {
                (v as Walk <T>).visit(p.info);
            }
            if (p.rSon != null)
            {
                SortedLeftTreeWalk_out(p.rSon, v);
            }
        }
Пример #22
0
        /// <summary>
        /// Inserts the requested T into the database and sets the baskets AscentPayload to new records identity
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IPostBasket <T, TId> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetInsertDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            var id = await DbInterface.ExecuteScalarAsync(statement).ConfigureAwait(false);

            basket.AscentPayload = Descriptor.ProjectColumnValue <TId>(id);
        }
Пример #23
0
        public Task AscendFromAsync(IPostBasket <Types.MatingEvent, string> basket, IVisit visit)
        {
            // grab baskets on the way up and translate their contents
            var message = basket.AscentPayload;

            if (!string.IsNullOrWhiteSpace(message))
            {
                message = message
                          .Replace("and", "y")
                          .Replace("had", "tienen")
                          .Replace("children", "niños");

                basket.AscentPayload = message;
            }

            return(Task.CompletedTask);
        }
Пример #24
0
        public Task AddResultAsync(IGetCollectionBasket <Frog> basket, IVisit visit)
        {
            basket.AscentPayload = new[]
            {
                new Frog {
                    Id = 1, Name = "Kermit", DateOfBirth = DateTime.Today.AddDays(-30)
                },
                new Frog {
                    Id = 2, Name = "Frank", DateOfBirth = DateTime.Today.AddDays(-29)
                },
                new Frog {
                    Id = 3, Name = "Freddy", DateOfBirth = DateTime.Today.AddDays(-28)
                }
            };

            return(Task.CompletedTask);
        }
Пример #25
0
        protected override void SortedRTreeWalk(Item p, IVisit <T> v)
        {
            int i = 0;

            if (p.rSon != null)
            {
                SortedRTreeWalk(p.rSon, v);
            }
            if (Disbalance(p, ref i) == Disbalance())
            {
                v.visit(p.info);
                Console.WriteLine("+");
            }
            if (p.lSon != null)
            {
                SortedRTreeWalk(p.lSon, v);
            }
        }
Пример #26
0
        private void RaiseVisitCommand(IVisit visit)
        {
            if (visit is IVisit Visit)
            {
                var target = CommandTarget;

                var routedCmd = VisitCommand as RoutedCommand;
                if (routedCmd != null && routedCmd.CanExecute(Visit, target))
                {
                    routedCmd.Execute(Visit, target);
                }
                else if (VisitCommand != null && VisitCommand.CanExecute(Visit))
                {
                    // This is NOT a routed command. The command "VisitCommand" itself is defined
                    // below as a command source. The target is defined in DoctorView.xaml as "SelectedName" in AppointmentEditor.
                    VisitCommand.Execute(Visit);
                }
            }
        }
Пример #27
0
        /// <summary>
        /// Retreives the requested T from the database and adds it to the baskets AscendPayload
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IGetBasket <TId, T> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetSelectDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false))
            {
                if (!await rdr.ReadAsync().ConfigureAwait(false))
                {
                    throw new InvalidOperationException($"No '{typeof(T)}' record found");
                }

                basket.AscentPayload = Mapper.MapObject(rdr);
            }
        }
        /// <summary>
        /// This Handles the ScheduledAppointment event of the AppointmentDataGrid control. This event is triggered when an item selection is made.
        /// This is XAML bound in Appointments.xaml
        ///       <customcontrols:AppointmentDataGrid ...customcontrols:AppointmentListView.ScheduledAppointment  ="AppointmentDataGrid_ScheduledAppointment"...
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="ScheduledAppointmentEventArgs"/> instance containing the event data.</param>
        private void AppointmentDataGrid_ScheduledAppointment(object sender, ScheduledAppointmentEventArgs args)
        {
            AdornerClose();
            AppointmentDataGrid fe = (AppointmentDataGrid)sender;

            ((ICloseable)DataContext).RequestClose += Appointments_RequestClose;

            // The appointmentKey comes directly from the selected listview element.
            IVisit visit = (IVisit)args.appointmentKey;

            // Must set the selected visit in the AppointmentEditor before the bindings of the adorner bind it to the DataGridAnnotationControl.
            // RaiseCommand here causes the "Command" (defined below) of the Appointments.XAML to call the RelayCommand via the DoctorView.Xaml.
            // The Command Target is SelectedVisit is the AppointmentEditor.cs.
            RaiseVisitCommand(visit);

            // Creation of the adorner will create the DatGridAnnotationControl and immediately create the bindings.
            _adorner = new DataGridAnnotationAdorner(fe);

            // put adorner into the adornerlayer.
            InstallAdorner(fe, _adorner);
        }
Пример #29
0
        /// <summary>
        /// Retrieves the requested collection of T's from the database and adds them to the baskets AscendPayload
        /// </summary>
        /// <param name="basket">A basket</param>
        /// <param name="visit">The visit the basket is currently making</param>
        /// <returns>A Task that may be awaited</returns>
        public async Task AddResultAsync(IGetCollectionBasket <T> basket, IVisit visit)
        {
            if (basket == null)
            {
                throw new ArgumentNullException(nameof(basket));
            }

            var statement = GetSelectDbStatement(basket.DescentPayload);

            visit.Log(statement.ToString());

            using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false))
            {
                var objs = new List <T>();
                while (await rdr.ReadAsync().ConfigureAwait(false))
                {
                    var obj = Mapper.MapObject(rdr);
                    objs.Add(obj);
                }

                basket.AscentPayload = objs.ToArray();
            }
        }
Пример #30
0
 public void Visit(IVisit visitor)
 {
     visitor.onLabel(this);
 }
Пример #31
0
 public VisitController(IVisit visit, yamamadbContext db)
 {
     _visit = visit;
     _db    = db;
 }
Пример #32
0
 void IElement.Visit(IVisit visitor)
 {
     visitor.onButton(this);
 }
Пример #33
0
 /// <summary>
 /// вывод дерева. внешняя функция
 /// </summary>
 /// <param name="v">интерфейс посещения вершины</param>
 public virtual void SortedLeftTreeWalk_out(IVisit <T> v)
 {
     SortedLeftTreeWalk_out(root, v);
 }
Пример #34
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 public VisitLogic(IVisit context)
 {
     _context = context;
 }