private void FillSchedule(Mcm.Data.Dto.Object obj, SearchViewData data, Metadata metadata, string type)
 {
   var title = GetMetadata(metadata.MetadataXml, "Title");
   data.Title = string.IsNullOrEmpty(title) ? GetMetadata(metadata.MetadataXml, "Filename") : title;
   data.Type = type;
   data.FreeText = GetMetadata(metadata.MetadataXml, "AllText");
   data.Url = MetadataHelper.GetUrl(obj, "PDF");
   data.PubStartDate = Helpers.DateTimeHelper.ParseAndFormatDate(GetMetadata(metadata.MetadataXml, "Date"));
   data.PubEndDate = string.Empty;
 }
    public override IList<IViewData> Index(object objectsToIndex)
    {
      var obj = objectsToIndex as Mcm.Data.Dto.Object;

      if (obj == null) return new List<IViewData>();

      var data = new SearchViewData();

      switch (obj.ObjectTypeID)
      {
        case RadioObjectId:
          {
            data = CreateRadioSearchViewData(obj, data);

            if (data == null) return new List<IViewData>();

            break;
          }
        case ScheduleObjectId:
          {
            var metadata = obj.Metadatas.FirstOrDefault(item => item.MetadataSchemaGuid == ScheduleMetadataSchemaGuid);
            if (metadata == null) return new List<IViewData>();
            FillSchedule(obj, data, metadata, "Schedule");
            break;
          }
        case ScheduleNoteObjectId:
          {
            var metadata =
              obj.Metadatas.FirstOrDefault(item => item.MetadataSchemaGuid == ScheduleNoteMetadataSchemaGuid);
            if (metadata == null) return new List<IViewData>();
            FillSchedule(obj, data, metadata, "ScheduleNote");
            break;
          }
        case SegmentedScheduleObjectId:
          {
            var metadata = obj.Metadatas.FirstOrDefault(item => item.MetadataSchemaGuid == ProgramMetadataSchemaGuid);
            var larmmetadata = obj.Metadatas.FirstOrDefault(item => item.MetadataSchemaGuid == LarmMetadataSchemaGuid);

            if (metadata == null) return null;

            var larmmetadataString = "";

            if (larmmetadata != null) larmmetadataString = MetadataHelper.GetXmlContent(larmmetadata.MetadataXml);

            data.HasLarmMetadata = !string.IsNullOrEmpty(larmmetadataString);

            data.Url = MetadataHelper.GetUrl(obj, "PDF");

            data.Title = GetMetadata(metadata.MetadataXml, "Title");
            data.Channel = GetMetadata(metadata.MetadataXml, "PublicationChannel");
            data.Type = "SegmentedSchedule";

            data.FreeText = metadata.MetadataXml.Root.Value + " " + larmmetadataString;
            data.PubStartDate =
              DateTimeHelper.ParseAndFormatDate(GetMetadata(metadata.MetadataXml, "PublicationDateTime"));
            data.PubEndDate =
              DateTimeHelper.ParseAndFormatDate(GetMetadata(metadata.MetadataXml, "PublicationEndDateTime"));

            data.Duration = TimeCodeHelper.ConvertToTimeCode(data.PubStartDate, data.PubEndDate);
            data.DurationSec = TimeCodeHelper.ConvertToDurationInSec(data.PubStartDate, data.PubEndDate).ToString();


            break;
          }

        case AnnotationObjectId:
          {
            //Get Radio object
            var radioRelation = obj.ObjectRelationInfos.FirstOrDefault(o => o.Object1TypeID == RadioObjectId);

            if (radioRelation == null) return new List<IViewData>();

            var radioObject = Repository.ObjectGet(radioRelation.Object1Guid, true, true, true);

            //Index RadioObject
            data = CreateRadioSearchViewData(radioObject, data);

            //Index radioobject not the annotation object
            obj = radioObject;

            if (data == null) return new List<IViewData>();

            break;
          }
        default:
          return new List<IViewData>();
      }

      data.ObjectFolders = obj.ObjectFolders;
      data.Identifier = obj.Guid.ToString();

      return new[] {data};
    }
    private SearchViewData CreateRadioSearchViewData(Mcm.Data.Dto.Object obj, SearchViewData data)
    {
      var metadata = obj.Metadatas.FirstOrDefault(item => item.MetadataSchemaGuid == ProgramMetadataSchemaGuid);
      var larmmetadata = obj.Metadatas.FirstOrDefault(item => item.MetadataSchemaGuid == LarmMetadataSchemaGuid);

      if (metadata == null) return null;

      var larmmetadataString = "";

      if (larmmetadata != null) larmmetadataString = MetadataHelper.GetXmlContent(larmmetadata.MetadataXml);

      //throw new Exception("dates: "+  GetMetadata(metadata.MetadataXml, "PublicationDateTime") + " " + GetMetadata(metadata.MetadataXml, "PublicationEndDateTime"));


      data.HasLarmMetadata = !string.IsNullOrEmpty(larmmetadataString);

      data.Title = GetMetadata(metadata.MetadataXml, "Title");
      data.Channel = GetMetadata(metadata.MetadataXml, "PublicationChannel");
      data.Type = "Radio";
      data.FreeText = MetadataHelper.GetXmlContent(metadata.MetadataXml) + " " + larmmetadataString;
      data.PubStartDate = DateTimeHelper.ParseAndFormatDate(GetMetadata(metadata.MetadataXml, "PublicationDateTime"));
        //"2005-08-10T12:00:00Z";
      data.PubEndDate = DateTimeHelper.ParseAndFormatDate(GetMetadata(metadata.MetadataXml, "PublicationEndDateTime"));
        //"2005-08-10T12:05:00Z";
      data.Duration = TimeCodeHelper.ConvertToTimeCode(data.PubStartDate, data.PubEndDate);
      data.DurationSec = TimeCodeHelper.ConvertToDurationInSec(data.PubStartDate, data.PubEndDate).ToString();
      data.ThumbUrl = MetadataHelper.GetUrl(obj, "Thumbnail");
      data.DomsId = GetMetadata(metadata.MetadataXml, "SB.DomsID");

      if (obj.ObjectRelationInfos != null)
      {
        data.AnnotationCount =
          obj.ObjectRelationInfos.Count(robj => robj.Object2TypeID == AnnotationObjectId).ToString();
        data.AttachedFilesCount =
          obj.ObjectRelationInfos.Count(robj => robj.Object2TypeID == AttachedFileObjectId).ToString();
        data.FreeTextAnnotation = GetRelatedObjectsFreeText(obj);
      }

      return data;
    }