Example #1
0
        internal bool ValidateForLimits()
        {
            if (EnmlContent().Length < Evernote.EDAM.Limits.Constants.EDAM_NOTE_CONTENT_LEN_MIN || EnmlContent().Length > Evernote.EDAM.Limits.Constants.EDAM_NOTE_CONTENT_LEN_MAX)
            {
                ENSDKLogger.ENSDKLogInfo(string.Format("Note fails validation for content length: {0}", this));
                return(false);
            }

            var maxResourceSize = Evernote.EDAM.Limits.Constants.EDAM_RESOURCE_SIZE_MAX_FREE;

            if (ENSession.SharedSession.IsPremiumUser)
            {
                maxResourceSize = Evernote.EDAM.Limits.Constants.EDAM_RESOURCE_SIZE_MAX_PREMIUM;
            }

            foreach (var rs in Resources)
            {
                if (rs.Data.Length > maxResourceSize)
                {
                    ENSDKLogger.ENSDKLogInfo(string.Format("Note fails validation for resource length: {0}", this));
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
 public void AddResource(ENResource resource)
 {
     if (resource != null)
     {
         if (Resources.Count >= Evernote.EDAM.Limits.Constants.EDAM_NOTE_RESOURCES_MAX)
         {
             ENSDKLogger.ENSDKLogInfo(string.Format("Too many resources already on note. Ignoring {0}. Note {1}.", resource, this));
         }
         else
         {
             InvalidateCachedContent();
             Resources.Add(resource);
         }
     }
 }
Example #3
0
        internal static ENResource ResourceWithServiceResource(Resource serviceResource)
        {
            if (serviceResource.Data.Body == null)
            {
                ENSDKLogger.ENSDKLogError("Can't create an ENResource from an EDAMResource with no body");
                return(null);
            }

            var resource = new ENResource();

            resource.Data      = serviceResource.Data.Body;
            resource.MimeType  = serviceResource.Mime;
            resource.Filename  = serviceResource.Attributes.FileName;
            resource.SourceUrl = serviceResource.Attributes.SourceURL;
            return(resource);
        }
Example #4
0
        internal Note EDAMNoteToReplaceServiceNoteGUID(string guid)
        {
            // Turn the ENNote into an EDAMNote. Use the cached EDAMNote as a starting point if we have one
            // and if it matches the note GUID we're given. This way we can preserve the characteristics
            // of the "original" note we might be replacing, but not propagate those properties to a
            // a completely fresh note.
            Note edNote = null;

            if (ServiceNote != null && ServiceNote.Guid == guid)
            {
                // TODO: Make sure we don't need a copy here like the iOS SDK
                edNote = ServiceNote;
                // Don't preserve these. Our caller will either rewrite them or leave them blank.
                edNote.Guid              = null;
                edNote.NotebookGuid      = null;
                edNote.UpdateSequenceNum = 0;
            }
            else
            {
                edNote = new Note();
            }

            edNote.Content = EnmlContent();
            if (string.IsNullOrEmpty(edNote.Content))
            {
                ENNoteContent emptyContent = ENNoteContent.NoteContentWithString("");
                edNote.Content = emptyContent.EnmlWithResources(Resources);
            }
            // Invalidate the derivative content fields.
            edNote.ContentHash   = null;
            edNote.ContentLength = 0;

            edNote.Title = Title;
            if (string.IsNullOrEmpty(edNote.Title))
            {
                // Only use a dummy title if we couldn't get a real one inside limits.
                edNote.Title = "Untitled Note";
            }

            // Set up note attributes.
            if (edNote.Attributes == null)
            {
                edNote.Attributes = new NoteAttributes();
            }
            var sourceApplication = ENSession.SharedSession.SourceApplication;

            // Write sourceApplication and source on all notes.
            edNote.Attributes.SourceApplication = sourceApplication;
            edNote.Attributes.Source            = "";

            // If reminder is flagged on, set reminderOrder to the current UNIX timestamp by convention.
            // (Preserve existing reminderOrder if present)
            if (IsReminder)
            {
                if (edNote.Attributes.ReminderOrder == 0)
                {
                    edNote.Attributes.ReminderOrder = DateTime.Now.ToEdamTimestamp();
                }
            }

            if (SourceUrl != null)
            {
                edNote.Attributes.SourceURL = SourceUrl;
            }

            // Move tags over if present.
            if (TagNames != null)
            {
                edNote.TagNames = TagNames;
            }

            // Turn any ENResources on the note into EDAMResources.
            List <Resource> edResources = new List <Resource>();

            foreach (var localResource in Resources)
            {
                Resource rs = localResource.EDAMResource();
                if (rs != null)
                {
                    edResources.Add(rs);
                }
            }

            // Always set the resources array, even if empty. If we end up using this EDAMNote to
            // update an existing note, we always desire the intention of removing any existing resources.
            edNote.Resources = edResources;

            // Set EDAM attributes if EdamAttributes dictionary is not null.
            if (EdamAttributes != null)
            {
                foreach (string key in EdamAttributes.Keys)
                {
                    var value = EdamAttributes[key];
                    try
                    {
                        var piInstance = typeof(NoteAttributes).GetProperty(key);
                        piInstance.SetValue(edNote.Attributes, value, null);
                    }
                    catch (KeyNotFoundException)
                    {
                        ENSDKLogger.ENSDKLogError(string.Format("Key {0} not found on EDAMNote.Attributes", key));
                    }
                    catch (Exception)
                    {
                        ENSDKLogger.ENSDKLogError(string.Format("Unable to set value {0} for key {1} on EDAMNote.Attributes", value, key));
                    }
                }
            }

            return(edNote);
        }