/* * Old version prior to versioning simplification: * public IEnumerable<SocketsPart> RightItemsFromConnectors(IEnumerable<ConnectorPart> connectors, params string[] types) * { * var ids = connectors.Select(c => new { VersionId = c.RightContentVersionId, Id = c.RightContentVersionId.HasValue ? null : (int?)c.RightContentItemId }).ToList(); * var rightIds = ids.Where(c=>c.Id.HasValue).Select(c=>c.Id.Value); * var rightVersionIds = ids.Where(c => c.VersionId.HasValue).Select(c => c.VersionId.Value); * // TODO: Stuck between a rock and a hard place with QueryHints. WithQueryHintsFor actually generates a new content item in memory to figure out the parts to be expanded. * // We possibly can't assume this will be optimal in all scenarios. On the other hand, we need to do something fairly complex to get the generic types from all the drivers. * var qh = QueryHints.Empty; // QueryHintsForTypes(types); * var content = Services.ContentManager.GetManyByVersionId<SocketsPart>(rightVersionIds, qh) * .Concat(Services.ContentManager.GetMany<SocketsPart>(rightIds, VersionOptions.Latest, qh)); * return content; * } * public IEnumerable<SocketsPart> LeftItemsFromConnectors(IEnumerable<ConnectorPart> connectors, params string[] types) * { * var ids = connectors.Select(c => new { VersionId = c.LeftContentVersionId, Id = c.LeftContentVersionId.HasValue ? null : (int?)c.LeftContentItemId }).ToList(); * var leftIds = ids.Where(c => c.Id.HasValue).Select(c => c.Id.Value); * var leftVersionIds = ids.Where(c => c.VersionId.HasValue).Select(c => c.VersionId.Value); * // TODO: Stuck between a rock and a hard place with QueryHints. WithQueryHintsFor actually generates a new content item in memory to figure out the parts to be expanded. * // We possibly can't assume this will be optimal in all scenarios. On the other hand, we need to do something fairly complex to get the generic types from all the drivers. * var qh = QueryHintsForTypes(types); * var content = Services.ContentManager.GetManyByVersionId<SocketsPart>(leftVersionIds, qh) * .Concat(Services.ContentManager.GetMany<SocketsPart>(leftIds, VersionOptions.Latest, qh)); * return content; * } */ public IEnumerable <ConnectorDescriptor> AllowableConnectorTypes(IContent content) { // Enforce sockets part. // TODO: Throw an error - this shouldn't be called on anything without sockets var part = content.As <SocketsPart>(); if (part == null) { return(Enumerable.Empty <ConnectorDescriptor>()); } var ConnectorTypes = ConnectorTypeDefinitions(); // TODO: PERF: This can't be optimal with a lot of content types floating around, need a lookup. return(ConnectorTypes.Select(d => { var s = d.Parts.First(p => p.PartDefinition.Name == typeof(ConnectorPart).Name).Settings.GetModel <ConnectorTypePartSettings>(); var allowTypes = s == null ? Enumerable.Empty <string>() : s.ListAllowedContentLeft(); return new { Settings = s, Definition = d, Allowed = (s != null && (!allowTypes.Any() || allowTypes.Any(t => t == part.TypeDefinition.Name))) }; }).Where(s => s.Allowed).Select(s => { var def = new ConnectorDescriptor(s.Definition, s.Settings); return def; })); }
public IActionResult RemoteServerDescriptor() { RemoteServerDescriptor serverDescriptor = new RemoteServerDescriptor(); var connectorDescriptor = new ConnectorDescriptor(); connectorDescriptor.Name = "ProvisioningService"; connectorDescriptor.Type = "Capgemini.ProvisioningPortal.Connector"; connectorDescriptor.Path = "api"; connectorDescriptor.ConnectionInstanceProperties.Add(new ConnectionInstancePropertyDescriptor() { Name = "url", DisplayName = "URL", HelpText = "Url to the provisioning service", Type = "String", Required = true }); connectorDescriptor.Actions.Add(BuildRequestStatusActionDescriptor()); connectorDescriptor.Actions.Add(BuildRequestVmActionDescriptor()); serverDescriptor.Connectors.Add(connectorDescriptor); return(new ObjectResult(serverDescriptor)); }
public IActionResult RemoteServerDescriptor() { RemoteServerDescriptor serverDescriptor = new RemoteServerDescriptor(); var connectorDescriptor = new ConnectorDescriptor(); connectorDescriptor.Name = "RemedyITSM9"; connectorDescriptor.Type = "Capgemini.RemedyITSM9.ServiceRequest.Connector"; connectorDescriptor.Path = "api"; connectorDescriptor.ConnectionInstanceProperties.Add(new ConnectionInstancePropertyDescriptor() { Name = "url", DisplayName = "URL", HelpText = "Url to the Remedy 9 ITSM API", Type = "String", Required = true }); connectorDescriptor.Actions.Add(BuildCreateUserServiceRequestActionDescriptor()); connectorDescriptor.Actions.Add(BuildUserServiceRequestStatusActionDescriptor()); serverDescriptor.Connectors.Add(connectorDescriptor); return(new ObjectResult(serverDescriptor)); }
private string ConnectorDisplayName(ConnectorDescriptor t) { return(String.IsNullOrWhiteSpace(t.Settings.SocketDisplayName) ? (t.Definition.DisplayName + (t.Settings.AllowMany ? "s" : "")) : t.Settings.SocketDisplayName); }
protected IEnumerable <IConnector> CreateConnector(IContent left, IContent right, ConnectorDescriptor ConnectorDef, bool createInverseIfPossible, bool ignorePermissions = false) { // Check sockets var leftSock = left.As <SocketsPart>(); var rightSock = right.As <SocketsPart>(); // TODO: SocketsPart doesn't need any data so we could consider automatically welding it to any content that has valid connectors. It's // very rare that we want a connector type to apply to anything so maybe should disable the wildcard. if (leftSock == null || rightSock == null) { throw new OrchardException(T("Attempted to create connector between non-socket content %0 (%1) and %2 (%3). You must add SocketsPart to content to participate in connections.", left.ContentItem.ContentType, leftSock == null ? "hasn't" : "has", right.ContentItem.ContentType, rightSock == null ? "hasn't" : "has")); } // Build a new item var connector = Services.ContentManager.New <ConnectorPart>(ConnectorDef.Name); // Check security var createContext = new ConnectorCreateContext(left, right, ConnectorDef); createContext.ConnectorContent = connector; createContext.SiblingConnectors = leftSock.Sockets[ConnectorDef.Name].ConnectorQuery; if (!ignorePermissions && !Services.Authorizer.Authorize(Permissions.PublishContent, connector, T("Cannot create connector"))) { return(Enumerable.Empty <IConnector>()); } // Store left and right items connector.LeftContentItemId = left.ContentItem.Id; connector.RightContentItemId = right.ContentItem.Id; // Handle versioning if (left.ContentItem.VersionRecord != null) { connector.LeftContentVersionId = left.ContentItem.VersionRecord.Id; } if (right.ContentItem.VersionRecord != null) { connector.RightContentVersionId = right.ContentItem.VersionRecord.Id; } // Invoke Creating event _connectorHandlers.Value.Invoke(c => c.Creating(createContext), Logger); if (createContext.Cancel) { return(Enumerable.Empty <IConnector>()); } // Create the item and invoke Created Services.ContentManager.Create(connector, ((left.ContentItem.VersionRecord != null)? (left.ContentItem.VersionRecord.Published ? VersionOptions.Published : VersionOptions.Draft) : VersionOptions.Published)); _connectorHandlers.Value.Invoke(c => c.Created(createContext), Logger); IEnumerable <IConnector> returnList = new[] { connector }; if (ConnectorDef.PartDefinition != null) { var settings = ConnectorDef.Settings; // Can we create an inverse? if (createInverseIfPossible && !String.IsNullOrWhiteSpace(settings.InverseConnectorType)) { var inverseDef = DescribeConnector(settings.InverseConnectorType); var inverseContext = new ConnectorCreateContext(right, left, inverseDef); inverseContext.InverseConnectorContent = createContext.ConnectorContent; _connectorHandlers.Value.Invoke(c => c.CreatingInverse(inverseContext), Logger); if (!inverseContext.Cancel) { // Create it var inverseCreate = CreateConnector(right, left, inverseDef, false, ignorePermissions); var inverseFirst = inverseCreate.FirstOrDefault().As <ConnectorPart>(); // Exchange Ids if (inverseFirst != null) { connector.InverseConnector = inverseFirst; inverseFirst.InverseConnector = connector; } returnList = returnList.Concat(inverseCreate); } } } return(returnList.ToArray()); }