Beispiel #1
0
		public static XS__templates[] Load_fromFile(
			params string[] filePath_in
		) {
			FileStream _stream;
			XS__templates[] _output 
				= new XS__templates[filePath_in.Length];

			for (int i = 0; i < filePath_in.Length; i++) {
				_stream = new FileStream(
					filePath_in[i],
					FileMode.Open,
					FileAccess.Read,
					FileShare.Read
				);

				try {
					_output[i] = (XS__templates)new XmlSerializer(typeof(XS__templates)).Deserialize(
						_stream
					);
				} catch (Exception _ex) {
					throw new Exception(string.Format(
						"\n---\n{0}.{1}.Load_fromFile():\nERROR READING XML:\n{2}\n---\n{3}",
						typeof(XS0__templates).Namespace, 
						typeof(XS0__templates).Name, 
						filePath_in[i],
						_ex.Message
					));
				}
				_output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
			}
			return _output;
		}
Beispiel #2
0
        public static XS__templates[] Load_fromFile(
            params string[] filePath_in
            )
        {
            FileStream _stream;

            XS__templates[] _output
                = new XS__templates[filePath_in.Length];

            for (int i = 0; i < filePath_in.Length; i++)
            {
                _stream = new FileStream(
                    filePath_in[i],
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Read
                    );

                try {
                    _output[i] = (XS__templates) new XmlSerializer(typeof(XS__templates)).Deserialize(
                        _stream
                        );
                } catch (Exception _ex) {
                    throw new Exception(string.Format(
                                            "\n---\n{0}.{1}.Load_fromFile():\nERROR READING XML:\n{2}\n---\n{3}",
                                            typeof(XS0__templates).Namespace,
                                            typeof(XS0__templates).Name,
                                            filePath_in[i],
                                            _ex.Message
                                            ));
                }
                _output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
            }
            return(_output);
        }
Beispiel #3
0
        public static XS__templates[] Load_fromURI(
            params Uri[] filePath_in
            )
        {
            XS__templates[] _output
                = new XS__templates[filePath_in.Length];

            for (int i = 0; i < filePath_in.Length; i++)
            {
                if (filePath_in[i].IsFile)
                {
                    _output[i] = XS__templates.Load_fromFile(
                        filePath_in[i].LocalPath
                        )[0];
                    // no need! everything's been taken care at: XS__templates.Load_fromFile(...)
                    //_output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
                }
                else
                {
                    try {
                        _output[i] = (XS__templates) new XmlSerializer(typeof(XS__templates)).Deserialize(
                            OGen.Libraries.PresentationLayer.WebForms.Utilities.ReadURL(
                                filePath_in[i].ToString()
                                )
                            );
                    } catch (Exception _ex) {
                        throw new Exception(string.Format(
                                                System.Globalization.CultureInfo.CurrentCulture,
                                                "\n---\n{0}.{1}.Load_fromURI():\nERROR READING XML:\n{2}\n---\n{3}",
                                                typeof(XS__templates).Namespace,
                                                typeof(XS__templates).Name,
                                                //(filePath_in[i].IsFile)
                                                //	? filePath_in[i].LocalPath
                                                //	:
                                                filePath_in[i].ToString(),
                                                _ex.Message
                                                ));
                    }
                    _output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
                }
            }

            return(_output);
        }
Beispiel #4
0
        public static XS__templates[] Load_fromFile(
            params string[] filePath_in
            )
        {
            FileStream _stream;

            XS__templates[] _output
                = new XS__templates[filePath_in.Length];

            for (int i = 0; i < filePath_in.Length; i++)
            {
                _stream = new FileStream(
                    filePath_in[i],
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Read
                    );

                try {
                    _output[i] = (XS__templates) new XmlSerializer(typeof(XS__templates)).Deserialize(
                        _stream
                        );
                    _stream.Close();
#if !NET_1_1
                    _stream.Dispose();
#endif
                } catch (Exception _ex) {
                    throw new Exception(string.Format(
                                            System.Globalization.CultureInfo.CurrentCulture,
                                            "\n---\n{0}.{1}.Load_fromFile():\nERROR READING XML:\n{2}\n---\n{3}\n---\n{4}\n---\n",
                                            typeof(XS__templates).Namespace,
                                            typeof(XS__templates).Name,
                                            filePath_in[i],
                                            _ex.Message,
                                            _ex.InnerException
                                            ));
                }
                _output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
            }
            return(_output);
        }
