Esempio n. 1
0
 /*
  * Insert the previously given values into the db table.
  * A warning will be printed and no data added if the given data doesn't
  * fit the db file's structure.
  */
 public override void Execute()
 {
     // insert always into packed files at the save to file
     foreach (PackedFile packed in PackedFiles)
     {
         // we'll read from packed, but that is in the source pack;
         // get or create the db file in the target pack
         DBFile targetFile = GetTargetFile(packed);
         foreach (RowValues insertValues in Source.Values)
         {
             if (targetFile.CurrentType.Fields.Count == insertValues.Count)
             {
                 DBRow newRow = targetFile.GetNewEntry();
                 for (int i = 0; i < newRow.Count; i++)
                 {
                     newRow[i].Value = insertValues[i];
                 }
                 targetFile.Entries.Add(newRow);
             }
             else
             {
                 Console.WriteLine("Cannot insert: was given {0} values, expecting {1} in {2}",
                                   insertValues.Count, targetFile.CurrentType.Fields.Count, packed.FullPath);
                 Console.WriteLine("Values: {0}", string.Join(",", insertValues));
             }
         }
         // encode and store in target pack
         PackedFile newPacked = new PackedFile(packed.FullPath, false);
         newPacked.Data = PackedFileDbCodec.GetCodec(newPacked).Encode(targetFile);
         SaveTo.Add(newPacked, true);
     }
 }
Esempio n. 2
0
        public void StreamToAxapta(Stream stream, SaveTo saveTo, string fileName)
        {
            using (var streamWriter = new StreamWriter(stream))
            {
                streamWriter.Flush();

                var ftpManager = GetFtpManager(saveTo);
                ftpManager.Upload(stream.Reset(), fileName);
            }
        }
 public override void Execute()
 {
     if (SaveTo != null)
     {
         foreach (PackedFile packed in PackedFiles)
         {
             SaveTo.Add(packed, true);
         }
     }
 }
Esempio n. 4
0
        private void SetArchiveDirectoryPath(SaveTo saveTo)
        {
            var directory = GetDirectory(saveTo);

            _directoryPathName = Path.Combine(_archiveDirectoryPath, String.Format("{0:yyyy-MM}", DateTime.Now), directory, String.Format("{0:dd}", DateTime.Now));

            if (!Directory.Exists(_directoryPathName))
            {
                Directory.CreateDirectory(_directoryPathName);
            }
        }
Esempio n. 5
0
        private FtpManager GetFtpManager(SaveTo saveTo)
        {
            var ftpSetting = new FtpSetting
            {
                FtpAddress  = _vendorSettingRepo.GetVendorSetting(SapphVendorID, FtpAddressSettingKey),
                FtpUsername = _vendorSettingRepo.GetVendorSetting(SapphVendorID, FtpUsernameSettingKey),
                FtpPassword = _vendorSettingRepo.GetVendorSetting(SapphVendorID, FtpPasswordSettingKey),
                Path        = GetDirectory(saveTo)
            };

            var ftpManager = new FtpManager(ftpSetting.FtpUri, null, false, true);

            return(ftpManager);
        }
Esempio n. 6
0
        private void LoadOptions()
        {
            RegistryKey userKey    = null;
            RegistryKey machineKey = null;
            RegistryKey key;

            if (String.IsNullOrEmpty(RegistryKeyToStoreOptions))
            {
                return;
            }

            try
            {
                userKey    = Registry.CurrentUser.OpenSubKey("Software\\" + RegistryKeyToStoreOptions);
                machineKey = Registry.LocalMachine.OpenSubKey("Software\\" + RegistryKeyToStoreOptions);
            }
            catch             //(System.Exception e)
            {
            }

            if (userKey == null && machineKey == null)
            {
                return;
            }

            if (userKey != null)
            {
                key = userKey;
            }
            else
            {
                key = machineKey;
            }

            try
            {
                _defaultDevice      = (String)key.GetValue("Default Device", "");
                _saveTo             = (SaveTo)Enum.Parse(typeof(SaveTo), (String)key.GetValue("Save To", SaveTo.File));
                _outputFolder       = (String)key.GetValue("Output Folder", SaveTo.File);
                _fileNamingTemplate = (String)key.GetValue("File Naming Template", "Image_{0:D2}");
                _outputFormat       = (OutputFormat)Enum.Parse(typeof(OutputFormat), (String)key.GetValue("Output Format", OutputFormat.JPEG));
                _jpegQuality        = (int)key.GetValue("JPEG Quality", 95);
                _tiffCompression    = (TiffCompression)Enum.Parse(typeof(TiffCompression), (String)key.GetValue("TIFF Compression", TiffCompression.LZW));
            }
            catch (Exception e)
            {
                throw new ScanException("Failed to get options.", e);
            }
        }
