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

Dynamic Module data not showing up in the administration panel of sitefinity

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

现在的问题是,当我 运行 我的导入工具时,它对我们的 QA 站点起作用并且 运行 没问题,但是当我们去查看管理面板上的数据时它没有出现在网站上。我还检查了 sql 服务器中的 table,导入的数据就在那里。我还确保数据已发布并设置为可见,所以我不确定为什么数据没有显示在管理部分。有人有什么想法吗??

代码如下:

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

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

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);
        }