Exemple #1
0
        public GroupInfo2(params WeShelfGroupId[] groups)
            : this()
        {
            TkDebug.AssertArgumentNull(groups, "groups", null);

            Groups.AddRange(groups);
        }
Exemple #2
0
        internal GroupInfo4(GroupInfos groupInfos)
            : this()
        {
            TkDebug.AssertArgumentNull(groupInfos, "groupInfos", null);

            Groups.AddRange(groupInfos.Groups);
        }
Exemple #3
0
        void FlushGroups()
        {
            for (int i = 0; i < Groups.Count; i++)
            {
                ListViewGroup group = Groups[i];

                if (group.Items.Count == 0)
                {
                    _groups.Remove((SmartGroup)group);
                    Groups.RemoveAt(i--);
                }
            }

            bool shouldShow = (Groups.Count > 1);

            if (ShowGroups != shouldShow)
            {
                ShowGroups = shouldShow;

                if (shouldShow)
                {
                    // Recreate the groups
                    Groups.Clear();
                    Groups.AddRange(new List <ListViewGroup>(_groups.Values).ToArray());
                }
            }
        }
 protected override void AfterGetData()
 {
     Groups.SelectMany(x => x.Units).ForEach(x => x.PropertyChanged -= UnitOnPropertyChanged);
     Groups.Clear();
     Groups.AddRange(_groups);
     Groups.SelectMany(x => x.Units).ForEach(x => x.PropertyChanged += UnitOnPropertyChanged);
 }
        internal void RefreshData(string name, XmppContactSubscriptionType subscription, IList <string> groups)
        {
            Name = ((name == null) ? String.Empty : name);

            if (!String.IsNullOrEmpty(Name))
            {
                displayName = this.name;
            }
            else
            {
                displayName = contactId.UserName;
            }

            Subscription = subscription;

            if (groups != null && groups.Count > 0)
            {
                Groups.AddRange(groups);
            }
            else
            {
                Groups.Add("Contacts");
            }

            //NotifyPropertyChanged(() => DisplayName);
            //NotifyPropertyChanged(() => Groups);
        }
Exemple #6
0
        public GroupInfo4(params GroupInfo3[] groups)
            : this()
        {
            TkDebug.AssertArgumentNull(groups, "groups", null);

            Groups.AddRange(groups);
        }
Exemple #7
0
        /// <summary>
        ///     Get the model collection :
        ///     SubModel are transformed as Module
        ///     InlineModel are transformed as Group
        /// </summary>
        /// <param name="parentModel"></param>
        /// <returns></returns>
        //TODO change name SubModel into Module - InlineModel into Group
        public virtual ModelCollection GetModelCollection(Model parentModel)
        {
            var models = new ModelCollection();

            foreach (var subModel in SubModels)
            {
                var modelCollection = subModel.GetModelCollection(null);
                Variables.AddRange(modelCollection.GetVariables());
                Groups.AddRange(modelCollection.GetGroups());
                // Add module
                Module.CreateInstance(this, subModel.Name);
                models.AddRange(modelCollection);
            }

            foreach (var subModel in InlineModels)
            {
                var modelCollection = subModel.GetModelCollection(this);
                var variables       = modelCollection.GetVariables();
                Variables.AddRange(variables);
                // Add group for each inline model
                // InlineModel.Name are the same as their parentModel, therefore we use the className
                var group = new Group(subModel.GetType().Name, Name, variables.Names);
                Groups.Add(group);
            }

            models[0] = this;
            return(models);
        }
