private SmartObjectDefinition CreateSmartObject(string smoName)
        {
            try
            {
                // Delete the smartobject if it already exists
                this.DeleteSmartObject(smoName);

                toolStripStatusLabel1.Text = ("Creating SmartObject properties for '" + smoName + "'");
                statusStrip1.Update();
                ManagementServerConnect();

                // Get SmartBox service instance
                ServiceInstance serviceInstance = ServiceInstance.Create(_smoManagementServer.GetServiceInstanceForExtend(new Guid(_smartboxGuid), string.Empty));
                ExtendObject    extendObject    = serviceInstance.GetCreateExtender();

                extendObject.Name = smoName;
                extendObject.Metadata.DisplayName = smoName;

                // Create 'id' property
                ExtendObjectProperty idProperty = new ExtendObjectProperty();
                idProperty.Name = "ID";
                idProperty.Metadata.DisplayName = idProperty.Name;
                idProperty.Type       = PropertyDefinitionType.Autonumber;
                idProperty.ExtendType = ExtendPropertyType.UniqueIdAuto;

                // Create 'name' property
                ExtendObjectProperty nameProperty = new ExtendObjectProperty();
                nameProperty.Name = "Name";
                nameProperty.Metadata.DisplayName = nameProperty.Name;
                nameProperty.Type = PropertyDefinitionType.Text;

                // Create other properties here as needed
                // Add the new properties below

                // Add properties
                extendObject.Properties.Add(idProperty);
                extendObject.Properties.Add(nameProperty);

                SmartObjectDefinition smoDefinition = new SmartObjectDefinition();

                // Create SmartObject Definition
                smoDefinition.Create(extendObject);
                smoDefinition.AddDeploymentCategory("Test SmartObjects");

                smoDefinition.Build();

                return(smoDefinition);
            }

            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                ManagementServerCloseConnection();
            }
        }
        public static ServiceInstance GetServiceInstance(ServiceInstanceSettings serviceInstanceSettings)
        {
            serviceInstanceSettings.ThrowIfNull("serviceInstanceSettings");

            var connection = WrapperFactory.Instance.GetSmartObjectManagementServerWrapper(null);

            using (connection.BaseAPIServer?.Connection)
            {
                var serviceInstance = ServiceInstance.Create(connection.GetServiceInstance(serviceInstanceSettings.Guid, ServiceExplorerLevel.ServiceObject));
                return(serviceInstance);
            }
        }
