public AttachmentDataAdapter(OleDbDataReader dr, int rowNumber)
        {
            AttachmentDto = new BaseAttachmentDto();

            AttachmentDto.Tag = dr.SafeString((int)AttachmentColumn.Tag).Trim();
            AttachmentDto.Type = dr.SafeString((int)AttachmentColumn.Type).Trim();
            AttachmentDto.AttachmentType = dr.SafeString((int)AttachmentColumn.AttachmentType).Trim();
            AttachmentDto.Filename = dr.SafeString((int)AttachmentColumn.Filename).Trim();
            AttachmentDto.Description = dr.SafeString((int)AttachmentColumn.Description).Trim();

            CheckType(rowNumber);
        }
        private void InsertAttachment(BaseAttachmentDto attachmentDto)
        {
            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.InsertAttachmentCompleted += (s1, e1) =>
                {
                    BaseAttachmentDto result = e1.Result.EntityResult;

                    if (result == null)
                    {
                        mGlobalImportResult.ErrorMessages.Add(string.Format("Failed to save Attachment '{0}' for Type '{1}'.  ", attachmentDto.Filename, attachmentDto.Type));

                        //grab another
                        ProcessSingleAttachmentFile();
                    }
                    else
                    {
                        FinishedAttachmentInsert(result);
                    }
                };
            attachmentDto.UploadedById = CMS.User.Id;
            cmsWebServiceClient.InsertAttachmentAsync(attachmentDto);
        }
        private void TransferSingleAttachmentFile(FileInfo fileInfo, BaseAttachmentDto attachmentDto)
        {
            long sentFileSize = fileInfo.Length;
            long writtenFileSize = 0;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            try
            {
                Stream stream = fileInfo.OpenRead();

                if (stream.Length > int.MaxValue)
                {
                    DbImportResult r = new DbImportResult();
                    r.ErrorMessages = new List<string>();
                    r.ErrorMessages.Add(string.Format("File [{0}] can not be bigger than 2GB. ", fileInfo.Name));
                    FileTransferFailed(r);
                    return;
                }

                int transferChunkSize = Utils.GetTransferChunkSize(stream);
                CommonUploadFile file = new CommonUploadFile { Name = fileInfo.Name, Size = stream.Length, Path = attachmentDto.Path };

                if (stream.Position > -1 && stream.Position < stream.Length)
                {
                    int chunkSize = Utils.GetCurrentChunkSize(stream, transferChunkSize);

                    byte[] fileBytes = new byte[chunkSize];
                    stream.Read(fileBytes, 0, chunkSize);

                    cmsWebServiceClient.UploadFileCompleted +=
                        (s1, e1) =>
                        {
                            if (stream.Position > -1 && stream.Position < stream.Length)
                            {
                                chunkSize = Utils.GetCurrentChunkSize(stream, transferChunkSize);

                                fileBytes = new byte[chunkSize];
                                stream.Read(fileBytes, 0, chunkSize);
                                writtenFileSize += e1.Result.EntityResult.WrittenByteArraySize;

                                cmsWebServiceClient.UploadFileAsync(file.Name, fileBytes, CMS.AppSetting.AttachmentsRootUrl, file.Path, true);
                            }
                            else
                            {
                                //Close the stream when all files are uploaded
                                stream.Close();

                                writtenFileSize += e1.Result.EntityResult.WrittenByteArraySize;

                                if (writtenFileSize < sentFileSize)
                                {
                                    DbImportResult r = new DbImportResult();
                                    r.ErrorMessages = new List<string>();
                                    r.ErrorMessages.Add("There was a loss of information while attempting to transfer the file.  Please try again. ");
                                    FileTransferFailed(r);
                                    return;
                                }

                                BeginAttachmentInsert(attachmentDto);
                            }
                        };

                    cmsWebServiceClient.UploadFileAsync(file.Name, fileBytes, CMS.AppSetting.AttachmentsRootUrl, file.Path, false);
                }
            }
            catch (Exception ex)
            {
                mGlobalImportResult.ErrorMessages.Add(ex.Message);
            }
        }
