예제 #1
0
        public static ImportStatus GetStatus()
        {
            ImportFromBasecamp importd = null;

            lock (Imports.SynchRoot)
            {
                importd =
                    Imports.GetItems().Where(x => x.Id == CoreContext.TenantManager.GetCurrentTenant().TenantId).
                    SingleOrDefault();
            }
            if (importd == null)
            {
                lock (Completed)
                {
                    //Maybe it's completed already
                    importd = Completed.Where(x => x.Id == CoreContext.TenantManager.GetCurrentTenant().TenantId).
                              FirstOrDefault();
                }
            }
            if (importd != null)
            {
                return(importd.Status);
            }
            throw new KeyNotFoundException("Import not found");
        }
예제 #2
0
        public static int Add(string url, string token, bool processClosed, bool disableNotifications)
        {
            lock (Imports.SynchRoot)
            {
                if (Imports.GetItems().Count(x => x.Id == CoreContext.TenantManager.GetCurrentTenant().TenantId) > 0)
                {
                    throw new DuplicateNameException("Import already running");
                }
            }
            lock (Completed)
            {
                Completed.RemoveAll(x => x.Id == CoreContext.TenantManager.GetCurrentTenant().TenantId);
            }

            SecurityContext.DemandPermissions(ASC.Core.Users.Constants.Action_AddRemoveUser);
            ProjectSecurity.DemandCreateProject();

            var importTask = new ImportFromBasecamp(url, token, HttpContext.Current, SecurityContext.CurrentAccount.ID, processClosed, disableNotifications, Global.EngineFactory);//NOTE: engine factory newly created!!!

            lock (Imports.SynchRoot)
            {
                Imports.Add(importTask);
            }
            return(importTask.Id);
        }
예제 #3
0
        public static IEnumerable <Project> GetProjects(string url, string userName, string password)
        {
            var basecampManager = BaseCamp.GetInstance(ImportFromBasecamp.PrepUrl(url).ToString().TrimEnd('/') + "/api/v1", userName, password);

            return(basecampManager.Projects.Select(r => new Project {
                ID = r.ID, Title = r.Name, Status = r.IsClosed ? ProjectStatus.Closed : ProjectStatus.Open
            }).ToList());
        }
예제 #4
0
 public bool Equals(ImportFromBasecamp other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.Id == Id);
 }
예제 #5
0
        public static int CheckUsersQuota(string url, string userName, string password)
        {
            var basecampManager    = BaseCamp.GetInstance(ImportFromBasecamp.PrepUrl(url).ToString().TrimEnd('/') + "/api/v1", userName, password);
            var countImportedUsers = basecampManager.People.Count();
            var remainingAmount    = TenantExtra.GetRemainingCountUsers();

            if (remainingAmount == 0)
            {
                return(0);
            }

            var difference = remainingAmount - countImportedUsers;

            return(difference >= 0 ? remainingAmount : -remainingAmount);
        }
예제 #6
0
        public static int Add(string url, string userName, string password, bool processClosed, bool disableNotifications, bool importUsersAsCollaborators, IEnumerable <int> projects)
        {
            var status = GetStatus();

            if (imports.GetItems().Count(x => x.Id == TenantProvider.CurrentTenantID) > 0 || (status.Started && !status.Completed))
            {
                throw new DuplicateNameException("Import already running");
            }

            SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser);

            var importTask = new ImportFromBasecamp(url, userName, password, SecurityContext.CurrentAccount.ID, processClosed, disableNotifications, importUsersAsCollaborators, Global.EngineFactory, projects);

            imports.Add(importTask);

            return(importTask.Id);
        }
예제 #7
0
        private static void DoImport(ImportFromBasecamp obj)
        {
            try
            {
                obj.StartImport();

                NotifyClient.Instance.SendAboutImportComplite(obj.InitiatorId);
            }
            catch (Exception e)
            {
                obj.ImportError(e);
            }
            finally
            {
                obj.ImportComplete();
            }
        }
        public static int Add(string url, string userName, string password, bool processClosed, bool disableNotifications, bool importUsersAsCollaborators, IEnumerable<int> projects)
        {
            if (Imports.GetItems().Count(x => x.Id == TenantProvider.CurrentTenantID) > 0)
                throw new DuplicateNameException("Import already running");
            
            lock (Completed)
            {
                Completed.RemoveAll(x => x.Id == TenantProvider.CurrentTenantID);
            }

            SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser);

            var importTask = new ImportFromBasecamp(url, userName, password, SecurityContext.CurrentAccount.ID, processClosed, disableNotifications, importUsersAsCollaborators, Global.EngineFactory, projects);
            
            Imports.Add(importTask);
            
            return importTask.Id;
        }
예제 #9
0
        public static ImportStatus GetStatus()
        {
            ImportFromBasecamp importd = Imports.GetItems().SingleOrDefault(x => x.Id == TenantProvider.CurrentTenantID);

            if (importd == null)
            {
                lock (Completed)
                {
                    //Maybe it's completed already
                    importd = Completed.FirstOrDefault(x => x.Id == TenantProvider.CurrentTenantID);
                    Completed.RemoveAll(x => x.Id == TenantProvider.CurrentTenantID);
                }
            }
            if (importd != null)
            {
                return(importd.Status);
            }
            throw new KeyNotFoundException("Import not found"); //todo: return ImportStatus
        }
예제 #10
0
        public static int Add(string url, string token, bool processClosed, bool disableNotifications)
        {
            lock (Imports.SynchRoot)
            {
                if (Imports.GetItems().Count(x => x.Id == CoreContext.TenantManager.GetCurrentTenant().TenantId) > 0)
                    throw new DuplicateNameException("Import already running");

            }
            lock (Completed)
            {
                Completed.RemoveAll(x => x.Id == CoreContext.TenantManager.GetCurrentTenant().TenantId);
            }

            SecurityContext.DemandPermissions(ASC.Core.Users.Constants.Action_AddRemoveUser);
            ProjectSecurity.DemandCreateProject();

            var importTask = new ImportFromBasecamp(url, token, HttpContext.Current, SecurityContext.CurrentAccount.ID, processClosed, disableNotifications, Global.EngineFactory);//NOTE: engine factory newly created!!!
            lock (Imports.SynchRoot)
            {
                Imports.Add(importTask);
            }
            return importTask.Id;
        }
예제 #11
0
 private static void DoImport(ImportFromBasecamp obj)
 {
     try
     {
         obj.StartImport();
         obj.Status.Completed = true;
         NotifyClient.Instance.SendAboutImportComplite(obj.InitiatorId);
     }
     catch (Exception e)
     {
         obj.Status.LogError(ImportResource.ImportFailed, e);
         obj.Status.Error = e;
         obj.LogError("generic error", e);
     }
     finally
     {
         obj.Status.CompletedAt = DateTime.Now;
         lock (Completed)
         {
             Completed.Add(obj);
         }
     }
 }
예제 #12
0
 private static void DoImport(ImportFromBasecamp obj)
 {
     try
     {
         obj.StartImport();
         obj.Status.Completed = true;
         NotifyClient.Instance.SendAboutImportComplite(obj.InitiatorId);
     }
     catch (Exception e)
     {
         obj.Status.LogError(SettingsResource.ImportFailed, e);
         obj.Status.Error = e.GetType().ToString();
         obj.LogError("generic error", e);
     }
     finally
     {
         obj.Status.CompletedAt = DateTime.Now;
         lock (Completed)
         {
             Completed.Add(obj);
         }
     }
 }
예제 #13
0
 public bool Equals(ImportFromBasecamp other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id;
 }