Exemple #1
0
        private T Deserialize <T>(SerializationHandler <T> handler, BufferReader br, Envelope env, bool isDynamic, bool isRaw, T objectToReuse, string typeName, IDictionary <string, TypeSchema> schemas)
        {
            if (isDynamic)
            {
                var deserializer = new DynamicMessageDeserializer(typeName, schemas);
                objectToReuse = deserializer.Deserialize(br);
            }
            else if (isRaw)
            {
                objectToReuse = (T)(object)Message.Create(br, env);
            }
            else
            {
                int currentPosition = br.Position;
                try
                {
                    handler.Deserialize(br, ref objectToReuse, this.context);
                }
                catch
                {
                    this.PsiStoreReader.EnsureMetadataUpdate();
                    br.Seek(currentPosition);
                    handler.Deserialize(br, ref objectToReuse, this.context);
                }
            }

            this.context.Reset();
            return(objectToReuse);
        }
Exemple #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            CurrentSaveFilePath = SerializationHandler.GetDefaultSavePath();
            // Load standard file
            SerializedDataContainer appData = SerializationHandler.LoadData(CurrentSaveFilePath);

            if (appData != null)
            {
                SetFileData(appData);
            }
            else
            {
                SetFileData(new SerializedDataContainer());
            }

            // Set file filter
            Application.Current.Resources.Add(Constants.FileFilterName, Constants.FileFilterString);

            // TODO
            // Create object relation
            // Load standard items into the app

            // Load main window
            MainWindow win = new MainWindow();

            win.Show();
        }
Exemple #3
0
        const int IDX_STATUS      = 4;  //监视状态列索引号
        public MainForm(string arg)
        {
            InitializeComponent();


            watcherList          = new List <XWXFileSystemWatcher>();
            serializationHandler = new SerializationHandler();
            FBD      = new FolderBrowserDialog();
            recorder = ModuleFactory.GetRecordModule();
            autoMode = new AutoModeHandler();
            this.NotifyIconContextMenu.Items[0].Click += delegate { System.Environment.Exit(0); };  //点击小图标退出按钮退出应用程序
            this.FormClosing           += new FormClosingEventHandler(MainForm_FormClosing);
            this.OnWatchSettingChanged += new SettingChangedHandler(HandleWatchSettingChanged);
            if (arg == "-automode")//如果包含-autoload参数,则自动加载之前的监视项记录
            {
                LoadWatches();
                this.WindowState = FormWindowState.Minimized;//自动模式下最小化
            }
            toolTip1.SetToolTip(chbAuto, "开机自动运行并恢复以往监视记录");
            chbAuto.Checked = autoMode.IsAutoModeON;
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval  = 600000;
            timer.Elapsed  += Timer_Elapsed;
            timer.AutoReset = true;
            timer.Enabled   = true;
        }
Exemple #4
0
        public MainWindow()
        {
            InitializeComponent();

            ConfigureRaffleHandler();


            #region Configure Question's Answers loader
            int[] indexes      = new List <string>(Properties.Settings.Default.AnswersIndex.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)).Select(s => int.Parse(s)).ToArray();
            int   forfeitIndex = Properties.Settings.Default.ForfeitIndex;
            #endregion

            #region configure players and records
            mPlayers = SerializationHandler.LoadPlayers(PlayersFile, forfeitIndex, indexes);
            mRecords.ValidatePlayers(ref mPlayers, Properties.Settings.Default.LotteryEngine != "Causality");
            #endregion

            #region Configure Lottery Engine
            if (Properties.Settings.Default.LotteryEngine == "Causality")
            {
                Lottery.CurrentEngine = Lottery.LotteryEngine.Causality;
            }
            else
            {
                Lottery.CurrentEngine = Lottery.LotteryEngine.Default;
            }
            #endregion

            //MarketImage();
        }
Exemple #5
0
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            bool isRunningFireworks = false;

            lock (mMutex)
            {
                isRunningFireworks = !mIsRunningEffect;
            }

            if (isRunningFireworks)
            {
                if (Key.Space == e.Key)
                {
                    displayWinnerName.Foreground = new SolidColorBrush(Colors.Black);
                    mIsRunningEffect             = true;

                    //displayWinnerName.Text = "Hello World";
                    Thread t = new Thread(DoRaffleRunningState);
                    t.Start();
                }
                else if (Key.Z == e.Key && (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != 0)
                {
                    SerializationHandler.RestoreRecords(LotteryRecordFile);
                    mRecords = SerializationHandler.LoadRecords(LotteryRecordFile);
                }
                else if (Key.S == e.Key)
                {
                    mRaffleStateHandler.ShowAnswer();
                }
            }
        }