Esempio n. 3
0
        public void Register(bool refreshOnly = false)
        {
            var server = WrapperFactory.Instance.GetServer <ServiceManagementServer>();

            using (server.Connection)
            {
                var serviceManagementServerWrapper = WrapperFactory.Instance.GetServiceManagementServerWrapper(server);
                var serviceConfig = this.GetServiceConfigInfo(serviceManagementServerWrapper);

                var serviceInstancesCompactXml = serviceManagementServerWrapper.GetServiceInstancesCompact(_serviceTypeCreator.Guid);
                var serviceInstances           = ServiceInstanceInfoList.Create(serviceInstancesCompactXml);

                var smartObjectManagementServer = WrapperFactory.Instance.GetServer <SmartObjectManagementServer>();
                using (smartObjectManagementServer.Connection)
                {
                    var smartObjectManagementServerWrapper = WrapperFactory.Instance.GetSmartObjectManagementServerWrapper(smartObjectManagementServer);

                    // Remove ServiceInstance with the same name
                    foreach (var instanceInfo in serviceInstances)
                    {
                        if (instanceInfo.Name == _serviceInstanceSettings.Name &&
                            instanceInfo.Guid != _serviceInstanceSettings.Guid)
                        {
                            smartObjectManagementServerWrapper.DeleteSmartObjects(instanceInfo.Guid);
                            serviceManagementServerWrapper.DeleteServiceInstance(instanceInfo.Guid);
                        }
                    }
                }

                // Refresh if exists
                var existingServiceInstance = serviceInstances.FirstOrDefault(i => i.Guid == _serviceInstanceSettings.Guid);

                if (existingServiceInstance != null)
                {
                    if (refreshOnly)
                    {
                        serviceManagementServerWrapper.RefreshServiceInstance(_serviceInstanceSettings.Guid);
                    }
                    else
                    {
                        serviceManagementServerWrapper.RefreshServiceInstance(
                            _serviceInstanceSettings.Guid,
                            serviceConfig.WriteXml());
                    }
                }
                else
                {
                    serviceManagementServerWrapper.RegisterServiceInstance(
                        _serviceTypeCreator.Guid,
                        _serviceInstanceSettings.Guid,
                        _serviceInstanceSettings.Name,
                        _serviceInstanceSettings.DisplayName,
                        _serviceInstanceSettings.Description ?? _serviceInstanceSettings.DisplayName,
                        serviceConfig.WriteXml());
                }

                // Output all the ServiceObjects and methods
                using (var serviceInstance = ServiceInstance.Create(serviceManagementServerWrapper.GetServiceInstance(_serviceInstanceSettings.Guid)))
                {
                    serviceInstance.ServiceObjects.Sort();

                    foreach (ServiceObject serviceObject in serviceInstance.ServiceObjects)
                    {
                        Debug.WriteLine(serviceObject.Name);
                        foreach (ServiceObjectMethod method in serviceObject.Methods)
                        {
                            Debug.WriteLine("\t" + method.Name);
                        }
                    }
                }
            }
        }
        private SmartObjectDefinition CreateServiceJoin(string smoName1, string smoName2)
        {
            try
            {
                // Delete the smartobject if it already exists
                this.DeleteSmartObject(smoName1 + smoName2);

                toolStripStatusLabel1.Text = ("Creating ServiceJoin SmartObject '" + smoName1 + " " + smoName2 + "'");
                statusStrip1.Update();

                ManagementServerConnect();

                // Get first serviceobject

                ServiceInstance serviceInstance1 = ServiceInstance.Create(_smoManagementServer.GetServiceInstanceForExtend(new Guid(_smartboxGuid), smoName1));
                ServiceObject   serviceObject1   = serviceInstance1.ServiceObjects[0];

                if (serviceObject1 == null)
                {
                    throw new Exception("Serviceobject does not exist. " + smoName1);
                }

                // Get second serviceobject

                ServiceInstance serviceInstance2 = ServiceInstance.Create(_smoManagementServer.GetServiceInstanceForExtend(new Guid(_smartboxGuid), smoName2));
                ServiceObject   serviceObject2   = serviceInstance2.ServiceObjects[0];

                if (serviceObject2 == null)
                {
                    throw new Exception("Serviceobject does not exist. " + smoName2);
                }

                // Create SmartObjectDefinition

                SmartObjectDefinition smoDefinition = new SmartObjectDefinition();
                smoDefinition.Name = smoName1 + smoName2;
                smoDefinition.Metadata.DisplayName = smoName1 + " " + smoName2;

                // Get Getlist servicemethod

                ServiceObjectMethod method = serviceObject1.Methods["GetList"];

                if (method == null)
                {
                    throw new Exception("GetList method does not exist on " + serviceObject1.Name);
                }

                // Create SmartMethodDefinition

                SmartMethodDefinition soMethod = new SmartMethodDefinition();
                soMethod.Name = method.Name;
                soMethod.Metadata.DisplayName = method.DisplayName;

                smoDefinition.Methods.Add(soMethod);

                // Map the first ServiceObject
                string executionBlockName = soMethod.Map(method);

                foreach (ServiceObjectProperty soProperty in serviceObject1.Properties)
                {
                    SmartPropertyDefinition smartProperty = new SmartPropertyDefinition();
                    smartProperty.Name = soProperty.Name + "_1";
                    smartProperty.Metadata.DisplayName = soProperty.Name + "_1";
                    smoDefinition.Properties.Add(smartProperty);

                    smoDefinition.MapProperty(smartProperty, soProperty, executionBlockName, method.Name);
                }

                // Map the second ServiceObject

                method = serviceObject2.Methods["GetList"];

                if (method == null)
                {
                    throw new Exception("GetList method does not exist on " + serviceObject1.Name);
                }

                executionBlockName = soMethod.Map(method);

                foreach (ServiceObjectProperty soProperty in serviceObject2.Properties)
                {
                    SmartPropertyDefinition smartProperty = new SmartPropertyDefinition();
                    smartProperty.Name = soProperty.Name + "_2";
                    smartProperty.Metadata.DisplayName = soProperty.Name + "_2";
                    smoDefinition.Properties.Add(smartProperty);

                    smoDefinition.MapProperty(smartProperty, soProperty, executionBlockName, method.Name);
                }

                ServiceJoinDetails joinDetails = smoDefinition.Methods[0].JoinDetails;
                joinDetails.From = soMethod.ExecutionBlocks[0].ServiceInstance.ServiceObjects[0];

                ServiceJoin serviceJoin = new ServiceJoin();
                serviceJoin.From = soMethod.ExecutionBlocks[0].ServiceInstance.ServiceObjects[0];;
                serviceJoin.To   = soMethod.ExecutionBlocks[1].ServiceInstance.ServiceObjects[0];;

                serviceJoin.AddCondition("Condition", serviceObject1.Properties[1], serviceObject2.Properties[1]);

                joinDetails.ServiceJoins.Add(serviceJoin);

                smoDefinition.AddDeploymentCategory("Test SmartObjects");

                smoDefinition.Build();
                return(smoDefinition);
            }

            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                ManagementServerCloseConnection();
            }
        }