Ejemplo n.º 1
0
        public bool UploadImage(byte[] data, string fmt, ImageItemViewModel item)
        {
            try
            {
                if (string.IsNullOrEmpty(DefaultServer))
                {
                    DefaultServer = "SMMS";
                    GlobalConfig.Instance.SaveSettings();
                }
                string AssemblyName = "ImageHosting.Module.ImageServer." + DefaultServer;

                IImageServer server = (IImageServer)Assembly.Load(AssemblyName).CreateInstance(AssemblyName + ".ImageServer");
                var          config = GlobalConfig.Instance.GetImageServerConfig(DefaultServer);
                bool         bRes   = server.SetConfig(config);

                if (!bRes)
                {
                    var result = MessageBox.Show("确定?", "此图床服务需要必要的设置,是否跳转到设置界面?", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        IRegionManager regionManager = ServiceLocator.Current.GetInstance <IRegionManager>();
                        regionManager.RequestNavigate(RegionToken.NavigationBarRegionName, AssemblyName + ".Views." + DefaultServer);
                    }
                    return(false);
                }

                item.Info.DisplayName = "Clipboard_" + Guid.NewGuid().ToString() + fmt;
                item.Info.Extname     = fmt;
                string ImageURL = string.Empty;

                bRes = server.UploadImage(data, item.Info.DisplayName, out ImageURL);

                if (bRes && !string.IsNullOrEmpty(ImageURL))
                {
                    item.Info.GUID        = Guid.NewGuid().ToString();
                    item.Info.UploadTime  = DateTime.Now.ToFileTimeUtc();
                    item.Info.ImageServer = server.ServerName();
                    item.Info.ImageUrl    = ImageURL;
                    item.Info.Filename    = item.Info.GUID + item.Info.Extname;

                    string dst = GlobalUtil.GetCacheDirectory() + "\\" + item.Info.Filename;
                    // File.Copy(path, dst, true);
                    using (var file = new  FileStream(dst, FileMode.Create, FileAccess.Write))
                    {
                        file.Write(data, 0, data.Length);
                        file.Flush();
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(false);
            }
        }
        private void ShowImageItem(ImageItemViewModel obj)
        {
            ImageItem = obj;
            RaisePropertyChanged(nameof(ImagePath));
            IRegionManager regionManager = ServiceLocator.Current.GetInstance <IRegionManager>();

            regionManager.RequestNavigate(RegionToken.MainContentRegionName, new Uri("ImageDetailsView", UriKind.RelativeOrAbsolute));
        }
        public ImageItemControl(ImageItemViewModel item)
            : base(item)
        {
            this.item = item;

            InitializeComponent();

            this.DataContext = this.item;
        }
        public ImageItemEditorControl(ImageItemViewModel item)
        {
            this.item = item;

            InitializeComponent();

            this.DataContext = this.item;
            this.GeneralItemEditor.SetItem(this.item);
        }
Ejemplo n.º 5
0
        private void UploadImage(string FilePath)
        {
            ImageItemViewModel item = new ImageItemViewModel();

            item.Info = new ImageInfo();
            bool bRes = UploadFactory.Instance.UploadImage(FilePath, item);

            if (bRes)
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                {
                    _eventAggregator.GetEvent <UploadImageEvent>().Publish(item);
                }));
            }
            else
            {
            }
        }
Ejemplo n.º 6
0
        private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            // unsubscribe old
            if (ViewModel != null)
            {
                ViewModel.PropertyChanged -= DataContextOnPropertyChanged;
            }

            if (DataContext == null)
            {
                ViewModel = null;
                return;
            }

            // subscribe new
            Debug.Assert(DataContext is ImageItemViewModel);
            ViewModel = (ImageItemViewModel)DataContext;
            ViewModel.PropertyChanged += DataContextOnPropertyChanged;
        }
Ejemplo n.º 7
0
        private void UploadFromClipBoardExcute()
        {
            // MessageBox.Show("UploadFromClipBoardExcute", "OK", MessageBoxButton.OK);
            IDataObject data = Clipboard.GetDataObject();

            if (data.GetDataPresent(typeof(Bitmap)))
            {
                BitmapSource bs = Clipboard.GetImage();

                using (MemoryStream ms = new MemoryStream())
                {
                    BitmapEncoder enc = new BmpBitmapEncoder();
                    enc.Frames.Add(BitmapFrame.Create(bs));
                    enc.Save(ms);
                    Image image = Image.FromStream(ms);

                    byte[] buffer = new byte[ms.Length];
                    ms.Seek(0, SeekOrigin.Begin);
                    ms.Read(buffer, 0, buffer.Length);

                    ImageItemViewModel item = new ImageItemViewModel();
                    item.Info = new ImageInfo();
                    bool bRes = UploadFactory.Instance.UploadImage(buffer, ".bmp", item);

                    if (bRes)
                    {
                        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            _eventAggregator.GetEvent <UploadImageEvent>().Publish(item);
                        }));
                    }
                    else
                    {
                    }
                }

                //Bitmap b = new Bitmap(bs.PixelWidth,bs.PixelHeight,(System.Drawing.Imaging.PixelFormat.)bs.Format);
                //System.Drawing.Image image = (Image)Clipboard.GetImage();

                ////var image =as Image;
                //using (var ms = new MemoryStream())
                //{
                //    image.Save(ms, image.RawFormat);

                //    byte[] buffer = new byte[ms.Length];
                //    ms.Seek(0, SeekOrigin.Begin);
                //    ms.Read(buffer, 0, buffer.Length);

                //    ImageItemViewModel item = new ImageItemViewModel();
                //   // item.Info = new ImageInfo();
                //    bool bRes = UploadFactory.Instance.UploadImage(buffer, "." + image.RawFormat.ToString(), item);

                //    if (bRes)
                //    {
                //        Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                //        {
                //            _eventAggregator.GetEvent<UploadImageEvent>().Publish(item);
                //        }));
                //    }
                //    else
                //    {

                //    }
                //}
            }
        }
