Ejemplo n.º 1
0
        private void DeploySolution(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            var farm = modelHost.HostFarm;
            var existringSolution = FindExistingSolution(modelHost, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existringSolution,
                ObjectType = typeof(SPSolution),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            var tmpWspDirectory = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N"));
            var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory);

            Directory.CreateDirectory(tmpWspDirectoryPath);

            var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName);
            File.WriteAllBytes(tmpWspFilPath, definition.Content);

            if (existringSolution == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new farm solution");
                existringSolution = farm.Solutions.Add(tmpWspFilPath, (uint)definition.LCID);
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Upgrading existing farm solution");

                if (existringSolution.Deployed)
                {
                    existringSolution.Upgrade(tmpWspFilPath);
                }
                else
                {
                    // TODO
                    // https://github.com/SubPointSolutions/spmeta2/issues/324
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existringSolution,
                ObjectType = typeof(SPSolution),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });
        }
Ejemplo n.º 2
0
        protected SPSolution FindExistingSolution(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall,
                "Resolving farm solution by SolutionId: [{0}] and Name: [{1}]",
                 new object[]
                    {
                        definition.SolutionId,
                        definition.FileName
                    });

            var farm = modelHost.HostFarm;

            return farm.Solutions.FirstOrDefault(s =>
                s.Name.ToUpper() == definition.FileName.ToUpper() ||
                definition.SolutionId != Guid.Empty && s.SolutionId == definition.SolutionId);
        }
        private void DeployWebApplication(FarmModelHost farmModelHost, SPFarm farm, WebApplicationDefinition webApplicationDefinition)
        {
            var webApps = SPWebService.ContentService.WebApplications;

            var webAppBuilder = new SPWebApplicationBuilder(farm);

            webAppBuilder.Port = webApplicationDefinition.Port;
            webAppBuilder.ApplicationPoolId = webApplicationDefinition.ApplicationPoolId;

            if (!string.IsNullOrEmpty(webApplicationDefinition.ManagedAccount))
            {
                webAppBuilder.IdentityType = IdentityType.SpecificUser;

                var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
                var maccount = managedAccounts.FindOrCreateAccount(webApplicationDefinition.ManagedAccount);

                webAppBuilder.ManagedAccount = maccount;
            }
            else
            {
                webAppBuilder.ApplicationPoolUsername = webApplicationDefinition.ApplicationPoolUsername;

                var password = new SecureString();

                foreach (char c in webApplicationDefinition.ApplicationPoolPassword.ToCharArray())
                    password.AppendChar(c);

                webAppBuilder.ApplicationPoolPassword = password;
            }

            webAppBuilder.CreateNewDatabase = webApplicationDefinition.CreateNewDatabase;

            webAppBuilder.DatabaseName = webApplicationDefinition.DatabaseName;
            webAppBuilder.DatabaseServer = webApplicationDefinition.DatabaseServer;

            webAppBuilder.UseNTLMExclusively = webApplicationDefinition.UseNTLMExclusively;

            webAppBuilder.HostHeader = webApplicationDefinition.HostHeader;
            webAppBuilder.AllowAnonymousAccess = webApplicationDefinition.AllowAnonymousAccess;
            webAppBuilder.UseSecureSocketsLayer = webApplicationDefinition.UseSecureSocketsLayer;

            var webApp = webAppBuilder.Create();
            webApp.Provision();
        }
 private void ValidateWebApplication(FarmModelHost farmModelHost, Microsoft.SharePoint.Administration.SPFarm sPFarm, WebApplicationDefinition webApplicationDefinition)
 {
    
 }
        private void DeployFarmManagedProperty(object modelHost, FarmModelHost farmModelHost, ManagedPropertyDefinition definition)
        {
            farmModelHost.ShouldUpdateHost = false;

            ManagedPropertyCollection properties;
            List<CrawledPropertyInfo> crawledProps;

            var existingProperty = GetCurrentObject(modelHost, definition, out properties, out crawledProps);

            var isNewMapping = existingProperty == null;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingProperty,
                ObjectType = typeof(ManagedProperty),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (existingProperty == null)
            {
                existingProperty = properties.Create(definition.Name, (ManagedDataType)Enum.Parse(typeof(ManagedDataType), definition.ManagedType));
            }

            existingProperty.Description = definition.Description ?? string.Empty;

            if (definition.Searchable.HasValue)
                existingProperty.HasMultipleValues = definition.Searchable.Value;

            if (definition.Queryable.HasValue)
                existingProperty.Queryable = definition.Queryable.Value;

            if (definition.Retrievable.HasValue)
                existingProperty.Retrievable = definition.Retrievable.Value;

            if (definition.HasMultipleValues.HasValue)
                existingProperty.HasMultipleValues = definition.HasMultipleValues.Value;

            if (definition.Refinable.HasValue)
                existingProperty.Refinable = definition.Refinable.Value;

            if (definition.Sortable.HasValue)
                existingProperty.Sortable = definition.Sortable.Value;

            if (definition.SafeForAnonymous.HasValue)
                existingProperty.SafeForAnonymous = definition.SafeForAnonymous.Value;

            if (definition.TokenNormalization.HasValue)
                existingProperty.TokenNormalization = definition.TokenNormalization.Value;


            //if (isNewMapping)
            //{
            var mappings = existingProperty.GetMappings();

            foreach (var managedPropertyMappping in definition.Mappings)
            {
                var crawledProp = crawledProps
                    .FirstOrDefault(p => p.Name.ToUpper() == managedPropertyMappping.CrawledPropertyName.ToUpper());

                if (crawledProp == null)
                    continue;

                var mapping = new Mapping
                {
                    CrawledPropertyName = crawledProp.Name,
                    ManagedPid = existingProperty.PID,
                    CrawledPropset = crawledProp.Propset,
                };

                mappings.Add(mapping);
            }

            existingProperty.SetMappings(mappings);
            //}

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = existingProperty,
                ObjectType = typeof(ManagedProperty),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            // Write the changes back
            existingProperty.Update();
        }