Exemplo n.º 1
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
		}
Exemplo n.º 2
0
 private void WorkBlockStart(Worker sender, Worker.WorkItem item)
 {
     view.SetStatus(string.Format("START! - {0}", item.Name));
 }
Exemplo n.º 3
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
                            );
                    }