Ejemplo n.º 1
0
        public GRPDEFRecord(RecordReader reader, RecordContext context)
            : base(reader, context)
        {
            this.Definition = new GroupDefinition();

            UInt16 groupNameIndex = reader.ReadIndex();

            if (groupNameIndex == 0 || groupNameIndex > context.Names.Count)
            {
                throw new InvalidDataException("GroupNameIndex is out of range.");
            }
            this.Definition.Name = context.Names[groupNameIndex - 1];

            while (!reader.IsEOF)
            {
                reader.ReadByte(); // 'type' ignored
                UInt16 segmentIndex = reader.ReadIndex();
                if (segmentIndex == 0 || segmentIndex > context.Segments.Count)
                {
                    throw new InvalidDataException("SegmentIndex is out of range.");
                }
                this.Definition.Segments.Add(context.Segments[segmentIndex - 1]);
            }

            context.Groups.Add(Definition);
        }
        /// <inheritdoc />
        protected override void AddGroupsFromTable(DataTable groupTable, ICollection<GroupDefinition> groups)
        {
            if (groupTable.Columns.Count < 2)
            {
                throw new ArgumentException("Table with groups must contains minimum two columns. GroupName and GroupId.");
            }

            groupTable.Rows.Cast<DataRow>()
                      .ToList()
                      .ForEach(
                          row =>
                              {
                                  var group = new GroupDefinition(this.Instance, row[0].ToString(), row[1].ToString())
                                                  {
                                                      GroupType = QueryScope.InstanceGroup
                                                  };

                                  foreach (DataColumn column in groupTable.Columns)
                                  {
                                      group.GroupParameters.Add(column.ColumnName, row[column].ToString());
                                  }

                                  groups.Add(group);
                              });
        }
Ejemplo n.º 3
0
        public void ConnectWithUnknownExportingGroup()
        {
            using (var source = new CancellationTokenSource())
            {
                var commands = new Mock <ICompositionCommands>();
                {
                    commands.Setup(c => c.Add(It.IsAny <GroupCompositionId>(), It.IsAny <GroupDefinition>()))
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));
                }

                var connector         = new Mock <IConnectGroups>();
                var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
                var layer             = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics);

                var exportingGroup = new GroupDefinition("Group1");
                var task           = layer.Add(exportingGroup);
                task.Wait();

                var importDefinition = GroupImportDefinition.CreateDefinition(
                    "a",
                    new GroupRegistrationId("b"),
                    null,
                    Enumerable.Empty <ImportRegistrationId>());
                Assert.Throws <UnknownPartGroupException>(() => layer.Connect(task.Result, importDefinition, new GroupCompositionId()));
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        protected override void AddGroupsFromTable(DataTable groupTable, ICollection <GroupDefinition> groups)
        {
            if (groupTable.Columns.Count < 2)
            {
                throw new ArgumentException("Table with groups must contains minimum two columns. GroupName and GroupId.");
            }

            groupTable.Rows.Cast <DataRow>()
            .ToList()
            .ForEach(
                row =>
            {
                var group = new GroupDefinition(this.Instance, row[0].ToString(), row[1].ToString())
                {
                    GroupType = QueryScope.InstanceGroup
                };

                foreach (DataColumn column in groupTable.Columns)
                {
                    group.GroupParameters.Add(column.ColumnName, row[column].ToString());
                }

                groups.Add(group);
            });
        }
Ejemplo n.º 5
0
 public RawGroup(GroupDefinition definition, ISpectrum owningSpectrum)
 {
     this._definition     = definition;
     this._components     = CreateComponents(0);
     this._owningSpectrum = owningSpectrum;
     CreateUniqueComponent(definition);
 }
Ejemplo n.º 6
0
        public SpectraContainerTabPage(ISpectraContainer container, ProjectForm projectForm)
            : base(container.Name)
        {
            this._container       = container;
            this.Name             = container.Name;
            this._projectForm     = projectForm;
            _groupsControl        = new TabControl();
            _groupsControl.Name   = "groupsControl";
            _groupsControl.Parent = this;
            _groupsControl.Dock   = DockStyle.Fill;
            int id = 0;

            foreach (IGroup group in container.Spectra[0].Parameters)
            {
                if (!projectForm.project.BindingsManager.Contains(container, group.Definition.name))
                {
                    GroupDefinition gd = group.Definition;
                    if ((gd.Type & GroupType.Hidden) != GroupType.Hidden)
                    {
                        //_groupsControl.TabPages.Add(new GroupTabPage(container.Spectra, gd, projectForm.statusStrip1, _groupsControl));
                        InsertGroupTabPage(gd.name, id++);
                    }
                }
            }
            //if (projectForm.project.BindingsManager.Contains(container))
            //    SortableGroupGrids = false;
        }
