Exemple #1
0
        public static void ImportUsers(Guid organizationId, AppsService service, out int totalCount, out int failedCount)
        {
            totalCount  = 0;
            failedCount = 0;

            if (service == null)
            {
                return;
            }

            UserFeed userFeed = service.RetrieveAllUsers();

            if (userFeed == null)
            {
                return;
            }

            totalCount = userFeed.Entries.Count;
            for (int i = 0; i < totalCount; i++)
            {
                try
                {
                    UserEntry userEntry = userFeed.Entries[i] as UserEntry;
                    ImportUser(userEntry, organizationId, service.Domain);
                }
                catch
                {
                    failedCount++;
                }
            }
        }
        protected void lbStep1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(ddlDomains.SelectedValue))
            {
                try
                {
                    AppsService service  = new AppsService(ddlDomains.SelectedValue, UserContext.Current.Organization.GoogleAdminAuthToken);
                    UserFeed    userFeed = service.RetrieveAllUsers();

                    DataTable dt = new DataTable();
                    dt.Columns.Add(Resources.GoogleIntegrationControl_UsernameColumn_HeaderText, typeof(string));
                    dt.Columns.Add(Resources.GoogleIntegrationControl_FirstNameColumn_HeaderText, typeof(string));
                    dt.Columns.Add(Resources.GoogleIntegrationControl_LastNameColumn_HeaderText, typeof(string));
                    dt.Columns.Add(Resources.GoogleIntegrationControl_AdminColumn_HeaderText, typeof(string));

                    for (int i = 0; i < userFeed.Entries.Count; i++)
                    {
                        UserEntry userEntry = userFeed.Entries[i] as UserEntry;
                        dt.Rows.Add(userEntry.Login.UserName, userEntry.Name.GivenName, userEntry.Name.FamilyName, userEntry.Login.Admin ? Resources.GoogleIntegrationControl_AdminColumn_Value : string.Empty);
                    }

                    gvStep1Results.DataSource = dt;
                    gvStep1Results.DataBind();

                    mvStep1.SetActiveView(vwStep1Result);

                    lbImportUsers.Text    = Resources.GoogleIntegrationControl_ImportUsers_LinkButton_Text;
                    lbImportUsers.Visible = lbImportUsers.Enabled = dt.Rows.Count > 0;
                }
                catch (AppsException a)
                {
                    lblStep1Error.Text = string.Format(CultureInfo.CurrentCulture, Resources.GoogleIntegrationControl_GoogleAppsError_Text, a.ErrorCode, a.InvalidInput, a.Reason);
                    mvStep1.SetActiveView(vwStep1Error);
                }
                catch (Exception ex)
                {
                    ShowError(ex, lblStep1Error, mvStep1, vwStep1Error);
                }
            }
            else
            {
                lblStep1Error.Text = Resources.GoogleIntegrationControl_DomainMisingError_Text;
                mvStep1.SetActiveView(vwStep1Error);
            }
        }
Exemple #3
0
        private static void UserOperations(AppsService service)
        {
            // Create a new user.
            UserEntry insertedEntry = service.CreateUser(testUserName, "Jane",
                                                         "Doe", "testuser-password");

            Console.WriteLine("Created new user '{0}'", insertedEntry.Login.UserName);

            // Suspend the user.
            UserEntry suspendedEntry = service.SuspendUser(testUserName);

            Console.WriteLine("Suspended account for {0}", suspendedEntry.Login.UserName);

            // Restore the user.
            UserEntry restoredEntry = service.RestoreUser(testUserName);

            Console.WriteLine("Restored user {0}", restoredEntry.Login.UserName);

            // Query for a single user.
            UserEntry entry = service.RetrieveUser(testUserName);

            Console.WriteLine("Retrieved user {0}", entry.Login.UserName);

            // Query for a page of users.
            UserFeed feed = service.RetrievePageOfUsers(testUserName);

            entry = feed.Entries[0] as UserEntry;
            Console.WriteLine("Retrieved page of {0} users, beginning with '{1}'", feed.Entries.Count,
                              entry.Login.UserName);

            // Query for all users.
            feed  = service.RetrieveAllUsers();
            entry = feed.Entries[0] as UserEntry;
            Console.WriteLine("Retrieved all {0} users in the domain, beginning with '{1}'",
                              feed.Entries.Count, entry.Login.UserName);

            // Update the user's given name.
            restoredEntry.Name.GivenName = "John";
            UserEntry updatedEntry = service.UpdateUser(entry);

            Console.WriteLine("Updated user with new given name '{0}'", updatedEntry.Name.GivenName);
        }
