Ejemplo n.º 1
0
        async Task AttemptRestart(IRestartable restartable, int attempt, Exception error)
        {
            attempt += 1;

            // quite if there are no more delays in the sequence
            if (!_delays.MoveNext())
            {
                await restartable.MaxRestartsReached(attempt);

                return;
            }

            // attempt another restart
            TimeSpan delay = _delays.Current;

            Debug.Assert(delay > TimeSpan.Zero);
            await restartable.PauseBeforeRestart(delay);

            try
            {
                await restartable.Restart();
            }
            catch (Exception ex)
            {
                Logging.Log.Warning("Failed to restart: " + ex);
                return;
            }
            Monitor(restartable, attempt);
        }
Ejemplo n.º 2
0
 public override void SetRestartConsumer(IRestartable restartConsumer)
 {
     if (this.restartMax != 0 || restartConsumer == null)
     {
         this.restartConsumer = restartConsumer;
     }
 }
Ejemplo n.º 3
0
    private GameObject SpawnObjectInternal(string name, Transform transform)
    {
        if (!Objects.ContainsKey(name))
        {
            Debug.LogError("unknown object pool: " + name);
            return(null);
        }

        Queue <GameObject> q = Objects[name];

        if (q.Count == 0)
        {
            return(null);
        }

        GameObject toReturn = q.Dequeue();

        IRestartable Restarter = toReturn.GetComponent <IRestartable>();

        if (Restarter != null)
        {
            Restarter.Restart();
        }

        toReturn.transform.position   = transform.position;
        toReturn.transform.rotation   = transform.rotation;
        toReturn.transform.localScale = transform.localScale;

        q.Enqueue(toReturn);

        return(toReturn);
    }
Ejemplo n.º 4
0
        private void BackupForRestart(byte[] buffer, int offset, int count, int fileOffset, bool force)
        {
            InternalDebug.Assert(restartConsumer != null);

            if (!force && fileOffset > restartMax)
            {
                restartConsumer.DisableRestart();
                restartConsumer = null;

                preamble = null;
                return;
            }

            if (restartCache == null)
            {
                restartCache = new ByteCache();
            }

            byte[] cacheBuffer;
            int    cacheOffset;

            restartCache.GetBuffer(count, out cacheBuffer, out cacheOffset);

            Buffer.BlockCopy(buffer, offset, cacheBuffer, cacheOffset, count);

            restartCache.Commit(count);
        }
Ejemplo n.º 5
0
    public void DiscardInstantiatedPrefab()
    {
        if (_placingType == PlacingManager.PlacingType.instantiate)
        {
            Destroy(AssociatedGO);
            AssociatedGO = null;
        }
        else
        {
            if (AssociatedGO == null)
            {
                return;
            }

            foreach (Transform tr in AssociatedGO.transform)
            {
                tr.gameObject.SetActive(false);
            }
            IRestartable restartComponent = AssociatedGO.GetComponent <IRestartable>();
            if (restartComponent != null)
            {
                restartComponent.Restart();
            }
            AssociatedGO = null;
        }
    }
Ejemplo n.º 6
0
 public void Monitor(IRestartable restartable, int attempt = 0)
 {
     if (restartable.MonitoredTask == null)
     {
         throw new ArgumentException("restartable.Running is null");
     }
     restartable.MonitoredTask.ContinueWith(t => { AttemptRestart(restartable, attempt, t.Exception); }, TaskContinuationOptions.OnlyOnFaulted);
 }
Ejemplo n.º 7
0
        private void DetectEncoding(byte[] buffer, int start, int end)
        {
            if (end - start < 2)
            {
                return;
            }

            Encoding newEncoding = null;

            if (buffer[start] == 0xFE && buffer[start + 1] == 0xFF)
            {
                newEncoding = Encoding.BigEndianUnicode;
            }
            else if (buffer[start] == 0xFF && buffer[start + 1] == 0xFE)
            {
                if (end - start >= 4 &&
                    buffer[start + 2] == 0 &&
                    buffer[start + 3] == 0)
                {
                    newEncoding = Encoding.UTF32;
                }
                else
                {
                    newEncoding = Encoding.Unicode;
                }
            }
            else if (end - start >= 3 &&
                     buffer[start] == 0xEF &&
                     buffer[start + 1] == 0xBB &&
                     buffer[start + 2] == 0xBF)
            {
                newEncoding = Encoding.UTF8;
            }
            else if (end - start >= 4 &&
                     buffer[start] == 0 &&
                     buffer[start + 1] == 0 &&
                     buffer[start + 2] == 0xFE &&
                     buffer[start + 3] == 0xFF)
            {
                newEncoding = new UTF32Encoding(true, true);
            }

            if (newEncoding != null)
            {
                this.encoding = newEncoding;
                this.decoder  = this.encoding.GetDecoder();

                this.preamble = this.encoding.GetPreamble();

                this.minDecodeChars = this.GetMaxCharCount(this.minDecodeBytes);

                if (this.restartConsumer != null)
                {
                    this.restartConsumer.DisableRestart();
                    this.restartConsumer = null;
                }
            }
        }