Ejemplo n.º 7
0
        public void BuildShouldCreateFlatListWhenGroupingByOneCriteria(GroupDefinition grouping)
        {
            // Arrange
            var sut = Construct(grouping, GroupDefinition.Status);

            var branch     = Substitute.For <IBranch>();
            var definition = Substitute.For <IBuildDefinition>();

            var branches    = new[] { branch };
            var definitions = new[] { definition };

            var builds = new List <IBuild>();

            var b1 = Substitute.For <IBuild>();

            b1.Definition.Returns(definition);
            b1.Branch.Returns(branch);
            builds.Add(b1);

            // Act
            var actual = sut.Build(builds, branches, definitions);

            // Assert
            var expectedCount = builds.Count;

            Assert.Equal(expectedCount, actual.Children.Count());
        }
Ejemplo n.º 8
0
        public void Add()
        {
            var lockKey     = new DatasetLockKey();
            var datasetLock = new Mock <ITrackDatasetLocks>();
            {
                datasetLock.Setup(d => d.LockForWriting())
                .Returns(lockKey)
                .Verifiable();
                datasetLock.Setup(d => d.RemoveWriteLock(It.IsAny <DatasetLockKey>()))
                .Callback <DatasetLockKey>(key => Assert.AreSame(lockKey, key))
                .Verifiable();
            }

            var originalId         = new GroupCompositionId();
            var originalDefinition = new GroupDefinition("a");
            var storage            = new Mock <IStoreGroupsAndConnections>();
            {
                storage.Setup(s => s.Add(It.IsAny <GroupCompositionId>(), It.IsAny <GroupDefinition>()))
                .Callback <GroupCompositionId, GroupDefinition>(
                    (id, def) =>
                {
                    Assert.AreSame(originalId, id);
                    Assert.AreSame(originalDefinition, def);
                });
            }

            var commands = new CompositionCommands(datasetLock.Object, storage.Object);
            var task     = commands.Add(originalId, originalDefinition);

            task.Wait();

            datasetLock.Verify(d => d.LockForWriting(), Times.Once());
            datasetLock.Verify(d => d.RemoveWriteLock(It.IsAny <DatasetLockKey>()), Times.Once());
        }
 public GroupDefinitionViewModel(GroupDefinition groupDefinition)
 {
     GroupDefinition             = groupDefinition;
     _groupByText                = StringLocalizer.GroupBy;
     SortingDefinitionsViewModel = new SortingDefinitionsViewModel(groupDefinition);
     SortingDefinitionsViewModel.SelectedSortingDefinitionChanged += OnSelectedSortingDefinitionChanged;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a new <see cref="GroupDefinition"/> to the graph and returns the ID for that group.
        /// </summary>
        /// <param name="id">The ID of the group that is being added.</param>
        /// <param name="group">The group that should be added to the graph.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="group"/> is <see langword="null" />.
        /// </exception>
        public void Add(GroupCompositionId id, GroupDefinition group)
        {
            {
                Lokad.Enforce.Argument(() => id);
                Lokad.Enforce.Argument(() => group);
            }

            if (!m_Definitions.ContainsKey(group.Id))
            {
                m_Definitions.Add(group.Id, group);
            }

            m_Groups.Add(id, group.Id);
            m_GroupConnections.AddVertex(id);

            foreach (var part in group.Parts)
            {
                var partId = new PartCompositionId(id, part.Id);
                m_Parts.Add(partId, new PartCompositionInfo(part));
                m_PartConnections.AddVertex(partId);
            }

            var parts = PartsForGroup(id);

            ConnectParts(group.InternalConnections, parts, parts);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The process group.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="parameterValues">The parameter values.</param>
        /// <param name="result">The result.</param>
        /// <param name="queryItem">The query item.</param>
        /// <param name="group">The group.</param>
        /// <param name="subProgress">The sub progress.</param>
        protected virtual void ExecuteQuery(
            QueryInfo query,
            QueryExecutionParams parameters,
            QueryInstanceResultInfo result,
            QueryItemInfo queryItem,
            GroupDefinition group,
            ProgressItem subProgress
            )
        {
            // Log.InfoFormat("146:query:'{0}'",
            //  query
            // );

            var qr = this.ExecuteQueryItemFunction.Invoke(
                this.Instance,
                queryItem,
                string.IsNullOrWhiteSpace(group.Name) ? parameters.DefaultDatabase : group.Name,
                //group.Name,
                group.Id,
                query.Parameters,
                parameters.Values.ToList(),
                subProgress
                );

            // костыль. Наверное, прибъется вообще после убиения "групп"
            qr.Database = group.Name;

            result.AddDatabaseResult(qr);
        }
Ejemplo n.º 12
0
        private string GetGroupConditionCommand(GroupDefinition bracketDefinition)
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (var condition in bracketDefinition.SeriesConnection)
            {
                switch (condition.Condition)
                {
                case Conditions.ColumnCondition:
                    stringBuilder.Append($" {GetRelationString((ColumnConditionDefinition)condition)}");
                    break;

                case Conditions.AndConjunction:
                    stringBuilder.Append(" AND");
                    break;

                case Conditions.OrConjunction:
                    stringBuilder.Append(" OR");
                    break;

                case Conditions.Bracket:
                    stringBuilder.Append($" ( {GetGroupConditionCommand((GroupDefinition)condition)} )");
                    break;

                case Conditions.Select:
                    string selectCondition = $" {condition.GetColumnName()} IN ( {GetSelectCommand(condition.GetSelectData())} )";
                    stringBuilder.Append($" ( {selectCondition.Replace(";", "")} )");
                    break;
                }
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 13
0
        private string GetConditionCommand(GroupDefinition bracketDefinition)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append($"WHERE{GetGroupConditionCommand(bracketDefinition)}");
            return(stringBuilder.ToString());
        }
 /// <inheritdoc />
 public override IEnumerable <ParameterValue> GetParametersFromDefinition(GroupDefinition definition)
 {
     return(new[] { new ParameterValue()
                    {
                        Name = string.Empty, StringValue = string.Empty
                    } });
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Adds a new <see cref="GroupDefinition"/> to the graph and returns the ID for that group.
        /// </summary>
        /// <param name="group">The group that should be added to the graph.</param>
        /// <returns>
        /// A task which returns the ID for the group.
        /// </returns>
        public Task <GroupCompositionId> Add(GroupDefinition group)
        {
            {
                Debug.Assert(group != null, "The definition that should be added should not be a null reference.");
            }

            var id         = new GroupCompositionId();
            var remoteTask = m_Commands.Add(id, group);

            m_Diagnostics.Log(
                LevelToLog.Trace,
                HostConstants.LogPrefix,
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.ProxyCompositionLayer_LogMessage_AddingGroup_WithId,
                    id));

            return(remoteTask.ContinueWith(
                       t =>
            {
                lock (m_Lock)
                {
                    m_Groups.Add(id, group);
                    m_GroupConnections.AddVertex(id);
                }

                return id;
            }));
        }
Ejemplo n.º 16
0
        public void Connect()
        {
            using (var source = new CancellationTokenSource())
            {
                var commands = new Mock <ICompositionCommands>();
                {
                    commands.Setup(c => c.Add(It.IsAny <GroupCompositionId>(), It.IsAny <GroupDefinition>()))
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));

                    commands.Setup(c => c.Connect(It.IsAny <GroupConnection>()))
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));
                }

                var connector = new Mock <IConnectGroups>();
                {
                    connector.Setup(
                        c => c.GenerateConnectionFor(
                            It.IsAny <GroupDefinition>(),
                            It.IsAny <GroupImportDefinition>(),
                            It.IsAny <GroupDefinition>()))
                    .Callback <GroupDefinition, GroupImportDefinition, GroupDefinition>(
                        (importingGroup, importDef, exportingGroup) => { })
                    .Returns(Enumerable.Empty <PartImportToPartExportMap>());
                }

                var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
                var layer             = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics);

                var exportingDefinition = new GroupDefinition("Group1");
                var addTask             = layer.Add(exportingDefinition);
                var exportingId         = addTask.Result;

                var importingDefinition = new GroupDefinition("Group2");
                addTask = layer.Add(importingDefinition);
                var importingId = addTask.Result;

                var importDefinition = GroupImportDefinition.CreateDefinition(
                    "a",
                    new GroupRegistrationId("b"),
                    null,
                    Enumerable.Empty <ImportRegistrationId>());
                var connectTask = layer.Connect(importingId, importDefinition, exportingId);
                connectTask.Wait();

                Assert.IsTrue(layer.IsConnected(importingId, importDefinition));
                Assert.IsTrue(layer.IsConnected(importingId, importDefinition, exportingId));
                Assert.AreEqual(exportingId, layer.ConnectedTo(importingId, importDefinition));
            }
        }