Beispiel #4
0
            internal static IImporter CreateImporter(ImportFileMetaData metaData, DocumentVersion documentVersion = null, BaseAttachmentDto attachmentDto = null)
            {
                switch (metaData.ImportType)
                {
                    case CommonUtils.ImportType.CreateRelatedDocuments:
                        return new RelatedDocumentImporter(metaData);

                    case CommonUtils.ImportType.CreateIssue:
                    case CommonUtils.ImportType.UpdateIssue:
                        return new IssueImporter(metaData);
                    case CommonUtils.ImportType.CreateMilestones:
                        return new MilestoneImporter(metaData);

                    case CommonUtils.ImportType.CreateUpdateFinancial:
                        return new FinancialImporter(metaData);

                    case CommonUtils.ImportType.CreateIssueReferences:
                    case CommonUtils.ImportType.UpdateIssueReferences:
                        return new IssueSystemReferencesImporter(metaData);

                    case CommonUtils.ImportType.Cji3:
                        return new Cji3Importer(metaData);

                    case CommonUtils.ImportType.Cji5:
                        return new Cji5Importer(metaData);

                    case CommonUtils.ImportType.CreatePipe:
                    case CommonUtils.ImportType.UpdatePipe:
                        return new PipeImporter(metaData);
                    case CommonUtils.ImportType.CreatePipeComponent:
                    case CommonUtils.ImportType.UpdatePipeComponent:
                        return new PipeComponentImporter(metaData);

                    case CommonUtils.ImportType.CreateMechanical:
                    case CommonUtils.ImportType.UpdateMechanical:
                        return new MechanicalImporter(metaData);
                    case CommonUtils.ImportType.CreateMechanicalComponent:
                    case CommonUtils.ImportType.UpdateMechanicalComponent:
                        return new MechanicalComponentImporter(metaData);

                    case CommonUtils.ImportType.CreateElectrical:
                    case CommonUtils.ImportType.UpdateElectrical:
                        return new ElectricalImporter(metaData);
                    case CommonUtils.ImportType.CreateElectricalComponent:
                    case CommonUtils.ImportType.UpdateElectricalComponent:
                        return new ElectricalComponentImporter(metaData);

                    case CommonUtils.ImportType.CreateInstrument:
                    case CommonUtils.ImportType.UpdateInstrument:
                        return new InstrumentImporter(metaData);
                    case CommonUtils.ImportType.CreateInstrumentComponent:
                    case CommonUtils.ImportType.UpdateInstrumentComponent:
                        return new InstrumentComponentImporter(metaData);

                    case CommonUtils.ImportType.CreateCalibrationComponent:
                    case CommonUtils.ImportType.UpdateCalibrationComponent:
                        return new CalibrationComponentImporter(metaData);

                    case CommonUtils.ImportType.CreateMobilePlant:
                    case CommonUtils.ImportType.UpdateMobilePlant:
                        return new MobilePlantImporter(metaData);

                    case CommonUtils.ImportType.CreateMobilePlantComponent:
                    case CommonUtils.ImportType.UpdateMobilePlantComponent:
                        return new MobilePlantComponentImporter(metaData);

                    case CommonUtils.ImportType.CreateDocument:
                    case CommonUtils.ImportType.UpdateDocument:
                        return new DocumentImporter(metaData);

                    case CommonUtils.ImportType.CreateDocumentVersionStep1:
                    case CommonUtils.ImportType.UpdateDocumentVersion: //we don't need the file
                        return new DocumentVersionImporter(metaData);

                    case CommonUtils.ImportType.CreateDocumentLocations:
                        return new DocumentLocationImporter(metaData);

                    case CommonUtils.ImportType.CreateAttachmentDtoStep1:
                    case CommonUtils.ImportType.UpdateAttachment: //we don't need the file
                        return new AttachmentImporter(metaData);

                    case CommonUtils.ImportType.LinkRelatedEquipmentDocument:
                        return new DocumentEquipmentImporter(metaData);

                    //CONTROL SYSTEM
                    case CommonUtils.ImportType.CreateControlsSystems:
                    case CommonUtils.ImportType.UpdateControlSystems:
                        return new ControlSystemImporter(metaData);
                    case CommonUtils.ImportType.CreateControlComponents:
                    case CommonUtils.ImportType.UpdateControlComponents:
                        return new ControlComponentImporter(metaData);
                    case CommonUtils.ImportType.CreateEngineeringProperties:
                    case CommonUtils.ImportType.UpdateEngineeringProperties:
                        return new EngineeringPropertiesImporter(metaData);
                    case CommonUtils.ImportType.CreateTuningProperties:
                    case CommonUtils.ImportType.UpdateTuningProperties:
                        return new TuningPropertiesImporter(metaData);
                    case CommonUtils.ImportType.CreateInterlocks:
                    case CommonUtils.ImportType.UpdateInterlocks:
                        return new InterlockImporter(metaData);
                    case CommonUtils.ImportType.CreateInterlockRisks:
                    case CommonUtils.ImportType.UpdateInterlockRisks:
                        return new InterlockRiskImporter(metaData);

                    //ALARMS
                    case CommonUtils.ImportType.CreateAlarms:
                    case CommonUtils.ImportType.UpdateAlarms:
                        return new AlarmImporter(metaData);

                    //Testing
                    case CommonUtils.ImportType.CreateComponentTestingProperties:
                    case CommonUtils.ImportType.UpdateComponentTestingProperties:
                        return new ComponentTestingPropertiesImporter(metaData);

                }

                return null;
            }
