public bool Execute(FileItem item, AutoExportPluginConfig configData)
        {
            configData.IsRedy  = false;
            configData.IsError = false;
            var conf = new ExecuteFilePluginViewModel(configData);

            if (string.IsNullOrEmpty(conf.PathToExe) || !File.Exists(conf.PathToExe))
            {
                configData.IsRedy  = true;
                configData.IsError = true;
                configData.Error   = "No executable path was set or executable not found";
                return(false);
            }
            var outfile = item.FileName;

            if (configData.ConfigDataCollection.Count > 0 || !configData.RunAfterTransfer)
            {
                outfile = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);
            }
            if (File.Exists(outfile))
            {
                PhotoUtils.Run(conf.PathToExe,
                               string.IsNullOrEmpty(conf.Params) ? outfile : conf.Params.Replace("%1", outfile), ProcessWindowStyle.Normal);
            }
            else
            {
                configData.IsError = true;
                configData.Error   = "Output file not found !";
            }

            configData.IsRedy = true;
            return(true);
        }
Esempio n. 2
0
        private void Restore()
        {
            if (ServiceProvider.Settings.SelectedBitmap == null ||
                ServiceProvider.Settings.SelectedBitmap.FileItem == null)
            {
                return;
            }
            var item = ServiceProvider.Settings.SelectedBitmap.FileItem;

            if (File.Exists(item.BackupFileName))
            {
                try
                {
                    PhotoUtils.WaitForFile(item.FileName);
                    File.Copy(item.BackupFileName, item.FileName, true);
                    item.RemoveThumbs();
                    item.IsLoaded = false;
                    ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Refresh_Image);
                }
                catch (Exception ex)
                {
                    Log.Error("Error restore", ex);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow" /> class.
        /// </summary>
        public MainWindow()
        {
            DisplayName = "Default";
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (sender1, args) => this.Close()));

            SelectPresetCommand = new RelayCommand <CameraPreset>(SelectPreset);
            DeletePresetCommand = new RelayCommand <CameraPreset>(DeletePreset,
                                                                  (o) => ServiceProvider.Settings.CameraPresets.Count > 0);
            LoadInAllPresetCommand = new RelayCommand <CameraPreset>(LoadInAllPreset);
            VerifyPresetCommand    = new RelayCommand <CameraPreset>(VerifyPreset);
            ConfigurePluginCommand = new RelayCommand <AutoExportPluginConfig>(ConfigurePlugin);
            AddPluginCommand       = new RelayCommand <IAutoExportPlugin>(AddPlugin);
            InitializeComponent();


            if (!string.IsNullOrEmpty(ServiceProvider.Branding.ApplicationTitle))
            {
                Title = ServiceProvider.Branding.ApplicationTitle;
            }
            if (!string.IsNullOrEmpty(ServiceProvider.Branding.LogoImage) &&
                File.Exists(ServiceProvider.Branding.LogoImage))
            {
                BitmapImage bi = new BitmapImage();
                // BitmapImage.UriSource must be in a BeginInit/EndInit block.
                bi.BeginInit();
                bi.UriSource = new Uri(PhotoUtils.GetFullPath(ServiceProvider.Branding.LogoImage));
                bi.EndInit();
                Icon = bi;
            }
            _selectiontimer.Elapsed              += _selectiontimer_Elapsed;
            _selectiontimer.AutoReset             = false;
            ServiceProvider.WindowsManager.Event += WindowsManager_Event;
        }