Ejemplo n.º 8
0
    private void OnTriggerExit(Collider other)
    {
        IRestartable Restarter = other.transform.root.GetComponent <IRestartable>();

        if (Restarter == null)
        {
            return;
        }
        Restarter.End();
    }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="topLevel"></param>
 /// <param name="editableLevel"></param>
 /// <param name="levelName"></param>
 public PauseMenuScreen(TopLevelModel topLevel, EditableLevel editableLevel, string levelName)
     : base(topLevel)
 {
     base.TransitionOnTime = TimeSpan.FromSeconds(0.5);
       base.TransitionOffTime = TimeSpan.FromSeconds(0.5);
       EditorMode = true;
       custom = editableLevel.Custom;
       this.restartable = editableLevel;
       LevelName = levelName;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="topLevel"></param>
 /// <param name="simulation"></param>
 /// <param name="levelName"></param>
 public PauseMenuScreen(TopLevelModel topLevel, Simulation simulation, string levelName)
     : base(topLevel)
 {
     base.TransitionOnTime = TimeSpan.FromSeconds(0.5);
       base.TransitionOffTime = TimeSpan.FromSeconds(0.5);
       EditorMode = false;
       custom = false;
       this.restartable = simulation;
       LevelName = levelName;
 }
Ejemplo n.º 11
0
        public bool RestartWithNewEncoding(Encoding newEncoding)
        {
            if (this.encoding.CodePage == newEncoding.CodePage)
            {
                if (this.restartConsumer != null)
                {
                    this.restartConsumer.DisableRestart();
                    this.restartConsumer = null;

                    if (this.restartCache != null)
                    {
                        this.restartCache.Reset();
                        this.restartCache = null;
                    }
                }

                return(false);
            }

            if (this.restartConsumer == null || !this.restartConsumer.CanRestart())
            {
                return(false);
            }

            this.restartConsumer.Restart();

            this.SetNewEncoding(newEncoding);

            this.encodingChanged = true;

            if (this.readEnd != 0 && this.readFileOffset != 0)
            {
                this.BackupForRestart(this.readBuffer, 0, this.readEnd, this.readFileOffset, true);

                this.readEnd = 0;

                this.readFileOffset = 0;
            }
            else
            {
            }

            this.readCurrent   = 0;
            this.pushChunkUsed = 0;

            this.restartConsumer = null;

            this.parseStart = this.parseEnd = 0;

            this.restarting = this.restartCache != null && this.restartCache.Length != 0;

            return(true);
        }
Ejemplo n.º 12
0
 protected override void Dispose()
 {
     if (restartCache != null && restartCache is IDisposable)
     {
         ((IDisposable)restartCache).Dispose();
     }
     restartCache    = null;
     pullSource      = null;
     pushSource      = null;
     parseBuffer     = null;
     readBuffer      = null;
     pushChunkBuffer = null;
     preamble        = null;
     restartConsumer = null;
     base.Dispose();
 }
Ejemplo n.º 13
0
        protected override void Dispose()
        {
            if (this.restartCache != null && this.restartCache is IDisposable)
            {
                ((IDisposable)this.restartCache).Dispose();
            }

            this.restartCache    = null;
            this.pullSource      = null;
            this.pushSource      = null;
            this.parseBuffer     = null;
            this.readBuffer      = null;
            this.pushChunkBuffer = null;
            this.preamble        = null;
            this.restartConsumer = null;

            base.Dispose();
        }
Ejemplo n.º 14
0
        private void DetectEncoding(byte[] buffer, int start, int end)
        {
            if (end - start < 2)
            {
                return;
            }
            Encoding encoding = null;

            if (buffer[start] == 254 && buffer[start + 1] == 255)
            {
                encoding = Encoding.BigEndianUnicode;
            }
            else if (buffer[start] == 255 && buffer[start + 1] == 254)
            {
                if (end - start >= 4 && buffer[start + 2] == 0 && buffer[start + 3] == 0)
                {
                    encoding = Encoding.UTF32;
                }
                else
                {
                    encoding = Encoding.Unicode;
                }
            }
            else if (end - start >= 3 && buffer[start] == 239 && buffer[start + 1] == 187 && buffer[start + 2] == 191)
            {
                encoding = Encoding.UTF8;
            }
            else if (end - start >= 4 && buffer[start] == 0 && buffer[start + 1] == 0 && buffer[start + 2] == 254 && buffer[start + 3] == 255)
            {
                encoding = new UTF32Encoding(true, true);
            }
            if (encoding != null)
            {
                this.encoding  = encoding;
                decoder        = this.encoding.GetDecoder();
                preamble       = this.encoding.GetPreamble();
                minDecodeChars = GetMaxCharCount(minDecodeBytes);
                if (restartConsumer != null)
                {
                    restartConsumer.DisableRestart();
                    restartConsumer = null;
                }
            }
        }
Ejemplo n.º 15
0
        private int DecodeFromBuffer(byte[] buffer, ref int start, int end, int fileOffset, bool flush)
        {
            int num = 0;

            if (fileOffset == 0)
            {
                if (detectEncodingFromByteOrderMark)
                {
                    DetectEncoding(buffer, start, end);
                }
                if (preamble.Length != 0 && end - start >= preamble.Length)
                {
                    int num2 = 0;
                    while (num2 < preamble.Length && preamble[num2] == buffer[start + num2])
                    {
                        num2++;
                    }
                    if (num2 == preamble.Length)
                    {
                        start += preamble.Length;
                        num    = preamble.Length;
                        if (restartConsumer != null)
                        {
                            restartConsumer.DisableRestart();
                            restartConsumer = null;
                        }
                    }
                }
                encodingChanged = true;
                preamble        = null;
            }
            int num3 = end - start;

            if (GetMaxCharCount(num3) >= parseBuffer.Length - parseEnd)
            {
                num3 = CalculateMaxBytes(parseBuffer.Length - parseEnd - 1);
            }
            int chars = decoder.GetChars(buffer, start, num3, parseBuffer, parseEnd);

            parseEnd += chars;
            parseBuffer[parseEnd] = '\0';
            start += num3;
            return(num3 + num);
        }
Ejemplo n.º 16
0
        private void BackupForRestart(byte[] buffer, int offset, int count, int fileOffset, bool force)
        {
            if (!force && fileOffset > restartMax)
            {
                restartConsumer.DisableRestart();
                restartConsumer = null;
                preamble        = null;
                return;
            }
            if (restartCache == null)
            {
                restartCache = new ByteCache();
            }
            byte[] dst;
            int    dstOffset;

            restartCache.GetBuffer(count, out dst, out dstOffset);
            Buffer.BlockCopy(buffer, offset, dst, dstOffset, count);
            restartCache.Commit(count);
        }
Ejemplo n.º 17
0
#pragma warning restore CS0649

        public ExtensionsForm(ExtensionManager mg, IRestartable restartable)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            manager          = mg;
            this.restartable = restartable;

            var enabled_plgs  = manager.Plugins.Where(p => p.Enabled);
            var disabled_plgs = manager.Plugins.Where(p => !p.Enabled);

            foreach (var plg in enabled_plgs)
            {
                enabledListBox.Items.Add(new ListItem()
                {
                    Text = plg.Name, Tag = plg
                });
            }
            enabledListBox.SelectedIndexChanged += (s, a) => ItemSelected(enabledListBox);
            enabledListBox.GotFocus             += (s, a) =>
            {
                deactivateButton.Enabled = true;
                activateButton.Enabled   = false;
            };

            foreach (var plg in disabled_plgs)
            {
                disabledListBox.Items.Add(new ListItem()
                {
                    Text = plg.Name, Tag = plg
                });
            }
            disabledListBox.SelectedIndexChanged += (s, a) => ItemSelected(disabledListBox);
            disabledListBox.GotFocus             += (s, a) =>
            {
                deactivateButton.Enabled = false;
                activateButton.Enabled   = true;
            };

            this.AddSizeStateHandler();
        }
