/// <summary> /// ОБработка МКИЭТЗ /// </summary> /// <param name="localContext"></param> /// <param name="markgr"></param> /// <param name="request"></param> /// <param name="statusCode"></param> /// <param name="protectionDocIcfems"></param> private void ProcessIcfem(NiisWebContext localContext, MARKGR markgr, Request request, string statusCode, IList <DicIcfemProtectionDocRelation> protectionDocIcfems) { foreach (var v in markgr.CURRENT.VIENNAGR.VIECLA3) { var icefIcfem = localContext.DicICFEMs.FirstOrDefault(cf => cf.Code.Replace(".", "").Trim() == v.Trim()); if (icefIcfem != null) { if (localContext.DicIcfemRequestRelations.All(icf => icf.DicIcfemId != icefIcfem.Id && icf.RequestId != request.Id)) { LogMsg(null, icefIcfem.NameRu, "МКИЭТЗ"); request.Icfems.Add(new DicIcfemRequestRelation { DicIcfemId = icefIcfem.Id, DicIcfem = icefIcfem }); if (statusCode == "D.TZ") { protectionDocIcfems.Add(new DicIcfemProtectionDocRelation { DicIcfemId = icefIcfem.Id, DicIcfem = icefIcfem }); } } } } }
/// <summary> /// (511) МКТУ- Описание отказа по классу /// </summary> /// <param name="localContext"></param> /// <param name="markgr"></param> /// <param name="request"></param> /// <param name="statusCode"></param> /// <param name="protectionDocIcgs"></param> private void ProcessIcgsRefuse(NiisWebContext localContext, MARKGR markgr, Request request, string statusCode, IList <ICGSProtectionDoc> protectionDocIcgs) { foreach (var lin in markgr.LIN.Where(l => l.DCPCD.Contains(KZ))) { foreach (var limto in lin.LIMTO) { var icgs = localContext.DicICGSs.FirstOrDefault(di => di.NameEn.Contains(limto.NICCLAI.Trim())); if (icgs != null) { var gsterStr = new[] { limto.GSTERMEN, limto.GSTERMES, limto.GSTERMFR }.FirstOrDefault(str => !string.IsNullOrEmpty(str)) ?? string.Empty; var icgsObj = localContext.ICGSRequests.FirstOrDefault(icf => icf.IcgsId != icgs.Id && icf.RequestId != request.Id); if (icgsObj == null) { var ir = new ICGSRequest { IcgsId = icgs.Id, Icgs = icgs, IsRefused = true }; LogMsg(ir.Description, gsterStr, "(511) МКТУ- Описание отказа по классу"); ir.ClaimedDescription = ir.Description = gsterStr; request.ICGSRequests.Add(ir); } else { LogMsg(icgsObj.Description, gsterStr, "(511) МКТУ- Описание отказа по классу"); icgsObj.Description = icgsObj.ClaimedDescription = gsterStr; } if (statusCode == "D.TZ") { protectionDocIcgs.Add(new ICGSProtectionDoc { DateCreate = DateTimeOffset.Now, ClaimedDescription = gsterStr, Description = gsterStr, IsNegative = false }); } } } } }
/// <summary> /// Обработка изображения /// </summary> /// <param name="localContext"></param> /// <param name="markgr"></param> /// <param name="request"></param> private void ProcessImage(NiisWebContext localContext, MARKGR markgr, Request request) { var fileNameFromXml = (markgr.CURRENT.IMAGE.NAME + "." + markgr.CURRENT.IMAGE.TYPE).ToLower().Trim(); var imageZip = _zipArchive.Entries.FirstOrDefault(ent => ent.Name.ToLower().Contains(fileNameFromXml) || ent.Name.ToLower().Contains(markgr.CURRENT.IMAGE.NAME.ToLower().Trim()) || fileNameFromXml.Contains(ent.Name.ToLower())); if (imageZip != null) { var ms = new MemoryStream(); for (var i = 0; i < 3; i++) { try { var imgStream = imageZip.Open(); imgStream.CopyTo(ms); LogMsg(null, fileNameFromXml, $"Изображение. Заявка {request.RequestNum}"); request.Image = ms.ToArray(); break; } catch (Exception e) { Log.Logger.Error(e, $"Изображение. Заявка {request.RequestNum}"); Thread.Sleep(1000); } } } else { if (!string.IsNullOrEmpty(request.NameEn) || !string.IsNullOrEmpty(request.NameRu) || !string.IsNullOrEmpty(request.NameKz)) { var lu = new LogoUpdater(); request.IsImageFromName = true; lu.Update(request); var logoText = string.Join(Environment.NewLine, request.NameRu, request.NameKz, request.NameEn); LogMsg(null, logoText, $"Изображение. Сформировано из названия. Заявка {request.RequestNum}"); } } }
/// <summary> /// МКТУ /// </summary> /// <param name="localContext"></param> /// <param name="markgr"></param> /// <param name="request"></param> /// <param name="statusCode"></param> /// <param name="protectionDocIcgs"></param> private void ProcessIcgs(NiisWebContext localContext, MARKGR markgr, Request request, string statusCode, IList <ICGSProtectionDoc> protectionDocIcgs) { foreach (var gsgr in markgr.CURRENT.BASICGS.GSGRs) { var icgs = localContext.DicICGSs.FirstOrDefault(di => di.NameEn.Contains(gsgr.NICCLAI.Trim())); if (icgs != null) { var gstrStr = new[] { gsgr.GSTERMEN, gsgr.GSTERMES, gsgr.GSTERMFR }.FirstOrDefault(str => !string.IsNullOrEmpty(str)) ?? string.Empty; var icgsObj = localContext.ICGSRequests.FirstOrDefault(icf => icf.IcgsId == icgs.Id && icf.RequestId == request.Id); if (icgsObj == null) { var ir = new ICGSRequest { IcgsId = icgs.Id, Icgs = icgs }; LogMsg(ir.Description, gstrStr, "МКТУ"); ir.ClaimedDescription = ir.Description = gstrStr; request.ICGSRequests.Add(ir); } else { LogMsg(icgsObj.Description, gstrStr, "МКТУ"); icgsObj.ClaimedDescription = icgsObj.Description = gstrStr; } if (statusCode == "D.TZ") { protectionDocIcgs.Add(new ICGSProtectionDoc { DateCreate = DateTimeOffset.Now, ClaimedDescription = gstrStr, Description = gstrStr }); } } } }
/// <summary> /// Обработка Патентообладателя /// </summary> /// <param name="localContext"></param> /// <param name="markgr"></param> /// <param name="request"></param> private void ProcessPatentHolder(NiisWebContext localContext, MARKGR markgr, Request request) { if (!localContext.RequestCustomers.Any(rc => rc.RequestId == request.Id && rc.Customer.Xin == markgr.CURRENT.HOLGR.CLID.Trim())) { // адрес var sb = new StringBuilder(); foreach (var addrl in markgr.CURRENT.HOLGR.ADDRESS.ADDRL) { sb.Append(addrl); sb.Append(" "); } var address = sb.ToString().Trim(); // название sb = new StringBuilder(); foreach (var nl in markgr.CURRENT.HOLGR.NAME.NAMEL) { sb.Append(nl.Trim()); sb.Append(" "); } var namel = sb.ToString().Trim(); var patentHolderRole = localContext.DicCustomerRoles.FirstOrDefault(dcr => dcr.NameRu == "Патентообладатель"); // не определено var patentHolderType = localContext.DicCustomerTypes.FirstOrDefault(dct => dct.Code == "4"); var patentHolder = localContext.DicCustomers.FirstOrDefault(dc => dc.Xin == markgr.CURRENT.HOLGR.CLID.Trim()) ?? new DicCustomer { DateCreate = DateTimeOffset.Now }; // страна var country = localContext.DicCountries .FirstOrDefault( dc => dc.Code.ToLower() == markgr.CURRENT.HOLGR.ADDRESS.COUNTRY.ToLower().Trim()); if (patentHolder.Id == 0) { LogMsg(patentHolder.Xin, markgr.CURRENT.HOLGR.CLID.Trim(), "Патентообладатель"); patentHolder.Xin = markgr.CURRENT.HOLGR.CLID.Trim(); } LogMsg(patentHolder.Address, address, "Патентообладатель. Адрес"); patentHolder.Address = address; LogMsg(patentHolder.NameEn, namel, "Патентообладатель. Название"); patentHolder.NameEnLong = namel; patentHolder.NameEn = namel; patentHolder.NameRuLong = namel; patentHolder.NameRu = namel; LogMsg(patentHolder.Country?.NameEn, country?.NameEn, "Патентообладатель. Страна"); patentHolder.CountryId = country?.Id; patentHolder.Country = country; patentHolder.Type = patentHolderType; localContext.RequestCustomers.Add(new RequestCustomer { Request = request, Customer = patentHolder, CustomerRole = patentHolderRole, DateCreate = DateTimeOffset.Now }); } }
/// <summary> /// Обработка информации о МТЗ /// </summary> /// <param name="markgr">Данные из xml</param> /// <param name="loopState"></param> /// <param name="localContext">Конекст БД</param> /// <returns></returns> private NiisWebContext ProcessItem(MARKGR markgr, ParallelLoopState loopState, NiisWebContext localContext) { //foreach (MARKGR markgr in romarinDto.MARKGRS) //{ // Only for KZ var isKz = markgr.EXN?.Any(e => e.DESPG != null && e.DESPG.DCPCD.Contains(KZ) || e.DESPG2 != null && e.DESPG2.DCPCD.Contains(KZ)); isKz = isKz.HasValue && isKz.Value || markgr.LIN != null && markgr.LIN.Any(l => l.DCPCD.Contains(KZ)); if (!isKz.Value) { return(localContext); } var protectionDocIcfems = new List <DicIcfemProtectionDocRelation>(); var protectionDocIcgs = new List <ICGSProtectionDoc>(); // Получить статус // Охрана var statusCode = "D.TZ"; if (markgr.RFNP.Any() || markgr.RFNT.Any() || markgr.EXN != null && markgr.EXN.Any() || markgr.ENN.Any()) { //Обработка заявки statusCode = "W"; } if (markgr.R18NT.Any()) { // Окончательный отказ statusCode = "03.10"; } // Заявка var request = localContext.Requests.FirstOrDefault(r => r.RequestNum == markgr.INTREGN.Trim()) ?? new Request { Id = 0, DateCreate = DateTimeOffset.Now, UserId = _mainExecutorId }; if (request.Id == 0) { localContext.Requests.Add(request); } else { localContext.Requests.Update(request); } //try //{ #region Convert Data // 2 (21) Регистрационный номер заявки LogMsg(request.RequestNum, markgr.INTREGN.Trim(), $"(21) Регистрационный номер заявки {markgr.INTREGN.Trim()}"); request.RequestNum = markgr.INTREGN.Trim(); // 1 (54) Название на иностранном языке LogMsg(request.NameEn, markgr.CURRENT?.IMAGE.TEXT?.Trim(), $"(54) Название на иностранном языке Заявка № {request.RequestNum}"); request.NameEn = markgr.CURRENT?.IMAGE.TEXT?.Trim(); // 3 (22) Дата подачи заявки LogMsg(request.RequestDate?.ToString(), DateFromString(markgr.INTREGD)?.ToString(), $"(22) Дата подачи заявки Заявка № {request.RequestNum}"); request.RequestDate = DateFromString(markgr.INTREGD); // 5 (891) Дата распространения на РК var exn = markgr.EXN?.FirstOrDefault(e => e.DESPG?.DCPCD != null && e.DESPG.DCPCD.Contains(KZ) || e.DESPG2?.DCPCD != null && e.DESPG2.DCPCD.Contains(KZ)); LogMsg(request.DistributionDate?.ToString(), DateFromString(markgr.INTREGD)?.ToString(), $"(891) Дата распространения на РК Заявка № {request.RequestNum}"); request.DistributionDate = DateFromString(exn?.REGEDAT); // 6 Патентообладатель if (markgr.CURRENT?.HOLGR?.ADDRESS != null) { ProcessPatentHolder(localContext, markgr, request); } if (markgr.CURRENT != null) { // 7 Изображение ProcessImage(localContext, markgr, request); // 8 Транслитерация LogMsg(request.Transliteration, markgr.CURRENT.MARTRAN?.Trim(), $"Транслитерация Заявка № {request.RequestNum}"); request.Transliteration = markgr.CURRENT.MARTRAN?.Trim(); // 9 МКИЭТЗ if (markgr.CURRENT.VIENNAGR != null) { // только детальный уровень ProcessIcfem(localContext, markgr, request, statusCode, protectionDocIcfems); } // 10 МКТУ if (markgr.CURRENT.BASICGS != null) { ProcessIcgs(localContext, markgr, request, statusCode, protectionDocIcgs); } } // 11 (511) МКТУ- Описание отказа по классу if (markgr.LIN != null && markgr.LIN.Any(l => l.DCPCD.Contains(KZ))) { ProcessIcgsRefuse(localContext, markgr, request, statusCode, protectionDocIcgs); } if (markgr.CURRENT != null) { // 12 (591) Цвета if (markgr.CURRENT.COLCLAGR != null) { var colors = new[] { markgr.CURRENT.COLCLAGR.COLCLAEN, markgr.CURRENT.COLCLAGR.COLCLAES, markgr.CURRENT.COLCLAGR.COLCLAFR }.FirstOrDefault(ls => ls != null); var colorStr = string.Empty; foreach (var color in colors) { colorStr += color.Trim() + " "; } LogMsg(request.RomarinColor, colorStr, $"(591) Цвета Заявка № {request.RequestNum}"); request.RomarinColor = colorStr; } // 13 Приоритетные данные if (markgr.CURRENT.PRIGR != null) { var country = localContext.DicCountries.FirstOrDefault(dc => dc.Code.Trim().ToLower() == markgr.CURRENT.PRIGR.PRICP.Trim().ToLower()); if (country == null) { Log.Logger.Error("Приоритетные данные. Страна не найдена: {0}. {1}", markgr.CURRENT.PRIGR.PRICP.Trim().ToLower(), $"Заявка № {request.RequestNum}"); } else { var dicEarlyType = localContext.DicEarlyRegTypes.FirstOrDefault(dr => dr.Code == "30 - 300"); var requestEarly = localContext.RequestEarlyRegs.FirstOrDefault(rer => rer.RegNumber == markgr.CURRENT.PRIGR.PRIAPPD.Trim()) ?? new RequestEarlyReg { Id = 0, DateCreate = DateTimeOffset.Now, RegNumber = markgr.CURRENT.PRIGR.PRIAPPD.Trim(), EarlyRegType = dicEarlyType }; if (requestEarly.Id == 0) { localContext.RequestEarlyRegs.Add(requestEarly); } else { localContext.RequestEarlyRegs.Update(requestEarly); } requestEarly.RegCountry = country; requestEarly.RegCountryId = country.Id; //requestEarly.PriorityDate = DateFromString(markgr.CURRENT.PRIGR?.PRIAPPD); requestEarly.Request = request; var priorityData = new[] { markgr.CURRENT.PRIGR?.TEXTEN, markgr.CURRENT.PRIGR?.TEXTES, markgr.CURRENT.PRIGR?.TEXTFR }.FirstOrDefault(txn => !string.IsNullOrEmpty(txn)); LogMsg(requestEarly.ITMRawPriorityData, priorityData, $"Приоритетные данные Заявка № {request.RequestNum}"); requestEarly.ITMRawPriorityData = priorityData; } } // 14 (526) Дискламация var disclaimerRu = new[] { markgr.CURRENT.DISCLAIMGR?.DISCLAIMEREN, markgr.CURRENT.DISCLAIMGR?.DISCLAIMERES, markgr.CURRENT.DISCLAIMGR?.DISCLAIMERFR }.FirstOrDefault(str => !string.IsNullOrEmpty(str)); LogMsg(request.DisclaimerRu, disclaimerRu, $"Дискламация Заявка № {request.RequestNum}"); request.DisclaimerRu = disclaimerRu; } // 15 Статус request.Status = localContext.DicRequestStatuses.FirstOrDefault(drs => drs.Code == statusCode); LogMsg(null, request.Status?.NameRu, $"Статус Заявка № {request.RequestNum}"); // 16 Тип ОД var protectionDocType = localContext.DicProtectionDocTypes.FirstOrDefault(t => t.Code == "ITM"); request.ProtectionDocType = protectionDocType; // Охранный документ if (statusCode == "D.TZ") { //todo! Данный статус заявки в системе в данный момент не используется, не понятно как должно работать /*var protectionDoc = * localContext.ProtectionDocs.FirstOrDefault(r => r.GosNumber == markgr.INTREGN.Trim()) * ?? new ProtectionDoc * { * DateCreate = DateTimeOffset.Now * }; * protectionDoc.Request = request; * * protectionDoc.NameEn = request.NameEn; * protectionDoc.GosNumber = request.RequestNum; * protectionDoc.GosDate = request.RequestDate; * // 4 (180) Срок действия ОД * LogMsg(protectionDoc.ValidDate?.ToString(), DateFromString(markgr.EXPDATE)?.ToString(), * $"(180) Срок действия ОД Заявка № {request.RequestNum}"); * protectionDoc.ValidDate = DateFromString(markgr.EXPDATE); * protectionDoc.DistributionDate = request.DistributionDate; * protectionDoc.Transliteration = request.Transliteration; * protectionDoc.Type = request.ProtectionDocType; * protectionDoc.DisclaimerRu = request.DisclaimerRu; * * protectionDoc.Icfems = new List<DicIcfemProtectionDocRelation>(); * foreach (var icfem in protectionDocIcfems) * { * if (localContext.DicIcfemProtectionDocRelations.All(icf => * icf.DicIcfemId != icfem.DicIcfemId && icf.ProtectionDocId != protectionDoc.Id)) * { * protectionDoc.Icfems.Add(icfem); * } * } * * protectionDoc.IcgsProtectionDocs = new List<ICGSProtectionDoc>(); * foreach (var icgspd in protectionDocIcgs) * { * if (localContext.ICGSProtectionDocs.All(icf => * icf.IcgsId != icgspd.Id && icf.ProtectionDocId != protectionDoc.Id)) * { * protectionDoc.IcgsProtectionDocs.Add(icgspd); * } * }*/ } // if (int.TryParse(request.RequestNum, out var reqNumber)) { if (reqNumber >= 1316814) { // Ожидание срока рассмотрения заявки var dicRouteStage = localContext.DicRouteStages.FirstOrDefault(dr => dr.Code == "TMI03.1"); // Начальник управления экспертизы международных заявок на товарные знаки if (dicRouteStage != null) { var requestWorkflow = localContext.RequestWorkflows.FirstOrDefault(rw => rw.OwnerId == request.Id); if (requestWorkflow == null) { var workFlow = new RequestWorkflow { CurrentStageId = dicRouteStage.Id, DateCreate = DateTimeOffset.Now, CurrentUserId = _mainExecutorId, RouteId = dicRouteStage.RouteId, IsComplete = dicRouteStage.IsLast, IsSystem = dicRouteStage.IsSystem, IsMain = dicRouteStage.IsMain, Owner = request }; localContext.RequestWorkflows.Add(workFlow); localContext.SaveChanges(); request.CurrentWorkflowId = workFlow.Id; } } } else { // Публикация ВОИС var dicRouteStage = localContext.DicRouteStages.FirstOrDefault(dr => dr.Code == "TMI03.3.4.5"); if (dicRouteStage != null) { var requestWorkflow = localContext.RequestWorkflows.FirstOrDefault(rw => rw.OwnerId == request.Id); if (requestWorkflow == null) { var workFlow = new RequestWorkflow { CurrentStageId = dicRouteStage.Id, DateCreate = DateTimeOffset.Now, CurrentUserId = _mainExecutorId, RouteId = dicRouteStage.RouteId, IsComplete = dicRouteStage.IsLast, IsSystem = dicRouteStage.IsSystem, IsMain = dicRouteStage.IsMain, Owner = request }; localContext.RequestWorkflows.Add(workFlow); localContext.SaveChanges(); request.CurrentWorkflowId = workFlow.Id; } } // Начальник управления экспертизы международных заявок на товарные знаки } } // 17 By office request.AdditionalDocs = new List <AdditionalDoc>(); // 17.1 Registration if (markgr.ENN != null) { ProcessAdditionalDocs(markgr.ENN, AdditionalDocType.Registration, localContext, ref request); } // 17.2 Subsequent designation if (markgr.EXN != null) { ProcessAdditionalDocs(markgr.EXN, AdditionalDocType.SubsequentDesignation, localContext, ref request); } // 17.3 Continuation of effect if (markgr.CENS != null) { ProcessAdditionalDocs(markgr.CENS, AdditionalDocType.ContinuationOfEffect, localContext, ref request); } // 17.4 Total provisional refusal of protection if (markgr.RFNT != null) { ProcessAdditionalDocs(markgr.RFNT, AdditionalDocType.TotalProvisionalRefusalOfProtection, localContext, ref request); } // 17.5 Statement indicating that the mark is protected for all the goods and services requested if (markgr.FINV != null) { ProcessAdditionalDocs(markgr.FINV, AdditionalDocType.StatementIndicatingThatTheMarkIsProtected, localContext, ref request); } // 17.6 Renewal if (markgr.REN != null) { ProcessAdditionalDocs(markgr.REN, AdditionalDocType.Renewal, localContext, ref request); } // 17.7 Limitation if (markgr.LIN != null) { ProcessAdditionalDocs(markgr.LIN, AdditionalDocType.Limitation, localContext, ref request); } // 17.8 Statement of grant of protection made under Rule 18ter(1) if (markgr.GP18N != null) { ProcessAdditionalDocs(markgr.GP18N, AdditionalDocType.StatementOfGrantOfProtectionMadeUnderRule, localContext, ref request); } // 17.9 Ex Officio examination completed but opposition or observations by third parties still possible, under Rule 18bis(1) if (markgr.ISN != null) { ProcessAdditionalDocs(markgr.ISN, AdditionalDocType.ExOfficioExaminationCompleted, localContext, ref request); } // 17.10 Confirmation of total provisional refusal under Rule 18ter(3) if (markgr.R18NT != null) { ProcessAdditionalDocs(markgr.R18NT, AdditionalDocType.ConfirmationOfTotalProvisionalRefusal, localContext, ref request); } // 17.11 Partial invalidation if (markgr.INNP != null) { ProcessAdditionalDocs(markgr.INNP, AdditionalDocType.PartialInvalidation, localContext, ref request); } // 17.12 Statement indicating the goods and services for which protection of the mark is granted under Rule 18ter(2)(ii) if (markgr.R18NP != null) { ProcessAdditionalDocs(markgr.R18NP, AdditionalDocType.StatementIndicatingTheGoodsAndServices, localContext, ref request); } // 17.13 Further statement under Rule 18ter(4) indicating that protection of the mark is granted for all the goods and services requested if (markgr.FDNV != null) { ProcessAdditionalDocs(markgr.FDNV, AdditionalDocType.FurtherStatementUnderRule, localContext, ref request); } // 17.14 Opposition possible after the 18 months time limit if (markgr.OPN != null) { ProcessAdditionalDocs(markgr.OPN, AdditionalDocType.OppositionPossibleAfterTimeLimit, localContext, ref request); } // 17.15 Statement of grant of protection following a provisional refusal under Rule 18ter(2)(i) if (markgr.R18NV != null) { ProcessAdditionalDocs(markgr.R18NV, AdditionalDocType.StatementOfGrantOfProtectionFollowingProvisionalRefusal, localContext, ref request); } // 17.16 Partial provisional refusal of protection if (markgr.RFNP != null) { ProcessAdditionalDocs(markgr.RFNP, AdditionalDocType.StatementOfGrantOfProtectionFollowingProvisionalRefusal, localContext, ref request); } _numberGenerator.GenerateBarcode(request); #endregion //} //catch (Exception e) //{ // Debug.WriteLine(e); //} //localContext.ProtectionDocs.Add(protectionDoc); return(localContext); }