Esempio n. 1
0
        public void Send(FileItem item, AutoExportPluginConfig configData)
        {
            try
            {
                var filename = item.FileName;
                configData.IsRedy  = false;
                configData.IsError = false;
                var conf = new DropboxViewModel(configData);

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

                conf.Upload(outfile, ServiceProvider.Settings.DefaultSession.Name, item.Name);

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

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

                conf.UploadFile(outfile, item.Name);

                // 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 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);
        }
        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;
        }
Esempio n. 5
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. 6
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 = PhotoUtils.ReplaceExtension(Path.GetTempFileName(), Path.GetExtension(item.Name));

                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, 0, 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. 7
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. 8
0
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            dest = PhotoUtils.ReplaceExtension(dest, ".jpg");
            var conf = new ScriptTransformViewModel(configData);

            using (Stream stream = ToStream(conf.Script))
            {
                MagickScript script = new MagickScript(stream);

                // Read image from file
                using (MagickImage image = new MagickImage(infile))
                {
                    // Execute script with the image and write it to a jpg file
                    script.Execute(image);
                    image.Format = MagickFormat.Jpeg;
                    image.Write(dest);
                }
            }
            return(dest);
        }