Esempio n. 1
0
        public static XS__RootMetadata Load_fromFile(
            string metadataFilepath_in,
            bool useMetacache_in
            )
        {
            string _key = metadataFilepath_in;

            if (
                useMetacache_in
                &&
                (metacache__ != null)
                &&
                Metacache.Contains(_key)
                )
            {
                return((XS__RootMetadata)XS__RootMetadata.Metacache[_key]);
            }
            else
            {
                XS__RootMetadata _rootmetadata = new XS__RootMetadata(
                    metadataFilepath_in
                    );
                if (useMetacache_in)
                {
                    XS__RootMetadata.Metacache.Add(
                        _key,
                        _rootmetadata
                        );
                }
                return(_rootmetadata);
            }
        }
Esempio n. 2
0
		//#endregion
//		#region public void Open(...);
		public void Open(
			string filename_in, 
			bool force_doNOTsave_in,
			dNotifyBack notifyBack_in
		) {
			#region Checking...
			if (this.hasChanges) {
				if (!force_doNOTsave_in) {
					throw new Exception(string.Format(
						"{0}.{1}.Open(): - must save before open", 
						this.GetType().Namespace, 
						this.GetType().Name
					));
				}
			}
			#endregion
			Filename = filename_in;

			if (notifyBack_in != null) notifyBack_in("opening...", true);
			if (notifyBack_in != null) notifyBack_in("- reading configuration from xml file", true);
			metadata_ = XS__RootMetadata.Load_fromFile(
				Filename,
				false
			);

			#region - reading metadata from business assembly
			string _debug_assembly = Path.Combine(
				ParentDirectoryname,
				businessAssembly(
					metadata_.MetadataExtendedCollection[0].ApplicationName, 
					metadata_.MetadataExtendedCollection[0].ApplicationNamespace, 
					false
				)
			);
			string _release_assembly = Path.Combine(
				ParentDirectoryname,
				businessAssembly(
					metadata_.MetadataExtendedCollection[0].ApplicationName,
					metadata_.MetadataExtendedCollection[0].ApplicationNamespace,
					true
				)
			);
			bool _debug_exits = File.Exists(_debug_assembly);
			bool _release_exits = File.Exists(_release_assembly);
			if (_debug_exits || _release_exits) {
				DateTime _debug_datetime = (_debug_exits) ? File.GetLastWriteTime(_debug_assembly) : DateTime.MinValue;
				DateTime _release_datetime = (_release_exits) ? File.GetLastWriteTime(_release_assembly) : DateTime.MinValue;
				string _assembly 
					= (_debug_datetime > _release_datetime)
						? _debug_assembly
						: _release_assembly;

				if (notifyBack_in != null) notifyBack_in("- reading metadata from business assembly", true);

				OGen.NTier.lib.metadata.metadataBusiness.XS__metadataBusiness _metadatabusiness;
				try {
					_metadatabusiness
						= OGen.NTier.lib.metadata.metadataBusiness.XS__metadataBusiness.Load_fromAssembly(
							_assembly,
							null,
							0
						);
				} catch (Exception _ex) {
					throw new Exception(string.Format(
						"\n---\nfailed to load assembly: {0}\n---\n{1}\n---\n{2}\n---\n{3}\n---", 
						_assembly, 
						_ex.Message, 
						_ex.InnerException,
						_ex.HelpLink
					));
					//_assembly
				}
				_metadatabusiness.ApplicationName = metadata_.MetadataExtendedCollection[0].ApplicationName;

				_metadatabusiness.SaveState_toFile(
					Path.Combine(
						Directoryname,
						string.Format(
							"MD_{0}.OGenXSD-metadataBusiness.xml",
							metadata_.MetadataExtendedCollection[0].ApplicationName
						)
					)
				);

				if (notifyBack_in != null) notifyBack_in("- saving business metadata to xml file", true);
			} else {
				if (notifyBack_in != null) notifyBack_in("- WARNING: no metadata from business assembly to read from", true);
			}
			#endregion

			#region - reading metadata from db
			if (notifyBack_in != null) notifyBack_in("- reading metadata from db", true);
			OGen.NTier.lib.metadata.metadataDB.XS__metadataDB _metadatadb 
				= OGen.NTier.lib.metadata.metadataDB.XS__metadataDB.Load_fromDB(
					null,
					metadata_.MetadataExtendedCollection[0].SubAppName,
					metadata_,
					0,
					metadata_dbconnectionstrings().Convert_toArray()
				);

			// NOTE: this is very important, every parameter / information
			// that's not comming from the database is empty,
			// and needs to be filled in order to be serialized to the xml file:
			_metadatadb.ApplicationName = metadata_.MetadataExtendedCollection[0].ApplicationName;
			for (int ff, tt, t = 0; t < metadata_.MetadataExtendedCollection[0].Tables.TableCollection.Count; t++) {
				for (int f = 0; f < metadata_.MetadataExtendedCollection[0].Tables.TableCollection[t].TableFields.TableFieldCollection.Count; f++) {
					if (metadata_.MetadataExtendedCollection[0].Tables.TableCollection[t].TableFields.TableFieldCollection[f].isViewPK) {
						tt = _metadatadb.Tables.TableCollection.Search(
							metadata_.MetadataExtendedCollection[0].Tables.TableCollection[t].Name,
							!metadata_.MetadataExtendedCollection[0].DBs.Supports_MySQL
						);
						if (tt < 0) continue;

						ff = _metadatadb.Tables.TableCollection[tt].TableFields.TableFieldCollection.Search(
							metadata_.MetadataExtendedCollection[0].Tables.TableCollection[t].TableFields.TableFieldCollection[f].Name,
							!metadata_.MetadataExtendedCollection[0].DBs.Supports_MySQL
						);
						if (ff < 0) continue;

						_metadatadb.Tables.TableCollection[
							tt
						].TableFields.TableFieldCollection[
							ff
						].isPK 
							= true;
					}
				}
			}


			for (int i = 0; i < metadata_.MetadataFiles.MetadataFiles.Count; i++) {
				if (
					metadata_.MetadataFiles.MetadataFiles[i].XMLFileType
					==
					OGen.NTier.lib.metadata.metadataDB.XS__metadataDB.METADATADB
				) {
					if (notifyBack_in != null) notifyBack_in("- saving db metadata to xml file", true);

					//--- BUG: using old db information
					//metadata_.MetadataDBCollection[0].SaveState_toFile(
					//    Path.Combine(
					//        Directoryname,
					//        metadata_.MetadataFiles.MetadataFiles[i].XMLFilename
					//    )
					//);

					//--- DEBUG: using new db information
					_metadatadb.SaveState_toFile(
						Path.Combine(
							Directoryname,
							metadata_.MetadataFiles.MetadataFiles[i].XMLFilename
						)
					);
					break;
				}
			}
			#endregion

			if (notifyBack_in != null) notifyBack_in("- re-reading configuration from xml file", true);
			metadata_ = XS__RootMetadata.Load_fromFile(
				Filename,
				false
			);

			if (notifyBack_in != null) notifyBack_in("... finished", true);
		}
