Windows 通用应用尝试开发 “51单片机汇编”总结

1、前言数据库

  终于完成windows通用应用“51单片机汇编”,半年前开始玩WindowsPhone开发的第一个真正意义上的App(还不少缺点=_=)。开发从1月中旬考完试到今天,期间实习了半个月,玩了几天,算起来基本弄了3个多星期吧。很少说,总结总结。windows

 

2、开发数据准备app

  应用中主要的数据是单片机的汇编指令,我主要用XML文件来储存数据,没有使用SQLLite数据库,数据格式以下图:async

xml文件的数据是我手输入的,因此这是比较烦的。(可能有更简洁的办法获取数据)。ide

  而xml文件每一个每一个节点对应实例,如Code字节下的实例C#代码以下:工具

 public Code(String uniqueId, String title, String subtitle, String imagepath, String insertTime, String description, String exmaple, String comment,string collectFlag)
        {
            this.UniqueId = uniqueId;
            this.Title = title;
            this.Subtitle = subtitle;
            this.ImagePath = imagepath;
            this.InsertTime = insertTime;
            this.Description = description;
            this.Example = exmaple;
            this.Comment = comment;
            this.CollectFlag = collectFlag;
        }

     
        public Code()
        {
            // TODO: Complete member initialization
        }
        public string UniqueId { get; set; }
        public string Title { get; set; }
        public string Subtitle { get; set; }
        public string ImagePath { get; set; }

        public string InsertTime { get; set; }
        public string Description { get; set; }
        public string Example { get; set; }
        public string Comment { get; set; }
        public string CollectFlag { get; set; }
        public override string ToString()
        {
            return this.Title;
        }
    }

  从xml文件取出数据则利用Linq to Xml,部分C#代码以下:动画

 public static async Task<Code> GetCodeAsync(string uniqueId)
        {
            //await _sampleDataSource.GetSampleDataAsync();
            //var matches = _sampleDataSource.Groups.SelectMany(group => group.Items).SelectMany(item=>item.Codes).Where((code)=>code.UniqueId.Equals(uniqueId));
            //if (matches.Count() == 1) return matches.First();
            //return null;
            //Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.xml");
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
            StorageFolder localfolder = ApplicationData.Current.LocalFolder;
            StorageFile XMLfile = await localfolder.CreateFileAsync(FILENAME, CreationCollisionOption.OpenIfExists);
            string xmlText = await FileIO.ReadTextAsync(XMLfile);
            XDocument xmlObject;
            xmlObject = XDocument.Parse(xmlText);
            var data = (from query in xmlObject.Descendants("Code")
                        where query.Element("UniqueId").Value == uniqueId
                        select new Code((string)query.Element("UniqueId"),
                               (string)query.Element("Title"),
                                (string)query.Element("Subtitle"),
                                (string)query.Element("ImagePath"),
                                (string)query.Element("StoreFlag"),
                                (string)query.Element("Description"),
                              (string)query.Element("Example"),
                               (string)query.Element("Comment"),
                               XmlDataService.CheckHasAttributes(query))).FirstOrDefault();
            return data;
        }

PS:本来在程序中,我是直接从 利用Uri:ms-appx:///DataModel/SampleData.xml获取xml文件,同时后续操做对文件进行数据的改写,这种办法在WindowsPhone8.1彻底可行,但在Windows8.1中,该文件是只读的,不能这样操做,不然会出现ACCESSDENY错误。我只能在程序第一次启动时,把SampleData.xml文件复制到LocalFolder里了,而后App之后对数据进行读写,都是对复制的文件进行读写(相比读取Installation里的文件,读取LocalFolder的文件,Windows应用没有发现什么不一样,但在WinodwsPhone中,读取数据的操做相对慢点,在个人Lumia620 内存512M,感受比较卡,不知道有什么办法解决)。负责文件操做主要是在App.xaml.cs,C#代码以下:this

