/// <inheritdoc />
        protected override void DeserializeFromUndo(SerializedReferenceDictionary <string, string> stateComponentUndoData)
        {
            base.DeserializeFromUndo(stateComponentUndoData);

            if (stateComponentUndoData.TryGetValue(nameof(SelectionState), out var serializedData))
            {
                var newSelectionState = StateComponentHelper.Deserialize <SelectionStateComponent>(serializedData);
                PersistedState.SetAssetViewStateComponent(m_GraphViewEditorWindowGUID, newSelectionState);
            }

            if (stateComponentUndoData.TryGetValue(nameof(GraphViewState), out serializedData))
            {
                var newGraphViewState = StateComponentHelper.Deserialize <GraphViewStateComponent>(serializedData);
                PersistedState.SetAssetStateComponent(newGraphViewState);
            }

            if (stateComponentUndoData.TryGetValue(nameof(BlackboardViewState), out serializedData))
            {
                var newBlackboardState = StateComponentHelper.Deserialize <BlackboardViewStateComponent>(serializedData);
                PersistedState.SetAssetStateComponent(newBlackboardState);
            }

            if (stateComponentUndoData.TryGetValue(nameof(WindowState), out serializedData))
            {
                var newWindowState = StateComponentHelper.Deserialize <WindowStateComponent>(serializedData);
                PersistedState.SetAssetStateComponent(newWindowState);
            }
        }
        /// <summary>
        /// Loads the graph asset model and the persisted state associated with the asset.
        /// </summary>
        /// <param name="assetModel">The graph asset model to load.</param>
        /// <param name="boundObject">The GameObject to which the graph is bound, if any.</param>
        public void LoadGraphAsset(IGraphAssetModel assetModel, GameObject boundObject)
        {
            ResetStateCaches();

            if (assetModel != null)
            {
                if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(assetModel as Object, out var guid, out long fileId))
                {
                    guid   = (assetModel as Object)?.GetInstanceID().ToString() ?? "0";
                    fileId = 0;
                }
                PersistedState.SetAssetKey(guid + "/" + fileId);
            }
            else
            {
                PersistedState.SetAssetKey("");
            }

            using (var windowStateUpdater = WindowState.UpdateScope)
            {
                windowStateUpdater.LoadGraphAsset(assetModel, boundObject);
            }

            using (var graphViewStateUpdater = GraphViewState.UpdateScope)
            {
                graphViewStateUpdater.LoadGraphAsset(assetModel);
            }
        }
        private protected override Overdrive.WindowStateComponent CreateWindowStateComponent(Hash128 guid)
        {
            var state = PersistedState.GetOrCreateViewStateComponent <WindowStateComponent>(guid, nameof(WindowState));

            state.m_GraphModel = m_GraphModel;
            return(state);
        }
        private protected override Overdrive.GraphViewStateComponent CreateGraphViewStateComponent()
        {
            var state = PersistedState.GetOrCreateAssetStateComponent <GraphViewStateComponent>(nameof(GraphViewState));

            state.m_GraphModel = m_GraphModel;
            return(state);
        }
Beispiel #5
0
 public void LastPersistedInfoWorks()
 {
     var test = new PersistedState<string> { CurrentTerm = 1 };
     test.AddEntry(new LogEntry<string>("dummy"));
     Check.That(test.LastPersistedTerm).IsEqualTo(1L);
     Check.That(test.LastPersistedIndex).IsEqualTo(0);
 }
Beispiel #6
0
        private void LoadPersistedState(PersistedState persistedState)
        {
            var handlerType = persistedState.HandlerType;
            var query       = persistedState.Query;

            if (handlerType == null)
            {
                throw new ArgumentNullException("persistedState", "HandlerType");
            }
            if (query == null)
            {
                throw new ArgumentNullException("persistedState", "Query");
            }
            if (handlerType == "")
            {
                throw new ArgumentException("HandlerType", "persistedState");
            }

            if (_state != ManagedProjectionState.Creating && _state != ManagedProjectionState.Loading)
            {
                throw new InvalidOperationException("LoadPersistedState is now allowed in this state");
            }

            _persistedState = persistedState;
            _runAs          = SerializedRunAs.DeserializePrincipal(persistedState.RunAs);
        }
Beispiel #7
0
 public void LogIsBetterWorks()
 {
     var test = new PersistedState<string> { CurrentTerm = 1 };
     Check.That(test.LogIsBetterThan(0, 0)).IsFalse();
     test.AddEntry(new LogEntry<string>("dummy"));
     Check.That(test.LogIsBetterThan(0, 0)).IsTrue();
     Check.That(test.LogIsBetterThan(1, 0)).IsFalse();
 }
