Esempio n. 1
0
 /// <summary>
 /// Captures the specified camera device.
 /// </summary>
 /// <param name="o">ICameraDevice</param>
 public static void Capture(object o)
 {
     if (o != null)
     {
         var camera = o as ICameraDevice;
         if (camera != null)
         {
             ServiceProvider.DeviceManager.LastCapturedImage[camera] = "";
             CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(camera);
             for (int i = 0; i < property.Delay; i++)
             {
                 StaticHelper.Instance.SystemMessage = "Countig down " + (property.Delay - i);
                 Thread.Sleep(1000);
             }
             if (property.UseExternalShutter && property.SelectedConfig != null)
             {
                 ServiceProvider.ExternalDeviceManager.AssertFocus(property.SelectedConfig);
                 Thread.Sleep(1000);
                 ServiceProvider.ExternalDeviceManager.OpenShutter(property.SelectedConfig);
                 Thread.Sleep(1000);
                 ServiceProvider.ExternalDeviceManager.CloseShutter(property.SelectedConfig);
                 return;
             }
             camera.CapturePhoto();
             ServiceProvider.Analytics.CameraCapture(camera);
         }
     }
 }
Esempio n. 2
0
        private string FormatFileName(ICameraDevice device, string ext, bool incremetCounter = true)
        {
            CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(device);
            string         res      = FileNameTemplate;

            if (!res.Contains("$C") && !AllowOverWrite)
            {
                res += "$C";
            }

            if (UseCameraCounter)
            {
                if (incremetCounter)
                {
                    property.Counter = property.Counter + property.CounterInc;
                }
                res = res.Replace("$C", property.Counter.ToString(new string('0', LeadingZeros)));
            }
            else
            {
                if (incremetCounter)
                {
                    Counter++;
                }
                res = res.Replace("$C", Counter.ToString(new string('0', LeadingZeros)));
            }
            res = res.Replace("$N", Name.Trim());
            if (device.ExposureCompensation != null)
            {
                res = res.Replace("$E", device.ExposureCompensation.Value != "0" ? device.ExposureCompensation.Value : "");
            }
            res = res.Replace("$D", DateTime.Now.ToString("yyyy-MM-dd"));
            res = res.Replace("$B", Barcode ?? "");

            var date          = new DateTime(1970, 1, 1, 0, 0, 0, DateTime.Now.Kind);
            var unixTimestamp = System.Convert.ToInt64((DateTime.Now - date).TotalSeconds);

            res = res.Replace("$UTime", unixTimestamp.ToString());

            res = res.Replace("$Type", GetType(ext));

            res = res.Replace("$X", property.DeviceName.Replace(":", "_").Replace("?", "_").Replace("*", "_"));
            res = res.Replace("$Tag1", SelectedTag1 != null ? SelectedTag1.Value.Trim() : "");
            res = res.Replace("$Tag2", SelectedTag1 != null ? SelectedTag2.Value.Trim() : "");
            res = res.Replace("$Tag3", SelectedTag1 != null ? SelectedTag3.Value.Trim() : "");
            res = res.Replace("$Tag4", SelectedTag1 != null ? SelectedTag4.Value.Trim() : "");
            //prevent multiple \ if a tag is empty
            while (res.Contains(@"\\"))
            {
                res = res.Replace(@"\\", @"\");
            }
            // if the file name start with \ the Path.Combine isn't work right
            if (res.StartsWith("\\"))
            {
                res = res.Substring(1);
            }
            return(res);
        }
Esempio n. 3
0
        private string FormatFileName(ICameraDevice device, string ext, bool incremetCounter = true)
        {
            CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(device);
            string         res      = FileNameTemplate;

            if (!res.Contains("$C"))
            {
                res += "$C";
            }

            if (UseCameraCounter)
            {
                if (incremetCounter)
                {
                    property.Counter = property.Counter + property.CounterInc;
                }
                res = res.Replace("$C", property.Counter.ToString(new string('0', LeadingZeros)));
            }
            else
            {
                if (incremetCounter)
                {
                    Counter++;
                }
                res = res.Replace("$C", Counter.ToString(new string('0', LeadingZeros)));
            }
            res = res.Replace("$N", Name.Trim());
            if (device.ExposureCompensation != null)
            {
                res = res.Replace("$E", device.ExposureCompensation.Value != "0" ? device.ExposureCompensation.Value : "");
            }
            res = res.Replace("$D", DateTime.Now.ToString("yyyy-MM-dd"));

            res = res.Replace("$Type", GetType(ext));

            res = res.Replace("$UTime", ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds).ToString());

            res = res.Replace("$Qt", (String.IsNullOrWhiteSpace(QuickTag) || ServiceProvider.Settings.DefaultSession.QuickTagOption == QuickTagOptions.None) ? "" : QuickTag + "_");
            res = res.Replace("$B", LastBarcode);
            res = res.Replace("$-", BarcodeDelimiter.ToString());

            res = res.Replace("$X", property.DeviceName.Replace(":", "_").Replace("?", "_").Replace("*", "_"));
            res = res.Replace("$Tag1", SelectedTag1 != null ? SelectedTag1.Value.Trim() : "");
            res = res.Replace("$Tag2", SelectedTag1 != null ? SelectedTag2.Value.Trim() : "");
            res = res.Replace("$Tag3", SelectedTag1 != null ? SelectedTag3.Value.Trim() : "");
            res = res.Replace("$Tag4", SelectedTag1 != null ? SelectedTag4.Value.Trim() : "");
            //prevent multiple \ if a tag is empty
            while (res.Contains(@"\\"))
            {
                res = res.Replace(@"\\", @"\");
            }
            // if the file name start with \ the Path.Combine isn't work right
            if (res.StartsWith("\\"))
            {
                res = res.Substring(1);
            }
            return(res);
        }
Esempio n. 4
0
        private void KeyDownThread(KeyboardHookEventArgs e)
        {
            _eventIsBusy = true;
            try
            {
                Key inputKey = KeyInterop.KeyFromVirtualKey((int)e.Key);
                foreach (var item in ServiceProvider.Settings.Actions)
                {
                    if (!item.Global)
                    {
                        continue;
                    }
                    if (item.Alt == e.isAltPressed && item.Ctrl == e.isCtrlPressed && item.KeyEnum == inputKey)
                    {
                        ServiceProvider.WindowsManager.ExecuteCommand(item.Name);
                    }
                }
                ICameraDevice lastDevice = null;
                foreach (ICameraDevice device in ServiceProvider.DeviceManager.ConnectedDevices)
                {
                    if (lastDevice != null)
                    {
                        lastDevice.WaitForCamera(1500);
                    }

                    // wait for camera to finish last transfer with timeot of 1.5 sec
                    device.WaitForCamera(1500);
                    // skip camera is camera is still busy
                    if (device.IsBusy)
                    {
                        continue;
                    }
                    CameraProperty property = device.LoadProperties();
                    if (property.KeyTrigger.KeyEnum != Key.None && property.KeyTrigger.Alt == e.isAltPressed &&
                        property.KeyTrigger.Ctrl == e.isCtrlPressed &&
                        property.KeyTrigger.KeyEnum == inputKey)
                    {
                        CameraHelper.Capture(device);
                        lastDevice = device;
                    }
                    if (property.KeyTriggerNoAF.KeyEnum != Key.None && property.KeyTriggerNoAF.Alt == e.isAltPressed &&
                        property.KeyTriggerNoAF.Ctrl == e.isCtrlPressed &&
                        property.KeyTriggerNoAF.KeyEnum == inputKey)
                    {
                        CameraHelper.CaptureNoAf(device);
                        lastDevice = device;
                    }
                }
            }
            catch (Exception exception)
            {
                StaticHelper.Instance.SystemMessage = exception.Message;
                Log.Error("Key trigger ", exception);
            }
            _eventIsBusy = false;
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the atached properties to a camera.
        /// </summary>
        /// <param name="cameraDevice">The camera device.</param>
        /// <returns>The atached CameraProperty</returns>
        public static CameraProperty LoadProperties(this ICameraDevice cameraDevice)
        {
            CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(cameraDevice);

            cameraDevice.DisplayName          = property.DeviceName;
            cameraDevice.AttachedPhotoSession = ServiceProvider.Settings.GetSession(property.PhotoSessionName);
            //if (cameraDevice!=null && cameraDevice.GetCapability(CapabilityEnum.CaptureInRam))
            //    cameraDevice.CaptureInSdRam = property.CaptureInSdRam;
            return(property);
        }
 public CameraProperty Get(ICameraDevice device)
 {
     if (device == null)
         return new CameraProperty();
     foreach (CameraProperty cameraProperty in Items)
     {
         if (cameraProperty.SerialNumber == device.SerialNumber)
             return cameraProperty;
     }
     var c = new CameraProperty() {SerialNumber = device.SerialNumber, DeviceName = device.DisplayName};
     Items.Add(c);
     return c;
 }
Esempio n. 7
0
        private string GetCamerasData()
        {
            string res = ":;response:cameras;count:" + ServiceProvider.DeviceManager.ConnectedDevices.Count;

            for (int i = 0; i < ServiceProvider.DeviceManager.ConnectedDevices.Count; i++)
            {
                CameraProperty property =
                    ServiceProvider.Settings.CameraProperties.Get(ServiceProvider.DeviceManager.ConnectedDevices[i]);
                res += string.Format(";serial{0}:{1};model{0}:{2};name{0}:{3}", i + 1,
                                     ServiceProvider.DeviceManager.ConnectedDevices[i].SerialNumber,
                                     ServiceProvider.DeviceManager.ConnectedDevices[i].DeviceName, property.DeviceName);
            }
            return(res);
        }
Esempio n. 8
0
 /// <summary>
 /// Captures the specified camera device.
 /// </summary>
 /// <param name="o">ICameraDevice</param>
 public static void Capture(object o)
 {
     if (o != null)
     {
         var camera = o as ICameraDevice;
         if (camera != null)
         {
             CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(camera);
             if (property.UseExternalShutter && property.SelectedConfig != null)
             {
                 ServiceProvider.ExternalDeviceManager.Start(property.SelectedConfig);
                 return;
             }
             camera.CapturePhoto();
         }
     }
 }
Esempio n. 9
0
 public static void CaptureNoAf(object o)
 {
     if (o != null)
     {
         var camera = o as ICameraDevice;
         if (camera != null)
         {
             CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(camera);
             if (property.UseExternalShutter && property.SelectedConfig != null)
             {
                 ServiceProvider.ExternalDeviceManager.OpenShutter(property.SelectedConfig);
                 Thread.Sleep(200);
                 ServiceProvider.ExternalDeviceManager.CloseShutter(property.SelectedConfig);
                 return;
             }
             camera.CapturePhotoNoAf();
         }
     }
 }
Esempio n. 10
0
        public CameraProperty Get(ICameraDevice device)
        {
            if (device == null)
            {
                return(new CameraProperty());
            }
            foreach (CameraProperty cameraProperty in Items)
            {
                if (cameraProperty.SerialNumber == device.SerialNumber)
                {
                    return(cameraProperty);
                }
            }
            var c = new CameraProperty()
            {
                SerialNumber = device.SerialNumber, DeviceName = device.DisplayName
            };

            Items.Add(c);
            return(c);
        }
Esempio n. 11
0
 /// <summary>
 /// Captures the specified camera device.
 /// </summary>
 /// <param name="o">ICameraDevice</param>
 public static void Capture(object o)
 {
     if (o != null)
     {
         var camera = o as ICameraDevice;
         if (camera != null)
         {
             ServiceProvider.DeviceManager.LastCapturedImage[camera] = "";
             CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(camera);
             if (property.UseExternalShutter && property.SelectedConfig != null)
             {
                 ServiceProvider.ExternalDeviceManager.AssertFocus(property.SelectedConfig);
                 Thread.Sleep(1000);
                 ServiceProvider.ExternalDeviceManager.OpenShutter(property.SelectedConfig);
                 Thread.Sleep(1000);
                 ServiceProvider.ExternalDeviceManager.CloseShutter(property.SelectedConfig);
                 return;
             }
             camera.CapturePhoto();
             ServiceProvider.Analytics.CameraCapture(camera);
         }
     }
 }
Esempio n. 12
0
        private string FormatFileName(ICameraDevice device, string file, bool incremetCounter = true)
        {
            CameraProperty property = ServiceProvider.Settings.CameraProperties.Get(device);
            string         res      = FileNameTemplate;

            if (incremetCounter)
            {
                property.Counter = property.Counter + property.CounterInc;
                Counter++;
            }

            Regex           regPattern = new Regex(@"\[(.*?)\]", RegexOptions.Singleline);
            MatchCollection matchX     = regPattern.Matches(res);

            foreach (Match match in matchX)
            {
                if (ServiceProvider.FilenameTemplateManager.Templates.ContainsKey(match.Value))
                {
                    res = res.Replace(match.Value,
                                      ServiceProvider.FilenameTemplateManager.Templates[match.Value].Pharse(match.Value, this, device,
                                                                                                            file));
                }
            }

            //prevent multiple \ if a tag is empty
            while (res.Contains(@"\\"))
            {
                res = res.Replace(@"\\", @"\");
            }
            // if the file name start with \ the Path.Combine isn't work right
            if (res.StartsWith("\\"))
            {
                res = res.Substring(1);
            }
            return(res);
        }
Esempio n. 13
0
 public CameraPreset()
 {
     Values         = new AsyncObservableCollection <ValuePair>();
     CameraProperty = new CameraProperty();
 }
 public LiveViewViewModel()
 {
     CameraProperty = new CameraProperty();
     CameraDevice = new NotConnectedCameraDevice();
     InitCommands();
 }
 public CameraPreset()
 {
     Values = new AsyncObservableCollection<ValuePair>();
     CameraProperty = new CameraProperty();
 }
Esempio n. 16
0
        public string Pharse(string template, PhotoSession session, ICameraDevice device, string fileName, string tempfileName)
        {
            CameraProperty property = device.LoadProperties();

            switch (template)
            {
            case "[Counter 3 digit]":
            case "[Counter 4 digit]":
            case "[Counter 5 digit]":
            case "[Counter 6 digit]":
            case "[Counter 7 digit]":
            case "[Counter 8 digit]":
            case "[Counter 9 digit]":
                return(session.Counter.ToString(new string('0', Convert.ToInt16(template.Substring(9, 1)))));

            case "[Series 4 digit]":
                return(session.Series.ToString(new string('0', 4)));

            case "[Camera Counter 3 digit]":
            case "[Camera Counter 4 digit]":
            case "[Camera Counter 5 digit]":
            case "[Camera Counter 6 digit]":
            case "[Camera Counter 7 digit]":
            case "[Camera Counter 8 digit]":
            case "[Camera Counter 9 digit]":
                return(property.Counter.ToString(new string('0', Convert.ToInt16(template.Substring(16, 1)))));

            case "[Session Name]":
                return(session.Name);

            case "[Capture Name]":
                return(session.CaptureName);

            case "[Exposure Compensation]":
                if (device != null && device.ExposureCompensation != null)
                {
                    return(device.ExposureCompensation.Value != "0" ? device.ExposureCompensation.Value : "");
                }
                return("");

            case "[FNumber]":
                if (device != null && device.FNumber != null)
                {
                    return(device.FNumber.Value ?? "");
                }
                return("");

            case "[Date yyyy-MM-dd]":
                return(DateTime.Now.ToString("yyyy-MM-dd"));

            case "[Date yyyy]":
                return(DateTime.Now.ToString("yyyy"));

            case "[Date yyyy-MM]":
                return(DateTime.Now.ToString("yyyy-MM"));

            case "[Date MMM]":
                return(DateTime.Now.ToString("MMM"));

            case "[Date yyyy-MM-dd-hh-mm-ss]":
                return(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));

            case "[Time hh-mm-ss]":
                return(DateTime.Now.ToString("HH-mm-ss"));

            case "[Time hh-mm]":
                return(DateTime.Now.ToString("HH-mm"));

            case "[Time hh]":
                return(DateTime.Now.ToString("HH"));

            case "[Barcode]":
                return(session.Barcode);

            case "[File format]":
                return(GetType(fileName));

            case "[Original Filename]":
                return(Path.GetFileNameWithoutExtension(fileName));

            case "[Camera Order]":
                return(property.SortOrder.ToString("D3"));

            case "[Camera Name]":
                return(property.DeviceName.Replace(":", "_").Replace("?", "_").Replace("*", "_"));

            case "[Selected Tag1]":
                return(session.SelectedTag1 != null?session.SelectedTag1.Value.Trim() : "");

            case "[Selected Tag2]":
                return(session.SelectedTag2 != null?session.SelectedTag2.Value.Trim() : "");

            case "[Selected Tag3]":
                return(session.SelectedTag3 != null?session.SelectedTag3.Value.Trim() : "");

            case "[Selected Tag4]":
                return(session.SelectedTag4 != null?session.SelectedTag4.Value.Trim() : "");

            case "[Unix Time]":
                var date          = new DateTime(1970, 1, 1, 0, 0, 0, DateTime.Now.Kind);
                var unixTimestamp = System.Convert.ToInt64((DateTime.Now - date).TotalSeconds);
                return(unixTimestamp.ToString());

            case "[DB Row 1]":
                return((session.ExternalData != null && session.ExternalData.Row1 != null)
                        ? session.ExternalData.Row1
                        : "");

            case "[DB Row 2]":
                return((session.ExternalData != null && session.ExternalData.Row2 != null)
                        ? session.ExternalData.Row2
                        : "");

            case "[DB Row 3]":
                return((session.ExternalData != null && session.ExternalData.Row3 != null)
                        ? session.ExternalData.Row3
                        : "");

            case "[DB Row 4]":
                return((session.ExternalData != null && session.ExternalData.Row4 != null)
                        ? session.ExternalData.Row4
                        : "");

            case "[DB Row 5]":
                return((session.ExternalData != null && session.ExternalData.Row5 != null)
                        ? session.ExternalData.Row5
                        : "");

            case "[DB Row 6]":
                return((session.ExternalData != null && session.ExternalData.Row6 != null)
                        ? session.ExternalData.Row6
                        : "");

            case "[DB Row 7]":
                return((session.ExternalData != null && session.ExternalData.Row7 != null)
                        ? session.ExternalData.Row7
                        : "");

            case "[DB Row 8]":
                return((session.ExternalData != null && session.ExternalData.Row8 != null)
                        ? session.ExternalData.Row8
                        : "");

            case "[DB Row 9]":
                return((session.ExternalData != null && session.ExternalData.Row9 != null)
                        ? session.ExternalData.Row9
                        : "");
            }
            return("");
        }
Esempio n. 17
0
 public LiveViewViewModel()
 {
     CameraProperty = new CameraProperty();
     CameraDevice = new NotConnectedCameraDevice();
     InitCommands();
     PreviewBitmapVisible = true;
 }