Exemple #8
0
        internal void SortGroups(ColumnHeader columnHeader, SortOrder sortOrder, Comparison <ListViewGroup> comparison)
        {
            SetArrow(columnHeader, sortOrder);

            SortedColumn = columnHeader;
            SortOrder    = sortOrder;

            if (sortOrder != SortOrder.None)
            {
                var groups = new ListViewGroup[Groups.Count];
                Groups.CopyTo(groups, 0);

                switch (sortOrder)
                {
                case SortOrder.Ascending:
                    Array.Sort(groups, comparison);
                    break;

                case SortOrder.Descending:
                    Array.Sort(groups, comparison);
                    Array.Reverse(groups);
                    break;
                }

                Groups.Clear();
                Groups.AddRange(groups);
            }
        }
        public void Load()
        {
            UnitOfWork = Container.Resolve <IUnitOfWork>();

            var salesUnits = UnitOfWork.Repository <SalesUnit>()
                             .Find(x => !x.IsRemoved && !x.IsLoosen && !x.Product.ProductBlock.IsService && x.OrderInTakeDate <= DateTime.Today)
                             .OrderBy(salesUnit => salesUnit.EndProductionDateCalculated)
                             .Select(salesUnit => new SalesUnitDates(salesUnit))
                             .ToList();

            _salesUnits = new ValidatableChangeTrackingCollection <SalesUnitDates>(salesUnits);

            //подписываемся на изменение каждой сущности
            _salesUnits.PropertyChanged += SalesUnitsOnPropertyChanged;

            Groups.Clear();
            var groups = _salesUnits
                         .GroupBy(x => new
            {
                Cost          = x.Model.Cost,
                Facility      = x.Model.Facility.Id,
                Product       = x.Model.Product.Id,
                Order         = x.Model.Order?.Id,
                Project       = x.Model.Project.Id,
                Specification = x.Model.Specification?.Id,
                x.PickingDate
            })
                         .Select(x => new SalesUnitDatesGroup(x))
                         .OrderBy(x => x.Units.First().Model.EndProductionDateCalculated);

            Groups.AddRange(groups);
        }
 public ChemicalElementGroup(string name, List <ChemicalElementGroup> groups = null)
 {
     Name = name;
     if (groups != null)
     {
         Groups.AddRange(groups);
     }
 }
Exemple #11
0
        public GrepMatch(string fileMatchId, int line, int start, int length, IEnumerable <GrepCaptureGroup> toCopy)
        {
            LineNumber    = line;
            StartLocation = start;
            Length        = length;

            FileMatchId = fileMatchId;

            Groups.AddRange(toCopy);
        }
Exemple #12
0
 public async Task Run(MainVM mvm)
 {
     Groups.AddRange(mvm.Groups
                     .Where(g => g.Do)
                     .Where(g => g.Passthroughs.Select(p => p.Do).Any())
                     .Select(g => new GroupTestVM(this, g)));
     await Task.WhenAll(Groups
                        .SelectMany(g => g.Passthroughs.Items)
                        .Select(t => Task.Run(t.Run)));
 }
Exemple #13
0
        private async void Groups_Imported()
        {
            var group = await client.Groups.GetGroupsAsync();

            if (group)
            {
                await sync.StartNew(() =>
                {
                    Groups.Clear();
                    Groups.AddRange(group.Response);
                });
            }
        }
Exemple #14
0
        public void SetGroups(IEnumerable <IGroup> groups)
        {
            if (Groups == null)
            {
                Groups = new ObservableCollection <IGroup>();
            }

            if (groups != null)
            {
                Groups.Clear();
                Groups.AddRange(groups);
            }
        }
Exemple #15
0
        public virtual ManifestModuleInfo LoadFromExternalManifest(ExternalModuleManifest manifest, ExternalModuleManifestVersion version)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            ModuleName = manifest.Id;
            if (version.Dependencies != null)
            {
                foreach (var dependency in version.Dependencies)
                {
                    DependsOn.Add(dependency.Id);
                }
            }

            Id              = manifest.Id;
            Version         = version.SemanticVersion;
            VersionTag      = version.VersionTag;
            PlatformVersion = version.PlatformSemanticVersion;
            ReleaseNotes    = version.ReleaseNotes;
            Ref             = version.PackageUrl;

            if (version.Dependencies != null)
            {
                Dependencies.AddRange(version.Dependencies.Select(x => new ModuleIdentity(x.Id, SemanticVersion.Parse(x.Version))));
            }
            if (version.Incompatibilities != null)
            {
                Incompatibilities.AddRange(version.Incompatibilities.Select(x => new ModuleIdentity(x.Id, SemanticVersion.Parse(x.Version))));
            }

            Title       = manifest.Title;
            Description = manifest.Description;
            Authors     = manifest.Authors;
            Owners      = manifest.Owners;
            LicenseUrl  = manifest.LicenseUrl;
            ProjectUrl  = manifest.ProjectUrl;
            IconUrl     = manifest.IconUrl;
            RequireLicenseAcceptance = manifest.RequireLicenseAcceptance;
            Copyright = manifest.Copyright;
            Tags      = manifest.Tags;
            Identity  = new ModuleIdentity(Id, Version);
            if (manifest.Groups != null)
            {
                Groups.AddRange(manifest.Groups);
            }
            return(this);
        }
