SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
AssocFileMgr.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Seci.Definitions;
5 
6 namespace Seci.Managers
7 {
11  public static class AssocFileMgr
12  {
16  private static SerialisableList<AssociatedFile> _associatedFiles = new SerialisableList<AssociatedFile>();
17 
18  internal static SerialisableList<AssociatedFile> AssociatedFiles { get { return _associatedFiles; } }
19 
20  #region Associated Files
21 
27  internal static void AddFile(AssociatedFile file)
28  {
29  if (!IsDuplicate(file.FileLocation))
30  {
31  _associatedFiles.Add(file);
32  }
33  }
34 
40  public static void AddFile(String fileName)
41  {
42  AssociatedFile file = new AssociatedFile(fileName);
43 
44  if (!IsDuplicate(fileName))
45  {
46  _associatedFiles.Add(file);
47  }
48  }
49 
54  internal static void RecreateFile(AssociatedFile file)
55  {
56  file.CreateFile();
57  }
58 
63  public static void RestoreFile(String fileName)
64  {
65  foreach (AssociatedFile file in _associatedFiles)
66  {
67  if (file.FileLocation.ToLower() == fileName.ToLower())
68  {
69  file.RestoreOriginal();
70  }
71  }
72  }
73 
79  public static Boolean IsDuplicate(String fileName)
80  {
81  //Check for duplicates
82  for (int i = 0; i < _associatedFiles.Count; ++i)
83  {
84  if (_associatedFiles[i].FileLocation.ToLower() == fileName.ToLower())
85  {
86  //Duplicate
87  return true;
88  }
89  }
90 
91  return false;
92  }
93 
99  public static Boolean RemoveFile(String fileName)
100  {
101  for (int i = 0; i < _associatedFiles.Count; ++i)
102  {
103  if (_associatedFiles[i].FileLocation == fileName)
104  {
105  _associatedFiles.RemoveAt(i);
106  return true;
107  }
108  }
109 
110  return false;
111  }
112 
117  public static Boolean AnyModifications()
118  {
119  for (int i = 0; i < _associatedFiles.Count; ++i)
120  {
121  //Ignore tpar and mpar files these are handled elsewhere
122  if (_associatedFiles[i].FileLocation.ToLower().EndsWith(".tpar") || _associatedFiles[i].FileLocation.ToLower().EndsWith(".mpar"))
123  {
124  continue;
125  }
126 
127  if (String.IsNullOrEmpty(_associatedFiles[i].OwningComponent) && _associatedFiles[i].HasBeenModified())
128  {
129  return true;
130  }
131  }
132 
133  return false;
134  }
135 
140  public static Boolean AnyModificationsToParFiles()
141  {
142  for (int i = 0; i < _associatedFiles.Count; ++i)
143  {
144  //Just check tpar and mpar files
145  if (_associatedFiles[i].FileLocation.ToLower().EndsWith(".tpar") || _associatedFiles[i].FileLocation.ToLower().EndsWith(".mpar"))
146  {
147  if (String.IsNullOrEmpty(_associatedFiles[i].OwningComponent) && _associatedFiles[i].HasBeenModified())
148  {
149  return true;
150  }
151  }
152  }
153 
154  return false;
155  }
156 
163  public static List<String> GetListOfAsscFiles(Boolean includeComps)
164  {
165  List<String> files = new List<String>();
166 
167  if (_associatedFiles != null)
168  {
169  for (int i = 0; i < _associatedFiles.Count; ++i)
170  {
171  if (includeComps || String.IsNullOrEmpty(_associatedFiles[i].OwningComponent))
172  {
173  files.Add(_associatedFiles[i].FileLocation);
174  }
175  }
176  }
177  return files;
178  }
179 
184  public static List<String> GetListOfComponentAsscFiles()
185  {
186  List<String> files = new List<String>();
187 
188  if (_associatedFiles != null)
189  {
190  for (int i = 0; i < _associatedFiles.Count; ++i)
191  {
192  if (!String.IsNullOrEmpty(_associatedFiles[i].OwningComponent))
193  {
194  files.Add(_associatedFiles[i].FileLocation);
195  }
196  }
197  }
198 
199  return files;
200  }
201 
202  #endregion
203  }
204 }
static List< String > GetListOfAsscFiles(Boolean includeComps)
Gets a list of all the associated files in a configuration. Including any associated files in the com...
static void RestoreFile(String fileName)
Restores the file to the original version that came from the configuration.
Definition: AssocFileMgr.cs:63
static Boolean RemoveFile(String fileName)
Remove a specfied associated file from the collection.
Definition: AssocFileMgr.cs:99
static Boolean AnyModificationsToParFiles()
Indicates whether any of the tpar or mpar files have been modified
static List< String > GetListOfComponentAsscFiles()
Gets a list of the associated files in components.
static Boolean AnyModifications()
Indicates whether any of the associated files has been modified.
static Boolean IsDuplicate(String fileName)
Checks that the file is not already saved in the configuration.
Definition: AssocFileMgr.cs:79
static void AddFile(String fileName)
Add an associated file to the collection(i.e. ini files). The file is read and saved as bytes inside ...
Definition: AssocFileMgr.cs:40
This class is used for storing files as part of a configuration. Typically, the files stored are ini ...
The manager class for associated files.
Definition: AssocFileMgr.cs:11