Exemple #4
0
        /// <summary>
        /// ....
        /// </summary>
        private int ExecInternalApps()
        {
            // Retrieve user list
            List <String> usernames = new List <string>();

            try
            {
                if (_config.appsOnlyOAuth)
                {
                    GOAuthRequestFactory reqF = new GOAuthRequestFactory("apps", "GDocBackup");
                    reqF.ConsumerKey    = _config.appsDomain;
                    reqF.ConsumerSecret = _config.appsOAuthSecret;
                    UserService userService = new UserService("GDocBackup");
                    userService.RequestFactory = reqF;
                    UserQuery query     = new UserQuery(_config.appsDomain, true);
                    UserFeed  usersFeed = userService.Query(query);
                    foreach (UserEntry entry in usersFeed.Entries)
                    {
                        usernames.Add(entry.Login.UserName);
                    }
                }
                else
                {
                    string      domainAdminUsername = this.BuildDomainUserFullName(_config.userName);
                    AppsService appsServ            = new AppsService(_config.appsDomain, domainAdminUsername, _config.password);
                    UserFeed    usersFeed           = appsServ.RetrieveAllUsers();
                    foreach (UserEntry entry in usersFeed.Entries)
                    {
                        usernames.Add(entry.Login.UserName);
                    }
                }

                DoFeedback("Users: (" + usernames.Count + ")");
                foreach (string x in usernames)
                {
                    DoFeedback(" > " + x);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error retrieving users list", ex);
            }

            // Build output folders, one for each user
            foreach (string username in usernames)
            {
                string x = Path.Combine(_config.outDir, username);
                if (!Directory.Exists(x))
                {
                    Directory.CreateDirectory(x);
                }
            }

            // Do work for each user!
            int errCount = 0;

            _totalAppUsers = usernames.Count;
            for (int i = 0; i < usernames.Count; i++)
            {
                _currentAppsUserIndex = i;
                try
                {
                    errCount += this.ExecBackupSingleUser(usernames[i]);
                }
                catch (Exception ex)
                {
                    errCount++;
                    DoFeedback("ERROR: " + ex.ToString(), 0);
                }
            }

            return(errCount);
        }
Exemple #5
0
        public static void ReplicateAllOrganizations()
        {
            int failed  = 0;
            int success = 0;

            DateTime startDate = DateTime.UtcNow;

            WriteResponseLog(string.Format("GoogleReplicator started replication process at {0}.", startDate));

            try
            {
                OrganizationCollection organizationCollection = OrganizationProvider.GetOrganizations(false, false);

                foreach (Organization org in organizationCollection)
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(org.GoogleAdminAuthToken))
                        {
                            var domains = EmailSuffixProvider.GetEmailSuffixesList(org.OrganizationId);

                            if (domains != null)
                            {
                                WriteResponseLog(string.Format("Organization '{0}' is setup for Google Replication and has {1} Google domains.", org.Name, domains.Count));

                                foreach (string domain in domains)
                                {
                                    bool isSuccess = false;

                                    try
                                    {
                                        WriteResponseLog(string.Format("Receiving users of Organization '{0}' from Google domain '{1}'.", org.Name, domain));

                                        AppsService service  = new AppsService(domain, org.GoogleAdminAuthToken);
                                        UserFeed    userFeed = service.RetrieveAllUsers();

                                        if (userFeed != null && userFeed.Entries != null)
                                        {
                                            int      totalUsers  = userFeed.Entries.Count;
                                            int      failedUsers = 0;
                                            DateTime start       = DateTime.UtcNow;
                                            WriteResponseLog(string.Format("Received {0} users from Google.", totalUsers));
                                            WriteResponseLog(string.Format("Replication for Organization '{0}' is started at {1}.", org.Name, start));

                                            totalUsers = userFeed.Entries.Count;
                                            for (int i = 0; i < totalUsers; i++)
                                            {
                                                UserEntry userEntry = userFeed.Entries[i] as UserEntry;
                                                try
                                                {
                                                    GoogleProvider.ImportUser(userEntry, org.OrganizationId, service.Domain);
                                                }
                                                catch (Exception ex)
                                                {
                                                    failedUsers++;
                                                    WriteResponseLog(string.Format("Replication failed for Organization: {0}; Google domain: {1}; UserName: {2}. Error message: {3}.", org.Name, domain, userEntry.Login.UserName, ex.Message));
                                                    WriteResponseLog(string.Format("Full error: {0}.", ex.ToString()));
                                                }
                                            }

                                            DateTime end = DateTime.UtcNow;
                                            WriteResponseLog(string.Format("Replication for Organization '{0}' is finished at {1}. Replication takes {2} minutes.", org.Name, end, Math.Round((end - start).TotalMinutes, TIME_ROUND_DIGITS)));
                                            WriteResponseLog(string.Format("Number of successfully replicated users: {0}.", totalUsers - failedUsers));
                                            WriteResponseLog(string.Format("Number of not successfully replicated users: {0}.", failedUsers));
                                            isSuccess = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        WriteResponseLog(string.Format("GoogleReplicator replication process is failed for Organization '{0}' for Google domain '{1}'. Error message: {2}.", org.Name, domain, ex.Message));
                                        WriteResponseLog(string.Format("Full error: {0}.", ex.ToString()));
                                    }

                                    if (!isSuccess)
                                    {
                                        failed++;
                                    }
                                    else
                                    {
                                        success++;
                                    }
                                }
                            }
                            else
                            {
                                WriteResponseLog(string.Format("Organization '{0}' is not configured for Google replication. Google domain is missing.", org.Name));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        failed++;
                        WriteResponseLog(string.Format("GoogleReplicator replication process failed for Organization '{0}'. Error: {1}.", org.Name, ex.ToString()));
                    }
                }
            }
            catch (Exception ex)
            {
                WriteResponseLog(string.Format("GoogleReplicator error: {0}.", ex.ToString()));
            }

            DateTime endDate = DateTime.UtcNow;

            WriteResponseLog(string.Format("GoogleReplicator finished replication process at {0}. Process was run for {1} minutes.", endDate, Math.Round((endDate - startDate).TotalMinutes, TIME_ROUND_DIGITS)));
            WriteResponseLog(string.Format("Number of successful replications: {0}.", success));
            WriteResponseLog(string.Format("Number of failed replications: {0}.", failed));
        }