Exemple #1
0
        private void HandleDragStart <TContainer, TItem, TValue>(MouseButtonEventArgs e, string format)
            where TContainer : ItemsControl
            where TItem : DependencyObject, IInputElement
        {
            TItem?listViewItem =
                ((DependencyObject)e.OriginalSource).FindAnchestor <TItem>();
            TContainer?listView = ((DependencyObject)e.OriginalSource).FindAnchestor <TContainer>();

            if (listViewItem == null || listView == null)
            {
                return;
            }

            this.startPoint = e.GetPosition(null);
            this.isDragging = false;

            var item = listView.ItemContainerGenerator.
                       ItemFromContainer(listViewItem);

            if (item is TValue element)
            {
                this.offset     = e.GetPosition(listViewItem) - default(Point);
                this.dragData   = new DataObject(format, element);
                this.dragSource = listViewItem;
            }
        }
 public void WriteNullable(TWriter writer, TItem?item)
 {
     if (!item.HasValue)
     {
         return;
     }
     Write(writer, item.Value);
 }
Exemple #3
0
        private AttributeSet?GetItemAttributeSet(TItem?item)
        {
            if (ItemAttributeSetFactory != null)
            {
                return(ItemAttributeSetFactory.Invoke(item));
            }

            return(ItemAttributeSet);
        }
        public void Save(TItem?item, int userId = Cms.Core.Constants.Security.SuperUserId)
        {
            if (item is null)
            {
                return;
            }

            using (ICoreScope scope = ScopeProvider.CreateCoreScope())

            {
                EventMessages eventMessages = EventMessagesFactory.Get();
                SavingNotification <TItem> savingNotification = GetSavingNotification(item, eventMessages);
                if (scope.Notifications.PublishCancelable(savingNotification))
                {
                    scope.Complete();
                    return;
                }

                if (string.IsNullOrWhiteSpace(item.Name))
                {
                    throw new ArgumentException("Cannot save item with empty name.");
                }

                if (item.Name != null && item.Name.Length > 255)
                {
                    throw new InvalidOperationException("Name cannot be more than 255 characters in length.");
                }

                scope.WriteLock(WriteLockIds);

                // validate the DAG transform, within the lock
                ValidateLocked(item); // throws if invalid

                item.CreatorId = userId;
                if (item.Description == string.Empty)
                {
                    item.Description = null;
                }

                Repository.Save(item); // also updates content/media/member items

                // figure out impacted content types
                ContentTypeChange <TItem>[] changes = ComposeContentTypeChanges(item).ToArray();

                // Publish this in scope, see comment at GetContentTypeRefreshedNotification for more info.
                _eventAggregator.Publish(GetContentTypeRefreshedNotification(changes, eventMessages));

                scope.Notifications.Publish(GetContentTypeChangedNotification(changes, eventMessages));

                SavedNotification <TItem> savedNotification = GetSavedNotification(item, eventMessages);
                savedNotification.WithStateFrom(savingNotification);
                scope.Notifications.Publish(savedNotification);

                Audit(AuditType.Save, userId, item.Id);
                scope.Complete();
            }
        }
Exemple #5
0
    private bool IsItemAccepted(TItem?dragTargetItem)
    {
        if (Accepts == null)
        {
            return(true);
        }

        return(Accepts(DragDropService.ActiveItem, dragTargetItem));
    }
    public TItem Copy(TItem original, string alias, string name, TItem?parent)
    {
        if (original == null)
        {
            throw new ArgumentNullException(nameof(original));
        }

        if (alias == null)
        {
            throw new ArgumentNullException(nameof(alias));
        }

        if (string.IsNullOrWhiteSpace(alias))
        {
            throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(alias));
        }

        if (parent != null && parent.HasIdentity == false)
        {
            throw new InvalidOperationException("Parent must have an identity.");
        }

        // this is illegal
        //var originalb = (ContentTypeCompositionBase)original;
        // but we *know* it has to be a ContentTypeCompositionBase anyways
        var originalb = (ContentTypeCompositionBase)(object)original;
        var clone     = (TItem)(object)originalb.DeepCloneWithResetIdentities(alias);

        clone.Name = name;

        //remove all composition that is not it's current alias
        var compositionAliases = clone.CompositionAliases().Except(new[] { alias }).ToList();

        foreach (var a in compositionAliases)
        {
            clone.RemoveContentType(a);
        }

        //if a parent is specified set it's composition and parent
        if (parent != null)
        {
            //add a new parent composition
            clone.AddContentType(parent);
            clone.ParentId = parent.Id;
        }
        else
        {
            //set to root
            clone.ParentId = -1;
        }

        Save(clone);
        return(clone);
    }
 public void Add(TItem item)
 {
     if (collectObject == null)
     {
         collectObject = new Collect <TItem>();
         firstObject   = item;
     }
     else
     {
         this.collectObject.Add(item);
     }
 }
 public void WriteNullable(
     TWriter writer,
     TItem?item,
     Action <TWriter, TItem>?write = null)
 {
     if (!item.HasValue)
     {
         return;
     }
     write ??= this.Write;
     write(writer, item.Value);
 }
        internal static bool TryGetContextItem <TItem>(this IOvBuilderContext builderContext,
                                                       out TItem?obj)
            where TItem : class
        {
            var item = builderContext.OfType <TItem>().FirstOrDefault();

            if (item != null)
            {
                obj = item;
                return(true);
            }

            obj = default !;
Exemple #10
0
    private string IsItemDragable(TItem?item)
    {
        if (item == null)
        {
            return("false");
        }
        if (AllowsDrag == null)
        {
            return("true");
        }

        return(AllowsDrag(item).ToString());
    }
        public TItem Copy(TItem original, string alias, string name, int parentId = -1)
        {
            TItem?parent = null;

            if (parentId > 0)
            {
                parent = Get(parentId);
                if (parent == null)
                {
                    throw new InvalidOperationException("Could not find parent with id " + parentId);
                }
            }
            return(Copy(original, alias, name, parent));
        }
        public IEnumerable <EntityContainer>?GetContainers(TItem?item)
        {
            var ancestorIds = item?.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
                              .Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asInt) ? asInt : int.MinValue)
                              .Where(x => x != int.MinValue && x != item.Id)
                              .ToArray();

            if (ancestorIds is null)
            {
                return(null);
            }

            return(GetContainers(ancestorIds));
        }