Ejemplo n.º 17
0
        public double MemoryInt = 0; ///po normalizacji
        ///kiedy intensywności mają wejść do parametrów searchu
        ///tutaj przechowywana będzie intensywność pierwszej składowej
        ///brana później do obliczania doubleAsterixSum (suma intensywności wolnych
        ///w search'u)

        public ContributedGroup(GroupDefinition definition, ISpectrum owningSpectrum)
        {
            this._definition     = definition;
            this._components     = CreateComponents(0);
            contribution         = new Parameter("contribution", this);
            this._owningSpectrum = owningSpectrum;
            CreateUniqueComponent(definition);
        }
Ejemplo n.º 18
0
        public GroupDefinition <T> Group(String displayName, short row, short column, String visible, int?rowspan = null, int?columnspan = null)
        {
            GroupDefinition <T> group = new GroupDefinition <T>(displayName, row, column, visible, rowspan, columnspan);

            Groups.Add(group);

            return(group);
        }
 private void refilterCatalog(GroupDefinition themeDefinition)
 {
     resetCatalog();
     filteredDefinitions.AddRange(filterDecorationListByTheme(themeDefinition));
     filteredDefinitions.AddRange(filterStructureListByTheme(themeDefinition));
     filteredDefinitions = sortDisplayedList(filteredDefinitions);
     PooledScrollRect.RefreshList(filteredDefinitions.Count);
 }
