Exemplo n.º 1
0
    private void LoadCommandTool()
    {
        string       path      = Storage.Instance.DataPathUserData;
        CommandStore storeComm = Serializator.LoadXml <CommandStore>(path);

        if (storeComm == null)
        {
            Debug.Log("############ LoadCommandTool storeComm is Empty  path=" + path);
            return;
        }
        else
        {
            if (storeComm.CommadsTemplate == null)
            {
                Debug.Log("############ LoadCommandTool storeComm  CommadsTemplate is Empty");
                return;
            }
            if (storeComm.CommadsTemplate.Count == 0)
            {
                Debug.Log("---- LoadCommandTool storeComm  CommadsTemplate is zero");
                return;
            }
            ClearAllCommandButtonsTool();
            foreach (string nameCommand in storeComm.CommadsTemplate)
            {
                CreateCommandLogButton(nameCommand, Color.white, ContentListLogCommand.transform, null, true);
            }

            //Debug.Log("---- LoadCommandTool Loaded..........");
        }
    }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     Net.sendGamePacket(new NetPackett()
     {
         messageType = MessageType.GameLoaded, data = Serializator.serialize(Net.myLobbyID + ":" + Net.myMatchID)
     });                                                                                                                                                   //request
 }
Exemplo n.º 3
0
        /// <summary>
        ///  Deserialize information about the last logged in user; get information about user with such an id from server;
        ///  store user info in <c>CurrentUser</c> property
        /// </summary>
        private void DeserializeLastUser()
        {
            User userCandidate;

            try
            {
                userCandidate = Serializator.Deserialize <User>(FileFolderHelper.LastUserFilePath);
            }
            catch (Exception ex)
            {
                userCandidate = null;
                Logger.Log("Failed to Deserialize last user", ex);
            }
            if (userCandidate == null)
            {
                Logger.Log("User was not deserialized");
                return;
            }
            using (var restClient = new UserApiService())
            {
                userCandidate = restClient.GetUserByGuid(userCandidate.Guid);
            }
            if (userCandidate == null)
            {
                Logger.Log("Failed to relogin last user");
            }
            else
            {
                CurrentUser = userCandidate;
            }
        }
        public SerializableResolver(Serializator serializator, Type resolveType)
            : base(resolveType)
        {
            if (serializator == null)
            {
                throw new ArgumentNullException($"{nameof(SerializableResolver)}. Initializing was failed: serializator cant be null");
            }
            if (resolveType == null)
            {
                throw new ArgumentNullException($"{nameof(SerializableResolver)}. Initializing was failed: resolveType cant be null");
            }

            Serializator    = serializator;
            InstanceFactory = new UninitializedInstanceFactory(resolveType);

            Constructor = resolveType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, ConstructorSignature, null);
            if (Constructor == null)
            {
                throw new NotImplementedException($"{nameof(SerializableResolver)}. Initializing was failed: resolveType not implemented constructor with <SerializationInfo>, <StreamingContext> parameters");
            }

            var resolverStorage             = Serializator.GetResolverManager().Storage;
            var serializationInfoConvention = Serializator.GetTypeManager().ConventionOf(typeof(SerializationInfo));

            resolverStorage.SetResolver(new SerializationInfoResolver(serializator), serializationInfoConvention);
        }
    /// <summary>
    /// Перезаписать профиль и начать новую игру на нём
    /// </summary>
    public void CreateNewGame()
    {
        if ((saveNameInputPanel.text != string.Empty))
        {
            if (chosenButton != null)
            {
                SaveInfo sInfo = chosenButton.SInfo;
                sInfo.hasData                = true;
                sInfo.loadSceneName          = firstLevelName;
                sInfo.saveName               = saveNameInputPanel.text;
                sInfo.saveTime               = System.DateTime.Now.ToString();
                savesInfo.currentProfileNumb = savesInfo.saves.IndexOf(sInfo);

                PlayerPrefs.SetInt("Profile Number", savesInfo.currentProfileNumb);
                PlayerPrefs.SetFloat("Hero Health", 12f);
                PlayerPrefs.SetInt("Checkpoint Number", 0);

                createNewFadePanel.SetActive(false);
                Serializator.SaveXmlSavesInfo(savesInfo, savesInfoPath);
                Serializator.SaveXml(null, savePath + "Profile" + savesInfo.currentProfileNumb.ToString() + ".xml");
                SceneManager.LoadScene(firstLevelName);
            }
            else
            {
                OpenCreateNewGameWindow(false);
            }
        }
    }
        public void ConnectToServer(String username, String password, String serverIp)
        {
            try
            {
                _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _clientSocket.Connect(IPAddress.Parse(serverIp), Port);
                LogInfo("Установлено соединение с сервером");
                Request req = new CommandRequest();
                ((CommandRequest)req).Command     = CommandType.Authorize;
                ((CommandRequest)req).CommandInfo = String.Format("{0};{1}", username, password);
                byte[] toSend = Encoding.Unicode.GetBytes(Serializator.Serialize(req));
                _clientSocket.Send(toSend, 0, toSend.Length, SocketFlags.None);

                StartListening();
            }
            catch (SocketException exc)
            {
                LogInfo(exc.Message);
            }
            catch (Exception exc)
            {
                LogInfo(exc.Message);
                _clientSocket.Close();
            }
        }
