public TaskInfo(Task.Task task, DateTime time, Worker.Worker person, Option someoption) { ResolvedTask = task; LastEditTime = time; Person = person; Something = someoption; }
public Client.Client LookForClients(string name, string wname, ref Client.Client[] c, ref Credit.Credit[] credits, ref Bank.Bank bank, ref Worker.Worker[] worker, int cw) { Client.Client cl = null; Worker.Worker wr = null; for (int i = 0; i < c.Length; i++) { if (c[i].Name == name) { cl = c[i]; break; } } wr = LookForWorkers(wname, ref worker, 0); if (cl == null || wr == null) { throw new Exception("Invalid worker name or client name"); } else { if (cw == 1) { ClientPart(ref cl, ref credits, ref bank, ref wr); } else { return(cl); } } return(null); }
public void WorkerPart(ref Worker.Worker w) { Console.Clear(); Console.WriteLine("1) for operations"); Console.WriteLine("2) for your information"); bool IsInt = int.TryParse(Console.ReadLine(), out int choose); if (IsInt) { if (choose == 1) { Console.Clear(); if (w.Operations != null) { for (int i = 0; i < w.OperationCount; i++) { w.Operations[i].Print(); Thread.Sleep(3000); } } } else if (choose == 2) { Console.Clear(); w.Print(); } } else { throw new Exception("Invalid type!"); } }
public MainWindow() { InitializeComponent(); inputFilePath.Text = System.IO.Path.Combine(Environment.CurrentDirectory, "Data.txt"); worker = new Worker.Worker(); }
public void addWorker(Worker.Worker resource) { Worker.Worker[] temp = new Worker.Worker[++WorkerCount]; if (Workers != null) { Workers.CopyTo(temp, 0); } temp[temp.Length - 1] = resource; Workers = temp; }
static async Task Main(string[] args) { var worker = new Worker.Worker("Data.txt"); int number = 0; await foreach (float res in worker.ReadFile()) { Console.WriteLine($"{number++}: {res}"); } Console.WriteLine("Hello World!"); }
public void run() { while (true) { server.Start(3); GUI.show("Waiting for Client..."); TcpClient client = server.AcceptTcpClient(); GUI.show("Connected with a client " + ((IPEndPoint)client.Client.RemoteEndPoint).Port.ToString()); Worker.Worker worker = new Worker.Worker(client); Thread th = new Thread(new ThreadStart(worker.takeClient)); th.Start(); } }
public void AddWorker(string id, string name, PublishCalculateCompleted calculateCallback) { lock (_workList) { if (!_workList.ContainsKey(id)) { IWorker work = new Worker.Worker(id, name); work.PublishCalculateCompleted += calculateCallback; _workList.TryAdd(id, work); } else { IWorker worker; if (_workList.TryGetValue(id, out worker)) { worker.Name = name; } } } }
public void HireWorker(Worker.Worker worker) { this._playerState.Workers.Add(worker); }
public SprintReport(Worker.Worker teamlead, List <Worker.Worker> team) { Teamlead = teamlead; Team = team; }
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 }
public DailyReport(Worker.Worker worker) { Worker = worker; }
protected void CommitChanges(Task.Task task, Worker.Worker worker) { task.Log.Add((worker, this)); }
public void ClientPart(ref Client.Client cl, ref Credit.Credit[] credits, ref Bank.Bank bank, ref Worker.Worker w) { Console.Clear(); Console.WriteLine("1) For look your credit(s)"); Console.WriteLine("2) For add new credit"); Console.WriteLine("3) For convert money to dollar"); bool IsInt = int.TryParse(Console.ReadLine(), out int choose); if (IsInt) { if (choose == 1) { Console.Clear(); foreach (var item in credits) { if (item.TheClient.Name == cl.Name) { item.Print(); } } Thread.Sleep(3000); Console.Clear(); } else if (choose == 2) { Console.Clear(); Console.Write("Enter amonut: "); decimal amount = Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("Enter month: "); int month = Convert.ToInt32(Console.ReadLine()); w.addOperation(new Operation.Operation(Guid.NewGuid(), $"New credit was added in {cl.Name} account", DateTime.Now)); Credit.Credit[] cre = new Credit.Credit[credits.Length + 1]; for (int i = 0; i < credits.Length; i++) { cre[i] = credits[i]; } cre[cre.Length - 1] = new Credit.Credit(Guid.NewGuid(), cl, amount, month); credits = cre; } else if (choose == 3) { Console.Clear(); Console.Write("Write amount: "); bool isD = decimal.TryParse(Console.ReadLine(), out decimal res); if (isD) { decimal dess = res * (17 / 10); cl.Salary += res; cl.Salary -= dess; bank.Budget += dess * (17 / 10) - dess * (171 / 10); bank.ProfitCalculating(); } } } else { throw new Exception("Invalid type!"); } }
public void Starter() { Worker.Worker w1 = new Worker.Worker(Guid.NewGuid(), "Hakuna", "", 35, "Cart operations", 2123); Worker.Worker w2 = new Worker.Worker(Guid.NewGuid(), "Sun", "", 26, "Cart operations", 221); Worker.Worker w3 = new Worker.Worker(Guid.NewGuid(), "Moon", "", 37, "Cart operations", 1233); Worker.Worker w4 = new Worker.Worker(Guid.NewGuid(), "Sky", "", 40, "Cart operations", 223); w1.addOperation(new Operation.Operation(Guid.NewGuid(), "Cart Added", DateTime.Now)); Worker.Worker[] workers = new Worker.Worker[4] { w1, w2, w3, w4 }; Manager.Manager m1 = new Manager.Manager(Guid.NewGuid(), "Matata", "", 46, "Main Manager", 98123); m1.addWorker(w1); m1.addWorker(w2); m1.addWorker(w3); m1.addWorker(w4); Manager.Manager m2 = new Manager.Manager(Guid.NewGuid(), "Glass", "", 19, "Manager", 2721); m2.addWorker(w1); m2.addWorker(w2); Manager.Manager m3 = new Manager.Manager(Guid.NewGuid(), "Light", "", 29, "Manager", 12671); m3.addWorker(w3); m3.addWorker(w4); Manager.Manager m4 = new Manager.Manager(Guid.NewGuid(), "Blue", "", 41, "Manager", 82342); m4.addWorker(w1); m4.addWorker(w3); Manager.Manager[] managers = new Manager.Manager[4] { m1, m2, m3, m4 }; Client.Client c1 = new Client.Client(Guid.NewGuid(), "Matatata", "Nana", 22, 34324, "X street,New York", "Y street, New Jersey"); Client.Client c2 = new Client.Client(Guid.NewGuid(), "Last", "Glass", 56, 1434, "I don't work", "Y street, Vegas"); Client.Client[] clients = new Client.Client[2] { c1, c2 }; Ceo.Ceo ceo = new Ceo.Ceo(Guid.NewGuid(), "Hakuna", "", 35, "Ceo", 100000); ceo.addWorker(w1); ceo.addWorker(w2); ceo.addWorker(w3); ceo.addWorker(w4); ceo.addManager(m1); ceo.addManager(m2); ceo.addManager(m3); ceo.addManager(m4); Credit.Credit cr1 = new Credit.Credit(Guid.NewGuid(), c1, 20013, 6); Credit.Credit cr3 = new Credit.Credit(Guid.NewGuid(), c1, 142, 2); Credit.Credit cr2 = new Credit.Credit(Guid.NewGuid(), c2, 41500, 3); m1.Ceo = ceo; m2.Ceo = ceo; m3.Ceo = ceo; m4.Ceo = ceo; Bank.Bank bank = new Bank.Bank("Time bank", 10000000, ceo); Credit.Credit[] credits = new Credit.Credit[3] { cr1, cr2, cr3 }; while (true) { try { Console.Clear(); Console.WriteLine("1) Ceo"); Console.WriteLine("2) Worker"); Console.WriteLine("3) Manager"); Console.WriteLine("4) Client"); Console.WriteLine("5) Bank"); Choose(Console.ReadLine(), ref ceo, ref workers, ref managers, ref clients, ref credits, bank); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
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 ); }
public abstract void Set(Task.Task task, Worker.Worker worker);