Esempio n. 4
0
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                var filename = item.FileName;
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new FacebookPluginViewModel(configData);

                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(filename));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);


                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error send facebook file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new SendEmailPluginViewModel(configData);

                var outfile = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                HelpProvider.SendEmail((string.IsNullOrEmpty(conf.Message) ? "." : conf.TransformTemplate(item, conf.Message)), (string.IsNullOrEmpty(conf.Subject) ? "Your photo" : conf.TransformTemplate(item, conf.Subject)),
                                       conf.From, conf.To, outfile);

                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error send email file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
        string SavePostedFile(UploadedFile uploadedFile)
        {
            string ret;
            string base64String;

            if (!uploadedFile.IsValid)
            {
                return(string.Empty);
            }

            var fileName = Path.Combine(MapPath(UploadDirectory), ThumbnailFileName);

            using (Image original = Image.FromStream(uploadedFile.FileContent))
            {
                base64String = PhotoUtils.ConvertImageToBase64(original);
                using (Image thumbnail = PhotoUtils.Inscribe(original, 100))
                {
                    PhotoUtils.SaveToJpeg(thumbnail, fileName);
                }
            }

            Session["base64Profile"] = "data:image/png;base64," + base64String;
            ret = string.Format("{0}|{1}", ThumbnailFileName, base64String);

            //return ThumbnailFileName;
            return(ret);
        }
Esempio n. 7
0
        public void Execute(object parameter)
        {
            if (!ServiceProvider.Settings.SelectedBitmap.FileItem.IsRaw)
            {
                MessageBox.Show("Raw file is needed for this action");
                return;
            }
            string _infile      = ServiceProvider.Settings.SelectedBitmap.FileItem.FileName;
            string _otfile      = Path.Combine(Path.GetDirectoryName(_infile), Path.GetFileNameWithoutExtension(_infile) + ".jpg");
            string _pathtoufraw =
                Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "ufraw",
                             "ufraw-batch.exe");

            if (File.Exists(_pathtoufraw))
            {
                if (PhotoUtils.RunAndWait(_pathtoufraw,
                                          " --wb=camera --saturation=1.2 --exposure=0 --black-point=auto --overwrite --out-type=jpg --output=" +
                                          _otfile + " " + _infile))
                {
                    ServiceProvider.Settings.DefaultSession.AddFile(_otfile);
                }
            }
            else
            {
                MessageBox.Show("Ufraw not found !");
            }
        }
Esempio n. 8
0
        private void ShowUnhandeledException(DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            Log.Error("Unhandled error ", e.Exception);
            ServiceProvider.Analytics.Error(e.Exception);
            string errorMessage =
                string.Format(
                    TranslationStrings.LabelUnHandledError,
                    e.Exception.Message + (e.Exception.InnerException != null
                                               ? "\n" +
                                           e.Exception.InnerException.Message
                                               : null));

            if (e.Exception.GetType() == typeof(MissingMethodException))
            {
                Log.Error("Damaged installation. Application exiting ");
                MessageBox.Show("Application crash !! Damaged installation!\nPlease unintall aplication from control panel and reinstall it!");
                Current?.Shutdown();
            }
            // check if wia 2.0 is registered
            // isn't a clean way
            if (errorMessage.Contains("{E1C5D730-7E97-4D8A-9E42-BBAE87C2059F}"))
            {
                MessageBox.Show(TranslationStrings.LabelWiaNotInstalled);
                PhotoUtils.RunAndWait("regwia.bat", "");
                MessageBox.Show(TranslationStrings.LabelRestartTheApplication);
                Application.Current.Shutdown();
            }
            else if (e.Exception.GetType() == typeof(OutOfMemoryException))
            {
                Log.Error("Out of memory. Application exiting ");
                MessageBox.Show(TranslationStrings.LabelOutOfMemory);
                if (Current != null)
                {
                    Current.Shutdown();
                }
            }
            else
            {
                if (MessageBox.Show(TranslationStrings.LabelAskSendLogFile, TranslationStrings.LabelApplicationError,
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Error) == MessageBoxResult.Yes)
                {
                    var wnd = new ErrorReportWnd("Application crash " + e.Exception.Message, e.Exception.StackTrace);
                    wnd.ShowDialog();
                }
                if (
                    MessageBox.Show(errorMessage, TranslationStrings.LabelApplicationError, MessageBoxButton.YesNo,
                                    MessageBoxImage.Error) ==
                    MessageBoxResult.No)
                {
                    if (Current != null)
                    {
                        Current.Shutdown();
                    }
                }
            }
        }
        private void Login()
        {
            FacebookClient client = new FacebookClient();

            client.AppId     = "1389684908024720";
            client.AppSecret = "20a29131265de09bf1421ed1284ca23e";
            PhotoUtils.Run(GenerateLoginUrl(client.AppId, "publish_actions,manage_pages").ToString());
        }