Ejemplo n.º 20
0
 /// <summary>
 ///     Constructor (without database).
 /// </summary>
 /// <param name="templateNode">Template node.</param>
 /// <param name="connection">Information group on connection.</param>
 public ConcreteTemplateNodeDefinition(TemplateNodeInfo templateNode, ConnectionGroupInfo connection)
 {
     this._templateNode = templateNode;
     this._group        = GroupDefinition.NullGroup;
     this.Connection    = connection;
     this.NodeActivated = true;
     this.NodeAvailable = true;
 }
Ejemplo n.º 21
0
        /// <summary>
        ///     Constructor (with database).
        /// </summary>
        /// <param name="templateNode">Template node.</param>
        /// <param name="group">Database.</param>
        /// ///
        /// <param name="connection">Connection group information.</param>
        public ConcreteTemplateNodeDefinition(TemplateNodeInfo templateNode, GroupDefinition @group, ConnectionGroupInfo connection)
        {
            Debug.Assert(templateNode.IsInstance);

            this._templateNode = templateNode;
            this._group        = @group;
            this.Connection    = connection;
            this.NodeActivated = true;
            this.NodeAvailable = true;
        }
Ejemplo n.º 22
0
        public void ReloadFromDataset()
        {
            var importingId = new GroupCompositionId();
            var exportingId = new GroupCompositionId();

            var importingGroup = new GroupDefinition("Group1");
            var exportingGroup = new GroupDefinition("Group2");

            var importDefinition = GroupImportDefinition.CreateDefinition(
                "a",
                new GroupRegistrationId("b"),
                null,
                Enumerable.Empty <ImportRegistrationId>());

            var state = new GroupCompositionState(
                new List <Tuple <GroupCompositionId, GroupDefinition> >
            {
                new Tuple <GroupCompositionId, GroupDefinition>(importingId, importingGroup),
                new Tuple <GroupCompositionId, GroupDefinition>(exportingId, exportingGroup),
            },
                new List <Tuple <GroupCompositionId, GroupImportDefinition, GroupCompositionId> >
            {
                new Tuple <GroupCompositionId, GroupImportDefinition, GroupCompositionId>(importingId, importDefinition, exportingId)
            });

            using (var source = new CancellationTokenSource())
            {
                var commands = new Mock <ICompositionCommands>();
                {
                    commands.Setup(c => c.CurrentState())
                    .Returns(
                        Task <GroupCompositionState> .Factory.StartNew(
                            () => state,
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));
                }

                var connector         = new Mock <IConnectGroups>();
                var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
                var layer             = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics);
                var task = layer.ReloadFromDataset();
                task.Wait();

                Assert.IsTrue(layer.Contains(importingId));
                Assert.AreEqual(importingGroup, layer.Group(importingId));

                Assert.IsTrue(layer.Contains(exportingId));
                Assert.AreEqual(exportingGroup, layer.Group(exportingId));

                Assert.IsTrue(layer.IsConnected(importingId, importDefinition));
                Assert.IsTrue(layer.IsConnected(importingId, importDefinition, exportingId));
                Assert.AreEqual(exportingId, layer.ConnectedTo(importingId, importDefinition));
            }
        }