Ejemplo n.º 8
0
 private void NewImageItem(ImageItemViewModel obj)
 {
     ImageItemGallaryData.Insert(0, obj);
     UpdateCacheConfig();
 }
        private async Task SaveHTMLFiles()
        {
            string htmlFileContents = string.Empty;

            using (StreamReader reader = new StreamReader(File.OpenRead(CDKProjectViewModel.TemplateIndexHTMLFilePath)))
            {
                htmlFileContents = await reader.ReadToEndAsync();
            }

            using (StreamWriter writer = new StreamWriter(File.Open(this.IndexHTMLFilePath, FileMode.Create)))
            {
                await writer.WriteAsync(htmlFileContents);
            }

            string scriptFileContents = string.Empty;

            using (StreamReader reader = new StreamReader(File.OpenRead(CDKProjectViewModel.TemplateScriptJSFilePath)))
            {
                scriptFileContents = await reader.ReadToEndAsync();
            }

            StringBuilder definedItems = new StringBuilder();

            definedItems.AppendLine();
            definedItems.AppendLine();
            definedItems.AppendLine("function initializeItems()");
            definedItems.AppendLine("{");
            foreach (SceneViewModel scene in this.Scenes)
            {
                foreach (ItemViewModel item in scene.Items)
                {
                    definedItems.Append("\t");
                    if (item is TextItemViewModel)
                    {
                        TextItemViewModel textItem = (TextItemViewModel)item;
                        definedItems.Append("addText(\"" + item.Name + "\", \"" + scene.Name + "\", \"" + textItem.Text + "\", " + textItem.Size + ", \"" + textItem.Color.ToLower() + "\", \"" + textItem.Font + "\", " + item.XPosition + ", " + item.YPosition + ", " + item.IsVisible.ToString().ToLower() + ", " + item.IsInteractive.ToString().ToLower() + ");");
                    }
                    else if (item is ImageItemViewModel)
                    {
                        ImageItemViewModel imageItem = (ImageItemViewModel)item;
                        definedItems.Append("addImage(\"" + item.Name + "\", \"" + scene.Name + "\", \"" + Path.GetFileName(imageItem.SourcePath) + "\", " + imageItem.Width + ", " + imageItem.Height + ", " + item.XPosition + ", " + item.YPosition + ", " + item.IsVisible.ToString().ToLower() + ", " + item.IsInteractive.ToString().ToLower() + ");");
                        if (File.Exists(imageItem.SourcePath))
                        {
                            File.Copy(imageItem.SourcePath, Path.Combine(this.SourceFolderPath, Path.GetFileName(imageItem.SourcePath)), overwrite: true);
                        }
                    }
                    else if (item is SoundItemViewModel)
                    {
                        SoundItemViewModel soundItem = (SoundItemViewModel)item;
                        if (File.Exists(soundItem.SourcePath))
                        {
                            File.Copy(soundItem.SourcePath, Path.Combine(this.SourceFolderPath, Path.GetFileName(soundItem.SourcePath)), overwrite: true);
                        }
                    }
                    else if (item is VideoItemViewModel)
                    {
                        VideoItemViewModel videoItem = (VideoItemViewModel)item;
                        string             filename  = Path.GetFileName(videoItem.SourcePath);
                        definedItems.Append("videoProperties[\"" + filename + "\"] = { x: " + item.XPosition + ", y: " + item.YPosition + ", width: " + videoItem.Width + ", height: " + videoItem.Height + " };");
                        if (File.Exists(videoItem.SourcePath))
                        {
                            File.Copy(videoItem.SourcePath, Path.Combine(this.SourceFolderPath, filename), overwrite: true);
                        }
                    }
                    definedItems.AppendLine();
                }
            }
            definedItems.AppendLine("}");

            using (StreamWriter writer = new StreamWriter(File.Open(this.ScriptJSFilePath, FileMode.Create)))
            {
                await writer.WriteAsync(scriptFileContents);

                await writer.WriteAsync(definedItems.ToString());
            }
        }