private SourceCode.SmartObjects.Authoring.SmartObjectDefinition CreateSmartBoxSmartObject(SourceCode.SmartObjects.Management.SmartObjectManagementServer SmartObjectManagementSvr, K2Field.Apps.Framework.Build.SmartObjectDefinition SmO, string DeploymentCategory)
        {
            ServiceInstance serviceInstance = ServiceInstance.Create(SmartObjectManagementSvr.GetServiceInstanceForExtend(SmO.ServiceInstanceId, string.Empty));
            ExtendObject extendObject = serviceInstance.GetCreateExtender();
            // do set ID here - set on SmartObjectDefinition - extender is specifically for SmartBox
            //extendObject.Guid = SmO.Id;
            extendObject.Name = SmO.SystemName;
            extendObject.Metadata.DisplayName = SmO.DisplayName;
            extendObject.Metadata.Description = SmO.Description;

            foreach(K2Field.Apps.Framework.Build.SmartObjectProperty prop in SmO.Properties)
            {
                ExtendObjectProperty SoProp = new ExtendObjectProperty();
                SoProp.Guid = prop.Id;
                SoProp.Name = prop.SystemName.Replace(" ", "_").Replace(".", "_");
                SoProp.Metadata.DisplayName = prop.DisplayName;
                SoProp.Type = (PropertyDefinitionType)prop.DataType;
                SoProp.ExtendType = (SourceCode.SmartObjects.Authoring.ExtendPropertyType)prop.ExtendType;

                if (prop.DataType == SmODataType.Text)
                {
                    if (prop.MaxSize.HasValue && prop.MaxSize.Value > 0)
                    {
                        SoProp.Metadata.AddServiceElement("maxsize", prop.MaxSize.Value.ToString());
                    }
                    else
                    {
                        SoProp.Metadata.AddServiceElement("maxsize", "200");
                    }
                }

                if (!extendObject.Properties.ContainsName(prop.SystemName))
                {
                    extendObject.Properties.Add(SoProp);
                }
            }

            SourceCode.SmartObjects.Authoring.SmartObjectDefinition smoDefinition = new SourceCode.SmartObjects.Authoring.SmartObjectDefinition();

            try
            {

                // Create SmartObject Definition
                smoDefinition.Create(extendObject);

                // must set the SmartObject Id here
                smoDefinition.Guid = SmO.Id;
                smoDefinition.AddDeploymentCategory(DeploymentCategory);

                smoDefinition.Build();
            }
            catch (SmartObjectDefinitionException defEx)
            {
                MessageBox.Show(defEx.Message);
                throw;
            }

            return smoDefinition;
        }
        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();
            }
        }