本文整理汇总了C#中SaveOptions类的典型用法代码示例。如果您正苦于以下问题:C# SaveOptions类的具体用法?C# SaveOptions怎么用?C# SaveOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SaveOptions类属于命名空间,在下文中一共展示了SaveOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveXElement
private string SaveXElement(object elem, SaveOptions so)
{
string retVal = null;
switch (_mode)
{
case "Save":
using (StringWriter sw = new StringWriter())
{
if (_type.Name == "XElement")
{
(elem as XElement).Save(sw, so);
}
else if (_type.Name == "XDocument")
{
(elem as XDocument).Save(sw, so);
}
retVal = sw.ToString();
}
break;
case "ToString":
if (_type.Name == "XElement")
{
retVal = (elem as XElement).ToString(so);
}
else if (_type.Name == "XDocument")
{
retVal = (elem as XDocument).ToString(so);
}
break;
default:
TestLog.Compare(false, "TEST FAILED: wrong mode");
break;
}
return retVal;
}
示例2: SaveChanges
public override int SaveChanges(SaveOptions options)
{
BeforeSaveChanges(this);
var result = base.SaveChanges(options);
AfterSaveChanges(this);
return result;
}
示例3: Tidy
///<summary>
/// Tidies the XML file by formatting it in alphabetical order.
///</summary>
///<param name="inputXml"></param>
///<param name="saveOptions">Allows choosing between formatted/non-formatter output</param>
///<returns></returns>
public string Tidy(string inputXml, SaveOptions saveOptions)
{
var xmlDoc = XDocument.Parse(inputXml,LoadOptions.PreserveWhitespace);
var first = xmlDoc.Elements().First();
first.ReplaceWith(GetOrderedElement(first));
return xmlDoc.Declaration + xmlDoc.ToString(saveOptions);
}
示例4: CustomResourcesProcessing
// ExStart:PrefixForFontsHelper
private static string CustomResourcesProcessing(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
//-----------------------------------------------------------------------------
// It's just example of possible realization of cusstom processing of resources
// Referenced in result HTML
//-----------------------------------------------------------------------------
// 1) In this case we need only do something special
// with fonts, so let's leave processing of all other resources
// to converter itself
if (resourceSavingInfo.ResourceType != SaveOptions.NodeLevelResourceType.Font)
{
resourceSavingInfo.CustomProcessingCancelled = true;
return "";
}
// If supplied font resource, process it ourselves
// 1) Write supplied font with short name to desired folder
// You can easily do anythings - it's just one of realizations
_fontNumberForUniqueFontFileNames++;
string shortFontFileName = (_fontNumberForUniqueFontFileNames.ToString() + Path.GetExtension(resourceSavingInfo.SupposedFileName));
string outFontPath = _desiredFontDir + "\\" + shortFontFileName;
System.IO.BinaryReader fontBinaryReader = new BinaryReader(resourceSavingInfo.ContentStream);
System.IO.File.WriteAllBytes(outFontPath, fontBinaryReader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));
// 2) Return the desired URI with which font will be referenced in CSSes
string fontUrl = "http:// Localhost:255/document-viewer/GetFont/" + shortFontFileName;
return fontUrl;
}
示例5: SaveChanges
public override int SaveChanges(SaveOptions options)
{
foreach (ObjectStateEntry entry in
ObjectStateManager.GetObjectStateEntries(
EntityState.Added | EntityState.Modified))
{
if (entry.Entity is Configuration)
{
ValidateConfigurationAggregate((Configuration)entry.Entity);
}
else if (entry.Entity is Payment)
{
ValidatePaymentAggregate((Payment)entry.Entity);
if (entry.State == EntityState.Added)
{
Payment payment = (Payment)entry.Entity;
payment.PaymentCode = PaymentCode.NextPaymentCode(this);
}
}
}
return base.SaveChanges(options);
}
示例6: CustomSaveOfFontsAndImages
private static string CustomSaveOfFontsAndImages(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream);
byte[] resourceAsBytes = reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length);
if (resourceSavingInfo.ResourceType == SaveOptions.NodeLevelResourceType.Font)
{
Console.WriteLine("Font processed with handler. Length of content in bytes is " + resourceAsBytes.Length.ToString());
// Here You can put code that will save font to some storage, f.e database
MemoryStream targetStream = new MemoryStream();
targetStream.Write(resourceAsBytes, 0, resourceAsBytes.Length);
}
else if (resourceSavingInfo.ResourceType == SaveOptions.NodeLevelResourceType.Image)
{
Console.WriteLine("Image processed with handler. Length of content in bytes is " + resourceAsBytes.Length.ToString());
// Here You can put code that will save image to some storage, f.e database
MemoryStream targetStream = new MemoryStream();
targetStream.Write(resourceAsBytes, 0, resourceAsBytes.Length);
}
// We should return URI bt which resource will be referenced in CSS(for font)
// Or HTML(for images)
// This is very siplistic way - here we just return file name or resource.
// You can put here some URI that will include ID of resource in database etc.
// - this URI will be added into result CSS or HTML to refer the resource
return resourceSavingInfo.SupposedFileName;
}
示例7: SaveChanges
public override int SaveChanges(SaveOptions options)
{
int returnValue = 0;
// 因为我们不调用base.SaveChanges, 我们必须手动关闭链接.
// 否则我们将留下许多打开的链接, 最终导致链接瓶颈.
// Entity Framework提供了base.SaveChanges内部使用的EnsureConnection和ReleaseConnection.
// 这些是内部方法, 所以我们必须使用反射调用它们.
var EnsureConnectionMethod = typeof(ObjectContext).GetMethod(
"EnsureConnection", BindingFlags.Instance | BindingFlags.NonPublic);
EnsureConnectionMethod.Invoke(this, null);
// 使用ObjectStateManager.GetObjectStateEntries完成增加,修改,和删除集合.
foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Added))
{
Travel travel = ose.Entity as Travel;
if (travel != null)
{
RetryPolicy retryPolicy = new RetryPolicy();
retryPolicy.Task = new Action(() =>
{
this.InsertIntoTravel(travel.PartitionKey,
travel.Place, travel.GeoLocationText, travel.Time);
});
retryPolicy.Execute();
returnValue++;
}
}
foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Modified))
{
Travel travel = ose.Entity as Travel;
if (travel != null)
{
RetryPolicy retryPolicy = new RetryPolicy();
retryPolicy.Task = new Action(() =>
{
this.UpdateTravel(travel.PartitionKey,
travel.RowKey, travel.Place, travel.GeoLocationText, travel.Time);
});
retryPolicy.Execute();
returnValue++;
}
}
foreach (ObjectStateEntry ose in this.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
{
Travel travel = ose.Entity as Travel;
if (travel != null)
{
RetryPolicy retryPolicy = new RetryPolicy();
retryPolicy.Task = new Action(() =>
{
this.DeleteFromTravel(travel.PartitionKey, travel.RowKey);
});
retryPolicy.Execute();
returnValue++;
}
}
var ReleaseConnectionMethod = typeof(ObjectContext).
GetMethod("ReleaseConnection", BindingFlags.Instance | BindingFlags.NonPublic);
ReleaseConnectionMethod.Invoke(this, null);
return returnValue;
}
示例8: SaveChanges
public override int SaveChanges(SaveOptions options) {
foreach(ObjectStateEntry objectStateEntry in ObjectStateManager.GetObjectStateEntries(EntityState.Added)) {
if(objectStateEntry.Entity is Event) {
((Event)objectStateEntry.Entity).BeforeSave();
}
}
return base.SaveChanges(options);
}
示例9: SaveChanges
public void SaveChanges(SaveOptions saveOptions)
{
if (IsInTransaction)
{
throw new ApplicationException("A transaction is currently open. Use RollBackTransaction or CommitTransaction instead.");
}
((IObjectContextAdapter)_dbContext).ObjectContext.SaveChanges(saveOptions);
}
示例10: ToXml
/// <summary>
/// Преобразовать документ в XML-строку
/// </summary>
/// <param name="document"> Документ </param>
/// <param name="encoding"> Кодировка документа </param>
/// <param name="options"> Опции сохранения </param>
/// <returns> </returns>
public static string ToXml(this XDocument document, Encoding encoding, SaveOptions options)
{
using (var writer = new EncodedStringWriter(encoding))
{
document.Save(writer, options);
return writer.ToString();
}
}
示例11: SaveChanges
public int SaveChanges(SaveOptions options, bool logChanges)
{
int result = base.SaveChanges(options);
if(SavedChanges != null)
SavedChanges(this, null);
return result;
}
示例12: SaveChanges
public override int SaveChanges(SaveOptions options)
{
int result = base.SaveChanges(options);
if (SavedChanges != null)
SavedChanges(this, new EventArgs());
return result;
}
示例13: SaveChanges
public void SaveChanges(SaveOptions saveOptions)
{
if (IsInTransaction)
{
throw new ApplicationException("A transaction is running. Call CommitTransaction instead.");
}
((IObjectContextAdapter)_dbContext).ObjectContext.SaveChanges(saveOptions);
}
示例14: SaveChanges
public override int SaveChanges(SaveOptions options)
{
var changes = ObjectStateManager.GetObjectStateEntries(EntityState.Unchanged);
foreach (var change in changes)
{
var entityWithId = change.Entity as EntityWithId;
if (entityWithId != null)
ChangeStateOfEntity(ObjectStateManager, entityWithId);
}
return base.SaveChanges(options);
}
示例15: ToString
public string ToString (SaveOptions options)
{
StringWriter sw = new StringWriter ();
XmlWriterSettings s = new XmlWriterSettings ();
s.ConformanceLevel = ConformanceLevel.Auto;
s.Indent = options != SaveOptions.DisableFormatting;
XmlWriter xw = XmlWriter.Create (sw, s);
WriteTo (xw);
xw.Close ();
return sw.ToString ();
}