示例#1
0
        private bool Update(Task requestedTask, Task originalTask, Task newTask)
        {
            bool updated = false;
            // timestamps!!
            Type t = requestedTask.GetType();
            foreach (PropertyInfo pi in t.GetProperties())
            {
                object serverValue = pi.GetValue(requestedTask, null);
                object origValue = pi.GetValue(originalTask, null);
                object newValue = pi.GetValue(newTask, null);

                // if this is the TasgTags field make it simple - if this update is the last one, it wins
                if (pi.Name == "TaskTags")
                {
                    if (newTask.LastModified > requestedTask.LastModified)
                    {
                        pi.SetValue(requestedTask, newValue, null);
                        updated = true;
                    }
                    continue;
                }

                // if the value has changed, process further
                if (!Object.Equals(origValue, newValue))
                {
                    // if the server has the original value, or the new task has a later timestamp than the server, then make the update
                    if (Object.Equals(serverValue, origValue) || newTask.LastModified > requestedTask.LastModified)
                    {
                        pi.SetValue(requestedTask, newValue, null);
                        updated = true;
                    }
                }
            }

            return updated;
        }