本文整理汇总了C#中SessionBase.Persist方法的典型用法代码示例。如果您正苦于以下问题:C# SessionBase.Persist方法的具体用法?C# SessionBase.Persist怎么用?C# SessionBase.Persist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionBase
的用法示例。
在下文中一共展示了SessionBase.Persist方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createDatabaseLocations
public void createDatabaseLocations(SessionBase session)
{
session.BeginUpdate();
Person person = new Person("Mats", "Persson", 54);
session.Persist(person);
session.Commit();
verifyDatabaseLocations(session);
}
示例2: Initialize
void Initialize()
{
SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath;
m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory);
try
{
m_session.BeginUpdate();
List<FederationViewModel> federationInfos = new List<FederationViewModel>();
List<FederationInfo> federationInfosToRemove = new List<FederationInfo>();
foreach (FederationInfo info in m_session.AllObjects<FederationInfo>())
{
try
{
federationInfos.Add(new FederationViewModel(info));
}
catch (Exception ex)
{
if (MessageBox.Show(ex.Message + " for " + info.HostName + " " + info.SystemDbsPath + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
federationInfosToRemove.Add(info);
}
}
foreach (FederationInfo info in federationInfosToRemove)
info.Unpersist(m_session);
if (federationInfos.Count() == 0)
{
string host = Properties.Settings.Default.DatabaseManagerHost;
if (host == null || host.Length == 0)
host = Dns.GetHostName();
FederationInfo info = new FederationInfo(host,
Properties.Settings.Default.DatabaseManagerDirectory,
Properties.Settings.Default.TcpIpPortNumber,
Properties.Settings.Default.DoWindowsAuthentication,
null,
Properties.Settings.Default.WaitForLockMilliseconds,
Properties.Settings.Default.UseClientServer,
"Database Manager");
m_session.Persist(info);
m_session.Commit();
federationInfos.Add(new FederationViewModel(info));
}
if (m_session.InTransaction)
m_session.Commit();
m_federationViews = federationInfos;
}
catch (Exception ex)
{
if (m_session.InTransaction)
m_session.Abort();
if (MessageBox.Show(ex.Message + " for " + SessionBase.LocalHost + " " + Properties.Settings.Default.DatabaseManagerDirectory + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
DirectoryInfo dir = new DirectoryInfo(Properties.Settings.Default.DatabaseManagerDirectory);
dir.Delete(true);
Initialize();
}
}
}
示例3: parseMovie
void parseMovie(SessionBase session, string line, ImdbRoot imdbRoot, ActingPerson acting)
{
line = new string(line.SkipWhile(aChar => aChar == '\t').ToArray<char>()); // skip any leading tabs
string movieName = new string(line.TakeWhile(aChar => aChar != '(').ToArray<char>()); // start of year
if (movieName.Length == 0 || movieName[0] != '\"') // then it is a TV series - skipping for now
{
line = line.Substring(movieName.Length + 1);
string yearString = new string(line.TakeWhile(aChar => aChar != ')').ToArray<char>()); // end of year
bool unknownYear = yearString == "????";
bool notEndOfMovieName = (yearString.Length < 4 || (yearString.Length > 4 && yearString[4] != '/') || Char.IsNumber(yearString[0]) == false || Char.IsNumber(yearString[1]) == false) && unknownYear == false;
while (notEndOfMovieName)
{
movieName += "(";
string extendedName = new string(line.TakeWhile(aChar => aChar != '(').ToArray<char>());
movieName += extendedName;
line = line.Substring(extendedName.Length + 1);
yearString = new string(line.TakeWhile(aChar => aChar != ')').ToArray<char>()); // end of year
unknownYear = yearString == "????";
notEndOfMovieName = (yearString.Length < 4 || (yearString.Length > 4 && yearString[4] != '/') || Char.IsNumber(yearString[0]) == false || Char.IsNumber(yearString[1]) == false) && unknownYear == false;
}
movieName = movieName.TrimEnd(trimEndChars);
line = line.Substring(yearString.Length + 1);
yearString = new string(yearString.TakeWhile(aChar => aChar != '/').ToArray<char>()); // skip year string like 2010/I
Int16 year;
if (unknownYear)
year = 0;
else
year = Int16.Parse(yearString);
line = new string(line.SkipWhile(aChar => aChar != '(' && aChar != '[').ToArray<char>()); // start of role
bool video = line.Length > 1 && line[0] == '(' && line[1] == 'V';
bool tv = line.Length > 2 && line[0] == '(' && line[1] == 'T' && line[2] == 'V';
if (tv == false && video == false)
{
string role = null;
if (line.Length > 1 && line[0] == '[')
{
line = line.Substring(1);
role = new string(line.TakeWhile(aChar => aChar != ']').ToArray<char>()); // end of role
}
Movie movie = new Movie(movieName, year, session);
if (!imdbRoot.MovieSet.TryGetKey(movie, ref movie))
{
session.Persist(movie);
imdbRoot.MovieSet.Add(movie);
}
if (role != null)
acting.InMovieAs.Add(movie, role);
movie.Cast.Add(acting);
}
}
}
示例4: CreateDirectoriesAndFiles
void CreateDirectoriesAndFiles(DirectoryInfo dirInfo, Folder folder, SessionBase session)
{
foreach (DirectoryInfo dir in dirInfo.GetDirectories())
{
Folder subFolder = new Folder(dir.Name, folder, session);
CreateDirectoriesAndFiles(dir, subFolder, session);
}
foreach (FileInfo fileInfo in dirInfo.GetFiles())
{
FileInDb file = new FileInDb(fileInfo.Name, folder);
byte[] bytes = File.ReadAllBytes(fileInfo.FullName);
FileContent fileContent = new FileContent(bytes);
session.Persist(fileContent);
file.Content = fileContent;
}
}
示例5: AllFederationsViewModel
public AllFederationsViewModel()
{
SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath;
m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory);
m_session.BeginUpdate();
List<FederationViewModel> federationInfos = new List<FederationViewModel>();
foreach (FederationInfo info in m_session.AllObjects<FederationInfo>())
{
try
{
federationInfos.Add(new FederationViewModel(info));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
if (federationInfos.Count() == 0)
{
string host = Properties.Settings.Default.DatabaseManagerHost;
if (host == null || host.Length == 0)
host = Dns.GetHostName();
FederationInfo info = new FederationInfo(host,
Properties.Settings.Default.DatabaseManagerDirectory,
Properties.Settings.Default.TcpIpPortNumber,
Properties.Settings.Default.DoWindowsAuthentication,
null,
Properties.Settings.Default.UseClientServer,
"Database Manager");
m_session.Persist(info);
m_session.Commit();
federationInfos.Add(new FederationViewModel(info));
}
if (m_session.InTransaction)
m_session.Commit();
m_federationViews = new ReadOnlyCollection<FederationViewModel>(federationInfos);
}
示例6: Persist
/// <summary>
/// Persists this object.
/// </summary>
/// <param name="placeHint">Use placement as specified by this object type, see <see cref="OptimizedPersistable.PlacementDatabaseNumber"/>, <see cref="OptimizedPersistable.ObjectsPerPage()"/> and <see cref="OptimizedPersistable.PagesPerDatabase()"/></param>
/// <param name="session">The session managing this object</param>
/// <param name="persistRefs">Persist any referenced object now or delay until flush/commit</param>
/// <param name="disableFlush">Controlls possible flushing of updated pages. Set to true if you want to prevent updated pages from being flushed to disk and setting such pages to a non updated state.</param>
/// <returns>The object id of the persistent object</returns>
public virtual UInt64 Persist(SessionBase session, IOptimizedPersistable placeHint, bool persistRefs = true, bool disableFlush = false)
{
Placement place = new Placement(session, placeHint, this, persistRefs, UInt32.MaxValue, placeHint.FlushIfPageFull);
return session.Persist(place, this, session.OpenSchema(false), UInt16.MaxValue - 1, disableFlush);
}
示例7: Interaction
public Interaction(Customer customer, User user, SessionBase session)
{
session.Persist(this);
customer.AddInteraction(this);
user.AddInteraction(this);
}
示例8: ParseActors
void ParseActors(SessionBase session, ImdbRoot imdbRoot)
{
using (FileStream stream = File.OpenRead(System.IO.Path.Combine(imdbTextFilesDir, "actors.list.gz")))
{
using (GZipStream decompress = new GZipStream(stream, CompressionMode.Decompress))
{
using (System.IO.StreamReader file = new System.IO.StreamReader(decompress))
{
string line;
int lineNumber = 0;
while ((line = file.ReadLine()) != null)
{ // skip all the intro stuff
lineNumber++;
if (line.Length > 5 && line[0] == '-' && line[5] == '\t')
break;
}
while ((line = file.ReadLine()) != null)
{
lineNumber++;
string actorName = new string(line.TakeWhile(aChar => aChar != '\t').ToArray<char>()); // end of name
if (line.Length > 10 && line[0] == '-' && line[1] == '-' && line[2] == '-' && line[3] == '-')
break; // signals end of input
line = line.Substring(actorName.Length + 1);
Actor actor = new Actor(actorName, session);
session.Persist(actor);
imdbRoot.ActorSet.Add(actor);
parseMovie(session, line, imdbRoot, actor);
while ((line = file.ReadLine()) != null)
{
if (line.Length == 0)
break;
lineNumber++;
parseMovie(session, line, imdbRoot, actor);
}
}
}
}
}
}
示例9: Save
public void Save(SessionBase session)
{
session.Persist(this);
}
示例10: createInitialObjects
void createInitialObjects(IssueTracker issueTracker, User user, SessionBase session)
{
Project project = new Project(user, "VelocityDB", "Object Database Management System");
session.Persist(project);
issueTracker.ProjectSet.Add(project);
Component webSite = new Component(user, "Web Site", "VelocityDB.com", project);
session.Persist(webSite);
issueTracker.ComponentSet.Add(webSite);
Component samples = new Component(user, "Samples", "Samples applications provided", project);
session.Persist(samples);
issueTracker.ComponentSet.Add(samples);
Component collections = new Component(user, "Collections", "Any of the collection classes", project);
session.Persist(collections);
issueTracker.ComponentSet.Add(collections);
Component performance = new Component(user, "Performance", "Any performance issue", project);
session.Persist(performance);
issueTracker.ComponentSet.Add(performance);
ProductVersion version = new ProductVersion(user, "5.0.16", "First initial version", new DateTime(2015, 11, 29));
session.Persist(version);
issueTracker.VersionSet.Add(version);
version = new ProductVersion(user, "4.7", "June 13 version", new DateTime(2015, 06, 13));
session.Persist(version);
issueTracker.VersionSet.Add(version);
}
示例11: lookupUser
User lookupUser(IssueTracker issueTracker, SessionBase session)
{
string userEmail = this.User.Identity.Name;
User user = new User(userEmail);
string dataPath = HttpContext.Current.Server.MapPath("~/Database");
if (!issueTracker.UserSet.TryGetValue(user, ref user))
{
CustomerContact existingCustomer = null;
string firstName = null;
string lastName = null;
string userName = null;
try
{
using (SessionNoServer session2 = new SessionNoServer(dataPath, 2000, true, true))
{
session2.BeginRead();
Root velocityDbroot = session2.AllObjects<Root>(false).FirstOrDefault();
CustomerContact lookup = new CustomerContact(userEmail, null);
velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer);
session2.Commit();
firstName = existingCustomer.FirstName;
lastName = existingCustomer.LastName;
userName = existingCustomer.UserName;
}
}
catch (System.Exception ex)
{
this.errorLabel.Text = ex.ToString();
}
user = new User(null, userEmail, firstName, lastName, userName);
session.Persist(user);
issueTracker.UserSet.Add(user);
}
return user;
}