GetTempFileName() public static méthode

public static GetTempFileName ( ) : string
Résultat string
Exemple #1
0
        private async void RunByStep(object sender, RoutedEventArgs e)
        {
            if (_firstStep)
            {
                var tmp = Path.GetTempFileName();
                await File.WriteAllTextAsync(tmp, PCode.Text);

                Input.IsReadOnly = false;
                var buffer     = new StringBuilder();
                var stepOutput = "";
                var curIns     = "";
                var pc         = 0;
                _firstStep = false;
                await RunAsync(
                    tmp,
                    (_, e) =>
                {
                    // Console.Out.WriteLine(e.Data);
                    if (e.Data?.StartsWith("**") ?? false)
                    {
                        var output = stepOutput;
                        var ins    = curIns;
                        Dispatcher.Invoke(() =>
                        {
                            Stack.Text = buffer.ToString();
                            Exec.Text += output;
                            PCode.Focus();
                            //Console.Out.WriteLine(pc);
                            if (pc == -99)
                            {
                                return;
                            }
                            var idx = PCode.GetCharacterIndexFromLineIndex(pc);
                            PCode.Select(idx, ins.Length);
                        }, DispatcherPriority.Render);
                        buffer.Clear();
                        stepOutput = "";
                        curIns     = "";
                    }
                    else if (e.Data?.StartsWith("print") ?? false)
                    {
                        stepOutput = e.Data + "\n";
                    }
                    else if (e.Data?.StartsWith("Press") ?? false)
                    {
                        // do nothing
                    }
                    else
                    {
                        if (e.Data?.StartsWith("-->") ?? false)
                        {
                            curIns = e.Data.Substring(9);     // catch ins
                        }

                        if (e.Data?.StartsWith("PC =") ?? false)
                        {
                            Console.Out.WriteLine(e.Data.Substring(5));
                            pc = int.Parse(e.Data.Substring(5));     // catch PC
                        }
                        buffer.AppendLine(e.Data);
                    }
                },
                    true
                    );
            }
            await(_inputWriter?.WriteLineAsync("c") ?? Task.FromResult(1));
        }
