Exemple #1
0
        public void CopyToInbound(string extrFileName, MySqlConnection connection, MySqlTransaction transaction)
        {
            var command = new MySqlCommand(@"
update usersettings.PriceItems
set LastDownload = ?FileTime, LocalLastDownload=?LocalLastDownload
where Id = ?Id",
                                           connection, transaction);

            command.Parameters.AddWithValue("?Id", PriceItemId);
            command.Parameters.AddWithValue("?FileTime", FileTime);
            command.Parameters.AddWithValue("?LocalLastDownload", LocalLastDownload);
            command.ExecuteNonQuery();

            var ignore = Convert.ToBoolean(MySqlHelper.ExecuteScalar(connection, @"
select SilentSkipProcessing from Usersettings.PricesData pd
join Usersettings.PricesCosts pc on pc.PriceCode = pd.PriceCode
where pc.PriceItemId = ?priceItemId", new MySqlParameter("priceItemId", PriceItemId)));

            if (ignore)
            {
                log.WarnFormat("Обработка прайса отключена, игнорирую файл {0}", FilePath);
                return;
            }

            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }
            File.Copy(extrFileName, FilePath);
            PriceItemList.AddItem(this);
        }
Exemple #2
0
        public void ResendPrice(WcfCallParameter paramDownlogId)
        {
            var downlogId = Convert.ToUInt64(paramDownlogId.Value);
            var drFocused = MySqlHelper.ExecuteDataRow(ConnectionHelper.GetConnectionString(),
                                                       @"
SELECT distinct
  logs.RowID as DRowID,
  logs.LogTime as DLogTime,
  logs.Addition as DAddition,
  logs.ArchFileName as DArchFileName,
  logs.ExtrFileName as DExtrFileName,
  sp.Name as DFirmName,
  r.Region as DRegion,
  if(pd.CostType = 1, concat('[Колонка] ', pc.CostName), pd.PriceName) as DPriceName,
  pim.Id as DPriceItemId,
  pd.PriceCode as DPriceCode,
  pd.ParentSynonym,
  if(pd.CostType = 1, pc.CostCode, null) DCostCode,
  st.Type as DSourceType,
  s.PricePath as DPricePath,
  s.EmailTo as DEmailTo,
  s.EmailFrom as DEmailFrom,
  s.ArchivePassword,
  pricefmts.FileExtention as DFileExtention
FROM
  logs.downlogs as logs,
  Customers.Suppliers sp,
  usersettings.pricesdata pd,
  usersettings.pricescosts pc,
  usersettings.PriceItems pim,
  farm.regions r,
  farm.sources s,
  farm.Sourcetypes st,
  farm.formrules fr,
  farm.pricefmts
WHERE
	pim.Id = logs.PriceItemId
and pc.PriceItemId = pim.Id
and pc.PriceCode = pd.PriceCode
and ((pd.CostType = 1) OR (exists(select * from userSettings.pricesregionaldata prd where prd.PriceCode = pd.PriceCode and prd.BaseCost=pc.CostCode)))
and sp.Id = pd.firmcode
and r.regioncode = sp.HomeRegion
and s.Id = pim.SourceId
and st.Id = s.SourceTypeId
and logs.ResultCode in (2, 3)
and fr.Id = pim.FormRuleId
and pricefmts.id = fr.PriceFormatId
and logs.Rowid = ?DownLogId",
                                                       new MySqlParameter("?DownLogId", downlogId));

            var filename = GetFileFromArhive(downlogId);
            var sourceArchiveFileName = filename;
            var archFileName          = drFocused["DArchFileName"].ToString();
            var externalFileName      = drFocused["DExtrFileName"].ToString();
            var extractedFile         = string.Empty;

            try {
                if (drFocused["DSourceType"].ToString().Equals("EMAIL", StringComparison.OrdinalIgnoreCase))
                {
                    // Если файл пришел по e-mail, то это должен быть файл *.eml, открываем его на чтение
                    filename      = ExtractFileFromAttachment(filename, archFileName, externalFileName);
                    extractedFile = filename;
                }
                var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(archFileName));
                if (ArchiveHelper.IsArchive(filename))
                {
                    if (File.Exists(tempDirectory))
                    {
                        File.Delete(tempDirectory);
                    }
                    if (Directory.Exists(tempDirectory))
                    {
                        Directory.Delete(tempDirectory, true);
                    }
                    Directory.CreateDirectory(tempDirectory);
                    ArchiveHelper.Extract(filename, externalFileName, tempDirectory, drFocused["ArchivePassword"].ToString());
                    filename = FileHelper.FindFromArhive(tempDirectory, externalFileName);
                    if (String.IsNullOrEmpty(filename))
                    {
                        var errorMessage = String.Format(
                            "Невозможно найти файл {0} в распакованном архиве!", externalFileName);
                        throw new FaultException <string>(errorMessage, new FaultReason(errorMessage));
                    }
                }

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

                var priceExtention  = drFocused["DFileExtention"].ToString();
                var destinationFile = Path.Combine(Settings.Default.InboundPath,
                                                   "d" + drFocused["DPriceItemId"] + "_" + downlogId + priceExtention);

                if (File.Exists(destinationFile))
                {
                    throw new FaultException <string>(MessagePriceInQueue,
                                                      new FaultReason(MessagePriceInQueue));
                }

                File.Copy(filename, destinationFile);

                var item = new PriceProcessItem(true,
                                                Convert.ToUInt64(drFocused["DPriceCode"].ToString()),
                                                (drFocused["DCostCode"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drFocused["DCostCode"].ToString()),
                                                Convert.ToUInt64(drFocused["DPriceItemId"].ToString()),
                                                destinationFile,
                                                (drFocused["ParentSynonym"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drFocused["ParentSynonym"].ToString()));
                PriceItemList.AddItem(item);

                var priceItemId = Convert.ToUInt64(drFocused["DPriceItemId"]);
                downlogId = LogResendPriceAsDownload(priceItemId, archFileName, externalFileName, paramDownlogId.LogInformation);
                if (downlogId > 0)
                {
                    destinationFile = Path.Combine(Settings.Default.HistoryPath,
                                                   downlogId + Path.GetExtension(sourceArchiveFileName));
                    File.Copy(sourceArchiveFileName, destinationFile);
                }
                if (Directory.Exists(tempDirectory))
                {
                    FileHelper.Safe(() => Directory.Delete(tempDirectory, true));
                }
            }
            finally {
                if (File.Exists(extractedFile))
                {
                    File.Delete(extractedFile);
                }
            }
        }