private void AppendImage(GadgetItemOnline item, DataRow dr, string key)
 {
     if (dr[key] != null)
     {
         item.SnapshotList.Add(new AppImage(dr[key].ToString()));
     }
 }
示例#2
0
        private bool app_Filter(object item)
        {
            TypeItem typeItem = this.headerListBox.SelectedItem as TypeItem;

            if (typeItem == null)
            {
                return(false);
            }

            if (item is AppItem)
            {
                AppItem gadgetItem = item as AppItem;
                if (typeItem.Type == gadgetItem.Type)
                {
                    return(true);
                }
            }
            else
            {
                GadgetItemOnline onlineItem = item as GadgetItemOnline;
                if (typeItem.Type == onlineItem.AppSubType ||
                    typeItem.Type < 0)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        private void StartInstall()
        {
            GadgetItemOnline item = this.appListBox.SelectedItem as GadgetItemOnline;

            if (item == null)
            {
                return;
            }

            AppInstallMgr.Instance.Start(item);
        }
示例#4
0
        private string GetTempFile(GadgetItemOnline item)
        {
            Assembly assembly   = Assembly.GetExecutingAssembly();
            string   tempFolder = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(assembly.Location), "temp");

            if (!Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
            }

            return(System.IO.Path.Combine(tempFolder, item.Id + ".zip"));
        }
        private void ShowCategory(GadgetItemOnline item)
        {
            TypeItem typeItem    = DataMgr.Instance.LocalTypeCollection.GetById(item.AppType);
            TypeItem subTypeItem = DataMgr.Instance.LocalTypeCollection.GetById(item.AppSubType);

            if (typeItem != null)
            {
                this.categroyTextBlock.Text = typeItem.Title;
            }
            if (subTypeItem != null)
            {
                this.categroyTextBlock.Text += " >> ";
                this.categroyTextBlock.Text += subTypeItem.Title;
            }
        }
示例#6
0
        internal void Start(GadgetItemOnline item)
        {
            lock (this.collectionLocker)
            {
                if (Enumerable.Count <AppInstallItem>(this.installingAppCollection, (c) => (c.AppItem.Id == item.Id)) > 0)
                {
                    return;
                }
            }

            string tempPackFile = this.GetTempFile(item);

            HttpHelper helper = new HttpHelper();

            AppInstallItem appInstallItem = new AppInstallItem(item, helper, tempPackFile);

            lock (this.collectionLocker)
            {
                this.installingAppCollection.Add(appInstallItem);
            }

            this.InitHttpHelper(helper, appInstallItem);

            if (this.runningItem != null)
            {
                return;
            }

            this.UpdateState(InstallState.Downloading, appInstallItem);

            this.runningItem = appInstallItem;
            try
            {
                this.runningItem.WebClient.DownloadFileAsync(this.runningItem.AppItem.PackageUrl, this.runningItem.LocakPackFile);
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
                this.UpdateState(InstallState.DownloadFail, this.runningItem);
                this.runningItem = null;
                this.Next();
            }
        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            GadgetItemOnline item = this.DataContext as GadgetItemOnline;

            this.appItem = DataMgr.Instance.getAppItemById(item.UniqueId);
            var query = from temp in AppInstallMgr.Instance.AppInstallItems
                        where temp.AppItem.UniqueId == item.UniqueId
                        select temp;

            if (appItem != null)
            {
                MainWindow mainWnd = App.Current.MainWindow as MainWindow;
                mainWnd.Activate();
                mainWnd.LoadGadget(this.appItem);

                foreach (Window wnd in App.Current.Windows)
                {
                    if (wnd is AppStoreWindow)
                    {
                        wnd.Close();
                    }
                }
            }
            else
            {
                if (query.Count() > 0)
                {
                    this.addButton.Content = "正在安装";
                }
                //else if (item.Price > 0)
                //{

                //}
                else
                {
                    AppInstallMgr.Instance.Start(this.DataContext as GadgetItemOnline);
                    this.addButton.Content = "正在安装";
                }
            }
        }
示例#8
0
        private bool ExtractPackFile()
        {
            try
            {
                double price = 0.0f;
                if (!double.TryParse(this.priceTextBox.Text, out price))
                {
                    MessageBox.Show("请为应用输入正确的价格。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(false);
                }

                //     string userId = this.userIdTextBox.Text;
                //     string password = this.passwordTextBox.Password;
                if (string.IsNullOrEmpty(userId))
                {
                    MessageBox.Show("请输入注册用的邮箱或者登陆ID。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(false);
                }

                if (string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("请输入密码。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(false);
                }


                FileStream fs = File.OpenRead(this.packageFile);

                // Check File Header
                string fileHeader = this.ReadString(fs);
                if (fileHeader != "{B5F6844E-984C-4129-8D19-79FDEFBDD5DC}" &&
                    fileHeader != "{BE4A1507-5B37-42EA-9E08-43EF4F363C42}" &&
                    fileHeader != "{8D2C2705-B49D-4730-BF39-B0E7E0E09172}")
                {
                    MessageBox.Show("安装包格式不正确。", "上传应用", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }

                // Check AppTitle and AppId
                string appId    = this.ReadString(fs);
                string appTitle = this.ReadString(fs);

                this.appItem = new GadgetItemOnline();

                appItem.Id    = appId;
                appItem.Title = appTitle;
                // Description
                appItem.Description = this.ReadString(fs);

                // Logos
                appItem.Thumbnail = this.ExtractLogo(fs, appId);

                // Entry File;
                string temp = this.ReadString(fs);
                temp = this.ReadString(fs);

                appItem.AppType    = BitConverter.ToInt32(this.ReadBytes(fs), 0);
                appItem.AppSubType = BitConverter.ToInt32(this.ReadBytes(fs), 0);
                appItem.CreateDate = DateTime.Parse(this.ReadString(fs));

                appItem.Creator        = this.ReadString(fs);
                appItem.CreatorLogo    = this.ReadString(fs);
                appItem.CreatorWebSite = this.ReadString(fs);

                fs.Close();
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
                StringBuilder strBuilder = new StringBuilder("安装包格式错误.");
                strBuilder.AppendLine(ex.Message);
                MessageBox.Show(strBuilder.ToString(), "上传应用", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            return(true);
        }
        internal void ShowAppItem(GadgetItemOnline item)
        {
            this.DataContext = item;

            this.createTimeTextBlock.Text = item.CreateDate.ToLocalTime().ToString();
            this.priceTextBlock.Text      = string.Format("{0}元", item.Price.ToString()) + "(推广期,免费使用)";

            this.ShowCategory(item);

            this.appItem = DataMgr.Instance.getAppItemById(item.UniqueId);
            var query = from temp in AppInstallMgr.Instance.AppInstallItems
                        where temp.AppItem.UniqueId == item.UniqueId
                        select temp;

            if (appItem != null)
            {
                this.addButton.Content = "打开";
            }
            else
            {
                if (query.Count() > 0)
                {
                    this.addButton.Content = "正在安装";
                }
                //else if (item.Price > 0)
                //{

                //}
                else
                {
                    this.addButton.Content = "添加";
                }
            }

            this.snapshotListBox.ItemsSource = null;
            this.authorTextBlock.Text        = string.Empty;

            UserPaidInfo userPaidInfo = null;

            if (item.SnapshotList.Count == 0)
            {
                this.IsEnabled = false;

                BackgroundWorker worker = new BackgroundWorker();
                worker.WorkerSupportsCancellation = true;
                worker.WorkerReportsProgress      = true;
                worker.DoWork += ((s, e) =>
                {
                    string strRet = DataMgr.Instance.AppService.GetAppAttachInfo(Convert.ToInt32(item.Id), item.CreatorId, LoginInfo.GetMD5Hash("4%!@s*&d"));
                    if (!string.IsNullOrEmpty(strRet))
                    {
                        string[] strRets = strRet.Split(new string[] { "||" }, StringSplitOptions.None);
                        item.Creator = strRets[0];
                        if (strRets.Length > 1)
                        {
                            item.SnapshotList.Add(new AppImage(strRets[1]));
                            if (strRets.Length > 2)
                            {
                                item.SnapshotList.Add(new AppImage(strRets[2]));
                            }
                            if (strRets.Length > 3)
                            {
                                item.SnapshotList.Add(new AppImage(strRets[3]));
                            }
                            if (strRets.Length > 4)
                            {
                                item.SnapshotList.Add(new AppImage(strRets[4]));
                            }
                            if (strRets.Length > 5)
                            {
                                item.SnapshotList.Add(new AppImage(strRets[5]));
                            }
                        }
                    }

                    //try
                    //{
                    //    userPaidInfo = DataMgr.Instance.AppService.GetUserPaidInfo(item.UniqueId,
                    //        DataMgr.Instance.LoginInfo.LoginId,
                    //        DataMgr.Instance.LoginInfo.Password,
                    //        LoginInfo.GetMD5Hash("##32*d_&"));
                    //}
                    //catch (Exception ex)
                    //{
                    //    Debug.Assert(false, ex.Message);
                    //}
                });
                worker.RunWorkerCompleted += ((s, e) =>
                {
                    this.snapshotListBox.ItemsSource = item.SnapshotList;
                    this.authorTextBlock.Text = item.Creator;
                    this.IsEnabled = true;

                    if (item.Price > 0 && userPaidInfo != null)
                    {
                        // Temp no need paid
                        if (userPaidInfo == null || userPaidInfo.Paid)
                        {
                            this.addButton.Content = "添加";
                        }
                        else
                        {
                            this.addButton.Content = "购买";
                            Style style = App.Current.TryFindResource("ButtonStyle_IconBtn_Single") as Style;
                            if (style != null)
                            {
                                this.addButton.Style = style;
                            }
                        }
                    }
                });
                worker.RunWorkerAsync();
            }
            else
            {
                this.snapshotListBox.ItemsSource = item.SnapshotList;
                this.authorTextBlock.Text        = item.Creator;
            }
        }
示例#10
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string method = "DownNum";
                if (this.SubTypeId == TypeItem.New ||
                    this.TypeId == TypeItem.New)
                {
                    method = "AddDate";
                }

                DataTable dt = null;
                if (this.TypeId != TypeItem.NotApproved)
                {
                    dt = DataMgr.Instance.AppService.GetAppList(pageIndex,
                                                                maxRetriveCount,
                                                                Convert.ToInt32(DataMgr.Instance.LoginInfo.Id),
                                                                this.TypeId,
                                                                this.SubTypeId,
                                                                method,
                                                                ref totalPage,
                                                                ref totalRecord,
                                                                LoginInfo.GetMD5Hash("$df@#d^&"));
                }
                else
                {
#if DEBUG
                    dt = this.getNotApproveApps();
#endif
                }

                List <GadgetItemOnline> tempList = new List <GadgetItemOnline>();
                foreach (DataRow dr in dt.Rows)
                {
                    Debug.WriteLine("{0}", dr);
                    GadgetItemOnline itemOnline = new GadgetItemOnline();
                    itemOnline.Id              = dr["ID"].ToString();
                    itemOnline.Thumbnail       = dr["ICON"] as string;
                    itemOnline.PackageUrl      = dr["FileUrl"] as string;
                    itemOnline.Title           = dr["Name"] as string;
                    itemOnline.AppType         = Convert.ToInt32(dr["ClassID"]);
                    itemOnline.AppSubType      = Convert.ToInt32(dr["SubClassID"]);
                    itemOnline.Description     = dr["Sketch"] as string;
                    itemOnline.LongDescription = dr["Detail"] as string;
                    itemOnline.CreateDate      = Convert.ToDateTime(dr["AddDate"]);
                    itemOnline.CreatorId       = Convert.ToInt32(dr["UserID"]);
                    itemOnline.Version         = dr["Version"] as string;
                    itemOnline.UniqueId        = dr["UniqueId"] as string;
                    itemOnline.Price           = Convert.ToSingle(dr["Price"]);
                    if (!string.IsNullOrEmpty(itemOnline.UniqueId))
                    {
                        itemOnline.UniqueId = itemOnline.UniqueId.Trim();
                    }

                    TypeItem typeItem = DataMgr.Instance.LocalTypeCollection.GetById(itemOnline.AppSubType);
                    if (typeItem != null)
                    {
                        itemOnline.SubTypeName = typeItem.Title;
                    }
                    else
                    {
                        itemOnline.SubTypeName = string.Empty;
                    }

                    //if (itemOnline.AppSubType == 202 &&
                    //    itemOnline.AppType == 200)
                    //    itemOnline.Thumbnail = @"pack://*****:*****@"pack://application:,,,/Resources/Images/FastCalc.png";

                    var queryItem = from item in tempList
                                    where item.UniqueId == itemOnline.UniqueId
                                    select item;
                    if (queryItem.Count() == 0)
                    {
                        tempList.Add(itemOnline);
                    }
                }

                string key = getKey(typeId, subTypeId, pageIndex);
                if (this.appItemOnlineDictionary.ContainsKey(key))
                {
                    this.totalPageDictionary[key]     = this.totalPage;
                    this.appItemOnlineDictionary[key] = tempList;
                }
                else
                {
                    this.totalPageDictionary.Add(key, this.totalPage);
                    this.appItemOnlineDictionary.Add(key, tempList);
                }

                foreach (DataColumn column in dt.Columns)
                {
                    Console.WriteLine(column.ColumnName);
                }
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
            }

            Thread.Sleep(0);
        }