Пример #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));
        }
Пример #2
0
 protected internal void CheckHost(Asana host)
 {
     if ((host ?? Host) == null)
     {
         throw new NullReferenceException("Host not set to remote data update.");
     }
 }
Пример #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));
        }
Пример #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;
        }
Пример #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;
        }
Пример #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));
        }
Пример #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));
        }
Пример #8
0
 public static Task Save(this AsanaObject obj, Asana host, AsanaFunction function)
 {
     return(host.Save(obj, function));
 }
Пример #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);
        }
Пример #10
0
 public virtual Task RefreshAsync(Asana host = null)
 {
     throw new NotImplementedException();
 }
Пример #11
0
 public virtual Task Refresh(Asana host = null)
 {
     return(RefreshAsync(host));
 }
Пример #12
0
 static public void Save(this AsanaObject obj, Asana host)
 {
     host.Save(obj, null);
 }
Пример #13
0
 static public void Save(this AsanaObject obj, Asana host, AsanaFunction function)
 {
     host.Save(obj, function);
 }
Пример #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);
        }
Пример #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);
        }
Пример #16
0
 public static Task Save(this AsanaObject obj, Asana host)
 {
     return(host.Save(obj, null));
 }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="request"></param>
 /// <param name="host"></param>
 public AsanaRequest(HttpWebRequest request, Asana host)
 {
     _request = request;
     _host    = host;
 }
Пример #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);
        }
Пример #23
0
 public static Task Delete(this AsanaObject obj, Asana host)
 {
     return(host.Delete(obj));
 }
Пример #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)
                {
                }
            }
        }