Exemplo n.º 7
0
    public void SavePlayerXML()
    {
        Debug.Log("Saving player data....");
        string path = Storage.Instance.DataPathPlayer;

        Serializator.SaveXml <PlayerData>(m_playerDataGame, path, true);
    }
Exemplo n.º 8
0
        private void Serialize()
        {
            string path = Serializator.PathFromType(typeof(Gamer));

            lock (_lock)
            {
                // Open isolated storage.
                using (var isolatedStorageFile = Platform.GetUserStoreForApplication())
                {
                    // Open file from storage.
                    using (Stream stream = isolatedStorageFile.OpenFile(path, FileMode.Create))
                    {
                        using (BinaryWriter writer = new BinaryWriter(stream))
                        {
                            writer.Write(_achievementInfos.Count);

                            foreach (var ach in _achievementInfos)
                            {
                                writer.Write(ach.Key);
                                writer.Write(ach.Value.Completion);
                            }

                            writer.Write(_leaderboardInfos.Count);

                            foreach (var lb in _leaderboardInfos)
                            {
                                writer.Write(lb.Key);
                                writer.Write(lb.Value.Score);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void btnLoadFromXML_Click(object sender, EventArgs e)
        {
            string         path  = null;
            List <Product> lista = null;

            this.rtbFromXML.Text         = "";
            this.openFileDialog.Title    = "Browse XML file";
            this.openFileDialog.FileName = "Choose File";
            this.openFileDialog.Filter   = "xml files (*.xml)|*.xml";
            if (this.openFileDialog.ShowDialog() == DialogResult.OK)
            {
                path = openFileDialog.FileName;
                if (File.Exists(path))
                {
                    try
                    {
                        lista = new List <Product>();
                        Serializator <List <Product> > fromXML = new Serializator <List <Product> >();
                        lista = fromXML.OpenXML(path, lista);
                        foreach (Product item in lista)
                        {
                            this.rtbFromXML.Text += item.ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error while opening XML: " + ex.Message);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public IPackage Run()
        {
            Alive = true;
            UdpClient  Client   = new UdpClient(LocalPort);
            IPEndPoint remoteIp = null;

            try
            {
                while (Alive)
                {
                    byte[]       data = Client.Receive(ref remoteIp);
                    Serializator obj  = new Serializator();
                    IPackage     p    = obj.Deserialize(data);
                    return(p);
                }
                return(null);
            }
            catch (ObjectDisposedException)
            {
                if (!Alive)
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                Client.Close();
            }
        }
Exemplo n.º 11
0
        protected override void OnMessage(MessageEventArgs e)
        {
            var packet = Serializator.deserialize <NetData>(e.RawData);

            Session.instance.receiving.Add(packet);
            base.OnMessage(e);
        }
Exemplo n.º 12
0
        private static ScorePair NegaMax(ChessBoard chessBoard, int depth,
                                         MovePair lastMove = null)
        {
            Serializator ser = new Serializator();

            if (depth == 0)
            {
                return(new Tuple <int, MovePair>(
                           CountScore(chessBoard, chessBoard.CurrentPlayer), lastMove));
            }

            ScorePair maxS = new ScorePair(Int32.MinValue, null);

            List <Tuple <ChessPiece, Tuple <int, int> > > allMovesThisTurn = chessBoard
                                                                             .GetAllPossibleMoves()
                                                                             .FindAll(chessPieceNMoves => chessPieceNMoves.Item1.GetPlayer() == chessBoard.CurrentPlayer);

            foreach (var move in allMovesThisTurn)
            {
                ChessBoard chessBoardCopy = ser.DeepCopy(chessBoard);
                var        thisMove       = new MovePair(move.Item1.Position, move.Item2);

                if (chessBoardCopy.MovePiece(thisMove.Item1, thisMove.Item2))
                {
                    int score = -NegaMax(chessBoardCopy, depth - 1, thisMove).Item1;
                    if (score > maxS.Item1)
                    {
                        maxS = new ScorePair(score, thisMove);
                    }
                }
            }

            return(maxS);
        }
Exemplo n.º 13
0
        public void Init(int minDaysFromFirstUse, int minAppOpenings, int minDaysToRemind)
        {
            string version = Platform.CurrentVersion;

            bool loaded = true;

            _data = Serializator.Deserialize <AppRaterData>(Serializator.PathFromType(typeof(AppRaterData)));

            if (_data == null)
            {
                loaded = false;
                _data  = new AppRaterData();
            }

            _minDaysFromFirstUse = minDaysFromFirstUse;
            _minAppOpenings      = minAppOpenings;
            _minDaysToRemind     = minDaysToRemind;

            if (!loaded || (_data.DontRemindUntilNextVersion && version != _data.LastOpenedVersion))
            {
                _data.FirstUse                   = DateTime.Today;
                _data.LastTimeAsked              = DateTime.Today;
                _data.RemindLater                = false;
                _data.AppAlreadyRated            = false;
                _data.NumberOfAppOpenings        = 0;
                _data.LastOpenedVersion          = version;
                _data.FirstTime                  = true;
                _data.DontRemindUntilNextVersion = false;
                Serialize();
            }
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            IFileReader     textReader = new TextReader(Properties.Settings.Default.FilePath);
            List <TextLine> textLines  = (List <TextLine>)textReader.Read();

            if (textLines == null)
            {
                return;
            }

            List <Word> wordsInText = (TextLine.Parse(textLines));

            Console.WriteLine(Parser.GetCorcodance(wordsInText));
            try
            {
                Serializator.SerializeConcordance(wordsInText);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            wordsInText.Clear();
            try
            {
                wordsInText = Serializator.DeserializeConcordance();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
 private void ReceiveCallback(IAsyncResult result)
 {
     try
     {
         int bytesReceived = ((Socket)result.AsyncState).EndReceive(result);
         if (bytesReceived != 0)
         {
             String respStr = Encoding.Unicode.GetString(_inbuffer);
             respStr  = respStr.Substring(0, respStr.IndexOf('\0'));
             Responce = Serializator.DeserializeResponce(respStr);
             if (Responce is AnalyzeResponce)
             {
                 _dbprovider.SaveReport(Responce as AnalyzeResponce);
             }
             OnResponceReceived();
             _inbuffer = new byte[512];
             _clientSocket.BeginReceive(_inbuffer, 0, _inbuffer.Length, SocketFlags.None, ReceiveCallback, _clientSocket);
         }
         else
         {
             _clientSocket.Close();
         }
     }
     catch (ObjectDisposedException)
     {
         LogInfo("Получение данных остановлено;");
     }
     catch (Exception exc)
     {
         _clientSocket.Close();
         LogInfo(exc.Message);
     }
 }
Exemplo n.º 16
0
        public void WriteTest()
        {
            var serializator = new Serializator();
            var catalog      = new Catalog()
            {
                Date  = DateTime.Now,
                Books = new List <Book>
                {
                    new Book
                    {
                        Author           = "Mikhail",
                        Description      = "test",
                        Genre            = "test",
                        Id               = "test",
                        Isbn             = "test",
                        PublishDate      = DateTime.Now,
                        Publisher        = "test",
                        RegistrationDate = DateTime.Now,
                        Title            = "test"
                    }
                }
            };

            serializator.WriteXml(catalog, $"{_path}books2.xml", "http://library.by/catalog");


            Assert.IsTrue(File.Exists($"{_path}books2.xml"));
            Assert.IsTrue(File.ReadAllLines($"{_path}books2.xml").Length > 0);
        }
Exemplo n.º 17
0
        public void DeserializeXmlExeption_NullPath()
        {
            Thinkpad notebook = null;
            Serializator <Thinkpad> serializer = new Serializator <Thinkpad>();

            notebook = serializer.OpenXML(null, notebook);
        }
Exemplo n.º 18
0
        private static ScorePair AlphaBetaMax(ChessBoard chessBoard, int alpha, int beta, int depth)
        {
            if (depth == 0)
            {
                return(new ScorePair(CountScore(chessBoard, chessBoard.CurrentPlayer), null));
            }
            Serializator ser = new Serializator();
            List <Tuple <ChessPiece, Tuple <int, int> > > allMovesThisTurn = chessBoard
                                                                             .GetAllPossibleMoves()
                                                                             .FindAll(chessPieceNMoves => chessPieceNMoves.Item1.GetPlayer() == chessBoard.CurrentPlayer);

            MovePair bestMove = null;

            foreach (var move in allMovesThisTurn)
            {
                ChessBoard chessBoardCopy = ser.DeepCopy(chessBoard);
                var        thisMove       = new MovePair(move.Item1.Position, move.Item2);
                if (chessBoardCopy.MovePiece(thisMove.Item1, thisMove.Item2))
                {
                    var score = AlphaBetaMin(chessBoardCopy, alpha, beta, depth - 1).Item1;
                    if (score >= beta)
                    {
                        return(new ScorePair(beta, null)); // fail hard beta-cutoff
                    }
                    if (score > alpha)
                    {
                        alpha    = score; // alpha acts like max in MiniMax
                        bestMove = thisMove;
                    }
                }
            }

            return(new ScorePair(alpha, bestMove));
        }
Exemplo n.º 19
0
        private ConvertorParams readCofigFile()
        {
            string          formSettingsFullPath = Path.Combine(userDocumentsPath, formSettingsDirectoryName, formSettingsFileName);
            ConvertorParams convertorParams;

            if (Serializator.Read <ConvertorParams>(formSettingsFullPath) != null)
            {
                convertorParams = Serializator.Read <ConvertorParams>(formSettingsFullPath);
            }
            else
            {
                convertorParams = new ConvertorParams();
            }

            if (fullFilePathWithExtentions != null)
            {
                string fileFormat = Path.GetExtension(fullFilePathWithExtentions);
                convertorParams.ReadFilePath = $"{Path.GetDirectoryName(fullFilePathWithExtentions)}\\{Path.GetFileNameWithoutExtension(fullFilePathWithExtentions)}";
                foreach (FileExtention value in Enum.GetValues(typeof(FileExtention)))
                {
                    if (value.GetFileExtension() == fileFormat)
                    {
                        convertorParams.ReadFileExtention = value;
                        break;
                    }
                    convertorParams.ReadFileExtention = FileExtention.uknown;
                }
            }
            return(convertorParams);
        }
Exemplo n.º 20
0
        public void ReadTest()
        {
            var serializator = new Serializator();
            var result       = serializator.ReadXml($"{_path}books.xml", "http://library.by/catalog");

            Assert.IsTrue(result.Books.Count == 12);
            Assert.IsTrue(result.Books[11].Id == "bk112");
        }
Exemplo n.º 21
0
 public static void CreateSavesInfo()
 {
     Serializator.SaveXmlSavesInfo(new SavesInfo(3), "Assets/StreamingAssets/SavesInfo.xml");
     Serializator.SaveXml(null, "Assets/StreamingAssets/Saves/Profile0.xml");
     Serializator.SaveXml(null, "Assets/StreamingAssets/Saves/Profile1.xml");
     Serializator.SaveXml(null, "Assets/StreamingAssets/Saves/Profile2.xml");
     PlayerPrefs.SetInt("Checkpoint Number", 0);
 }
Exemplo n.º 22
0
 public FeedViewModel()
 {
     Favourites = Serializator.DeserializeList();
     ResetFeed();
     Items    = new Hashtable();
     FeedUrls = new ObservableCollection <string>();
     GetSubscriptions();
 }
        public override sealed void Serialize(XElement serialized, object obj)
        {
            var leng = Fields.Count;

            for (int i = 0; i < leng; i++)
            {
                serialized.Add(Serializator.AutoResolve(Fields[i].GetValue(obj)));
            }
        }
Exemplo n.º 24
0
 private static void ClientSocketGame_OnMessage(object sender, MessageEventArgs e)
 {
     if (e.IsBinary)
     {
         NetPackett packet = new NetPackett();
         packet = Serializator.DeserializeNetPackett(e.RawData);
         receiving.Add(packet);
     }
 }
Exemplo n.º 25
0
    public void SaveTilesData()
    {
        TilesData tilesDataSavw = new TilesData()
        {
            TilesD = m_CollectionDataMapTiles
        };

        Serializator.SaveTilesDataXml(tilesDataSavw, Storage.Instance.DataPathTiles, true);
    }
Exemplo n.º 26
0
    Labr GetLabr(int LabrSize)
    {
        byte[] data = new byte[LabrSize];

        reader.Read(data, 0, LabrSize);

        Labr result = Serializator.ByteArrayToObject(data) as Labr;

        return(result);
    }
Exemplo n.º 27
0
 public MultirankArrayResolver(Type resolveType, Serializator serializator) : base(resolveType)
 {
     if (!resolveType.IsArray)
     {
         throw new ArgumentException($"MultirankArrayResolver. Initializing was failed: {nameof(resolveType)} is not array");
     }
     ElementType  = resolveType.GetElementType();
     Rank         = resolveType.GetArrayRank();
     Serializator = serializator ?? throw new ArgumentNullException($"MultirankArrayResolver. Initializing was failed: ");
 }
Exemplo n.º 28
0
    /// <summary>
    /// Сбросить прогресс уровня
    /// </summary>
    public void ResetLevelData()
    {
        GameData gData = Serializator.DeXml(datapath + profileNumber.ToString() + ".xml");

        if (gData != null)
        {
            gData.ResetLevelData();
        }
        Serializator.SaveXml(gData, datapath + profileNumber.ToString() + ".xml");
    }
Exemplo n.º 29
0
 public void LoadPlayerData()
 {
     Debug.Log("Loading player data....");
     m_playerDataGame = Serializator.LoadXml <PlayerData>(Storage.Instance.DataPathPlayer);
     if (m_playerDataGame == null)
     {
         Debug.Log("############## LoadPlayerData is empty : path=" + Storage.Instance.DataPathPlayer);
         m_playerDataGame = new PlayerData();
     }
 }
Exemplo n.º 30
0
    /*
     * public void SaveLevelParts()
     * {
     *
     *  Storage.GenGrid.SaveAllRealGameObjects();
     *  if (Storage.Instance.GridDataG == null)
     *  {
     *      Debug.Log("Error SaveLevel gridData is null !!!");
     *      return;
     *  }
     *  Serializator.SaveGridPartsXml(Storage.Instance.GridDataG, Storage.Instance.DataPathLevel, true);
     * }
     */

    public void SaveLevelCash()
    {
        Storage.GenGrid.SaveAllRealGameObjects();
        if (Storage.Instance.GridDataG == null)
        {
            Debug.Log("Error SaveLevel gridData is null !!!");
            return;
        }
        Serializator.SaveGridCashXml(Storage.Instance.GridDataG, Storage.Instance.DataPathLevel, true);
    }
Exemplo n.º 31
0
        private void Save()
        {
            Serializator serializator = new Serializator ();

            serializator.Set (offenceAreas.Count);
            for (int index = 0; index < offenceAreas.Count; index++) {
                serializator.Set (offenceAreas [index]);
                serializator.Set (offenceTimes [index]);
            }

            serializator.Save (offenceDataKey);
        }
Exemplo n.º 32
0
        private void Load()
        {
            var serializator = new Serializator ();
            if (!serializator.Load (GetSerKey ()))
                return;

            uint size;
            serializator.Get (out size);
            for (uint i = 0; i < size; i++) {
                uint critterId;
                serializator.Get (out critterId);
                Item container;
                serializator.Get (out container);
                if (container == null)
                    continue;
                critterContainerMap.Add (critterId, container);
            }
        }
Exemplo n.º 33
0
        private void Load()
        {
            Serializator serializator = new Serializator ();
            if (!serializator.Load (offenceDataKey))
                return;

            offenceAreas = new List<uint> ();
            offenceTimes = new List<ulong> ();
            uint count = 0;
            serializator.Get (out count);
            for (int index = 0; index < count; index++) {
                uint area;
                serializator.Get (out area);
                offenceAreas.Add (area);
                ulong time;
                serializator.Get (out time);
                offenceTimes.Add (time);
            }
        }
Exemplo n.º 34
0
        private void Save()
        {
            var serializator = new Serializator ();

            serializator.Set ((uint)critterContainerMap.Count);
            foreach (var container in critterContainerMap) {
                serializator.Set (container.Key);
                serializator.Set (container.Value.Id);
            }

            serializator.Save (GetSerKey ());
        }