Esempio n. 10
0
 private void ShowAlbum()
 {
     if (!string.IsNullOrEmpty(SelectedAlbum) && SelectedAlbum.Contains("||"))
     {
         string id = SelectedAlbum.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries)[0];
         PhotoUtils.Run("https://www.facebook.com/" + id);
     }
 }
Esempio n. 11
0
 public static void Run(HelpSections sections)
 {
     if (_helpData == null)
     {
         Init();
     }
     PhotoUtils.Run(_helpData[sections], "");
 }
 private void button5_Click(object sender, RoutedEventArgs e)
 {
     if (!Directory.Exists(ServiceProvider.Settings.OverlayFolder))
     {
         Directory.CreateDirectory(ServiceProvider.Settings.OverlayFolder);
     }
     PhotoUtils.Run("explorer", ServiceProvider.Settings.OverlayFolder, ProcessWindowStyle.Normal);
 }
Esempio n. 13
0
 private void PlayVideo()
 {
     if (!File.Exists(OutPutFile))
     {
         MessageBox.Show("Video file not found !");
         return;
     }
     PhotoUtils.Run(OutPutFile);
 }
        public MainMenuViewModel()
        {
            SendCommand         = new GalaSoft.MvvmLight.Command.RelayCommand <string>(Send);
            SettingsCommand     = new RelayCommand(EditSettings);
            ThumbSizeCommand    = new GalaSoft.MvvmLight.Command.RelayCommand <int>(ThumbSize);
            SetLayoutCommand    = new GalaSoft.MvvmLight.Command.RelayCommand <string>(SetLayout);
            SelectAllCommand    = new RelayCommand(delegate { ServiceProvider.Settings.DefaultSession.SelectAll(); });
            SelectNoneCommand   = new RelayCommand(delegate { ServiceProvider.Settings.DefaultSession.SelectNone(); });
            SelectLiked         = new RelayCommand(delegate { ServiceProvider.Settings.DefaultSession.SelectLiked(); });
            SelectUnLiked       = new RelayCommand(delegate { ServiceProvider.Settings.DefaultSession.SelectUnLiked(); });
            SelectInvertCommand = new RelayCommand(delegate { ServiceProvider.Settings.DefaultSession.SelectInver(); });
            SelectSeries        =
                new RelayCommand(delegate
            {
                try
                {
                    ServiceProvider.Settings.DefaultSession.SelectSameSeries(
                        ServiceProvider.Settings.SelectedBitmap.FileItem.Series);
                }
                catch (Exception ex)
                {
                    Log.Error("SelectSeries", ex);
                }
            });
            NewSessionCommand     = new RelayCommand(NewSession);
            EditSessionCommand    = new RelayCommand(EditSession);
            DelSessionCommand     = new RelayCommand(DelSession);
            RefreshSessionCommand = new RelayCommand(RefreshSession);
            ShowSessionCommand    = new RelayCommand(ShowSession);
            RefreshCommand        = new RelayCommand(Refresh);
            CameraPropertyCommand =
                new RelayCommand(
                    () => ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.CameraPropertyWnd_Show,
                                                                        ServiceProvider.DeviceManager.SelectedCameraDevice));
            UseAsMasterCommand = new RelayCommand(UseAsMaster);

            ToggleFocusCommand   = new RelayCommand(() => ShowFocusPoints = !ShowFocusPoints);
            FlipPreviewCommand   = new RelayCommand(() => FlipPreview = !FlipPreview);
            HomePageCommand      = new RelayCommand(() => PhotoUtils.Run("http://www.digicamcontrol.com/", ""));
            CheckUpdateCommand   = new RelayCommand(() => NewVersionWnd.CheckForUpdate(true));
            ForumCommand         = new RelayCommand(() => PhotoUtils.Run("http://www.digicamcontrol.com/forum/", ""));
            SendLogFileCommand   = new RelayCommand(() => new ErrorReportWnd("Log file").ShowDialog());
            ShowChangeLogCommand = new RelayCommand(NewVersionWnd.ShowChangeLog);
            AboutCommand         = new RelayCommand(() => new AboutWnd().ShowDialog());
            ManualPageCommand    = new RelayCommand(() => HelpProvider.Run(HelpSections.MainMenu));

            ExecuteExportPluginCommand = new GalaSoft.MvvmLight.Command.RelayCommand <IExportPlugin>(ExecuteExportPlugin);
            ExecuteToolPluginCommand   = new GalaSoft.MvvmLight.Command.RelayCommand <IToolPlugin>(ExecuteToolPlugin);
            if (ServiceProvider.DeviceManager != null)
            {
                ServiceProvider.DeviceManager.CameraConnected    += DeviceManager_CameraConnected;
                ServiceProvider.DeviceManager.CameraDisconnected += DeviceManager_CameraConnected;
            }
            ExportSessionCommand = new RelayCommand(ExportSession);
            ImportSessionCommand = new RelayCommand(ImportSession);
        }
