Exemplo n.º 1
0
        // Initialize a new ENNote from an EDAMNote.
        internal ENNote(Note edamNote)
        {
            // Copy the fields that can be edited at this level.
            _Title     = edamNote.Title;
            _Content   = ENNoteContent.NoteContentWithENML(edamNote.Content);
            IsReminder = edamNote.Attributes.ReminderOrder != 0;
            SourceUrl  = edamNote.Attributes.SourceURL;
            _TagNames  = edamNote.TagNames;            //This is usually null, unfortunately, on notes that come from the service.

            // Resources to ENResources
            _Resources = new List <ENResource>();
            if (edamNote.Resources != null)
            {
                foreach (Resource serviceResource in edamNote.Resources)
                {
                    ENResource resource = ENResource.ResourceWithServiceResource(serviceResource);
                    if (resource != null)
                    {
                        _Resources.Add(resource);
                    }
                }
            }

            // Keep a copy of the service note around with all of its extra properties
            // in case we have to convert back to an EDAMNote later.
            ServiceNote = edamNote;

            // Get rid of these references here; they take up memory and we can let them be potentially cleaned up.
            ServiceNote.Content   = null;
            ServiceNote.Resources = null;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
		// Initialize a new ENNote from an EDAMNote.
		internal ENNote(Note edamNote)
		{
			// Copy the fields that can be edited at this level.
			_Title = edamNote.Title;
			_Content = ENNoteContent.NoteContentWithENML(edamNote.Content);
			this.IsReminder = edamNote.Attributes.ReminderOrder != 0;
			this.SourceUrl = edamNote.Attributes.SourceURL;
			_TagNames = edamNote.TagNames; //This is usually null, unfortunately, on notes that come from the service.

			// Resources to ENResources
			_Resources = new List<ENResource>();
			if (edamNote.Resources != null)
			{
				foreach (Resource serviceResource in edamNote.Resources)
				{
					ENResource resource = ENResource.ResourceWithServiceResource(serviceResource);
					if (resource != null)
					{
						_Resources.Add(resource);
					}
				}
			}

			// Keep a copy of the service note around with all of its extra properties
			// in case we have to convert back to an EDAMNote later.
			ServiceNote = edamNote;

			// Get rid of these references here; they take up memory and we can let them be potentially cleaned up.
			ServiceNote.Content = null;
			ServiceNote.Resources = null;
		}