Beispiel #8
0
 private void FixUpOldProjectionRunAs(PersistedState persistedState)
 {
     if (persistedState.RunAs == null || string.IsNullOrEmpty(persistedState.RunAs.Name))
     {
         _runAs = SystemAccount.Principal;
         persistedState.RunAs = SerializedRunAs.SerializePrincipal(ProjectionManagementMessage.RunAs.System);
     }
 }
Beispiel #9
0
 public void InitializeNew(PersistedState persistedState, IEnvelope replyEnvelope)
 {
     LoadPersistedState(persistedState);
     UpdateProjectionVersion();
     _pendingPersistedState = true;
     SetLastReplyEnvelope(replyEnvelope);
     PrepareWriteStartOrLoadStopped();
 }
Beispiel #10
0
        /// <summary>
        /// This code will loop over the entire network and remove any spikes which match the correct rules.
        /// </summary>
        /// <param name="networkRef">the network which this neuron belongs to and for which this method is being executed</param>
        /// <param name="Connections">connections that this neuron has</param>
        /// <returns></returns>
        public bool?RemoveSpikes(SNP_Network networkRef)
        {
            int index;

            if (this.ActiveDelay == 0)
            {
                if (PersistedState.Equals(true))
                {
                    this.SpikeCount = "";
                    PersistedState  = false;
                    return(true);
                }
                else if (PersistedState.Equals(null))
                {
                    this.SpikeCount = "";
                    PersistedState  = false;
                    return(null);
                }
                else
                {
                    index = MatchRules();
                    if (this.Rules[index].IsMatched(this.SpikeCount).Equals(null))
                    {
                        if (this.Rules[index].Delay > 0)
                        {
                            this.ActiveDelay    = this.Rules[index].Delay;
                            this.PersistedState = null;
                            return(false);
                        }
                        this.SpikeCount = "";
                        return(null);
                    }
                    else if (this.Rules[index].IsMatched(this.SpikeCount).Equals(false))
                    {
                        return(false);
                    }
                    else if (this.Rules[index].IsMatched(this.SpikeCount).Equals(true))
                    {
                        if (this.Rules[index].Delay > 0)
                        {
                            this.ActiveDelay    = this.Rules[index].Delay;
                            this.PersistedState = true;
                            return(false);
                        }
                        this.SpikeCount = "";
                        return(true);
                    }
                }
            }
            else
            {
                this.ActiveDelay--;
                return(false);
            }
            // this should never happen.
            Console.Error.WriteLine("Foreach loop failed.");
            return(false);
        }
Beispiel #11
0
        public void AppendEntries()
        {
            var test = new PersistedState<string> { CurrentTerm = 1 };

            test.AddEntry(new LogEntry<string>("dummy"));
            test.CurrentTerm = 2;
            test.AppendEntries(-1,  new[] {new LogEntry<string>("dummy", 2)});
            Check.That(test.EntryMatches(0, 2L)).IsTrue();
        }
Beispiel #12
0
        public void LogEntryMatches()
        {
            var test = new PersistedState<string> { CurrentTerm = 1 };

            test.AddEntry(new LogEntry<string>("dummy"));
            test.CurrentTerm = 2;
            test.AddEntry(new LogEntry<string>("dummy"));
            Check.That(test.EntryMatches(0, 1L)).IsTrue();
        }
Beispiel #13
0
        public void CanAddCommands()
        {
            var test = new PersistedState<string>();

            test.AddEntry(new LogEntry<string>("dummy"));
            test.AddEntry(new LogEntry<string>("dummy"));

            Check.That(test.LogEntries[0].Term).IsEqualTo(0L);
            Check.That(test.LogEntries[1].Term).IsEqualTo(0L);
        }
Beispiel #14
0
        public void LastPersistedInfoWorks()
        {
            var test = new PersistedState <string> {
                CurrentTerm = 1
            };

            test.AddEntry(new LogEntry <string>("dummy"));
            Check.That(test.LastPersistedTerm).IsEqualTo(1L);
            Check.That(test.LastPersistedIndex).IsEqualTo(0);
        }
Beispiel #15
0
        public void CanAddCommands()
        {
            var test = new PersistedState <string>();

            test.AddEntry(new LogEntry <string>("dummy"));
            test.AddEntry(new LogEntry <string>("dummy"));

            Check.That(test.LogEntries[0].Term).IsEqualTo(0L);
            Check.That(test.LogEntries[1].Term).IsEqualTo(0L);
        }