Exemple #2
0
        public void Operators()
        {
            string eq_tes1 = null, eq_tes2 = null;

            Assert.AreEqual(eq_tes1, null, "string null  eq  null");
            Assert.IsTrue(eq_tes1 == null, "string null  ==  null  is true");
            Assert.IsFalse(eq_tes1 != null, "string null  !=  null  is false");
            Assert.AreEqual(eq_tes1, eq_tes2, "string null  eq  string null ");
            Assert.IsTrue(eq_tes1 == eq_tes2, "string null  ==  string null  is true");
            Assert.IsFalse(eq_tes1 != eq_tes2, "string null  !=  string null  is false");

            PathInfo path_eq_tes1 = null, path_eq_tes2 = null;

            // Compare not assigned PathInfo property with null - null == null

            Assert.AreEqual(path_eq_tes1, null, "PathInfo null  eq  null");
            Assert.IsTrue(path_eq_tes1 == null, "PathInfo null  ==  null  is true");
            Assert.IsFalse(path_eq_tes1 != null, "PathInfo null  !=  null  is false");
            Assert.AreEqual(path_eq_tes1, path_eq_tes2, "PathInfo null  eq  PathInfo null ");
            Assert.IsTrue(path_eq_tes1 == path_eq_tes2, "PathInfo null  ==  PathInfo null  is true");
            Assert.IsFalse(path_eq_tes1 != path_eq_tes2, "PathInfo null  !=  PathInfo null  is false");
            Assert.IsFalse(path_eq_tes1 < path_eq_tes2, "PathInfo null  <  PathInfo null  is false");
            Assert.IsFalse(path_eq_tes1 > path_eq_tes2, "PathInfo null  >  PathInfo null  is false");

            // Compare empty PathInfo() object with null - new PathInfo() != null

            Assert.AreNotEqual(new PathInfo(), null, "new PathInfo()  not eq  null");
            Assert.IsFalse(new PathInfo() == null, "new PathInfo() == null  is false");
            Assert.IsTrue(new PathInfo() != null, "new PathInfo() != null  is true");
            Assert.AreNotEqual(new PathInfo(), path_eq_tes2, "new PathInfo()  not eq  PathInfo null");
            Assert.IsFalse(new PathInfo() == path_eq_tes2, "new PathInfo() == PathInfo null  is false");
            Assert.IsTrue(new PathInfo() != path_eq_tes2, "new PathInfo() != PathInfo null  is true");
            Assert.IsFalse(new PathInfo() < path_eq_tes2, "new PathInfo() < PathInfo null  is false");
            Assert.IsTrue(new PathInfo() > path_eq_tes2, "new PathInfo() > PathInfo null  is true");
            Assert.IsTrue(new PathInfo().CompareTo(path_eq_tes2) > 0, "new PathInfo().CompareTo(PathInfo null) > 0  is true");

            // Compare empty PathInfo() object with empty PathInfo() - new PathInfo() == new PathInfo() as two empty paths

            path_eq_tes2 = new PathInfo();
            Assert.AreEqual(new PathInfo(), new PathInfo(), "new PathInfo()  eq  new PathInfo()");
            Assert.IsTrue(new PathInfo() == new PathInfo(), "new PathInfo() == new PathInfo()  is true");
            Assert.IsFalse(new PathInfo() != new PathInfo(), "new PathInfo() != new PathInfo()  is false");
            Assert.IsFalse(new PathInfo() < new PathInfo(), "new PathInfo() < new PathInfo()  is false");
            Assert.IsFalse(new PathInfo() > new PathInfo(), "new PathInfo() > new PathInfo()  is false");
            Assert.IsTrue(new PathInfo().CompareTo(new PathInfo()) == 0, "new PathInfo().CompareTo(new PathInfo()) == 0  is true");

            // Verify the equivalence checking of two equivalent paths

            var temp_path_string = IOPath.GetTempPath();

            Assert.AreEqual(new PathInfo(temp_path_string), new PathInfo(new PathInfo(temp_path_string)), "new PathInfo(GetTempPath())  eq  new PathInfo(GetTempPath())");
            Assert.IsTrue(new PathInfo(temp_path_string) == new PathInfo(new PathInfo(temp_path_string)), "new PathInfo(GetTempPath()) == new PathInfo(GetTempPath())  is true");
            Assert.IsFalse(new PathInfo(temp_path_string) != new PathInfo(new PathInfo(temp_path_string)), "new PathInfo(GetTempPath()) != new PathInfo(GetTempPath())  is false");

            // Verify the equivalence checking of two inequivalent paths

            var temp_file_string = IOPath.GetTempFileName();

            Assert.AreNotEqual(new PathInfo(temp_path_string), new PathInfo(new PathInfo(temp_file_string)), "new PathInfo(GetTempPath())  not eq  new PathInfo(GetTempFileName())");
            Assert.IsFalse(new PathInfo(temp_path_string) == new PathInfo(new PathInfo(temp_file_string)), "new PathInfo(GetTempPath()) == new PathInfo(GetTempFileName())  is false");
            Assert.IsTrue(new PathInfo(temp_path_string) != new PathInfo(new PathInfo(temp_file_string)), "new PathInfo(GetTempPath()) != new PathInfo(GetTempFileName())  is true");

            // Verify the comparison of two paths

            Assert.IsTrue(new PathInfo(@"C:\Z") > new PathInfo(@"C:\A"), @" C:\Z) > C:\A  is true");
            Assert.IsTrue(new PathInfo(@"C:\A") < new PathInfo(@"C:\Z"), @" C:\A) < C:\Z  is true");
            Assert.IsTrue(new PathInfo(@"C:\Z").CompareTo(new PathInfo(@"C:\A")) > 0, "new PathInfo(C:/Z).CompareTo(new PathInfo(C:/A)) > 0  is true");
            Assert.IsFalse(new PathInfo(@"C:\A\Z") > new PathInfo(@"C:\Z\A"), @" C:\A\Z < C:\Z\A  is false");
            Assert.IsFalse(new PathInfo(@"C:\Z\A") < new PathInfo(@"C:\A\Z"), @" C:\Z\A > C:\A\Z  is false");
            Assert.IsTrue(new PathInfo(@"C:\A\Z").CompareTo(new PathInfo(@"C:\Z\A")) < 0, "new PathInfo(C:/A/Z).CompareTo(new PathInfo(C:/Z/A)) < 0  is true");
            Assert.IsTrue(new PathInfo(@"C:\Z").CompareTo(new PathInfo(@"C:\A\Z")) > 0, @" 'C:\Z'.CompareTo('C:\A') > 0  is true");
            Assert.IsTrue(new PathInfo(@"C:\B").CompareTo(new PathInfo(@"C:\Z\A")) < 0, @" 'C:\A'.CompareTo('C:\Z') < 0  is true");

            // Combine operator

            var temp_path = new PathInfo(IOPath.GetTempPath());
            var some_file = temp_path / "some_file_name.txt";

            Assert.AreEqual(some_file, IOPath.Combine(temp_path_string, "some_file_name.txt"), "Combine / operator");

            // Hash code verification

            Assert.IsTrue(new PathInfo(@"C:\Z").GetHashCode() == new PathInfo(@"c:\z").GetHashCode(), @"A hash code case insensitive");

            var rnd = new Random(Environment.TickCount);

            for (int i = 0; i < 20000; i++)
            {
                var name = new PathInfo().GenerateRandom(null, null, false).FileName;
                var mask = new StringBuilder(new PathInfo().GenerateRandom(null, null, false).FileName);
                for (int k = 0; k < 8; k++)
                {
                    mask[rnd.Next(mask.Length)] = name[rnd.Next(name.Length)];
                }
                for (int k = 0; k < 5; k++)
                {
                    mask[rnd.Next(mask.Length)] = '?';
                    mask[rnd.Next(mask.Length)] = '*';
                }
                var stringmask    = mask.ToString().Replace("***", "*").Replace("**", "*");
                var regex_pattern = mask.Replace("*", ".*").Replace("?", ".").Insert(0, '^').Append('$').ToString();

                if (Regex.IsMatch(name, regex_pattern, System.Text.RegularExpressions.RegexOptions.CultureInvariant | System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    != PathInfo.MatchesMaskComparer(name, stringmask))
                {
                    Assert.Fail(string.Format("{0} and {1}", name, stringmask));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Photoes the captured.
        /// </summary>
        /// <param name="o">The o.</param>
        private void PhotoCaptured(object o)
        {
            PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs;

            if (eventArgs == null)
            {
                return;
            }
            try
            {
                Log.Debug(TranslationStrings.MsgPhotoTransferBegin);
                eventArgs.CameraDevice.IsBusy = true;
                var extension = Path.GetExtension(eventArgs.FileName);

                // the capture is for live view preview
                if (LiveViewManager.PreviewRequest.ContainsKey(eventArgs.CameraDevice) &&
                    LiveViewManager.PreviewRequest[eventArgs.CameraDevice])
                {
                    LiveViewManager.PreviewRequest[eventArgs.CameraDevice] = false;
                    var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + extension);
                    eventArgs.CameraDevice.TransferFile(eventArgs.Handle, file);
                    eventArgs.CameraDevice.IsBusy           = false;
                    eventArgs.CameraDevice.TransferProgress = 0;
                    eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);
                    LiveViewManager.Preview[eventArgs.CameraDevice] = file;
                    LiveViewManager.OnPreviewCaptured(eventArgs.CameraDevice, file);
                    return;
                }

                CameraProperty property = eventArgs.CameraDevice.LoadProperties();
                PhotoSession   session  = (PhotoSession)eventArgs.CameraDevice.AttachedPhotoSession ??
                                          ServiceProvider.Settings.DefaultSession;
                StaticHelper.Instance.SystemMessage = "";


                if (!eventArgs.CameraDevice.CaptureInSdRam || PhotoUtils.IsMovie(eventArgs.FileName))
                {
                    if (property.NoDownload)
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);
                        StaticHelper.Instance.SystemMessage = "File transfer disabled";
                        return;
                    }
                    if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg"))
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);
                        return;
                    }
                }

                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferBegin;

                string tempFile = Path.GetTempFileName();

                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                Stopwatch stopWatch = new Stopwatch();
                // transfer file from camera to temporary folder
                // in this way if the session folder is used as hot folder will prevent write errors
                stopWatch.Start();
                if (!eventArgs.CameraDevice.CaptureInSdRam && session.DownloadThumbOnly)
                {
                    eventArgs.CameraDevice.TransferFileThumb(eventArgs.Handle, tempFile);
                }
                else
                {
                    eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile);
                }
                eventArgs.CameraDevice.TransferProgress = 0;
                eventArgs.CameraDevice.IsBusy           = false;
                stopWatch.Stop();
                string strTransfer = "Transfer time : " + stopWatch.Elapsed.TotalSeconds.ToString("##.###") + " Speed :" +
                                     Math.Round(
                    new System.IO.FileInfo(tempFile).Length / 1024.0 / 1024 /
                    stopWatch.Elapsed.TotalSeconds, 2) + " Mb/s";
                Log.Debug(strTransfer);

                string fileName = "";
                if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam)
                {
                    fileName =
                        session.GetNextFileName(eventArgs.FileName, eventArgs.CameraDevice, tempFile);
                }
                else
                {
                    fileName = Path.Combine(session.Folder, eventArgs.FileName);
                    if (File.Exists(fileName) && !session.AllowOverWrite)
                    {
                        fileName =
                            StaticHelper.GetUniqueFilename(
                                Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) +
                                "_", 0,
                                Path.GetExtension(fileName));
                    }
                }

                if (session.AllowOverWrite && File.Exists(fileName))
                {
                    PhotoUtils.WaitForFile(fileName);
                    File.Delete(fileName);
                }

                // make lower case extension
                if (session.LowerCaseExtension && !string.IsNullOrEmpty(Path.GetExtension(fileName)))
                {
                    fileName = Path.Combine(Path.GetDirectoryName(fileName),
                                            Path.GetFileNameWithoutExtension(fileName) + Path.GetExtension(fileName).ToLower());
                }


                if (session.AskSavePath)
                {
                    SaveFileDialog dialog = new SaveFileDialog();
                    dialog.Filter           = "All files|*.*";
                    dialog.Title            = "Save captured photo";
                    dialog.FileName         = fileName;
                    dialog.InitialDirectory = Path.GetDirectoryName(fileName);
                    if (dialog.ShowDialog() == true)
                    {
                        fileName = dialog.FileName;
                    }
                    else
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        if (File.Exists(tempFile))
                        {
                            File.Delete(tempFile);
                        }
                        return;
                    }
                }

                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }


                string backupfile = null;
                if (session.BackUp)
                {
                    backupfile = session.CopyBackUp(tempFile, fileName);
                    if (string.IsNullOrEmpty(backupfile))
                    {
                        StaticHelper.Instance.SystemMessage = "Unable to save the backup";
                    }
                }

                // execute plugins which are executed before transfer
                if (ServiceProvider.Settings.DefaultSession.AutoExportPluginConfigs.Count((x) => !x.RunAfterTransfer) > 0)
                {
                    FileItem tempitem = new FileItem(tempFile);
                    tempitem.Name           = Path.GetFileName(fileName);
                    tempitem.BackupFileName = backupfile;
                    tempitem.Series         = session.Series;
                    tempitem.AddTemplates(eventArgs.CameraDevice, session);
                    ExecuteAutoexportPlugins(eventArgs.CameraDevice, tempitem, false);
                }


                if ((!eventArgs.CameraDevice.CaptureInSdRam || PhotoUtils.IsMovie(fileName)) && session.DeleteFileAfterTransfer)
                {
                    eventArgs.CameraDevice.DeleteObject(new DeviceObject()
                    {
                        Handle = eventArgs.Handle
                    });
                }

                File.Copy(tempFile, fileName);

                if (File.Exists(tempFile))
                {
                    PhotoUtils.WaitForFile(tempFile);
                    File.Delete(tempFile);
                }

                if (session.WriteComment)
                {
                    if (!string.IsNullOrEmpty(session.Comment))
                    {
                        Exiv2Helper.SaveComment(fileName, session.Comment);
                    }
                    if (session.SelectedTag1 != null && !string.IsNullOrEmpty(session.SelectedTag1.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag1.Value);
                    }
                    if (session.SelectedTag2 != null && !string.IsNullOrEmpty(session.SelectedTag2.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag2.Value);
                    }
                    if (session.SelectedTag3 != null && !string.IsNullOrEmpty(session.SelectedTag3.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag3.Value);
                    }
                    if (session.SelectedTag4 != null && !string.IsNullOrEmpty(session.SelectedTag4.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag4.Value);
                    }
                }

                if (session.ExternalData != null)
                {
                    session.ExternalData.FileName = fileName;
                }

                // prevent crash og GUI when item count updated
                Dispatcher.Invoke(new Action(delegate
                {
                    try
                    {
                        _selectedItem = session.GetNewFileItem(fileName);
                        _selectedItem.BackupFileName = backupfile;
                        _selectedItem.Series         = session.Series;
                        // _selectedItem.Transformed = tempitem.Transformed;
                        _selectedItem.AddTemplates(eventArgs.CameraDevice, session);
                        ServiceProvider.Database.Add(new DbFile(_selectedItem, eventArgs.CameraDevice.SerialNumber, eventArgs.CameraDevice.DisplayName, session.Name));
                    }
                    catch (Exception ex)
                    {
                    }
                }));

                // execute plugins which are executed after transfer
                ExecuteAutoexportPlugins(eventArgs.CameraDevice, _selectedItem, true);

                Dispatcher.Invoke(() =>
                {
                    _selectedItem.RemoveThumbs();
                    session.Add(_selectedItem);
                    ServiceProvider.OnFileTransfered(_selectedItem);
                });


                if (ServiceProvider.Settings.MinimizeToTrayIcon && !IsVisible && !ServiceProvider.Settings.HideTrayNotifications)
                {
                    MyNotifyIcon.HideBalloonTip();
                    MyNotifyIcon.ShowBalloonTip("Photo transfered", fileName, BalloonIcon.Info);
                }

                ServiceProvider.DeviceManager.LastCapturedImage[eventArgs.CameraDevice] = fileName;

                //select the new file only when the multiple camera support isn't used to prevent high CPU usage on raw files
                if (ServiceProvider.Settings.AutoPreview &&
                    !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&&
                    !ServiceProvider.Settings.UseExternalViewer)
                {
                    if ((Path.GetExtension(fileName).ToLower() == ".jpg" && ServiceProvider.Settings.AutoPreviewJpgOnly) ||
                        !ServiceProvider.Settings.AutoPreviewJpgOnly)
                    {
                        if ((DateTime.Now - _lastLoadTime).TotalSeconds < 4)
                        {
                            _selectiontimer.Stop();
                            _selectiontimer.Start();
                        }
                        else
                        {
                            ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, _selectedItem);
                        }
                    }
                }
                _lastLoadTime = DateTime.Now;
                //ServiceProvider.Settings.Save(session);
                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferDone + " " + strTransfer;

                if (ServiceProvider.Settings.UseExternalViewer &&
                    File.Exists(ServiceProvider.Settings.ExternalViewerPath))
                {
                    string arg = ServiceProvider.Settings.ExternalViewerArgs;
                    arg = arg.Contains("%1") ? arg.Replace("%1", fileName) : arg + " " + fileName;
                    PhotoUtils.Run(ServiceProvider.Settings.ExternalViewerPath, arg, ProcessWindowStyle.Normal);
                }
                if (ServiceProvider.Settings.PlaySound)
                {
                    PhotoUtils.PlayCaptureSound();
                }
                eventArgs.CameraDevice.ReleaseResurce(eventArgs.Handle);

                //show fullscreen only when the multiple camera support isn't used
                if (ServiceProvider.Settings.Preview &&
                    !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&&
                    !ServiceProvider.Settings.UseExternalViewer)
                {
                    ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.FullScreenWnd_ShowTimed);
                }

                Log.Debug("Photo transfer done.");
            }
            catch (Exception ex)
            {
                eventArgs.CameraDevice.IsBusy       = false;
                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferError + " " + ex.Message;
                Log.Error("Transfer error !", ex);
            }
            // not indicated to be used
            GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