Exemple #13
0
        public override void Bind(TItem?item)
        {
            base.Bind(item);

            if (_itemBindingSet == null)
            {
                _itemBindingSet = new BindingSet <TItem?>(item);
                Bind(_itemBindingSet);
                _itemBindingSet.Apply();
            }
            else
            {
                _itemBindingSet.SetSourceItem(item);
            }
        }
    public IEnumerable <TItem> GetChildren(Guid id)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds);
        TItem?found = Get(id);

        if (found == null)
        {
            return(Enumerable.Empty <TItem>());
        }

        IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == found.Id);

        return(Repository.Get(query));
    }
        public int Compare(TItem?x, TItem?y)
        {
            foreach (Func <TItem, object>?item in _preSort)
            {
                if (x == null && y == null)
                {
                    continue;
                }

                if (x == null)
                {
                    return(-1);
                }

                if (y == null)
                {
                    return(1);
                }

                object?xValue = item.Invoke(x);
                object?yValue = item.Invoke(y);

                if (xValue == null && yValue == null)
                {
                    continue;
                }

                if (xValue == null)
                {
                    return(-1);
                }

                if (yValue == null)
                {
                    return(1);
                }

                int result = (xValue as IComparable).CompareTo(yValue);
                if (result == 0)
                {
                    continue;
                }

                return(!_groupSortDescending ? result : -result);
            }

            return(FinalCompare(x, y));
        }
 public Attempt <string[]?> ValidateComposition(TItem?compo)
 {
     try
     {
         using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true))
         {
             scope.ReadLock(ReadLockIds);
             ValidateLocked(compo !);
         }
         return(Attempt <string[]?> .Succeed());
     }
     catch (InvalidCompositionException ex)
     {
         return(Attempt.Fail(ex.PropertyTypeAliases, ex));
     }
 }
    public bool HasChildren(Guid id)
    {
        using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
        {
            scope.ReadLock(ReadLockIds);
            TItem?found = Get(id);
            if (found == null)
            {
                return(false);
            }

            IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == found.Id);
            var            count = Repository.Count(query);
            return(count > 0);
        }
    }
        public bool Filter(ref TItem?input, out TItem?output, ref bool willBreak)
        {
            output = input;

            if (_param != null)
            {
                if (input == null)
                {
                    return(false);
                }

                return(_param.Value.Equals(input.Value));
            }

            return(input == null);
        }
        /// <summary>
        /// Sets the SelectedItem in SharedItems.SelectedItems which raises the event SelecteItemsChanged
        /// </summary>
        protected virtual bool?SetSelectedItem(TItem?item)
        {
            _logger.LogTrace($"SetSelectedItem - set selected and Item property to {item}");

            if (item == null)
            {
                return(null);
            }

            bool?result = _itemsService.SetSelectedItem(item);

            if (result == true)
            {
                Item = item;
            }
            return(result);
        }
    public PipelineConfiguration <TItem, TData> With(TItem item)
    {
        if (_first is null)
        {
            _first = item;
            _last  = _first;
        }
        else
        {
            if (_last != null)
            {
                _last.Next = item;
            }

            _last = item;
        }
        return(this);
    }
 public int FinalCompare(TItem?x, TItem?y)
 {
     if (x != null && y != null)
     {
         if (_original.IndexOf(x) > _original.IndexOf(y))
         {
             return(1);
         }
         else if (_original.IndexOf(x) < _original.IndexOf(y))
         {
             return(-1);
         }
         else
         {
             return(0);
         }
     }
     return(0);
 }
        public static bool TryGetValue <TItem>(this IMemoryCache cache, object key, out TItem?value)
        {
            if (cache.TryGetValue(key, out object?result))
            {
                if (result == null)
                {
                    value = default;
                    return(true);
                }

                if (result is TItem item)
                {
                    value = item;
                    return(true);
                }
            }

            value = default;
            return(false);
        }
