Esempio n. 1
0
        /// <summary>
        /// 加载数据包
        /// </summary>
        /// <param name="strXapName">xap包名称</param>
        private void LoadData(string strXapName)
        {
            string          sDllSourceName  = string.Empty;
            AssemblyPart    asmPart         = null;
            List <XElement> deploymentParts = new List <XElement>();

            try
            {
                #region "直接加载xap包中的dll"
                dtstart = DateTime.Now;
                using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
                {
                    //打开本地xap包流
                    IsolatedStorageFileStream sXapfileStream = store.OpenFile(strXapName, FileMode.Open, FileAccess.Read);
                    if (sXapfileStream.Length == 0)
                    {
                        //IosManager.DeletFile(ApplicationPath, "SMT.SAAS.Platform.Main.xap");
                        List <string> dllNames = new List <string>();
                        dllNames.Add("SMT.SAAS.Platform.xap");
                        DownLoadDll(dllNames);
                    }

                    #region Original Code
                    StreamResourceInfo srXapSri       = new StreamResourceInfo(sXapfileStream, "application/binary");
                    Stream             manifestStream = Application.GetResourceStream(srXapSri, new Uri("AppManifest.xaml", UriKind.Relative)).Stream;

                    string appManifest = new StreamReader(manifestStream).ReadToEnd();
                    manifestStream.Close();
                    //Linq to xml
                    XElement deploymentRoot = XDocument.Parse(appManifest).Root;
                    deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements()
                                       select assemblyParts).ToList();
                    //检测所有包是否在本地,不在,就从服务器上下载
                    bool          canStart  = true;
                    List <string> dllDelete = new List <string>();
                    foreach (XElement xElement in deploymentParts)
                    {
                        if (xElement.Attribute("Source").Value.Contains("zip") &&
                            !IosManager.ExistsFile(strApplicationPath + @"/" + xElement.Attribute("Source").Value))
                        {
                            dllDelete.Add(xElement.Attribute("Source").Value);
                            canStart = false;
                        }
                    }
                    if (!canStart)
                    {
                        DownLoadDll(dllDelete);
                        return;
                    }

                    StreamResourceInfo streamInfo;
                    //Assembly assemblyViewModel = null;
                    string message = string.Empty;
                    foreach (XElement xElement in deploymentParts)
                    {
                        try
                        {
                            sDllSourceName = xElement.Attribute("Source").Value;
                            dtstart        = DateTime.Now;
                            //setLoadmingMessage( "正在加载:" + DllSourceName);
                            if (!sDllSourceName.Contains("zip"))
                            {
                                //直接加载dll
                                asmPart        = new AssemblyPart();
                                asmPart.Source = sDllSourceName;
                                streamInfo     = Application.GetResourceStream(new StreamResourceInfo(sXapfileStream, "application/binary"), new Uri(sDllSourceName, UriKind.Relative));

                                if (sDllSourceName == "SMT.SAAS.Platform.dll")
                                {
                                    asmMain = asmPart.Load(streamInfo.Stream);
                                }
                                else
                                {
                                    var a = asmPart.Load(streamInfo.Stream);
                                    message = message + a.FullName + System.Environment.NewLine + "从DLL文件中直接加载程序集: " + a.FullName;
                                }
                                streamInfo.Stream.Close();
                            }
                            else
                            {
                                //加载zip包
                                //setLoadmingMessage("正在加载:" + DllSourceName);
                                if (sDllSourceName.Contains("zip"))
                                {
                                    //打开本地zip包流
                                    IsolatedStorageFileStream zipfileStream = IosManager.GetFileStream(strApplicationPath + @"/" + sDllSourceName);
                                    streamInfo     = Application.GetResourceStream(new StreamResourceInfo(zipfileStream, "application/binary"), new Uri(sDllSourceName.Replace("zip", "dll"), UriKind.Relative));
                                    asmPart        = new AssemblyPart();
                                    asmPart.Source = sDllSourceName.Replace("zip", "dll");
                                    var a = asmPart.Load(streamInfo.Stream);
                                    streamInfo.Stream.Close();
                                    message = message + a.FullName + System.Environment.NewLine + "从Zip文件中加载程序集: " + a.FullName;
                                    SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage("从Zip文件中加载程序集: " + a.FullName);
                                }
                            }
                            dtend = DateTime.Now;
                            string strmsg = "加载成功:" + sDllSourceName + " 加载耗时: " + (dtend - dtstart).Milliseconds.ToString() + " 毫秒";
                            SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(strmsg);
                        }
                        catch (Exception ex)
                        {
                            string strmsg = "加载失败:" + sDllSourceName + " 错误信息: " + ex.ToString();
                            SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(strmsg);
                            SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                            setLoadmingMessage("系统加载出错,请联系管理员");
                            HtmlPage.Window.Invoke("loadCompletedSL", new string[] { "false", strmsg });
                            return;
                        }
                    }
                    message = string.Empty;;
                    #endregion
                }
                #endregion

                setLoadmingMessage("系统检测更新完毕,正在打开单据,请稍后...");

                //return;
                if (isFirstUser == true)
                {
                    //MainPage = asmMain.CreateInstance("SMT.SAAS.Platform.Xamls.MainPage") as UIElement;
                    uMainPage = asmMain.CreateInstance("SMT.SAAS.Platform.Xamls.MVCMainPage") as UIElement;
                    if (uMainPage == null)
                    {
                        MessageBox.Show("系统加载错误,请清空silverlight缓存后再试,或联系管理员");
                        setLoadmingMessage("系统加载错误,请清空silverlight缓存后再试,或联系管理员");
                        return;
                    }
                    AppContext.AppHost.SetRootVisual(uMainPage);
                }
            }
            catch (Exception ex)
            {
                HtmlPage.Window.Invoke("loadCompletedSL", new string[] { "false", ex.ToString() });
                this.txtUserMsg.Text = @"silverlight本地存储异常,请右键点击silverlight"
                                       + System.Environment.NewLine + "选择应用程序存储,然后点击全部删除后刷新页面再试";
                SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(sDllSourceName + " 加载系统出错:" + ex.ToString());
                SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 组件下载完成事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void webcDllVersion_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage("下载版本文件出错,请联系管理员" + e.Error.ToString());
                    SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                    return;
                }
                if (e.Result.Length < 1)
                {
                    SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage("获取服务器更新列表为空,请联系管理员");
                    SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                    Loginform.NotifyUserMessage("获取服务器更新列表出错,请联系管理员");
                    return;
                }
                Loginform.NotifyUserMessage("获取服务器更新列表成功,正在获取更新......");
                //将读取服务器下载的Dll Version XML
                StreamResourceInfo XapSri              = new StreamResourceInfo(e.Result, "text/xml");
                Stream             manifestStream      = XapSri.Stream;
                string             strVersionXmlServer = new StreamReader(manifestStream).ReadToEnd();
                //Linq to xml   manifestStream
                XElement dllVersionXElementServer     = XDocument.Parse(strVersionXmlServer).Root;
                var      dllVersionXElementlistServer = (from ent in dllVersionXElementServer.Elements().Elements()
                                                         select ent).ToList();

                //本地存在dllversion.xml文件
                if (IosManager.ExistsFile(dllVersionFilePath))
                {
                    //比较版本并下载新版本的dll及zip文件
                    IsolatedStorageFileStream xmlIsoStreamLocal = IosManager.GetFileStream(dllVersionFilePath);
                    StreamResourceInfo        XapSrilocal       = new StreamResourceInfo(xmlIsoStreamLocal, "text/xml");
                    Stream versionXmlStreamLocal = XapSrilocal.Stream;
                    string versionXmlLocal       = new StreamReader(versionXmlStreamLocal).ReadToEnd();
                    xmlIsoStreamLocal.Close();
                    if (string.IsNullOrEmpty(versionXmlLocal))
                    {
                        needDownDllNames = (from ent in dllVersionXElementlistServer
                                            select ent.Attribute("Source").Value).ToList();

                        DownLoadDll(needDownDllNames);
                        return;
                    }
                    XElement deploymentRoot       = XDocument.Parse(versionXmlLocal).Root;
                    var      dllVersionglistlocal = (from assemblyParts in deploymentRoot.Elements().Elements()
                                                     select assemblyParts).ToList();

                    var needUpdataDlls = from a in dllVersionXElementlistServer
                                         join b in dllVersionglistlocal
                                         on a.Attribute("Source").Value equals b.Attribute("Source").Value
                                             where a.Attribute("version").Value != b.Attribute("version").Value
                                         select a;

                    if (needUpdataDlls.Count() > 0)
                    {
                        Loginform.NotifyUserMessage("系统检测到更新,正在更新本地程序,请稍等......");
                        needDownDllNames = (from ent in needUpdataDlls
                                            select ent.Attribute("Source").Value).ToList();

                        DownLoadDll(needDownDllNames);
                    }
                    else
                    {
                        //判断是否所有dll都在本地存在,处理那种下载途中断网后的问题
                        List <string> needDownload = new List <string>();
                        foreach (var q in dllVersionglistlocal)
                        {
                            string filepath = strApplicationPath + @"/" + q.Attribute("Source").Value;
                            if (!IosManager.ExistsFile(filepath))
                            {
                                Loginform.NotifyUserMessage(@"silverlight本地存储异常,请右键点击silverlight
                                ,选择应用程序存储,然后点击全部删除后刷新页面再试");
                                needDownload.Add(q.Attribute("Source").Value);
                                break;
                            }
                        }
                        if (needDownload.Count() > 0)
                        {
                            //DownLoadDll(needDownload);
                        }
                        else
                        {
                            if (UpdateDllCompleted != null)
                            {
                                UpdateDllCompleted(this, null);
                            }
                        }
                    }
                }
                else
                {
                    //从服务器下载所有包
                    needDownDllNames = (from ent in dllVersionXElementlistServer
                                        select ent.Attribute("Source").Value).ToList();

                    DownLoadDll(needDownDllNames);
                }
            }
            catch (Exception ex)
            {
                SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage("更新系统出错,请联系管理员:" + ex.ToString());
                SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                Loginform.NotifyUserMessage("系统更新错误,请联系管理员");
            }
            finally
            {
                //存储versxml到本地
                byte[] streambyte = new byte[e.Result.Length];
                e.Result.Seek(0, SeekOrigin.Begin);
                e.Result.Read(streambyte, 0, streambyte.Length);
                e.Result.Close();
                IosManager.CreateFile(strApplicationPath, "DllVersion.xml", streambyte);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 组件下载完成事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void webcDllVersion_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    string msg = "下载版本文件出错,请联系管理员" + e.Error.ToString();
                    SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(msg);
                    SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                    HtmlPage.Window.Invoke("loadCompletedSL", new string[] { "false", msg });
                    return;
                }
                if (e.Result.Length < 1)
                {
                    SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage("获取服务器更新列表为空,请联系管理员");
                    SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                    txtUserMsg.Text = "获取服务器更新列表出错,请联系管理员";
                    HtmlPage.Window.Invoke("loadCompletedSL", new string[] { "false", txtUserMsg.Text });
                    return;
                }
                //txtUserMsg.Text = "获取服务器更新列表成功,正在获取更新......";
                //将读取服务器下载的Dll Version XML
                StreamResourceInfo sXapSri             = new StreamResourceInfo(e.Result, "text/xml");
                Stream             manifestStream      = sXapSri.Stream;
                string             strVersionXmlServer = new StreamReader(manifestStream).ReadToEnd();
                //Linq to xml   manifestStream
                XElement dllVersionXElementServer     = XDocument.Parse(strVersionXmlServer).Root;
                var      dllVersionXElementlistServer = (from ent in dllVersionXElementServer.Elements().Elements()
                                                         select ent).ToList();

                //本地存在dllversion.xml文件
                if (IosManager.ExistsFile(dllVersionFilePath))
                {
                    //比较版本并下载新版本的dll及zip文件
                    IsolatedStorageFileStream xmlIsoStreamLocal = IosManager.GetFileStream(dllVersionFilePath);
                    StreamResourceInfo        sXapSrilocal      = new StreamResourceInfo(xmlIsoStreamLocal, "text/xml");
                    Stream versionXmlStreamLocal = sXapSrilocal.Stream;
                    string versionXmlLocal       = new StreamReader(versionXmlStreamLocal).ReadToEnd();
                    xmlIsoStreamLocal.Close();
                    if (string.IsNullOrEmpty(versionXmlLocal))
                    {
                        needDownDllNames = (from ent in dllVersionXElementlistServer
                                            select ent.Attribute("Source").Value).ToList();

                        DownLoadDll(needDownDllNames);
                        return;
                    }
                    XElement deploymentRoot       = XDocument.Parse(versionXmlLocal).Root;
                    var      dllVersionglistlocal = (from assemblyParts in deploymentRoot.Elements().Elements()
                                                     select assemblyParts).ToList();

                    var needUpdataDlls = from a in dllVersionXElementlistServer
                                         join b in dllVersionglistlocal
                                         on a.Attribute("Source").Value equals b.Attribute("Source").Value
                                             where a.Attribute("version").Value != b.Attribute("version").Value
                                         select a;

                    if (needUpdataDlls.Count() > 0)
                    {
                        //txtUserMsg.Text = "系统检查到更新,正在更新本地程序,请稍等......";
                        needDownDllNames = (from ent in needUpdataDlls
                                            select ent.Attribute("Source").Value).ToList();

                        DownLoadDll(needDownDllNames);
                    }
                    else
                    {
                        //从本地加载系统
                        LoadData(strApplicationPath + @"/SMT.SAAS.Platform.xap");
                    }
                }
                else
                {
                    //从服务器下载所有包
                    needDownDllNames = (from ent in dllVersionXElementlistServer
                                        select ent.Attribute("Source").Value).ToList();

                    DownLoadDll(needDownDllNames);
                }
            }
            catch (Exception ex)
            {
                string msg = "更新系统出错,请联系管理员:" + ex.ToString();
                HtmlPage.Window.Invoke("loadCompletedSL", new string[] { "false", msg });
                SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(msg);
                SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                txtUserMsg.Text = "系统更新错误,请联系管理员";
            }
            finally
            {
                //存储versxml到本地
                byte[] streambyte = new byte[e.Result.Length];
                e.Result.Seek(0, SeekOrigin.Begin);
                e.Result.Read(streambyte, 0, streambyte.Length);
                e.Result.Close();
                IosManager.CreateFile(strApplicationPath, "DllVersion.xml", streambyte);
            }
        }
