动态模块数据未显示在sitefinity的管理面板中

时间:2018-01-29 14:45:10

标签: sitefinity sitefinity-10

我有一个动态模块,我创建了一些从我创建的导入工具导入的数据。现在,我将这些模块的配置信息保存在/ app_data / Sitefinity下,并将它们检入我们的tfs版本控制系统,一切都在我们的本地和开发环境下运行良好。但是我们在QA上遇到了一个问题,即构建没有正确导入模块并修复此问题我最终不得不删除QA上的模块并将其从我们在dev上的配置中导入。所以现在动态模块在我们的管理模块中工作得很好,我们可以在那里手动创建数据。

现在的问题是,当我运行我的导入工具时,它会对我们的QA网站起作用并运行良好,但是当我们查看管理面板上的数据时,它不会显示在网站上。我还检查了sql server中的表,导入的数据就在那里。此外,我已确保数据已发布并设置为可见,因此我不确定为什么数据未显示在管理部分中。有人有什么想法吗?

以下是代码:

// Set the culture name for the multilingual fields
                var cultureName = "en";
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);

                Type locationType =
                    TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Locations.Location");
                DynamicContent location = null;

                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager("dynamicProvider2");
                dynamicModuleManager.Provider.SuppressSecurityChecks = true;


                location = dynamicModuleManager.GetDataItems(locationType)
                    .FirstOrDefault(
                        x =>
                            x.GetValue<string>("OperationId") == importLocation.OperationId.ToString() &&
                            x.Status == ContentLifecycleStatus.Master && x.Visible == true);

                if (location == null && importLocation.IsActive)
                {
                    // We have a new location.
                    DynamicContent locationItem = dynamicModuleManager.CreateDataItem(locationType);

                    locationItem.SetString("Title", importLocation.Title, cultureName);
                    locationItem.SetString("Description", importLocation.Description, cultureName);
                    locationItem.SetString("OperationId", importLocation.OperationId.ToString(), cultureName);

                    Address address = new Address();
                    CountryElement addressCountry =
                        Config.Get<LocationsConfig>().Countries.Values.First(x => x.Name == "United States");
                    address.CountryCode = addressCountry.IsoCode;
                    address.StateCode = importLocation.State;
                    address.City = importLocation.City;
                    address.Street = importLocation.Street;
                    address.Zip = importLocation.Zip;

                    address.Latitude = importLocation.Latitude;
                    address.Longitude = importLocation.Longitude;
                    address.MapZoomLevel = 8;
                    locationItem.SetValue("Address", address);
                    locationItem.Visible = true;

                    TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
                    taxonomyManager.Provider.SuppressSecurityChecks = true;
                    var foundRootServiceArea = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>()
                            .FirstOrDefault(t => t.Name == "Service-Areas");
                    foreach (var serviceArea in importLocation.ServiceAreas)
                    {
                        var foundServiceArea =
                            foundRootServiceArea.Taxa.FirstOrDefault(w => w.Name == serviceArea);
                        if (foundServiceArea != null)
                        {
                            locationItem.Organizer.AddTaxa("ServiceAreas", foundServiceArea.Id);
                        }
                        else
                        {
                            var newServiceArea = taxonomyManager.CreateTaxon<HierarchicalTaxon>();
                            newServiceArea.Title = serviceArea;
                            newServiceArea.Name = serviceArea;
                            foundRootServiceArea.Taxa.Add(newServiceArea);

                            locationItem.Organizer.AddTaxa("ServiceAreas", newServiceArea.Id);
                        }

                    }

                    locationItem.SetValue("PublicationDate", DateTime.UtcNow);

                    // Modified to publish instead of set items as draft
                    locationItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published",
                        new CultureInfo(cultureName));

                    // You need to call SaveChanges() in order for the items to be actually persisted to data store
                    dynamicModuleManager.SaveChanges();

                    // Use lifTecycle so that LanguageData and other Multilingual related values are correctly created
                    DynamicContent checkOutLocationItem =
                        dynamicModuleManager.Lifecycle.CheckOut(locationItem) as DynamicContent;
                    dynamicModuleManager.Lifecycle.CheckIn(checkOutLocationItem);
                    dynamicModuleManager.SaveChanges();

                    return Ok();
                }
                else if (location != null)
                {
                    // Check to see if we need to update each field.
                    if (location.DoesFieldExist("Title") && !String.IsNullOrEmpty(location.GetValue("Title").ToString()))
                    {
                        if (location.GetValue("Title").ToString() != importLocation.Title)
                        {
                            location.SetString("Title", importLocation.Title);
                        }
                    }

                    if (location.DoesFieldExist("Description") &&
                        !String.IsNullOrEmpty(location.GetValue("Description").ToString()))
                    {
                        if (location.GetValue("Description").ToString() != importLocation.Description)
                        {
                            location.SetString("Description", importLocation.Description);
                        }
                    }

                    if (location.DoesFieldExist("Address"))
                    {
                        var address = location.GetValue<Address>("Address");
                        if (address.City != importLocation.City)
                        {
                            address.City = importLocation.City;
                        }
                        if (address.StateCode != importLocation.State)
                        {
                            address.StateCode = importLocation.State;
                        }
                        if (address.Street != importLocation.Street)
                        {
                            address.Street = importLocation.Street;
                        }
                        if (address.Zip != importLocation.Zip)
                        {
                            address.Zip = importLocation.Zip;
                        }
                        if (address.Latitude != importLocation.Latitude)
                        {
                            address.Latitude = importLocation.Latitude;
                        }
                        if (address.Longitude != importLocation.Longitude)
                        {
                            address.Longitude = importLocation.Longitude;
                        }

                        location.SetValue("Address", address);
                    }
                    location.Visible = importLocation.IsActive;

                    if (!importLocation.IsActive)
                    {
                        location.Status = ContentLifecycleStatus.Deleted;
                        dynamicModuleManager.SaveChanges();
                    }
                    else
                    {        
                        location.SetWorkflowStatus(
                             dynamicModuleManager.Provider.ApplicationName, 
                             "Published", new CultureInfo(cultureName));

                        dynamicModuleManager.SaveChanges();

                        DynamicContent checkOutLocationItem =
                            dynamicModuleManager.Lifecycle.CheckOut(location) as 
                            DynamicContent;

 dynamicModuleManager.Lifecycle.CheckIn(checkOutLocationItem);
                        dynamicModuleManager.SaveChanges();
                    }

                    return Ok();
                }

1 个答案:

答案 0 :(得分:1)

为了根据模块名称动态检索当前站点的提供程序,我创建了这个帮助方法。

public static DynamicModuleManager GetDynamicProvider(string moduleName)
        {
            // Set the provider name for the DynamicModuleManager here. All available providers are listed in
            // Administration -> Settings -> Advanced -> DynamicModules -> Providers                

            var provider = SystemManager.CurrentContext.CurrentSite.GetDefaultProvider(moduleName);

            var providerName = (provider != null) ? provider.ProviderName : DynamicModuleManager.GetDefaultProviderName();

            return DynamicModuleManager.GetManager(providerName);
        }