示例#1
0
            public void AllowModificationWithOutChangeset()
            {
                string batchRequestsDirectory = Path.Combine(TestUtil.ServerUnitTestSamples, @"tests\BatchRequests");

                using (OpenWebDataServiceHelper.EntitySetAccessRule.Restore())
                    using (OpenWebDataServiceHelper.ServiceOperationAccessRule.Restore())
                    {
                        CustomRowBasedContext.PreserveChanges = false;
                        TestUtil.RunCombinations(
                            new string[] { "4.0" },
                            (dataServiceVersion) =>
                        {
                            Type contextType      = typeof(CustomRowBasedContext);
                            string requestContent = File.ReadAllText(Path.Combine(batchRequestsDirectory, "ModificationOutsideChangesetbatch" + ".txt"));

                            string responseFileName = "ModificationOutsideChangesetresponse.txt";

                            responseFileName = Path.Combine(batchRequestsDirectory, responseFileName);
                            using (ChangeScope.GetChangeScope(contextType))
                            {
                                string actualResponse = BatchTestUtil.GetResponse(requestContent, contextType, WebServerLocation.InProcess, dataServiceVersion);
                                BatchTestUtil.CompareBatchResponse(responseFileName, actualResponse);
                            }
                        });
                    }
            }
        /// <summary>
        /// Run the delegates for Element and Diagram for the current element.
        /// - changeScope.Item   Only Element itself and Diagrams of element, not beneath element
        /// - changeScope...     Element and all beneath Element
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="el"></param>
        /// <param name="setEl"></param>
        /// <param name="setDia"></param>
        /// <param name="parameterStrings"></param>
        /// <param name="changeScope"></param>
        public static void DoRecursiveEl(Repository rep, EA.Element el, SetElement setEl, SetDiagram setDia,
                                         string[] parameterStrings, ChangeScope changeScope)
        {
            // perform change for element
            setEl?.Invoke(rep, el, parameterStrings);

            // perform changes for diagrams beneath element
            foreach (EA.Diagram dia in el.Diagrams)
            {
                if (dia != null)
                {
                    setDia?.Invoke(rep, dia, parameterStrings);
                }
            }
            // only the item itself, no recursion
            if (changeScope == ChangeScope.Item)
            {
                return;
            }

            //run all elements
            foreach (EA.Element elTrgt in el.Elements)
            {
                DoRecursiveEl(rep, elTrgt, setEl, setDia, parameterStrings, changeScope);
            }
        }
示例#3
0
            public void SampleBatchTest()
            {
                using (OpenWebDataServiceHelper.EntitySetAccessRule.Restore())
                    using (OpenWebDataServiceHelper.ServiceOperationAccessRule.Restore())
                    {
                        CustomRowBasedContext.PreserveChanges = false;
                        string batchRequestsDirectory = Path.Combine(TestUtil.ServerUnitTestSamples, @"tests\BatchRequests");
                        TestUtil.RunCombinations(
                            Directory.GetFiles(batchRequestsDirectory, "*batch*"),
                            (fileName) =>
                        {
                            string batchRequest     = File.ReadAllText(fileName);
                            string responseFileName = fileName.Replace("batch", "response");

                            string RequestMaxVersion = "4.0";

                            TestUtil.RunCombinations(
                                new Type[] { typeof(CustomDataContext), typeof(CustomRowBasedContext) },
                                (contextType) =>
                            {
                                if (contextType == typeof(CustomRowBasedContext))
                                {
                                    // Hide Region navigation property on the Customer ResponseType to make
                                    // both contexts look identical
                                    OpenWebDataServiceHelper.EntitySetAccessRule.Value = new Dictionary <string, EntitySetRights>()
                                    {
                                        { "Regions", EntitySetRights.None },
                                        { "*", EntitySetRights.All }
                                    };

                                    // Hide service operations returning hidden types.
                                    OpenWebDataServiceHelper.ServiceOperationAccessRule.Value = new Dictionary <string, ServiceOperationRights>()
                                    {
                                        { "GetRegionByName", ServiceOperationRights.None },
                                        { "*", ServiceOperationRights.All }
                                    };
                                }

                                TestUtil.RunCombinations(
                                    new WebServerLocation[] { WebServerLocation.InProcess },
                                    (location) =>
                                {
                                    using (ChangeScope.GetChangeScope(contextType))
                                    {
                                        string actualResponse = BatchTestUtil.GetResponse(batchRequest, contextType, location, RequestMaxVersion);
                                        BatchTestUtil.CompareBatchResponse(responseFileName, actualResponse);
                                    }
                                });
                            });
                        });
                    }
            }
        /// <summary>
        /// Wrapper to change DiagramLink style
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="pos"></param>
        /// <param name="changeScope"></param>
        // ReSharper disable once MemberCanBePrivate.Global
        public static void DiagramLinkStyleWrapper(Repository rep, int pos, ChangeScope changeScope)
        {
            if (DiagramStyle.DiagramStyleItems == null && DiagramStyle.DiagramLinkStyleItems.Count <= pos)
            {
                MessageBox.Show("", "No DiagramLink style in 'Settings.json' found");
                return;
            }
            string type     = $@"{DiagramStyle.DiagramLinkStyleItems[pos].Type}".Trim();
            string style    = $@"{DiagramStyle.DiagramLinkStyleItems[pos].Style}".Trim();
            string property = $@"{DiagramStyle.DiagramLinkStyleItems[pos].Property}".Trim();

            DiagramLinkStyleWrapper(rep, type, style, property, changeScope);
        }
        /// <summary>
        /// Dialog to ask and enter a user. Enter a user is only possible if the user has the rights.
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="changeScope"></param>
        /// <param name="lToDelete"></param>
        public DlgAuthor(Repository rep, ChangeScope changeScope, List <string> lToDelete)
        {
            _rep = rep;
            var sql = new UtilSql(rep);

            InitializeComponent();
            _listChanged.DataSource = lToDelete;
            switch (changeScope)
            {
            case ChangeScope.Item:
                Text = _items;
                break;

            case ChangeScope.Package:
                Text = _packages;
                break;

            case ChangeScope.PackageRecursive:
                Text = _packagesRecursive;
                break;
            }
            if (rep.IsSecurityEnabled)
            {
                _isSecurityEnabled = true;

                // check if user has the rights to manage users
                if (sql.UserHasPermission(rep.GetCurrentLoginUser(true)))
                {
                    _users         = sql.GetUsers();
                    txtStatus.Text = "Security is enabled: Choose user";
                }
                else
                {
                    txtStatus.Text = "Security is enabled: Only person with 'Manage User' are allowed to change users!";

                    MessageBox.Show("User has no 'Manage Users' right", "Insufficient user rights");
                    btnOk.Enabled = false;
                }
            }
            else
            {
                _users         = sql.GetUsers();
                txtStatus.Text = "Security isn't enabled: Choose or enter your desired author name!";
            }


            cmbUser.Text       = _user;
            cmbUser.DataSource = _users;
        }
