Exemple #1
0
 private static void SetIsNew(NavbarsItem newNavItem, NavbarsItem navItem)
 {
     newNavItem.Images.ForEach((ImagesItem item) =>
     {
         ImagesItem imagesItem = navItem.Images.FirstOrDefault <ImagesItem>((ImagesItem q) => q.BigImage == item.BigImage);
         if (imagesItem != null)
         {
             item.IsNew = imagesItem.IsNew;
         }
     });
 }
Exemple #2
0
 public ActionResult Create([Bind(Include = "Id,Name,Description,Price,Adress,PhoneContact,image,IDUser,idGroup,idCity")] Items items, IEnumerable <HttpPostedFileBase> files)
 {
     if (ModelState.IsValid)
     {
         items.IDUser = User.Identity.GetUserId();
         db.Items.Add(items);
         db.SaveChanges();
         Items      item = db.Items.ToList().Last();
         ImagesItem test = new ImagesItem();
         foreach (HttpPostedFileBase file in files)
         {
             if (file != null)
             {
                 test.Items = item;
                 test.Image = new byte[file.ContentLength];
                 file.InputStream.Read(test.Image, 0, file.ContentLength);
                 db.ImagesItem.Add(test);
                 db.SaveChanges();
             }
         }
     }
     return(RedirectToAction("Index"));
 }
