Ejemplo n.º 1
0
        public Task AddProject(AsanaProject proj, Asana host)
        {
            Dictionary <string, object> project = new Dictionary <string, object>();

            project.Add("project", proj.ID);
            AsanaResponseEventHandler savedCallback = null;

            savedCallback = (s) =>
            {
                // add it manually
                if (Projects == null)
                {
                    Projects = new AsanaProject[1];
                }
                else
                {
                    AsanaProject[] lProjects = Projects;
                    Array.Resize(ref lProjects, Projects.Length + 1);
                    Projects = lProjects;
                }

                Projects[Projects.Length - 1] = proj;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            return(host.Save(this, AsanaFunction.GetFunction(Function.AddProjectToTask), project));
        }
Ejemplo n.º 2
0
 protected internal void CheckHost(Asana host)
 {
     if ((host ?? Host) == null)
     {
         throw new NullReferenceException("Host not set to remote data update.");
     }
 }
Ejemplo n.º 3
0
        public Task AddTag(AsanaTag proj, Asana host)
        {
            Dictionary <string, object> Tag = new Dictionary <string, object>();

            Tag.Add("tag", proj.ID);
            AsanaResponseEventHandler savedCallback = null;

            savedCallback = (s) =>
            {
                // add it manually
                if (Tags == null)
                {
                    Tags = new AsanaTag[1];
                }
                else
                {
                    AsanaTag[] lTags = Tags;
                    Array.Resize(ref lTags, Tags.Length + 1);
                    Tags = lTags;
                }

                Tags[Tags.Length - 1] = proj;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            return(host.Save(this, AsanaFunction.GetFunction(Function.AddTagToTask), Tag));
        }
Ejemplo n.º 4
0
        public override async Task RefreshAsync(Asana host = null)
        {
            CheckHost(host);
            var workspace = await(Host ?? host).GetWorkspaceByIdAsync(ID);

            Name           = workspace.Name;
            IsOrganization = workspace.IsOrganization;
        }
Ejemplo n.º 5
0
        public override async Task RefreshAsync(Asana host = null)
        {
            CheckHost(host);
            var project = await(host ?? Host).GetProjectByIdAsync(ID);

            Name       = project.Name;
            CreatedAt  = project.CreatedAt;
            ModifiedAt = project.ModifiedAt;
            Notes      = project.Notes;
            Archived   = project.Archived;
            Workspace  = project.Workspace;
            Followers  = project.Followers;
            Team       = project.Team;
            Color      = project.Color;
        }
Ejemplo n.º 6
0
        public Task RemoveProject(AsanaProject proj, Asana host)
        {
            Dictionary <string, object> project = new Dictionary <string, object>();

            project.Add("project", proj.ID);
            AsanaResponseEventHandler savedCallback = null;

            savedCallback = (s) =>
            {
                // add it manually
                int            index     = Array.IndexOf(Projects, proj);
                AsanaProject[] lProjects = new AsanaProject[Projects.Length - 1];
                if (index != 0)
                {
                    Array.Copy(Projects, lProjects, index);
                }
                Array.Copy(Projects, index + 1, lProjects, index, lProjects.Length - index);

                Projects = lProjects;
                Saving  -= savedCallback;
            };
            Saving += savedCallback;
            return(host.Save(this, AsanaFunction.GetFunction(Function.RemoveProjectFromTask), project));
        }
Ejemplo n.º 7
0
        public Task RemoveTag(AsanaTag proj, Asana host)
        {
            Dictionary <string, object> Tag = new Dictionary <string, object>();

            Tag.Add("tag", proj.ID);
            AsanaResponseEventHandler savedCallback = null;

            savedCallback = (s) =>
            {
                // add it manually
                int        index = Array.IndexOf(Tags, proj);
                AsanaTag[] lTags = new AsanaTag[Tags.Length - 1];
                if (index != 0)
                {
                    Array.Copy(Tags, lTags, index);
                }
                Array.Copy(Tags, index + 1, lTags, index, lTags.Length - index);

                Tags    = lTags;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            return(host.Save(this, AsanaFunction.GetFunction(Function.RemoveTagFromTask), Tag));
        }
Ejemplo n.º 8
0
 public static Task Save(this AsanaObject obj, Asana host, AsanaFunction function)
 {
     return(host.Save(obj, function));
 }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static private T[] SafeAssignArray <T>(Dictionary <string, object> source, string name, Asana host)
        {
            T[] value = null;

            if (source.ContainsKey(name) && source[name] != null)
            {
                throw new NotImplementedException();
            }

            return(value);
        }
Ejemplo n.º 10
0
 public virtual Task RefreshAsync(Asana host = null)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public virtual Task Refresh(Asana host = null)
 {
     return(RefreshAsync(host));
 }
Ejemplo n.º 12
0
 static public void Save(this AsanaObject obj, Asana host)
 {
     host.Save(obj, null);
 }
Ejemplo n.º 13
0
 static public void Save(this AsanaObject obj, Asana host, AsanaFunction function)
 {
     host.Save(obj, function);
 }
Ejemplo n.º 14
0
        public void RemoveProject(AsanaProject proj, Asana host)
        {
            Dictionary<string, object> project = new Dictionary<string, object>();
            project.Add("project", proj.ID);
            AsanaResponseEventHandler savedCallback = null;
            savedCallback = (s) =>
            {
                // add it manually
                int index = Array.IndexOf(Projects, proj);
                AsanaProject[] lProjects = new AsanaProject[Projects.Length - 1];
                if(index != 0)
                    Array.Copy(Projects, lProjects, index);
                Array.Copy(Projects, index+1, lProjects, index, lProjects.Length - index);

                Projects = lProjects;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            host.Save(this, AsanaFunction.GetFunction(Function.RemoveProjectFromTask), project);
        }
Ejemplo n.º 15
0
        public void AddProject(AsanaProject proj, Asana host)
        {
            Dictionary<string, object> project = new Dictionary<string, object>();
            project.Add("project", proj.ID);
            AsanaResponseEventHandler savedCallback = null;
            savedCallback = (s) =>
            {
                // add it manually
                if (Projects == null)
                    Projects = new AsanaProject[1];
                else
                {
                    AsanaProject[] lProjects = Projects;
                    Array.Resize(ref lProjects, Projects.Length + 1);
                    Projects = lProjects;
                }

                Projects[Projects.Length - 1] = proj;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            host.Save(this, AsanaFunction.GetFunction(Function.AddProjectToTask), project);
        }
Ejemplo n.º 16
0
 public static Task Save(this AsanaObject obj, Asana host)
 {
     return(host.Save(obj, null));
 }
Ejemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static private T SafeAssign <T>(Dictionary <string, object> source, string name, Asana host)
        {
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
            T             value     = default(T);

            if (source.ContainsKey(name) && source[name] != null)
            {
                if (converter.CanConvertFrom(typeof(string)) && !string.IsNullOrWhiteSpace(source[name].ToString()))
                {
                    value = (T)converter.ConvertFromString(source[name].ToString());
                }
            }

            return(value);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static private AsanaObject SafeAssignAsanaObject <T>(Dictionary <string, object> source, string name, Asana host) where T : AsanaObject
        {
            T value = null;

            if (source.ContainsKey(name) && source[name] != null)
            {
                var obj = source[name] as Dictionary <string, object>;
                value = (T)AsanaObject.Create(typeof(T));
                Parsing.Deserialize(obj, (value as AsanaObject), host);
            }

            return(value);
        }
Ejemplo n.º 19
0
        public Task RemoveTag(AsanaTag proj, Asana host)
        {
            Dictionary<string, object> Tag = new Dictionary<string, object>();
            Tag.Add("tag", proj.ID);
            AsanaResponseEventHandler savedCallback = null;
            savedCallback = (s) =>
            {
                // add it manually
                int index = Array.IndexOf(Tags, proj);
                AsanaTag[] lTags = new AsanaTag[Tags.Length - 1];
                if (index != 0)
                    Array.Copy(Tags, lTags, index);
                Array.Copy(Tags, index + 1, lTags, index, lTags.Length - index);

                Tags = lTags;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            return host.Save(this, AsanaFunction.GetFunction(Function.RemoveTagFromTask), Tag);
        }
Ejemplo n.º 20
0
        public Task AddTag(AsanaTag proj, Asana host)
        {
            Dictionary<string, object> Tag = new Dictionary<string, object>();
            Tag.Add("tag", proj.ID);
            AsanaResponseEventHandler savedCallback = null;
            savedCallback = (s) =>
            {
                // add it manually
                if (Tags == null)
                    Tags = new AsanaTag[1];
                else
                {
                    AsanaTag[] lTags = Tags;
                    Array.Resize(ref lTags, Tags.Length + 1);
                    Tags = lTags;
                }

                Tags[Tags.Length - 1] = proj;
                Saving -= savedCallback;
            };
            Saving += savedCallback;
            return host.Save(this, AsanaFunction.GetFunction(Function.AddTagToTask), Tag);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="request"></param>
 /// <param name="host"></param>
 public AsanaRequest(HttpWebRequest request, Asana host)
 {
     _request = request;
     _host    = host;
 }
Ejemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static private T[] SafeAssignAsanaObjectArray <T>(Dictionary <string, object> source, string name, Asana host) where T : AsanaObject
        {
            T[] value = null;

            if (source.ContainsKey(name) && source[name] != null)
            {
                var list = source[name] as List <object>;

                value = new T[list.Count];
                for (int i = 0; i < list.Count; ++i)
                {
                    T newObj = (T)AsanaObject.Create(typeof(T));
                    Parsing.Deserialize(list[i] as Dictionary <string, object>, (newObj as AsanaObject), host);
                    value[i] = newObj;
                }
            }

            return(value);
        }
Ejemplo n.º 23
0
 public static Task Delete(this AsanaObject obj, Asana host)
 {
     return(host.Delete(obj));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Deserializes a dictionary based on AsanaDataAttributes
        /// </summary>
        /// <param name="data"></param>
        /// <param name="obj"></param>
        static internal void Deserialize(Dictionary <string, object> data, AsanaObject obj, Asana host)
        {
            foreach (var p in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (p.Name == "Host")
                {
                    if (obj.Host != host)
                    {
                        p.SetValue(obj, host, new object[] { });
                    }
                    continue;
                }

                try
                {
                    var cas = p.GetCustomAttributes(typeof(AsanaDataAttribute), false);
                    if (cas.Length == 0)
                    {
                        continue;
                    }

                    AsanaDataAttribute ca = cas[0] as AsanaDataAttribute;

                    if (!data.ContainsKey(ca.Name))
                    {
                        continue;
                    }

                    if (p.PropertyType == typeof(string))
                    {
                        p.SetValue(obj, SafeAssignString(data, ca.Name), null);
                    }
                    else
                    {
                        Type       t      = p.PropertyType.IsArray ? p.PropertyType.GetElementType() : p.PropertyType;
                        MethodInfo method = null;
                        if (typeof(AsanaObject).IsAssignableFrom(t))
                        {
                            method = typeof(Parsing).GetMethod(p.PropertyType.IsArray ? "SafeAssignAsanaObjectArray" : "SafeAssignAsanaObject", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(new Type[] { t });
                        }
                        else
                        {
                            method = typeof(Parsing).GetMethod(p.PropertyType.IsArray ? "SafeAssignArray" : "SafeAssign", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(new Type[] { t });
                        }

                        var methodResult = method.Invoke(null, new object[] { data, ca.Name, host });

                        // this check handle base-class properties
                        if (p.DeclaringType != obj.GetType())
                        {
                            var p2 = p.DeclaringType.GetProperty(p.Name);
                            p2.SetValue(obj, methodResult, null);
                        }
                        else
                        {
                            p.SetValue(obj, methodResult, null);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }