Beispiel #1
0
            public static object Bind(ISerializeData Data, Type Type)
            {
                if (Data == null)
                {
                    throw new NullReferenceException("Data cannot be null");
                }

                if (Type.IsArray != (Data is ISerializeArray))
                {
                    throw new ArgumentException("Type [" + Type + "] and [" + Data.GetType() + "] are not same");
                }

                Type elementType = (Type.IsArray ? Type.GetElementType() : Type);

                if (Data is ISerializeObject)
                {
                    ISerializeObject obj = (ISerializeObject)Data;

                    if (obj.Contains(TYPE_FIELD_NAME))
                    {
                        string typeName = obj.Get <string>(TYPE_FIELD_NAME);

                        elementType = Type.GetType(typeName);

                        if (elementType == null)
                        {
                            throw new ArgumentException(string.Format("Couldn't find Specified type {0}", typeName), TYPE_FIELD_NAME);
                        }
                    }

                    return(Bind(obj, elementType));
                }

                return(Bind((ISerializeArray)Data, Type));
            }
 public DBTableDataConnection(ISerializeData data)
 {
     this.data   = data;
     this.Fields = new string[1] {
         "*"
     };
 }
Beispiel #3
0
        private void MainWindow_FormClosing(Object sender, FormClosingEventArgs e)
        {
            //DataBaseWriter dataBaseWrite = new DataBaseWriter();
            this.mapper         = new BoardDataMapper();
            this.savedGameState = new SavedGameState
            {
                BoardSize        = this.matrixAlgorithm.BoardSize,
                CurrentTurn      = this.matrixAlgorithm.CurrentTurn,
                CurrentTurnCount = this.matrixAlgorithm.CurrentTurnCount,
                BoardData        = this.mapper.WriteCurrentBoardToString(this.matrixAlgorithm),
            };
            Data data = new Data
            {
                CurrentGame = this.savedGameState,
                Round       = this.settings.RoundCount,
                HistoryList = this.settings.HistoryList,
                Difficulty  = this.ChooseDifficulty()
            };
            HistoryData historyData = new HistoryData
            {
                HistoryList = this.settings.HistoryList,
            };

            dataBaseWriter.WriteDatabaseFile(historyData);
            this.serialize = (ISerializeData)SerDesFactory.Create(typeof(ISerializeData));
            this.serialize.SerializeJson(Application.StartupPath + "/settings/autosave.json", data);
            this.serialize.SerializeXml(Application.StartupPath + "/settings/autosave.xml", data);
        }
 public SenderMediaSerialize(ISerializeData serializeData, string key, IFilterTransformTo <T> transform)
 {
     SerializeData = serializeData;
     Key           = key;
     Transform     = transform;
     Name          = $"serialize {Key} with {transform.Name} into {SerializeData.GetType().Name}";
 }
Beispiel #5
0
 public static void Override(ISerializeData Data, ISerializeData On)
 {
     if (Data is ISerializeObject)
     {
         Override((ISerializeObject)Data, (ISerializeObject)On);
     }
     else
     {
         Override((ISerializeArray)Data, (ISerializeArray)On);
     }
 }
        public void CreateItem(ICoreData ItemData)
        {
            string        _strDBName  = GetDBPath();
            IDbConnection _connection = new SqliteConnection(_strDBName);
            IDbCommand    _command    = _connection.CreateCommand();
            string        tableName   = "items";
            string        sql         = "";

            _connection.Open();

            if (ItemData != null)
            {
                if (ItemData.BaseData is ISerializeData)
                {
                    ISerializeData itemSerializeDataInterface = ItemData.BaseData as ISerializeData;
                    if (itemSerializeDataInterface == null)
                    {
                        Debug.LogError("The external DB item data does not implement the interface ISerializeData");
                        return;
                    }

                    IPropertySerializer propertiesInterface = ItemData.BaseData.Properties as IPropertySerializer;
                    string serializedProperties             = string.Empty;
                    if (propertiesInterface != null)
                    {
                        serializedProperties = propertiesInterface.Serialize();
                    }

                    sql = string.Format("INSERT INTO " + tableName + " (item_uuid, type, data, properties)" +
                                        " VALUES ( \"{0}\", \"{1}\", \"{2}\", \"{3}\");",
                                        ItemData.BaseData.UniqueUUID,
                                        ItemData.BaseData.Type,
                                        itemSerializeDataInterface.SerializeItemData(),
                                        serializedProperties
                                        );
                    _command.CommandText = sql;
                    _command.ExecuteNonQuery();
                }
                else
                {
                    Debug.LogError("External DB item [" + ItemData.BaseData.Name + "] does not implement ISerializeData interface.");
                }
            }
            else
            {
                Debug.Log("The external DB item is null.");
            }

            _command.Dispose();
            _command = null;

            _connection.Close();
            _connection = null;
        }