Esempio n. 15
0
        public JsonResult Upload(FormCollection collection)
        {
            var model = new PhotoEntry();

            //获取上传文件队列
            var oFile = Request.Files["Filedata"];

            if (oFile != null)
            {
                string topDir = collection["folder"];  // 获取uploadify的folder配置,在此示例中,客户端配置了上传到 Files/ 文件夹
                // 检测并创建目录:当月上传的文件放到以当月命名的文件夹中,例如2011年11月的文件放到网站根目录下的 /Files/201111 里面

                string dateFolder      = Utility.GetUploadBasePath(topDir) + @"/" + DateTime.Now.Date.ToString("yyyyMM");
                string thumbnailFolder = dateFolder + @"/thumbnail";
                if (!Directory.Exists(dateFolder))         // 检测是否存在磁盘目录
                {
                    Directory.CreateDirectory(dateFolder); // 不存在的情况下,创建这个文件目录 例如 C:/wwwroot/Files/201111/
                }
                if (!Directory.Exists(thumbnailFolder))
                {
                    Directory.CreateDirectory(thumbnailFolder);
                }

                // 使用Guid命名文件,确保每次文件名不会重复
                string guidFileName = Guid.NewGuid() + Path.GetExtension(oFile.FileName).ToLower();
                // 保存文件,注意这个可是完整路径,例如C:/wwwroot/Files/201111/92b2ce5b-88af-405e-8262-d04b552f48cf.jpg
                var originalPath = dateFolder + @"/" + guidFileName;
                oFile.SaveAs(originalPath);

                var original = new DirectoryInfo(originalPath).FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //////// TODO 在此,您可以添加自己的业务逻辑,比如保存这个文件信息到数据库
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                var thumbnailPath = thumbnailFolder + @"/" + guidFileName;

                using (var file = System.IO.File.OpenRead(originalPath))
                {
                    PhotoUtils.CutForCustom(file, thumbnailPath, 380, 252, 50);
                }

                string thumbnail = new DirectoryInfo(thumbnailPath).FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");
                var    newsId    = DataCast.Get <int>(collection["NewsId"]);


                model.Description = "请添加描述";
                model.NewsId      = newsId;
                model.Original    = @"~\" + original;
                model.Thumbnail   = @"~\" + thumbnail;
                _photo.Add(model);
            }

            return(Json(model));
        }
