Exemple #1
0
        public UploadResponse Upload(UploadRequest request)
        {
            var tempFile = Path.GetTempFileName();

            try
            {
                // write data to a temp file
                File.WriteAllBytes(tempFile, request.DataContent);

                // create the new document object, and put the remote file
                var args = new AttachedDocumentCreationArgs
                {
                    MimeType             = request.MimeType,
                    FileExtension        = request.FileExtension,
                    LocalContentFilePath = tempFile
                };

                var document = AttachedDocument.Create(args, AttachmentStore.GetClient());
                PersistenceContext.Lock(document, DirtyState.New);

                PersistenceContext.SynchState();

                var assembler = new AttachedDocumentAssembler();
                return(new UploadResponse(assembler.CreateAttachedDocumentSummary(document)));
            }
            finally
            {
                File.Delete(tempFile);
            }
        }
Exemple #2
0
        public Patient FindDocumentOwner(AttachedDocument document)
        {
            var q = this.GetNamedHqlQuery("documentPatientOwner");

            q.SetParameter(0, document);
            return((Patient)q.UniqueResult());
        }
        public AttachedDocumentSummary CreateAttachedDocumentSummary(AttachedDocument doc)
        {
            var summary = new AttachedDocumentSummary();

            UpdateAttachedDocumentSummary(doc, summary);

            return(summary);
        }
 public void UpdateAttachedDocumentSummary(AttachedDocument doc, AttachedDocumentSummary summary)
 {
     summary.DocumentRef      = doc.GetRef();
     summary.CreationTime     = doc.CreationTime;
     summary.ReceivedTime     = doc.DocumentReceivedTime;
     summary.MimeType         = doc.MimeType;
     summary.ContentUrl       = doc.ContentUrl;
     summary.FileExtension    = doc.FileExtension;
     summary.DocumentHeaders  = new Dictionary <string, string>(doc.DocumentHeaders);
     summary.DocumentTypeName = doc.DocumentTypeName;
 }
Exemple #5
0
        /// <summary>
        /// Returns the list of documents attached to a test case
        /// </summary>
        /// <param name="projectId">The id of the project</param>
        /// <param name="testCaseId">The id of the test case</param>
        /// <returns>The list of documents</returns>
        public List <AttachedDocument> GetAttachedDocuments(int projectId, int testCaseId)
        {
            List <AttachedDocument> attachedDocs = new List <AttachedDocument>();

            //Connect to the project.
            if (this._client.Connection_ConnectToProject(projectId))
            {
                try
                {
                    RemoteSort remoteSort = new RemoteSort();
                    remoteSort.PropertyName  = "Filename";
                    remoteSort.SortAscending = true;
                    RemoteDocument[] remoteDocuments = this._client.Document_RetrieveForArtifact((int)ArtifactType.TestCase, testCaseId, null, remoteSort);

                    //Iterate through each document and download the physical file if it is a file
                    foreach (RemoteDocument remoteDocument in remoteDocuments)
                    {
                        //Populate the internal object class
                        AttachedDocument attachedDoc = new AttachedDocument();
                        attachedDocs.Add(attachedDoc);
                        attachedDoc.Type                      = (AttachedDocument.AttachmentType)remoteDocument.AttachmentTypeId;
                        attachedDoc.FilenameOrUrl             = remoteDocument.FilenameOrUrl;
                        attachedDoc.TestCaseId                = remoteDocument.ArtifactId.Value;
                        attachedDoc.ProjectAttachmentTypeId   = remoteDocument.ProjectAttachmentTypeId.Value;
                        attachedDoc.ProjectAttachmentFolderId = remoteDocument.ProjectAttachmentFolderId.Value;
                        attachedDoc.Size                      = remoteDocument.Size;
                        attachedDoc.Tags                      = remoteDocument.Tags;
                        attachedDoc.UploadDate                = remoteDocument.UploadDate;
                        attachedDoc.EditedDate                = remoteDocument.EditedDate;
                        attachedDoc.CurrentVersion            = remoteDocument.CurrentVersion;

                        if (remoteDocument.AttachmentTypeId == (int)AttachedDocument.AttachmentType.File)
                        {
                            byte[] binaryData = this._client.Document_OpenFile(remoteDocument.AttachmentId.Value);
                            attachedDoc.BinaryData = binaryData;
                        }
                    }
                }
                catch (Exception exception)
                {
                    string strMessage = "Error getting attachments for test case TC:" + testCaseId + " in project PR:" + projectId + " (" + exception.Message + ")";
                    Logger.LogMessage(strMessage, System.Diagnostics.EventLogEntryType.Error);
                    return(null);
                }
            }
            else
            {
                string strMessage = "Could not connect to project PR:" + projectId + ".";
                Logger.LogMessage(strMessage, System.Diagnostics.EventLogEntryType.Error);
                return(null);
            }

            return(attachedDocs);
        }