Beispiel #7
0
 /// <summary>
 /// 写一个对象
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="propertyName"></param>
 /// <param name=""></param>
 public static void WriteObject(this JsonWriter writer, string propertyName, ISerializeData serializeData)
 {
     if (serializeData != null)
     {
         writer.WritePropertyName(propertyName);
         writer.WriteObjectStart();
         {
             serializeData.Serialize(writer);
         }
         writer.WriteObjectEnd();
     }
 }
Beispiel #8
0
        public static T Create <T>(string Data)
        {
            Type type = typeof(T);

            ISerializeData data = parser.Parse(ref Data);

            if (data is T)
            {
                return((T)data);
            }

            return(Bind <T>(data));
        }
Beispiel #9
0
            private static object Bind(ISerializeArray Array, Type Type)
            {
                Array arr = null;

                Type elementType = Type.GetElementType();

                if (Type.Name.Contains(","))                 // Multidimension
                {
                    List <object>  dimensions = new List <object>();
                    ISerializeData data       = Array;
                    while (true)
                    {
                        ISerializeArray arrTemp = (ISerializeArray)data;

                        dimensions.Add((int)arrTemp.Count);

                        if (arrTemp.Count == 0)
                        {
                            break;
                        }

                        data = arrTemp.Get <ISerializeArray>(0);
                        if (data == null)
                        {
                            break;
                        }

                        if (!(data is ISerializeArray))
                        {
                            break;
                        }
                    }

                    arr = (Array)Activator.CreateInstance(Type, dimensions.ToArray());

                    int[] indices = new int[dimensions.Count];

                    Bind(Array, elementType, arr, indices, 0);
                }
                else                 // Jagged
                {
                    arr = (Array)Activator.CreateInstance(Type, (int)Array.Count);

                    for (uint i = 0; i < Array.Count; ++i)
                    {
                        arr.SetValue(Cast(Array.Get <object>(i), elementType), i);
                    }
                }

                return(arr);
            }
        public void UpdateItem(string itemUUID, ICoreData itemDBData)
        {
            string        sql       = "";
            string        tableName = "items";
            string        conn      = GetDBPath();
            IDbConnection dbconn    = (IDbConnection) new SqliteConnection(conn);

            dbconn.Open();
            IDbCommand dbcmd = dbconn.CreateCommand();

            ISerializeData itemSerializeDataInterface = null;

            if (itemDBData.BaseData is ISerializeData)
            {
                itemSerializeDataInterface = itemDBData.BaseData as ISerializeData;

                if (itemSerializeDataInterface == null)
                {
                    Debug.LogError("The external DB item data does not implement the interface ISerializeData");
                    return;
                }
            }


            #region DB Structure
            //CREATE TABLE `items` (
            // `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
            // `object_id`	TEXT DEFAULT '00000000-0000-0000-0000-000000000000',
            // `owner_id`	INTEGER NOT NULL,
            // `object_owner_id`	TEXT,
            // `type`	TEXT NOT NULL,
            // `data`	BLOB NOT NULL,
            // `position`	BLOB NOT NULL,
            // `rotation`	BLOB NOT NULL,
            // `timeout` INTEGER
            //);
            #endregion DB Structure

            // should i add player uuid on the where statment????
            sql = string.Format("UPDATE \"" + tableName + "\" SET data=\"{0}\" WHERE item_uuid=\"{2}\";",
                                itemSerializeDataInterface.SerializeItemData(), itemUUID);

            dbcmd.CommandText = sql;
            dbcmd.ExecuteNonQuery();

            dbcmd.Dispose();
            dbcmd = null;

            dbconn.Close();
            dbconn = null;
        }