Beispiel #5
0
		public static XS__templates[] Load_fromURI(
			params Uri[] filePath_in
		) {
			XS__templates[] _output 
				= new XS__templates[filePath_in.Length];

			for (int i = 0; i < filePath_in.Length; i++) {
				if (filePath_in[i].IsFile) {
					_output[i] = XS__templates.Load_fromFile(
						filePath_in[i].LocalPath
					)[0];
					// no need! everything's been taken care at: XS__templates.Load_fromFile(...)
					//_output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
				} else {
					try {
						_output[i] = (XS__templates)new XmlSerializer(typeof(XS__templates)).Deserialize(
							OGen.lib.presentationlayer.webforms.utils.ReadURL(
								filePath_in[i].ToString()
							)
						);
					} catch (Exception _ex) {
						throw new Exception(string.Format(
							"\n---\n{0}.{1}.Load_fromURI():\nERROR READING XML:\n{2}\n---\n{3}",
							typeof(XS__templates).Namespace, 
							typeof(XS__templates).Name, 
							//(filePath_in[i].IsFile)
							//	? filePath_in[i].LocalPath
							//	: 
							filePath_in[i].ToString(),
							_ex.Message
						));
					}
					_output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
				}
			}

			return _output;
		}
Beispiel #6
0
		public static XS__templates[] Load_fromFile(
			params string[] filePath_in
		) {
			FileStream _stream;
			XS__templates[] _output 
				= new XS__templates[filePath_in.Length];

			for (int i = 0; i < filePath_in.Length; i++) {
				_stream = new FileStream(
					filePath_in[i],
					FileMode.Open,
					FileAccess.Read,
					FileShare.Read
				);

				try {
					_output[i] = (XS__templates)new XmlSerializer(typeof(XS__templates)).Deserialize(
						_stream
					);
					_stream.Close();
#if !NET_1_1
					_stream.Dispose();
#endif
				} catch (Exception _ex) {
					throw new Exception(string.Format(
						System.Globalization.CultureInfo.CurrentCulture,
						"\n---\n{0}.{1}.Load_fromFile():\nERROR READING XML:\n{2}\n---\n{3}\n---\n{4}\n---\n",
						typeof(XS__templates).Namespace, 
						typeof(XS__templates).Name, 
						filePath_in[i],
						_ex.Message,
						_ex.InnerException
					));
				}
				_output[i].root_templates_ = ROOT + "." + TEMPLATES + "[" + i + "]";
			}
			return _output;
		}
		private void build(
			dBuild notifyBack_in, 
//			bool loadMetadata_in, 
			MetadataInterface metadata_in,
			params string[] templateTypes_in
		) {
			notifyback_ = notifyBack_in;
			//notifyback_("- common items", true);

			if (xmltemplatesfileuri_.IsFile) {
				xmltemplatesdir_ = Path.GetDirectoryName(
					xmltemplatesfileuri_.LocalPath
				);
			} else {
				xmltemplatesdir_ = xmltemplatesfileuri_.ToString().Substring(
					0, 
					xmltemplatesfileuri_.ToString().LastIndexOf("/")
				);
			}

			#region dbconnectionstrings_[0..n].Connection_createInstance();
			for (int d = 0; d < dbconnectionstrings_.Count; d++) {
				dbconnectionstrings_[d].Connection_createInstance();
			}
			#endregion

			//metadata_ = new cDBMetadata(xmlmetadatafile_, xmlmetadataroot_);
			metadata_ = metadata_in;
//            if (loadMetadata_in) {
//// ToDos: now! index must be sinchronized, not very convenient :(
//                for (int m = 0; m < metadatas_.Length; m++) {
//                    metadatas_[m].LoadState_fromFile(
//                        //xmlmetadatafile_, 
//                        metafiles_[m].Path, 
//                        //xmlmetadataroot_
//                        metafiles_[m].Root
//                    );
//                }
//            }

			templates_ = (xmltemplatesfileuri_.IsFile)
				? XS__templates.Load_fromFile(xmltemplatesfileuri_.LocalPath)[0]
				: XS__templates.Load_fromURI(xmltemplatesfileuri_)[0]
			;

			bool _finished;
			ArrayList _finishedTemplates = new ArrayList(templates_.TemplateCollection.Count);
			do {
				_finished = true;
				for (template_ = 0; template_ < templates_.TemplateCollection.Count; template_++) {
					#region if (_finishedPreviously = ...) continue;
					bool _finishedPreviously = false;
					for (int f = 0; f < _finishedTemplates.Count; f++) {
						if (
							templates_.TemplateCollection[template_].ID
							==
							(string)_finishedTemplates[f]
						) {
							_finishedPreviously = true;
							break;
						}
					}
					if (_finishedPreviously) continue;
					#endregion
					#region if (!utils.StringArrayContains(templateTypes_in, templates_.TemplateCollection[template_].TemplateType)) continue;
					if (
						(templateTypes_in != null)
						&&
						(templateTypes_in.Length > 0)
						&&
						(templates_.TemplateCollection[template_].TemplateType != "")
						&&
						!utils.StringArrayContains(
							templateTypes_in,
							templates_.TemplateCollection[template_].TemplateType
						)
					) {
						notifyback_(
							string.Format(
								"#{0}/{1} - {2} ",
								_finishedTemplates.Count + 1,
								templates_.TemplateCollection.Count,
								templates_.TemplateCollection[template_].ID
							),
							false
						);

						_finishedTemplates.Add(templates_.TemplateCollection[template_].ID);
						_finished = false;

						notifyback_("... skipping!", true);

						continue;
					}
					#endregion
					#region if ((_finishedDependencies = ...) == templates_[template_].Dependencies.Count) { _finishedTemplates.Add(templates_[template_].ID); _finished = false; }
					#region int _finishedDependencies = ...;
					int _finishedDependencies = 0;
					for (int d = 0; d < templates_.TemplateCollection[template_].Dependencies.DependencyCollection.Count; d++) {
						for (int f = 0; f < _finishedTemplates.Count; f++) {
							if (
								templates_.TemplateCollection[template_].Dependencies.DependencyCollection[d].TemplateID
								==
								(string)_finishedTemplates[f]
							) {
								_finishedDependencies++;
								break;
							}
						}
					}
					#endregion
					if (_finishedDependencies == templates_.TemplateCollection[template_].Dependencies.DependencyCollection.Count) {
						#region RUNNING: templates_[template_] ...

						notifyback_(
							string.Format(
								"#{0}/{1} - {2} ",
								_finishedTemplates.Count + 1,
								templates_.TemplateCollection.Count,
								templates_.TemplateCollection[template_].ID
							),
							false
						);

						bool _valuehasbeenfound_out = false;
						metadata_.IterateThrough_fromRoot(
							templates_.TemplateCollection[template_].IterationType,
							new utils.IterationFoundDelegate(notifyme),
							ref _valuehasbeenfound_out
						);
						#endregion

						// adding template to finished list of templates
						_finishedTemplates.Add(templates_.TemplateCollection[template_].ID);
						_finished = false;

						notifyback_((_valuehasbeenfound_out ? "... DONE!" : "NOT doing!"), true);
					}
					#endregion
				}
			} while (!_finished);
			#region if (templates_.Count != _finishedTemplates.Count) throw new Exception("unsolved dependencies");
			if (templates_.TemplateCollection.Count != _finishedTemplates.Count) {
				string _error = "list of Templates with unsolved dependencies:\n";
				for (int t = 0; t < templates_.TemplateCollection.Count; t++) {
					_finished = false;
					for (int f = 0; f < _finishedTemplates.Count; f++) {
						if ((string)_finishedTemplates[f] == templates_.TemplateCollection[template_].ID) {
							_finished = true;
							break;
						}
					}
					if (!_finished) {
						_error += string.Format(
							"\t{0}\n", 
							templates_.TemplateCollection[template_].ID
						);
					}
				}
				throw new Exception(_error);
			}
			#endregion

			#region dbconnectionstrings_[0..n].Connection_clearInstance();
			for (int d = 0; d < dbconnectionstrings_.Count; d++) {
				dbconnectionstrings_[d].Connection_clearInstance();
			}
			#endregion
		}
