protected void GenerateLoadSqlCommand ( SqlCommand command, LoadType loadType, Guid keyToLoadBy, Guid instanceId, List<CorrelationKey> keysToAssociate ) { long surrogateLockOwnerId = base.StoreLock.SurrogateLockOwnerId; byte[] concatenatedKeyProperties = null; bool singleKeyToAssociate = (keysToAssociate != null && keysToAssociate.Count == 1); if (keysToAssociate != null) { concatenatedKeyProperties = SerializationUtilities.CreateKeyBinaryBlob(keysToAssociate); } double operationTimeout = this.TimeoutHelper.RemainingTime().TotalMilliseconds; SqlParameterCollection parameters = command.Parameters; parameters.Add(new SqlParameter { ParameterName = "@surrogateLockOwnerId", SqlDbType = SqlDbType.BigInt, Value = surrogateLockOwnerId }); parameters.Add(new SqlParameter { ParameterName = "@operationType", SqlDbType = SqlDbType.TinyInt, Value = loadType }); parameters.Add(new SqlParameter { ParameterName = "@keyToLoadBy", SqlDbType = SqlDbType.UniqueIdentifier, Value = keyToLoadBy }); parameters.Add(new SqlParameter { ParameterName = "@instanceId", SqlDbType = SqlDbType.UniqueIdentifier, Value = instanceId }); parameters.Add(new SqlParameter { ParameterName = "@handleInstanceVersion", SqlDbType = SqlDbType.BigInt, Value = base.InstancePersistenceContext.InstanceVersion }); parameters.Add(new SqlParameter { ParameterName = "@handleIsBoundToLock", SqlDbType = SqlDbType.Bit, Value = base.InstancePersistenceContext.InstanceView.IsBoundToLock }); parameters.Add(new SqlParameter { ParameterName = "@keysToAssociate", SqlDbType = SqlDbType.Xml, Value = singleKeyToAssociate ? DBNull.Value : SerializationUtilities.CreateCorrelationKeyXmlBlob(keysToAssociate) }); parameters.Add(new SqlParameter { ParameterName = "@encodingOption", SqlDbType = SqlDbType.TinyInt, Value = base.Store.InstanceEncodingOption }); parameters.Add(new SqlParameter { ParameterName = "@concatenatedKeyProperties", SqlDbType = SqlDbType.VarBinary, Value = (object) concatenatedKeyProperties ?? DBNull.Value }); parameters.Add(new SqlParameter { ParameterName = "@operationTimeout", SqlDbType = SqlDbType.Int, Value = (operationTimeout < Int32.MaxValue) ? Convert.ToInt32(operationTimeout) : Int32.MaxValue }); parameters.Add(new SqlParameter { ParameterName = "@singleKeyId", SqlDbType = SqlDbType.UniqueIdentifier, Value = singleKeyToAssociate ? keysToAssociate[0].KeyId : (object) DBNull.Value }); }
public LoadFileGump( Mobile mobile, ArrayList argsList, LoadType loadtype, string filename ) : base(0,0) { gumpMobile = mobile; ArgsList = argsList; GetArgsList(); GetTextColors(); loadType = loadtype; FileName = filename; AddPage(0); // Page 0 MC.DisplayStyle( this, StyleTypeConfig, 180, 180, 340, 120 ); MC.DisplayBackground( this, BackgroundTypeConfig, 200, 200, 300, 40 ); MC.DisplayBackground( this, BackgroundTypeConfig, 200, 260, 300, 20 ); AddHtml( 221, 181, 280, 20, MC.ColorText( titleTextColor, "Load File" ), false, false ); switch ( loadType ) { case LoadType.Manual: { AddHtml( 201, 201, 280, 20, MC.ColorText( defaultTextColor, "Type in the filename to load:" ), false, false ); MC.DisplayBackground( this, ActiveTEBGTypeConfig, 200, 220, 300, 18 ); AddTextEntry( 200, 220, 300, 15, ActiveTextEntryTextColor, 0, "" ); break; } case LoadType.FileBrowserMsf: { AddHtml( 201, 201, 280, 20, MC.ColorText( defaultTextColor, "Are you sure you want to load file:" ), false, false ); AddHtml( 201, 221, 280, 20, MC.ColorText( defaultTextColor, MC.CropDirectory( FileName ) ), false, false ); break; } case LoadType.FileBrowserMbk: { MC.DisplayStyle( this, StyleTypeConfig, 180, 160, 340, 20 ); MC.DisplayBackground( this, BackgroundTypeConfig, 181, 161, 338, 18 ); AddHtml( 201, 161, 280, 20, MC.ColorText( defaultTextColor, "Warning: All Mega Spawners will be removed." ), false, false ); AddHtml( 201, 201, 280, 20, MC.ColorText( defaultTextColor, "Are you sure you want to load backup file:" ), false, false ); AddHtml( 201, 221, 280, 20, MC.ColorText( defaultTextColor, MC.CropDirectory( FileName ) ), false, false ); break; } } AddHtml( 441, 261, 60, 20, MC.ColorText( defaultTextColor, "Cancel" ), false, false ); AddButton( 400, 260, 4017, 4019, 0, GumpButtonType.Reply, 0 ); AddHtml( 241, 261, 60, 20, MC.ColorText( defaultTextColor, "Ok" ), false, false ); AddButton( 200, 260, 4023, 4025, 1, GumpButtonType.Reply, 0 ); }
// Database simulation public static IPoints LoadDataset(string websitepath, LoadType loadType = LoadType.Csv) { switch (loadType) { case LoadType.Serialized: throw new NotSupportedException(MethodBase.GetCurrentMethod().ToString()); case LoadType.Csv: return LoadDatasetFromCsv(websitepath); default: throw new ApplicationException("LoadDatasetFromDatabase unknown loadtype"); } }
public void LoadContent(string filename, List<List<string>> attributes, List<List<string>> contents, string identifier) { using (StreamReader reader = new StreamReader(filename)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (line.Contains("EndLoad=") && line.Contains(identifier)) { identifierFound = false; break; } else if (line.Contains("Load=") && line.Contains(identifier)) { identifierFound = true; continue; } if (identifierFound) { if (line.Contains("Load=")) { tempAttributes = new List<string>(); line = line.Remove(0, line.IndexOf("=") + 1); type = LoadType.Attributes; } else { tempContents = new List<string>(); type = LoadType.Contents; } string[] lineArray = line.Split(']'); foreach (string li in lineArray) { string newLine = li.Trim('[', ' ', ']'); if (newLine != String.Empty) { if (type == LoadType.Contents) tempContents.Add(newLine); else tempAttributes.Add(newLine); } } if (type == LoadType.Contents && tempContents.Count > 0) { contents.Add(tempContents); attributes.Add(tempAttributes); } } } } }
public MetaReader(IStreamManager streamManager, uint baseOffset, ICacheFile cache, BuildInformation buildInfo, LoadType type, FieldChangeSet ignore) { _streamManager = streamManager; BaseOffset = baseOffset; _cache = cache; _ignoredFields = ignore; _type = type; // Load layouts _reflexiveLayout = buildInfo.GetLayout("reflexive"); _tagRefLayout = buildInfo.GetLayout("tag reference"); _dataRefLayout = buildInfo.GetLayout("data reference"); }
public MetaReader(IStreamManager streamManager, uint baseOffset, ICacheFile cache, EngineDescription buildInfo, LoadType type, FieldChangeSet ignore) { _streamManager = streamManager; BaseOffset = baseOffset; _cache = cache; _ignoredFields = ignore; _type = type; // Load layouts _tagBlockLayout = buildInfo.Layouts.GetLayout("tag block"); _tagRefLayout = buildInfo.Layouts.GetLayout("tag reference"); _dataRefLayout = buildInfo.Layouts.GetLayout("data reference"); }
public override XDocument LoadDocument(string location, LoadType type) { XDocument doc = new XDocument(); try { if (type == LoadType.Disk) { doc = loadFromDisk(location); } } catch (Exception ex) { throw new InvalidInputFileException(ex); } return doc; }
static LoadEventListener() { Reload = new LoadType("Get") .SetAllowNulls(false) .SetAllowProxyCreation(false) .SetCheckDeleted(true) .SetNakedEntityReturned(false) .SetExactPersister(true); // NH: Different behavior to pass NH-295 Get = new LoadType("Get") .SetAllowNulls(true) .SetAllowProxyCreation(false) .SetCheckDeleted(true) .SetNakedEntityReturned(false) .SetExactPersister(true); // NH: Different behavior to pass NH-295 Load = new LoadType("Load") .SetAllowNulls(false) .SetAllowProxyCreation(true) .SetCheckDeleted(true) .SetNakedEntityReturned(false); ImmediateLoad = new LoadType("ImmediateLoad") .SetAllowNulls(true) .SetAllowProxyCreation(false) .SetCheckDeleted(false) .SetNakedEntityReturned(true); InternalLoadEager = new LoadType("InternalLoadEager") .SetAllowNulls(false) .SetAllowProxyCreation(false) .SetCheckDeleted(false) .SetNakedEntityReturned(false); InternalLoadLazy = new LoadType("InternalLoadLazy") .SetAllowNulls(false) .SetAllowProxyCreation(true) .SetCheckDeleted(false) .SetNakedEntityReturned(false); InternalLoadNullable = new LoadType("InternalLoadNullable") .SetAllowNulls(true) .SetAllowProxyCreation(false) .SetCheckDeleted(false) .SetNakedEntityReturned(false); }
private void DoLoad(LoadType loadType) { lock (loadLock) { instance.timer.Change(Timeout.Infinite, Timeout.Infinite); var tran = Cat.NewTransaction("LoadDataSource", loadType.ToString()); logger.Info("Load data source begin - " + loadType.ToString()); try { if (instance.names == null) instance.names = instance.GetNames(); if (instance.names.Length > 0) { var coll = DataSourceProvider.GetProvider().GetConnectionStrings(instance.names); DataSourceManager.AddConnectionStrings(coll); string names = string.Join(",", DataSourceManager.GetAllNames()); Cat.LogEvent("LoadDataSource.Cache", "LoadDataSource.Cache.Entries", CatConstants.SUCCESS, names); logger.Info("Data sources cached", names); } tran.Status = CatConstants.SUCCESS; } catch (Exception ex) { var msg = "Error occured during loading data source."; Cat.LogError(msg, ex); tran.SetStatus(ex); logger.Error(msg, ex); if (loadType == LoadType.Initialize) throw; } finally { tran.Complete(); logger.Info("Load data source end."); instance.timer.Change(ConfigHelper.UpdateInterval * 1000, Timeout.Infinite); } } }
public void LoadContent(string filename, List<List<string>> loadAttributes, List<List<string>> loadContents) { using (StreamReader reader = new StreamReader(filename)) { while(!reader.EndOfStream) { string line = reader.ReadLine(); if (line.Contains("Load=")) { tempAttributes = new List<string>(); line.Remove(0, line.IndexOf("=")-1); type = LoadType.Attributes; } else { tempContents = new List<string>(); type = LoadType.Contents; } string[] lineArray = line.Split(']'); foreach (var li in lineArray) { string newLine = li.Trim('[', ' ', ']'); if (newLine != string.Empty) { if(type == LoadType.Contents) tempContents.Add(newLine); else tempAttributes.Add(newLine); } } if (type == LoadType.Contents && tempContents.Count > 0) { contents.Add(tempContents); attributes.Add(tempAttributes); } } } }
//===================================================================== /// <summary> /// 加载资源,如果资源已经加载过,则直接从缓存中获取 /// </summary> /// <param name="fullName">全名</param> /// <param name="priority">优先级</param> /// <param name="loadType">加载类型</param> /// <param name="loadStart">加载开始前执行的方法</param> /// <param name="loadProgress">加载开始后且在结束前每帧执行的方法</param> /// <param name="loadEnd">加载结束后执行的方法</param> /// <param name="loadFail">加载失败后执行的方法</param> /// <param name="unZipStart">解压开始前执行的方法</param> /// <param name="unZipProgress">解压开始后且在结束前每帧执行的方法</param> /// <param name="unZipEnd">解压完毕后执行的方法</param> /// <param name="unZipFail">解压失败后执行的方法</param> public void addLoad(string fullName, LoadPriority priority = LoadPriority.two, LoadType loadType = LoadType.local, LoadFunctionDele loadStart = null, LoadFunctionDele loadProgress = null, LoadFunctionDele loadEnd = null, LoadFunctionDele loadFail = null, LoadFunctionDele unZipStart = null, LoadFunctionDele unZipProgress = null, LoadFunctionDele unZipEnd = null, LoadFunctionDele unZipFail = null) { LoadInfo loadInfo = new LoadInfo(); loadInfo.fullName = fullName; loadInfo.priority = priority; loadInfo.loadType = loadType; loadInfo.loadStart = loadStart; loadInfo.loadProgress = loadProgress; loadInfo.loadEnd = loadEnd; loadInfo.loadFail = loadFail; loadInfo.unZipStart = unZipStart; loadInfo.unZipProgress = unZipProgress; loadInfo.unZipEnd = unZipEnd; loadInfo.unZipFail = unZipFail; addLoad(loadInfo); }
public virtual void OnLoad(LoadEvent @event, LoadType loadType) { ISessionImplementor source = @event.Session; IEntityPersister persister; if (@event.InstanceToLoad != null) { persister = source.GetEntityPersister(null, @event.InstanceToLoad); //the load() which takes an entity does not pass an entityName @event.EntityClassName = @event.InstanceToLoad.GetType().FullName; } else { persister = GetEntityPersister(source.Factory, @event.EntityClassName); } if (persister == null) { throw new HibernateException("Unable to locate persister: " + @event.EntityClassName); } if (persister.IdentifierType.IsComponentType) { // skip this check for composite-ids relating to dom4j entity-mode; // alternatively, we could add a check to make sure the incoming id value is // an instance of Element... } else { System.Type idClass = persister.IdentifierType.ReturnedClass; if (idClass != null && !idClass.IsInstanceOfType(@event.EntityId)) { throw new TypeMismatchException("Provided id of the wrong type. Expected: " + idClass + ", got " + @event.EntityId.GetType()); } } EntityKey keyToLoad = new EntityKey(@event.EntityId, persister, source.EntityMode); try { if (loadType.IsNakedEntityReturned) { //do not return a proxy! //(this option indicates we are initializing a proxy) @event.Result = Load(@event, persister, keyToLoad, loadType); } else { //return a proxy if appropriate if (@event.LockMode == LockMode.None) { @event.Result = ProxyOrLoad(@event, persister, keyToLoad, loadType); } else { @event.Result = LockAndLoad(@event, persister, keyToLoad, loadType, source); } } } catch (HibernateException e) { log.Info("Error performing load command", e); throw; } }
/// <summary> /// If the class to be loaded has been configured with a cache, then lock /// given id in that cache and then perform the load. /// </summary> /// <returns> The loaded entity </returns> protected virtual object LockAndLoad(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, ISessionImplementor source) { ISoftLock sLock = null; CacheKey ck; if (persister.HasCache) { ck = new CacheKey(@event.EntityId, persister.IdentifierType, persister.RootEntityName, source.EntityMode, source.Factory); sLock = persister.Cache.Lock(ck, null); } else { ck = null; } object entity; try { entity = Load(@event, persister, keyToLoad, options); } finally { if (persister.HasCache) { persister.Cache.Release(ck, sLock); } } object proxy = @event.Session.PersistenceContext.ProxyFor(persister, keyToLoad, entity); return proxy; }
/// <summary> /// Given that there is no pre-existing proxy. /// Check if the entity is already loaded. If it is, return the entity, /// otherwise create and return a proxy. /// </summary> private object CreateProxyIfNecessary(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext) { object existing = persistenceContext.GetEntity(keyToLoad); if (existing != null) { // return existing object or initialized proxy (unless deleted) log.Debug("entity found in session cache"); if (options.IsCheckDeleted) { EntityEntry entry = persistenceContext.GetEntry(existing); Status status = entry.Status; if (status == Status.Deleted || status == Status.Gone) { return null; } } return existing; } else { log.Debug("creating new proxy for entity"); // return new uninitialized proxy object proxy = persister.CreateProxy(@event.EntityId, @event.Session); persistenceContext.BatchFetchQueue.AddBatchLoadableEntityKey(keyToLoad); persistenceContext.AddProxy(keyToLoad, (INHibernateProxy)proxy); ((INHibernateProxy)proxy) .HibernateLazyInitializer .ReadOnly = @event.Session.DefaultReadOnly || !persister.IsMutable; return proxy; } }
/// <summary> /// 加载字典。 /// </summary> /// <param name="dictionaryName">字典名称。</param> /// <param name="dictionaryAsset">字典资源。</param> /// <param name="loadType">字典加载方式。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>是否加载成功。</returns> protected override bool LoadDictionary(string dictionaryName, object dictionaryAsset, LoadType loadType, object userData) { TextAsset textAsset = dictionaryAsset as TextAsset; if (textAsset == null) { Log.Warning("Dictionary asset '{0}' is invalid.", dictionaryName); return(false); } bool retVal = false; switch (loadType) { case LoadType.Text: retVal = m_LocalizationManager.ParseDictionary(textAsset.text, userData); break; case LoadType.Bytes: retVal = m_LocalizationManager.ParseDictionary(textAsset.bytes, userData); break; case LoadType.Stream: using (MemoryStream stream = new MemoryStream(textAsset.bytes, false)) { retVal = m_LocalizationManager.ParseDictionary(stream, userData); } break; default: Log.Warning("Unknown load type."); return(false); } if (!retVal) { Log.Warning("Dictionary asset '{0}' parse failure.", dictionaryName); } return(retVal); }
public bool LoadXML(string sourceXMLOrFile, LoadType loadType) { return LoadXML(sourceXMLOrFile, loadType, Encoding.UTF8); }
private void SetReadWriteInfo(ResourceName resourceName, LoadType loadType, int length, int hashCode) { GetOrAddCheckInfo(resourceName).SetReadWriteInfo(loadType, length, hashCode); }
private void SetVersionInfo(ResourceName resourceName, LoadType loadType, int length, int hashCode, int zipLength, int zipHashCode) { GetOrAddCheckInfo(resourceName).SetVersionInfo(loadType, length, hashCode, zipLength, zipHashCode); }
/// <summary> Perfoms the load of an entity. </summary> /// <returns> The loaded entity. </returns> protected virtual object Load(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) { if (@event.InstanceToLoad != null) { if (@event.Session.PersistenceContext.GetEntry(@event.InstanceToLoad) != null) { throw new PersistentObjectException("attempted to load into an instance that was already associated with the session: " + MessageHelper.InfoString(persister, @event.EntityId, @event.Session.Factory)); } persister.SetIdentifier(@event.InstanceToLoad, @event.EntityId, @event.Session.EntityMode); } object entity = DoLoad(@event, persister, keyToLoad, options); bool isOptionalInstance = @event.InstanceToLoad != null; if (!options.IsAllowNulls || isOptionalInstance) { if (entity == null) { @event.Session.Factory.EntityNotFoundDelegate.HandleEntityNotFound(@event.EntityClassName, @event.EntityId); } } if (isOptionalInstance && entity != @event.InstanceToLoad) { throw new NonUniqueObjectException(@event.EntityId, @event.EntityClassName); } return entity; }
/// <summary> /// Attempts to locate the entity in the session-level cache. /// </summary> /// <param name="event">The load event </param> /// <param name="keyToLoad">The EntityKey representing the entity to be loaded. </param> /// <param name="options">The load options. </param> /// <returns> The entity from the session-level cache, or null. </returns> /// <remarks> /// If allowed to return nulls, then if the entity happens to be found in /// the session cache, we check the entity type for proper handling /// of entity hierarchies. /// If checkDeleted was set to true, then if the entity is found in the /// session-level cache, it's current status within the session cache /// is checked to see if it has previously been scheduled for deletion. /// </remarks> protected virtual object LoadFromSessionCache(LoadEvent @event, EntityKey keyToLoad, LoadType options) { ISessionImplementor session = @event.Session; object old = session.GetEntityUsingInterceptor(keyToLoad); if (old != null) { // this object was already loaded EntityEntry oldEntry = session.PersistenceContext.GetEntry(old); if (options.IsCheckDeleted) { Status status = oldEntry.Status; if (status == Status.Deleted || status == Status.Gone) { return RemovedEntityMarker; } } if (options.IsAllowNulls) { IEntityPersister persister = GetEntityPersister(@event.Session.Factory, @event.EntityClassName); if (!persister.IsInstance(old, @event.Session.EntityMode)) { return InconsistentRTNClassMarker; } } UpgradeLock(old, oldEntry, @event.LockMode, session); } return old; }
/// <summary> /// Coordinates the efforts to load a given entity. First, an attempt is /// made to load the entity from the session-level cache. If not found there, /// an attempt is made to locate it in second-level cache. Lastly, an /// attempt is made to load it directly from the datasource. /// </summary> /// <param name="event">The load event </param> /// <param name="persister">The persister for the entity being requested for load </param> /// <param name="keyToLoad">The EntityKey representing the entity to be loaded. </param> /// <param name="options">The load options. </param> /// <returns> The loaded entity, or null. </returns> protected virtual object DoLoad(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) { if (log.IsDebugEnabled) { log.Debug("attempting to resolve: " + MessageHelper.InfoString(persister, @event.EntityId, @event.Session.Factory)); } object entity = LoadFromSessionCache(@event, keyToLoad, options); if (entity == RemovedEntityMarker) { log.Debug("load request found matching entity in context, but it is scheduled for removal; returning null"); return null; } if (entity == InconsistentRTNClassMarker) { log.Debug("load request found matching entity in context, but the matched entity was of an inconsistent return type; returning null"); return null; } if (entity != null) { if (log.IsDebugEnabled) { log.Debug("resolved object in session cache: " + MessageHelper.InfoString(persister, @event.EntityId, @event.Session.Factory)); } return entity; } entity = LoadFromSecondLevelCache(@event, persister, options); if (entity != null) { if (log.IsDebugEnabled) { log.Debug("resolved object in second-level cache: " + MessageHelper.InfoString(persister, @event.EntityId, @event.Session.Factory)); } return entity; } if (log.IsDebugEnabled) { log.Debug("object not resolved in any cache: " + MessageHelper.InfoString(persister, @event.EntityId, @event.Session.Factory)); } return LoadFromDatasource(@event, persister, keyToLoad, options); }
/// <summary> /// 解析版本资源列表。 /// </summary> /// <param name="fileUri">版本资源列表文件路径。</param> /// <param name="bytes">要解析的数据。</param> /// <param name="errorMessage">错误信息。</param> private void ParseVersionList(string fileUri, byte[] bytes, string errorMessage) { if (m_VersionListReady) { throw new GameFrameworkException("Version list has been parsed."); } if (bytes == null || bytes.Length <= 0) { throw new GameFrameworkException("Version list is invalid."); } MemoryStream memoryStream = null; try { memoryStream = new MemoryStream(bytes); using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { memoryStream = null; char[] header = binaryReader.ReadChars(3); if (header[0] != VersionListHeader[0] || header[1] != VersionListHeader[1] || header[2] != VersionListHeader[2]) { throw new GameFrameworkException("Version list header is invalid."); } byte listVersion = binaryReader.ReadByte(); if (listVersion == 0) { byte[] encryptBytes = binaryReader.ReadBytes(4); m_ResourceManager.m_ApplicableGameVersion = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes)); m_ResourceManager.m_InternalResourceVersion = binaryReader.ReadInt32(); int resourceCount = binaryReader.ReadInt32(); string[] names = new string[resourceCount]; string[] variants = new string[resourceCount]; int[] lengths = new int[resourceCount]; Dictionary <string, string[]> dependencyAssetNamesCollection = new Dictionary <string, string[]>(); for (int i = 0; i < resourceCount; i++) { names[i] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes)); variants[i] = null; byte variantLength = binaryReader.ReadByte(); if (variantLength > 0) { variants[i] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes)); } LoadType loadType = (LoadType)binaryReader.ReadByte(); lengths[i] = binaryReader.ReadInt32(); int hashCode = binaryReader.ReadInt32(); int zipLength = binaryReader.ReadInt32(); int zipHashCode = binaryReader.ReadInt32(); int assetNamesCount = binaryReader.ReadInt32(); string[] assetNames = new string[assetNamesCount]; for (int j = 0; j < assetNamesCount; j++) { assetNames[j] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytes(hashCode))); int dependencyAssetNamesCount = binaryReader.ReadInt32(); string[] dependencyAssetNames = new string[dependencyAssetNamesCount]; for (int k = 0; k < dependencyAssetNamesCount; k++) { dependencyAssetNames[k] = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), Utility.Converter.GetBytes(hashCode))); } if (variants[i] == null || variants[i] == m_CurrentVariant) { dependencyAssetNamesCollection.Add(assetNames[j], dependencyAssetNames); } } ResourceName resourceName = new ResourceName(names[i], variants[i]); SetVersionInfo(resourceName, loadType, lengths[i], hashCode, zipLength, zipHashCode); if (variants[i] == null || variants[i] == m_CurrentVariant) { ProcessAssetInfo(resourceName, assetNames); } } ProcessAssetDependencyInfo(dependencyAssetNamesCollection); ResourceGroup resourceGroupAll = m_ResourceManager.GetResourceGroup(string.Empty); for (int i = 0; i < resourceCount; i++) { resourceGroupAll.AddResource(names[i], variants[i], lengths[i]); } int resourceGroupCount = binaryReader.ReadInt32(); for (int i = 0; i < resourceGroupCount; i++) { string groupName = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes)); ResourceGroup resourceGroup = m_ResourceManager.GetResourceGroup(groupName); int groupResourceCount = binaryReader.ReadInt32(); for (int j = 0; j < groupResourceCount; j++) { ushort versionIndex = binaryReader.ReadUInt16(); if (versionIndex >= resourceCount) { throw new GameFrameworkException(string.Format("Version index '{0}' is invalid, resource count is '{1}'.", versionIndex, resourceCount)); } resourceGroup.AddResource(names[versionIndex], variants[versionIndex], lengths[versionIndex]); } } } else { throw new GameFrameworkException("Version list version is invalid."); } } m_VersionListReady = true; RefreshCheckInfoStatus(); } catch (Exception exception) { if (exception is GameFrameworkException) { throw; } throw new GameFrameworkException(string.Format("Parse version list exception '{0}'.", exception.Message), exception); } finally { if (memoryStream != null) { memoryStream.Dispose(); memoryStream = null; } } }
/// <summary> /// Performs the process of loading an entity from the configured underlying datasource. /// </summary> /// <param name="event">The load event </param> /// <param name="persister">The persister for the entity being requested for load </param> /// <param name="keyToLoad">The EntityKey representing the entity to be loaded. </param> /// <param name="options">The load options. </param> /// <returns> The object loaded from the datasource, or null if not found. </returns> protected virtual object LoadFromDatasource(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) { ISessionImplementor source = @event.Session; bool statsEnabled = source.Factory.Statistics.IsStatisticsEnabled; var stopWath = new Stopwatch(); if (statsEnabled) { stopWath.Start(); } object entity = persister.Load(@event.EntityId, @event.InstanceToLoad, @event.LockMode, source); if (@event.IsAssociationFetch && statsEnabled) { stopWath.Stop(); source.Factory.StatisticsImplementor.FetchEntity(@event.EntityClassName, stopWath.Elapsed); } return entity; }
private void ImportXml( string fileName, LoadType loadType ) { gumpMobile.SendMessage( "Importing spawners..." ); XmlDocument xml = new XmlDocument(); xml.Load( fileName ); XmlElement spawners = xml["MegaSpawners"]; version = GetInnerText( spawners["Version"] ); if ( MC.IsValidVersion( version ) ) { int delay = 0; new LoadSpawnersTimer( ArgsList, gumpMobile, version, spawners, fileName, true, delay ).Start(); } else { Messages = String.Format( "Error reading file. Unknown version: {0}. Please {1} another filename.", version, loadType == LoadType.Manual ? "type in" : "select" ); if ( loadType == LoadType.Manual ) gumpMobile.SendMessage( Messages ); OpenGump(); return; } }
/// <summary> Attempts to load the entity from the second-level cache. </summary> /// <param name="event">The load event </param> /// <param name="persister">The persister for the entity being requested for load </param> /// <param name="options">The load options. </param> /// <returns> The entity from the second-level cache, or null. </returns> protected virtual object LoadFromSecondLevelCache(LoadEvent @event, IEntityPersister persister, LoadType options) { ISessionImplementor source = @event.Session; bool useCache = persister.HasCache && ((source.CacheMode & CacheMode.Get) == CacheMode.Get) && @event.LockMode.LessThan(LockMode.Read); if (useCache) { ISessionFactoryImplementor factory = source.Factory; CacheKey ck = new CacheKey(@event.EntityId, persister.IdentifierType, persister.RootEntityName, source.EntityMode, factory); object ce = persister.Cache.Get(ck, source.Timestamp); if (factory.Statistics.IsStatisticsEnabled) { if (ce == null) { factory.StatisticsImplementor.SecondLevelCacheMiss(persister.Cache.RegionName); log.DebugFormat("Entity cache miss: {0}", ck); } else { factory.StatisticsImplementor.SecondLevelCacheHit(persister.Cache.RegionName); log.DebugFormat("Entity cache hit: {0}", ck); } } if (ce != null) { CacheEntry entry = (CacheEntry) persister.CacheEntryStructure.Destructure(ce, factory); // Entity was found in second-level cache... // NH: Different behavior (take a look to options.ExactPersister (NH-295)) if (!options.ExactPersister || persister.EntityMetamodel.SubclassEntityNames.Contains(entry.Subclass)) { return AssembleCacheEntry(entry, @event.EntityId, persister, @event); } } } return null; }
/// <summary> /// Creates the load procedure. /// </summary> /// <param name="owner">The owner.</param> /// <param name="type">The type.</param> /// <param name="fileNames">The file names.</param> /// <returns></returns> public static ILoadProcedure CreateLoadProcedure(IServerConnection owner, LoadType type, IEnumerable<string> fileNames) { var proc = CreateLoadProcedure(owner, type); var fproc = proc.SubType as IBaseLoadProcedure; if (fproc != null) { if (fileNames != null) { foreach (var f in fileNames) { fproc.SourceFile.Add(f); } } } return proc; }
public LoadTemplateAction(LoadType loadType, string filename) : base() { LoadType = loadType; Filename = filename; }
/// <summary> /// 解析读写区资源列表。 /// </summary> /// <param name="fileUri">读写区资源列表文件路径。</param> /// <param name="bytes">要解析的数据。</param> /// <param name="errorMessage">错误信息。</param> private void ParseReadWriteList(string fileUri, byte[] bytes, string errorMessage) { if (m_ReadWriteListReady) { throw new GameFrameworkException("Read-write list has been parsed."); } if (bytes == null || bytes.Length <= 0) { m_ReadWriteListReady = true; RefreshCheckInfoStatus(); return; } MemoryStream memoryStream = null; try { memoryStream = new MemoryStream(bytes); using (BinaryReader binaryReader = new BinaryReader(memoryStream)) { memoryStream = null; char[] header = binaryReader.ReadChars(3); if (header[0] != ReadWriteListHeader[0] || header[1] != ReadWriteListHeader[1] || header[2] != ReadWriteListHeader[2]) { throw new GameFrameworkException("Read-write list header is invalid."); } byte listVersion = binaryReader.ReadByte(); if (listVersion == 0) { byte[] encryptBytes = binaryReader.ReadBytes(4); int resourceCount = binaryReader.ReadInt32(); for (int i = 0; i < resourceCount; i++) { string name = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(binaryReader.ReadByte()), encryptBytes)); string variant = null; byte variantLength = binaryReader.ReadByte(); if (variantLength > 0) { variant = Utility.Converter.GetString(Utility.Encryption.GetXorBytes(binaryReader.ReadBytes(variantLength), encryptBytes)); } LoadType loadType = (LoadType)binaryReader.ReadByte(); int length = binaryReader.ReadInt32(); int hashCode = binaryReader.ReadInt32(); SetReadWriteInfo(new ResourceName(name, variant), loadType, length, hashCode); ResourceName resourceName = new ResourceName(name, variant); if (m_ResourceManager.m_ReadWriteResourceInfos.ContainsKey(resourceName)) { throw new GameFrameworkException(string.Format("Read-write resource info '{0}' is already exist.", resourceName.FullName)); } m_ResourceManager.m_ReadWriteResourceInfos.Add(resourceName, new ReadWriteResourceInfo(loadType, length, hashCode)); } } else { throw new GameFrameworkException("Read-write list version is invalid."); } } m_ReadWriteListReady = true; RefreshCheckInfoStatus(); } catch (Exception exception) { if (exception is GameFrameworkException) { throw; } throw new GameFrameworkException(string.Format("Parse read-write list exception '{0}'.", exception.Message), exception); } finally { if (memoryStream != null) { memoryStream.Dispose(); memoryStream = null; } } }
/// <summary> /// Registers the load procedure factory method. /// </summary> /// <param name="type">The type.</param> /// <param name="method">The method.</param> public static void RegisterLoadProcedureFactoryMethod(LoadType type, LoadProcCreatorFunc method) { if (_loadProcFactories.ContainsKey(type)) throw new ArgumentException(OSGeo.MapGuide.MaestroAPI.Strings.LoadProcFactoryMethodAlreadyRegistered + type); _loadProcFactories[type] = method; }
protected void GenerateLoadSqlCommand(SqlCommand command, LoadType loadType, Guid keyToLoadBy, Guid instanceId, List<CorrelationKey> keysToAssociate) { long surrogateLockOwnerId = base.StoreLock.SurrogateLockOwnerId; byte[] buffer = null; bool flag = (keysToAssociate != null) && (keysToAssociate.Count == 1); if (keysToAssociate != null) { buffer = SerializationUtilities.CreateKeyBinaryBlob(keysToAssociate); } double totalMilliseconds = base.TimeoutHelper.RemainingTime().TotalMilliseconds; SqlParameterCollection parameters = command.Parameters; SqlParameter parameter = new SqlParameter { ParameterName = "@surrogateLockOwnerId", SqlDbType = SqlDbType.BigInt, Value = surrogateLockOwnerId }; parameters.Add(parameter); SqlParameter parameter2 = new SqlParameter { ParameterName = "@operationType", SqlDbType = SqlDbType.TinyInt, Value = loadType }; parameters.Add(parameter2); SqlParameter parameter3 = new SqlParameter { ParameterName = "@keyToLoadBy", SqlDbType = SqlDbType.UniqueIdentifier, Value = keyToLoadBy }; parameters.Add(parameter3); SqlParameter parameter4 = new SqlParameter { ParameterName = "@instanceId", SqlDbType = SqlDbType.UniqueIdentifier, Value = instanceId }; parameters.Add(parameter4); SqlParameter parameter5 = new SqlParameter { ParameterName = "@handleInstanceVersion", SqlDbType = SqlDbType.BigInt, Value = base.InstancePersistenceContext.InstanceVersion }; parameters.Add(parameter5); SqlParameter parameter6 = new SqlParameter { ParameterName = "@handleIsBoundToLock", SqlDbType = SqlDbType.Bit, Value = base.InstancePersistenceContext.InstanceView.IsBoundToLock }; parameters.Add(parameter6); SqlParameter parameter7 = new SqlParameter { ParameterName = "@keysToAssociate", SqlDbType = SqlDbType.Xml, Value = flag ? DBNull.Value : SerializationUtilities.CreateCorrelationKeyXmlBlob(keysToAssociate) }; parameters.Add(parameter7); SqlParameter parameter8 = new SqlParameter { ParameterName = "@encodingOption", SqlDbType = SqlDbType.TinyInt, Value = base.Store.InstanceEncodingOption }; parameters.Add(parameter8); SqlParameter parameter9 = new SqlParameter { ParameterName = "@concatenatedKeyProperties", SqlDbType = SqlDbType.VarBinary, Value = buffer ?? DBNull.Value }; parameters.Add(parameter9); SqlParameter parameter10 = new SqlParameter { ParameterName = "@operationTimeout", SqlDbType = SqlDbType.Int, Value = (totalMilliseconds < 2147483647.0) ? Convert.ToInt32(totalMilliseconds) : 0x7fffffff }; parameters.Add(parameter10); SqlParameter parameter11 = new SqlParameter { ParameterName = "@singleKeyId", SqlDbType = SqlDbType.UniqueIdentifier, Value = flag ? ((object) keysToAssociate[0].KeyId) : ((object) DBNull.Value) }; parameters.Add(parameter11); }
/// <summary> /// Creates the load procedure. /// </summary> /// <param name="owner">The owner.</param> /// <param name="type">The type.</param> /// <returns></returns> public static ILoadProcedure CreateLoadProcedure(IServerConnection owner, LoadType type) { if (type == LoadType.Dwg || type == LoadType.Raster) throw new NotSupportedException(OSGeo.MapGuide.MaestroAPI.Strings.UnsupportedLoadProcedureType); if (_loadProcFactories.ContainsKey(type)) { var proc = _loadProcFactories[type](); proc.CurrentConnection = owner; return proc; } throw new InvalidOperationException(OSGeo.MapGuide.MaestroAPI.Strings.CannotCreateLoadProcedureSubType + type); }
/// <summary> /// Based on configured options, will either return a pre-existing proxy, /// generate a new proxy, or perform an actual load. /// </summary> /// <returns> The result of the proxy/load operation.</returns> protected virtual object ProxyOrLoad(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) { if (log.IsDebugEnabled) { log.Debug("loading entity: " + MessageHelper.InfoString(persister, @event.EntityId, @event.Session.Factory)); } if (!persister.HasProxy) { // this class has no proxies (so do a shortcut) return Load(@event, persister, keyToLoad, options); } else { IPersistenceContext persistenceContext = @event.Session.PersistenceContext; // look for a proxy object proxy = persistenceContext.GetProxy(keyToLoad); if (proxy != null) { return ReturnNarrowedProxy(@event, persister, keyToLoad, options, persistenceContext, proxy); } else { if (options.IsAllowProxyCreation) { return CreateProxyIfNecessary(@event, persister, keyToLoad, options, persistenceContext); } else { // return a newly loaded object return Load(@event, persister, keyToLoad, options); } } } }
public abstract XDocument LoadDocument(string location, LoadType type);
/// <summary> /// Given that there is a pre-existing proxy. /// Initialize it if necessary; narrow if necessary. /// </summary> private object ReturnNarrowedProxy(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext, object proxy) { log.Debug("entity proxy found in session cache"); var castedProxy = (INHibernateProxy) proxy; ILazyInitializer li = castedProxy.HibernateLazyInitializer; if (li.Unwrap) { return li.GetImplementation(); } object impl = null; if (!options.IsAllowProxyCreation) { impl = Load(@event, persister, keyToLoad, options); // NH Different behavior : NH-1252 if (impl == null && !options.IsAllowNulls) { @event.Session.Factory.EntityNotFoundDelegate.HandleEntityNotFound(persister.EntityName, keyToLoad.Identifier); } } if (impl == null && !options.IsAllowProxyCreation && options.ExactPersister) { // NH Different behavior : NH-1252 return null; } return persistenceContext.NarrowProxy(castedProxy, persister, keyToLoad, impl); }
/// <summary> /// 从文件或者URL加载XML /// Easy way to load XML from a file or URL /// </summary> public bool LoadXML(string sourceXMLOrFile, LoadType loadType, Encoding encoding) { bool bLoadResult = false; try { switch (loadType) { case LoadType.FromString: m_xmlDocument.LoadXml(sourceXMLOrFile); // loading from source XML text break; case LoadType.FromLocalFile: m_xmlDocument.Load(sourceXMLOrFile); // loading from a file break; case LoadType.FromURL: { string sURLContent = GetURLContent(sourceXMLOrFile, encoding); m_xmlDocument.LoadXml(sURLContent); break; } default: string sErr = "Developer note: No LoadType case supported for " + loadType.ToString(); throw (new Exception(sErr)); } DoPostLoadCreateInit(); bLoadResult = true; } catch (Exception e) { HandleException(e); } return bLoadResult; }
/// <summary> /// 增加资源更新。 /// </summary> /// <param name="resourceName">资源名称。</param> /// <param name="loadType">资源加载方式。</param> /// <param name="length">资源大小。</param> /// <param name="hashCode">资源哈希值。</param> /// <param name="zipLength">压缩包大小。</param> /// <param name="zipHashCode">压缩包哈希值。</param> /// <param name="resourcePath">资源路径。</param> public void AddResourceUpdate(ResourceName resourceName, LoadType loadType, int length, int hashCode, int zipLength, int zipHashCode, string resourcePath) { m_UpdateCandidateInfo.Add(new UpdateInfo(resourceName, loadType, length, hashCode, zipLength, zipHashCode, resourcePath)); }