Esempio n. 1
0
        public void SaveFile(string fname)
        {
            List <JControlOutputData> lst = new List <JControlOutputData>();

            foreach (var c in stage.AllControls)
            {
                JWCControl jc = c as JWCControl;
                if (jc == null)
                {
                    continue;
                }
                lst.Add(jc.OutputProperty());
            }

            JWCSaveFile file = new JWCSaveFile();

            file.Width         = (int)stage.MainStage.Width;
            file.Height        = (int)stage.MainStage.Height;
            file.AllControls   = lst;
            file.BgUsePic      = stage.BgUsePic;
            file.BackGroundPic = stage.BgFilename;
            Color cl = stage.BgColor;

            file.BackColor = new byte[4] {
                cl.A, cl.R, cl.G, cl.B
            };

            file.Communicator = commu;
            file.ComAdapter   = adapter;
            file.ComName      = ComFname;
            file.AdaName      = AdaFname;

            file.Version = Assembly.GetExecutingAssembly().GetName().Version;

            JWCSerializer <JWCSaveFile> jse = new JWCSerializer <JWCSaveFile>();

            jse.Serialize(file, fname);
        }
Esempio n. 2
0
        public void LoadFile(string fname)
        {
            JWCSerializer <JWCSaveFile> jse = new JWCSerializer <JWCSaveFile>();
            JWCSaveFile file = jse.Deserialize(fname);

            stage.ClearAll(file.Width, file.Height);

            foreach (var s in file.AllControls)
            {
                string     fullname = s["FullName"].ToString();
                JWCControl jc       = JWCControlFactory.CreateInstance(fullname);
                jc.InputProperty(s);
                jc.IsEditMode = true;
                jc.Init(true);
                stage.AddControl(jc);
            }
            Color cl = Color.FromArgb(file.BackColor[0], file.BackColor[1], file.BackColor[2], file.BackColor[3]);

            stage.SetBg(file.BgUsePic, cl, file.BackGroundPic);
            commu    = file.Communicator;
            adapter  = file.ComAdapter;
            ComFname = file.ComName;
            AdaFname = file.AdaName;
        }
Esempio n. 3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SetRunFilePath();
            if (!System.IO.File.Exists(Filepath))
            {
                return;
            }

            JWCSerializer <JWCSaveFile> jse = new JWCSerializer <JWCSaveFile>();
            JWCSaveFile file = jse.Deserialize(this.Filepath);
            Color       cl   = Color.FromArgb(file.BackColor[0], file.BackColor[1], file.BackColor[2], file.BackColor[3]);

            Communicator = JWCCommunicatorFactory.CreateCommunicator(file.ComName);
            if (Communicator == null)
            {
                MessageBox.Show("创建通信器失败!这可能是由于没有导入相关插件导致的。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
                return;
            }
            Communicator.InputProperty(file.Communicator);
            Adaptor = JWCCommunicatorFactory.CreateAdapter(file.AdaName);
            if (Adaptor == null)
            {
                MessageBox.Show("创建适配器失败!这可能是由于没有导入相关插件导致的。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
                return;
            }
            Adaptor.InputProperty(file.ComAdapter);
            Adaptor.SetCommunicator(Communicator);

            foreach (var s in file.AllControls)
            {
                string     fullname = s["FullName"].ToString();
                JWCControl jc       = JWCControlFactory.CreateInstance(fullname);
                if (jc == null)
                {
                    MessageBox.Show("读入控件失败!这可能是由于没有导入相关插件导致的。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.Close();
                    return;
                }
                jc.InputProperty(s);
                jc.IsEditMode = false;
                jc.Init(false);
                jc.Parent = grid_main;
                grid_main.Children.Add(jc);
                IDataSender se = jc as IDataSender;
                if (se != null)
                {
                    Adaptor.AppendSender(se);
                }
                IDataReceiver re = jc as IDataReceiver;
                if (re != null)
                {
                    Adaptor.AppendReceiver(re);
                }
            }
            this.Height = grid_main.Height = file.Height;
            this.Width  = grid_main.Width = file.Width;
            SetBg(file.BgUsePic, cl, file.BackGroundPic);
            Communicator.Initialization();
            Adaptor.Initialization();
            Communicator.Start();
        }