Esempio n. 4
0
        private void LoadAssemblyPart(Object state)
        {
            string          XapName         = strApplicationPath + @"/SMT.SAAS.Platform.xap";
            string          DllSourceName   = string.Empty;
            AssemblyPart    asmPart         = null;
            List <XElement> deploymentParts = new List <XElement>();

            try
            {
                #region "直接加载xap包中的dll"
                dtstart = DateTime.Now;
                using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
                {
                    //打开本地xap包流

                    IsolatedStorageFileStream XapfileStream = store.OpenFile(XapName, FileMode.Open, FileAccess.Read);
                    if (XapfileStream.Length == 0)
                    {
                        //IosManager.DeletFile(ApplicationPath, "SMT.SAAS.Platform.Main.xap");
                        List <string> dllNames = new List <string>();
                        dllNames.Add("SMT.SAAS.Platform.xap");
                        DownLoadDll(dllNames);
                    }

                    #region Original Code
                    StreamResourceInfo XapSri         = new StreamResourceInfo(XapfileStream, "application/binary");
                    Stream             manifestStream = Application.GetResourceStream(XapSri, new Uri("AppManifest.xaml", UriKind.Relative)).Stream;

                    string appManifest = new StreamReader(manifestStream).ReadToEnd();
                    manifestStream.Close();
                    //Linq to xml
                    XElement deploymentRoot = XDocument.Parse(appManifest).Root;
                    deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements()
                                       select assemblyParts).ToList();
                    //检测所有包是否在本地,不在,就从服务器上下载
                    bool          canStart  = true;
                    List <string> dllDelete = new List <string>();
                    foreach (XElement xElement in deploymentParts)
                    {
                        if (xElement.Attribute("Source").Value.Contains("zip") &&
                            !IosManager.ExistsFile(strApplicationPath + @"/" + xElement.Attribute("Source").Value))
                        {
                            dllDelete.Add(xElement.Attribute("Source").Value);
                            canStart = false;
                        }
                    }
                    if (!canStart)
                    {
                        DownLoadDll(dllDelete);
                        return;
                    }

                    StreamResourceInfo streamInfo;
                    //Assembly assemblyViewModel = null;
                    foreach (XElement xElement in deploymentParts)
                    {
                        try
                        {
                            DllSourceName = xElement.Attribute("Source").Value;
                            dtstart       = DateTime.Now;
                            //form.setLoadmingMessage( "正在加载:" + DllSourceName);
                            if (!DllSourceName.Contains("zip"))
                            {
                                //直接加载dll
                                asmPart        = new AssemblyPart();
                                asmPart.Source = DllSourceName;
                                streamInfo     = Application.GetResourceStream(new StreamResourceInfo(XapfileStream, "application/binary"), new Uri(DllSourceName, UriKind.Relative));

                                if (DllSourceName == "SMT.SAAS.Platform.dll")
                                {
                                    asmMain = asmPart.Load(streamInfo.Stream);
                                }
                                else
                                {
                                    var a = asmPart.Load(streamInfo.Stream);
                                }
                                streamInfo.Stream.Close();
                            }
                            else
                            {
                                //加载zip包
                                //form.setLoadmingMessage("正在加载:" + DllSourceName);
                                if (DllSourceName.Contains("zip"))
                                {
                                    //打开本地zip包流
                                    IsolatedStorageFileStream zipfileStream = IosManager.GetFileStream(strApplicationPath + @"/" + DllSourceName);
                                    streamInfo     = Application.GetResourceStream(new StreamResourceInfo(zipfileStream, "application/binary"), new Uri(DllSourceName.Replace("zip", "dll"), UriKind.Relative));
                                    asmPart        = new AssemblyPart();
                                    asmPart.Source = DllSourceName.Replace("zip", "dll");
                                    var a = asmPart.Load(streamInfo.Stream);
                                    streamInfo.Stream.Close();
                                    SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage("从Zip文件中加载程序集: " + a.FullName);
                                }
                            }
                            dtend = DateTime.Now;
                            string strmsg = "加载成功:" + DllSourceName + " 加载耗时: " + (dtend - dtstart).Milliseconds.ToString() + " 毫秒";
                            SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(strmsg);
                        }
                        catch (Exception ex)
                        {
                            string strmsg = "加载失败:" + DllSourceName + " 错误信息: " + ex.ToString();
                            SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(strmsg);
                            SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
                            Loginform.NotifyUserMessage("系统加载出错,请联系管理员");
                            return;
                        }
                    }

                    #endregion
                }
                #endregion

                Loginform.NotifyUserMessage("系统检测更新完毕,请您登录系统");
                Loginform.setbtnLoginEnable(true);
            }
            catch (Exception ex)
            {
                Loginform.NotifyUserMessage(@"silverlight本地存储异常,请右键点击silverlight
                                ,选择应用程序存储,然后点击全部删除后刷新页面再试");
                SMT.SAAS.Main.CurrentContext.AppContext.SystemMessage(DllSourceName + " 加载系统出错:" + ex.ToString());
                SMT.SAAS.Main.CurrentContext.AppContext.ShowSystemMessageText();
            }
        }