【发布时间】:2018-01-29 14:45: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();
}
【问题讨论】:
-
MultiSite 模块是否已激活?如果是这样,您需要确保将动态模块配置为在该站点上显示,并在导入过程中使用正确的提供程序名称。如果没有,可能值得分享一些导入代码
-
感谢您的回复。我确实激活了多站点模块,并且我选择了我的模块来使用该站点。我在上面添加了导入代码。我也在管理员中设置了提供程序,但是对于提供程序的参数 applicationName 之一,我确实有一个问题,我已将其设置为 dynamicProvider2。那应该是网站名称吗??
-
不,不一定是站点名称。 dynamicProvider2 是由 Sitefinity 生成的,所以最好保持原样。那么,我假设你的问题解决了吗?
-
我将尝试更改该应用程序名称,看看会发生什么,此时我已经尝试了其他所有方法。我一试就回这里。