Esempio n. 16
0
        private void Print(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                PrintDialog dlg = new PrintDialog();
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf    = new PrintPluginViewModel(configData);
                var outfile = Path.Combine(Path.GetTempPath(), Path.GetFileName(item.FileName));

                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                System.Printing.PrintCapabilities capabilities = dlg.PrintQueue.GetPrintCapabilities(dlg.PrintTicket);
                var PageWidth  = (int)capabilities.PageImageableArea.ExtentWidth;
                var PageHeight = (int)capabilities.PageImageableArea.ExtentHeight;

                var panel = new StackPanel
                {
                    Margin = new Thickness(conf.Margin),
                };

                var image = new Image
                {
                    Source  = BitmapLoader.Instance.LoadImage(outfile, PageWidth > PageHeight ? PageWidth : PageHeight, conf.Rotate ? 90 : 0),
                    Width   = PageWidth,
                    Height  = PageHeight,
                    Stretch = Stretch.Uniform,
                };


                panel.Children.Add(image);
                panel.UpdateLayout();
                panel.Measure(new Size(PageWidth, PageHeight));
                panel.Arrange(new Rect(new Point(0, 0), panel.DesiredSize));
                panel.UpdateLayout();
                dlg.PrintVisual(panel, item.Name);
                image.Source = null;
                panel.Children.Clear();
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error print file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }

            configData.IsRedy = true;
        }
Esempio n. 17
0
        public bool Execute(FileItem item, AutoExportPluginConfig configData)
        {
            configData.IsRedy  = false;
            configData.IsError = false;
            var filename = item.FileName;
            var conf     = new TransformPluginViewModel(configData);
            var outfile  = Path.GetTempFileName();

            outfile = PhotoUtils.ReplaceExtension(outfile, Path.GetExtension(filename));
            outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);
            if (conf.CreateNew)
            {
                string newFile = Path.Combine(Path.GetDirectoryName(filename),
                                              Path.GetFileNameWithoutExtension(filename) + "_transformed" + ".jpg");
                newFile = PhotoUtils.GetNextFileName(newFile);

                File.Copy(outfile, newFile, true);

                if (ServiceProvider.Settings.DefaultSession.GetFile(newFile) == null)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        FileItem im    = new FileItem(newFile);
                        im.Transformed = true;
                        var i          = ServiceProvider.Settings.DefaultSession.Files.IndexOf(item);
                        if (ServiceProvider.Settings.DefaultSession.Files.Count - 1 == i)
                        {
                            ServiceProvider.Settings.DefaultSession.Files.Add(im);
                        }
                        else
                        {
                            ServiceProvider.Settings.DefaultSession.Files.Insert(i + 1, im);
                        }
                    }));
                }
            }
            else
            {
                // wait for file to be not locked
                PhotoUtils.WaitForFile(filename);
                File.Copy(outfile, filename, true);
                item.IsLoaded = false;
                item.RemoveThumbs();
                item.Transformed = true;
            }
            // remove unused file
            if (outfile != item.FileName)
            {
                PhotoUtils.WaitForFile(outfile);
                File.Delete(outfile);
            }
            configData.IsRedy = true;
            return(true);
        }
Esempio n. 18
0
 private void MenuItem_Click_1(object sender, RoutedEventArgs e)
 {
     if (PhotoUtils.CheckForUpdate())
     {
         Close();
     }
     else
     {
         MessageBox.Show(TranslationStrings.MsgApplicationUpToDate);
     }
 }
 public void Open()
 {
     try
     {
         var file = Path.Combine(Settings.ApplicationFolder, "Data", "msl", SelectedScript + ".msl");
         PhotoUtils.Run("notepad.exe", file);
     }
     catch (Exception ex)
     {
         Log.Error("Error", ex);
     }
 }
 private void ShowSession()
 {
     try
     {
         PhotoUtils.Run(ServiceProvider.Settings.DefaultSession.Folder);
     }
     catch (Exception ex)
     {
         Log.Error("Error refresh session ", ex);
         ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.MainWnd_Message, ex.Message);
     }
 }