Ejemplo n.º 18
0
 public bool RestartWithNewEncoding(Encoding newEncoding)
 {
     if (encoding.CodePage == newEncoding.CodePage)
     {
         if (restartConsumer != null)
         {
             restartConsumer.DisableRestart();
             restartConsumer = null;
             if (restartCache != null)
             {
                 restartCache.Reset();
                 restartCache = null;
             }
         }
         return(false);
     }
     if (restartConsumer == null || !restartConsumer.CanRestart())
     {
         return(false);
     }
     restartConsumer.Restart();
     SetNewEncoding(newEncoding);
     encodingChanged = true;
     if (readEnd != 0 && readFileOffset != 0)
     {
         BackupForRestart(readBuffer, 0, readEnd, readFileOffset, true);
         readEnd        = 0;
         readFileOffset = 0;
     }
     readCurrent     = 0;
     pushChunkUsed   = 0;
     restartConsumer = null;
     parseStart      = (parseEnd = 0);
     restarting      = (restartCache != null && restartCache.Length != 0);
     return(true);
 }
Ejemplo n.º 19
0
 public GameRestarter(IRestartable game)
 {
     _game = game;
 }
Ejemplo n.º 20
0
        private int DecodeFromBuffer(byte[] buffer, ref int start, int end, int fileOffset, bool flush)
        {
            int preambleLength = 0;

            if (fileOffset == 0)
            {
                if (this.detectEncodingFromByteOrderMark)
                {
                    this.DetectEncoding(buffer, start, end);
                }

                InternalDebug.Assert(this.preamble != null);

                if (this.preamble.Length != 0 && end - start >= this.preamble.Length)
                {
                    int i;

                    for (i = 0; i < this.preamble.Length; i++)
                    {
                        if (this.preamble[i] != buffer[start + i])
                        {
                            break;
                        }
                    }

                    if (i == this.preamble.Length)
                    {
                        start         += this.preamble.Length;
                        preambleLength = this.preamble.Length;

                        if (this.restartConsumer != null)
                        {
                            this.restartConsumer.DisableRestart();
                            this.restartConsumer = null;
                        }
                    }
                }

                this.encodingChanged = true;

                this.preamble = null;
            }

            int bytesToDecode = end - start;

            if (this.GetMaxCharCount(bytesToDecode) >= this.parseBuffer.Length - this.parseEnd)
            {
                bytesToDecode = this.CalculateMaxBytes(this.parseBuffer.Length - this.parseEnd - 1);

                InternalDebug.Assert(bytesToDecode < end - start);
            }

            int charsDecoded = this.decoder.GetChars(buffer, start, bytesToDecode, this.parseBuffer, this.parseEnd);

            InternalDebug.Assert(charsDecoded <= this.parseBuffer.Length - this.parseEnd - 1);

            this.parseEnd += charsDecoded;

            this.parseBuffer[this.parseEnd] = '\0';

            start += bytesToDecode;

            return(bytesToDecode + preambleLength);
        }