Beispiel #8
0
        private void build(
            dBuild notifyBack_in,
//			bool loadMetadata_in,
            MetadataInterface metadata_in
            )
        {
            notifyback_ = notifyBack_in;
            //notifyback_("- common items", true);

            if (xmltemplatesfileuri_.IsFile)
            {
                xmltemplatesdir_ = Path.GetDirectoryName(
                    xmltemplatesfileuri_.LocalPath
                    );
            }
            else
            {
                xmltemplatesdir_ = xmltemplatesfileuri_.ToString().Substring(
                    0,
                    xmltemplatesfileuri_.ToString().LastIndexOf("/")
                    );
            }

            #region dbconnectionstrings_[0..n].Connection_createInstance();
            for (int d = 0; d < dbconnectionstrings_.Count; d++)
            {
                dbconnectionstrings_[d].Connection_createInstance();
            }
            #endregion

            //metadata_ = new cDBMetadata(xmlmetadatafile_, xmlmetadataroot_);
            metadata_ = metadata_in;
//            if (loadMetadata_in) {
//// ToDos: now! index must be sinchronized, not very convenient :(
//                for (int m = 0; m < metadatas_.Length; m++) {
//                    metadatas_[m].LoadState_fromFile(
//                        //xmlmetadatafile_,
//                        metafiles_[m].Path,
//                        //xmlmetadataroot_
//                        metafiles_[m].Root
//                    );
//                }
//            }

            templates_ = (xmltemplatesfileuri_.IsFile)
                                ? XS__templates.Load_fromFile(xmltemplatesfileuri_.LocalPath)[0]
                                : XS__templates.Load_fromURI(xmltemplatesfileuri_)[0]
            ;

            bool      _finished;
            ArrayList _finishedTemplates = new ArrayList(templates_.TemplateCollection.Count);
            do
            {
                _finished = true;
                for (template_ = 0; template_ < templates_.TemplateCollection.Count; template_++)
                {
                    #region if (_finishedPreviously = ...) continue;
                    bool _finishedPreviously = false;
                    for (int f = 0; f < _finishedTemplates.Count; f++)
                    {
                        if (
                            templates_.TemplateCollection[template_].ID
                            ==
                            (string)_finishedTemplates[f]
                            )
                        {
                            _finishedPreviously = true;
                            break;
                        }
                    }
                    if (_finishedPreviously)
                    {
                        continue;
                    }
                    #endregion
                    #region if ((_finishedDependencies = ...) == templates_[template_].Dependencies.Count) { _finishedTemplates.Add(templates_[template_].ID); _finished = false; }
                    #region int _finishedDependencies = ...;
                    int _finishedDependencies = 0;
                    for (int d = 0; d < templates_.TemplateCollection[template_].Dependencies.DependencyCollection.Count; d++)
                    {
                        for (int f = 0; f < _finishedTemplates.Count; f++)
                        {
                            if (
                                templates_.TemplateCollection[template_].Dependencies.DependencyCollection[d].TemplateID
                                ==
                                (string)_finishedTemplates[f]
                                )
                            {
                                _finishedDependencies++;
                                break;
                            }
                        }
                    }
                    #endregion
                    if (_finishedDependencies == templates_.TemplateCollection[template_].Dependencies.DependencyCollection.Count)
                    {
                        #region RUNNING: templates_[template_] ...

                        notifyback_(
                            string.Format(
                                "#{0}/{1} - {2} ",
                                _finishedTemplates.Count + 1,
                                templates_.TemplateCollection.Count,
                                templates_.TemplateCollection[template_].ID
                                ),
                            false
                            );

                        bool _valuehasbeenfound_out = false;
                        metadata_.IterateThrough_fromRoot(
                            templates_.TemplateCollection[template_].IterationType,
                            new utils.IterationFoundDelegate(notifyme),
                            ref _valuehasbeenfound_out
                            );
                        #endregion

                        // adding template to finished list of templates
                        _finishedTemplates.Add(templates_.TemplateCollection[template_].ID);
                        _finished = false;

                        notifyback_((_valuehasbeenfound_out ? "... DONE!" : "nothing"), true);
                    }
                    #endregion
                }
            } while (!_finished);
            #region if (templates_.Count != _finishedTemplates.Count) throw new Exception("unsolved dependencies");
            if (templates_.TemplateCollection.Count != _finishedTemplates.Count)
            {
                string _error = "list of Templates with unsolved dependencies:\n";
                for (int t = 0; t < templates_.TemplateCollection.Count; t++)
                {
                    _finished = false;
                    for (int f = 0; f < _finishedTemplates.Count; f++)
                    {
                        if ((string)_finishedTemplates[f] == templates_.TemplateCollection[template_].ID)
                        {
                            _finished = true;
                            break;
                        }
                    }
                    if (!_finished)
                    {
                        _error += string.Format(
                            "\t{0}\n",
                            templates_.TemplateCollection[template_].ID
                            );
                    }
                }
                throw new Exception(_error);
            }
            #endregion

            #region dbconnectionstrings_[0..n].Connection_clearInstance();
            for (int d = 0; d < dbconnectionstrings_.Count; d++)
            {
                dbconnectionstrings_[d].Connection_clearInstance();
            }
            #endregion
        }
