Пример #1
0
        private void PrepareCertificationData(CarrierPlugin cp)
        {
            ICarrierService plugin = CreateCarrierService(this, cp);

            if (plugin != null)
            {
                UploadFileMaintenance upload = PXGraph.CreateInstance <UploadFileMaintenance>();
                CarrierResult <IList <CarrierCertificationData> > result = plugin.GetCertificationData();

                if (result != null)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (Message message in result.Messages)
                    {
                        sb.AppendFormat("{0}:{1} ", message.Code, message.Description);
                    }

                    if (result.IsSuccess)
                    {
                        CarrierPlugin copy = (CarrierPlugin)Plugin.Cache.CreateCopy(cp);

                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                        {
                            ZipArchive zip = new ZipArchive(ms, false);

                            foreach (CarrierCertificationData d in result.Result)
                            {
                                using (System.IO.Stream zipStream = zip.OpenWrite(string.Format("{0}.{1}", d.Description, d.Format)))
                                {
                                    zipStream.Write(d.File, 0, d.File.Length);
                                }
                            }

                            FileInfo file = new FileInfo("CertificationData.zip", null, ms.ToArray());
                            upload.SaveFile(file, FileExistsAction.CreateVersion);
                            PXNoteAttribute.SetFileNotes(Plugin.Cache, copy, file.UID.Value);
                        }

                        Plugin.Update(copy);

                        this.Save.Press();
                    }
                    else
                    {
                        throw new PXException(SO.Messages.CarrierServiceError, sb.ToString());
                    }
                }
            }
        }