public App()
        {
            this.InitializeComponent();

            if ((string)localsetting.Values["IsHubFirstOpen"] != "true")
            {
                localsetting.Values["IsHubFirstOpen"] = "true";
                LoadXmlFile();
            }
            this.Suspending += this.OnSuspending;
        }
....
 public static async void LoadXmlFile()
        {
            string FILENAME = "CodeCopyFile.XML";
            StorageFolder localfolder = ApplicationData.Current.LocalFolder;
            var dataUri = new Uri("ms-appx:///DataModel/SampleData.xml");
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);  
            await file.CopyAsync(localfolder, FILENAME, NameCollisionOption.ReplaceExisting);
        }

 

2、对Xml文件数据进行改写spa

  这个App须要对用户的数据进行存储,我直接把用户本身的数据写到原文件中,好比App:设计

在Windows8.1中:

在WindowsPhone8.1中:

在两种平台都须要把用户本身的笔记保存下来。这里主要是对xml文件进行改写,十分简单,记录笔记方法C#代码以下:

public static async Task<bool> WriteComment(string uniqueId, string comment)
        {
            StorageFolder localfolder = ApplicationData.Current.LocalFolder;
            StorageFile XMLfile = await localfolder.CreateFileAsync(FILENAME, CreationCollisionOption.OpenIfExists);
            using (Stream stream = await XMLfile.OpenStreamForReadAsync())
            {
                XDocument xmlObject = XDocument.Load(stream);
                foreach (var codeValue in xmlObject.Descendants("Code").ToArray())
                {
                    if ((string)codeValue.Element("UniqueId") == uniqueId)
                    {
                        using (Stream newstream = await XMLfile.OpenStreamForWriteAsync())//这里须要注意,在修改编辑已存在的xml文件时须要设置Length=0,position=0,从新写。
                        {
                            DateTime time = DateTime.Now;
                            var insertTime = string.Format("修改时间:{0}年{1}月{2}日 {3}:{4}", time.Year, time.Month, time.Day, time.TimeOfDay.Hours, time.TimeOfDay.Minutes);
                            codeValue.SetElementValue("Comment", comment);
                            codeValue.SetElementValue("StoreFlag", insertTime);//修改时间
                            newstream.SetLength(0);
                            xmlObject.Save(newstream);
                            //   await newstream.FlushAsync();
                        }
                        return true;
                    }
                }
            }


            return false;
        }

 

3、UI

  本应用后台核心代码基本是对数据进行读写,这部分代码写好后,我就进行两个平台的UI设计了,说实话比较喜欢UI设计,挺好玩的。由于最开始学的就是WindowsPhone,WindowsPhone平台上的UI设计比较熟悉,比较快弄好,可是弄好后,一些界面在不一样分辨率的模拟器手机会有点不一样呈现,还须要以后的修改,比较喜欢本身设计的这个页面:

感受挺好的。

  至于Windows8.1,以前没有学过开发windowsApp,比较费力,并且该应用在Windows上体验应该比较差吧,若屏幕纵向,彻底不能看的节奏。在设计在Windows的App的 UI时,不少参考了@MS-UAP  http://www.cnblogs.com/ms-uap/  上面博客园的通用应用设计,好比TopBar基本是用MS-UAP的。

 

4、后续

  后续的话,代码整理整理。还有设计方面,在应用上小细节加一些WPF动画,感受挺炫的;应用功能方面,还能够增长单片机定时器、串口速率等计算工具...弄完了,爽!!最后祝你们羊年快乐,心愿成真,身体健康。祝本身在大三下学期找个好实习,大四找个好工做,万事如意!!!

 

你们感兴趣的能够,下载看看,初次开发,多多建议!

51单片机汇编 Windows Store 连接 :http://apps.microsoft.com/windows/app/51/b8ffef35-7fa7-45d5-9cd5-f2672bf9a8fe

51单片机汇编 WindowsPhone Store 连接:http://www.windowsphone.com/s?appid=3519c5ac-f013-4663-8eb9-fd536fdd8c8f

51单片机汇编 代码:http://pan.baidu.com/s/1sjpyXat   密码:7e6l

相关文章
相关标签/搜索