コード例 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var instance = existingValue as ContentTemplateSerializationFormat;

            if (instance == null)
            {
                instance = new ContentTemplateSerializationFormat();
            }

            JObject obj = serializer.Deserialize <JObject>(reader);

            instance.TemplateId           = Read <int>(obj, "TemplateId");
            instance.PrettyName           = Read <string>(obj, "PrettyName") ?? "";
            instance.DefaultDataInstances = new List <Data.IData>();

            JArray dataInstances = obj["DefaultDataInstances"].ToObject <JArray>(serializer);

            foreach (JObject dataInstance in dataInstances)
            {
                Type       dataType = dataInstance["DataType"].ToObject <Type>(serializer);
                Data.IData data     = TryReadData(dataInstance, serializer, "Data", dataType);
                instance.DefaultDataInstances.Add(data);
            }

            return(instance);
        }
コード例 #2
0
ファイル: RuntimeEntity.cs プロジェクト: suzuke/forge
 public RuntimeEntity(int uniqueId, ITemplate template, IEventDispatcher eventDispatcher)
     : this(uniqueId, eventDispatcher, "")
 {
     foreach (DataAccessor accessor in template.SelectData())
     {
         Data.IData data = template.Current(accessor);
         AddData_unlocked(accessor, data.Duplicate());
     }
 }
コード例 #3
0
ファイル: RuntimeEntity.cs プロジェクト: suzuke/forge
        public Data.IData Modify(DataAccessor accessor)
        {
            var id = accessor.Id;

            // if we don't contain the data, then we might have added in this frame, which means we
            // want to just return the added data -- otherwise, there is no data to modify
            if (ContainsData(accessor) == false)
            {
                Data.IData added = GetAddedData_unlocked(accessor);
                if (added != null)
                {
                    return(added);
                }

                throw new NoSuchDataException(this, accessor);
            }

            // notify everyone that the data has been modified and see if we're the first ones to
            // modify the data
            if (_data[id].ModificationActivation.TryActivate())
            {
                _concurrentModifications.Add(accessor);
                ModificationNotifier.Notify();
            }

            // someone else already modified the data
            else
            {
                // nonversioned data cannot be modified multiple times unless its concurrent
                if (_data[id] is NonVersionedDataContainer)
                {
                    if (((NonVersionedDataContainer)_data[id]).Data is Data.ConcurrentNonVersioned == false)
                    {
                        throw new RemodifiedDataException(this, accessor);
                    }
                }

                // versioned data cannot be modified multiple times unless its concurrent
                if (_data[id] is VersionedDataContainer)
                {
                    if (((VersionedDataContainer)_data[id]).Current is Data.IConcurrent == false)
                    {
                        throw new RemodifiedDataException(this, accessor);
                    }
                }
            }

            if (_data[id] is VersionedDataContainer)
            {
                return(((VersionedDataContainer)_data[id]).Modifying);
            }
            else
            {
                return(((NonVersionedDataContainer)_data[id]).Data);
            }
        }
コード例 #4
0
        public bool BlockNoBlockClassificacao(string commandsql, mClassificacao obj)
        {
            Data.IData mdata = Data.Instances.DataM();

            mdata.ClearParameters();
            mdata.AddParameters("@Bloqueado", obj.Bloqueado);
            mdata.AddParameters("@Codigo", obj.Codigo);

            return(mdata.Write(commandsql));
        }
コード例 #5
0
ファイル: RuntimeEntity.cs プロジェクト: suzuke/forge
        public Data.IData AddOrModify(DataAccessor accessor)
        {
            if (ContainsData(accessor) == false || WasRemoved(accessor))
            {
                lock (_toAddStage1) {
                    Data.IData added = GetAddedData_unlocked(accessor);
                    if (added == null)
                    {
                        added = AddData_unlocked(accessor);
                    }

                    return(added);
                }
            }

            return(Modify(accessor));
        }
コード例 #6
0
        public bool InsertClassificacao(string sqlcommand1, string sqlcommand2, mClassificacao obj)
        {
            Data.IData mdata = Data.Instances.DataM();

            int last_codigo = 0;

            foreach (DataRow dr in mdata.Read(sqlcommand2).Rows)
            {
                last_codigo = (int)dr[0] + 1;
            }

            mdata.ClearParameters();

            mdata.AddParameters("@Codigo", last_codigo);
            mdata.AddParameters("@Nome", obj.Nome);
            mdata.AddParameters("@Cadastro", obj.Cadastro.ToShortDateString());
            mdata.AddParameters("@Alterado", obj.Alterado.ToShortDateString());
            mdata.AddParameters("@Bloqueado", obj.Bloqueado);

            return(mdata.Write(sqlcommand1));
        }
コード例 #7
0
ファイル: RuntimeEntity.cs プロジェクト: suzuke/forge
        private Data.IData AddData_unlocked(DataAccessor accessor, Data.IData instance = null)
        {
            // ensure that we have not already added a data of this type
            if (GetAddedData_unlocked(accessor) != null || ContainsData(accessor))
            {
                throw new AlreadyAddedDataException(this, accessor);
            }

            // add our data
            if (instance == null)
            {
                instance = (Data.IData)Activator.CreateInstance(accessor.DataType);
            }
            _toAddStage1.Add(instance);

            // notify the entity manager
            ModificationNotifier.Notify();
            DataStateChangeNotifier.Notify();

            // return the new instance
            return(instance);
        }
