Пример #1
0
		private static Plus2 CreatePlus2Object(string fileName) {
			Plus2 result = new Plus2();

			result.Name = fileName.Split('.')[1];
			Console.WriteLine("plus2 name is " + result.Name);

			result.ModuleName = Path.ChangeExtension(fileName, null);
			Console.WriteLine("plus2 module is " + result.ModuleName);

			ArrayList features = new ArrayList();

			foreach (string line in GetLines(fileName)) {
				//creates feature objects.
				string[] properties = line.Split(';');
				if (properties.Length == 2) { // valid plus I lines
					Feature2 feature = new Feature2();
					feature.Name = properties[0];
					feature.Description = "nohint";

					ArrayList records = new ArrayList();
                    //for BDS 1-4 versions
					for (int i = 1; i < 5; i++) {
						EnabledRecord record = new EnabledRecord();
						record.Version = i;
						record.Enabled = Convert.ToBoolean(properties[1]);

						records.Add(record);
                    }
					feature.EnabledRecords = (EnabledRecord[]) records.ToArray(typeof(EnabledRecord));

					features.Add(feature);
				}
			}
			result.Features = (Feature2[]) features.ToArray(typeof(Feature2));

			return result;
		}
Пример #2
0
		/// <summary>
		/// Loads a Plus2 object from file.
		/// </summary>
		/// <param name="fileName">File name</param>
		/// <returns></returns>
//		public static Plus2 Load(string fileName ) {
//			Debug.Indent();
//			Debug.WriteLine("--> Enter PlusArrayList.LoadPlus2");
//
//			Plus2 result = null;
//
//			if (BeWise.Common.Utils.Utils.FileIsValid(fileName)) {
//				XmlSerializer _Serializer = new XmlSerializer(typeof(Plus2));
//				FileStream _FileStream = null;
//				XmlReader _Reader = null;
//				try {
//					try {
//						_FileStream = File.OpenRead(fileName);
//					}
//					catch (DirectoryNotFoundException) {
//						// no such directory
//						Debug.WriteLine("no such directory");
//						//OTAUtils.AddMessage("No such directory");
//					}
//					catch (FileNotFoundException) {
//						// cannot find the file
//						Debug.WriteLine("no file");
//						//OTAUtils.AddMessage("Cannot find the file");
//					}
//					catch (ArgumentException) {
//						Debug.WriteLine("invalid file name.");
//					}
//					finally {
//
//						_Reader = new XmlTextReader(_FileStream);
//
//						if (_FileStream != null) {
//							result = (Plus2) _Serializer.Deserialize(_Reader);
//						}
//						else {
//							Debug.WriteLine("null file stream");
//						}
//					}
//				}
//				catch (XmlException) {
//					//OTAUtils.AddMessage("Cannot read the plus2 file.");
//				} catch (InvalidOperationException) {
//					Console.WriteLine("deserialization fails");
//				}
//				finally {
//					if (_Reader != null) {
//						_Reader.Close();
//					}
//					else {
//						Debug.WriteLine("null reader");
//					}
//				}
//			}
//			else {
//				Debug.WriteLine("invalid plus2 file");
//			}
//			Debug.WriteLine("<-- Leave PlusArrayList.LoadPlus2");
//			Debug.Unindent();
//			return result;
//		}
		/// <summary>
		/// Saves a Plus2 object to file.
		/// </summary>
		/// <param name="fileName">File name</param>
		/// <param name="plus2">Object</param>
		public static void Save( string fileName, Plus2 plus2 ) {
            Debug.Indent();
			Debug.WriteLine("--> Enter PlusArrayList.SavePlus2");

			XmlSerializer _Serializer = new XmlSerializer(typeof(Plus2));
            Stream _FileStream = null;
            XmlTextWriter _Writer = null;
            
            try {
				_FileStream = new FileStream(fileName, FileMode.Create);

            }
            catch (DirectoryNotFoundException) {
                Debug.WriteLine("no such directory");
                // no such directory
                //OTAUtils.AddMessage("No such directory");
            }
			catch (ArgumentException) {
            	Debug.WriteLine("invalid file name");
			}
            finally {
                _Writer = new XmlTextWriter(_FileStream, new UTF8Encoding());
                _Writer.Formatting = Formatting.Indented;
                
                if (_FileStream != null) {
					// Serialize using the XmlTextWriter.
					Console.WriteLine(plus2);
					_Serializer.Serialize(_Writer, plus2);
                }
                else {
                    Debug.WriteLine("null file stream");
                }
                _Writer.Close();
            }
            Debug.WriteLine("<-- Leave PlusArrayList.SavePlus2");
            Debug.Unindent();
        }