Beispiel #16
0
        private PersistedState <string> BuildLog(int entries)
        {
            var test = new PersistedState <string>();

            for (var i = 0; i < entries; i++)
            {
                test.AddEntry(new LogEntry <string>("dummy"));
            }

            return(test);
        }
Beispiel #17
0
        public void AppendEntries()
        {
            var test = new PersistedState <string> {
                CurrentTerm = 1
            };

            test.AddEntry(new LogEntry <string>("dummy"));
            test.CurrentTerm = 2;
            test.AppendEntries(-1, new[] { new LogEntry <string>("dummy", 2) });
            Check.That(test.EntryMatches(0, 2L)).IsTrue();
        }
Beispiel #18
0
        public void LogEntryMatches()
        {
            var test = new PersistedState <string> {
                CurrentTerm = 1
            };

            test.AddEntry(new LogEntry <string>("dummy"));
            test.CurrentTerm = 2;
            test.AddEntry(new LogEntry <string>("dummy"));
            Check.That(test.EntryMatches(0, 1L)).IsTrue();
        }
Beispiel #19
0
        public void LogIsBetterWorks()
        {
            var test = new PersistedState <string> {
                CurrentTerm = 1
            };

            Check.That(test.LogIsBetterOrSameAs(0, 0)).IsFalse();
            test.AddEntry(new LogEntry <string>("dummy"));
            Check.That(test.LogIsBetterOrSameAs(0, 0)).IsTrue();
            Check.That(test.LogIsBetterOrSameAs(1, 0)).IsFalse();
        }
    public System.Collections.IEnumerator GetPersistedStateAsync(System.Action <PersistedState> process)
    {
        PersistedState state = new PersistedState();

        state.version    = PersistedState.CurrentVersion;
        state.cellString = null;
        Debug.Assert(terrainV2 != null, "terrainV2 was null?");
        yield return(terrainV2.SerializeAsync(bytes => state.v2Data = ToBase64(bytes)));

        state.metadata = GetMetadata();
        process(state);
    }
Beispiel #21
0
        public ActionResult Save(NotaDTO dto)
        {
            PersistedState ps = _notasService.Edit(dto);

            if (ps == PersistedState.OK)
            {
                NotasCache cached = GetSessionItem <NotasCache>(Resources.MisNotas);
                RemoveFromSession(Resources.MisNotas);
                SetSessionItem(Resources.MisNotas, _notasService.UpdateCache(cached, dto));
            }
            return(SimpleJSONFeedback(ps));
        }
Beispiel #22
0
        public void TermChangeResetsVotedFor()
        {
            var test = new PersistedState<string>();
            test.CurrentTerm = 2;
            test.VotedFor = "myself";

            test.CurrentTerm = 3;

            Check.That(test.CurrentTerm).IsEqualTo(3L);

            Check.That(test.VotedFor).IsNullOrEmpty();
        }
        public PersistedState Edit(NotaDTO dto)
        {
            Nota       nota = FindById(dto.NotaId);
            AES_Result res  = CryptoService.AES_Encrypt(dto.NoteContent);

            nota.NoteContent = res.CipherData;
            nota.Nonce       = res.Nonce;
            nota.LUDT        = DateTime.Now;
            PersistedState ps = _notasRepo.TrySaveChanges();

            _notasRepo.Dispose();
            return(ps);
        }
Beispiel #24
0
        public void TermChangeResetsVotedFor()
        {
            var test = new PersistedState <string>();

            test.CurrentTerm = 2;
            test.VotedFor    = "myself";

            test.CurrentTerm = 3;

            Check.That(test.CurrentTerm).IsEqualTo(3L);

            Check.That(test.VotedFor).IsNullOrEmpty();
        }
Beispiel #25
0
        public ActionResult Delete(SinglePropJson json)
        {
            PersistedState ps = _notasService.Remove(int.Parse(json.Value));

            if (ps == PersistedState.OK)
            {
                NotasCache cached = GetSessionItem <NotasCache>(Resources.MisNotas);
                RemoveFromSession(Resources.MisNotas);
                SetSessionItem(Resources.MisNotas, _notasService.RemoveFromCache(cached, json));
            }

            return(SimpleJSONFeedback(ps));
        }