Esempio n. 7
0
        public void ExportToArchive <T>(IEnumerable <T> listOfDatCol, SaveTo saveTo, string fileName)
        {
            SetArchiveDirectoryPath(saveTo);

            var filePathName = Path.Combine(_directoryPathName, fileName);

            if (!File.Exists(filePathName))
            {
                File.Create(filePathName).Dispose();
            }

            var engine = new FileHelperEngine(typeof(T));

            engine.WriteFile(filePathName, listOfDatCol);
        }
Esempio n. 8
0
        private void cameraBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            ICameraInfo cameraInfo = CameraInfo;

            if (cameraInfo != null)
            {
                SetControlsEnabled(true);

                UIHelper.FillComboBoxWith(isoComboBox, cameraInfo.AvailableIsoSpeeds, cameraInfo.CurrentIsoSpeed);
                UIHelper.FillComboBoxWith(apertureComboBox, cameraInfo.AvailableApertures, cameraInfo.CurrentAperture);
                UIHelper.FillComboBoxWith(exposalComboBox, cameraInfo.AvailableExposals, cameraInfo.CurrentExposal);
                UIHelper.FillComboBoxWith(saveToComboBox, SaveTo.SaveToValues, SaveTo.With(SaveToEnum.Save_by_downloading_to_a_host_computer));
                UIHelper.FillComboBoxWith(imageQualityComboBox, cameraInfo.AvailableImageQualities, cameraInfo.CurrentImageQuality);
            }
            else
            {
                SetControlsEnabled(false);
            }
        }