Esempio n. 21
0
        private void Login()
        {
            FacebookClient client = new FacebookClient();

            client.AppId     = ClientId;
            client.AppSecret = ClientSecret;
            //PhotoUtils.Run(GenerateLoginUrl(client.AppId,"publish_actions,manage_pages").ToString());
            _miniWebServer = new MiniWebServer(SendResponse, Server);
            _miniWebServer.Run();
            PhotoUtils.Run(
                GenerateLoginUrl(client.AppId, "publish_actions,manage_pages,user_photos,publish_pages").ToString());
        }
Esempio n. 22
0
        private void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new FtpPluginViewModel(configData);

                var outfile = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));
                outfile = AutoExportPluginHelper.ExecuteTransformPlugins(item, configData, outfile);

                using (FtpClient conn = new FtpClient())
                {
                    conn.Host = conf.Server;
                    if (conf.Port > 0)
                    {
                        conn.Port = conf.Port;
                    }

                    conn.Credentials = new NetworkCredential(conf.User, conf.Pass);
                    if (!string.IsNullOrWhiteSpace(conf.ServerPath))
                    {
                        conn.SetWorkingDirectory(conf.ServerPath);
                    }
                    using (Stream ostream = conn.OpenWrite(item.Name))
                    {
                        try
                        {
                            var data = File.ReadAllBytes(outfile);
                            ostream.Write(data, 0, data.Length);
                        }
                        finally
                        {
                            ostream.Close();
                        }
                    }
                }
                // remove unused file
                if (outfile != item.FileName)
                {
                    PhotoUtils.WaitForFile(outfile);
                    File.Delete(outfile);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error senf ftp file", exception);
                configData.IsError = true;
                configData.Error   = exception.Message;
            }
            configData.IsRedy = true;
        }
Esempio n. 23
0
        public GetEnquireModel GetEnquire(string chfid)
        {
            GetEnquireModel response;

            response = insureeRepository.GetEnquire(chfid);

            if (response != null)
            {
                response.PhotoBase64 = PhotoUtils.CreateBase64ImageFromFilepath(_configuration.GetValue <string>("AppSettings:UpdatedFolder"), response.PhotoPath);
            }

            return(response);
        }
Esempio n. 24
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(ServiceProvider.Branding.StartupScreenImage) &&
         File.Exists(ServiceProvider.Branding.StartupScreenImage))
     {
         BitmapImage bi = new BitmapImage();
         // BitmapImage.UriSource must be in a BeginInit/EndInit block.
         bi.BeginInit();
         bi.UriSource = new Uri(PhotoUtils.GetFullPath(ServiceProvider.Branding.StartupScreenImage));
         bi.EndInit();
         background.Source = bi;
     }
 }
        public async Task <IActionResult> CreatePost([FromForm] string caption,
                                                     [FromForm] IList <IFormFile> uploads,
                                                     [FromRoute] string username)
        {
            if (uploads.Count <= 0)
            {
                return(BadRequest(new { Err = "Cannot create a post without any photo!" }));
            }

            // validate user
            var user = await DbContext.Users.SingleOrDefaultAsync(u => u.Username == username);

            if (user is null)
            {
                return(BadRequest(new { Err = "Unauthorized user!" }));
            }

            var transaction = DbContext.Database.BeginTransaction();

            // create post content
            var post = new Post()
            {
                Caption = caption,
                UserId  = user.Id,
                Created = DateTimeOffset.UtcNow
            };

            DbContext.Add(post);
            await DbContext.SaveChangesAsync();

            post = await DbContext.Posts
                   .Include(p => p.User).ThenInclude(u => u.AvatarPhoto)
                   .Where(p => p.Id == post.Id)
                   .FirstOrDefaultAsync();

            // create file uploads
            var uploadedFiles = uploads.Select(async upload => await PhotoUtils.UploadPhotoAsync(upload, PhotoServingPath))
                                .Select(task => task.Result)
                                .Select(fileName => new Photo()
            {
                PostId   = post.Id,
                FileName = fileName
            });

            DbContext.AddRange(uploadedFiles);
            await DbContext.SaveChangesAsync();

            await transaction.CommitAsync();

            return(Created(Url.Action("GetPostById", "Post", new { id = post.Id }), ResponseModelFactory.Create(post)));
        }