Ejemplo n.º 23
0
 /// <inheritdoc />
 public override IEnumerable <ParameterValue> GetParametersFromDefinition(GroupDefinition definition)
 {
     return
         (definition.GroupParameters.Select(
              groupParameter =>
              new ParameterValue()
     {
         Name = "@" + groupParameter.Key,
         StringValue = groupParameter.Value
     }));
 }
Ejemplo n.º 24
0
 public DefaultGroupGUI(DataGridView gridView, List <ISpectrum> spectra, GroupDefinition groupDefinition, GroupTabPage groupTabPage)
 {
     this.gridView        = gridView;
     this.spectra         = spectra;
     this.groupDefinition = groupDefinition;
     //this.comparers = new List<Comparer<ISpectrum>>();
     this.numberFormat = new CultureInfo("en-US", false).NumberFormat;
     this.numberFormat.NumberDecimalSeparator = ".";
     this.parentProject = spectra[0].Container.ParentProject;
     this.groupTabPage  = groupTabPage;
 }
 /// <inheritdoc />
 public override IEnumerable<ParameterValue> GetParametersFromDefinition(GroupDefinition definition)
 {
     return
         definition.GroupParameters.Select(
             groupParameter =>
             new ParameterValue()
                 {
                     Name = "@" + groupParameter.Key,
                     StringValue = groupParameter.Value
                 });
 }
Ejemplo n.º 26
0
        private void toolStripButton1_Click(object sender, System.EventArgs e)
        {
            GroupDefinition gd = new GroupDefinition();

            gd       = this._patternGroupsDefinition[1];
            gd.Type &= ~GroupType.CalcContribution;
            gd.name  = String.Format("Package {0}", this._groupCounter++);
            groupsGrid.RowCount++;
            groupsGrid.Rows[groupsGrid.RowCount - 1].Cells[0].Value = gd;
            groupsGrid.Rows[groupsGrid.RowCount - 1].Cells[1].Value = gd.name;
            groupsGrid.Rows[groupsGrid.RowCount - 1].Cells[2].Value = (gd.Type & GroupType.CalcContribution) == GroupType.CalcContribution;
        }
Ejemplo n.º 27
0
 public SortingDefinitionsViewModel(GroupDefinition forGroupDefinition)
 {
     ForGroupDefinition = forGroupDefinition;
     Sortings           = new RemoveTrackingObservableCollection <SortingDefinitionViewModel>
     {
         new SortingDefinitionViewModel(forGroupDefinition, SortingDefinition.AlphabeticalDescending),
         new SortingDefinitionViewModel(forGroupDefinition, SortingDefinition.AlphabeticalAscending),
         new SortingDefinitionViewModel(forGroupDefinition, SortingDefinition.StatusAscending),
         new SortingDefinitionViewModel(forGroupDefinition, SortingDefinition.StatusDescending)
     };
     SelectedViewModel = Sortings.First();
 }
Ejemplo n.º 28
0
        public void Remove()
        {
            GroupCompositionId storedId         = null;
            GroupDefinition    storedDefinition = null;

            using (var source = new CancellationTokenSource())
            {
                var commands = new Mock <ICompositionCommands>();
                {
                    commands.Setup(c => c.Add(It.IsAny <GroupCompositionId>(), It.IsAny <GroupDefinition>()))
                    .Callback <GroupCompositionId, GroupDefinition>(
                        (id, def) =>
                    {
                        storedId         = id;
                        storedDefinition = def;
                    })
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));

                    commands.Setup(c => c.Remove(It.IsAny <GroupCompositionId>()))
                    .Callback <GroupCompositionId>(id => storedId = id)
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));
                }

                var connector         = new Mock <IConnectGroups>();
                var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
                var layer             = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics);

                var definition = new GroupDefinition("Group1");
                var task       = layer.Add(definition);
                task.Wait();

                Assert.AreSame(storedId, task.Result);
                Assert.AreSame(definition, storedDefinition);
                Assert.IsTrue(layer.Contains(task.Result));

                var otherTask = layer.Remove(task.Result);
                otherTask.Wait();

                Assert.AreSame(task.Result, storedId);
                Assert.IsFalse(layer.Contains(task.Result));
            }
        }
Ejemplo n.º 29
0
 public SharedGroupTabPage(List <ISpectrum> spectra,
                           GroupDefinition definition,
                           StatusStrip statusStrip,
                           TabControl parentTabControl,
                           ProjectForm parentProjectForm,
                           GroupBinding binding)
     : base(spectra, definition, statusStrip, parentTabControl, parentProjectForm)
 {
     this._binding  = binding;
     grid.FixedCols = 3;
     UpdateName();
     refreshReferences();
 }