Esempio n. 9
0
 private void Export_Click(object sender, EventArgs e)
 {
     if (Icons.SelectedItems.Count > 0 && SaveTo.ShowDialog() == DialogResult.OK)
     {   // Collect all checked items from the Export menu and parse into an array of width x length sizes.
         var sizes = Array.ConvertAll(Choices(ExportAs.DropDownItems),
                                      item => Parse(item.Text.Replace("&", string.Empty).ToLowerInvariant().Trim()));
         foreach (ListViewItem selection in Icons.SelectedItems)
         {
             SingleIcon icon = (new MultiIcon()).Add(selection.Text);
             foreach (var size in sizes)
             {
                 icon.Add(imageMso[selection.Text, size[0], size[1]]);
             }
             icon.Save(Path.Combine(SaveTo.SelectedPath, string.Format("{0}.{1}", selection.Text, "ico")));
             DestroyIcon(icon.Icon.Handle);
         }
         MessageBox.Show("Export Complete.", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 10
0
        public ParserBase(ILogger logger, SaveTo saveTo)
        {
            this.logger = logger;
            this.saveTo = saveTo;

            var region = typeof(TLicense).ToString().GetStrByRegexGroup(@".(\w+)License$");

            var folderPath = ConfigurationManager.AppSettings.Get("ResultsFolderPath");

            if (string.IsNullOrEmpty(folderPath))
            {
                throw new ConfigurationErrorsException($"В файле конфигурации не задан параметр ResultsFolderPath (Путь к папке для сохранения результата)");
            }

            if (folderPath.Intersect(Path.GetInvalidFileNameChars()).Any())
            {
                throw new ConfigurationErrorsException($"В файле конфигурации параметр ResultsFolderPath содержит недопустимые символы");
            }

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            filePath = $"{folderPath}/{region}.json";

            var targetUriString = ConfigurationManager.AppSettings.Get($"{region}TargetUrl");

            if (string.IsNullOrEmpty(targetUriString))
            {
                throw new ConfigurationErrorsException($"В файле конфигурации не задан параметр {region}TargetUrl (нужна ссылка на ресурс для парсинга)");
            }

            if (Uri.TryCreate(targetUriString, UriKind.Absolute, out var url) == false)
            {
                throw new ConfigurationErrorsException($"В конфиге прописан некорретный url (параметр {region}TargetUrl)");
            }
            basicUrl = url;

            InitStorage();
        }
Esempio n. 11
0
        public void ExportToAxapta <T>(IEnumerable <T> listOfDatCol, SaveTo saveTo, string fileName)
        {
            var ofDatCol = listOfDatCol as IList <T> ?? listOfDatCol.ToList();

            if (!ofDatCol.Any())
            {
                return;
            }

            using (Stream memoryStream = new MemoryStream())
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    var engine = new FileHelperEngine(typeof(T));
                    engine.WriteStream(streamWriter, ofDatCol.ToList());

                    streamWriter.Flush();

                    var ftpManager = GetFtpManager(saveTo);
                    ftpManager.Upload(memoryStream.Reset(), fileName);
                }
        }
Esempio n. 12
0
 private void Save_Click(object sender, EventArgs e)
 {
     if (Icons.SelectedItems.Count > 0 && SaveTo.ShowDialog() == DialogResult.OK)
     {   // Collect all checked items from the Save menu and parse into an array of image formats.
         var formats = Array.ConvertAll(Choices(SaveAs.DropDownItems), item => Format(item.Name));
         var size    = Parse(Pixels.Text.ToLowerInvariant().Trim());
         foreach (ListViewItem selection in Icons.SelectedItems)
         {
             using (var image = imageMso[selection.Text, size[0], size[1]])
                 using (var canvas = new Bitmap(size[0], size[1]))
                     using (var drawing = Graphics.FromImage(canvas))
                     { // Image is drawn on a colored opaque canvas for formats that do not support transparency.
                         drawing.Clear(Palette.Color);
                         drawing.DrawImage(image, 0, 0);
                         foreach (ImageFormat format in formats)
                         {
                             string filename = Path.Combine(SaveTo.SelectedPath,
                                                            string.Format("{0}.{1}", selection.Text, Extension(format)));
                             if (format == ImageFormat.Icon)
                             { // image.Save(filename, format); // Loses color depth. Use IconLib instead.
                                 SingleIcon icon = (new MultiIcon()).Add(selection.Text);
                                 icon.Add(image);
                                 icon.Save(filename);
                                 DestroyIcon(icon.Icon.Handle);
                             }
                             else if (format == ImageFormat.Bmp || format == ImageFormat.Gif || format == ImageFormat.Jpeg)
                             {
                                 canvas.Save(filename, format); // These formats do not support alpha channel transparency.
                             }
                             else
                             {
                                 image.Save(filename, format);
                             }
                         }
                     }
         }
         MessageBox.Show("Save Complete.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 13
0
        public void CopyToArchive(string ftpUri, SaveTo saveTo, string fileNameToCopy)
        {
            SetArchiveDirectoryPath(saveTo);

            var ftpManager = new FtpManager(ftpUri, null, false, true);

            foreach (var file in ftpManager.GetFiles())
            {
                var fileName = Path.GetFileName(file);

                if (fileName != null && !fileName.Equals(Path.GetFileName(fileNameToCopy)))
                {
                    continue;
                }
                try
                {
                    using (var stream = ftpManager.Download(fileName))
                    {
                        var filePath = Path.Combine(_directoryPathName, fileNameToCopy);

                        try
                        {
                            SaveStreamToFile(filePath, stream);
                        }
                        catch (IOException exception)
                        {
                            throw new Exception(exception.Message);
                        }
                    }
                    return;
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Could not process file {0}! Error: {1}", file, e.Message));
                }
            }
        }
Esempio n. 14
0
 /*
  * Delete all entries matching the where clause if any was given,
  * or all entries if none was given.
  */
 public override void Execute()
 {
     if (SaveTo == null)
     {
         return;
     }
     foreach (PackedFile packed in PackedFiles)
     {
         PackedFile   result = new PackedFile(packed.FullPath, false);
         DBFile       dbFile = PackedFileDbCodec.Decode(packed);
         List <DBRow> kept   = new List <DBRow>();
         foreach (DBRow field in dbFile.Entries)
         {
             if (whereClause != null && !whereClause.Accept(field))
             {
                 kept.Add(field);
             }
         }
         DBFile newDbFile = new DBFile(dbFile.Header, dbFile.CurrentType);
         newDbFile.Entries.AddRange(kept);
         result.Data = PackedFileDbCodec.GetCodec(packed).Encode(newDbFile);
         SaveTo.Add(result, true);
     }
 }
        private void UploadNotification <T>(ICollection <T> listOfNotifications, string orderNumber, SaveTo saveTo)
        {
            if (!listOfNotifications.Any())
            {
                return;
            }

            _orderNumber = orderNumber;
            var fileName = NotificationFileName;

            _archiveService.ExportToAxapta(listOfNotifications, saveTo, fileName);
            _archiveService.ExportToArchive(listOfNotifications, saveTo, fileName);
        }
        private void LoadOptions()
        {
            RegistryKey userKey = null;
            RegistryKey machineKey = null;
            RegistryKey key;

            if (String.IsNullOrEmpty(RegistryKeyToStoreOptions))
            {
                return;
            }

            try
            {
                userKey = Registry.CurrentUser.OpenSubKey("Software\\" + RegistryKeyToStoreOptions);
                machineKey = Registry.LocalMachine.OpenSubKey("Software\\" + RegistryKeyToStoreOptions);
            }
            catch //(System.Exception e)
            {
            }

            if (userKey == null && machineKey == null)
            {
                return;
            }

            if (userKey != null)
            {
                key = userKey;
            }
            else
            {
                key = machineKey;
            }

            try
            {
                _defaultDevice = (String) key.GetValue("Default Device", "");
                _saveTo = (SaveTo) Enum.Parse(typeof(SaveTo), (String) key.GetValue("Save To", SaveTo.File));
                _outputFolder = (String) key.GetValue("Output Folder", SaveTo.File);
                _fileNamingTemplate = (String) key.GetValue("File Naming Template", "Image_{0:D2}");
                _outputFormat = (OutputFormat) Enum.Parse(typeof(OutputFormat), (String) key.GetValue("Output Format", OutputFormat.JPEG));
                _jpegQuality = (int) key.GetValue("JPEG Quality", 95);
                _tiffCompression = (TiffCompression) Enum.Parse(typeof(TiffCompression), (String) key.GetValue("TIFF Compression", TiffCompression.LZW));
            }
            catch (Exception e)
            {
                throw new ScanException("Failed to get options.", e);
            }
        }
Esempio n. 17
0
 public VolgogradParser(ILogger logger, SaveTo saveTo) : base(logger, saveTo)
 {
 }
Esempio n. 18
0
 private string NextOutputFileName()
 {
     OutputNumber++;
     return(SaveTo.Remove(SaveTo.LastIndexOf('.')) + '_' + OutputNumber.ToString().PadLeft(3, '0') + Path.GetExtension(SaveTo));
 }
Esempio n. 19
0
 public VoronezhParser(ILogger logger, SaveTo saveTo) : base(logger, saveTo)
 {
 }
Esempio n. 20
0
        private string GetDirectory(SaveTo saveTo)
        {
            string directory;

            switch (saveTo)
            {
            case SaveTo.StockDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, StockDirectorySettingKey);
                break;

            case SaveTo.CorrectionStockDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorrectionStockDirectorySettingKey);
                break;

            case SaveTo.CorruptStockDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorruptStockDirectorySettingKey);
                break;

            case SaveTo.CorruptCorrectionStockDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorruptCorrectionStockDirectorySettingKey);
                break;

            case SaveTo.PurchaseOrderDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, PurchaseOrderDirectorySettingKey);
                break;

            case SaveTo.ReceivedPurchaseOrderConfirmationDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, PurchaseOrderReceivedConfirmationDirectorySettingKey);
                break;

            case SaveTo.CorruptPurchaseOrderDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorruptPurchaseOrderDirectorySettingKey);
                break;

            case SaveTo.PickTicketDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, PickTicketDirectorySettingKey);
                break;

            case SaveTo.PickingPickTicketShipmentConfirmationDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, PickingShipmentConfirmationDirectorySettingKey);
                break;

            case SaveTo.TransferPickTicketShipmentConfirmationDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, TransferShipmentConfirmationDirectorySettingKey);
                break;

            case SaveTo.CorruptPickTicketDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorruptPickTicketDirectorySettingKey);
                break;

            case SaveTo.CorruptNotificationDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorruptNotificationDirectorySettingKey);
                break;

            case SaveTo.CustomerInformationDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CustomerInformationDirectorySettingKey);
                break;

            case SaveTo.CorruptCustomerInformationDirectory:
                directory = _vendorSettingRepo.GetVendorSetting(SapphVendorID, CorruptCustomerInformationDirectorySettingKey);
                break;

            default:
                throw new NotImplementedException();
            }

#if DEBUG
            return(directory.Replace("Staging", "Test"));
#else
            return(directory);
#endif
        }