Exemple #6
0
        public void Test2()
        {
            var cq  = new CertificateQuality(100);
            var doc = new AttachedDocument(100);

            doc.Content = ImagesConverter.ToByteArray(new Bitmap(@"D:\Repositories\HalfbloodApp\Halfblood.UnitTests\Halfblood.UnitTests\36.jpg"));
            cq.Documents.Add(doc);

            var context = new CopyContext <CertificateQuality>(cq);

            context.Commit();
        }
        private void ExecutedFind(object sender, ExecutedRoutedEventArgs e)
        {
            var pubinfo = e.Parameter as IUserInformation;

            if ((pubinfo == null) || (pubinfo.Source == null) || (AttachedDocument == null))
            {
                return;
            }

            // if is defined Field then jump directly to it
            if (pubinfo.NavigateToSourceAction != null)
            {
                pubinfo.NavigateToSourceAction.Invoke();
                return;
            }

            //if there is a bookmark with name of the workitem title
            if (!string.IsNullOrEmpty(pubinfo.Source.Id.ToString(CultureInfo.InvariantCulture)) && pubinfo.Source.Id != 0)
            {
                object title = string.Concat("w2t", pubinfo.Source.Id.ToString(CultureInfo.InvariantCulture));

                if (AttachedDocument.Bookmarks.Exists(title.ToString()))
                {
                    AttachedDocument.Bookmarks[title].Select();
                }
                else
                {
                    //if there is no bookmark, but it has an Id -> Find ID!
                    Microsoft.Office.Interop.Word.Range range = AttachedDocument.Range();
                    var find = range.Find;
                    find.Text = pubinfo.Source.Id.ToString(CultureInfo.InvariantCulture);
                    if (find.Execute())
                    {
                        range.Select();
                    }
                }
            }
            else
            {
                //If not propper synced, search for the Title
                Microsoft.Office.Interop.Word.Range range = AttachedDocument.Range();
                var find = range.Find;
                if (!pubinfo.Source.Fields.Contains(FieldReferenceNames.SystemTitle))
                {
                    return;
                }
                find.Text = pubinfo.Source.Fields[FieldReferenceNames.SystemTitle].Value;
                if (find.Execute())
                {
                    range.Select();
                }
            }
        }
Exemple #8
0
        public void Test5()
        {
            var connection = new NhConnection("hibernate.cfg.xml");

            connection.Connecting();
            ISession session = connection.GetSessionFactory().OpenSession();

            var doc = new AttachedDocument
            {
                AttachedDocumentType = new AttachedDocumentType {
                    Rn = 813609324
                },
                BData    = new byte[] { 1, 2, 3 },
                Code     = "Code",
                Catalog  = new Catalog(465000873),
                Document = 437790479,
                Note     = "1",
                //  UnitCode = "Contracts"
            };

            session.Save(doc);

            return;
            //            var planCertificate =
            //                session.Query<PlanCertificate>()
            //                    .Fetch(x => x.CertificateQuality)
            //                    .ThenFetchMany(x => x.ChemicalIndicatorValues)
            //                    .Where(x => x.Rn == 1008028460L).ToList().First();
            //
            //            var dto = planCertificate.MapTo<PlanCertificateDto>();
            //            planCertificate = dto.MapTo<PlanCertificate>();
            //
            //            session.Clear();
            //            session.Dispose();
            //
            //
            //            session = connection.GetSessionFactory().OpenSession();
            //
            //            planCertificate.Rn = 0;
            //            planCertificate.CertificateQuality.Rn = 0;
            //
            //
            //            planCertificate.CertificateQuality.AttachedDocuments.Add(doc);
            //
            //
            //            var repository = new RepositoryFactory(session).Create<PlanCertificate>();
            //            repository.Insert(planCertificate);
            //
            //            session.Flush();
            //            session.Dispose();
        }
		public Patient FindDocumentOwner(AttachedDocument document)
		{
			var q = this.GetNamedHqlQuery("documentPatientOwner");
			q.SetParameter(0, document);
			return (Patient) q.UniqueResult();
		}