Exemple #4
0
        /// <summary>
        /// Photoes the captured.
        /// </summary>
        /// <param name="o">The o.</param>
        private void PhotoCaptured(object o)
        {
            PhotoCapturedEventArgs eventArgs = o as PhotoCapturedEventArgs;

            if (eventArgs == null)
            {
                return;
            }
            try
            {
                Log.Debug("Photo transfer begin.");
                eventArgs.CameraDevice.IsBusy = true;
                CameraProperty property = eventArgs.CameraDevice.LoadProperties();
                PhotoSession   session  = (PhotoSession)eventArgs.CameraDevice.AttachedPhotoSession ??
                                          ServiceProvider.Settings.DefaultSession;
                StaticHelper.Instance.SystemMessage = "";

                var extension = Path.GetExtension(eventArgs.FileName);

                if (!eventArgs.CameraDevice.CaptureInSdRam || (extension != null && extension.ToLower() == ".mov"))
                {
                    if (property.NoDownload)
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        return;
                    }
                    if (extension != null && (session.DownloadOnlyJpg && extension.ToLower() != ".jpg"))
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        return;
                    }
                }

                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferBegin;

                string tempFile = Path.GetTempFileName();

                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                if (!eventArgs.CameraDevice.CaptureInSdRam && session.DownloadThumbOnly)
                {
                    eventArgs.CameraDevice.TransferFileThumb(eventArgs.Handle, tempFile);
                }
                else
                {
                    eventArgs.CameraDevice.TransferFile(eventArgs.Handle, tempFile);
                }

                string fileName = "";
                if (!session.UseOriginalFilename || eventArgs.CameraDevice.CaptureInSdRam)
                {
                    fileName =
                        session.GetNextFileName(eventArgs.FileName, eventArgs.CameraDevice);
                }
                else
                {
                    fileName = Path.Combine(session.Folder, eventArgs.FileName);
                    if (File.Exists(fileName) && !session.AllowOverWrite)
                    {
                        fileName =
                            StaticHelper.GetUniqueFilename(
                                Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) +
                                "_", 0,
                                Path.GetExtension(fileName));
                    }
                }

                if (session.AllowOverWrite && File.Exists(fileName))
                {
                    PhotoUtils.WaitForFile(fileName);
                    File.Delete(fileName);
                }

                // make lower case extension
                if (session.LowerCaseExtension && !string.IsNullOrEmpty(Path.GetExtension(fileName)))
                {
                    fileName = Path.Combine(Path.GetDirectoryName(fileName),
                                            Path.GetFileNameWithoutExtension(fileName) + Path.GetExtension(fileName).ToLower());
                }


                if (session.AskSavePath)
                {
                    SaveFileDialog dialog = new SaveFileDialog();
                    dialog.Filter           = "All files|*.*";
                    dialog.Title            = "Save captured photo";
                    dialog.FileName         = fileName;
                    dialog.InitialDirectory = Path.GetDirectoryName(fileName);
                    if (dialog.ShowDialog() == true)
                    {
                        fileName = dialog.FileName;
                    }
                    else
                    {
                        eventArgs.CameraDevice.IsBusy = false;
                        if (File.Exists(tempFile))
                        {
                            File.Delete(tempFile);
                        }
                        return;
                    }
                }

                if (!Directory.Exists(Path.GetDirectoryName(fileName)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(fileName));
                }

                File.Copy(tempFile, fileName);

                string backupfile = null;
                if (session.BackUp)
                {
                    backupfile = session.CopyBackUp(tempFile, fileName);
                    if (string.IsNullOrEmpty(backupfile))
                    {
                        StaticHelper.Instance.SystemMessage = "Unable to save the backup";
                    }
                }

                if (!eventArgs.CameraDevice.CaptureInSdRam && session.DeleteFileAfterTransfer)
                {
                    eventArgs.CameraDevice.DeleteObject(new DeviceObject()
                    {
                        Handle = eventArgs.Handle
                    });
                }


                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }

                if (session.WriteComment)
                {
                    if (!string.IsNullOrEmpty(session.Comment))
                    {
                        Exiv2Helper.SaveComment(fileName, session.Comment);
                    }
                    if (session.SelectedTag1 != null && !string.IsNullOrEmpty(session.SelectedTag1.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag1.Value);
                    }
                    if (session.SelectedTag2 != null && !string.IsNullOrEmpty(session.SelectedTag2.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag2.Value);
                    }
                    if (session.SelectedTag3 != null && !string.IsNullOrEmpty(session.SelectedTag3.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag3.Value);
                    }
                    if (session.SelectedTag4 != null && !string.IsNullOrEmpty(session.SelectedTag4.Value))
                    {
                        Exiv2Helper.AddKeyword(fileName, session.SelectedTag4.Value);
                    }
                }

                if (session.ExternalData != null)
                {
                    session.ExternalData.FileName = fileName;
                }

                // prevent crash og GUI when item count updated
                Dispatcher.Invoke(new Action(delegate
                {
                    try
                    {
                        _selectedItem = session.GetNewFileItem(fileName);
                        _selectedItem.BackupFileName = backupfile;
                        _selectedItem.Series         = session.Series;
                        _selectedItem.AddTemplates(eventArgs.CameraDevice, session);
                        ServiceProvider.Database.Add(new DbFile(_selectedItem, eventArgs.CameraDevice.DisplayName,
                                                                eventArgs.CameraDevice.SerialNumber, session.Name));
                    }
                    catch (Exception ex)
                    {
                    }
                }));

                foreach (AutoExportPluginConfig plugin in ServiceProvider.Settings.DefaultSession.AutoExportPluginConfigs)
                {
                    if (!plugin.IsEnabled)
                    {
                        continue;
                    }
                    var pl = ServiceProvider.PluginManager.GetAutoExportPlugin(plugin.Type);
                    try
                    {
                        pl.Execute(_selectedItem, plugin);
                        ServiceProvider.Analytics.PluginExecute(plugin.Type);
                        Log.Debug("AutoexportPlugin executed " + plugin.Type);
                    }
                    catch (Exception ex)
                    {
                        plugin.IsError = true;
                        plugin.Error   = ex.Message;
                        plugin.IsRedy  = true;
                        Log.Error("Error to apply plugin", ex);
                    }
                }

                Dispatcher.Invoke(() =>
                {
                    _selectedItem.RemoveThumbs();
                    session.Add(_selectedItem);
                    ServiceProvider.OnFileTransfered(_selectedItem);
                });

                if (ServiceProvider.Settings.MinimizeToTrayIcon && !IsVisible && !ServiceProvider.Settings.HideTrayNotifications)
                {
                    MyNotifyIcon.HideBalloonTip();
                    MyNotifyIcon.ShowBalloonTip("Photo transfered", fileName, BalloonIcon.Info);
                }

                ServiceProvider.DeviceManager.LastCapturedImage[eventArgs.CameraDevice] = fileName;

                //select the new file only when the multiple camera support isn't used to prevent high CPU usage on raw files
                if (ServiceProvider.Settings.AutoPreview &&
                    !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&&
                    !ServiceProvider.Settings.UseExternalViewer)
                {
                    if ((Path.GetExtension(fileName).ToLower() == ".jpg" && ServiceProvider.Settings.AutoPreviewJpgOnly) ||
                        !ServiceProvider.Settings.AutoPreviewJpgOnly)
                    {
                        if ((DateTime.Now - _lastLoadTime).TotalSeconds < 4)
                        {
                            _selectiontimer.Stop();
                            _selectiontimer.Start();
                        }
                        else
                        {
                            ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.Select_Image, _selectedItem);
                        }
                    }
                }
                _lastLoadTime = DateTime.Now;
                //ServiceProvider.Settings.Save(session);
                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferDone;
                eventArgs.CameraDevice.IsBusy       = false;
                //show fullscreen only when the multiple camera support isn't used
                if (ServiceProvider.Settings.Preview &&
                    !ServiceProvider.WindowsManager.Get(typeof(MultipleCameraWnd)).IsVisible&&
                    !ServiceProvider.Settings.UseExternalViewer)
                {
                    ServiceProvider.WindowsManager.ExecuteCommand(WindowsCmdConsts.FullScreenWnd_ShowTimed);
                }
                if (ServiceProvider.Settings.UseExternalViewer &&
                    File.Exists(ServiceProvider.Settings.ExternalViewerPath))
                {
                    string arg = ServiceProvider.Settings.ExternalViewerArgs;
                    arg = arg.Contains("%1") ? arg.Replace("%1", fileName) : arg + " " + fileName;
                    PhotoUtils.Run(ServiceProvider.Settings.ExternalViewerPath, arg, ProcessWindowStyle.Normal);
                }
                if (ServiceProvider.Settings.PlaySound)
                {
                    PhotoUtils.PlayCaptureSound();
                }
                Log.Debug("Photo transfer done.");
            }
            catch (Exception ex)
            {
                eventArgs.CameraDevice.IsBusy       = false;
                StaticHelper.Instance.SystemMessage = TranslationStrings.MsgPhotoTransferError + " " + ex.Message;
                Log.Error("Transfer error !", ex);
            }
            // not indicated to be used
            GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