示例#6
0
            [Ignore] // Remove Atom
            // [TestCategory("Partition2"), TestMethod, Variation]
            public void UriCompositionRulesChangedOnServer()
            {
                string batchRequestsDirectory = Path.Combine(TestUtil.ServerUnitTestSamples, @"tests\BatchRequests");

                using (OpenWebDataServiceHelper.EntitySetAccessRule.Restore())
                    using (OpenWebDataServiceHelper.ServiceOperationAccessRule.Restore())
                    {
                        CustomRowBasedContext.PreserveChanges = false;
                        TestUtil.RunCombinations(
                            new string[] { "4.0" },
                            UnitTestsUtil.BooleanValues,
                            (dataServiceVersion, insertForwardSlashCharacter) =>
                        {
                            Type contextType      = typeof(CustomRowBasedContext);
                            string requestContent = File.ReadAllText(Path.Combine(batchRequestsDirectory, "UriCompositionReproRequest.txt"));
                            if (insertForwardSlashCharacter)
                            {
                                requestContent = requestContent.Replace("{InsertForwardSlash}", "/");
                            }
                            else
                            {
                                requestContent = requestContent.Replace("{InsertForwardSlash}", string.Empty);
                            }

                            string responseFileName = "UriCompositionSucessResponse.txt";
                            if (insertForwardSlashCharacter)
                            {
                                // if the DSV is set to v3 and the post and bind uris start with a forward slash,
                                // the absolute uris produced by the RequestUriProcessor will be based at a different location.
                                responseFileName = "UriCompositionErrorResponse.txt";
                            }

                            responseFileName = Path.Combine(batchRequestsDirectory, responseFileName);
                            using (ChangeScope.GetChangeScope(contextType))
                            {
                                string actualResponse = BatchTestUtil.GetResponse(requestContent, contextType, WebServerLocation.InProcess, dataServiceVersion);
                                BatchTestUtil.CompareBatchResponse(responseFileName, actualResponse);
                            }
                        });
                    }
            }