Beispiel #26
0
        private void FixupOldProjectionModes(PersistedState persistedState)
        {
            switch ((int)persistedState.Mode)
            {
            case 2:     // old continuous
                persistedState.Mode = ProjectionMode.Continuous;
                break;

            case 3:     // old persistent
                persistedState.Mode        = ProjectionMode.Continuous;
                persistedState.EmitEnabled = persistedState.EmitEnabled ?? true;
                break;
            }
        }
Beispiel #27
0
        static IPersistedState GetPersistedState(Android.OS.Bundle?state)
        {
            var dict = new PersistedState();

            var keyset = state?.KeySet();

            if (keyset != null)
            {
                foreach (var k in keyset)
                {
                    dict[k] = state?.Get(k)?.ToString();
                }
            }

            return(dict);
        }
Beispiel #28
0
        static IPersistedState GetPersistedState(Tizen.Applications.Bundle?state)
        {
            var dict = new PersistedState();

            var keyset = state?.Keys;

            if (keyset != null)
            {
                foreach (var k in keyset)
                {
                    dict[k] = state?.GetItem <string>(k);
                }
            }

            return(dict);
        }
    public PersistedState GetPersistedState()
    {
        PersistedState state = new PersistedState();

        state.version    = PersistedState.CurrentVersion;
        state.cellString = null;
        using (new Util.ProfileBlock("v2TerrainSerialize"))
        {
            if (terrainV2 != null)
            {
                state.v2Data = ToBase64(terrainV2.Serialize());
            }
        }
        state.metadata = GetMetadata();
        return(state);
    }
    public void SetPersistedState(Vector2 worldSize, PersistedState state)
    {
        byte[] legacyData = null;
        if (state.cellString != null && state.cellString.Length > 0)
        {
            legacyData = Unzip(state.cellString);
        }

        byte[] v2Data = null;
        if (!state.v2Data.IsNullOrEmpty())
        {
            v2Data = Unzip(state.v2Data);
        }

        bool loadingDataFromBeforeDigging = state.version < PersistedState.FirstVersionWithDigging;

        Reset(worldSize, v2Data, loadingDataFromBeforeDigging, legacyData, state.metadata.customStyleWorkshopIds, state.simpleData);
    }
        public void SettingAStateComponentAndGettingItWorks()
        {
            var persistedState = new PersistedState();

            persistedState.SetAssetKey("42424242");
            var viewGuid1 = SerializableGUID.Generate();

            // View State Components
            {
                var firstState        = persistedState.GetOrCreateViewStateComponent <WindowStateComponent>(viewGuid1, "");
                var newStateComponent = new WindowStateComponent();
                persistedState.SetViewStateComponent(viewGuid1, newStateComponent);
                var secondState = persistedState.GetOrCreateViewStateComponent <WindowStateComponent>(viewGuid1, "");
                Assert.IsNotNull(firstState);
                Assert.IsNotNull(secondState);
                Assert.AreSame(newStateComponent, secondState);
            }

            // Asset State Components
            {
                var firstState        = persistedState.GetOrCreateAssetStateComponent <BlackboardViewStateComponent>("");
                var newStateComponent = new BlackboardViewStateComponent();
                persistedState.SetAssetStateComponent(newStateComponent);
                var secondState = persistedState.GetOrCreateAssetStateComponent <BlackboardViewStateComponent>("");
                Assert.IsNotNull(firstState);
                Assert.IsNotNull(secondState);
                Assert.AreSame(newStateComponent, secondState);
            }

            // Asset View State Components
            {
                var firstState        = persistedState.GetOrCreateAssetViewStateComponent <SelectionStateComponent>(viewGuid1, "");
                var newStateComponent = new SelectionStateComponent();
                persistedState.SetAssetViewStateComponent(viewGuid1, newStateComponent);
                var secondState = persistedState.GetOrCreateAssetViewStateComponent <SelectionStateComponent>(viewGuid1, "");
                Assert.IsNotNull(firstState);
                Assert.IsNotNull(secondState);
                Assert.AreSame(newStateComponent, secondState);
            }

            PersistedState.RemoveViewState(viewGuid1);
        }
Beispiel #32
0
        static IPersistedState GetPersistedState(Foundation.NSDictionary[]?states)
        {
            var state = new PersistedState();

            if (states != null)
            {
                foreach (var s in states)
                {
                    foreach (var k in s.Keys)
                    {
                        var key = k.ToString();
                        var val = s?[k]?.ToString();

                        state[key] = val;
                    }
                }
            }

            return(state);
        }
