Example #1
0
        public void contain_title()
        {
            var writer    = XmlWriter.Create(new MemoryStream());
            var workspace = new WorkspaceElement();

            Assert.Throws <AtomSpecificationViolationException>(() => workspace.WriteXml(writer));
            writer.Close();
        }
Example #2
0
        public static ServiceDocument ToServiceDocument(IEnumerable <string> userStreams,
                                                        IEnumerable <string> systemStreams,
                                                        string userHostName)
        {
            if (userStreams == null || systemStreams == null || userHostName == null)
            {
                return(null);
            }

            var document = new ServiceDocument();

            var userWorkspace = new WorkspaceElement();

            userWorkspace.SetTitle("User event streams");

            var systemWorkspace = new WorkspaceElement();

            systemWorkspace.SetTitle("System event streams");

            foreach (var userStream in userStreams)
            {
                var collection = new CollectionElement();

                collection.SetTitle(userStream);
                collection.SetUri(HostName.Combine(userHostName, "/streams/{0}", userStream));

                collection.AddAcceptType(ContentType.Xml);
                collection.AddAcceptType(ContentType.Atom);
                collection.AddAcceptType(ContentType.Json);
                collection.AddAcceptType(ContentType.AtomJson);

                userWorkspace.AddCollection(collection);
            }

            foreach (var systemStream in systemStreams)
            {
                var collection = new CollectionElement();

                collection.SetTitle(systemStream);
                collection.SetUri(HostName.Combine(userHostName, "/streams/{0}", systemStream));

                collection.AddAcceptType(ContentType.Xml);
                collection.AddAcceptType(ContentType.Atom);
                collection.AddAcceptType(ContentType.Json);
                collection.AddAcceptType(ContentType.AtomJson);

                systemWorkspace.AddCollection(collection);
            }

            document.AddWorkspace(userWorkspace);
            document.AddWorkspace(systemWorkspace);

            return(document);
        }
Example #3
0
        private void OnFlowchartExceptionCaught(FlowchartException exception)
        {
            WorkspaceElement exceptionElement = AllActiveElements.Find(x => x.InnerElement == exception.Element);

            if (!ActiveErrorSigns.ContainsKey(exceptionElement))
            {
                ErrorSign sign = ErrorSign.CreateSign(exceptionElement.transform.position, transform, exception.Message);
                ActiveErrorSigns.Add(exceptionElement, sign);
                sign.button.onClick.AddListener(() => { ActiveErrorSigns.Remove(exceptionElement); });
            }

            Debug.LogError("Flowchart exception was caught - " + exception.Message, exceptionElement);
        }
Example #4
0
        private T GetModelElement <T>(
            [NotNull] string fullName,
            [NotNull] IWorkspaceName workspaceName,
            [NotNull] IDictionary <WorkspaceElement, T> index,
            [NotNull] Func <string, IList <T> > getForName,
            [CanBeNull] Func <string, IWorkspaceName, T> getForCurrentContext)
            where T : class, IModelElement
        {
            Assert.ArgumentNotNullOrEmpty(fullName, nameof(fullName));
            Assert.ArgumentNotNull(workspaceName, nameof(workspaceName));
            Assert.ArgumentNotNull(index, nameof(index));
            Assert.ArgumentNotNull(getForName, nameof(getForName));

            var workspaceElement = new WorkspaceElement(workspaceName, fullName);

            T modelElement;

            if (index.TryGetValue(workspaceElement, out modelElement))
            {
                return(modelElement);
            }

            // model element not yet cached - search for it

            IWorkspace workspace;

            try
            {
                workspace = WorkspaceUtils.OpenWorkspace(workspaceName);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          $"Error opening workspace name to select model element for name '{fullName}'",
                          e);
            }

            var inaccessibleModels = new List <string>();

            _domainTransactions.UseTransaction(
                delegate
            {
                if (getForCurrentContext != null)
                {
                    modelElement = getForCurrentContext(fullName, workspaceName);
                    if (modelElement != null)
                    {
                        return;
                    }
                }

                IList <T> candidates = getForName(fullName);
                Assert.NotNull(candidates, "no dataset list returned");

                if (!ModelElementNameUtils.IsQualifiedName(fullName))
                {
                    // the gdb element name is unqualified
                    // search as is (in models that allow opening from default db)
                    modelElement = GetCandidateInSameDatabase(
                        candidates, workspace, ModelElementNameType.Any, inaccessibleModels);
                }
                else
                {
                    // the dataset name is qualified
                    // search datasets in models that use qualified names (and that allow opening from default db)
                    modelElement = GetCandidateInSameDatabase(
                        candidates, workspace, ModelElementNameType.Qualified,
                        inaccessibleModels);

                    // not found: unqualify, search in models with unqualified dataset names
                    if (modelElement == null)
                    {
                        candidates =
                            getForName(ModelElementNameUtils.GetUnqualifiedName(fullName));

                        modelElement = GetCandidateInSameDatabase(
                            candidates, workspace, ModelElementNameType.Unqualified,
                            inaccessibleModels);
                    }
                }
            });

            if (modelElement == null && inaccessibleModels.Count > 0)
            {
                // only if no candidate was found: warn if any of the candidates
                // could not be verified because of an invalid workspace reference
                if (inaccessibleModels.Count == 1)
                {
                    string inaccessibleModelName = inaccessibleModels.First();

                    _msg.Warn(
                        $"Workspace for model '{inaccessibleModelName}' containing '{fullName}' cannot be opened.");
                }
                else
                {
                    _msg.Warn(
                        "The master database workspaces for the following models cannot be opened:");
                    using (_msg.IncrementIndentation())
                    {
                        foreach (string inaccessibleModelName in inaccessibleModels)
                        {
                            _msg.Warn($"{inaccessibleModelName}");
                        }
                    }
                }
            }

            // add element even if null (to not search again for unregistered element)
            index.Add(workspaceElement, modelElement);

            return(modelElement);
        }
Example #5
0
 public void RemoveElement(WorkspaceElement element)
 {
     AllActiveElements.Remove(element);
 }
Example #6
0
 public void AddElement(WorkspaceElement element)
 {
     AllActiveElements.Add(element);
 }