Exemple #10
0
        public void ExcuteViewDocumentCommand(object obj)
        {
            try
            {
                AttachmentDTO attachment = null;
                switch (SelectedTabItem.Name)
                {
                case "TabAgreement":
                    attachment = SelectedRequiredDocument.AgreementAttachment;
                    break;

                case "TabPassport":
                    attachment = SelectedRequiredDocument.PassportAttachment;
                    break;

                case "TabIdCard":
                    attachment = SelectedRequiredDocument.IdCardAttachment;
                    break;

                case "TabContactIdCard":
                    attachment = SelectedRequiredDocument.ContactIdCardAttachment;
                    break;

                case "TabFingerPrint":
                    attachment = SelectedRequiredDocument.FingerPrintAttachment;
                    break;

                case "TabMedical":
                    attachment = SelectedRequiredDocument.MedicalAttachment;
                    break;

                case "TabPreDeparture":
                    attachment = SelectedRequiredDocument.PreDepartureAttachment;
                    break;

                case "TabGradeEight":
                    attachment = SelectedRequiredDocument.GradeEightAttachment;
                    break;

                case "TabCoc":
                    attachment = SelectedRequiredDocument.CocAttachment;
                    break;

                case "TabInsurance":
                    attachment = SelectedRequiredDocument.InsuranceAttachment;
                    break;
                }

                if (attachment != null && attachment.AttachedFile != null)
                {
                    if (SelectedTabItem.Name == "TabAgreement")
                    {
                        var pdfFilePath = Environment.SpecialFolder.MyDocuments + attachment.Id + ".pdf";
                        System.IO.File.WriteAllBytes(pdfFilePath, attachment.AttachedFile);
                        System.Diagnostics.Process.Start(pdfFilePath);
                    }
                    else
                    {
                        var myDataSet = new ReportsDataSet();

                        myDataSet.LetterHeads.Rows.Add("1", attachment.AttachedFile, null, null, "", "");

                        var myReport = new AttachedDocument();
                        myReport.SetDataSource(myDataSet);

                        var report = new ReportViewerCommon(myReport);
                        report.ShowDialog();
                    }
                }
            }
            catch
            {
            }
        }
        private void Save()
        {
            if (IsAttach && !string.IsNullOrEmpty(SearchCompanyTxt) && !string.IsNullOrEmpty(DocumentNumber))
            {
                Document newDocument = FillDocument();

                // Get path from tree nodes
                string url = CurrentNode == null ? "" : GetNewPath(CurrentNode);

                // Check folder exist
                string path = string.IsNullOrEmpty(url) ? "" : FolderService.GetFolderPath((int)CurrentPresentation, CurrentNode.Node.Name, url) + string.Format("{0} {1}.{2}", SelectedDocumentType.descriptionRU, newDocument.number.Replace("/", "_").Replace("\\", "_"), AttachedDocument.Substring(AttachedDocument.LastIndexOf(".") + 1));

                if (document != null && document.id != null && document.id > 0) // Update
                {
                    // Update link if need
                    if (AttachedDocument != DocumentService.ReadDocumentLink(document.id))
                    {
                        if (!string.IsNullOrEmpty(path))
                        {
                            DocumentService.UpdateDocumentLink(path, path.Substring(path.LastIndexOf(".") + 1), (int)document.linkId);

                            // Copy attached file to destination
                            if (FileSystemService.CopyFile(AttachedDocument, path))
                            {
                                MessagesService.Show("РЕДАКТИРОВАНИЕ", "Файл удачно занесен в архив");
                            }
                        }
                        else
                        {
                            MessagesService.Show("РЕДАКТИРОВАНИЕ", "Изменение прикрепленного файла не возможно, так как не выбрана ветка пути.\nБудут изменены лишь основные данные.");
                        }
                    }

                    // Update document
                    DocumentService.UpdateDocument(newDocument, document.id);

                    // Update serial number
                    if (CurrentPresentation == PresentationEnum.Archive)
                    {
                        DocumentService.UpdateDocumentWithASN(document.id, DocumentSerialNumber);
                    }

                    // Update view
                    presentTreeVM.DetailsVM.SelectedDocument.Document = DocumentService.ReadDocument(document.id);

                    // Close panel
                    Cancel();
                }
                else // Create
                {
                    // Create link
                    int linkId = DocumentService.CreateDocumentLink(path, path.Substring(path.LastIndexOf(".") + 1));

                    if (linkId > 0)
                    {
                        newDocument.linkId = linkId;
                        string query = string.Format("{0}={1},{2}", CurrentNode.Node.Level_id, CurrentNode.Node.Name, presentTreeVM.GetParentValues(CurrentNode.Parent));

                        // Create document in base
                        int newDocId = DocumentService.CreateDocument(newDocument, (int)CurrentPresentation, query);

                        if (newDocId > 0)
                        {
                            // Set archive serial number if archive presentation
                            if (CurrentPresentation == PresentationEnum.Archive)
                            {
                                DocumentService.UpdateDocumentWithASN(newDocId, DocumentSerialNumber);
                            }

                            // Copy attached file to destination
                            if (FileSystemService.CopyFile(AttachedDocument, path))
                            {
                                MessagesService.Show("СОХРАНЕНИЕ", "Файл удачно занесен в архив");

                                // Update view
                                presentTreeVM.DetailsVM.Documents.Add(new DocumentVM(DocumentService.ReadDocument(newDocId)));

                                // Close panel
                                Cancel();
                            }
                            else
                            {
                                MessagesService.Show("СОХРАНЕНИЕ", "Произошла ошибка во время занесения файла в архив");
                            }
                        }
                        else
                        {
                            MessagesService.Show("СОХРАНЕНИЕ", "Произошла ошибка во время сохранения документа в базе");
                        }
                    }
                    else
                    {
                        MessagesService.Show("СОХРАНЕНИЕ", "Произошла ошибка во время сохранения пути");
                    }
                }
            }
            else
            {
                MessagesService.Show("СОХРАНЕНИЕ", "Нет прикрепленного документа или не все данные заполненны.");
            }
        }