/// <summary> /// Loads the specified filename and relocates enumerator position. /// If file is not part of the current library, ImageFileReader will change to the appropriate library. /// </summary> /// <param name="FileName">Name of file.</param> /// <returns>DFImageFile object.</returns> public DFImageFile LoadFile(string FileName) { // Always use upper case FileName = FileName.ToUpper(); // Change library type based on filename LibraryTypes NewLibraryType = ParseLibraryType(FileName); if (NewLibraryType == LibraryTypes.None) { return(null); } // Set new library type LibraryType = NewLibraryType; // Get index of file int Index = GetFileIndex(MyLibraryType, FileName); if (-1 == Index) { return(null); } // Load file if (LoadFile(MyLibraryType, Index)) { return(ImageFile); } else { return(null); } }
/// <summary> /// Discards all cached image data. /// </summary> public void DiscardAll() { // Discard file name arrays TextureFileNames = null; ImgFileNames = null; CifFileNames = null; RciFileNames = null; SkyFileNames = null; // Discard file arrays TextureFileItems = null; ImgFileItems = null; CifFileItems = null; RciFileItems = null; SkyFileItems = null; // Discard hashtables TextureHashtable = null; ImgHashtable = null; CifHashtable = null; RciHashtable = null; SkyHashtable = null; // Clear current library type, forcing files to be reindexed on next change MyLibraryType = LibraryTypes.None; LastOpenLibraryType = LibraryTypes.None; LastOpenFileIndex = -1; }
/// <summary> /// Sets file item by index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <param name="Item">ImageFileItem to store.</param> private void SetFileItem(LibraryTypes Type, int Index, ImageFileItem Item) { // Index must be within range if (Index < 0 || Index >= GetFileCount(Type)) { return; } // Get path by index switch (Type) { case LibraryTypes.Texture: TextureFileItems[Index] = Item; break; case LibraryTypes.Img: ImgFileItems[Index] = Item; break; case LibraryTypes.Cif: CifFileItems[Index] = Item; break; case LibraryTypes.Rci: RciFileItems[Index] = Item; break; case LibraryTypes.Sky: SkyFileItems[Index] = Item; break; } }
/// <summary> /// Gets absolute path to file by index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <returns>Name of file.</returns> private string GetFileName(LibraryTypes Type, int Index) { // Index must be within range if (Index < 0 || Index >= GetFileCount(Type)) { return(string.Empty); } // Get path by index switch (Type) { case LibraryTypes.Texture: return(TextureFileItems[Index].FileName); case LibraryTypes.Img: return(ImgFileItems[Index].FileName); case LibraryTypes.Cif: return(CifFileItems[Index].FileName); case LibraryTypes.Rci: return(RciFileItems[Index].FileName); case LibraryTypes.Sky: return(SkyFileItems[Index].FileName); default: return(string.Empty); } }
/// <summary> /// Gets file item by index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <returns>ImageFileItem object.</returns> private ImageFileItem GetFileItem(LibraryTypes Type, int Index) { // Index must be within range if (Index < 0 || Index >= GetFileCount(Type)) { return(new ImageFileItem()); } // Get path by index switch (Type) { case LibraryTypes.Texture: return(TextureFileItems[Index]); case LibraryTypes.Img: return(ImgFileItems[Index]); case LibraryTypes.Cif: return(CifFileItems[Index]); case LibraryTypes.Rci: return(RciFileItems[Index]); case LibraryTypes.Sky: return(SkyFileItems[Index]); default: return(new ImageFileItem()); } }
/// <summary> /// Gets number of files in specified library. /// </summary> /// <param name="Type">Library type.</param> /// <returns>File count.</returns> private int GetFileCount(LibraryTypes Type) { // Get count by type switch (Type) { case LibraryTypes.Texture: if (null == TextureFileItems) { return(0); } else { return(TextureFileItems.Count); } case LibraryTypes.Img: if (null == ImgFileItems) { return(0); } else { return(ImgFileItems.Count); } case LibraryTypes.Cif: if (null == CifFileItems) { return(0); } else { return(CifFileItems.Count); } case LibraryTypes.Rci: if (null == RciFileItems) { return(0); } else { return(RciFileItems.Count); } case LibraryTypes.Sky: if (null == SkyFileItems) { return(0); } else { return(SkyFileItems.Count); } default: return(0); } }
/// <summary> /// Discard a file object so it will be garbage collected. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file to discard.</param> private void DiscardFile(LibraryTypes Type, int Index) { // Discard by type ImageFileItem Item = GetFileItem(Type, Index); Item.ImageFile = null; SetFileItem(Type, Index, Item); }
/// <summary> /// Loads file by index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <returns>True if successful, otherwise false.</returns> private bool LoadFile(LibraryTypes Type, int Index) { // Arena2 must be valid, which implies files are indexed if (0 == GetFileCount(Type)) { return(false); } // Get file item and exit if already loaded (ImageFile is non-null) ImageFileItem Item = GetFileItem(Type, Index); if (null != Item.ImageFile) { MyFileIndex = Index; return(true); } // Discard last file DiscardLastFile(); // Compose full path to file string FilePath = Path.Combine(MyArena2Path, GetFileName(Type, Index)); // Create file object Item.ImageFile = CreateFile(Type); if (null == Item.ImageFile) { return(false); } // Load file if (!Item.ImageFile.Load(FilePath, Usage, true)) { return(false); } // Load pallette string PaletteName = Item.ImageFile.PaletteName; if (!string.IsNullOrEmpty(PaletteName)) { string PalettePath = Path.Combine(MyArena2Path, PaletteName); Item.ImageFile.LoadPalette(PalettePath); } // Set file item SetFileItem(Type, Index, Item); // Store new file index MyFileIndex = Index; // Store new library and index for auto-discard later LastOpenLibraryType = LibraryType; LastOpenFileIndex = Index; return(true); }
/// <summary> /// Gets description of file by index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <returns>File description.</returns> private string GetFileDescription(LibraryTypes Type, int Index) { // File must be loaded to get description if (!LoadFile(Type, Index)) { return(string.Empty); } // Get file description return(GetFileItem(Type, Index).ImageFile.Description); }
/// <summary> /// Gets record count of file by index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <returns>File record count.</returns> private int GetFileRecordCount(LibraryTypes Type, int Index) { // File must be loaded if (!LoadFile(Type, Index)) { return(0); } // Get file record count return(GetFileItem(Type, Index).ImageFile.RecordCount); }
/// <summary> /// Gets frame count of record by file index within specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <param name="Record">Record to obtain framecount from.</param> /// <returns>File record count.</returns> private int GetFileFrameCount(LibraryTypes Type, int Index, int Record) { // File must be loaded if (!LoadFile(Type, Index)) { return(0); } // Get record frame count return(GetFileItem(Type, Index).ImageFile.GetFrameCount(Record)); }
/// <summary> /// Discard last open file based on auto-discard property. /// </summary> private void DiscardLastFile() { // Discard based on auto-discard property if (AutoDiscard && LastOpenLibraryType != LibraryTypes.None && LastOpenFileIndex >= 0) { // Discard last file and clear DiscardFile(LastOpenLibraryType, LastOpenFileIndex); LastOpenLibraryType = LibraryTypes.None; LastOpenFileIndex = -1; } }
/// <summary> /// Gets image file object of index from specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="Index">Index of file.</param> /// <returns>DFImageFile object.</returns> private DFImageFile GetImageFile(LibraryTypes Type, int Index) { // File must be loaded if (!LoadFile(Type, Index)) { return(null); } // Get the item ImageFileItem Item = GetFileItem(Type, Index); return(Item.ImageFile); }
/// <summary> /// Create new file item lists and hashtables. Old lists and hashtables will be garbage collected. /// </summary> /// <param name="Type">Library type.</param> private void CreateFileList(LibraryTypes Type) { // Create new lists to hold file items switch (Type) { case LibraryTypes.Texture: TextureFileItems = new List <ImageFileItem>(); break; case LibraryTypes.Img: ImgFileItems = new List <ImageFileItem>(); break; case LibraryTypes.Cif: CifFileItems = new List <ImageFileItem>(); break; case LibraryTypes.Rci: RciFileItems = new List <ImageFileItem>(); break; case LibraryTypes.Sky: SkyFileItems = new List <ImageFileItem>(); break; } // Create new hashtable for fast index lookups switch (Type) { case LibraryTypes.Texture: TextureHashtable = new Hashtable(); break; case LibraryTypes.Img: ImgHashtable = new Hashtable(); break; case LibraryTypes.Cif: CifHashtable = new Hashtable(); break; case LibraryTypes.Rci: RciHashtable = new Hashtable(); break; case LibraryTypes.Sky: SkyHashtable = new Hashtable(); break; } }
/// <summary> /// Creates a new file resource by library type. /// </summary> /// <param name="Type">Library type.</param> /// <returns>DFImageFile object.</returns> private DFImageFile CreateFile(LibraryTypes Type) { switch (Type) { case LibraryTypes.Texture: return(new TextureFile()); case LibraryTypes.Img: return(new ImgFile()); case LibraryTypes.Cif: case LibraryTypes.Rci: return(new CifRciFile()); case LibraryTypes.Sky: return(new SkyFile()); default: return(null); } }
/// <summary> /// Gets array of file names for specified library. /// </summary> /// <param name="Type">Library type.</param> /// <returns>Array of filenames.</returns> private string[] GetFileNames(LibraryTypes Type) { // Get by type switch (Type) { case LibraryTypes.Texture: return(TextureFileNames); case LibraryTypes.Img: return(ImgFileNames); case LibraryTypes.Cif: return(CifFileNames); case LibraryTypes.Rci: return(RciFileNames); case LibraryTypes.Sky: return(SkyFileNames); default: return(null); } }
/// <summary> /// Initializes a new instance of the <see cref="LibraryDownloadEvent"/> class. /// </summary> /// <param name="libraryType">Type of the library.</param> public LibraryDownloadEvent(LibraryTypes libraryType) { LibraryType = libraryType; }
/// <summary> /// Gets index of file in specified library. /// </summary> /// <param name="Type">Library type.</param> /// <param name="FileName">Name of file.</param> /// <returns>Index of file.</returns> private int GetFileIndex(LibraryTypes Type, string FileName) { // Check file exists switch (Type) { case LibraryTypes.Texture: if (!TextureHashtable.ContainsKey(FileName)) { return(-1); } break; case LibraryTypes.Img: if (!ImgHashtable.ContainsKey(FileName)) { return(-1); } break; case LibraryTypes.Cif: if (!CifHashtable.ContainsKey(FileName)) { return(-1); } break; case LibraryTypes.Rci: if (!RciHashtable.ContainsKey(FileName)) { return(-1); } break; case LibraryTypes.Sky: if (!SkyHashtable.ContainsKey(FileName)) { return(-1); } break; default: return(-1); } // Get index based on type switch (Type) { case LibraryTypes.Texture: return((int)TextureHashtable[FileName]); case LibraryTypes.Img: return((int)ImgHashtable[FileName]); case LibraryTypes.Cif: return((int)CifHashtable[FileName]); case LibraryTypes.Rci: return((int)RciHashtable[FileName]); case LibraryTypes.Sky: return((int)SkyHashtable[FileName]); default: return(-1); } }
/// <summary> /// Retrieves code. /// </summary> /// <param name="libraryType">The library type.</param> /// <returns>The <see cref="Dictionary{TKey,TValue}"/>.</returns> public Dictionary<string, SourceCodeDto> GetCode(LibraryTypes libraryType) { var result = new Dictionary<string, SourceCodeDto>(); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; using (var command = new SqlCommand("GetAllCode", connection)) { command.CommandType = CommandType.StoredProcedure; if (((libraryType & LibraryTypes.System) == LibraryTypes.System) && ((libraryType & LibraryTypes.Custom) == LibraryTypes.Custom)) { command.Parameters.AddWithValue("@includeCustom", 1); command.Parameters.AddWithValue("@includeSystem", 1); } else { command.Parameters.AddWithValue( (libraryType & LibraryTypes.System) == LibraryTypes.System ? "@includeSystem" : "@includeCustom", 1); } using (var sr = new SafeDataReader(command.ExecuteReader())) { while (sr.Read()) { var clientCode = sr.GetString(0); var serverCode = sr.GetString(1); var systemName = sr.GetString(2); var isSystem = sr.GetBool(3); var version = ParseVersion(sr.GetString(4)); result.Add( systemName, new SourceCodeDto { ClientCode = clientCode, ServerCode = serverCode, IsSystem = isSystem, Version = version }); } } } } return result; }
/// <summary> /// Initializes a new instance of the <see cref="LibraryBuilderContext"/> class. /// </summary> /// <param name="sourceCode">The source Code.</param> /// <param name="libraryType">The library Type.</param> public LibraryBuilderContext(IDictionary<string, SourceCodeDto> sourceCode, LibraryTypes libraryType) { LibraryType = libraryType; SourceCode = sourceCode; }
/// <summary> /// Cleans runtime scripts. /// </summary> /// <param name="libraryType">The library type.</param> public void CleanRuntimeScripts(LibraryTypes libraryType) { const string Sql = @" UPDATE dbo.PublishedProcesses SET RuntimeUpdateScript = NULL FROM dbo.PublishedProcesses pp INNER JOIN dbo.Processes p ON pp.ProcessId = p.Id WHERE p.IsRemoved = 0 AND p.IsInactive = 0 AND ((p.IsSystem = 1 AND @includeSystemProceses = 1) OR (p.IsSystem = 0 AND @includeUserProcesses = 1))"; var includeSystemProcesses = (libraryType & LibraryTypes.System) == LibraryTypes.System; var includeUserProcesses = (libraryType & LibraryTypes.Custom) == LibraryTypes.Custom; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; using (var command = new SqlCommand(Sql, connection)) { command.Parameters.AddWithValue("@includeSystemProceses", includeSystemProcesses); command.Parameters.AddWithValue("@includeUserProcesses", includeUserProcesses); command.ExecuteNonQuery(); } } }
/// <summary> /// Retrieves runtime scripts. /// </summary> /// <param name="libraryType">The library type.</param> /// <returns>Returns the collection of runtime update scripts.</returns> public Dictionary<int, string> GetRuntimeScripts(LibraryTypes libraryType) { var result = new Dictionary<int, string>(); const string Query = @" SELECT pp.Id,RuntimeUpdateScript FROM dbo.PublishedProcesses pp INNER JOIN dbo.Processes p ON pp.ProcessId = p.Id WHERE pp.RuntimeUpdateScript IS NOT NULL AND p.IsRemoved = 0 AND p.IsInactive = 0 AND ((p.IsSystem = 1 AND @includeSystemProceses = 1) OR (p.IsSystem = 0 AND @includeUserProcesses = 1)) ORDER BY LastModifiedOn"; var includeSystemProcesses = (libraryType & LibraryTypes.System) == LibraryTypes.System; var includeUserProcesses = (libraryType & LibraryTypes.Custom) == LibraryTypes.Custom; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; using (var command = new SqlCommand(Query, connection)) { command.Parameters.AddWithValue("@includeSystemProceses", includeSystemProcesses); command.Parameters.AddWithValue("@includeUserProcesses", includeUserProcesses); using (var sr = new SafeDataReader(command.ExecuteReader())) { while (sr.Read()) { result.Add(sr.GetInt32(0), sr.GetString(1)); } } } } return result; }
/// <summary> /// Retrieves republish list. /// </summary> /// <param name="currentVersion">The current version.</param> /// <param name="libraryType">The library type.</param> /// <returns>The list of DTO <see cref="List{T}" />.</returns> public IEnumerable<ProcessInfoDTO> GetRepublishList(string currentVersion, LibraryTypes libraryType) { var result = new List<ProcessInfoDTO>(); using (var cmd = new SqlCommand("GetRepublishList")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@version", currentVersion); if (((libraryType & LibraryTypes.System) == LibraryTypes.System) && ((libraryType & LibraryTypes.Custom) == LibraryTypes.Custom)) { cmd.Parameters.AddWithValue("@includeCustom", 1); cmd.Parameters.AddWithValue("@includeSystem", 1); } else { cmd.Parameters.AddWithValue( (libraryType & LibraryTypes.System) == LibraryTypes.System ? "@includeSystem" : "@includeCustom", 1); } Database.GetDataReader( cmd, sr => { while (sr.Read()) { result.Add(new ProcessInfoDTO { Id = sr.GetInt(0), SystemName = sr.GetString(1), Guid = sr.GetGuid(2), Name = sr.GetString(3), Version = ParseVersion(sr.GetString(4, string.Empty)) }); } }); } return result; }
/// <summary> /// Retrieves the scripts that update the full-text indexes on processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> /// <returns> /// The collection of scripts. /// </returns> public IList<string> GetFullTextUpdateScripts(LibraryTypes libraryTypes) { const string CommandText = @" SELECT pp.[FullTextUpdateScript] FROM [dbo].[PublishedProcesses] pp INNER JOIN [dbo].[Processes] p ON p.[Id] = pp.[ProcessId] WHERE p.[IsRemoved] = 0 AND p.[IsInactive] = 0 AND LEN(pp.[FullTextUpdateScript]) > 0 AND (p.[IsSystem] = 1 AND @includeSystemProcesses = 1 OR p.[IsSystem] = 0 AND @includeUserProcesses = 1)"; using (var connectionManager = GetConnectionManager()) { using (var cmd = new SqlCommand(CommandText, connectionManager.Connection)) { cmd.Parameters.AddWithValue("@includeSystemProcesses", libraryTypes.HasFlag(LibraryTypes.System)); cmd.Parameters.AddWithValue("@includeUserProcesses", libraryTypes.HasFlag(LibraryTypes.Custom)); using (var reader = new SafeDataReader(cmd.ExecuteReader())) { var result = new List<string>(); while (reader.Read()) { result.Add(reader.GetString(0)); } return result; } } } }
/// <summary> /// Updates the system indexes for all processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> public override void UpdateSystemIndexes(LibraryTypes libraryTypes) { var existingIndexes = GetExistingSystemIndexes(libraryTypes); var indexDefinitions = GetProcessIndexDefinitions(libraryTypes).Where(index => !IsReduntant(index)).ToArray(); foreach (var oldIndex in existingIndexes.Where(oldIndex => !indexDefinitions.Contains(oldIndex))) { TryDropIndex(oldIndex); } foreach (var newIndex in indexDefinitions.Where(newIndex => !existingIndexes.Contains(newIndex))) { TryCreateIndex(newIndex); } }
/// <summary> /// Updates the full-text indexes for processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> public virtual void UpdateFullTextIndexes(LibraryTypes libraryTypes) { }
/// <summary> /// Updates the system indexes for all processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> public override void UpdateSystemIndexes(LibraryTypes libraryTypes) { throw new NotImplementedException(); }
/// <summary> /// Determines whether the specified process is included in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> /// <param name="processName"> /// The process name. /// </param> /// <returns> /// <c>true</c> if the specified process is included in the specified libraries; otherwise, <c>false</c>. /// </returns> private static bool IsProcessIncluded(LibraryTypes libraryTypes, string processName) { return Constants.AllSystemProcesses.Contains(processName) ? libraryTypes.HasFlag(LibraryTypes.System) : libraryTypes.HasFlag(LibraryTypes.Custom); }
/// <summary> /// Gets the system index definitions for the processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> /// <returns> /// The collection of index definitions. /// </returns> private IList<DbIndexDefinition> GetExistingSystemIndexes(LibraryTypes libraryTypes) { var indexes = GetExistingSystemIndexes(); return indexes.Where(ix => IsProcessIncluded(libraryTypes, ix.TableName)).ToList(); }
/// <summary> /// Gets the definitions of the system indexes that should be created for the processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> /// <returns> /// The collection of index definitions. /// </returns> private static IEnumerable<DbIndexDefinition> GetProcessIndexDefinitions(LibraryTypes libraryTypes) { const string CommandText = @" DECLARE @Indexes TABLE ( [Id] INT ,[ProcessName] NVARCHAR(200) ,[IsUnique] BIT ); INSERT INTO @Indexes SELECT i.[Id] ,p.[SystemName] ,i.[IsUnique] FROM [dbo].[ProcessIndexes] i INNER JOIN [dbo].[Processes] p ON p.[Id] = i.[ProcessId] WHERE p.[IsRemoved] = 0 AND p.[IsInactive] = 0 AND ( (p.[IsSystem] = 1 AND @includeSystemProcesses = 1) OR (p.[IsSystem] = 0 AND @includeCustomProcesses = 1)) SELECT * FROM @Indexes SELECT f.[IndexId] ,f.[FieldName] ,f.[SortOrder] FROM [dbo].[ProcessIndexFields] f INNER JOIN @Indexes i ON i.[Id] = f.[IndexId] ORDER BY f.[IndexId], f.[FieldOrdinal]"; using (var ctx = GetMetaDatabaseConnectionManager()) { using (var cmd = new SqlCommand(CommandText, ctx.Connection)) { cmd.Parameters.AddWithValue("@includeSystemProcesses", libraryTypes.HasFlag(LibraryTypes.System)); cmd.Parameters.AddWithValue("@includeCustomProcesses", libraryTypes.HasFlag(LibraryTypes.Custom)); using (var reader = cmd.ExecuteReader()) { var indexList = new List<DbIndexDefinition>(); var indexMap = new Dictionary<int, DbIndexDefinition>(); while (reader.Read()) { var indexId = reader.GetInt32("Id"); var indexName = string.Format("SystemIndex-{0}", indexId); var index = new DbIndexDefinition { Name = indexName, TableName = reader.GetString("ProcessName"), IsUnique = reader.GetBoolean("IsUnique") }; indexList.Add(index); indexMap.Add(indexId, index); } reader.NextResult(); while (reader.Read()) { var indexId = reader.GetInt32("IndexId"); var index = indexMap[indexId]; index.Columns.Add( new DbIndexColumnDefinition { Name = reader.GetString("FieldName"), SortOrder = reader.GetEnum("SortOrder", DbSortOrder.Unspecified) }); } return indexList; } } } }
/// <summary> /// Saves this library info to the default location of the specified library type. /// </summary> /// <param name="libraryType"> /// The library type. /// </param> public void Save(LibraryTypes libraryType) { Save(GetFilePath(libraryType)); }
/// <summary> /// Updates the full-text indexes for processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> public override void UpdateFullTextIndexes(LibraryTypes libraryTypes) { var scripts = ProcessDal.GetFullTextUpdateScripts(libraryTypes).Where(script => !string.IsNullOrWhiteSpace(script)).ToList(); using (var connectionManager = GetRuntimeDatabaseConnectionManager()) { for (var index = 0; index < scripts.Count; index++) { var commandText = scripts[index]; WriteTraceMessage(string.Format(CultureInfo.InvariantCulture, "Creating full-text index {0} out of {1}", index + 1, scripts.Count)); try { using (var cmd = new SqlCommand(commandText, connectionManager.Connection)) { cmd.CommandTimeout = CommandTimeout; cmd.ExecuteNonQuery(); } } catch (Exception ex) { Logger.Log(LogSeverity.Error, commandText, ex); throw; } } } }
private static string GetVersionInfoFileName(LibraryTypes libraryType) { return string.Format(CultureInfo.InvariantCulture, "{0}.{1}.xml", Constants.VersionInfoFileName, libraryType); }
/// <summary> /// Loads the <see cref="DynamicLibraryInfo"/> for the specified library type from default location. /// </summary> /// <param name="libraryType"> /// The library type. /// </param> /// <returns> /// The <see cref="DynamicLibraryInfo"/>. /// </returns> public static DynamicLibraryInfo Load(LibraryTypes libraryType) { var filePath = GetFilePath(libraryType); if (string.IsNullOrEmpty(filePath)) { return null; } try { return Load(filePath); } catch (FileNotFoundException) { return null; } }
/// <summary> /// Publishes the loaded event. /// </summary> /// <param name="libraryType">Type of the library.</param> /// <exception cref="System.Exception">Cannot import Event Aggregator</exception> private void PublishLoadedEvent(LibraryTypes libraryType) { if (TheEventAggregator == null) CompositionInitializer.SatisfyImports(this); if (TheEventAggregator == null) throw new Exception("Cannot import Event Aggregator"); TheEventAggregator.Publish(new LibraryDownloadEvent(libraryType)); }
private static string GetFilePath(LibraryTypes libraryType) { if (string.IsNullOrEmpty(Settings.SilverlightOutputFolder)) { return null; } var outputFolder = Path.Combine(Settings.SilverlightOutputFolder, Constants.DynamicSubfolder); var filePath = Path.Combine(outputFolder, GetVersionInfoFileName(libraryType)); return filePath; }
/// <summary> /// Index all files of specified library type. /// </summary> /// <param name="FilePaths">Array of absolute paths to files.</param> /// <param name="Type">Library type.</param> /// <returns></returns> private bool IndexLibrary(ref string[] FilePaths, LibraryTypes Type) { // Create file name arrays switch (Type) { case LibraryTypes.Texture: TextureFileNames = new string[(FilePaths.Length - Arena2.TextureFile.UnsupportedFilenames.Length)]; break; case LibraryTypes.Img: ImgFileNames = new string[(FilePaths.Length - Arena2.TextureFile.UnsupportedFilenames.Length)]; break; case LibraryTypes.Cif: CifFileNames = new string[FilePaths.Length]; break; case LibraryTypes.Rci: RciFileNames = new string[FilePaths.Length]; break; case LibraryTypes.Sky: SkyFileNames = new string[FilePaths.Length]; break; } // Index and hash files int Index = 0; TextureFile TextureFile = new TextureFile(); ImgFile ImgFile = new ImgFile(); foreach (string FilePath in FilePaths) { // Get filename only string FileName = Path.GetFileName(FilePath); // Handle unsupported TEXTURE files if (LibraryTypes.Texture == Type) { if (!TextureFile.IsFilenameSupported(FileName)) { continue; } } // Handle unsupported IMG files if (LibraryTypes.Img == Type) { if (!ImgFile.IsFilenameSupported(FileName)) { continue; } } // Store file name in array switch (Type) { case LibraryTypes.Texture: TextureFileNames[Index] = FileName; break; case LibraryTypes.Img: ImgFileNames[Index] = FileName; break; case LibraryTypes.Cif: CifFileNames[Index] = FileName; break; case LibraryTypes.Rci: RciFileNames[Index] = FileName; break; case LibraryTypes.Sky: SkyFileNames[Index] = FileName; break; } // Create file item ImageFileItem Item = new ImageFileItem(); Item.FileName = FileName; Item.LibraryType = Type; Item.ImageFile = null; // Add file item based on type switch (Type) { case LibraryTypes.Texture: TextureFileItems.Add(Item); break; case LibraryTypes.Img: ImgFileItems.Add(Item); break; case LibraryTypes.Cif: CifFileItems.Add(Item); break; case LibraryTypes.Rci: RciFileItems.Add(Item); break; case LibraryTypes.Sky: SkyFileItems.Add(Item); break; } // Hash file index based on type switch (Type) { case LibraryTypes.Texture: TextureHashtable.Add(FileName, Index); break; case LibraryTypes.Img: ImgHashtable.Add(FileName, Index); break; case LibraryTypes.Cif: CifHashtable.Add(FileName, Index); break; case LibraryTypes.Rci: RciHashtable.Add(FileName, Index); break; case LibraryTypes.Sky: SkyHashtable.Add(FileName, Index); break; } // Increment index Index++; } return(true); }
/// <summary> /// The download library from storage. /// </summary> /// <param name="libraryType"> /// The library type. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool DownloadLibraryFromStorage(LibraryTypes libraryType) { if (libraryType == LibraryTypes.System) { var pathBin = Path.Combine(Settings.ApplicationPath, "bin"); if (!BlobExistsOnCloud(Systemlib)) { return false; } DownloadItemFromBLOBByName(ContainerName, Systemlib, pathBin); } if (libraryType == LibraryTypes.Custom) { var pathClintBin = Path.Combine(Settings.SilverlightOutputFolder, Constants.DynamicSubfolder); if (!BlobExistsOnCloud(Customlib)) { return false; } DownloadItemFromBLOBByName(ContainerName, Customlib, pathClintBin, false); } return true; }
/// <summary> /// Updates the system indexes for all processes in the specified libraries. /// </summary> /// <param name="libraryTypes"> /// The library types. /// </param> public abstract void UpdateSystemIndexes(LibraryTypes libraryTypes);