Exemple #5
0
 public TemporaryFile()
     : base(new FileInfo(IOPath.GetTempFileName()))
 {
 }
 protected override bool TryGetCodeFile(Parameters param, out string codeFile)
 {
     codeFile = Path.GetTempFileName();
     File.WriteAllText(codeFile, Encoding.UTF8.GetString(Properties.Resources.dependent_peptides));
     return(true);
 }
Exemple #7
0
 public TemporaryFile()
 {
     _path = IOPath.GetTempFileName();
 }
        private async Task M1()
        {
            cb = new RoslynCodeBase(DebugFn)
            {
                JTF2       = JTF2,
                SourceText = Filename != null?File.ReadAllText(Filename) : "",
                                 DocumentTitle = Filename ?? "Untitled",
                                 Rectangle     = new Rectangle(),
                                 FontSize      = 14.0,
                                 FontFamily    = new FontFamily("Lucida Console")
            };
            await cb.UpdateFormattedTextAsync();

            DirectoryInfo d = new DirectoryInfo(@"C:\temp\code");

            LocalPrintServer s = new LocalPrintServer();

            // var pdfQueues = s.GetPrintQueues().Where(queue => queue.FullName.ToLowerInvariant().Contains("pdf") && !queue.IsInError && !queue.IsOffline).ToList();
            // PrintDialog pd1  = new PrintDialog();
            //pd1.ShowDialog();
            _dp       = new RoslynPaginator(cb);
            PageCount = _dp.PageCount;
            // pd1.PrintDocument(_dp, "code");

            // PrintQueue q;
            // if (pdfQueues.Count() == 1)
            // {
            // q = pdfQueues.First();
            // }
            // else
            // {
            // q = pdfQueues.Skip(1).First();
            // }

            var tf = Path.Combine(d.FullName, Path.ChangeExtension(Path.GetFileName(Path.GetTempFileName()), ".xps"));
            //Path.GetTempFileName();

            var _xpsDocument = new XpsDocument(tf,
                                               FileAccess.ReadWrite);

            var xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);

            xpsDocumentWriter.Write(_dp);
            _xpsDocument.Close();
            var f2 = Path.Combine(d.FullName, Path.ChangeExtension(Path.GetFileName(Path.GetTempFileName()), ".xps"));

            File.Copy(tf, f2);
            var f3 = Path.Combine(d.FullName, Path.ChangeExtension(Path.GetFileName(Path.GetTempFileName()), ".xps"));

            File.Copy(tf, f3);

            // var j = q.AddJob("code", f2, false);
            //j.Commit();
            _xps2            = new XpsDocument(f2, FileAccess.Read);
            DocView.Document = _xps2.GetFixedDocumentSequence();
            // grid.Children.Remove(cb);
            // DocView.Document = cb;
            var        b1 = _dp._bmp;
            ImageBrush b2 = new ImageBrush(b1);

            rect2.Fill     = b2;
            AllPagesBitmap = b1;
            b2.Stretch     = Stretch.Uniform;
            CurPage        = 0;
        }