Exemple #3
0
        /// <summary>
        /// 构造函数,初始化当前的显示主要数据信息
        /// </summary>
        /// <param name="dataService"></param>
        public MainViewModel(IDataService dataService)
        {
            string name;
            string installPath;
            string installPath1;

            this._dataService = dataService;

            //注册消息,打开指定的URL
            base.MessengerInstance.Register <int>(this, MessageToken.ToOpenUrl, (int pageIndex) => {
                ImagesItem imagesItem = this.SelectedNavbar.Images[pageIndex];
                if ((imagesItem.OpenLink ? true : imagesItem.IsNew))
                {
                    imagesItem.IsNew = false;
                    if (imagesItem.OpenLink)
                    {
                        MainViewModel.OpenUrl(imagesItem.Link);
                    }
                }
            }, false);

            //注册消息,打开指定URL
            base.MessengerInstance.Register <string>(this, MessageToken.ToOpenStrUrl, new Action <string>(MainViewModel.OpenUrl), false);

            //注册消息,改变当前的图片
            base.MessengerInstance.Register <int>(this, MessageToken.OnChangeImage, (int pageIndex) => {
                try
                {
                    string smallImage = this.SelectedNavbar.Images[pageIndex].SmallImage;
                    if (!this.SmallImageUrl.Equals(smallImage))
                    {
                        this.SmallImageUrl = smallImage;
                    }
                }
                catch (Exception exception)
                {
                    this._logger.Error <Exception>(exception);
                }
            }, false);

            //注册消息,启动Revit
            base.MessengerInstance.Register <string>(this, MessageToken.ToOpenRevit, (string filePath) => {
                try
                {
                    string str         = string.Concat(this.SelectedRevitProduct.InstallLocation, "\\Revit.exe");
                    string[] strArrays = null;
                    if (!string.IsNullOrWhiteSpace(filePath))
                    {
                        strArrays = new string[] { filePath };
                    }
                    ProcessHelper.StartProcess(str, strArrays);
                    this.Config.LocalImageLinkData = this.ImageLinkData;
                    this.Config.BeePCProductList   = (
                        from item in this.BeePCProducts
                        select item.InstallPath).ToList <string>();
                    GlobalData.Config = this.Config;
                    GlobalData.Save();
                }
                catch (Exception exception)
                {
                    this._logger.Error <Exception>(exception);
                }
            }, false);

            //注册消息
            base.MessengerInstance.Register <string>(this, MessageToken.ToAddBeePC, (string path) => path.InitBeePCProduct((BeePCProduct beepc, Exception ex) => {
                if (ex != null)
                {
                    this._logger.Error <Exception>(ex);
                }
                else if (this.BeePCProducts.FirstOrDefault <BeePCProduct>((BeePCProduct item) => item.InstallPath.Equals(beepc.InstallPath)) == null)
                {
                    this.BeePCProducts.Add(beepc);
                    if (this.SelectedBeePCProduct == null)
                    {
                        this.SelectedBeePCProduct = this.BeePCProducts.FirstOrDefault <BeePCProduct>();
                        this.RaisePropertyChanged <BeePCProduct>(Expression.Lambda <Func <BeePCProduct> >(Expression.Property(Expression.Constant(this, typeof(MainViewModel)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(MainViewModel).GetMethod("get_SelectedBeePCProduct").MethodHandle)), new ParameterExpression[0]));
                    }
                    this.RaisePropertyChanged <ObservableCollection <BeePCProduct> >(Expression.Lambda <Func <ObservableCollection <BeePCProduct> > >(Expression.Property(Expression.Constant(this, typeof(MainViewModel)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(MainViewModel).GetMethod("get_BeePCProducts").MethodHandle)), new ParameterExpression[0]));
                }
            }), false);

            //注册消息,删除BeePC
            base.MessengerInstance.Register <string>(this, MessageToken.ToDelBeePC, (string path) => {
                BeePCProduct beePCProduct = this.BeePCProducts.FirstOrDefault <BeePCProduct>((BeePCProduct item) => item.InstallPath.Equals(path));
                if (beePCProduct != null)
                {
                    this.BeePCProducts.Remove(beePCProduct);
                }
                if (this.SelectedBeePCProduct == null)
                {
                    this.SelectedBeePCProduct = this.BeePCProducts.FirstOrDefault <BeePCProduct>();
                    this.RaisePropertyChanged <BeePCProduct>(Expression.Lambda <Func <BeePCProduct> >(Expression.Property(Expression.Constant(this, typeof(MainViewModel)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(MainViewModel).GetMethod("get_SelectedBeePCProduct").MethodHandle)), new ParameterExpression[0]));
                }
                this.RaisePropertyChanged <ObservableCollection <BeePCProduct> >(Expression.Lambda <Func <ObservableCollection <BeePCProduct> > >(Expression.Property(Expression.Constant(this, typeof(MainViewModel)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(MainViewModel).GetMethod("get_BeePCProducts").MethodHandle)), new ParameterExpression[0]));
            }, false);

            //注册消息,版本改变
            base.MessengerInstance.Register <PropertyChangedMessage <BeePCProduct> >(this, (PropertyChangedMessage <BeePCProduct> argument0) => this.ChangeBeePCVersion(), false);

            //注册消息Revit产品信息
            base.MessengerInstance.Register <PropertyChangedMessage <RevitProduct> >(this, (PropertyChangedMessage <RevitProduct> message) => {
                this.ChangeBeePCVersion();
                this.HistoryFiles.Clear();
                if (message.NewValue != null)
                {
                    message.NewValue.ReadRecentFiles().ForEach((HistoryFile item) => this.HistoryFiles.Add(item));
                }
            }, false);


            this.ImageLinkData = this._dataService.GetLocalImageLinkData();
            this.RevitProducts.Clear();

            //开始获取Revit版本
            foreach (RevitProduct revitProduct in this._dataService.GetRevitProducts())
            {
                this.RevitProducts.Add(revitProduct);
            }
            this.BeePCProducts.Clear();

            //开始获取BeePC版本
            foreach (BeePCProduct beePCProduct1 in this._dataService.GetBeePCProducts())
            {
                this.BeePCProducts.Add(beePCProduct1);
            }
            //获取当前的配置信息
            this.Config = this._dataService.GetAppConfig();

            if (!this.RevitProducts.Any <RevitProduct>())
            {
                MessageBox.Show(new MessageBoxInfo()
                {
                    Caption = "提示",
                    Message = "请先安装Revit,再使用本软件!"
                });
            }
            //获取当前的产品信息和配置路径
            if ((!this.BeePCProducts.Any <BeePCProduct>() ? false : string.IsNullOrWhiteSpace(this.Config.SelectBeePC)))
            {
                AppConfig    config        = this.Config;
                BeePCProduct beePCProduct2 = this.BeePCProducts.FirstOrDefault <BeePCProduct>();
                if (beePCProduct2 != null)
                {
                    installPath1 = beePCProduct2.InstallPath;
                }
                else
                {
                    installPath1 = null;
                }
                config.SelectBeePC = installPath1;
            }

            //当前的安装路径
            if (this.BeePCProducts.All <BeePCProduct>((BeePCProduct item) => item.InstallPath != this.Config.SelectBeePC))
            {
                AppConfig    appConfig     = this.Config;
                BeePCProduct beePCProduct3 = this.BeePCProducts.FirstOrDefault <BeePCProduct>();
                if (beePCProduct3 != null)
                {
                    installPath = beePCProduct3.InstallPath;
                }
                else
                {
                    installPath = null;
                }
                appConfig.SelectBeePC = installPath;
            }
            if ((!this.RevitProducts.Any <RevitProduct>() ? false : string.IsNullOrWhiteSpace(this.Config.SelectRevit)))
            {
                AppConfig    config1       = this.Config;
                RevitProduct revitProduct1 = this.RevitProducts.FirstOrDefault <RevitProduct>();
                if (revitProduct1 != null)
                {
                    name = revitProduct1.Name;
                }
                else
                {
                    name = null;
                }
                config1.SelectRevit = name;
            }

            //获取图片连接数据
            this._dataService.GetImageLinkData((ImageLinkData imgData, Exception ex) => {
                if (ex == null)
                {
                    try
                    {
                        if (this.ImageLinkData.Version < imgData.Version)
                        {
                            imgData.DownLoadImages();
                            if ((!imgData.CheckLocalImages() || !imgData.ConvertServer2Local() ? false : this.ImageLinkData.SetIsNew(imgData)))
                            {
                                this.ImageLinkData.DeleteImages();
                                DispatcherHelper.CheckBeginInvokeOnUI(() => {
                                    this.ImageLinkData  = imgData;
                                    this.SelectedNavbar = this.ImageLinkData.Navbars.FirstOrDefault <NavbarsItem>();
                                });
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    catch (Exception exception)
                    {
                        this._logger.Error <Exception>(exception);
                    }
                }
                else
                {
                    this._logger.Error <Exception>(ex);
                }
            });

            //获取连接信息
            this._dataService.GetLikeNumber((string number, Exception ex) => {
                if (ex != null)
                {
                    this._logger.Error <Exception>(ex);
                    this.LikeNumber = "暂无数据";
                }
                else
                {
                    this.LikeNumber = number;
                }
            });
            //获取天气信息
            this._dataService.GetWeather(this.Config.WeatherUrl, (WeatherInfo weather, Exception ex) => {
                if (ex != null)
                {
                    this._logger.Error <Exception>(ex);
                }
                else
                {
                    this.LocationWeatherInfo = weather;
                }
            });

            //获取当前的选择菜单
            this.SelectedNavbar = this.ImageLinkData.Navbars.FirstOrDefault <NavbarsItem>();

            //
            this.RaisePropertyChanged <bool>(Expression.Lambda <Func <bool> >(Expression.Property(Expression.Constant(this, typeof(MainViewModel)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(MainViewModel).GetMethod("get_CanOpen").MethodHandle)), new ParameterExpression[0]));
        }