Beispiel #9
0
		private void build(
			OGen.Libraries.Generator.Build notifyBack_in, 
//			bool loadMetadata_in, 
			IMetadata metadata_in,
			Statistics statistics_in,
			params string[] templateTypes_in
		) {
			this.notifyback_ = notifyBack_in;
			//this.notifyback_("- common items", true);

			if (this.xmltemplatesfileuri_.IsFile) {
				this.xmltemplatesdir_ = Path.GetDirectoryName(
					this.xmltemplatesfileuri_.LocalPath
				);
			} else {
				this.xmltemplatesdir_ = this.xmltemplatesfileuri_.ToString().Substring(
					0,
					this.xmltemplatesfileuri_.ToString().LastIndexOf("/", StringComparison.CurrentCulture)
				);
			}

			//this.metadata_ = new cDBMetadata(this.xmlmetadatafile_, this.xmlmetadataroot_);
			this.metadata_ = metadata_in;
//            if (loadMetadata_in) {
//// ToDos: now! index must be sinchronized, not very convenient :(
//                for (int m = 0; m < this.metadatas_.Length; m++) {
//                    this.metadatas_[m].LoadState_fromFile(
//                        //this.xmlmetadatafile_, 
//                        this.metafiles_[m].Path, 
//                        //this.xmlmetadataroot_
//                        this.metafiles_[m].Root
//                    );
//                }
//            }

			this.templates_ = (this.xmltemplatesfileuri_.IsFile)
				? XS__templates.Load_fromFile(this.xmltemplatesfileuri_.LocalPath)[0]
				: XS__templates.Load_fromURI(this.xmltemplatesfileuri_)[0]
			;

			#region int _templateName_MaxLength = ...;
			int _templateName_MaxLength = 0;
			for (int i = 0; i < this.templates_.TemplateCollection.Count; i++) {
				if (this.templates_.TemplateCollection[i].ID.Length > _templateName_MaxLength) {
					_templateName_MaxLength = this.templates_.TemplateCollection[i].ID.Length;
				}
			}
			#endregion

#if NET_1_1
			OGen.Libraries.Worker.WorkItem[] _templatesState
				= new Worker.WorkItem[templates_.TemplateCollection.Count];
#else
			OGen.Libraries.Worker.WorkItem<XS_templateType>[] _templatesState
				= new Worker.WorkItem<XS_templateType>[this.templates_.TemplateCollection.Count];
#endif
			int _threadIterarionCounter = 0;
			object _threadIterarionCounterLocker = new object();
			for (int i = 0; i < this.templates_.TemplateCollection.Count; i++) {

				// must check priorities, hence Waiting, otherwise Ready
				#region WorkItemState _state = (skipping) ? WorkItemState.Done : WorkItemState.Waiting;
				OGen.Libraries.Worker.WorkItemState _state
					= OGen.Libraries.Worker.WorkItemState.Waiting;
				if (
					(templateTypes_in != null)
					&&
					(templateTypes_in.Length > 0)
					&&
					!string.IsNullOrEmpty(this.templates_.TemplateCollection[i].TemplateType)
					&&
					!OGen.Libraries.Utilities.StringArrayContains(
						templateTypes_in,
						this.templates_.TemplateCollection[i].TemplateType
					)
				) {
					string _stepNum = (++_threadIterarionCounter).ToString(System.Globalization.CultureInfo.CurrentCulture);
					string _stepOf = this.templates_.TemplateCollection.Count.ToString(System.Globalization.CultureInfo.CurrentCulture);
					this.notifyback_(
						string.Format(
							System.Globalization.CultureInfo.CurrentCulture,
							"thread 0: {0}#{1}/{2} - {3} {4} skipping!",
							string.Empty.PadLeft(_stepOf.Length - _stepNum.Length, ' '),
							_stepNum,
							_stepOf,
							this.templates_.TemplateCollection[i].ID,

							string.Empty.PadLeft(_templateName_MaxLength - this.templates_.TemplateCollection[i].ID.Length + 3, '.')
						),
						true
					);

					_state = OGen.Libraries.Worker.WorkItemState.Done;
				}
				#endregion

#if NET_1_1
				_templatesState[i] = new OGen.Libraries.Worker.WorkItem(
#else
				_templatesState[i] = new OGen.Libraries.Worker.WorkItem<XS_templateType>(
#endif
					this.templates_.TemplateCollection[i],
					_state
				);
			}

			OGen.Libraries.Worker.Worker _worker = new Worker.Worker();
			int _numthreads = 4;
			WorkerThread[] _workthreads = new WorkerThread[_numthreads];
			for (int t = 0; t < _workthreads.Length; t++) {
				#region DBConnectionstrings _dbconnectionstrings = ...;
				DBConnectionstrings _dbconnectionstrings = new DBConnectionstrings();
				for (int d = 0; d < this.dbconnectionstrings_.Count; d++) {
					_dbconnectionstrings.Add(
						this.dbconnectionstrings_[d].DBServerType,
						this.dbconnectionstrings_[d].Connectionstring
					);
				}
				for (int d = 0; d < _dbconnectionstrings.Count; d++) {
					_dbconnectionstrings[d].Connection_createInstance();
				}
				#endregion

#if DEBUG
				int T = t;
#endif
				System.Threading.Thread _thread = new System.Threading.Thread(delegate() {
#if NET_1_1
					_worker.DoWork(
#else
					_worker.DoWork<XS_templateType>(
#endif
						_templatesState,
						delegate(
#if NET_1_1
							object template_in
#else
							XS_templateType template_in
#endif
						) {
#if NET_1_1
							XS_templateType _template = (XS_templateType)template_in;
#else
							XS_templateType _template = template_in;
#endif

							#region int _finishedDependencies = ...;
							int _finishedDependencies = 0;
							for (int d = 0; d < _template.Dependencies.DependencyCollection.Count; d++) {
								for (int f = 0; f < _templatesState.Length; f++) {
									if (
										_template.Dependencies.DependencyCollection[d].TemplateID
										==
#if NET_1_1
										((XS_templateType)_templatesState[f].Item).ID
#else
										_templatesState[f].Item.ID
#endif
									) {
										if (_templatesState[f].State == Worker.WorkItemState.Done) {
											_finishedDependencies++;
										}
										break;
									}
								}
							}
							#endregion
							return (_finishedDependencies == _template.Dependencies.DependencyCollection.Count);
						},
						delegate(
#if NET_1_1
							object template_in
#else
							XS_templateType template_in
#endif
						) {
#if NET_1_1
							XS_templateType _template = (XS_templateType)template_in;
#else
							XS_templateType _template = template_in;
#endif

#if DEBUG
							long _begin = DateTime.Now.Ticks;
#endif

							#region RUNNING: _template ...

							bool _valuehasbeenfound_out = false;
							this.metadata_.IterateThrough_fromRoot(
								_template.IterationType,
								delegate(string message_in) {
									this.notifyme(
										message_in,
										_template,
										_dbconnectionstrings,
										statistics_in
									);
								},
								ref _valuehasbeenfound_out
							);
							#endregion

							int _threaditerarion;
							lock (_threadIterarionCounterLocker) {
								_threaditerarion = _threadIterarionCounter;

								_threadIterarionCounter = ++_threaditerarion;
							}

#if DEBUG
							_workthreads[T].TotalTicks += DateTime.Now.Ticks - _begin;
							TimeSpan _end = new TimeSpan(DateTime.Now.Ticks - _begin);
#endif
							string _stepNum = _threaditerarion.ToString(System.Globalization.CultureInfo.CurrentCulture);
							string _stepOf = this.templates_.TemplateCollection.Count.ToString(System.Globalization.CultureInfo.CurrentCulture);
							this.notifyback_(
								string.Format(
									System.Globalization.CultureInfo.CurrentCulture,
#if DEBUG
									"thread {6}: {0}#{1}/{2} - {3} {4} {5} ({7}s {8}m)",
#else
									"thread {6}: {0}#{1}/{2} - {3} {4} {5}",
#endif
									string.Empty.PadLeft(_stepOf.Length - _stepNum.Length, ' '),
									_stepNum,
									_stepOf,
#if NET_1_1
									((XS_templateType)template_in).ID,
									"".PadLeft(_templateName_MaxLength - ((XS_templateType)template_in).ID.Length + 3, '.'),
#else
									template_in.ID,
									string.Empty.PadLeft(_templateName_MaxLength - template_in.ID.Length + 3, '.'),
#endif
									(_valuehasbeenfound_out ? "DONE!" : "NOT doing!"),
									System.Threading.Thread.CurrentThread.Name

#if DEBUG
									,
									Convert.ToInt32(_end.TotalSeconds),
									_end.Milliseconds
#endif

								),
								true
							);

						}
					);
				});
				_thread.Name = string.Format(
					System.Globalization.CultureInfo.CurrentCulture, 
					"{0}", 
					t + 1
				);
				_thread.IsBackground = true;
				_workthreads[t] = new WorkerThread(
					_thread,
					_dbconnectionstrings
				);
				_thread.Start();
			}

			for (int t = 0; t < _workthreads.Length; t++) {
				_workthreads[t].Thread.Join();
				#region _workthreads[t].DBConnectionstrings[0..n].Connection_createInstance();
				for (int d = 0; d < _workthreads[t].DBConnectionstrings.Count; d++) {
					_workthreads[t].DBConnectionstrings[d].Connection_clearInstance();
				}
				#endregion
			}

#if DEBUG
			for (int t = 0; t < _workthreads.Length; t++) {
				TimeSpan _span = new TimeSpan(_workthreads[t].TotalTicks);
				Console.WriteLine(
					"thread {0}: work span: {1}s {2}m",
					_workthreads[t].Thread.Name,
					Convert.ToInt32(_span.TotalSeconds),
					_span.Milliseconds
				);
			}
#endif
		}
Beispiel #10
0
        private void build(
            OGen.Libraries.Generator.Build notifyBack_in,
//			bool loadMetadata_in,
            IMetadata metadata_in,
            Statistics statistics_in,
            params string[] templateTypes_in
            )
        {
            this.notifyback_ = notifyBack_in;
            //this.notifyback_("- common items", true);

            if (this.xmltemplatesfileuri_.IsFile)
            {
                this.xmltemplatesdir_ = Path.GetDirectoryName(
                    this.xmltemplatesfileuri_.LocalPath
                    );
            }
            else
            {
                this.xmltemplatesdir_ = this.xmltemplatesfileuri_.ToString().Substring(
                    0,
                    this.xmltemplatesfileuri_.ToString().LastIndexOf("/", StringComparison.CurrentCulture)
                    );
            }

            //this.metadata_ = new cDBMetadata(this.xmlmetadatafile_, this.xmlmetadataroot_);
            this.metadata_ = metadata_in;
//            if (loadMetadata_in) {
//// ToDos: now! index must be sinchronized, not very convenient :(
//                for (int m = 0; m < this.metadatas_.Length; m++) {
//                    this.metadatas_[m].LoadState_fromFile(
//                        //this.xmlmetadatafile_,
//                        this.metafiles_[m].Path,
//                        //this.xmlmetadataroot_
//                        this.metafiles_[m].Root
//                    );
//                }
//            }

            this.templates_ = (this.xmltemplatesfileuri_.IsFile)
                                ? XS__templates.Load_fromFile(this.xmltemplatesfileuri_.LocalPath)[0]
                                : XS__templates.Load_fromURI(this.xmltemplatesfileuri_)[0]
            ;

            #region int _templateName_MaxLength = ...;
            int _templateName_MaxLength = 0;
            for (int i = 0; i < this.templates_.TemplateCollection.Count; i++)
            {
                if (this.templates_.TemplateCollection[i].ID.Length > _templateName_MaxLength)
                {
                    _templateName_MaxLength = this.templates_.TemplateCollection[i].ID.Length;
                }
            }
            #endregion

#if NET_1_1
            OGen.Libraries.Worker.WorkItem[] _templatesState
                = new Worker.WorkItem[templates_.TemplateCollection.Count];
#else
            OGen.Libraries.Worker.WorkItem <XS_templateType>[] _templatesState
                = new Worker.WorkItem <XS_templateType> [this.templates_.TemplateCollection.Count];
#endif
            int    _threadIterarionCounter       = 0;
            object _threadIterarionCounterLocker = new object();
            for (int i = 0; i < this.templates_.TemplateCollection.Count; i++)
            {
                // must check priorities, hence Waiting, otherwise Ready
                #region WorkItemState _state = (skipping) ? WorkItemState.Done : WorkItemState.Waiting;
                OGen.Libraries.Worker.WorkItemState _state
                    = OGen.Libraries.Worker.WorkItemState.Waiting;
                if (
                    (templateTypes_in != null)
                    &&
                    (templateTypes_in.Length > 0)
                    &&
                    !string.IsNullOrEmpty(this.templates_.TemplateCollection[i].TemplateType)
                    &&
                    !OGen.Libraries.Utilities.StringArrayContains(
                        templateTypes_in,
                        this.templates_.TemplateCollection[i].TemplateType
                        )
                    )
                {
                    string _stepNum = (++_threadIterarionCounter).ToString(System.Globalization.CultureInfo.CurrentCulture);
                    string _stepOf  = this.templates_.TemplateCollection.Count.ToString(System.Globalization.CultureInfo.CurrentCulture);
                    this.notifyback_(
                        string.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            "thread 0: {0}#{1}/{2} - {3} {4} skipping!",
                            string.Empty.PadLeft(_stepOf.Length - _stepNum.Length, ' '),
                            _stepNum,
                            _stepOf,
                            this.templates_.TemplateCollection[i].ID,

                            string.Empty.PadLeft(_templateName_MaxLength - this.templates_.TemplateCollection[i].ID.Length + 3, '.')
                            ),
                        true
                        );

                    _state = OGen.Libraries.Worker.WorkItemState.Done;
                }
                #endregion

#if NET_1_1
                _templatesState[i] = new OGen.Libraries.Worker.WorkItem(
#else
                _templatesState[i] = new OGen.Libraries.Worker.WorkItem <XS_templateType>(
#endif
                    this.templates_.TemplateCollection[i],
                    _state
                    );
            }

            OGen.Libraries.Worker.Worker _worker = new Worker.Worker();
            int            _numthreads           = 4;
            WorkerThread[] _workthreads          = new WorkerThread[_numthreads];
            for (int t = 0; t < _workthreads.Length; t++)
            {
                #region DBConnectionstrings _dbconnectionstrings = ...;
                DBConnectionstrings _dbconnectionstrings = new DBConnectionstrings();
                for (int d = 0; d < this.dbconnectionstrings_.Count; d++)
                {
                    _dbconnectionstrings.Add(
                        this.dbconnectionstrings_[d].DBServerType,
                        this.dbconnectionstrings_[d].Connectionstring
                        );
                }
                for (int d = 0; d < _dbconnectionstrings.Count; d++)
                {
                    _dbconnectionstrings[d].Connection_createInstance();
                }
                #endregion

#if DEBUG
                int T = t;
#endif
                System.Threading.Thread _thread = new System.Threading.Thread(delegate() {
#if NET_1_1
                    _worker.DoWork(
#else
                    _worker.DoWork <XS_templateType>(
#endif
                        _templatesState,
                        delegate(
#if NET_1_1
                            object template_in
#else
                            XS_templateType template_in
#endif
                            ) {
#if NET_1_1
                        XS_templateType _template = (XS_templateType)template_in;
#else
                        XS_templateType _template = template_in;
#endif

                        #region int _finishedDependencies = ...;
                        int _finishedDependencies = 0;
                        for (int d = 0; d < _template.Dependencies.DependencyCollection.Count; d++)
                        {
                            for (int f = 0; f < _templatesState.Length; f++)
                            {
                                if (
                                    _template.Dependencies.DependencyCollection[d].TemplateID
                                    ==
#if NET_1_1
                                    ((XS_templateType)_templatesState[f].Item).ID
#else
                                    _templatesState[f].Item.ID
#endif
                                    )
                                {
                                    if (_templatesState[f].State == Worker.WorkItemState.Done)
                                    {
                                        _finishedDependencies++;
                                    }
                                    break;
                                }
                            }
                        }
                        #endregion
                        return(_finishedDependencies == _template.Dependencies.DependencyCollection.Count);
                    },
                        delegate(
#if NET_1_1
                            object template_in
#else
                            XS_templateType template_in
#endif
                            ) {
#if NET_1_1
                        XS_templateType _template = (XS_templateType)template_in;
#else
                        XS_templateType _template = template_in;
#endif

#if DEBUG
                        long _begin = DateTime.Now.Ticks;
#endif

                        #region RUNNING: _template ...

                        bool _valuehasbeenfound_out = false;
                        this.metadata_.IterateThrough_fromRoot(
                            _template.IterationType,
                            delegate(string message_in) {
                            this.notifyme(
                                message_in,
                                _template,
                                _dbconnectionstrings,
                                statistics_in
                                );
                        },
                            ref _valuehasbeenfound_out
                            );
                        #endregion

                        int _threaditerarion;
                        lock (_threadIterarionCounterLocker) {
                            _threaditerarion = _threadIterarionCounter;

                            _threadIterarionCounter = ++_threaditerarion;
                        }

#if DEBUG
                        _workthreads[T].TotalTicks += DateTime.Now.Ticks - _begin;
                        TimeSpan _end = new TimeSpan(DateTime.Now.Ticks - _begin);
#endif
                        string _stepNum = _threaditerarion.ToString(System.Globalization.CultureInfo.CurrentCulture);
                        string _stepOf = this.templates_.TemplateCollection.Count.ToString(System.Globalization.CultureInfo.CurrentCulture);
                        this.notifyback_(
                            string.Format(
                                System.Globalization.CultureInfo.CurrentCulture,
#if DEBUG
                                "thread {6}: {0}#{1}/{2} - {3} {4} {5} ({7}s {8}m)",
#else
                                "thread {6}: {0}#{1}/{2} - {3} {4} {5}",
#endif
                                string.Empty.PadLeft(_stepOf.Length - _stepNum.Length, ' '),
                                _stepNum,
                                _stepOf,
#if NET_1_1
                                ((XS_templateType)template_in).ID,
                                "".PadLeft(_templateName_MaxLength - ((XS_templateType)template_in).ID.Length + 3, '.'),
#else
                                template_in.ID,
                                string.Empty.PadLeft(_templateName_MaxLength - template_in.ID.Length + 3, '.'),
#endif
                                (_valuehasbeenfound_out ? "DONE!" : "NOT doing!"),
                                System.Threading.Thread.CurrentThread.Name

#if DEBUG
                                ,
                                Convert.ToInt32(_end.TotalSeconds),
                                _end.Milliseconds
#endif

                                ),
                            true
                            );
                    }