Esempio n. 3
0
		static void Main(string[] args) {
			bool _found = false;
			string _file1 = 
			    System.IO.Path.Combine(
			        #if !NET_1_1
			        System.Configuration.ConfigurationManager.AppSettings
			        #else
			        System.Configuration.ConfigurationSettings.AppSettings
			        #endif
			            ["ogenPath"],

					@"..\..\OGen-NTier_UTs\OGen-metadatas\MD_OGen-NTier_UTs.OGenXSD-metadata.xml"
			    )
			;
			XS__RootMetadata _root = new XS__RootMetadata(
				_file1
			);

			Console.WriteLine(
				"null? '{0}'", 
				(_root.Read_fromRoot(
					"ROOT.metadataExtended[0].tables.table[0].tableSearches.tableSearch[0].name"
				) == null)
			);

			_root.IterateThrough_fromRoot(
				"ROOT.metadataExtended[n].tables.table[n].tableSearches.tableSearch[n].tableSearchUpdates.tableSearchUpdate[n]",
				new OGen.lib.generator.utils.IterationFoundDelegate(notifyme), 
				ref _found
			);
			Console.WriteLine(
				"found? '{0}'",
				_found
			);
			return;









			Console.WriteLine(
				"TableName: '{0}' : '{1}' : '{2}' : '{3}' : '{4}'", 
				_root.Read_fromRoot("ROOT.metadataExtended[0].tables.table[0].name"),
				_root.Read_fromRoot("ROOT.metadataDB[0].tables.table[0].hasPK"), 
				_root.Read_fromRoot("ROOT.metadataDB[0].tables.table[0].parallel_ref.name"), 
				_root.Read_fromRoot("ROOT.metadataDB[0].tables.table[0].hasPK"),
				_root.Read_fromRoot("ROOT.metadataExtended[0].tables.table[0].parallel_ref.hasPK")
			);
			_root.IterateThrough_fromRoot(
				"ROOT.metadataExtended[n].tables.table[n]",
				new OGen.lib.generator.utils.IterationFoundDelegate(notifyme),
				ref _found
			);
			Console.WriteLine((_found) ? "done!\n" : "nothing to do\n");

			Console.WriteLine(
				"SearchName: '{0}'", 
				_root.Read_fromRoot("ROOT.metadataExtended[0].tables.table[0].tableSearches.tableSearch[0].name")
			);
			_root.IterateThrough_fromRoot(
				"ROOT.metadataExtended[n].tables.table[n].tableSearches.tableSearch[n]",
				new OGen.lib.generator.utils.IterationFoundDelegate(notifyme),
				ref _found
			);
			Console.WriteLine((_found) ? "done!\n" : "nothing to do\n");


			Console.WriteLine();
			Console.ReadLine();
			return;

			#region //test1...
			//string _file1 = 
			//    System.IO.Path.Combine(
			//        #if !NET_1_1
			//        System.Configuration.ConfigurationManager.AppSettings
			//        #else
			//        System.Configuration.ConfigurationSettings.AppSettings
			//        #endif
			//            ["ogenPath"],

			//        //@"..\..\OGen-NTier_UTs\OGen-metadatas\MD_OGen-NTier_UTs.OGen-metadata.xml"
			//        @"..\..\OGen-NTier_UTs\OGen-metadatas\xxx_apagar.xml"
			//    )
			//;
			//string _file2 =
			//    System.IO.Path.Combine(
			//        #if !NET_1_1
			//        System.Configuration.ConfigurationManager.AppSettings
			//        #else
			//        System.Configuration.ConfigurationSettings.AppSettings
			//        #endif
			//            ["ogenPath"],

			//        //@"..\..\OGen-NTier_UTs\OGen-metadatas\MD0_OGen-NTier_UTs.OGen-metadata.xml"
			//        @"..\..\OGen-NTier_UTs\OGen-metadatas\xxx0_apagar.xml"
			//    )
			//;
			//DBServerTypes _aux_dbservertype = DBServerTypes.SQLServer;
			//cDBMetadata _aux_metadata;

			//_aux_metadata = new cDBMetadata();
			//#region //testings...
			////_aux_metadata.LoadState_fromDB(
			////    null, 
			////    DBServerTypes.SQLServer,
			////    "server=127.0.0.1;uid=sa;pwd=passpub;database=OGen-NTier_UTs;", 
			////    "", 
			////    true
			////);
			////for (int t = 0; t < _aux_metadata.Tables.Count; t++) {
			////    Console.WriteLine(_aux_metadata.Tables[t].Name);
			////}
			////return;
			//#endregion

			//_aux_metadata.LoadState_fromFile(
			//    _file1
			//);
			//Console.WriteLine("--- {0}", _aux_metadata.ApplicationName);
			//xpto(_aux_metadata);
			//_aux_metadata.SaveState_toFile(
			//    _file2
			//);

			//_aux_metadata = new cDBMetadata();
			//_aux_metadata.LoadState_fromFile(
			//    _file2
			//);
			//xpto(_aux_metadata);
			#endregion
		}
Esempio n. 4
0
		public static XS__RootMetadata Load_fromFile(
			string metadataFilepath_in, 
			bool useMetacache_in
		) {
			string _key = metadataFilepath_in;
			if (
				useMetacache_in
				&&
				(metacache__ != null)
				&&
				Metacache.Contains(_key)
			) {
				return (XS__RootMetadata)XS__RootMetadata.Metacache[_key];
			} else {
				XS__RootMetadata _rootmetadata = new XS__RootMetadata(
					metadataFilepath_in
				);
				if (useMetacache_in) {
					XS__RootMetadata.Metacache.Add(
						_key, 
						_rootmetadata
					);
				}
				return _rootmetadata;
			}
		}