我们正在连接到第三方系统(易于预订)以将信息导入我们的 CMS。直到上周这一切都很好,并引发了以下错误。我是.net 的新手.. 所以任何帮助将不胜感激!
[IOException: The format of the specified network name is invalid.
]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7714920
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +61
System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async) +65
System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint) +94
[WebException: The format of the specified network name is invalid.
]
System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint) +330
System.Net.FileWebRequest.GetResponseCallback(Object state) +260
[WebException: The format of the specified network name is invalid.
]
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +287
System.Net.WebClient.DownloadData(Uri address) +106
System.Net.WebClient.DownloadData(String address) +29
CoA.BookEasy.OperatorManager.GetRemoteFile(String url) in d:\Dev\ArmadaleVisitorCentre\CoA.BookEasy.OperatorImport\OperatorManager.cs:731
CoA.BookEasy.OperatorManager.SetFeatureImage(ContentVersion cv, List`1 list) in d:\Dev\ArmadaleVisitorCentre\CoA.BookEasy.OperatorImport\OperatorManager.cs:606
CoA.BookEasy.OperatorManager.ImportOperatorData(ContentVersion operatorCV, Int32 operatorId) in d:\Dev\ArmadaleVisitorCentre\CoA.BookEasy.OperatorImport\OperatorManager.cs:419
CoA.BookEasy.OperatorManager.ImportOperators(List`1 operatorIds, ContentVersion parentCV) in d:\Dev\ArmadaleVisitorCentre\CoA.BookEasy.OperatorImport\OperatorManager.cs:336
CoA.BookEasy.OperatorManager.ProcessContent(ProcessContentDelegate`1 processDelegate, List`1 toProcess, ContentVersion cv) in d:\Dev\ArmadaleVisitorCentre\CoA.BookEasy.OperatorImport\OperatorManager.cs:297
CoA.Admin.WebUI.CoA_BookeasyOperatorAdmin.ProcessContent(ProcessContentDelegate`1 processDelegate, List`1 toProcess, ContentVersion cv) in C:\dev\ArmadaleVisitorCentre\CoA.Admin.WebUI\CoA_BookeasyOperatorAdmin.aspx.cs:411
CoA.Admin.WebUI.CoA_BookeasyOperatorAdmin.CreateSelectedHere_Click(Object sender, EventArgs e) in C:\dev\ArmadaleVisitorCentre\CoA.Admin.WebUI\CoA_BookeasyOperatorAdmin.aspx.cs:193
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
这是相关代码:-
#region CRUD
public void ProcessContent<T>(ProcessContentDelegate<T> processDelegate, List<T> toProcess, ContentVersion cv)
{
//Only allow one thread to create at a time - that way ImportOperator() will catch any double-ups
//Using same thread locker that is used to cache the remote operators for added safety
lock (locker)
{
if (validation.Count == 0)
{
processDelegate(toProcess, cv);
}
}
}
private ContentVersion CreateChildPage(ContentVersion parentCV, ObjectType ot)
{
ContentVersion new_cv = null;
Content newPage = new Content();
SessionUser su = _user;
bool userCanCreateContent = AccessManager.GetInstance().CanPerformTask(su, "Create content");
if (userCanCreateContent)
{
ItemPermission ip = ItemPermissionManager.GetItemPermissionByContentVersion(parentCV);
bool canCreateType = (ip == null) ? true : ip.listObjectTypes.Contains<ObjectType>(ot);
if (canCreateType)
{
validation.AddRange(ContentManager.CreateNew(newPage, parentCV.objContent, ot, su, false));
if (validation.Count == 0)
{
new_cv = newPage.listVersions.LastOrDefault<ContentVersion>();
}
}
else
{
validation.Add("You cannot create a page of the type \"" + ot.name + "\" here.");
}
}
else
{
validation.Add("You do not have permission to create new pages.");
}
return new_cv;
}
public void ImportOperators(List<int> operatorIds, ContentVersion parentCV)
{
foreach (int operatorId in operatorIds)
{
ImportOperator(operatorId, parentCV);
if (validation.Count > 0)
{
break;
}
}
}
public void ImportOperators(List<BookeasyOperator> operators, ContentVersion parentCV)
{
foreach (BookeasyOperator o in operators)
{
ImportOperator(o.OperatorID, parentCV);
if (validation.Count > 0)
{
break;
}
}
}
private void ImportOperator(int operatorId, ContentVersion parentCV)
{
if (!cvsByBookeasyId.ContainsKey(operatorId))
{
ContentVersion new_cv = CreateChildPage(parentCV, ot);
if (validation.Count > 0)
{
return;
}
ImportOperatorData(new_cv, operatorId);
}
}
private void ImportOperatorData(ContentVersion operatorCV, int operatorId)
{
if (!operators.ContainsKey(operatorId))
{
validation.Add("The operator with the ID " + operatorId.ToString() + " does not seem to exist.");
return;
}
ContentVersion c = operatorCV;
BookeasyOperator o = operators[operatorId];
DataField df_Body = GetDataField(c, "Body");
DataField df_BookeasyOperatorID = GetDataField(c, "Bookeasy Operator ID");
DataField df_IsAutoUpdatedFromBookEasy = GetDataField(c, "Is Auto-Updated from BookEasy");
DataField df_FeatureImage = GetDataField(c, "Feature Image");
DataField df_Summary = GetDataField(c, "Summary");
DataField df_FirstName = GetDataField(c, "First Name");
DataField df_Surname = GetDataField(c, "Surname");
DataField df_BusinessName = GetDataField(c, "Business Name");
DataField df_OpeningHours = GetDataField(c, "Opening Hours");
DataField df_OpeningHoursDetails = GetDataField(c, "Opening Hours Details");
DataField df_Location = GetDataField(c, "Location");
DataField df_Email = GetDataField(c, "Email");
DataField df_Website = GetDataField(c, "Website");
DataField df_Phone = GetDataField(c, "Phone");
DataField df_Fax = GetDataField(c, "Fax");
DataField df_Mobile = GetDataField(c, "Mobile");
DataField df_OperatorType = GetDataField(c, "Operator Type");
DataField df_AccommodationGrouping = GetDataField(c, "Accommodation Grouping");
DataField df_SettingAndAtmosphere = GetDataField(c, "Setting and Atmosphere");
DataField df_Region = GetDataField(c, "Region");
DataField df_BusinessGrouping = GetDataField(c, "Business Grouping");
DataField df_Facilities = GetDataField(c, "Facilities");
DataField df_LastUpdatedByBookEasy = GetDataField(c, "Last Updated by BookEasy");
DataField df_IsMothership = GetDataField(c, "Is Mothership");
DataField df_TariffFrom = GetDataField(c, "Tariff From");
DataField df_TariffTo = GetDataField(c, "Tariff To");
DataField df_DepartureTime = GetDataField(c, "Departure Time");
DataField df_ArrivalTime = GetDataField(c, "Arrival Time");
DataField df_StarRating = GetDataField(c, "Star Rating");
DataField df_IsSelfRated = GetDataField(c, "Is Self Rated");
DataField df_Policies = GetDataField(c, "Policies");
DataField df_BookableTypes = GetDataField(c, "Bookable Types");
DataField df_HideContactDetails = GetDataField(c, "Hide Contact Details");
string content = OrDefault(o.PointOfDifference) + "\r\n\r\n" + OrDefault(o.Description);
content = CleanContent(content);
c.name = o.TradingName;
df_Body.value = HtmlifyContent(content);
df_BookeasyOperatorID.value = operatorId.ToString();
df_IsAutoUpdatedFromBookEasy.value = "Yes";
df_FeatureImage.value = SetFeatureImage(c, o.Pictures);
df_Summary.value = SummariseContent(content);
df_FirstName.value = OrDefault(o.FirstName);
df_Surname.value = OrDefault(o.Surname);
df_BusinessName.value = OrDefault(o.TradingName);
df_OpeningHours.value = OrDefault(o.Hours);
df_Email.value = OrDefault(o.Email);
df_Website.value = OrDefault(o.Website);
df_Phone.value = OrDefault(o.Telephone1);
df_Fax.value = OrDefault(o.Facsimile);
df_Mobile.value = OrDefault(o.Mobile);
df_Facilities.value = ListToSeamlessString(o.Facilities);
df_SettingAndAtmosphere.value = GetSettingAndAtmosphereAsSeamlessString(o);
df_BusinessGrouping.value = GetBusinessTypesAsSeamlessString(o);
df_IsMothership.value = (o.IsMothership) ? "Yes" : "No";
df_LastUpdatedByBookEasy.value = GetSeamlessTime(o.DateModified);
df_TariffFrom.value = OrDefault(o.TarriffFrom);
df_TariffTo.value = OrDefault(o.TarriffTo);
df_DepartureTime.value = OrDefault(o.DepartureTime);
df_ArrivalTime.value = OrDefault(o.ArrivalTime);
df_StarRating.value = GetStarRating(o.StarRating);
df_IsSelfRated.value = (o.IsSelfRated) ? "Yes" : "No";
df_Policies.value = CleanContent(o.Cancellation);
df_BookableTypes.value = ListToSeamlessString(o.BookableTypes);
df_HideContactDetails.value = (o.HideContactDetails) ? "Yes" : "No";
if (o.OperatorDetails != null)
{
OperatorDetailsShort od = o.OperatorDetails;
df_OperatorType.value = GetOperatorTypesAsSeamlessString(od.OperatorTypes);
df_AccommodationGrouping.value = ListToSeamlessString(od.OperatorGroupings);
df_Region.value = GetOperatorLocationsAsSeamlessString(od.Locations);
df_Location.value = SetLocation(o.TradingName, o.ResidentialAddress, od.Latitude, od.Longitude);
}
if (df_OperatorType.value == "") df_OperatorType.value = GetOperatorTypesAsSeamlessString(o);
if (df_AccommodationGrouping.value == "") df_AccommodationGrouping.value = GetAccommodationGroupingAsSeamlessString(o);
if (df_Region.value == "") df_Region.value = GetOperatorLocationsAsSeamlessString(o);
c.objTemplate = ct;
validation.AddRange(ContentVersionManager.Save(c));
validation.AddRange(WorkflowManager.SubmitItemVersionToStage(c, _user, "Created through Bookeasy Operator Import Manager", true, true, null, null, null, false));
}
public void UpdateOperators(List<int> operatorIds, ContentVersion ignoredForDelegate)
{
UpdateOperators(operatorIds);
}
private void UpdateOperators(List<int> operatorIds)
{
foreach (int operatorId in operatorIds)
{
UpdateOperator(operatorId);
/*
* Actually Allow this to continue, even if one page fails - should be non-fatal and just report on errors
if (validation.Count > 0)
{
break;
}*/
}
}
private void UpdateOperator(int operatorId)
{
if (cvsByBookeasyId.ContainsKey(operatorId))
{
foreach (OperatorDecisionHelper odh in cvsByBookeasyId[operatorId])
{
UpdateOperatorData(odh);
/*
* Actually Allow this to continue, even if one page fails - should be non-fatal and just report on errors
if (validation.Count > 0)
{
return;
}*/
}
}
}
private void UpdateOperatorData(OperatorDecisionHelper odh)
{
ContentVersion NewVersion = new ContentVersion();
validation.AddRange(ContentVersionManager.MakeCopy(NewVersion, ContentVersionManager.Get(odh.ContentVersion.id), _user, false));
NewVersion.sequence = odh.ContentVersion.sequence;
NewVersion.objContentParent = odh.ContentVersion.objContentParent;
NewVersion.versionNumber = odh.ContentVersion.versionNumber + 1;
ImportOperatorData(NewVersion, odh.BookEasyOperatorId);
}
public void ArchiveOperators(List<Guid> cvIds, ContentVersion ignoredForDelegate)
{
ArchiveOperators(cvIds);
}
private void ArchiveOperators(List<Guid> cvIds)
{
foreach (Guid cvId in cvIds)
{
ArchiveOperator(cvId);
if (validation.Count > 0)
{
break;
}
}
}
private void ArchiveOperator(Guid cvid)
{
ContentVersion cv = ContentVersionManager.Get(cvid);
if (cv != null)
{
validation.AddRange(ContentManager.Archive(cv.objContent.id));
}
}
#endregion
#region Operator Content Management
#region Location Management
private string SetLocation(string name, string address, double lat, double lon)
{
if (name == null || address == null || name == "" || address == "" || lat == 0 || lon == 0)
{
return "";
}
string parentLink = "$" + _user.currentGroup.id.ToString() + "$" + "/Tools/Locations";
string link = parentLink + "/" + FormatTools.StripAndReplaceURLUnfriendlyChars(name);
ContentVersion LocationCv = ContentVersionManager.GetActiveByLink(link).FirstOrDefault<ContentVersion>();
if (LocationCv == null)
{
ContentVersion parent_cv = ContentVersionManager.GetActiveByLink(parentLink).FirstOrDefault<ContentVersion>();
if (parent_cv != null)
{
LocationCv = CreateNewLocation(parent_cv, name, address, lat, lon);
}
else
{
return "";
}
}
return string.Concat(HttpContext.Current.Server.HtmlEncode(name), FormatTools.KEY_VALUE_PAIR_DELIMITER, LocationCv.link, FormatTools.KEY_VALUE_PAIR_DELIMITER, "newwindow");
//return LocationCv.link;
}
private ContentVersion CreateNewLocation(ContentVersion parent, string name, string address, double lat, double lon)
{
ObjectType ot = ObjectTypeManager.GetByName("Location");
ContentVersion new_cv = CreateChildPage(parent, ot);
DataField df_address = GetDataField(new_cv, "Location Street Address");
DataField df_lat = GetDataField(new_cv, "Location Latitude");
DataField df_lon = GetDataField(new_cv, "Location Longitude");
try
{
df_address.value = address;
df_lat.value = lat.ToString();
df_lon.value = lon.ToString();
new_cv.name = name;
validation.AddRange(ContentVersionManager.Save(new_cv));
validation.AddRange(WorkflowManager.SubmitItemVersionToStage(new_cv, _user, "Created through Location panel", true, true, null, null, null, false));
return new_cv;
}
catch
{
}
return null;
}
#endregion
#region Feature Image Management
private string SetFeatureImage(ContentVersion cv, List<string> list)
{
if (list == null || list.Count == 0) return "";
string RemoteURL = list[0];
string LocalURL = "";
Uri uri = new Uri(RemoteURL);
string filename = Path.GetFileName(uri.LocalPath);
MemoryStream file = GetRemoteFile(RemoteURL);
if (file != null)
{
LocalURL = WriteOutputSeamlessFile(cv, filename, file);
}
return LocalURL;
}
private string WriteOutputSeamlessFile(ContentVersion cv, string filename, MemoryStream ms)
{
Seamless.CMS.File OutputFile;
string LocalURL = "";
bool CreateNewFile = true;
ObjectType ot = ObjectTypeManager.GetByName("Image");
List<FileVersion> fvList = new List<FileVersion>();
foreach (Seamless.CMS.File file in cv.listFilesOwned)
{
FileVersion fv = FileVersionManager.GetFileLatest(file.id);
if (fv != null)
{
fvList.Add(fv);
}
}
FileVersion outputFv = fvList.FirstOrDefault<FileVersion>(pfv => pfv.name == filename);
if (outputFv != null)
{
string fileID = outputFv.id.ToString();
string physicalLocation = CMSSettings.physicalAssetDirFile + fileID;
if (System.IO.File.Exists(physicalLocation))
{
FileStream fs = new FileStream(physicalLocation, FileMode.Open);
HashAlgorithm ha = (HashAlgorithm)CryptoConfig.CreateFromName("SHA1");
Int64 fsh = BitConverter.ToInt64(ha.ComputeHash(fs), 0);
Int64 msh = BitConverter.ToInt64(ha.ComputeHash(ms), 0);
CreateNewFile = (fsh != msh);
}
if (CreateNewFile)
{
cv.listFilesOwned.Remove(outputFv.objFile);
}
}
if (CreateNewFile)
{
OutputFile = FileManager.CreateNew((Folder)null, _user, false, ot);
OutputFile.listVersions[0].name = filename;
OutputFile.listVersions[0].objCheckedOutBy = null;
string fileID = OutputFile.listVersions[0].id.ToString();
string physicalLocation = CMSSettings.physicalAssetDirFile + fileID;
try
{
FileStream fs = new FileStream(physicalLocation, FileMode.Create);
ms.WriteTo(fs);
LocalURL = FinaliseOutputFile(cv, OutputFile, filename);
}
catch
{
ExceptionManager.Log("Could not generate feature image for: " + cv.name);
}
}
else
{
LocalURL = getURLFromFilenameAndID(outputFv.objFile.id, filename);
}
return LocalURL;
}
private Seamless.CMS.File GetOutputSeamlessFile(ContentVersion cv, string filename)
{
ObjectType ot = ObjectTypeManager.GetByName("Image");
Seamless.CMS.File OutputFile;
List<FileVersion> fvList = new List<FileVersion>();
foreach (Seamless.CMS.File file in cv.listFilesOwned)
{
FileVersion fv = FileVersionManager.GetFileLatest(file.id);
if (fv != null)
{
fvList.Add(fv);
}
}
FileVersion outputFv = fvList.FirstOrDefault<FileVersion>(pfv => pfv.name == filename);
if (outputFv != null)
{
cv.listFilesOwned.Remove(outputFv.objFile);
}
OutputFile = FileManager.CreateNew((Folder)null, _user, false, ot);
OutputFile.listVersions[0].name = filename;
OutputFile.listVersions[0].objCheckedOutBy = null;
return OutputFile;
}
private string FinaliseOutputFile(ContentVersion cv, Seamless.CMS.File OutputFile, string filename)
{
SessionUser su = _user;
FileInfo fi = new FileInfo(CMSSettings.physicalAssetDirFile + OutputFile.listVersions[0].id.ToString());
OutputFile.listVersions[0].size = (int)fi.Length;
OutputFile.listVersions[0].objWorkflow = null;
OutputFile.listVersions[0].isPublished = true;
OutputFile.listVersions[0].activateDate = DateTime.Now;
OutputFile.listVersions[0].deactivateDate = DateTime.MaxValue;
OutputFile.listVersions[0].isRolledback = false;
FileVersionManager.Save(OutputFile.listVersions[0]);
OutputFile.objGroup = su.currentGroup;
OutputFile.objOwnerContentVersion = cv;
OutputFile.isArchived = false;
FileManager.Save(OutputFile);
if (!cv.listFilesOwned.Contains(OutputFile))
{
cv.listFilesOwned.Add(OutputFile);
}
return getURLFromFilenameAndID(OutputFile.id, filename);
}
private string getURLFromFilenameAndID(Guid guid, string filename)
{
return "files/" + guid.ToString() + "/" + filename + FormatTools.KEY_VALUE_PAIR_DELIMITER.ToString();
}
private MemoryStream GetRemoteFile(string url)
{
MemoryStream file;
WebClient client = new WebClient();
try
{
file = new MemoryStream(client.DownloadData(url));
}
finally
{
client.Dispose();
}
return file;
}
#endregion