Beispiel #5
0
        private int GetAttachmentTypeId(BaseAttachmentDto dto, CmsEntities cee)
        {
            int match = (from x in cee.AttachmentTypes where x.Code.ToLower() == dto.AttachmentType.ToLower() select x.Id).FirstOrDefault();

            if (match > 0)
            {
                return match;
            }
            return 0;
        }
Beispiel #6
0
 public AttachmentImporter(ImportFileMetaData metaData, BaseAttachmentDto baseAttachmentDto = null)
 {
     MetaData = metaData;
     WorkSheetName = ImportWorkSheetName.Attachments.ToString();
 }
Beispiel #7
0
        private int GetParentId(BaseAttachmentDto dto, CmsEntities cee)
        {
            if (dto.Type.ToLower() == CommonUtils.EntityType.Document.ToString().ToLower())
            {
                int match = (from x in cee.Documents where x.Name.ToLower() == dto.Tag.ToLower() select x.Id).FirstOrDefault();

                if (match > 0)
                {
                    return match;
                }
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.Electrical.ToString().ToLower())
            {
                int match = (from x in cee.ElectricalEquipments where x.Name.ToLower() == dto.Tag.ToLower() select x.Id).FirstOrDefault();

                if (match > 0)
                {
                    return match;
                }
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.Mechanical.ToString().ToLower())
            {
                int match = (from x in cee.MechanicalEquipments where x.Name.ToLower() == dto.Tag.ToLower() select x.Id).FirstOrDefault();

                if (match > 0)
                {
                    return match;
                }
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.MobilePlant.ToString().ToLower())
            {
                int match = (from x in cee.MobilePlants where x.Name.ToLower() == dto.Tag.ToLower() select x.Id).FirstOrDefault();

                if (match > 0)
                {
                    return match;
                }
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.Instrument.ToString().ToLower())
            {
                int match = (from x in cee.Instruments where x.Name.ToLower() == dto.Tag.ToLower() select x.Id).FirstOrDefault();

                if (match > 0)
                {
                    return match;
                }
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.Issue.ToString().ToLower())
            {
                int result;
                int match = 0;

                if (int.TryParse(dto.Tag, out result))
                {
                    match = (from x in cee.Issues where x.Id == result select x.Id).FirstOrDefault();
                }

                if (match > 0)
                {
                    return match;
                }
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.Pipe.ToString().ToLower())
            {

                PipeComponentDataAdapter adapter = new PipeComponentDataAdapter(dto.Tag);
                if (!adapter.ErrorMessages.Any())
                {

                    int pipeAreaNumber = int.Parse(adapter.PipeAreaNumber);
                    int pipeSequence = int.Parse(adapter.PipeSequence);

                    int match = (from x in cee.Pipes 
                                 where x.PipeClass.Name == adapter.PipeClass.ToLower() 
                                 && x.PipeFluidCode.Name==adapter.PipeFluidCode.ToLower()
                                 && x.PipeSize.Name == adapter.PipeSize
                                 && x.PipeSpecialFeature.Name==adapter.PipeSpecialFeature
                                 && x.Area.AreaNumber == pipeAreaNumber
                                 && x.SequenceNo == pipeSequence
                                 select x.Id).FirstOrDefault();

                    if (match > 0)
                    {
                        return match;
                    }
                }
                else
                {
                    DbImportResult.ErrorMessages.AddRange(adapter.ErrorMessages);
                }



              
            }
            else if (dto.Type.ToLower() == CommonUtils.EntityType.Control.ToString().ToLower())
            {
                int match = (from x in cee.ControlSystems where x.Name.ToLower() == dto.Tag.ToLower() select x.Id).FirstOrDefault();

                if (match > 0)
                {
                    return match;
                }
            }
            return 0;
        }
Beispiel #8
0
        private void PopulateBaseAttachmentDtoFks(BaseAttachmentDto dto)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                cee.Configuration.LazyLoadingEnabled = false;

                //GetParentId
                int parentId = GetParentId(dto, cee);
                if (parentId == 0)
                {
                    DbImportResult.ErrorMessages.Add(string.Format("Could not find Equipment '{0}' .", dto.Tag));
                    return;
                }
                dto.ParentId = parentId;

                //GetAttachmentTypeId
                int attachmentTypeId = GetAttachmentTypeId(dto, cee);
                if (attachmentTypeId == 0)
                {
                    DbImportResult.ErrorMessages.Add(string.Format("Could not find Attachment Type {0}.", dto.AttachmentType));
                    return;
                }
                dto.AttachmentTypeId = attachmentTypeId;

            }
        }