Ejemplo n.º 21
0
        private int DecodeFromBuffer(byte[] buffer, ref int start, int end, int fileOffset, bool flush)
        {
            var preambleLength = 0;

            if (fileOffset == 0)
            {
                if (detectEncodingFromByteOrderMark)
                {
                    DetectEncoding(buffer, start, end);
                }


                InternalDebug.Assert(preamble != null);



                if (preamble.Length != 0 && end - start >= preamble.Length)
                {
                    int i;

                    for (i = 0; i < preamble.Length; i++)
                    {
                        if (preamble[i] != buffer[start + i])
                        {
                            break;
                        }
                    }

                    if (i == preamble.Length)
                    {
                        start         += preamble.Length;
                        preambleLength = preamble.Length;

                        if (restartConsumer != null)
                        {
                            restartConsumer.DisableRestart();
                            restartConsumer = null;
                        }
                    }
                }


                encodingChanged = true;


                preamble = null;
            }

            var bytesToDecode = end - start;

            if (GetMaxCharCount(bytesToDecode) >= parseBuffer.Length - parseEnd)
            {
                bytesToDecode = CalculateMaxBytes(parseBuffer.Length - parseEnd - 1);

                InternalDebug.Assert(bytesToDecode < end - start);
            }

            var charsDecoded = decoder.GetChars(buffer, start, bytesToDecode, parseBuffer, parseEnd);

            InternalDebug.Assert(charsDecoded <= parseBuffer.Length - parseEnd - 1);

            parseEnd += charsDecoded;

            parseBuffer[parseEnd] = '\0';


            start += bytesToDecode;

            return(bytesToDecode + preambleLength);
        }
Ejemplo n.º 22
0
 public ExtensionsControlHandler(ExtensionManager mg, IRestartable restartable)
 {
     this.mg          = mg;
     this.restartable = restartable;
 }
Ejemplo n.º 23
0
 public RestartCommand(IRestartable restartable)
 {
     this.restartable = restartable;
 }
Ejemplo n.º 24
0
 public DefaultPlugin(IRestartable restartable, Bootstrapper bootstrapper)
 {
     this.restartable  = restartable;
     this.bootstrapper = bootstrapper;
 }
 // Token: 0x06001006 RID: 4102 RVA: 0x0007605B File Offset: 0x0007425B
 public virtual void SetRestartConsumer(IRestartable restartConsumer)
 {
 }