Esempio n. 26
0
        protected void ImageHomeUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            if (e.UploadedFile.IsValid)
            {
                string filePath = UploadHomeDirectory + TempData["HomeImageName"];

                using (Image original = Image.FromStream(e.UploadedFile.FileContent))
                {
                    PhotoUtils.SaveToJpeg(original, Request.MapPath(filePath));
                }

                e.CallbackData = TempData["HomeImageName"] + "|" + Url.Content(filePath) + "?refresh=" + Guid.NewGuid();
            }
        }
 public void SetCamera(string camera)
 {
     if (string.IsNullOrEmpty(camera))
     {
         return;
     }
     foreach (var cameraDevice in ServiceProvider.DeviceManager.ConnectedDevices)
     {
         if ((PhotoUtils.IsNumeric(camera) && cameraDevice.SerialNumber == camera.Trim()) || cameraDevice.DeviceName.Replace(" ", "_") == camera.Replace(" ", "_"))
         {
             TargetDevice = cameraDevice;
             break;
         }
     }
 }
Esempio n. 28
0
        public FamilyModel GetByCHFID(string chfid, Guid userUUID)
        {
            FamilyModel response;

            response = familyRepository.GetByCHFID(chfid, userUUID);

            if (response != null)
            {
                foreach (var insure in response.Insurees)
                {
                    insure.PhotoBase64 = PhotoUtils.CreateBase64ImageFromFilepath(_configuration.GetValue <string>("AppSettings:UpdatedFolder"), insure.PhotoPath);
                }
            }

            return(response);
        }
Esempio n. 29
0
        private void ShowUnhandeledException(DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            Log.Error("Unhandled error ", e.Exception);

            string errorMessage =
                string.Format(
                    TranslationStrings.LabelUnHandledError,

                    e.Exception.Message + (e.Exception.InnerException != null
                                   ? "\n" +
                                           e.Exception.InnerException.Message
                                   : null));

            // check if wia 2.0 is registered
            // isn't a clean way
            if (errorMessage.Contains("{E1C5D730-7E97-4D8A-9E42-BBAE87C2059F}"))
            {
                System.Windows.Forms.MessageBox.Show(TranslationStrings.LabelWiaNotInstalled);
                PhotoUtils.RunAndWait("regwia.bat", "");
                System.Windows.Forms.MessageBox.Show(TranslationStrings.LabelRestartTheApplication);
                Application.Current.Shutdown();
            }
            else if (e.Exception.GetType() == typeof(OutOfMemoryException))
            {
                Log.Error("Out of memory. Application exiting ");
                System.Windows.Forms.MessageBox.Show(TranslationStrings.LabelOutOfMemory);
                if (Current != null)
                {
                    Current.Shutdown();
                }
            }
            else
            {
                if (
                    MessageBox.Show(errorMessage, TranslationStrings.LabelApplicationError, MessageBoxButton.YesNo,
                                    MessageBoxImage.Error) ==
                    MessageBoxResult.No)
                {
                    if (Current != null)
                    {
                        Current.Shutdown();
                    }
                }
            }
        }
Esempio n. 30
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (ServiceProvider.Settings.SelectedBitmap == null ||
         ServiceProvider.Settings.SelectedBitmap.FileItem == null)
     {
         return;
     }
     if (!string.IsNullOrWhiteSpace(ServiceProvider.Settings.ExternalViewer) &&
         File.Exists(ServiceProvider.Settings.ExternalViewer))
     {
         PhotoUtils.Run(ServiceProvider.Settings.ExternalViewer,
                        "\"" + ServiceProvider.Settings.SelectedBitmap.FileItem.FileName + "\"", ProcessWindowStyle.Maximized);
     }
     else
     {
         PhotoUtils.Run("\"" + ServiceProvider.Settings.SelectedBitmap.FileItem.FileName + "\"", "",
                        ProcessWindowStyle.Maximized);
     }
 }