Ejemplo n.º 30
0
        private static SegmentGroup ConvertGroupDefinition(
            GroupDefinition def, Dictionary <object, object> objectMap)
        {
            SegmentGroup group = new SegmentGroup();

            group.Name     = def.Name;
            group.Segments = new LogicalSegment[def.Segments.Count];
            for (int i = 0; i < group.Segments.Length; i++)
            {
                group.Segments[i] = (LogicalSegment)objectMap[def.Segments[i]];
            }
            return(group);
        }
        private List <StaticGameDataDefinition> filterStructureListByTheme(GroupDefinition themeDefinition)
        {
            List <StaticGameDataDefinition> list = new List <StaticGameDataDefinition>();

            foreach (StaticGameDataDefinitionKey key in GroupDefinitionHelper.GetKeys <StructureDefinition>(themeDefinition))
            {
                if (int.TryParse(key.Id, out var result) && structureDefinitions.ContainsKey(result))
                {
                    list.Add(structureDefinitions[result]);
                }
            }
            return(list);
        }
        public void DefineImportWithObjectImports()
        {
            var             plugins    = CreatePluginTypes();
            GroupDefinition groupInfo  = null;
            var             repository = new Mock <IPluginRepository>();
            {
                repository.Setup(r => r.Parts())
                .Returns(plugins);
                repository.Setup(r => r.AddGroup(It.IsAny <GroupDefinition>(), It.IsAny <PluginFileInfo>()))
                .Callback <GroupDefinition, PluginFileInfo>((g, f) => groupInfo = g);
            }

            var importEngine = new Mock <IConnectParts>();
            {
                importEngine.Setup(i => i.Accepts(It.IsAny <SerializableImportDefinition>(), It.IsAny <SerializableExportDefinition>()))
                .Returns(true);
            }

            Func <Type, TypeIdentity>   identityGenerator = t => TypeIdentity.CreateDefinition(t);
            Func <IBuildFixedSchedules> scheduleBuilder   = () => new FixedScheduleBuilder();

            var builder = new GroupDefinitionBuilder(
                repository.Object,
                importEngine.Object,
                identityGenerator,
                scheduleBuilder,
                new PluginFileInfo("a", DateTimeOffset.Now));
            var firstInfo = builder.RegisterObject(typeof(ImportOnProperty));

            var groupImportName = "groupImport";

            builder.DefineImport(groupImportName, new List <ImportRegistrationId> {
                firstInfo.RegisteredImports.First()
            });

            var groupName = "MyGroup";

            builder.Register(groupName);

            Assert.IsNotNull(groupInfo);
            Assert.AreEqual(new GroupRegistrationId(groupName), groupInfo.GroupImports.First().ContainingGroup);
            Assert.IsNull(groupInfo.GroupImports.First().ScheduleInsertPosition);

            Assert.That(
                groupInfo.GroupImports.First().ImportsToMatch,
                Is.EquivalentTo(
                    new List <ImportRegistrationId>
            {
                firstInfo.RegisteredImports.First(),
            }));
        }
		/// <inheritdoc />
		protected override void ExecuteQuery(
			QueryInfo               query,
			QueryExecutionParams    parameters,
			QueryInstanceResultInfo result,
			QueryItemInfo           queryItem,
			GroupDefinition         group,
			ProgressItem            subProgress
		)
		{
			var tempValues = new List<ParameterValue>(parameters.Values);

			foreach (var parameter in group.GroupParameters)
			{
				tempValues.Add(new ParameterValue
					{
						Name        = "@" + parameter.Key,
						StringValue = parameter.Value
					}
				);
			}

			QueryDatabaseResultInfo databaseResult = this.ExecuteQueryItemFunction.Invoke(
				this.Instance,
				queryItem,
				null,
				null,
				query.Parameters,
				tempValues,
				subProgress
			);

			databaseResult.Database   = group.Name;
			databaseResult.DatabaseId = group.Id;

			result.AddDatabaseResult(databaseResult);
		}
 /// <inheritdoc />
 public override IEnumerable<ParameterValue> GetParametersFromDefinition(GroupDefinition definition)
 {
     return new[] { new ParameterValue() { Name = string.Empty, StringValue = string.Empty } };
 }
