Beispiel #1
0
        public string[] FindSynonyms(uint priceItemId)
        {
            long taskId = 0;

            try {
                log.Debug(String.Format("Попытка запуска поиска синонимов для, priceItemId = {0}", priceItemId));
                var item = PriceProcessItem.GetProcessItem(priceItemId);
                if (item == null)
                {
                    string er = String.Format("Файл прайс-листа не найден (priceItemId = {0})", priceItemId);
                    throw new FaultException <string>(er, new FaultReason(er));
                }
                var names = item.GetAllNames();
                if (names == null)
                {
                    string er = String.Format("Прайс-лист не формализован (priceItemId = {0})", priceItemId);
                    throw new FaultException <string>(er, new FaultReason(er));
                }
                if (names.Count == 0)
                {
                    string er = String.Format("Не найдено ни одной позиции в прайс-листе (priceItemId = {0})", priceItemId);
                    throw new FaultException <string>(er, new FaultReason(er));
                }
                // создаем задачу
                var handler = (IndexerHandler)Monitor.GetInstance().GetHandler(typeof(IndexerHandler));
                taskId = handler.AddTask(names, (uint)item.PriceCode);
            }
            catch (Exception e) {
                log.Warn("Ошибка в функции FindSynonyms:", e);
                throw;
            }
            return(new[] { "Success", taskId.ToString() });            // задача успешно создана
        }
Beispiel #2
0
        public static PriceProcessItem TryToLoadPriceProcessItem(string filename)
        {
            if (String.IsNullOrEmpty(filename))
            {
                return(null);
            }

            uint priceItemId  = ParseId(filename);
            var  isDownloaded = IsDownloadedPrice(filename);

            if (priceItemId == 0)
            {
                return(null);
            }

            var drPriceItem = MySqlHelper.ExecuteDataRow(
                ConnectionHelper.GetConnectionString(),
                @"select distinct
  pc.PriceCode as PriceCode,
  if(pd.CostType = 1, pc.CostCode, null) CostCode,
  pc.PriceItemId,
  pd.ParentSynonym,
  pi.LastDownload
from (usersettings.pricescosts pc, usersettings.pricesdata pd)
	join usersettings.priceitems pi on pc.PriceItemId = pi.Id
where pc.PriceItemId = ?PriceItemId
	  and ((pd.CostType = 1) or (exists(select * from userSettings.pricesregionaldata prd where prd.PriceCode = pd.PriceCode and prd.BaseCost=pc.CostCode)))
	  and pd.PriceCode = pc.PriceCode
group by pi.Id",
                new MySqlParameter("?PriceItemId", priceItemId));

            if (drPriceItem == null)
            {
                return(null);
            }

            var priceCode     = Convert.ToUInt64(drPriceItem["PriceCode"]);
            var costCode      = (drPriceItem["CostCode"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drPriceItem["CostCode"]);
            var parentSynonym = (drPriceItem["ParentSynonym"] is DBNull) ? null : (ulong?)Convert.ToUInt64(drPriceItem["ParentSynonym"]);
            var lastDownload  = (drPriceItem["LastDownload"] is DBNull) ? DateTime.MinValue : Convert.ToDateTime(drPriceItem["LastDownload"]);
            var item          = new PriceProcessItem(isDownloaded, priceCode, costCode, priceItemId, filename, parentSynonym);

            if (isDownloaded)
            {
                item.FileTime = lastDownload;
            }

            return(item);
        }
 //Возвращает true, если был добавлен в очередь, если false, значит есть скаченный, то добавлять не надо
 public static bool AddItem(PriceProcessItem item)
 {
     lock (list) {
         //Если элемент только что скачан, то добавляем его в список
         if (item.Downloaded)
         {
             list.Add(item);
             return(true);
         }
         //Если файл перепровели, то проверяем на существование скаченного
         if (DownloadedExists(item.PriceItemId))
         {
             return(false);
         }
         list.Add(item);
         return(true);
     }
 }
Beispiel #4
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);
                }
            }
        }