public void UpsertPlanContainer_Existing_Plan_Container_Succeeds()
        {
            // Arrange
            Guid containerUId = Guid.NewGuid();

            ;
            PlanContainer container = new PlanContainer()
            {
                UId  = containerUId,
                Name = _containerPrefix + containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            dal.UpsertPlanContainer(container);
            container.Description = "Modified";
            dal.UpsertPlanContainer(container);
            PlanContainer retContainer = dal.GetPlanContainerByUId(container.UId);

            // Assert
            Assert.AreEqual(container.UId, retContainer.UId);
            Assert.AreEqual(container.Name, retContainer.Name);
            Assert.AreEqual(container.Description, retContainer.Description);
        }
        public void GetPlanContainerByAny_Existing_Plan_Container_Succeeds()
        {
            Guid          containerUId = Guid.NewGuid();
            PlanContainer container    = new PlanContainer()
            {
                UId  = containerUId,
                Name = _containerPrefix + containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            dal.UpsertPlanContainer(container);
            var retContainers = dal.GetPlanContainerByAny(containerUId, null, null, null, null, null, null);

            // Assert
            Assert.IsTrue(retContainers.Count > 0);
            foreach (PlanContainer c in retContainers)
            {
                Assert.AreEqual(c.UId, container.UId);
                Assert.AreEqual(c.Name, container.Name);
            }
        }
Exemplo n.º 3
0
    private void UpdateSemestersInDataSet(PlanContainer container)
    {
        var planRow = m_collegeDataSet.Plans.Where(row =>
        {
            if (row.RowState != DataRowState.Deleted)
            {
                return(row.plan_record_id == container.PlanRecordId);
            }
            else
            {
                return(false);
            }
        }).First();

        foreach (var row in m_collegeDataSet.Semesters.Where(row =>
                                                             row.RowState != DataRowState.Deleted &&
                                                             row.plan_record_id == planRow.plan_record_id))
        {
            row.Delete();
        }
        foreach (var semesterCont in container.ListSemesters)
        {
            m_collegeDataSet.Semesters.AddSemestersRow(planRow,
                                                       semesterCont.SemesterNumber, semesterCont.HoursCount,
                                                       semesterCont.HoursPerWeek, semesterCont.HoursCountLPZ,
                                                       semesterCont.HoursCountKP, semesterCont.Exam);
        }
    }
        public Plan GetPlan(string planUniqueName)
        {
            PlanContainer      planContainer = GetPlanContainer(planUniqueName, returnTail: true, planItem: out PlanItem planItem);
            IPlanExecuteReader reader        = GetPlanExecuteReader(planContainer);

            return(reader.GetPlan(planItem.PlanFile));
        }
        public IEnumerable <string> GetPlanList(string filter = null, bool isRegexFilter = true)
        {
            PlanContainer      planContainer = GetPlanContainer(filter, returnTail: true);
            IPlanExecuteReader reader        = GetPlanExecuteReader(planContainer);

            return(reader.GetPlanList(planContainer.PlansUri, isRegexFilter));
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            EnterpriseStore     store = new EnterpriseStore();
            EnterpriseMemoryDal dal   = new EnterpriseMemoryDal(store);

            Group fooGroup = new Group {
                UId = Guid.NewGuid(), Name = "fooGroup", IsLocal = true
            };
            Group gooGroup = new Group {
                UId = Guid.NewGuid(), Name = "gooGroup", IsLocal = true
            };
            User steve = new User {
                UId = Guid.NewGuid(), Name = "steve"
            };

            dal.UpsertGroup(fooGroup);
            dal.UpsertUser(steve);
            dal.UpsertGroupMembership(new GroupMembershipItem(group: fooGroup, member: steve));

            PlanContainer top = new PlanContainer {
                UId = Guid.NewGuid(), Name = "top"
            };

            top.Security.Dacl.Add(new AccessControlEntry <FileSystemRight> {
                TrusteeUId = gooGroup.UId.Value, Right = FileSystemRight.Execute
            });
            PlanContainer child = new PlanContainer {
                UId = Guid.NewGuid(), Name = "child"
            };

            child.Security.Dacl.Add(new AccessControlEntry <FileSystemRight> {
                TrusteeUId = fooGroup.UId.Value, Right = FileSystemRight.Execute
            });
            top.Children.Add(child);

            store.Containers = new List <PlanContainer>
            {
                top
            };

            PlanItem planItem = new PlanItem
            {
                Name             = "xxx",
                UniqueName       = "xxx",
                PlanContainerUId = child.UId
            };

            store.PlanItems = new List <PlanItem>
            {
                planItem
            };


            bool hasAccess = dal.HasAccess("steve", @"top\child\xxx");
        }
Exemplo n.º 7
0
    private void AddPlanToDB(PlanContainer container)
    {
        int groupId = m_type == 0 ? m_groupSelector.GroupInfo.group_id :
                      m_planSelector.GroupInfo.group_id;

        m_college.AdapterManager.PlansTableAdapter.Insert(
            groupId, container.Subject.subject_id,
            container.SubjectType.subject_type_id, container.OKRCount,
            container.IKRCount);
        GetPlanAdapter(groupId).Fill(m_collegeDataSet.Plans);
        container.PlanRecordId = Convert.ToInt32(m_college.IdentCurrent("Plans"));
        UpdateSemestersInDataSet(container);
    }
Exemplo n.º 8
0
    private void InitList()
    {
        m_planList = new ListContainer <PlanContainer>();
        int height = new PlanContainer().Height;

        m_planList.Init(height + 5, new Point(0, m_groupSelector.Height),
                        "m_planList", new Size(), 3, 5);
        m_planList.BackColor = SystemColors.ControlLight;
        m_planList.HorizontalScroll.Enabled = false;
        m_planList.HorizontalScroll.Visible = false;
        UpdateListSize();
        Controls.Add(m_planList);
    }
        public void UpsertPlanContainer_Null_Plan_Container_Throws_Exception()
        {
            // Arrange
            PlanContainer container = null;
            DynamoDbDal   dal       = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            Exception ex = Assert.Throws <Exception>(() => dal.UpsertPlanContainer(container));

            // Assert
            StringAssert.AreEqualIgnoringCase("Plan container cannot be null.", ex.Message);
        }
        PlanContainer GetPlanContainer(string planUniqueName, bool returnTail, out PlanItem planItem)
        {
            string[] paths = planUniqueName.Split('\\');

            List <PlanContainer> list = _store.Containers;

            bool          ok   = true;
            PlanContainer root = null;
            PlanContainer tail = null;

            for (int i = 0; i < paths.Length - 1; i++)
            {
                PlanContainer curr = list.Find(x => x.Name.Equals(paths[i], StringComparison.OrdinalIgnoreCase));
                if (curr != null)
                {
                    if (tail == null)
                    {
                        tail          = curr.Clone(true);
                        tail.Security = curr.Security;
                        root          = tail;
                    }
                    else
                    {
                        PlanContainer child = curr.Clone(true);
                        child.Security = curr.Security;
                        tail.Children.Add(child);
                        tail = child;
                    }

                    list = curr.Children;
                }
                else
                {
                    ok = false;
                    break;
                }
            }

            planItem = null;
            if (ok)
            {
                planItem = _store.PlanItems.Find(p =>
                                                 p.UniqueName.Equals(paths[paths.Length - 1], StringComparison.OrdinalIgnoreCase) && p.PlanContainerUId == tail.UId);
                ok = planItem != null;
            }

            return(ok ? returnTail ? tail : root : null);
        }
        IPlanExecuteReader GetPlanExecuteReader(PlanContainer planContainer)
        {
            PlanExecuteReaderItem ri = _store.DefaultExecuteReader;

            if (planContainer.HasPlanExecuteReaderKey)
            {
                ri = _store.ExecuteReaders.SingleOrDefault(r => r.Key.Equals(planContainer.PlanExecuteReaderKey, StringComparison.OrdinalIgnoreCase));
            }

            if (ri == null)
            {
                throw new Exception($"Could not load PlanExecuteReader [{planContainer.PlanExecuteReaderKey}].");
            }

            return(AssemblyLoader.Load <IPlanExecuteReader>(ri.Type, string.Empty));
        }
        public void DeletePlanContainer_Existing_Container_Succeeds()
        {
            // Arrange
            Guid containerUId = Guid.NewGuid();

            ;
            PlanContainer container = new PlanContainer()
            {
                UId  = containerUId,
                Name = _containerPrefix + containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            dal.UpsertPlanContainer(container);

            Assert.DoesNotThrow(() => dal.DeletePlanContainer(containerUId));
        }
Exemplo n.º 13
0
    private void UpdatePlanInDataSet(PlanContainer container)
    {
        var planRow = m_collegeDataSet.Plans.Where(row =>
        {
            if (row.RowState != DataRowState.Deleted)
            {
                return(row.plan_record_id == container.PlanRecordId);
            }
            else
            {
                return(false);
            }
        }).First();

        planRow.ikr_count       = container.IKRCount;
        planRow.okr_count       = container.OKRCount;
        planRow.subject_id      = container.Subject.subject_id;
        planRow.subject_type_id = container.SubjectType.subject_type_id;

        UpdateSemestersInDataSet(container);
    }
        public void UpsertPlanContainer_Empty_Plan_Container_UId_Throws_Exception()
        {
            // Arrange
            Guid containerUId = Guid.Empty;

            ;
            PlanContainer container = new PlanContainer()
            {
                UId = containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            Exception ex = Assert.Throws <Exception>(() => dal.UpsertPlanContainer(container));

            // Assert
            StringAssert.AreEqualIgnoringCase("Plan container unique id cannot be empty.", ex.Message);
        }
        public void UpsertPlanContainer_Plan_Container_Without_Name_Throws_Exception()
        {
            // Arrange
            Guid containerUId = Guid.NewGuid();

            ;
            PlanContainer container = new PlanContainer()
            {
                UId = containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            Exception ex = Assert.Throws <Exception>(() => dal.UpsertPlanContainer(container));

            // Assert
            StringAssert.AreEqualIgnoringCase("Plan container name cannot be null or empty.", ex.Message);
        }
        public void UpsertPlanContainer_Null_Plan_Container_Table_Throws_Exception()
        {
            // Arrange
            Guid containerUId = Guid.NewGuid();

            ;
            PlanContainer container = new PlanContainer()
            {
                UId  = containerUId,
                Name = _containerPrefix + containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = ""
            };

            // Act
            Exception ex = Assert.Throws <Exception>(() => dal.UpsertPlanContainer(container));

            // Assert
            StringAssert.AreEqualIgnoringCase("Plan container table name must be specified.", ex.Message);
        }
Exemplo n.º 17
0
    private PlanContainer AddPlanContainer()
    {
        try
        {
            PlanContainer container = new PlanContainer(m_collegeDataSet.Subjects,
                                                        m_collegeDataSet.SubjectTypes);
            container.SubjectChanged += (sender, e) =>
            {
                if (e.OldSubject != null)
                {
                    foreach (var row in m_collegeDataSet.Subjects)
                    {
                        if (row.RowState == DataRowState.Deleted)
                        {
                            row.RejectChanges();
                            if (row.subject_id == e.OldSubject.subject_id)
                            {
                                break;
                            }
                            row.Delete();
                        }
                    }
                }

                var deleteRow = m_collegeDataSet.Subjects.Where(row =>
                                                                row.RowState != DataRowState.Deleted && row.subject_id ==
                                                                container.Subject.subject_id).First();
                deleteRow.Delete();
            };
            m_planList.Add(container);
            return(container);
        }
        catch (ApplicationException exc)
        {
            MyMessageBox.ShowError(exc.Message);
        }

        return(null);
    }
        public void UpsertPlanContainer_Non_Existent_Table_Throws_Exception()
        {
            // Arrange
            Guid containerUId = Guid.NewGuid();

            ;
            PlanContainer container = new PlanContainer()
            {
                UId  = containerUId,
                Name = _containerPrefix + containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = "XXXXXX"
            };

            // Act
            Exception ex = Assert.Throws <ResourceNotFoundException>(() => dal.UpsertPlanContainer(container));

            // Assert
            StringAssert.Contains("Requested resource not found: Table", ex.Message);
        }
Exemplo n.º 19
0
        public PlanContainer UpsertPlanContainer(PlanContainer planContainer)
        {
            if (planContainer == null)
            {
                throw new Exception("Plan container cannot be null.");
            }

            if (planContainer.UId == Guid.Empty)
            {
                throw new Exception("Plan container unique id cannot be empty.");
            }

            if (string.IsNullOrWhiteSpace(planContainer.Name))
            {
                throw new Exception("Plan container name cannot be null or empty.");
            }

            if (string.IsNullOrWhiteSpace(ContainerTable))
            {
                throw new Exception("Plan container table name must be specified.");
            }

            try
            {
                string   output = JsonConvert.SerializeObject(planContainer, Formatting.Indented, _settings);
                Document doc    = Document.FromJson(output);

                Table table = Table.LoadTable(_client, ContainerTable);
                table.PutItem(doc);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
                throw;
            }
            return(planContainer);
        }
Exemplo n.º 20
0
    private PlanContainer AddPlanContainerWithData(CollegeDataSet.PlansRow row)
    {
        var subjectRow = m_collegeDataSet.Subjects.
                         FindBysubject_id(row.subject_id);

        if (subjectRow == null)
        {
            throw new ApplicationException("Невозможно добавить запись, " +
                                           "т.к. запись с такой дисциплиной уже есть.");
        }

        PlanContainer container = AddPlanContainer();

        container.Subject     = CopySubjectRow(subjectRow);
        container.SubjectType = m_collegeDataSet.SubjectTypes.
                                FindBysubject_type_id(row.subject_type_id);
        container.OKRCount     = row.okr_count;
        container.IKRCount     = row.ikr_count;
        container.PlanRecordId = row.plan_record_id;
        var semesterTable = m_college.GetSemestersByPlan(row.plan_record_id);

        foreach (var semesterRow in semesterTable)
        {
            SemesterDataContainer semesterCont = new SemesterDataContainer();
            semesterCont.SemesterNumber = semesterRow.semester_number;
            semesterCont.Exam           = semesterRow.exam;
            semesterCont.HoursCount     = semesterRow.hours_count;
            semesterCont.HoursPerWeek   = semesterRow.hours_per_week;
            semesterCont.HoursCountKP   = semesterRow.kp_hours_count;
            semesterCont.HoursCountLPZ  = semesterRow.lpz_hours_count;
            container.ListSemesters.Add(semesterCont);
        }
        container.IsChanged = false;
        semesterTable.Dispose();

        return(container);
    }
        public void UpsertPlanContainer_Valid_Details_Succeeds()
        {
            // Arrange
            Guid containerUId = Guid.NewGuid();

            ;
            PlanContainer container = new PlanContainer()
            {
                UId  = containerUId,
                Name = _containerPrefix + containerUId
            };
            DynamoDbDal dal = new DynamoDbDal
            {
                ContainerTable = _containerTable
            };

            // Act
            dal.UpsertPlanContainer(container);
            PlanContainer retContainer = dal.GetPlanContainerByUId(container.UId);

            // Assert
            Assert.AreEqual(container.UId, retContainer.UId);
            Assert.AreEqual(container.Name, retContainer.Name);
        }
Exemplo n.º 22
0
    /// <summary>
    /// Computes the plan.
    /// </summary>
    /// <returns>
    /// Plan status.
    /// </returns>
    /// <param name='currentState'>
    /// Agent state.
    /// </param>
    /// <param name='_goalState'>
    /// Goal state.
    /// </param>
    /// <param name='plan'>
    /// Dictionary where plan will be stored.
    /// </param>
    /// <param name='inflation'>
    /// Inflation factor.
    /// </param>
    /// <param name='maxTime'>
    /// Maximum alloted time.
    /// </param>
    public PathStatus computePlan(ref DefaultState currentState, ref DefaultState _goalState,
                                  ref Dictionary <DefaultState, ARAstarNode> plan, ref float inflation, float maxTime)
    {
        DefaultState s = default(DefaultState);

        selectedPlanningDomain = default(PlanningDomainBase);
        goalState = _goalState;
        DetermineDomain(ref selectedPlanningDomain, ref currentState);
        currentStart = currentState;

        // introducing function that clears some temp data (e.g. tracked non det obstacles) from domain at the beginning
        // of each plan iteration
        //domain.clearAtBeginningOfEveryPlanIteration ();

        if (firstTime)
        {
            //inflationFactor = inflation;
            InitializeValues(ref currentState, ref goalState, inflation);
            Plan = new PlanContainer(plan);
            if (OneStep)
            {
                PerformOneStep();
            }
            else
            {
                ImprovePath(maxTime);
            }
        }
        else
        {
            if (goalMoved)
            {
                UpdateAfterGoalMoved(goalState);
            }
            if (moved)
            {
                UpdateAfterStartMoved(currentState);
            }

            if (inflationFactor < 1.0f)
            {
                inflationFactor = 1.0f;
            }

            //Check start node if it moved
            if (OneStep)
            {
                PerformOneStep();
            }
            else
            {
                ImprovePath(maxTime);
            }

            if (inflationFactor == 1.0f)
            {
                plannerFinished = true;
            }
        }
        //TODO: please return Status here
        //return true;
        return(Status);
        //return (inflationFactor == 1.0F);
    }
        public bool HasAccess(string securityContext, string planUniqueName, FileSystemRight right = FileSystemRight.Execute)
        {
            PlanContainer root = GetPlanContainer(planUniqueName);

            if (root == null)
            {
                throw new Exception("Plan path invalid or Plan not found.");
            }

            User user = _store.Users.GetByNameOrDefault <User>(securityContext);

            if (user == null || !user.IsEnabled)
            {
                return(false);
            }

            //stores the Guids from Suplex + ActiveDirectory for user's group membership
            List <Guid> groupMembership = new List <Guid>();

            //get the user's groupMembership from Suplex
            IEnumerable <GroupMembershipItem> gm = GetGroupMembership(user.UId.Value);

            foreach (GroupMembershipItem gmi in gm)
            {
                groupMembership.Add(gmi.GroupUId);
            }

            //get the Active Directory groupMembership, resolve the groups from Suplex
            List <string> adgm = DirectoryServicesHelper.GetGroupMembership(securityContext, ldapRoot: null, externalGroups: null);

            foreach (string group in adgm)
            {
                Group g = _store.Groups.GetByNameOrDefault <Group>(group);
                if (g != null && g.IsEnabled)
                {
                    groupMembership.Add(g.UId.Value);
                }
            }

            //delete any aces assigned to Trustees to which the user /does not belong/
            PlanContainer planCont = root;

            while (planCont != null)
            {
                for (int n = planCont.Security.Dacl.Count - 1; n >= 0; n--)
                {
                    if (!groupMembership.Contains(planCont.Security.Dacl[n].TrusteeUId.Value))
                    {
                        planCont.Security.Dacl.RemoveAt(n);
                    }
                }

                planCont = planCont.Children?.Count > 0 ? planCont.Children[0] : null;
            }

            //return root.EvalSecurity().GetByTypeRight( right ).AccessAllowed;
            //root.EvalSecurity();
            //return planCont.Security.Results.GetByTypeRight( right ).AccessAllowed;
            //eval security from top->down, return result from bottom node (last node found in while loop above)
            root.EvalSecurity();
            return(planCont.Security.HasAccess(right));
        }
Exemplo n.º 24
0
        // TODO: Check with Steve on returnAsHierarchy, startUId, validateRls
        public List <PlanContainer> GetPlanContainerByAny(Guid?planContainerUId, string name, string nodeUri, string createdBy, DateTime?createdTime, string modifiedBy, DateTime?modifiedTime, bool returnAsHierarchy = false,
                                                          Guid?startUId = null, bool validateRls = false)
        {
            List <PlanContainer> containerList = new List <PlanContainer>();

            if (string.IsNullOrWhiteSpace(ContainerTable))
            {
                throw new Exception("Plan container table name must be specified.");
            }

            try
            {
                Table      table      = Table.LoadTable(_client, ContainerTable);
                ScanFilter scanFilter = new ScanFilter();

                if (planContainerUId != null && planContainerUId != Guid.Empty)
                {
                    scanFilter.AddCondition("UId", ScanOperator.Equal, planContainerUId);
                }
                if (!string.IsNullOrWhiteSpace(name))
                {
                    scanFilter.AddCondition("Name", ScanOperator.Equal, name);
                }

                if (!string.IsNullOrWhiteSpace(nodeUri))
                {
                    scanFilter.AddCondition("NodeUri", ScanOperator.Equal, nodeUri);
                }
                if (!string.IsNullOrWhiteSpace(createdBy))
                {
                    scanFilter.AddCondition("AuditCreatedBy", ScanOperator.Equal, createdBy);
                }
                if (createdTime != null)
                {
                    scanFilter.AddCondition("AuditCreatedTime", ScanOperator.Equal, createdTime);
                }
                if (!string.IsNullOrWhiteSpace(modifiedBy))
                {
                    scanFilter.AddCondition("AuditModifiedBy", ScanOperator.Equal, modifiedBy);
                }
                if (modifiedTime != null)
                {
                    scanFilter.AddCondition("AuditModifiedTime", ScanOperator.Equal, modifiedTime);
                }

                if (scanFilter.ToConditions().Count == 0)
                {
                    throw new Exception("At least one filter condition must be specified.");
                }

                Search search = table.Scan(scanFilter);

                do
                {
                    List <Document> documentList = search.GetNextSet();
                    if (documentList.Count == 0)
                    {
                        throw new Exception("Plan container cannot be found.");
                    }

                    foreach (Document document in documentList)
                    {
                        string        json      = document.ToJsonPretty();
                        PlanContainer container = JsonConvert.DeserializeObject <PlanContainer>(json, _settings);
                        containerList.Add(container);
                    }
                } while (!search.IsDone);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
                throw;
            }

            return(containerList);
        }