本文整理汇总了C#中Serializer.CreateConnection方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.CreateConnection方法的具体用法?C# Serializer.CreateConnection怎么用?C# Serializer.CreateConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.CreateConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createProfile
private UserProfile createProfile()
{
UserProfile newProfile = null;
if ((_repositorySerializer = Connections.Repository) != null)
{
if ((_definitionsSerializer = Connections.Definitions) != null)
{
UserProxy proxy;
try
{
//Zuerst korrespondierenden Userproxy holen
IRestriction r = RestrictionFactory.Eq(typeof(UserProxy), "_LoginName", _settings.Username);
//IRestriction r = RestrictionFactory.Eq(typeof(UserProxy), "_LoginName", @"TestEditor");
proxy = _repositorySerializer.Connector.Load<UserProxy>(r);
if (proxy == null)
{
_Log.Error("No User Proxy");
_operation.failure("Services_UserProfile_Error_NoProxy", "");
return null;
}
if (string.IsNullOrEmpty(proxy.AgentURI))
{
_Log.Error("Cannot create Profile, empty AgentURI");
#if !DEBUG
_operation.failure("Services_UserProfile_Error_EmptyAgentURL","");
return null;
#endif
}
newProfile = _mobileSerializer.CreateISerializableObject<UserProfile>();
newProfile.LoginName = _settings.Username;
//newProfile.LoginName = @"TestEditor";
string agentName = null;
using (var conn = _definitionsSerializer.CreateConnection())
{
try
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT [AgentName] FROM [" + _settings.CurrentConnection.TaxonNamesInitialCatalog + "].[dbo].[IBFagents] WHERE [AgentURI] = '" + proxy.AgentURI + "'";
_Log.DebugFormat("Select AgentName Command: [{0}]", cmd.CommandText);
agentName = cmd.ExecuteScalar() as string;
_Log.DebugFormat("AgentName: [{0}]", agentName);
}
finally
{
conn.Close();
}
}
newProfile.CombinedNameCache = (!string.IsNullOrEmpty(agentName)) ? agentName : proxy.CombinedNameCache;
newProfile.HomeDB = _settings.CurrentConnection.InitialCatalog;
newProfile.AgentURI = proxy.AgentURI;
_mobileSerializer.Connector.Save(newProfile);
MessengerInstance.Send<SyncStepFinished>(SyncState.ProfileChanged);
}
catch (Exception ex)
{
newProfile = null;
//TODO
_operation.failure("","");
_Log.ErrorFormat("Error Creating Profile: {0}", ex);
}
}
else
_Log.Error("Definitions N/A");
}
else
_Log.Error("Repository N/A");
return newProfile;
}
示例2: updateProperties
//Überträgt die Namen von Properties vom Repository in die mobile Datenbank. Um doppelte Einträge zu vermeiden werden zunächst Einträge in der Mobilen Datenbank
//gelöscht. Kann mit Reflexion verallgemeinert und mit updateTaxonNames kombiniert werden.
public int updateProperties(string sourceTable, string targetTable, Serializer taxonrepSerializer, Serializer namesSerializer)
{
if (MappingDictionary.Mapping.ContainsKey(typeof(PropertyNames)))
MappingDictionary.Mapping[typeof(PropertyNames)] = sourceTable;
else
MappingDictionary.Mapping.Add(typeof(PropertyNames), sourceTable);
//Neue Properties holen
IList<PropertyNames> properties = new List<PropertyNames>();
this.setProgressValue(0);
this.setActionInformation("Get PropertyNames from Source-Table: " + sourceTable);
//IRestriction r = RestrictionFactory.TypeRestriction(typeof(PropertyNames));
//properties = taxonrepSerializer.Connector.LoadList<PropertyNames>(r);//geht nicht , weil auf der Sicht keine GUID definiert ist
DbConnection connRepository = taxonrepSerializer.CreateConnection();
DbCommand com = connRepository.CreateCommand();
StringBuilder sb = new StringBuilder();
sb.Append("Select * From ").Append(sourceTable);
com.CommandText = sb.ToString();
connRepository.Open();
DbDataReader reader = null;
try
{
reader = com.ExecuteReader();
}
catch (Exception e)
{
this.setProgressInformation("Exception while updating PropertyNames from: " + sourceTable);
connRepository.Close();
return -1;
}
int index = 0;//Index kann über Serializer nicht abgefragt werden
while (reader.Read())
{
PropertyNames prop = new PropertyNames();
prop.PropertyID = reader.GetInt32(0);
if (!reader.IsDBNull(1))
prop.PropertyURI = reader.GetString(1);
if (!reader.IsDBNull(2))
prop.DisplayText = reader.GetString(2);
if (!reader.IsDBNull(3))
prop.HierarchyCache = reader.GetString(3);
//primary key
prop.TermID = reader.GetInt32(4);
if (!reader.IsDBNull(5))
prop.BroaderTermID = reader.GetInt32(5);
properties.Add(prop);
index++;
this.setProgressInformation(index + " items already read");
}
this.setProgressValue(40);
connRepository.Close();
DbConnection connMobile = namesSerializer.CreateConnection();
connMobile.Open();
SqlCeTransaction trans = (SqlCeTransaction)connMobile.BeginTransaction();
//Alte Taxa löschen
this.setActionInformation("Delete old PropertyNames from Target-Table: " + targetTable);
this.setProgressInformation("");
DbCommand commandMobile = connMobile.CreateCommand();
sb = new StringBuilder();
sb.Append("Delete From ").Append(targetTable);
commandMobile.CommandText = sb.ToString();
commandMobile.ExecuteNonQuery();
this.setProgressValue(50);
//Taxa eintragen
this.setActionInformation("Save new PropertyNames in Target-Table: " + targetTable);
index = 0;
double part = ((double)50 / (double)properties.Count);
foreach (PropertyNames prop in properties)
{
sb = new StringBuilder(); //Alternativ mobileDBSerializer.Connector.Save(taxon)
sb.Append("Insert INTO ").Append(targetTable).Append(" (PropertyID,PropertyURI,DisplayText,HierarchyCache,TermID,BroaderTermID) VALUES (");
sb.Append(SqlUtil.SqlConvert(prop.PropertyID)).Append(",");
sb.Append(SqlUtil.SqlConvert(prop.PropertyURI)).Append(",").Append(SqlUtil.SqlConvert(prop.DisplayText)).Append(",").Append(SqlUtil.SqlConvert(prop.HierarchyCache)).Append(",").Append(prop.TermID).Append(",").Append(prop.BroaderTermID).Append(")");
DbCommand insert = connMobile.CreateCommand();
insert.CommandText = @sb.ToString();
insert.ExecuteNonQuery();
index++;
// Set ProgressInformation
this.setProgressInformation(index + " of " + properties.Count + " items already saved");
int offset = Convert.ToInt32(index * part);
this.setProgressValue(50 + offset);
}
trans.Commit();
connMobile.Close();
this.setActionInformation("Update PropertyNames");
return properties.Count;
}