public XdcamStream(IngestMedia media, bool forWrite)
 {
     if (media == null || media.Directory == null)
         throw new ApplicationException();
     Uri uri = new Uri(media.FullPath);
     _client = new XdcamClient();
     _client.Credentials = media.Directory.NetworkCredential;
     _client.Host = uri.Host;
     _client.UngracefullDisconnection = true;
     try
     {
         _client.Connect();
         _smil_index = 0;
         _media = media;
         _isEditList = media.SmilMetadata != null;
         if (_isEditList)
             _currentStream = _getNextStream();
         else
             _currentStream = forWrite ? _client.OpenWrite(uri.LocalPath) : _client.OpenRead(uri.LocalPath);
     }
     catch
     {
         _client.Dispose();
     }
 }
 protected override void GetVolumeInfo()
 {
     if (IsXDCAM && AccessType == TDirectoryAccessType.FTP)
         using (XdcamClient client = new XdcamClient())
         {
             Uri uri = new Uri(_folder, UriKind.Absolute);
             client.Host = uri.Host;
             client.Credentials = NetworkCredential;
             client.Connect();
             VolumeFreeSize = client.GetFreeDiscSpace();
             client.Disconnect();
         }
     else
         base.GetVolumeInfo();
 }
        private void _readXDCAM(XdcamClient client)
        {
            try
            {
                _xDCAMIndex = XDCAM.SerializationHelper<XDCAM.Index>.Deserialize(_readXMLDocument("INDEX.XML", client));
                if (_xDCAMIndex != null)
                {
                    ClearFiles();
                    foreach (XDCAM.Index.Clip clip in _xDCAMIndex.clipTable.clipTable)
                        try
                        {
                            IngestMedia newMedia = AddFile(clip.clipId + ".MXF") as IngestMedia;
                            if (newMedia != null)
                            {
                                newMedia._folder = "Clip";
                                newMedia._mediaName = clip.clipId;
                                newMedia._duration =  ((long)clip.dur).SMPTEFramesToTimeSpan(clip.fps);
                                newMedia._durationPlay = newMedia.Duration;
                                if (clip.aspectRatio == "4:3")
                                    newMedia._videoFormat = TVideoFormat.PAL;
                                if (clip.aspectRatio == "16:9")
                                    newMedia._videoFormat = TVideoFormat.PAL_FHA;
                                XDCAM.Index.Meta xmlClipFileNameMeta = clip.meta.FirstOrDefault(m => m.type == "PD-Meta");
                                if (xmlClipFileNameMeta != null && !string.IsNullOrWhiteSpace(xmlClipFileNameMeta.file))
                                {
                                    clip.ClipMeta = XDCAM.SerializationHelper<XDCAM.NonRealTimeMeta>.Deserialize(_readXMLDocument(@"Clip/" + xmlClipFileNameMeta.file, client));
                                    newMedia.ClipMetadata = clip.ClipMeta;
                                    if (clip.ClipMeta != null)
                                    {
                                        newMedia.LastUpdated = clip.ClipMeta.lastUpdate == default(DateTime) ? clip.ClipMeta.CreationDate.Value : clip.ClipMeta.lastUpdate;
                                        newMedia.MediaGuid = new Guid(clip.ClipMeta.TargetMaterial.umidRef.Substring(32, 32));
                                        TSMPTEFrameRate rate = (TSMPTEFrameRate)clip.ClipMeta.LtcChangeTable.tcFps;
                                        XDCAM.NonRealTimeMeta.LtcChange start = clip.ClipMeta.LtcChangeTable.LtcChangeTable.FirstOrDefault(l => l.frameCount == 0);
                                        if (start != null)
                                        {
                                            TimeSpan tcStart = start.value.LTCTimecodeToTimeSpan(rate);
                                            if (tcStart >= TimeSpan.FromHours(40)) // TC 40:00:00:00 and greater
                                                tcStart -= TimeSpan.FromHours(40);
                                            newMedia.TCStart = tcStart;
                                            newMedia.TCPlay = tcStart;
                                        }
                                        newMedia.Verified = true;
                                        newMedia.MediaStatus = TMediaStatus.Available;
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e);
                        }
                    if (_xDCAMIndex.editlistTable != null && _xDCAMIndex.editlistTable.editlistTable != null)
                        foreach (XDCAM.Index.EditList edl in _xDCAMIndex.editlistTable.editlistTable)
                        {
                            try
                            {

                                IngestMedia newMedia = AddFile(edl.file) as IngestMedia;
                                if (newMedia != null)
                                {
                                    newMedia._folder = "Clip";
                                    newMedia._duration = ((long)edl.dur).SMPTEFramesToTimeSpan(edl.fps);
                                    newMedia._durationPlay = newMedia.Duration;
                                    if (edl.aspectRatio == "4:3")
                                        newMedia._videoFormat = TVideoFormat.PAL;
                                    if (edl.aspectRatio == "16:9")
                                        newMedia._videoFormat = TVideoFormat.PAL_FHA;
                                    XDCAM.Index.Meta xmlClipFileNameMeta = edl.meta.FirstOrDefault(m => m.type == "PD-Meta");
                                    if (xmlClipFileNameMeta != null && !string.IsNullOrWhiteSpace(xmlClipFileNameMeta.file))
                                    {
                                        edl.EdlMeta = XDCAM.SerializationHelper<XDCAM.NonRealTimeMeta>.Deserialize(_readXMLDocument(@"Edit/" + xmlClipFileNameMeta.file, client));
                                        edl.smil = XDCAM.SerializationHelper<XDCAM.Smil>.Deserialize(_readXMLDocument(@"Edit/" + edl.file, client));
                                        newMedia.ClipMetadata = edl.EdlMeta;
                                        newMedia.SmilMetadata = edl.smil;
                                        if (edl.EdlMeta != null)
                                        {
                                            newMedia._lastUpdated = edl.EdlMeta.lastUpdate == default(DateTime) ? edl.EdlMeta.CreationDate.Value : edl.EdlMeta.lastUpdate;
                                            newMedia.MediaGuid = new Guid(edl.EdlMeta.TargetMaterial.umidRef.Substring(32, 32));
                                            XDCAM.NonRealTimeMeta.LtcChange start = edl.EdlMeta.LtcChangeTable.LtcChangeTable.FirstOrDefault(l => l.frameCount == 0);
                                            if (start != null)
                                            {
                                                TimeSpan tcStart = start.value.LTCTimecodeToTimeSpan((TSMPTEFrameRate) edl.EdlMeta.LtcChangeTable.tcFps);
                                                if (tcStart >= TimeSpan.FromHours(40)) // TC 40:00:00:00 and greater
                                                    tcStart -= TimeSpan.FromHours(40);
                                                newMedia.TCStart = tcStart;
                                                newMedia.TCPlay = tcStart;
                                            }
                                            newMedia.Verified = true;
                                            newMedia.MediaStatus = TMediaStatus.Available;
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e);
                            }
                        }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
 public override void Refresh()
 {
     if (_isRefreshing)
         return;
     _isRefreshing = true;
     try
     {
         if (IsXDCAM)
         {
             if (Monitor.TryEnter(_xdcamLockObject, 1000))
                 try
                 {
                     if (AccessType == TDirectoryAccessType.FTP)
                     {
                         using (XdcamClient client = new XdcamClient())
                         {
                             Uri uri = new Uri(_folder, UriKind.Absolute);
                             client.Host = uri.Host;
                             client.Credentials = NetworkCredential;
                             client.Connect();
                             VolumeFreeSize = client.GetFreeDiscSpace();
                             _readXDCAM(client);
                             client.Disconnect();
                         }
                     }
                     else
                         _readXDCAM(null);
                 }
                 finally
                 {
                     Monitor.Exit(_xdcamLockObject);
                 }
             else
                 throw new ApplicationException("Nie udało się uzyskać dostępu do XDCAM");
         }
         else
             if (AccessType == TDirectoryAccessType.FTP)
                 _ftpDirectoryList();
     }
     finally
     {
         _isRefreshing = false;
     }
 }