Exemple #23
0
        public VirtualOrderContainer <TItem> MoveAfter(TItem field, TItem?afterItem)
        {
            var index = GetIndex(field);

            if (afterItem == null)
            {
                MoveToIndex(index, 0);
            }
            else
            {
                var targetIndex = GetIndex(afterItem) + 1;
                if (targetIndex > index)
                {
                    targetIndex--;
                }

                MoveToIndex(index, targetIndex);
            }

            return(this);
        }
Exemple #24
0
    private string GetItemClass(TItem?item)
    {
        if (item == null)
        {
            return("");
        }
        var builder = new StringBuilder();

        builder.Append("bb-dd-draggable");
        if (ItemWrapperClass != null)
        {
            builder.Append($" {ItemWrapperClass(item)}");
        }

        var activeItem = DragDropService.ActiveItem;

        if (activeItem == null)
        {
            return(builder.ToString());
        }

        if (item.Equals(activeItem))
        {
            builder.Append(" no-pointer-events");
        }

        if (!item.Equals(activeItem) && item.Equals(DragDropService.DragTargetItem))
        {
            builder.Append(IsItemAccepted(DragDropService.DragTargetItem)
                ? " bb-dd-dragged-over"
                : " bb-dd-dragged-over-denied");
        }

        if (AllowsDrag != null && !AllowsDrag(item))
        {
            builder.Append(" bb-dd-noselect");
        }

        return(builder.ToString());
    }
    public IEnumerable <TItem> GetDescendants(int id, bool andSelf)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds);

        var descendants = new List <TItem>();

        if (andSelf)
        {
            TItem?self = Repository.Get(id);
            if (self is not null)
            {
                descendants.Add(self);
            }
        }

        var ids = new Stack <int>();

        ids.Push(id);

        while (ids.Count > 0)
        {
            var            i     = ids.Pop();
            IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == i);
            TItem[]? result = Repository.Get(query).ToArray();

            if (result is not null)
            {
                foreach (TItem c in result)
                {
                    descendants.Add(c);
                    ids.Push(c.Id);
                }
            }
        }

        return(descendants.ToArray());
    }
        /// <summary>
        /// Returns the value to be rendered in the user interface.
        /// </summary>
        /// <param name="item">The current TItem instance where to obtain the current field value.</param>
        /// <returns>A value that can be rendered in the user interface.</returns>
        public object?GetRenderValue(TItem?item)
        {
            if (item == null)
            {
                return(null);
            }
            var value = CompiledFieldFunc?.Invoke(item);

            if (value != null)
            {
                if (value is DateTimeOffset dto)
                {
                    // return simple date time string
                    return(dto.DateTime.ToString("yyyy-MM-dd"));
                }
                if (value is DateTime dt)
                {
                    // return date time string
                    return(dt.ToString("yyyy-MM-dd"));
                }
            }
            return(value);
        }
 public static bool ContainsNullable <TItem>(IEnumerable <TItem> list, TItem?value)
     where TItem : struct
 {
     return(value != null && list.Contains(value.Value));
 }
 internal ItemPropertyChangedEventArgs(TItem?item, SourceAndValue <INotifyPropertyChanged?, TValue> sourceAndValue, string propertyName)
     : base(propertyName)
 {
     this.SourceAndValue = sourceAndValue;
     this.Item           = item;
 }
Exemple #29
0
        public static TItem?SelectItem <TItem>(this ISysConsole sysConsole, IEnumerable <TItem> items, Func <TItem, string?> getCaption, TItem?defaultItem)
        {
            var selectionList = items
                                .SelectWithIndex()
                                .Select(x => new { Number = x.Index + 1, Text = getCaption(x.Data), Item = x.Data })
                                .ToArray();

            selectionList.ForEach(x => sysConsole.WriteLine($"[{x.Number}]: {x.Text}"));

            var selection = sysConsole.ReadLine();

            if (!int.TryParse(selection, out var selectionNumber))
            {
                throw new InvalidOperationException();
            }

            var selectedItem = selectionList.FirstOrDefault(x => x.Number == selectionNumber);

            return(selectedItem is null
                ? defaultItem
                : selectedItem.Item);
        }
Exemple #30
0
 public static TItem?SelectItem <TItem>(this ISysConsole sysConsole, IEnumerable <TItem> items, TItem?defaultItem)
 {
     return(sysConsole.SelectItem(items, x => x?.ToString(), defaultItem));
 }