Ejemplo n.º 35
0
		/// <summary>
		/// The execute query.
		/// </summary>
		/// <param name="query">The query.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <param name="progress">The progress.</param>
		/// <param name="groups">The groups.</param>
		/// <param name="result">The result.</param>
		/// <param name="queryItem">The query item.</param>
		private void ExecuteQuery(
			QueryInfo               query,
			QueryExecutionParams    parameters,
			ProgressItem            progress,
			GroupDefinition[]       groups,
			QueryInstanceResultInfo result,
			QueryItemInfo           queryItem
		)
		{
			// Log.InfoFormat("query:'{0}'",
			// 	query
			// );

			Debug.Assert(groups.Length <= 1);

			if (groups.Length == 0)
			{
				this.ExecuteQuery(
					query,
					parameters,
					result,
					queryItem,
					new GroupDefinition(
						this.Instance,
						string.Empty,
						string.Empty
					),
					progress
				);

				ProgressComplete(progress);
			}
			else
			{
				foreach (var group in groups)
				{
					if (group.ChildGroups.Count > 0)
					{
						var tempParams = parameters.Clone();

						tempParams.AddValues(
							this.GetGroupsResolver().GetParametersFromDefinition(group)
						);

						this.ExecuteQuery(
							query,
							tempParams,
							progress,
							group.ChildGroups.ToArray(),
							result,
							queryItem
						);
					}

					ProgressItem subProgress = null;

					if (progress != null)
					{
						try
						{
							subProgress = progress.GetChild();
						}
						catch (Exception)
						{
						}
					}

					this.ExecuteQuery(
						query,
						parameters,
						result,
						queryItem,
						@group,
						subProgress
					);

					ProgressComplete(subProgress);
				}
			}
		}
Ejemplo n.º 36
0
		/// <summary>
		/// Executes multyquery for database
		/// </summary>
		/// <param name="group">Database definition</param>
		/// <param name="templateNodeQueryInfos">Template nodes</param>
		/// <param name="progress">Progress item</param>
		/// <returns>Multyquery result</returns>
		public MultyQueryResultInfo ExecuteMultyQuery(
			GroupDefinition             @group,
			List<TemplateNodeQueryInfo> templateNodeQueryInfos,
			ProgressItem                progress
		)
		{
			////////////////////////////////////////////////////////////////////////////////////////
			// string strLogMessage = "DEBUG:MSSQLServerAuditor.Model.ExecuteMultyQuery(2)";
			// strLogMessage = strLogMessage + ";GD:" + @group.ToString();
			// log.Debug(strLogMessage);
			////////////////////////////////////////////////////////////////////////////////////////

			MultyQueryResultInfo result = new MultyQueryResultInfo();

			progress.SetPromisedChildCount(templateNodeQueryInfos.Count);

			foreach (TemplateNodeQueryInfo queryInfo in templateNodeQueryInfos)
			{
				List<QueryInfo> queries = this._model.GetQueryByTemplateNodeQueryInfo(queryInfo);

				QueryInfo query = queries.FirstOrDefault(x =>
					x.Source == (@group.Instance.Type) || x.Source == QuerySource.SQLite);

				if ((query.Source == QuerySource.MSSQL || query.Source == QuerySource.TDSQL) && this._skipMsSqlQueries)
				{
					continue;
				}

				QueryExecutionParams parameters = QueryExecutionParams.CreateFrom(queryInfo);

				QueryResultInfo queryResult = ExecuteQuery(
					@group,
					query,
					parameters,
					progress.GetChild()
				);

				result.Add(new TemplateNodeResultItem(queryInfo, queryResult));

				if (this._cancellationToken.IsCancellationRequested)
				{
					break;
				}
			}

			return result;
		}
Ejemplo n.º 37
0
		private QueryResultInfo ExecuteQuery(
			GroupDefinition      groupDefinition,
			QueryInfo            query,
			QueryExecutionParams parameters,
			ProgressItem         progress = null
		)
		{
			QueryResultInfo queryResult = new QueryResultInfo();
			InstanceInfo instance       = groupDefinition.Instance;

			QueryExecutorFactory factory = new QueryExecutorFactory(
				instance,
				this.ExecuteQueryItem,
				this.ExecuteSql
			);

			BaseQueryExecutor executor = factory.GetExecutor(
				query.Scope
			);

			CurrentStorage storage = this._model.GetVaultProcessor(
				instance.ConnectionGroup).CurrentStorage;

			ServerProperties props = instance.InitServerProperties(storage);
			QueryInstanceResultInfo instanceResult = executor.ExecuteQuerySimple(
				query,
				parameters,
				props.Version,
				progress,
				groupDefinition
			);

			queryResult.AddInstanceResult(instanceResult);

			return queryResult;
		}