Beispiel #11
0
        private ISerializeArray ParseArray(ISerializeData Parent)
        {
            ISerializeArray array = new JSONSerializeArray(Parent);

            while (true)
            {
                MoveToNextChar();

                char c = GetChar();

                if (c == ']')
                {
                    break;
                }

                c = GetChar();

                if (c == '{')
                {
                    array.Add(ParseObject(array));
                }
                else if (c == '[')
                {
                    array.Add(ParseArray(array));
                }
                else
                {
                    bool isString = (c == '"');

                    if (isString)
                    {
                        array.Add(ReadLiteral());
                    }
                    else
                    {
                        array.Add(CastItem(ReadToken()));
                    }
                }

                MoveToNextChar();

                c = GetChar();
                if (c != ',')
                {
                    break;
                }
            }

            return(array);
        }
Beispiel #12
0
        public static object Bind(Type Type, ISerializeData Data)
        {
            if (Data == null)
            {
                return(null);
            }

            if (Data.GetType() == Type)
            {
                return(Data);
            }

            return(ObjectBinder.Bind(Data, Type));
        }
Beispiel #13
0
 public MainWindow(IMatrixAlgorithm matrixAlgorithm, IAiMove aiMove, ISerializeData serialize,
                   IDeSerializeData deserializeData, IIniParseData iniParseData, IDataBaseWriter dataBaseWriter)
 {
     this.matrixAlgorithm = matrixAlgorithm ?? throw new ArgumentNullException(nameof(matrixAlgorithm));
     this.aiMove          = aiMove ?? throw new ArgumentNullException(nameof(aiMove));
     this.serialize       = serialize ?? throw new ArgumentNullException(nameof(serialize));
     this.deserializeData = deserializeData ?? throw new ArgumentNullException(nameof(deserializeData));
     this.iniParseData    = iniParseData ?? throw new ArgumentNullException(nameof(iniParseData));
     this.dataBaseWriter  = dataBaseWriter ?? throw new ArgumentNullException(nameof(dataBaseWriter));
     this.settings        = new Settings
     {
         HistoryList = new List <History>()
     };
     this.gamePanel = new GamePanel();
     this.InitializeComponent();
     this.txtBoxTrackBar.Text = this.boardSizeTrackBar.Value.ToString();
 }
Beispiel #14
0
 public void PushBack(ISerializeData data)
 {
     data.PushBack(this);
 }
Beispiel #15
0
 public void Read(ISerializeData data)
 {
     data.Read(this);
 }
Beispiel #16
0
 public void Write(ISerializeData data)
 {
     data.Write(this);
 }
Beispiel #17
0
 public FilterComparableFromSerializable(FilterComparable fc, ISerializeData serializeData)
 {
     Fc            = fc;
     SerializeData = serializeData;
 }
Beispiel #18
0
 public DBTableData(ISerializeData data) : base(data)
 {
     this.Fields = new string[1] {
         "*"
     };
 }
 public JSONSerializeArray(ISerializeData Parent)
 {
     this.Parent = Parent;
 }