示例#7
0
        /// <summary>
        /// Bulk Change Diagram Style according to:
        /// liParameter[0]  Styles/StyleEx
        /// liParameter[1]  PDATA/ExtendedStyle
        /// liParameter[2]  Properties
        /// liParameter[3]  Diagram types as comma, semicolon separated list
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="liParameter"></param>
        /// <param name="changeScope"></param>
        public static void ChangeDiagramStyle(Repository rep, string[] liParameter, ChangeScope changeScope = ChangeScope.PackageRecursive)
        {
            switch (rep.GetContextItemType())
            {
            case ObjectType.otDiagram:
                Diagram dia = (Diagram)rep.GetContextObject();
                SetDiagramStyle(rep, dia, liParameter);
                break;

            case ObjectType.otPackage:
                Package pkg = (Package)rep.GetContextObject();
                RecursivePackages.DoRecursivePkg(rep, pkg, null, null, SetDiagramStyle,
                                                 liParameter,
                                                 changeScope);
                break;

            case ObjectType.otElement:
                Element el = (Element)rep.GetContextObject();
                RecursivePackages.DoRecursiveEl(rep, el, null, SetDiagramStyle, liParameter,
                                                changeScope);
                break;
            }
        }
        public static void DoRecursivePkg(Repository rep, EA.Package pkg, SetPackage setPkg,
                                          SetElement setEl, SetDiagram setDia, string[] parameterStrings, ChangeScope changeScope)
        {
            // Change package
            setPkg?.Invoke(rep, pkg, parameterStrings);

            // only the package itself
            if (changeScope == ChangeScope.Item)
            {
                return;
            }

            // perform diagrams of package
            foreach (EA.Diagram dia in pkg.Diagrams)
            {
                if (dia != null)
                {
                    setDia?.Invoke(rep, dia, parameterStrings);
                }
            }
            // run elements of package
            foreach (EA.Element el in pkg.Elements)
            {
                DoRecursiveEl(rep, el, setEl, setDia, parameterStrings, changeScope);
            }

            // run packages of package
            if (changeScope != ChangeScope.Item)
            {
                if (changeScope == ChangeScope.Package)
                {
                    // inside package only the items
                    changeScope = ChangeScope.Item;
                }
                foreach (EA.Package pkgTrgt in pkg.Packages)
                {
                    DoRecursivePkg(rep, pkgTrgt, setPkg, setEl, setDia, parameterStrings, changeScope);
                }
            }
        }
        /// <summary>
        /// Wrapper to change DiagramLink style
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="type"></param>
        /// <param name="style"></param>
        /// <param name="property"></param>
        /// <param name="changeScope"></param>
        public static void DiagramLinkStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: false);

            // Handle selected diagram and its selected items (connector/objects)
            if (eaDia.Dia != null)
            {
                rep.SaveDiagram(eaDia.Dia.DiagramID);
                // over all links
                foreach (var link in eaDia.GetSelectedLinks())
                {
                    var linkStyle = new DiagramLinkStyle(rep, link, type, style, property);
                    if (linkStyle.IsToProcess())
                    {
                        linkStyle.UpdateStyles();
                        linkStyle.SetProperties();
                        linkStyle.SetEaLayoutStyles();
                    }
                }
                eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
            }
            else
            {
                var liParameter = new string[4];
                liParameter[0] = type;
                liParameter[1] = style;
                liParameter[2] = property;

                switch (rep.GetContextItemType())
                {
                case EA.ObjectType.otPackage:
                    EA.Package pkg = (EA.Package)rep.GetContextObject();
                    RecursivePackages.DoRecursivePkg(rep, pkg, null, null,
                                                     SetDiagramLinkStyle,
                                                     liParameter,
                                                     changeScope);
                    break;

                case EA.ObjectType.otElement:
                    EA.Element el = (EA.Element)rep.GetContextObject();
                    RecursivePackages.DoRecursiveEl(rep, el, null,
                                                    SetDiagramLinkStyle,
                                                    liParameter,
                                                    changeScope);
                    break;
                }
            }
        }
        /// <summary>
        /// Wrapper to change DiagramObject style
        /// - Selected Diagramobjects
        /// - Package (Diagrams and their DiagramObjects in package and below Elements)
        /// - Element (Diagrams and their DiagramObjects below Elements)
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="type"></param>
        /// <param name="style"></param>
        /// <param name="property"></param>
        /// <param name="changeScope"></param>
        public static void DiagramObjectStyleWrapper(Repository rep, string type, string style, string property, ChangeScope changeScope)
        {
            EaDiagram eaDia = new EaDiagram(rep, getAllDiagramObject: true);

            if (eaDia.Dia != null)
            {
                rep.SaveDiagram(eaDia.Dia.DiagramID);
                foreach (var diaObj in eaDia.SelObjects)
                {
                    var objectStyle = new DiagramObjectStyle(rep, diaObj, type, style, property);
                    if (objectStyle.IsToProcess())
                    {
                        objectStyle.UpdateStyles();
                        objectStyle.SetProperties();
                        objectStyle.SetEaLayoutStyles();
                        objectStyle.SetCompleteNessMarker();
                    }
                }
                eaDia.ReloadSelectedObjectsAndConnector(saveDiagram: false);
            }
            else
            {
                var liParameter = new string[4];
                liParameter[0] = type;
                liParameter[1] = style;
                liParameter[2] = property;

                switch (rep.GetContextItemType())
                {
                case EA.ObjectType.otPackage:
                    EA.Package pkg = (EA.Package)rep.GetContextObject();
                    RecursivePackages.DoRecursivePkg(rep, pkg, null, null,
                                                     SetDiagramObjectStyle,
                                                     liParameter,
                                                     changeScope);
                    break;

                case EA.ObjectType.otElement:
                    EA.Element el = (EA.Element)rep.GetContextObject();
                    RecursivePackages.DoRecursiveEl(rep, el, null,
                                                    SetDiagramObjectStyle,
                                                    liParameter,
                                                    changeScope);
                    break;
                }
            }
        }