Ejemplo n.º 38
0
		/// <summary>
		/// The process group.
		/// </summary>
		/// <param name="query">The query.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <param name="result">The result.</param>
		/// <param name="queryItem">The query item.</param>
		/// <param name="group">The group.</param>
		/// <param name="subProgress">The sub progress.</param>
		protected virtual void ExecuteQuery(
			QueryInfo               query,
			QueryExecutionParams    parameters,
			QueryInstanceResultInfo result,
			QueryItemInfo           queryItem,
			GroupDefinition         group,
			ProgressItem            subProgress
		)
		{
			// Log.InfoFormat("146:query:'{0}'",
			// 	query
			// );

			var qr = this.ExecuteQueryItemFunction.Invoke(
				this.Instance,
				queryItem,
				string.IsNullOrWhiteSpace(group.Name) ? parameters.DefaultDatabase : group.Name,
				//group.Name,
				group.Id,
				query.Parameters,
				parameters.Values.ToList(),
				subProgress
			);

			// костыль. Наверное, прибъется вообще после убиения "групп"
			qr.Database = group.Name;

			result.AddDatabaseResult(qr);
		}
Ejemplo n.º 39
0
		internal IEnumerable<GroupDefinition> ExtractDatabases()
		{
			List<GroupDefinition> databases = new List<GroupDefinition>();

			foreach (TemplateNodeResultItem resultItem in List)
			{
				foreach (var instancePair in resultItem.QueryResult.InstancesResult)
				{
					if ((instancePair.Value.ErrorInfo != null) && (!databases.Contains(GroupDefinition.NullGroup)))
					{
						databases.Add(GroupDefinition.NullGroup);
					}

					foreach (var databasePair in instancePair.Value.DatabasesResult)
					{
						GroupDefinition database = new GroupDefinition(
							instancePair.Value.Instance,
							databasePair.Value.Database,
							databasePair.Value.DatabaseId
						);

						if (!databases.Contains(database))
						{
							databases.Add(database);
						}
					}
				}
			}

			if (databases.Count == 0)
			{
				databases.Add(GroupDefinition.NullGroup);
			}

			return databases;
		}
Ejemplo n.º 40
0
		/// <summary>
		/// The get child groups definitions.
		/// </summary>
		/// <param name="parent">The parent.</param>
		/// <param name="parentDefinition">The parent definition.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <param name="version">The version.</param>
		private void GetChildGroupsDefinitions(
			QueryItemInfo               parent,
			GroupDefinition             parentDefinition,
			IEnumerable<ParameterValue> parameterValues,
			InstanceVersion             version
		)
		{
			QueryItemInfo childGroupSql = parent.ChildGroups.GetQueryItemForVersion(version);
			var           tempParams    = parameterValues.ToList();

			tempParams.AddRange(this.GetParametersFromDefinition(parentDefinition));

			try
			{
				DataTable[] groupsTabels = this.ExecuteSqlFunction(
					this.Instance,
					childGroupSql,
					null,
					childGroupSql.Parameters,
					tempParams,
					null,
					true
				);

				foreach (DataTable groupTable in groupsTabels)
				{
					this.AddGroupsFromTable(groupTable, parentDefinition.ChildGroups);
				}

				if (childGroupSql.ChildGroups == null || childGroupSql.ChildGroups.Count <= 0)
				{
					return;
				}

				foreach (GroupDefinition childGroup in parentDefinition.ChildGroups)
				{
					this.GetChildGroupsDefinitions(childGroupSql, childGroup, tempParams, version);
				}
			}
			catch (OperationCanceledException ex)
			{
				log.Error(ex);
				throw;
			}
			catch (Exception ex)
			{
				log.Error("instance=" + this.Instance.Name + " query=" + childGroupSql, ex);
			}
		}
Ejemplo n.º 41
0
		/// <summary>
		/// The get parameters from definition.
		/// </summary>
		/// <param name="definition">
		/// The parent definition.
		/// </param>
		/// <returns>
		/// The <see cref="IEnumerable{T}"/>.
		/// </returns>
		public abstract IEnumerable<ParameterValue> GetParametersFromDefinition(GroupDefinition definition);
Ejemplo n.º 42
0
		/// <summary>
		/// The prepare progress.
		/// </summary>
		/// <param name="progress">The progress.</param>
		/// <param name="groups">The groups.</param>
		private void PrepareProgress(ProgressItem progress, GroupDefinition[] groups)
		{
			if (progress != null)
			{
				if (groups.Length > 0)
				{
					progress.SetPromisedChildCount(groups.Length);
				}
				else
				{
					progress.SetProgress(100);
				}
			}
		}