Exemple #6
0
        public PropertiesForm(ProfilerProjectMode mode)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            projectMode = ProfilerProjectMode.CreateProject;

            project   = new ProjectInfo(ProjectType.File);
            this.Mode = mode;
            if (mode == ProfilerProjectMode.CreateProject)
            {
                List <string> files = SerializationHandler.GetRecentlyUsed();
                foreach (string file in files.GetRange(0, Math.Min(files.Count, 5)))
                {
                    LinkLabel label = new LinkLabel();
                    label.AutoSize = true;
                    label.Text     = file;
                    label.Click   += delegate
                    {
                        ProfilerForm.form.Project = SerializationHandler.OpenProjectInfo(label.Text);
                        Close();
                    };
                    recentProjects.Controls.Add(label);
                }
            }
        }
Exemple #7
0
        private bool SaveProject(ProjectInfo project, bool forceSaveDialog)
        {
            if (project == null)
            {
                return(true);
            }

            MessageBox.Show(this, "NOTE: You might not be able to load the data you're saving.  Please keep this in mind.", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            string filename = SerializationHandler.GetFilename(project);

            if (forceSaveDialog || filename == string.Empty)
            {
                SaveFileDialog saveDlg = new SaveFileDialog();

                saveDlg.DefaultExt = "nprof";
                saveDlg.FileName   = SerializationHandler.GetFilename(project);;
                saveDlg.Filter     = "NProf projects (*.nprof)|*.nprof|All files (*.*)|*.*";
                // saveDlg.InitialDirectory = TODO: store the most recently used direcotry somewhere and go there
                saveDlg.Title = "Save a NProf project file";

                if (saveDlg.ShowDialog(this) != DialogResult.OK)
                {
                    return(false);
                }

                project.Name = Path.GetFileNameWithoutExtension(saveDlg.FileName);
                filename     = saveDlg.FileName;
            }

            SerializationHandler.SaveProjectInfo(project, filename);

            return(true);
        }
Exemple #8
0
    private void CreateSoundPlatforms(List <AudioData> audioData)
    {
        for (int i = 0; i < audioData.Count; i++)
        {
            _bluePrints.Add(new SoundPlatformBluePrint(soundPlatformPrefab,
                                                       new PlatformProperties {
                clipIndex = i, color = colors[i % colors.Count], name = audioData[i].Title
            },
                                                       (int)BlueprintIndex.PlatformStart + i));
        }

        OnSetup?.Invoke(activeBlueprintId, _bluePrints.Count - 3);

        var defaultLevels = Directory.GetFiles(Path.Combine(Application.streamingAssetsPath, "DefaultLevels"), "*.json");
        var userLevels    = SerializationHandler.GetUserLevels();

        _levels.AddRange(defaultLevels);
        _levels.AddRange(userLevels);

        var levelNames = _levels.Select(Path.GetFileNameWithoutExtension).ToList();

        OnLevelSetup?.Invoke(levelNames);

        if (_levels.Count != 0)
        {
            LoadLevel(0);
        }
    }
Exemple #9
0
        public Proxier()
        {
            InitializeComponent();

            this.Text = $"Proxier v{Assembly.GetExecutingAssembly().GetName().Version}";
            SerializationHandler.DeserializeConfiguration();
            ProxyRouter.RoutingRequest += (o, e) => RequestsLog.AddObject((e as RoutingEventArgs));
        }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeserializerComponent{T}"/> class.
 /// </summary>
 /// <param name="pipeline">The pipeline to attach to.</param>
 /// <param name="serializers">A set of known serializers, or KnownSerializers.Default.</param>
 /// <param name="reusableInstance">An instance of type T to use as a deserialization buffer, or null / default(T) to let the component allocate one.</param>
 public DeserializerComponent(Pipeline pipeline, KnownSerializers serializers, T reusableInstance)
     : base(pipeline)
 {
     this.serializers      = serializers;
     this.context          = new SerializationContext(this.serializers);
     this.handler          = this.serializers.GetHandler <T>();
     this.reusableInstance = reusableInstance;
 }
Exemple #11
0
 public bool SaveFile(string fileName = null)
 {
     if (fileName != null)
     {
         CurrentSaveFilePath = fileName;
     }
     SerializationHandler.SaveDataToFile(GetSerializedData(), CurrentSaveFilePath);
     return(true);
 }
    //Deserialze packet and return our packet struct.
    public async Task <PosPacket> Recieve()
    {
        var result = await Client.ReceiveAsync();

        PosPacket temp = SerializationHandler.Deserialize <PosPacket>(result.Buffer);

        temp.Sender = result.RemoteEndPoint;
        return(temp);
    }
Exemple #13
0
        /// <summary>
        /// Converts the message into a sendable format
        /// </summary>
        /// <param name="msgContent"></param>
        /// <returns></returns>
        private NetOutgoingMessage prepareMsg(Message msgContent)
        {
            NetOutgoingMessage msg = server.CreateMessage();

            msg.Write((byte)msgContent.command);
            byte[] bytes = SerializationHandler.ObjectToByteArray(msgContent);
            msg.Write(bytes.Length);
            msg.Write(bytes);
            return(msg);
        }
Exemple #14
0
 private void Proxier_FormClosing(object sender, FormClosingEventArgs e)
 {
     SerializationHandler.SaveCurrent(ProxyRouter);
     SerializationHandler.Flush();
     ProcessHandler.ProcessesUpdated -= OnProcessesMonitorUpdate;
     ProxyRouter?.Dispose();
     try { ProcessHandler.Stop(); } catch { }
     try { ProcMonitorThread.Join(0); } catch { }
     try { ProcMonitorThread.Interrupt(); } catch { }
 }
        internal void MovePlayer(NetIncomingMessage msg)
        {
            int msgLength = msg.ReadInt32();

            byte[]            msgContents = msg.ReadBytes(msgLength);
            PlayerMoveMessage moveMsg     = (PlayerMoveMessage)SerializationHandler.ByteArrayToObject(msgContents);
            PlayerMove        move        = moveMsg.move; // TODO Do something with this

            gameServer.sendMsgToAll(moveMsg);
        }
Exemple #16
0
            public TypeSchema Initialize(KnownSerializers serializers, TypeSchema targetSchema)
            {
                this.handler = serializers.GetHandler <SharedContainer <T> >();
                var type        = this.GetType();
                var name        = TypeSchema.GetContractName(type, serializers.RuntimeVersion);
                var innerMember = new TypeMemberSchema("inner", typeof(SharedContainer <T>).AssemblyQualifiedName, true);
                var schema      = new TypeSchema(name, TypeSchema.GetId(name), type.AssemblyQualifiedName, TypeFlags.IsClass, new TypeMemberSchema[] { innerMember }, Version);

                return(targetSchema ?? schema);
            }
Exemple #17
0
        internal void AddPlayer(NetIncomingMessage msg)
        {
            int msgLength = msg.ReadInt32();

            byte[]            msgContents = msg.ReadBytes(msgLength);
            PlayerJoinMessage joinMsg     = (PlayerJoinMessage)SerializationHandler.ByteArrayToObject(msgContents);
            PlayerAttributes  player      = new PlayerAttributes(joinMsg.name, joinMsg.playerID, joinMsg.isHost, new Vector2(joinMsg.posX, joinMsg.posY));

            game.GameData.players.Add(player);
        }
        /// <summary>
        /// Sends the provided message to the server using reliable ordered delivery method
        /// </summary>
        /// <param name="msgContent"></param>
        public void sendMessage(Message msgContent)
        {
            NetOutgoingMessage msg = client.CreateMessage();

            msg.Write((byte)msgContent.command);
            byte[] bytes = SerializationHandler.ObjectToByteArray(msgContent);
            msg.Write(bytes.Length);
            msg.Write(bytes);
            client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
            client.FlushSendQueue();
        }
 //Reply by serializing the packet info and sending to everyone excpet the sender of the packet
 public void Reply(PosPacket packet, Dictionary <IPEndPoint, Guid> clients)
 {
     //Dont send back position values to the client who sent us the values
     foreach (KeyValuePair <IPEndPoint, Guid> client in clients)
     {
         if (client.Value != packet.userID)
         {
             var datagram = SerializationHandler.Serialize <PosPacket>(packet);
             Client.Send(datagram, datagram.Length, client.Key);
         }
     }
 }
Exemple #20
0
        private static void DoLottery()
        {
            List <Player> players = SerializationHandler.LoadPlayers(PlayersFile);
            Records       records = SerializationHandler.LoadRecords(LotteryRecordFile);

            records.ValidatePlayers(ref players);
            while (players.Count > 0)
            {
                Player winner = Lottery.GetWinner(records, players);
                SerializationHandler.SaveRecords(records, LotteryRecordFile);
            }
        }
Exemple #21
0
        private void _cmdFileRecentlyUsed_Click(object sender, EventArgs e)
        {
            Crownwood.Magic.Menus.MenuCommand pInfo = (Crownwood.Magic.Menus.MenuCommand)sender;
            string fileName = (string)pInfo.Tag;

            ProjectInfo project = SerializationHandler.OpenProjectInfo((string)pInfo.Tag);

            if (project != null)
            {
                _pic.Add(project);
                _pt.SelectProject(project);
            }
        }
Exemple #22
0
        internal void MovePlayer(NetIncomingMessage msg)
        {
            int msgLength = msg.ReadInt32();

            byte[]            msgContents = msg.ReadBytes(msgLength);
            PlayerMoveMessage moveMsg     = (PlayerMoveMessage)SerializationHandler.ByteArrayToObject(msgContents);
            PlayerMove        move        = moveMsg.move;

            if (game.GameData.clientsPlayerID != moveMsg.playerID)
            {
                game.GameData.getPlayer(moveMsg.playerID).currentMove = move;
            }
        }
        public void PlayerJoined(NetIncomingMessage msg)
        {
            int msgLength = msg.ReadInt32();

            byte[]            msgContents = msg.ReadBytes(msgLength);
            PlayerJoinMessage joinMsg     = (PlayerJoinMessage)SerializationHandler.ByteArrayToObject(msgContents);
            PlayerAttributes  player      = new PlayerAttributes(joinMsg.name, joinMsg.playerID, joinMsg.isHost);

            player.position = game.GameData.getSpawnPos();
            game.GameData.players.Add(player);
            gameServer.clientList.Add(new ClientInfo(msg.SenderConnection, player));
            logger.Debug("Player with name " + player.playerName + " added");
            ClientPlayerUpdate();
        }
Exemple #24
0
        /// <summary>
        /// Signs up a new user to Firebase
        /// </summary>
        /// <param name="email">User's email</param>
        /// <param name="password">User's password</param>
        /// <param name="callback">Executes if the user was created successfully, passes info on the newly created user</param>
        public static void SignUp(string email, string password, OnAuthSuccess callback)
        {
            var payload = $"{{\"email\":\"{email}\",\"password\":\"{password}\",\"returnSecureToken\":true}}";

            RestClient.Post(
                $"https://identitytoolkit.googleapis.com/v1/accounts:signUp?key={FirebaseInitializer.FirebaseInfo.apiKey}",
                payload).Then(
                response =>
            {
                var userInfo = new Dictionary <string, string>();
                SerializationHandler.FromJSONToObject(response.Text, out userInfo);
                callback(userInfo);
            }).Catch(Debug.Log);
        }
Exemple #25
0
        private T Deserialize <T>(SerializationHandler <T> handler, BufferReader br, T objectToReuse)
        {
            try
            {
                handler.Deserialize(br, ref objectToReuse, this.context);
            }
            catch
            {
                this.reader.EnsureMetadataUpdate();
                handler.Deserialize(br, ref objectToReuse, this.context);
            }

            this.context.Reset();
            return(objectToReuse);
        }
Exemple #26
0
        private void MRaffleStateHandler_StateChangeEvent(RaffleStateInterface.States state)
        {
            if (state == RaffleStateInterface.States.FireworksDone)
            {
                Player winner = Lottery.GetWinner(mRecords, mPlayers);
                SerializationHandler.SaveRecords(mRecords, LotteryRecordFile);

                mRaffleStateHandler.DisplayWinner(winner);

                lock (mMutex)
                {
                    mIsRunningEffect = false;
                }
            }
        }
Exemple #27
0
        public bool LoadDataFromFile(string fileName)
        {
            SerializedDataContainer appData = SerializationHandler.LoadData(fileName);

            if (appData != null)
            {
                SetFileData(appData);
                CurrentSaveFilePath = fileName;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #28
0
    private void PopulateDropdownMapSelection()
    {
        //load all save file names
        _hasSavedFiles = SerializationHandler.FetchSavefilesFromDisc(out List <string> savefiles);

        if (!_hasSavedFiles)
        {
            _loadMapButton.interactable = false;
            return;
        }

        _dropdownMapSelection.AddOptions(savefiles);
        _dropdownMapSelection.onValueChanged.AddListener(delegate {
            AcceptLoadedLevel(_dropdownMapSelection);
        });

        SetLoadLevelPanel(0);
    }
Exemple #29
0
    private void Awake()
    {
        _renderSetup = MAP_DATA.RENDER_SETUP;
        _mapConfig   = MAP_DATA.MAP_CONFIG;


        if (MAP_DATA.MAPSAVE == null)
        {
            LaunchNewPlaythrough();
        }
        else
        {
            LaunchNewPlaythrough(
                SerializationHandler.DeserializeTerrainData(),
                SerializationHandler.DeserializeTerrainTypes(),
                MAP_DATA.MAPSAVE.modelData
                );
        }
    }
Exemple #30
0
        private void _cmdFileOpen_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog openDlg = new OpenFileDialog();

            openDlg.DefaultExt = "nprof";
            openDlg.Filter     = "NProf projects (*.nprof)|*.nprof|All files (*.*)|*.*";
            // openDlg.InitialDirectory = TODO: store the most recently used directory somewhere and go there
            openDlg.Multiselect = true;
            openDlg.Title       = "Open a saved NProf project file";

            if (openDlg.ShowDialog(this) == DialogResult.OK)
            {
                foreach (string fileName in openDlg.FileNames)
                {
                    ProjectInfo project = SerializationHandler.OpenProjectInfo(fileName);
                    _pic.Add(project);
                    _pt.SelectProject(project);
                }
            }
        }