public void Run()
 {
     try
     {
         Reset();
         var errors = graph.Validate();
         if (errors.Count > 0)
         {
             throw new FLowNetworkValidationException(errors);
         }
         if (graph == null)
         {
             throw new InvalidConfigurationException("Can't run algorithm without graph.");
         }
         OnBeforeInit?.Invoke(this);
         Init();
         OnAfterInit?.Invoke(this);
         var timer = new Stopwatch();
         OnStart?.Invoke(this);
         timer.Start();
         Logic();
         timer.Stop();
         Elapsed = timer.Elapsed;
         Log.Write($"Algorithm {Name}. Max flow: {MaxFlow}. From: {graph.Source}, To: {graph.Target}, Time: {Elapsed}. Ticks: {Ticks}");
         OnFinish?.Invoke(this);
     }
     catch (Exception e)
     {
         Log.Write(e.Message, Log.ERROR);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Run experiment, before that calls Inicialization() method and after all replikations call AfterExperiment() method and invoke OnFinish event
        /// </summary>
        /// <returns></returns>
        public Task RunExperiment()
        {
            return(Task.Run(() =>
            {
                Inicialization();
                PartialResultData experimentResult = default(PartialResultData);
                for (long i = 1; i <= Replications; i++)
                {
                    mutex.WaitOne();

                    if (cancel)
                    {
                        return;
                    }

                    experimentResult = Experiment(i);

                    if (ResultIntervalCondition(i))
                    {
                        OnNewPartialResult?.Invoke(i, experimentResult);
                    }
                }
                OnNewPartialResult?.Invoke(Replications, experimentResult);
                OnFinish?.Invoke(AfterExperiment());
            }));
        }
Esempio n. 3
0
 private void OnContinue(object sender, EventArgs e)
 {
     if (currentStep == 1)
     {
         bool valid = UIUtils.ValidateEntriesWithEmpty(new Entry[] { emailEntry, pswdEntry, firstNameEntry, lastNameEntry, phoneNumberEntry }, this.page);
         if (!valid)
         {
             return;
         }
         BuildStep2();
         DataGate.VerifyPhoneNumber(phoneNumberEntry.Text, (res) =>
         {
             if (res.Code == ResponseCode.OK)
             {
                 currentCode = res.Result.Trim('"');
                 //TODO: temp
                 Device.BeginInvokeOnMainThread(() =>
                 {
                     codeEntry.Text = currentCode;
                 });
             }
         });
     }
     else
     {
         if (codeEntry.Text != currentCode)
         {
             UIUtils.ShowMessage("Confirmation code is not valid", this.page);
             return;
         }
         var sendData = new Dictionary <string, object>()
         {
             { "Email", emailEntry.Text },
             { "FbId", null },
             { "FirstName", firstNameEntry.Text },
             { "LastName", lastNameEntry.Text },
             { "Password", Ext.MD5.GetMd5String(pswdEntry.Text) },
             { "Phone", phoneNumberEntry.Text }
         };
         spinner = UIUtils.ShowSpinner((ContentPage)this.page);
         DataGate.CustomerSignupJson(sendData, (data) =>
         {
             var jobj = JObject.Parse(data.Result);
             Device.BeginInvokeOnMainThread(() =>
             {
                 if (data.Code == ResponseCode.OK && jobj["Id"] != null)
                 {
                     GlobalStorage.Settings.CustomerId = (string)jobj["Id"];
                     GlobalStorage.SaveAppSettings();
                 }
                 else
                 {
                     UIUtils.ShowMessage("Signup faled. Try later", this.page);
                 }
                 UIUtils.HideSpinner((ContentPage)this.page, spinner);
                 OnFinish?.Invoke(this, data);
             });
         });
     }
 }
Esempio n. 4
0
        public async void Copy(List <Item> items, string destination)
        {
            foreach (var item in items)
            {
                switch (item)
                {
                case DirectoryItem _:
                    Directory.CreateDirectory(Path.Combine(destination, item.Name));
                    Copy(new DirectoryItem(item.FullName).Subs, Path.Combine(destination, item.Name));
                    break;

                case FileItem _:
                    var progress = new Progress <double>(d =>
                    {
                        CurrentItemProgressBar.Value = d;
                        CurrentItemProgressText.Text = $"{CURRFILE} {item.Name} {d:f2}%";
                    });
                    await item.Copy(progress, destination);

                    break;
                }
            }

            CurrentItemProgressText.Text = "Finished copying";
            OnFinish?.Invoke(this, null);
        }
Esempio n. 5
0
File: Pole.cs Progetto: rela589n/x0
        void Control() //перевірка, чи раптом хтось не виграв. Якщо виграв
                       //- генерується подія OnFinish і передається символ-переможець
        {
            if (P[0, 0].IsCross && P[0, 1].IsCross && P[0, 2].IsCross || P[1, 0].IsCross && P[1, 1].IsCross && P[1, 2].IsCross || P[2, 0].IsCross && P[2, 1].IsCross && P[2, 2].IsCross || P[0, 0].IsCross && P[1, 0].IsCross && P[2, 0].IsCross || P[0, 1].IsCross && P[1, 1].IsCross && P[2, 1].IsCross || P[0, 2].IsCross && P[1, 2].IsCross && P[2, 2].IsCross || P[0, 0].IsCross && P[1, 1].IsCross && P[2, 2].IsCross || P[0, 2].IsCross && P[1, 1].IsCross && P[2, 0].IsCross)
            {
                active = false;
                OnFinish?.Invoke('X');
            }
            else if (P[0, 0].IsZero && P[0, 1].IsZero && P[0, 2].IsZero || P[1, 0].IsZero && P[1, 1].IsZero && P[1, 2].IsZero || P[2, 0].IsZero && P[2, 1].IsZero && P[2, 2].IsZero || P[0, 0].IsZero && P[1, 0].IsZero && P[2, 0].IsZero || P[0, 1].IsZero && P[1, 1].IsZero && P[2, 1].IsZero || P[0, 2].IsZero && P[1, 2].IsZero && P[2, 2].IsZero || P[0, 0].IsZero && P[1, 1].IsZero && P[2, 2].IsZero || P[0, 2].IsZero && P[1, 1].IsZero && P[2, 0].IsZero)
            {
                active = false;
                OnFinish?.Invoke('O');
            }
            else
            {
                for (int i = 0; i <= 2; ++i)
                {
                    for (int j = 0; j <= 2; ++j)
                    {
                        if (P[i, j].IsClear)
                        {
                            return;
                        }
                    }
                }

                active = false;
                OnFinish?.Invoke('N');
            }
        }
Esempio n. 6
0
    private IEnumerator Write(VertexHelper vh)
    {
        IsWorking = true;

        _canWait = true;
        HideLetters(vh);
        var waitforLetter = new WaitForSeconds(this._waitBetweenLetters);
        var lenght        = original.Count / 6;

        for (var i = 0; i < lenght; ++i)
        {
            for (var j = 0; j < 6; ++j)
            {
                var index  = (i * 6) + j;
                var tmpVer = modified[index];
                tmpVer.position = original[index].position;
                modified[index] = tmpVer;
            }
            vh.AddUIVertexTriangleStream(modified);
            vh.FillMesh(_mesh);
            _canvasRendered.SetMesh(_mesh);
            if (_canWait)
            {
                yield return(waitforLetter);
            }
        }
        IsWorking = false;
        if (OnFinish != null)
        {
            OnFinish.Invoke( );
        }
        yield return(null);
    }
Esempio n. 7
0
        public override void Invoke(CancellationToken token)
        {
            OnBegin?.Invoke();
            var box = new List <List <TItem> > {
                new List <TItem>()
            };
            var idx = 0;

            foreach (var item in Sources.GetConsumingEnumerable())
            {
                token.ThrowIfCancellationRequested();
                OnInterval?.Invoke(item);

                box[idx].Add(item);
                if (box[idx].Count != Size)
                {
                    continue;
                }

                Results.Add(box[idx].ToArray(), token);
                idx++;
                box.Add(new List <TItem>());
            }

            if (box[idx].Any())
            {
                Results.Add(box[idx].ToArray(), token);
            }
            Results.CompleteAdding();
            OnFinish?.Invoke();
        }
Esempio n. 8
0
 public bool Finish()
 {
     lock (Sync)
     {
         if (State == ParseState.Dormant)
         {
             return(false);
         }
         State = ParseState.Dormant;
         if (IsTransforming)
         {
             if (IsTransformFinishable && !(Transform as IFinishable).Finish())
             {
                 return(false);
             }
             if (Transform.BufferedReadable > 0 && !HandleReadable(Transform.Read()))
             {
                 return(false);
             }
         }
         Transform         = null;
         Malformed         = false;
         IsTransforming    = IsTransformFinishable = false;
         ChunkLengthString = null;
         ChunkIndex        = ChunkLength = 0;
         OnFinish?.Invoke();
         return(true);
     }
 }
Esempio n. 9
0
 public void DoFinish()
 {
     if (OnFinish != null)
     {
         OnFinish.Invoke();
     }
 }
Esempio n. 10
0
 public bool Finish()
 {
     lock (Sync)
     {
         if (Finished)
         {
             return(false);
         }
         if (IsTransforming)
         {
             if (IsTransformFinishable && !(Transform as IFinishable).Finish())
             {
                 return(false);
             }
             if (Transform.BufferedReadable > 0 && !WriteChunk(Transform.Read()))
             {
                 return(false);
             }
         }
         if (!WriteLast())
         {
             return(false);
         }
         Transform             = null;
         IsTransforming        = false;
         IsTransformFinishable = false;
         Finished      = true;
         Type          = null;
         CurrentLength = CurrentEncodedLength = 0;
         OnFinish?.Invoke();
         return(true);
     }
 }
Esempio n. 11
0
        // Update is called once per frame
        void Update()
        {
            if (!isStart)
            {
                return;
            }

            blackStartTime += Time.deltaTime * speed;

            if (blackStartTime > 1)
            {
                this.SetSolid(isFadeIn);
                isStart = false;
                OnFinish?.Invoke();
            }
            else
            {
                float lerp;
                if (isFadeIn)
                {
                    lerp = Mathf.Lerp(0, 1, blackStartTime > 1 ? 1 : blackStartTime);
                }
                else
                {
                    lerp = Mathf.Lerp(1, 0, blackStartTime > 1 ? 1 : blackStartTime);
                }
                image.color = new Color(image.color.r, image.color.g, image.color.b, lerp);
            }
        }
Esempio n. 12
0
 internal void Finished()
 {
     if (OnFinish != null)
     {
         OnFinish.Invoke(this);
     }
 }
Esempio n. 13
0
        public void OnBlockUpdated(CharacterBlock block)
        {
            if (finished)
            {
                return;
            }

            if (IsFilled())
            {
                finished = TryConfirm();
                if (finished)
                {
                    onFinish.Invoke(this);
                }
            }
            else if (this == MainWindow.selectedWord)
            {
                int currentIndex = Array.FindIndex(blocks, p => p == block) + 1;

                if (blocks.Length > currentIndex)
                {
                    blocks[currentIndex].Focus();
                }
            }
        }
Esempio n. 14
0
        public void Giveup(string giveupTip)
        {
            if (state != TOMATO_PLANT_STATE.Growing &&
                state != TOMATO_PLANT_STATE.Pause &&
                state < TOMATO_PLANT_STATE.Reaped)
            {
                throw new Exception("TomatoPlant giveup fail, state is " + state);
            }
            if (state < TOMATO_PLANT_STATE.Reaped)
            {
                state = TOMATO_PLANT_STATE.Giveup;
                OnGiveup?.Invoke(this);
            }
            else
            {
                state = TOMATO_PLANT_STATE.Finish;
                OnFinish?.Invoke(this);
            }

            TomatoMgr.OnTimeLoseSecond -= TimeLoseSecond;

            if (string.IsNullOrEmpty(giveupTip))
            {
                throw new Exception("TomatoPlant giveup unexpect, giveupTip is empty");
            }
            giveupRecord = giveupTip;
        }
Esempio n. 15
0
        public void Uninstall()
        {
            Console.WriteLine("Starting uninstall");
            OnStart?.Invoke();
            try {
                // Sneaky step: Remove URI handler.
                if (!string.IsNullOrEmpty(Info.ModURIProtocol) &&
                    !string.IsNullOrEmpty(Info.ModsDir))
                {
                    try {
                        RegistryKey regClasses = Registry
                                                 .CurrentUser
                                                 ?.OpenSubKey("Software", true)
                                                 ?.OpenSubKey("Classes", true);
                        regClasses?.DeleteSubKey(Info.ModURIProtocol, false);
                    } catch {
                    }
                }

                _Restore();
            } catch (Exception e) {
                Console.WriteLine(e);
                Console.WriteLine("Error! Please check installer-log.txt");
                OnError?.Invoke(e);
                if (Debugger.IsAttached)
                {
                    throw;
                }
                return;
            }
            Console.WriteLine("Finished uninstalling!");
            OnFinish?.Invoke();
        }
 void Update()
 {
     if (AttachedPlayer && AttachedPlayer.InputDevice.GetButtonDown(MappedButton.Special) && AttachedPlayer.CharacterType == TargetType)
     {
         OnFinish.Invoke();
     }
 }
Esempio n. 17
0
        public override void Invoke(CancellationToken token)
        {
            OnBegin?.Invoke();

            var tasks = new List <Task>();

            for (var i = 0; i < Workers; i++)
            {
                tasks.Add(Task.Factory.StartNew(() => {
                    foreach (var source in Sources.GetConsumingEnumerable())
                    {
                        token.ThrowIfCancellationRequested();

                        foreach (var result in filter(source))
                        {
                            Results.Add(result, token);
                            OnInnerInterval?.Invoke(result);
                        }

                        OnInterval?.Invoke(source);
                    }
                }, token));
            }

            Task.WaitAll(tasks.ToArray());

            Results.CompleteAdding();
            OnFinish?.Invoke();
        }
Esempio n. 18
0
 /// <summary>
 /// The Finish
 /// </summary>
 public void Finish()
 {
     OnRefresh?.Invoke();
     Stats.Finish();
     State = new FinishedState();
     OnFinish?.Invoke();
 }
Esempio n. 19
0
        public void Start()
        {
#if !DEBUG
            var freeSpaceDownload = (long)Util.GetDiskFreeSpace(_patchStore.Root.FullName);

            if (Downloads.Any(x => x.Patch.Length > freeSpaceDownload))
            {
                OnFinish?.Invoke(this, false);

                MessageBox.Show(string.Format(Loc.Localize("FreeSpaceError", "There is not enough space on your drive to download patches.\n\nYou can change the location patches are downloaded to in the settings.\n\nRequired:{0}\nFree:{1}"), Util.BytesToString(Downloads.OrderByDescending(x => x.Patch.Length).First().Patch.Length), Util.BytesToString(freeSpaceDownload)), "XIVLauncher Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var freeSpaceGame = (long)Util.GetDiskFreeSpace(_gamePath.Root.FullName);

            if (freeSpaceGame < AllDownloadsLength)
            {
                OnFinish?.Invoke(this, false);

                MessageBox.Show(string.Format(Loc.Localize("FreeSpaceGameError", "There is not enough space on your drive to install patches.\n\nYou can change the location the game is installed to in the settings.\n\nRequired:{0}\nFree:{1}"), Util.BytesToString(AllDownloadsLength), Util.BytesToString(freeSpaceGame)), "XIVLauncher Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
#endif

            _installer.StartIfNeeded();
            _installer.WaitOnHello();

            Task.Run(RunDownloadQueue, _cancelTokenSource.Token);
            Task.Run(RunApplyQueue, _cancelTokenSource.Token);
        }
Esempio n. 20
0
 public virtual bool Finish()
 {
     lock (Sync)
     {
         OnFinish?.Invoke();
         return(Finished = true);
     }
 }
Esempio n. 21
0
 private void FinishForm()
 {
     if (!_isOk)
     {
         OnFinish?.Invoke();
     }
     Close();
 }
Esempio n. 22
0
        private IEnumerator Process()
        {
            yield return(_routine.Invoke());

            _coroutine = null;

            OnFinish?.Invoke();
        }
        ///<summary>
        /// Called internally when the dialogue box has finished
        ///</summary>
        private void EndDialogue()
        {
            //Close the box
            animator.SetBool("IsOpen", false);

            OnFinish?.Invoke();
            OnFinish = null;
        }
Esempio n. 24
0
 public virtual void Update()
 {
     if (Finished)
     {
         State = AnimationState.Finished;
         OnFinish?.Invoke();
     }
 }
Esempio n. 25
0
 /**<summary> Game is finished, win or lose </summary>*/
 public void Finish(bool win)
 {
     if (finished)
     {
         return;
     }
     finished = true;
     OnFinish?.Invoke(win);
 }
Esempio n. 26
0
        public void Finish(T finishRestult)
        {
            if (!started)
            {
                return;
            }

            OnFinish?.Invoke(finishRestult);
        }
 public void OrderCancelled(CrossBot routine, string msg, bool faulted)
 {
     OnFinish?.Invoke(routine);
     Trader.SendMessageAsync($"Oops! Something has happened with your order: {msg}");
     if (!faulted)
     {
         CommandSentChannel.SendMessageAsync($"{Trader.Mention} - Your order has been cancelled: {msg}");
     }
 }
Esempio n. 28
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (_count == 0)
                {
                    _count       = 1;
                    _button.Text = _stateText;

                    _button.BackColor = Color.Lime;
                    Application.DoEvents();
                }
                else
                {
                    if (_count == 1)
                    {
                        _count = 2;

                        _button.Text = "  " + _stateText;
                        Application.DoEvents();
                    }
                    else
                    {
                        if (_count == 2)
                        {
                            _count = 3;

                            _button.Text = _stateText + "  ";
                            Application.DoEvents();
                        }
                        else
                        {
                            _timer.Enabled = false;
                            _count         = 0;

                            _button.Text      = _sourceText;
                            _button.BackColor = _sourceColor;

                            OnFinish?.Invoke(_button);

                            _button   = null;
                            _isRuning = false;
                        }
                    }
                }
            }
            catch
            {
                _count         = 0;
                _timer.Enabled = false;

                OnFinish?.Invoke(_button);

                _button   = null;
                _isRuning = false;
            }
        }
Esempio n. 29
0
 public void Execute()
 {
     OnStart?.Invoke();
     foreach (var item in Subjects)
     {
         item.Execute();
     }
     OnFinish?.Invoke();
 }
Esempio n. 30
0
 void Finish()
 {
     NumberInService--;
     Console.WriteLine($"{ClockTime}\t{GetType().Name}#{Index}\tFinish. #Pending: {NumberPending}, #In-Service: {NumberInService}");
     if (NumberPending > 0)
     {
         Start();
     }
     OnFinish.Invoke();
 }