/// <summary>
        /// Files the name for document.
        /// </summary>
        /// <param name="urlCache">
        /// The URL cache.
        /// </param>
        /// <returns>
        /// file name
        /// </returns>
        public string FileNameForDocument(UPSyncDocumentDownloadUrlCache urlCache)
        {
            UPCRMResultRow row;

            if (urlCache != null)
            {
                var fieldGroupCache = urlCache.FieldGroupUrlCacheForFieldGroup(this.FieldGroupName);
                row = fieldGroupCache.RowForRecordIdentification(this.RecordIdentification);
            }
            else
            {
                FieldControl fieldControl = ConfigurationUnitStore.DefaultStore.FieldControlByNameFromGroup("List", this.FieldGroupName);
                if (fieldControl == null)
                {
                    return(null);
                }

                var crmQuery = new UPContainerMetaInfo(fieldControl);
                var result   = crmQuery.ReadRecord(this.RecordIdentification);
                if (result.RowCount == 0)
                {
                    return(null);
                }

                row = (UPCRMResultRow)result.ResultRowAtIndex(0);
            }

            // FUNCTION NAME "Title"
            return(row.ValueAtIndex(1));
        }
        /// <summary>
        /// Servers the modification date.
        /// </summary>
        /// <param name="urlCache">
        /// The URL cache.
        /// </param>
        /// <returns>
        /// when the record last upated
        /// </returns>
        public DateTime?ServerModificationDate(UPSyncDocumentDownloadUrlCache urlCache)
        {
            if (this.DocumentFromFields)
            {
                return(null);
            }

            if (urlCache != null)
            {
                var fieldGroupCache = urlCache.FieldGroupUrlCacheForFieldGroup(this.FieldGroupName);
                var row             = fieldGroupCache.RowForRecordIdentification(this.RecordIdentification);
                if (fieldGroupCache.HasServerDateTime && row != null)
                {
                    string updateDateString = row.RawValueAtIndex(fieldGroupCache.ServerModifyDateFieldIndex);
                    string updateTimeString = row.RawValueAtIndex(fieldGroupCache.ServerModifyTimeFieldIndex);
                    return(!string.IsNullOrEmpty(updateDateString)
                        ? (DateTime?)UPCRMTimeZone.Current.DateFromClientDataMMDateStringTimeString(updateDateString, updateTimeString)
                        : null);
                }
            }

            var documentData = this.DocumentManager.DocumentDataForRecordIdentification(this.RecordIdentification);

            return(documentData?.ServerUpdateDate);
        }
        /// <summary>
        /// Downloads the ur ls for document.
        /// </summary>
        /// <param name="urlCache">The URL cache.</param>
        /// <returns></returns>
        public List <Uri> DownloadUrlsForDocument(UPSyncDocumentDownloadUrlCache urlCache)
        {
            if (this.downloadUrLsIntitialized)
            {
                return(this.downloadUrls);
            }

            this.downloadUrLsIntitialized = true;
            UPCRMResultRow row;
            FieldControl   fieldControl;

            if (urlCache != null)
            {
                var fieldGroupCache = urlCache.FieldGroupUrlCacheForFieldGroup(this.FieldGroupName);
                fieldControl = fieldGroupCache.FieldControl;
                row          = fieldGroupCache.RowForRecordIdentification(this.RecordIdentification);
            }
            else
            {
                fieldControl = ConfigurationUnitStore.DefaultStore.FieldControlByNameFromGroup("List", this.FieldGroupName);
                if (fieldControl == null)
                {
                    return(null);
                }

                var crmQuery = new UPContainerMetaInfo(fieldControl);
                var result   = crmQuery.ReadRecord(this.RecordIdentification);
                if (result.RowCount == 0)
                {
                    return(null);
                }

                row = (UPCRMResultRow)result.ResultRowAtIndex(0);
            }

            if (this.DocumentFromFields)
            {
                var documentDownloadURLs = new List <Uri>();
                foreach (var tab in fieldControl.Tabs)
                {
                    foreach (var field in tab.Fields)
                    {
                        string value = row.ValueAtIndex(field.TabIndependentFieldIndex);
                        if (!string.IsNullOrEmpty(value))
                        {
                            var documentData = this.DocumentManager.DocumentForKey(value);
                            Uri downloadURL  = documentData != null?
                                               ServerSession.CurrentSession.DocumentRequestUrlForRecordIdentification(documentData.RecordIdentification, documentData.Title) :
                                                   ServerSession.CurrentSession.DocumentRequestUrlForDocumentKey(value);

                            if (SmartbookResourceManager.DefaultResourceManager.ResourceForUrl(downloadURL, null) == null)
                            {
                                documentDownloadURLs.Add(downloadURL);
                            }
                        }
                    }
                }

                this.downloadUrls = documentDownloadURLs;
                return(documentDownloadURLs);
            }

            Uri downloadUrl = ServerSession.CurrentSession.DocumentRequestUrlForRecordIdentification(this.RecordIdentification, row.ValueAtIndex(1));

            if (SmartbookResourceManager.DefaultResourceManager.ResourceForUrl(downloadUrl, null) == null)
            {
                this.downloadUrls = new List <Uri> {
                    downloadUrl
                };
                return(this.downloadUrls);
            }

            return(null);
        }