Exemple #16
0
        public void SetOnline(string username)
        {
            var user = server.AuthManager.GetUser(username);

            lock (server.SessionManager)
            {
                Session oldSession = server.SessionManager.GetSession(user.UserId);
                if (oldSession != null)
                {
                    oldSession.Offline(SessionOfflineReason.MultiLogin);
                }
            }
            this.SessionUser = user;
            server.SessionManager.Add(this);
            Groups.AddRange(FriendshipManager.Instance.GetAllBuddyInGroup(user.Username));
        }
Exemple #17
0
        protected internal virtual void UpdateGroup(SmartListViewItem item, string[] values)
        {
            if (VirtualMode)
            {
                return; // Not valid for virtual
            }
            StringBuilder sb = new StringBuilder();

            foreach (SmartColumn col in GroupColumns)
            {
                int c = col.AllColumnsIndex;
                if (c < values.Length)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(GroupSeparator);
                    }

                    sb.Append(values[c]);
                }
            }

            string g = sb.ToString();

            if (item.Group != null && item.Group.Name == g)
            {
                return; // Nothing to do
            }
            item.Group = null;

            SmartGroup group = (SmartGroup)Groups[g];

            if (group == null)
            {
                string txt = string.IsNullOrEmpty(g) ? "<Rest>" : g;
                group = new SmartGroup(this, g, txt);
                _groups.Add(group, group);
                Groups.Clear();
                Groups.AddRange(new List <ListViewGroup>(_groups.Values).ToArray());
            }

            group.Items.Add(item);

            RefreshGroupsAvailable();
        }
        public void Merge(YmnosStructure source)
        {
            if (source == null)
            {
                return;
            }

            Groups.AddRange(source.Groups);

            if (source.Doxastichon != null)
            {
                Doxastichon = source.Doxastichon;
            }

            if (source.Theotokion?.Count > 0)
            {
                Theotokion = source.Theotokion;
            }
        }