Beispiel #33
0
        public override NSUserActivity?GetStateRestorationActivity(UIScene scene)
        {
            var window = Window.GetWindow();

            if (window is null)
            {
                return(null);
            }

            var persistedState = new PersistedState();

            window.Backgrounding(persistedState);

            // the user saved nothing, so there is nothing to restore
            if (persistedState.Count == 0)
            {
                return(null);
            }

            return(persistedState.ToUserActivity(window.GetType().FullName !));
        }
Beispiel #34
0
 private void FixUpOldFormat(ClientMessage.ReadStreamEventsBackwardCompleted completed, PersistedState persistedState)
 {
     if (persistedState.Version == null)
     {
         persistedState.Version = completed.Events[0].Event.EventNumber;
         persistedState.Epoch   = -1;
     }
     if (_lastWrittenVersion > persistedState.Version)
     {
         persistedState.Version = _lastWrittenVersion;
     }
 }
Beispiel #35
0
 //A medida que se complique la app, por ejemplo añadiendo posibilidad de hacer amigos y
 //de poner notas publicas y privadas y poder editar varias personas el mismo registro,
 //añadir a PersistedState el valor OutdatedEntity a raiz de comprobar si el campo que habría
 //que introducir en Nota, "concurrencyTimeStamp", del registro en base de datos es igual que el de la entidad que se está editando,
 //irían aumentando las casuísiticas y en este método se tratarían todas ellas, al menos las de carácter general.
 public ActionResult SimpleJSONFeedback(PersistedState ps)
 {
     return(Json(new { persState = ps == PersistedState.OK ? "OK" : "KO" }));
 }
 public void InitializeNew(PersistedState persistedState, IEnvelope replyEnvelope)
 {
     LoadPersistedState(persistedState);
     UpdateProjectionVersion();
     _pendingWritePersistedState = true;
     SetLastReplyEnvelope(replyEnvelope);
     PrepareOrWriteStartOrLoadStopped();
 }
Beispiel #37
0
 public void InitializeNew(Action completed, PersistedState persistedState)
 {
     LoadPersistedState(persistedState);
     UpdateProjectionVersion();
     Prepare(() => BeginWrite(() => StartOrLoadStopped(completed)));
 }
        private void LoadPersistedState(PersistedState persistedState)
        {
            var handlerType = persistedState.HandlerType;
            var query = persistedState.Query;

            if (handlerType == null) throw new ArgumentNullException("persistedState", "HandlerType");
            if (query == null) throw new ArgumentNullException("persistedState", "Query");
            if (handlerType == "") throw new ArgumentException("HandlerType", "persistedState");

            if (_state != ManagedProjectionState.Creating && _state != ManagedProjectionState.Loading)
                throw new InvalidOperationException("LoadPersistedState is now allowed in this state");

            _persistedState = persistedState;
        }
 private void FixupOldProjectionModes(PersistedState persistedState)
 {
     switch ((int) persistedState.Mode)
     {
         case 2: // old continuous
             persistedState.Mode = ProjectionMode.Continuous;
             break;
         case 3: // old persistent
             persistedState.Mode = ProjectionMode.Continuous;
             persistedState.EmitEnabled = persistedState.EmitEnabled ?? true;
             break;
     }
 }
 private void FixUpOldFormat(ClientMessage.ReadStreamEventsBackwardCompleted completed, PersistedState persistedState)
 {
     if (persistedState.Version == null)
     {
         persistedState.Version = completed.Events[0].Event.EventNumber;
         persistedState.Epoch = -1;
     }
     if (_lastWrittenVersion > persistedState.Version)
         persistedState.Version = _lastWrittenVersion;
 }
 private void FixUpOldProjectionRunAs(PersistedState persistedState)
 {
     if (persistedState.RunAs == null || string.IsNullOrEmpty(persistedState.RunAs.Name))
     {
         _runAs = SystemAccount.Principal;
         persistedState.RunAs = SerializePrincipal(ProjectionManagementMessage.RunAs.System);
     }
 }
 public void InitializeNew(Action completed, PersistedState persistedState)
 {
     LoadPersistedState(persistedState);
     UpdateProjectionVersion();
     Prepare(() => BeginWrite(() => StartOrLoadStopped(completed)));
 }
Beispiel #43
0
        private PersistedState<string> BuildLog(int entries)
        {
            var test = new PersistedState<string>();

            for (var i = 0; i < entries; i++)
            {
                test.AddEntry(new LogEntry<string>("dummy"));
            }

            return test;
        }