Beispiel #20
0
 public DBTableDataSqliteMemory(SqliteConnection cn, ISerializeData data) : base(data)
 {
     this.cn = cn;
 }
 public JSONSerializeObject(ISerializeData Parent)
 {
     this.Parent = Parent;
 }
        public BaseItem[] GetAllItems(string player_uuid = "")
        {
            List <BaseItem> items = new List <BaseItem>();

            string conn = GetDBPath();

            IDbConnection dbconn = (IDbConnection) new SqliteConnection(conn);

            dbconn.Open();

            #region DB Structure
            //CREATE TABLE `items` (
            // `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
            // `object_id`	TEXT DEFAULT '00000000-0000-0000-0000-000000000000',
            // `owner_id`	INTEGER NOT NULL,
            // `object_owner_id`	TEXT,
            // `type`	TEXT NOT NULL,
            // `data`	BLOB NOT NULL,
            // `position`	BLOB NOT NULL,
            // `rotation`	BLOB NOT NULL
            //);
            #endregion DB Structure

            IDbCommand dbcmd = dbconn.CreateCommand();
            string     sql   = "";
            if (string.IsNullOrEmpty(player_uuid))
            {
                sql = "SELECT id, item_uuid, type, data, properties " + "FROM items;";
            }
            else
            {
                sql = "SELECT id, item_uuid, type, data, properties " + "FROM items WHERE owner_uuid=\"" + player_uuid + "\";";
            }

            dbcmd.CommandText = sql;

            IDataReader reader = dbcmd.ExecuteReader();
            while (reader.Read())
            {
                //int id = reader.GetInt32(0);
                //string item_uuid = reader.GetString(1);
                //string type = reader.GetString(2);
                string data           = reader.GetString(3);
                string propertiesData = reader.GetString(4);


                var newData = Helper.FactoreData <SData>(data);

                BaseItem extItemDB = null;
                if (newData != null)
                {
                    ISerializeData iSerializeInterface = newData as ISerializeData;

                    if (iSerializeInterface != null)
                    {
                        extItemDB = iSerializeInterface.FactoryCloneItemFromData();
                    }
                    else
                    {
                        Debug.Log("The external DB item data does not implement the ISerializable interface");
                    }

                    IPropertySerializer propertySerializerInterface = extItemDB.BaseData.Properties as IPropertySerializer;
                    if (propertySerializerInterface != null)
                    {
                        propertySerializerInterface.Deserialize <List <Property> >(propertiesData);
                    }
                    else
                    {
                        Debug.Log("The external DB item data property does not implement the interface IPropertySerializer");
                    }
                }

                if (items.Contains(extItemDB) == false && extItemDB != null)
                {
                    items.Add(extItemDB);
                }
                else
                {
                    Debug.LogError("Trying to add a duplicated external DB item skipping.");
                }
            }

            reader.Close();
            reader = null;

            dbcmd.Dispose();
            dbcmd = null;

            dbconn.Close();
            dbconn = null;

            return(items.ToArray());
        }
Beispiel #23
0
 public static T Bind <T>(ISerializeData Data)
 {
     return((T)Bind(typeof(T), Data));
 }
        } // End of ImplDeserialize (...)

        protected virtual Boolean ImplSerializeData(SerializationContextType context)
        {
            ISerializeData tmp = context as ISerializeData;

            return(tmp == null || tmp.SerializeData);
        } // End of ImplSerializeData (...)
Beispiel #25
0
        private ISerializeObject ParseObject(ISerializeData Parent)
        {
            ISerializeObject obj = new JSONSerializeObject(Parent);

            while (true)
            {
                char c = GetChar();
                if (c == '}')
                {
                    break;
                }

                MoveToNextChar();

                c = GetChar();
                if (c != '"')
                {
                    break;
                }

                string key = ReadLiteral();

                MoveToNextChar();

                c = GetChar();
                if (c != ':')
                {
                    break;
                }

                MoveToNextChar();

                c = GetChar();

                if (c == '{')
                {
                    obj.Set(key, ParseObject(obj));
                }
                else if (c == '[')
                {
                    obj.Set(key, ParseArray(obj));
                }
                else
                {
                    bool isString = (c == '"');

                    if (isString)
                    {
                        obj.Set(key, ReadLiteral());
                    }
                    else
                    {
                        obj.Set(key, CastItem(ReadToken()));
                    }
                }

                MoveToNextChar();

                c = GetChar();
                if (c != ',')
                {
                    break;
                }
            }

            return(obj);
        }