Exemple #19
0
        public void RebindGroups()
        {
            BeginUpdate();

            HashSet <object> setGroups = _sourceGroups != null
                ? new HashSet <object>(_sourceGroups)
                : new HashSet <object>();

            BetterListViewGroup[] toDelete = Groups.
                                             Where(g => !setGroups.Contains(g.DataObject())).
                                             ToArray();
            foreach (BetterListViewGroup group in toDelete)
            {
                Groups.Remove(group);
            }

            BetterListViewGroup[] toUpdate = Groups.
                                             Where(g => setGroups.Contains(g.DataObject())).
                                             ToArray();
            foreach (BetterListViewGroup group in toUpdate)
            {
                group.Refresh();
            }

            IEnumerable <object>       toAdd       = setGroups.Except(Groups.Select(g => g.DataObject()));
            List <BetterListViewGroup> groupsToAdd = new List <BetterListViewGroup>();

            foreach (object dataObject in toAdd)
            {
                TaskListViewSourceGroup source = new TaskListViewSourceGroup(dataObject,
                                                                             _funcGroupValueMember, _funcGroupDisplayMember);
                BetterListViewGroup group = new BetterListViewGroup();
                group.BindDataSource(source);
                groupsToAdd.Add(group);
            }
            Groups.AddRange(groupsToAdd);

            EndUpdate();
        }
        /// <summary>
        /// 加载订单
        /// </summary>
        /// <param name="orders"></param>
        internal void LoadOrders(IEnumerable <OrderItem> orders)
        {
            SuspendLayout();
            BeginUpdate();

            Items.Clear();
            var items = orders.Select(s => new OrderTicketListViewItemGroup(s, this)).ToArray();

            Groups.AddRange(items.Select(s => s.Group).ToArray());
            Items.AddRange(items.SelectMany(s => s).Cast <ListViewItem>().ToArray());
            if (Items.Count > 0)
            {
                AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
            else
            {
                AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }

            EndUpdate();
            ResumeLayout();
        }
Exemple #21
0
        void InitUi()
        {
            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            SuspendLayout();
            BeginUpdate();

            AllowAutoToolTips = true;
            CacheImages       = true;
            DoubleBuffered    = true;
            GridLines         = (BetterListViewGridLines)QueryViewConfiguration.Instance.QueryResultListGridLine;
            SmoothScroll      = true;

            Columns.AddRange(new[] {
                new BetterListViewColumnHeader("")
                {
                    Text = "车次", Width = 120, Tag = "TC", AlignHorizontal = TextAlignmentHorizontal.Center
                },
                new BetterListViewColumnHeader("")
                {
                    Text = "发站/时间", Width = 80, Tag = "TS", AlignHorizontal = TextAlignmentHorizontal.Center
                },
                new BetterListViewColumnHeader("")
                {
                    Text = "到站/时间", Width = 80, Tag = "TR", AlignHorizontal = TextAlignmentHorizontal.Center
                },
                new BetterListViewColumnHeader("")
                {
                    Text = "天数/历时", Width = 70, Tag = "TE", AlignHorizontal = TextAlignmentHorizontal.Center
                }
            });
            Columns.AddRange(_viewConfiguration.SeatOrder.Select(s => new BetterListViewColumnHeader("")
            {
                Text = ParamData.SeatType[s], Width = ParamData.SeatType[s].Length > 3 ? 65 : 53, Tag = "S" + s, AlignHorizontal = TextAlignmentHorizontal.Center
            }).ToArray());
            Columns.Add(new BetterListViewColumnHeader("")
            {
                Text = "备注", Width = 120, AlignHorizontal = TextAlignmentHorizontal.Center
            });
            Groups.AddRange(new[]
            {
                _valid,
                _noneedticket,
                _notiket,
                _ignored,
                _underControl
            });
            _hourSellListGroup         = new Dictionary <string, BetterListViewGroup>();
            ShowGroups                 = tsUseGroup.Checked = _viewConfiguration.ShowGroups;
            tsUseGroup.CheckedChanged += (s, e) =>
            {
                _viewConfiguration.ShowGroups = tsUseGroup.Checked;
                ShowGroups = tsUseGroup.Checked;
                if (ShowGroups)
                {
                    var items = Items.Cast <QueryResultListViewItem>().ToArray();
                    Items.Clear();
                    items.ForEach(AssignItemGroup);
                    Items.AddRange(items);
                }
            };
            RefreshColumnVisibility();

            //图标状态
            if (_viewConfiguration.UseStatusIcon)
            {
                tsIconTypeS.Checked = true;
            }
            else
            {
                tsIconTypeT.Checked = true;
            }
            tsIconTypeT.Click += (s, e) =>
            {
                if (tsIconTypeT.Checked)
                {
                    return;
                }

                tsIconTypeT.Checked = true;
                tsIconTypeS.Checked = false;
                _viewConfiguration.UseStatusIcon = false;
                RefreshItemIcon();
            };
            tsIconTypeS.Click += (s, e) =>
            {
                if (tsIconTypeS.Checked)
                {
                    return;
                }

                tsIconTypeS.Checked = true;
                tsIconTypeT.Checked = false;
                _viewConfiguration.UseStatusIcon = true;
                RefreshItemIcon();
            };
            SortedColumnsRowsHighlight = BetterListViewSortedColumnsRowsHighlight.ShowAlways;
            ColorSortedColumn          = Color.FromArgb(255, 245, 245, 245);
            MultiSelect = false;
            AutoSizeItemsInDetailsView = true;
            ctxResult.Opening         += (s, e) =>
            {
                var item = GetSubItemAt(PointToClient(MousePosition));
                var row  = (QueryResultListViewItem)item?.Item;

                if (row == null)
                {
                    tsmiAddToSubmit.Tag     = null;
                    tsmiAddToSubmit.Enabled = false;
                    tsmiAddToSubmit.Text    = "添加所选车次到预定列表...";
                }
                else
                {
                    tsmiAddToSubmit.Enabled = true;

                    var ticketItem = item as TicketCellSubItem;
                    if (ticketItem == null || row.ResultItem.TicketCount.GetTicketData(ticketItem.Code) == null)
                    {
                        tsmiAddToSubmit.Text = $"添加车次 [{row.ResultItem.Code}] 到预定列表";
                        tsmiAddToSubmit.Tag  = Tuple.Create(row.ResultItem, (char?)null);
                    }
                    else
                    {
                        tsmiAddToSubmit.Text = $"添加车次 [{row.ResultItem.Code}] 的 [{ParamData.GetSeatTypeName(ticketItem.Code)}] 到预定列表";
                        tsmiAddToSubmit.Tag  = Tuple.Create(row.ResultItem, (char?)ticketItem.Code);
                    }
                }

                if (DisableContextMenu)
                {
                    e.Cancel = true;
                }
            };
            //添加到预定列表
            tsmiAddToSubmit.Click += (sender, args) =>
            {
                var(train, code) = (Tuple <QueryResultItem, char?>)tsmiAddToSubmit.Tag;

                QueryParam.AutoPreSubmitConfig.AddTrainCode(train.Code);
                if (code.HasValue)
                {
                    QueryParam.AutoPreSubmitConfig.AddSeat(code.Value);
                }
            };

            //排序
            InitSortInfo();

            //拖放支持
            InitDragDrop();

            //停靠站提示
            InitTrainStopPrompt();

            EndUpdate();
            ResumeLayout();

            AppContext.MainForm.IsWindowVisibleChanged += DetectReloadData;
            VisibleChanged += DetectReloadData;
        }
Exemple #22
0
        /// <summary>
        /// FilterViewを更新する。ごちゃごちゃしてるのでなんとかしたい
        /// </summary>
        /// <param name="o"></param>
        public void SetupContents(string textForSelected)
        {
            this.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
            this.ContextMenuStrip.Items.Add("読み修正", null, correctToolStripMenuItem_Click);

            ListViewItem selected = null;
            var          colid    = (int)this.Tag;
            var          col      = Controller.Columns[colid];

            try
            {
                IEnumerable <KeyValuePair <string, int> > cf = Controller.FetchColumnValueMultipleValue(col.Name, null);

                Dictionary <char, ListViewGroup> groups = new Dictionary <char, ListViewGroup>();
                groups.Add('\0', new ListViewGroup(" " + col.LocalText));

                int count_sum             = 0;
                List <ListViewItem> items = new List <ListViewItem>();

                foreach (var e in cf)
                {
                    string name           = e.Key;
                    var    count          = e.Value;
                    char   leading_letter = '\0';
                    string header         = "";
                    if (col.MappedTagField == "DATE")
                    {
                        int year = 0;
                        int.TryParse(name.Substring(0, Math.Min(4, name.Length)), out year);
                        leading_letter = (char)year;  // .Netのcharは16bitなので、yearの数値表現をそのままつっこめる 問題ないはず
                        header         = year.ToString();
                    }
                    else // tagDate以外のとき
                    {
                        leading_letter = yomigana.GetFirst(name);
                        header         = leading_letter == '\0' ? " その他" : leading_letter.ToString();
                    }
                    // 新しいグループを追加
                    if (!groups.ContainsKey(leading_letter))
                    {
                        groups.Add(leading_letter, new ListViewGroup(header));
                    }
                    var item = new ListViewItem(new string[] { name, "" + count });
                    item.ToolTipText = name + "\n" + count + "項目";
                    item.Group       = groups[leading_letter];
                    item.Tag         = name;
                    if (name == textForSelected)
                    {
                        selected = item;
                    }
                    items.Add(item);
                    count_sum += count;
                }
                var item_allFiles = new ListViewItem(new string[] { "すべて", count_sum.ToString() });
                item_allFiles.Group = groups['\0'];
                item_allFiles.Tag   = null;
                items.Add(item_allFiles);

                var grpList = groups.Select((_) => _.Value).OrderBy((_) => _.Header).ToArray();
                this.Invoke((MethodInvoker)(() =>
                {
                    Parent.Enabled = false;
                    BeginUpdate();
                    Items.Clear();
                    Groups.AddRange(grpList);
                    Items.AddRange(items.ToArray());
                    createFilterIndex(grpList);
                    EndUpdate();
                    if (selected != null)
                    {
                        selected.Selected = true;
                        selected.EnsureVisible();
                    }
                    Parent.Enabled = true;
                }));
            }
            catch (Exception e) { Logger.Log(e.ToString()); }
            yomigana.Flush();
        }
Exemple #23
0
        public void Process(DataSourceRequest request, bool processData)
        {
            RawData = Data;

            if (request.Sorts == null)
            {
                request.Sorts = OrderBy;
            }
            else if (request.Sorts.Any())
            {
                OrderBy.Clear();
                OrderBy.AddRange(request.Sorts);
            }
            else
            {
                OrderBy.Clear();
            }

            if (request.PageSize == 0)
            {
                request.PageSize = PageSize;
            }

            PageSize = request.PageSize;

            if (request.Groups == null)
            {
                request.Groups = Groups;
            }
            else if (request.Groups.Any())
            {
                Groups.Clear();
                Groups.AddRange(request.Groups);
            }
            else
            {
                Groups.Clear();
            }

            if (request.Filters == null)
            {
                request.Filters = Filters;
            }
            else if (request.Filters.Any())
            {
                Filters.Clear();
                Filters.AddRange(request.Filters);
            }
            else
            {
                Filters.Clear();
            }

            if (!request.Aggregates.Any())
            {
                request.Aggregates = Aggregates;
            }
            else if (request.Aggregates.Any())
            {
                MergeAggregateTypes(request);

                Aggregates.Clear();
                Aggregates.AddRange(request.Aggregates);
            }
            else
            {
                Aggregates.Clear();
            }

            if (Groups.Any() && Aggregates.Any() && Data == null)
            {
                Groups.Each(g => g.AggregateFunctions.AddRange(Aggregates.SelectMany(a => a.Aggregates)));
            }

            if (Data != null)
            {
                if (processData)
                {
                    var result = Data.AsQueryable().ToDataSourceResult(request);

                    Data = result.Data;

                    Total = result.Total;

                    AggregateResults = result.AggregateResults;
                }
                else
                {
                    var wrapper = Data as IGridCustomGroupingWrapper;
                    if (wrapper != null)
                    {
                        RawData = Data = wrapper.GroupedEnumerable.AsGenericEnumerable();
                    }
                }
            }

            Page = request.Page;

            if (Total == 0 || PageSize == 0)
            {
                TotalPages = 1;
            }
            else
            {
                TotalPages = (Total + PageSize - 1) / PageSize;
            }
        }
Exemple #24
0
 protected override void AfterGetData()
 {
     Groups.AddRange(_groups);
 }
Exemple #25
0
 public Team(IEnumerable <Group> groups, object customData = null)
 {
     CustomData = customData;
     Groups.AddRange(groups);
 }
Exemple #26
0
 public TestDB()
 {
     Courses.AddRange(testCourses);
     Groups.AddRange(testGroups);
     Students.AddRange(testStudents);
 }
Exemple #27
0
        public void ApplyTemplate(TunableListTemplate template)
        {
            if (null == template)
            {
                throw new ArgumentNullException(nameof(template));
            }

            Reset();

            if (null == template.Columns)
            {
                throw new BadTemplateException("null == template.Columns");
            }

            BeginUpdate();
            Enabled = false;

            HeaderStyle = template.HeaderClickable ? ColumnHeaderStyle.Clickable : ColumnHeaderStyle.Nonclickable;

            if (template.Groups.Count > 0)
            {
                var groups = new List <ListViewGroup>();

                foreach (var groupTemplate in template.Groups)
                {
                    if (null == groupTemplate.Key)
                    {
                        throw new BadTemplateException("null == groupTemplate.Key");
                    }

                    if (null == groupTemplate.HeaderText)
                    {
                        throw new BadTemplateException("null == groupTemplate.HeaderText");
                    }

                    groups.Add(new ListViewGroup(groupTemplate.Key, groupTemplate.HeaderText));
                }

                Groups.AddRange(groups.ToArray());
                ShowGroups = true;
            }

            var columnHeaders = new List <ColumnHeader>();

            foreach (var columnTemplate in template.Columns)
            {
                if (null == columnTemplate.Name)
                {
                    throw new BadTemplateException("null == columnTemplate.Name");
                }

                if (null == columnTemplate.HeaderText)
                {
                    throw new BadTemplateException("null == columnTemplate.HeaderText");
                }

                if (0 == columnTemplate.Width)
                {
                    throw new BadTemplateException("0 == columnTemplate.Width");
                }

                var columnHeader = new ColumnHeader
                {
                    Name  = columnTemplate.Name,
                    Text  = columnTemplate.HeaderText,
                    Width = columnTemplate.Width
                };

                columnHeaders.Add(columnHeader);
            }

            Columns.AddRange(columnHeaders.ToArray());

            if (null != template.CommandMenu && 0 != template.CommandMenu.Items.Count)
            {
                _commandMenu.ApplyTemplate(template.CommandMenu);
                ContextMenuStrip = _commandMenu;
            }

            if (template.Icons.Any())
            {
                foreach (var imageTemplate in template.Icons)
                {
                    if (null == imageTemplate.Name)
                    {
                        throw new BadTemplateException("null == imageTemplate.Name");
                    }

                    var iconHolder = imageTemplate.BuildIconHolder();

                    if (null == iconHolder)
                    {
                        throw new BadTemplateException("null == iconHolder");
                    }

                    var image = iconHolder.TryBuildImage();

                    if (null != image)
                    {
                        _imageList.Images.Add(imageTemplate.Name, image);
                    }
                }

                SmallImageList = _imageList;
            }

            if (template.CheckBoxes)
            {
                CheckBoxes = true;
                OwnerDraw  = true;
            }

            Enabled = true;
            EndUpdate();
        }
Exemple #28
0
        /// <summary>
        /// Criando regras iniciais e de testes
        /// </summary>
        private void Seed_Security()
        {
            if (!Groups.Any())
            {
                var groups = new Group[]
                {
                    new Group {
                        Name = "Security"
                    },
                    new Group {
                        Name = "Management"
                    },
                    new Group {
                        Name = "Configuration"
                    },
                    new Group {
                        Name = "Sales"
                    },
                    new Group {
                        Name = "Operation"
                    }
                };

                Groups.AddRange(groups);

                foreach (var enterprise in Enterprises)
                {
                    var name = enterprise.Name.EndsWith('s')
                        ? enterprise.Name + "\'s"
                        : enterprise.Name;

                    var group = new Group
                    {
                        Name       = $"{name} User",
                        Enterprise = enterprise
                    };

                    Groups.Add(group);
                }

                SaveChanges();
            }

            if (IsTest)
            {
                if (!Users.Any())
                {
                    {
                        var enterprise = Enterprises
                                         .Single(e => e.Name == "Enterprise Test");

                        var email = $"user@{enterprise.Name}.com".Replace(" ", "").ToLower();

                        var user = new User
                        {
                            Name       = "User",
                            PublicId   = CryptoHelper.Guid("U$1"),
                            PrivateId  = CryptoHelper.Guid("U$1"),
                            Email      = email,
                            Password   = CryptoHelper.Guid("user2019"),
                            Enterprise = enterprise
                        };

                        Users.Add(user);
                    }

                    foreach (var group in Groups
                             .Where(e => e.EnterpriseId == null))
                    {
                        foreach (var enterprise in Enterprises)
                        {
                            var email = $"{group.Name}@{enterprise.Name}.com".Replace(" ", "").ToLower();

                            var user = new User
                            {
                                Name       = group.Name,
                                PublicId   = CryptoHelper.Guid(group.Name + "#" + enterprise.Name),
                                PrivateId  = CryptoHelper.Guid(group.Name + "$" + enterprise.Name),
                                Email      = email,
                                Password   = CryptoHelper.Guid(group.Name.ToLower()),
                                Enterprise = enterprise
                            };

                            Users.Add(user);

                            var userGroup = new UserGroup
                            {
                                User  = user,
                                Group = group
                            };

                            UserGroups.AddRange(userGroup);
                        }
                    }

                    SaveChanges();
                }
            }

            if (!Areas.Any())
            {
                var areas = new Area[]
                {
                    new Area {
                        Id   = (int)AreaEnum.User,
                        Name = "User"
                    },
                    new Area {
                        Id   = (int)AreaEnum.Group,
                        Name = "Group"
                    },
                    new Area {
                        Id   = (int)AreaEnum.Customer,
                        Name = "Customer"
                    }
                };

                Areas.AddRange(areas);

                SaveChanges();
            }

            if (IsTest)
            {
                if (!AreaAccess.Any())
                {
                    // Sales tem acesso de leitura e escrita no CRM

                    {
                        var area = Areas
                                   .Find((int)AreaEnum.Customer);

                        var group = Groups
                                    .First(e => e.Name == "Sales");

                        var areaAccess = new AreaAccess
                        {
                            Area      = area,
                            Group     = group,
                            CanCreate = true,
                            CanDelete = false,
                            CanModify = true,
                            CanRead   = true
                        };

                        AreaAccess.Add(areaAccess);
                    }

                    // Management tem acesso completo ao CRM

                    {
                        var area = Areas
                                   .Find((int)AreaEnum.Customer);

                        var group = Groups
                                    .First(e => e.Name == "Management");

                        var areaAccess = new AreaAccess
                        {
                            Area      = area,
                            Group     = group,
                            CanCreate = true,
                            CanDelete = true,
                            CanModify = true,
                            CanRead   = true
                        };

                        AreaAccess.Add(areaAccess);
                    }

                    // Operation só pode consultar o CRM

                    {
                        var area = Areas
                                   .Find((int)AreaEnum.Customer);

                        var group = Groups
                                    .First(e => e.Name == "Operation");

                        var areaAccess = new AreaAccess
                        {
                            Area      = area,
                            Group     = group,
                            CanCreate = false,
                            CanDelete = false,
                            CanModify = false,
                            CanRead   = true
                        };

                        AreaAccess.Add(areaAccess);
                    }

                    // Segurança pode criar novos grupos

                    {
                        var area = Areas
                                   .Find((int)AreaEnum.Group);

                        var group = Groups
                                    .First(e => e.Name == "Security");

                        var areaAccess = new AreaAccess
                        {
                            Area      = area,
                            Group     = group,
                            CanCreate = true,
                            CanDelete = true,
                            CanModify = true,
                            CanRead   = true
                        };

                        AreaAccess.Add(areaAccess);
                    }

                    // Segurança pode criar novos usuários

                    {
                        var area = Areas
                                   .Find((int)AreaEnum.User);

                        var group = Groups
                                    .First(e => e.Name == "Security");

                        var areaAccess = new AreaAccess
                        {
                            Area      = area,
                            Group     = group,
                            CanCreate = true,
                            CanDelete = true,
                            CanModify = true,
                            CanRead   = true
                        };

                        AreaAccess.Add(areaAccess);
                    }

                    SaveChanges();
                }
            }

            if (!Policies.Any())
            {
                var area = Areas
                           .Find((int)AreaEnum.User);

                var policies = new Policy[]
                {
                    new Policy {
                        Id   = (int)PolicyEnum.User_ChangePassword,
                        Area = area,
                        Name = "Change Password"
                    },
                    new Policy {
                        Id   = (int)PolicyEnum.User_ChangeEmail,
                        Area = area,
                        Name = "Change Email"
                    }
                };

                Policies.AddRange(policies);

                SaveChanges();
            }

            if (IsTest)
            {
                if (!PolicyAccess.Any())
                {
                    // Segurança tem acesso às políticas de segurança

                    {
                        var area = Areas
                                   .Find((int)AreaEnum.User);

                        var group = Groups
                                    .First(e => e.Name == "Security");

                        foreach (var policy in Policies
                                 .Where(e => e.AreaId == area.Id))
                        {
                            var policyAccess = new PolicyAccess
                            {
                                Group  = group,
                                Policy = policy
                            };

                            PolicyAccess.AddRange(policyAccess);
                        }
                    }

                    SaveChanges();
                }
            }
        }
Exemple #29
0
        public DeviceListView() : base()
        {
            InitializeComponent();

            // Properties
            AllowColumnReorder = true;
            Anchor             = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
            FullRowSelect      = true;
            GridLines          = true;
            HideSelection      = false;
            LabelWrap          = false;
            Location           = new System.Drawing.Point(12, 15);
            Size           = new System.Drawing.Size(758, 233);
            Sorting        = SortOrder.Ascending;
            SmallImageList = this.imageListDevice;
            LargeImageList = this.imageListDevice;
            TabIndex       = 0;
            UseCompatibleStateImageBehavior = false;
            View = View.Details;

            // Columns
            columnDevice = new ColumnHeader()
            {
                Text  = "Device",
                Width = 70
            };
            columnBattery = new ColumnHeader()
            {
                Text  = "Battery",
                Width = 70
            };
            columnSessionId = new ColumnHeader()
            {
                Text  = "Session Id",
                Width = 90
            };
            columnDownload = new ColumnHeader()
            {
                Text  = "Download",
                Width = 90
            };
            columnRecording = new ColumnHeader()
            {
                Text  = "Recording",
                Width = 280
            };
            Columns.AddRange(new ColumnHeader[] { columnDevice, columnSessionId, columnBattery, columnDownload, columnRecording });

            // Groups
            groupOther       = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Other.ToString(), "Devices");
            groupNewData     = new ListViewGroup(OmApiNet.OmSource.SourceCategory.NewData.ToString(), "New Data");
            groupDownloaded  = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Downloaded.ToString(), "Downloaded");
            groupDownloading = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Downloading.ToString(), "Downloading");
            groupCharging    = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Charging.ToString(), "Charging");
            groupStandby     = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Standby.ToString(), "Standby");
            groupOutbox      = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Outbox.ToString(), "Outbox");
            groupRemoved     = new ListViewGroup(OmApiNet.OmSource.SourceCategory.Removed.ToString(), "Removed");
            groupFile        = new ListViewGroup(OmApiNet.OmSource.SourceCategory.File.ToString(), "Files");

            Groups.AddRange(new ListViewGroup[] { groupOther, groupNewData, groupDownloading, groupDownloaded, groupCharging, groupStandby, groupOutbox, groupRemoved, groupFile });
        }