コード例 #8
0
ファイル: DataAccessor.cs プロジェクト: suzuke/forge
 /// <summary>
 /// Helper constructor for DataAccessor(Type). This merely forwards the call with the type
 /// parameter being data.GetType().
 /// </summary>
 public DataAccessor(Data.IData data)
     : this(data.GetType())
 {
 }
コード例 #9
0
ファイル: RuntimeTemplate.cs プロジェクト: suzuke/forge
 /// <summary>
 /// Adds a default data instance to the template. The template "owns" the passed data
 /// instance; a copy is not made of it.
 /// </summary>
 /// <remarks>
 /// If the ITemplate is currently being backed by an IGameEngine, this will throw an
 /// InvalidOperationException.
 /// </remarks>
 /// <param name="data">The data instance to copy from.</param>
 public void AddDefaultData(Data.IData data)
 {
     throw new InvalidOperationException("Template cannot be modified while game is being played");
 }
コード例 #10
0
 public BaseBusinessLogic(Data.IData <T> Data)
 {
     _Data = (Data.BaseData <T>)Data;
 }
コード例 #11
0
ファイル: RuntimeEntity.cs プロジェクト: suzuke/forge
        /// <summary>
        /// Applies data state changes to the entity.
        /// </summary>
        /// <remarks>
        /// This function is not thread-safe; no other API calls can be made to the Entity while
        /// this function is being executed.
        /// </remarks>
        /// <returns>If more data state change updates are needed</returns>
        public void DataStateChangeUpdate()
        {
            // do removals
            {
                for (int i = 0; i < _toRemoveStage1.Count; ++i)
                {
                    int id = _toRemoveStage1[i].Id;
                    _removedLastFrame[id] = _toRemoveStage1[i];
                    // _removedLastFrame[id] is removed in stage2

                    _eventDispatcher.Submit(RemovedDataEvent.Create(this, DataAccessorFactory.GetTypeFromId(id)));
                }

                for (int i = 0; i < _toRemoveStage2.Count; ++i)
                {
                    int id = _toRemoveStage2[i].Id;
                    _removedLastFrame.Remove(id);
                    _data.Remove(id);
                }
                _toRemoveStage2.Clear();

                Utils.Swap(ref _toRemoveStage1, ref _toRemoveStage2);
            }

            // We don't throw an exception immediately. If we are throwing an exception, that means
            // that the Entity is in an invalid state (adding a bad data instance). However, the
            // only way to recover from that invalid state is by having this method terminate.
            // Hence, we only throw an exception at the end of the method.
            Exception exceptionToThrow = null;

            // do additions
            for (int i = 0; i < _toAddStage1.Count; ++i)
            {
                Data.IData added = _toAddStage1[i];
                int        id    = DataAccessorFactory.GetId(added.GetType());

                // make sure we do not readd the same data instance twice
                if (_data.ContainsKey(id))
                {
                    exceptionToThrow = new AlreadyAddedDataException(this, new DataAccessor(added));
                    continue;
                }

                _addedLastFrame[id] = added;

                if (added is Data.IVersioned)
                {
                    Data.IVersioned versioned = (Data.IVersioned)added;

                    _data[id] = new VersionedDataContainer(versioned.Duplicate(), versioned.Duplicate(), versioned.Duplicate());
                }
                else
                {
                    Data.NonVersioned nonVersioned = (Data.NonVersioned)added;
                    _data[id] = new NonVersionedDataContainer(nonVersioned);
                }

                // visualize the initial data
                _eventDispatcher.Submit(AddedDataEvent.Create(this, added.GetType()));
            }

            for (int i = 0; i < _toAddStage2.Count; ++i)
            {
                _addedLastFrame.Remove(new DataAccessor(_toAddStage2[i]).Id);
            }
            _toAddStage2.Clear();

            Utils.Swap(ref _toAddStage1, ref _toAddStage2);

            if (exceptionToThrow != null)
            {
                throw exceptionToThrow;
            }
        }
コード例 #12
0
ファイル: DataAccessor.cs プロジェクト: suzuke/forge
 /// <summary>
 /// Returns the id for the given data type. Forwards the call to GetId(Type).
 /// </summary>
 public static int GetId(Data.IData data)
 {
     return(GetId(data.GetType()));
 }
コード例 #13
0
 /// <summary>
 /// Adds a default data instance to the template. The template "owns" the passed data
 /// instance; a copy is not made of it.
 /// </summary>
 /// <remarks>
 /// If the ITemplate is currently being backed by an IGameEngine, this will throw an
 /// InvalidOperationException.
 /// </remarks>
 /// <param name="data">The data instance to copy from.</param>
 public void AddDefaultData(Data.IData data)
 {
     _defaultDataInstances[DataAccessorFactory.GetId(data)] = data;
 }