コード例 #1
0
ファイル: EntitySaver.cs プロジェクト: UKMonkey/Gobos
 private void SaveEntity(EntitySaveData data)
 {
     if (data.Data != null)
     {
         var stream = new FileStream(data.Targetname, FileMode.Create);
         stream.Write(data.Data, 0, data.Data.Length);
         stream.Close();
         stream.Dispose();
     }
 }
コード例 #2
0
        public void SaveEntities(ICollection <Entity> entities)
        {
            var toSave = new Dictionary <int, EntitySaveData>();

            foreach (var entity in entities)
            {
                if (!ShouldSaveEntity(entity))
                {
                    continue;
                }

                var saveData = new EntitySaveData
                {
                    Targetname = GetEntityTargetSaveFilename(entity),
                    Data       = GetEntityData(entity)
                };

                if (saveData.Targetname == null)
                {
                    continue;
                }

                toSave[entity.EntityId] = saveData;
            }

            if (toSave.Count == 0)
            {
                return;
            }

            lock (this)
            {
                foreach (var item in toSave)
                {
                    _entitiesToSave[item.Key] = item.Value;
                }
            }
        }