private void OnCommandDeleteMemberGroup(object sender, System.EventArgs e)
        {
            IGroupsView    view      = base._view as IGroupsView;
            IGroupsModel   model     = base._model as IGroupsModel;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();
            string         email     = view.UserEmail;

            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread deletemembergroup = new Thread(() => {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    if (email.Contains(","))
                    {
                        char delimiter  = ',';
                        string[] emails = email.Split(delimiter);
                        foreach (string newEmail in emails)
                        {
                            this.DeleteMemberGroup(model, newEmail, presenter);
                        }
                    }
                    if (!email.Contains(","))
                    {
                        this.DeleteMemberGroup(model, email, presenter);
                    }

                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IGroupsView, IGroupsModel>(
                                ref view, model
                                );
                            // update result and update view.
                            view.RenderGroupList();
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                            presenter.UpdateProgressInfo("Completed.");
                        }, null);
                    }
                }
            });

            deletemembergroup.Start();
        }
        private void OnDataChanged(object sender, System.EventArgs e)
        {
            ITeamFoldersView  view  = base._view as ITeamFoldersView;
            ITeamFoldersModel model = base._model as ITeamFoldersModel;

            PresenterBase.SetModelPropertiesFromView <ITeamFoldersModel, ITeamFoldersView>(
                ref model, view
                );
        }
        protected override void Initialize()
        {
            IDataMigrationView  view  = base._view as IDataMigrationView;
            IDataMigrationModel model = base._model as IDataMigrationModel;

            PresenterBase.SetViewPropertiesFromModel <IDataMigrationView, IDataMigrationModel>(
                ref view, model
                );
        }
        private void OnDataChanged(object sender, System.EventArgs e)
        {
            IDataMigrationView  view  = base._view as IDataMigrationView;
            IDataMigrationModel model = base._model as IDataMigrationModel;

            PresenterBase.SetModelPropertiesFromView <IDataMigrationModel, IDataMigrationView>(
                ref model, view
                );
        }
        private void OnDataChanged(object sender, EventArgs e)
        {
            IDumpUserContentView  view  = base._view as IDumpUserContentView;
            IDumpUserContentModel model = base._model as IDumpUserContentModel;

            PresenterBase.SetModelPropertiesFromView <IDumpUserContentModel, IDumpUserContentView>(
                ref model, view
                );
        }
        private void OnCommandListMembers(object sender, EventArgs e)
        {
            IDumpUserContentView  view      = base._view as IDumpUserContentView;
            IDumpUserContentModel model     = base._model as IDumpUserContentModel;
            IMainPresenter        presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            // notify view to mark start of process
            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }

            // TODO: to improve stability, we will need to ensure to kill
            // thread when user exits application while thread is running for REST service call
            Thread memberSearch = new Thread(() => {
                if (string.IsNullOrEmpty(model.UserAccessToken))
                {
                    SyncContext.Post(delegate {
                        presenter.ShowErrorMessage(ErrorMessages.INVALID_TOKEN, ErrorMessages.DLG_DEFAULT_TITLE);
                        presenter.UpdateProgressInfo("");
                        presenter.ActivateSpinner(false);
                        presenter.EnableControl(true);
                    }, null);
                }
                else
                {
                    // perform search
                    this.SearchMembers(model, presenter);
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IDumpUserContentView, IDumpUserContentModel>(
                                ref view, model
                                );
                            view.RenderMembersSearchResult();
                            if (model.MemberList.Count > 0)
                            {
                                view.LazyInitializeContextMenu();
                                view.EnableContextMenuItems(true);
                                //view.EnableDumpControl(true);
                            }
                            presenter.UpdateProgressInfo("Completed");
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                        }, null);
                    }
                }
            });

            // start async search
            memberSearch.Start();
        }
        protected override void Initialize()
        {
            // read data from model
            ILegalView  view  = base._view as ILegalView;
            ILegalModel model = base._model as ILegalModel;

            PresenterBase.SetViewPropertiesFromModel <ILegalView, ILegalModel>(
                ref view, model
                );
        }
        private void OnCommandSetFolderSyncSetting(object sender, System.EventArgs e)
        {
            ITeamFoldersView  view      = base._view as ITeamFoldersView;
            ITeamFoldersModel model     = base._model as ITeamFoldersModel;
            IMainPresenter    presenter = SimpleResolver.Instance.Get <IMainPresenter>();
            TeamFoldersModel  teamModel = view.GetTeamFolderIds();
            bool syncSetting            = view.SyncSetting;

            if (SyncContext != null)
            {
                SyncContext.Post(delegate
                {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread setfoldersyncsetting = new Thread(() =>
            {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate
                    {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    foreach (TeamFoldersListViewItemModel lvItem in teamModel.TeamFolders)
                    {
                        this.SetDefaultSyncSetting(model, lvItem.TeamFolderId, syncSetting, presenter);
                    }
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <ITeamFoldersView, ITeamFoldersModel>(
                                ref view, model
                                );
                            // update result and update view.
                            view.RenderTeamFoldersList();
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                            //presenter.UpdateProgressInfo("Completed.");
                        }, null);
                    }
                }
            });

            setfoldersyncsetting.Start();
        }
Esempio n. 9
0
        protected override void Initialize()
        {
            ConfigurationManager.RefreshSection("configuration");
            FileUtil.ResetConfigMechanism();
            GetConfigSettings();

            ISettingsView  view  = base._view as ISettingsView;
            ISettingsModel model = base._model as ISettingsModel;

            PresenterBase.SetViewPropertiesFromModel <ISettingsView, ISettingsModel>(
                ref view, model
                );
        }
        protected override void Initialize()
        {
            ITeamFoldersView  view  = base._view as ITeamFoldersView;
            ITeamFoldersModel model = base._model as ITeamFoldersModel;

            PresenterBase.SetViewPropertiesFromModel <ITeamFoldersView, ITeamFoldersModel>(
                ref view, model
                );

            SyncContext.Post(delegate {
                view.RefreshAccessToken();
            }, null);
        }
        private void OnCommandCreateTeamFolder(object sender, System.EventArgs e)
        {
            ITeamFoldersView  view           = base._view as ITeamFoldersView;
            ITeamFoldersModel model          = base._model as ITeamFoldersModel;
            IMainPresenter    presenter      = SimpleResolver.Instance.Get <IMainPresenter>();
            string            teamFolderName = view.TeamFolderName;
            bool syncSetting = view.SyncSetting;

            if (SyncContext != null)
            {
                SyncContext.Post(delegate
                {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread createteamfolder = new Thread(() =>
            {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate
                    {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    this.CreateTeamFolder(model, teamFolderName, presenter);
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <ITeamFoldersView, ITeamFoldersModel>(
                                ref view, model
                                );
                            // update result and update view.
                            view.RenderTeamFoldersList();
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                            presenter.UpdateProgressInfo("Completed.");
                        }, null);
                    }
                }
            });

            createteamfolder.Start();
        }
Esempio n. 12
0
        private void OnCommandDownloadPaper(object sender, System.EventArgs e)
        {
            IPaperView     view      = base._view as IPaperView;
            IPaperModel    model     = base._model as IPaperModel;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            if (SyncContext != null)
            {
                SyncContext.Post(delegate
                {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread downloadpaperdocs = new Thread(() =>
            {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate
                    {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    this.DownloadPaperDocs(model, view, presenter);
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IPaperView, IPaperModel>(
                                ref view, model
                                );
                            // update result and update view.
                            view.RenderPaperList();
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                        }, null);
                    }
                }
            });

            downloadpaperdocs.Start();
        }
Esempio n. 13
0
        protected override void Initialize()
        {
            // read data from model
            ITextSearchView  view  = base._view as ITextSearchView;
            ITextSearchModel model = base._model as ITextSearchModel;

            PresenterBase.SetViewPropertiesFromModel <ITextSearchView, ITextSearchModel>(
                ref view, model
                );

            SyncContext.Post(delegate {
                view.RefreshAccessToken();
                view.RenderSearchModeSelections();
                view.SetSearchResultLimit(model.SearchResultsLimit);
            }, null);
        }
        private void OnCommandCreateGroup(object sender, System.EventArgs e)
        {
            IGroupsView    view      = base._view as IGroupsView;
            IGroupsModel   model     = base._model as IGroupsModel;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();
            string         groupName = view.GroupName;
            string         groupType = view.GroupType;

            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread creategroup = new Thread(() => {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    this.CreateGroup(model, groupName, groupType, presenter);
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IGroupsView, IGroupsModel>(
                                ref view, model
                                );
                            // update result and update view.
                            view.RenderGroupList();
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                        }, null);
                    }
                }
            });

            creategroup.Start();
        }
        protected override void Initialize()
        {
            // read data from model
            IDumpUserContentView  view  = base._view as IDumpUserContentView;
            IDumpUserContentModel model = base._model as IDumpUserContentModel;

            PresenterBase.SetViewPropertiesFromModel <IDumpUserContentView, IDumpUserContentModel>(
                ref view, model
                );

            ContextMenuItemText = new string[]
            {
                LIST_FILES
            };
            view.SetContextMenuItemText(ContextMenuItemText);
            SyncContext.Post(delegate {
                view.RefreshAccessToken();
            }, null);
        }
Esempio n. 16
0
        private void OnCommandClear(object sender, EventArgs e)
        {
            ITextSearchModel model     = base._model as ITextSearchModel;
            ITextSearchView  view      = base._view as ITextSearchView;
            IMainPresenter   presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            model.QueryString        = string.Empty;
            model.SelectedSearchMode = TextSearchModel.TextSearchMode.Filename_only.ToString();
            model.SearchResultsLimit = ApplicationResource.SearchDefaultLimit;
            model.MemberList         = new List <MemberListViewItemModel>();

            PresenterBase.SetViewPropertiesFromModel <ITextSearchView, ITextSearchModel>(
                ref view, model
                );
            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    view.RenderComponents();
                }, null);
            }
        }
Esempio n. 17
0
        private void OnCommandApplySettings(object sender, System.EventArgs e)
        {
            ISettingsModel model     = base._model as ISettingsModel;
            ISettingsView  view      = base._view as ISettingsView;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            PresenterBase.SetModelPropertiesFromView <ISettingsModel, ISettingsView>(
                ref model, view
                );
            UpdateConfigSettings();

            // we will probably don't need to broadcast changes,
            // as previous result becomes no longere meaningful upon update of token or API urls.
            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    view.HideView();
                    presenter.UpdateProgressInfo("Settings Updated");
                    Application.Restart();
                }, null);
            }
        }
        private void OnCommandExportContentExcel(object sender, EventArgs e)
        {
            // Export to Excel
            IDataMigrationView  view  = base._view as IDataMigrationView;
            IDataMigrationModel model = base._model as IDataMigrationModel;

            PresenterBase.SetModelPropertiesFromView <IDataMigrationModel, IDataMigrationView>(
                ref model, view
                );
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            try
            {
                if (SyncContext != null)
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(false);
                        presenter.ActivateSpinner(true);
                        presenter.UpdateProgressInfo("Preparing Report...");
                    }, null);
                }

                FileInfo fileInfo = new FileInfo(model.OutputFileName);
                if (Directory.Exists(fileInfo.DirectoryName))
                {
                    Thread writeReportExcel = new Thread(() => {
                        int total = model.Contents.Count;
                        //set max rows per sheet to 1 million. Actual number Excel pukes on is anything over 1,048,576
                        int maxRowsPerSheet = 1000000;
                        int sheetCount      = 1;
                        int modelStartRow   = 0;
                        int modelEndRow     = 1;
                        int totalRowsLeft   = 0;
                        bool complete       = false;

                        //get inital rows left
                        totalRowsLeft = model.Contents.Count - maxRowsPerSheet;

                        //round up for number of sheets based on rowcount
                        int totalSheets = Convert.ToInt32(Math.Ceiling((double)total / (double)maxRowsPerSheet));

                        Excel.Application xlApp = new Excel.Application();
                        xlApp.DisplayAlerts     = false;

                        //Give error if Excel not installed on system
                        if (xlApp == null)
                        {
                            SyncContext.Post(delegate
                            {
                                presenter.EnableControl(true);
                                presenter.ActivateSpinner(false);
                                presenter.UpdateProgressInfo(ErrorMessages.EXCEL_MISSING);
                            }, null);
                            return;
                        }

                        Excel.Workbook xlWorkBook;
                        Excel.Worksheet xlWorkSheet = null;
                        object misValue             = Missing.Value;

                        xlWorkBook = xlApp.Workbooks.Add(misValue);

                        //need code to add extra worksheets, based on how many rows we have above
                        Excel.Sheets worksheets = xlWorkBook.Worksheets;

                        while (!complete)
                        {
                            while (sheetCount <= totalSheets)
                            {
                                var xlNewSheet  = (Excel.Worksheet)worksheets.Add(worksheets[sheetCount], Type.Missing, Type.Missing, Type.Missing);
                                xlNewSheet.Name = sheetCount.ToString();

                                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(sheetCount);

                                //write headers
                                xlWorkSheet.Cells[1, 1]  = "Owner Name";
                                xlWorkSheet.Cells[1, 2]  = "Owner Login";
                                xlWorkSheet.Cells[1, 3]  = "Path";
                                xlWorkSheet.Cells[1, 4]  = "Path ID";
                                xlWorkSheet.Cells[1, 5]  = "Item Name";
                                xlWorkSheet.Cells[1, 6]  = "Item ID";
                                xlWorkSheet.Cells[1, 7]  = "Item Type";
                                xlWorkSheet.Cells[1, 8]  = "Size";
                                xlWorkSheet.Cells[1, 9]  = "Created";
                                xlWorkSheet.Cells[1, 10] = "Last Modified";
                                xlWorkSheet.Cells[1, 11] = "Uploaded";

                                int endRow = 0;
                                //over 1 million rows, setting values for output to Excel sheets
                                if (totalRowsLeft > 0 && totalRowsLeft > maxRowsPerSheet)
                                {
                                    endRow = endRow + maxRowsPerSheet;
                                }
                                if (totalRowsLeft > 0 && totalRowsLeft < maxRowsPerSheet)
                                {
                                    endRow = endRow + totalRowsLeft;
                                }
                                modelEndRow = modelEndRow + endRow;

                                if (modelEndRow < model.Contents.Count)
                                {
                                    modelEndRow--;
                                }
                                if (modelEndRow > model.Contents.Count)
                                {
                                    modelEndRow = model.Contents.Count;
                                }
                                //we only need one sheet
                                if (totalRowsLeft < 0)
                                {
                                    modelEndRow = model.Contents.Count;
                                }
                                //start at 1 for each sheet so we can increment past header row
                                int rowCount = 1;

                                for (int i2 = modelStartRow; i2 < modelEndRow; i2++)
                                {
                                    ContentDisplayListViewItemModel lvItem = model.Contents[i2];
                                    rowCount++;
                                    endRow++;

                                    xlWorkSheet.Cells[rowCount, 1]  = (!string.IsNullOrEmpty(lvItem.OwnerName) ? lvItem.OwnerName : "");
                                    xlWorkSheet.Cells[rowCount, 2]  = (lvItem.Email);
                                    xlWorkSheet.Cells[rowCount, 3]  = (lvItem.ItemPathDisplay);
                                    xlWorkSheet.Cells[rowCount, 4]  = (!string.IsNullOrEmpty(lvItem.ItemPathId) ? lvItem.ItemPathId : "");
                                    xlWorkSheet.Cells[rowCount, 5]  = (lvItem.ItemName);
                                    xlWorkSheet.Cells[rowCount, 6]  = (!string.IsNullOrEmpty(lvItem.ItemId) ? lvItem.ItemId : "");
                                    xlWorkSheet.Cells[rowCount, 7]  = (lvItem.ItemType);
                                    xlWorkSheet.Cells[rowCount, 8]  = (!string.IsNullOrEmpty(lvItem.ItemSize) ? lvItem.ItemSize : "");
                                    xlWorkSheet.Cells[rowCount, 9]  = (!string.IsNullOrEmpty(lvItem.Created) ? lvItem.Created : "");
                                    xlWorkSheet.Cells[rowCount, 10] = (!string.IsNullOrEmpty(lvItem.LastModified) ? lvItem.LastModified : "");
                                    xlWorkSheet.Cells[rowCount, 11] = (!string.IsNullOrEmpty(lvItem.Uploaded) ? lvItem.Uploaded : "");

                                    if (SyncContext != null)
                                    {
                                        SyncContext.Post(delegate
                                        {
                                            presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (i2 + 1), total));
                                        }, null);
                                    }
                                }
                                //move one row count to make up for the header row
                                modelEndRow++;

                                modelStartRow = modelEndRow;
                                modelStartRow--;
                                sheetCount++;
                                //are we done?
                                if (modelEndRow >= model.Contents.Count)
                                {
                                    complete = true;
                                }
                            }
                        }
                        //delete default sheet and save to output file name specified in UI
                        xlWorkBook.Sheets["Sheet1"].Delete();
                        xlWorkBook.SaveAs(model.OutputFileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue,
                                          Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                        xlWorkBook.Close(true, misValue, misValue);
                        xlApp.Quit();

                        //release all resources
                        Marshal.ReleaseComObject(xlWorkBook);
                        Marshal.ReleaseComObject(xlApp);
                        Marshal.ReleaseComObject(xlWorkSheet);

                        if (SyncContext != null)
                        {
                            SyncContext.Post(delegate {
                                presenter.EnableControl(true);
                                presenter.ActivateSpinner(false);
                                presenter.UpdateProgressInfo("Completed");
                            }, null);
                        }
                    });
                    writeReportExcel.Start();
                }
                else
                {
                    throw new InvalidDataException(ErrorMessages.INVALID_EXPORT_FOLDER);
                }
            }
            catch (Exception ex)
            {
                if (SyncContext != null)
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("Completed with exception: " + ex.Message);
                    }, null);
                }
            }
        }
        //need work
        private void OnCommandExportGroupPerms(object sender, System.EventArgs e)
        {
            IGroupsView    view      = base._view as IGroupsView;
            IGroupsModel   model     = base._model as IGroupsModel;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread exportgroupperms = new Thread(() => {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    //need to get groups checked then get shared folders for each
                    this.ExportGroups(model, presenter);
                    this.ExportGroupPerms(model, presenter);

                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IGroupsView, IGroupsModel>(
                                ref view, model
                                );
                            string sPath = string.Empty;
                            if (model.GroupPerms.Count > 0)
                            {
                                //create CSV file in My Documents folder
                                sPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GroupPermsExport.csv";
                                CsvConfiguration config = new CsvConfiguration()
                                {
                                    HasHeaderRecord = true,
                                    Delimiter       = ",",
                                    Encoding        = System.Text.Encoding.UTF8
                                };
                                config.RegisterClassMap(new GroupPermsHeaderMap());
                                int total = model.GroupPerms.Count;
                                using (CsvWriter writer = new CsvWriter(new StreamWriter(sPath), config))
                                {
                                    writer.WriteHeader <GroupPermsHeaderRecord>();
                                    int count = 0;
                                    foreach (var item in model.GroupPerms)
                                    {
                                        writer.WriteField <string>(item.GroupName);
                                        writer.WriteField <string>(item.GroupId);
                                        writer.WriteField <string>(item.GroupManagementType);
                                        writer.WriteField <string>(item.GroupType);
                                        writer.WriteField <string>(item.SharedFolderName);
                                        writer.WriteField <string>(item.SharedFolderId);
                                        writer.WriteField <string>(item.IsMember);
                                        writer.WriteField <string>(item.IsOwner);
                                        writer.WriteField <string>(item.AccessType);
                                        writer.WriteField <string>(item.IsInherited);
                                        writer.WriteField <string>(item.IsTeamFolder);
                                        writer.WriteField <string>(item.IsInsideTeamFolder);
                                        count++;
                                        if (SyncContext != null)
                                        {
                                            SyncContext.Post(delegate
                                            {
                                                presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (count), total));
                                            }, null);
                                        }
                                        writer.NextRecord();
                                    }
                                }
                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate
                                    {
                                        presenter.UpdateProgressInfo("Completed. Exported file located at " + sPath);
                                    }, null);
                                }
                            }
                            if (model.GroupPerms.Count == 0)
                            {
                                presenter.UpdateProgressInfo("No groups were selected to export.");
                            }
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                        }, null);
                    }
                }
            });

            exportgroupperms.Start();
        }
        private void OnCommandExportContent(object sender, EventArgs e)
        {
            // Export to CSV
            IDataMigrationView  view  = base._view as IDataMigrationView;
            IDataMigrationModel model = base._model as IDataMigrationModel;

            PresenterBase.SetModelPropertiesFromView <IDataMigrationModel, IDataMigrationView>(
                ref model, view
                );
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            try
            {
                if (SyncContext != null)
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(false);
                        presenter.ActivateSpinner(true);
                        presenter.UpdateProgressInfo("Preparing Report...");
                    }, null);
                }

                FileInfo fileInfo = new FileInfo(model.OutputFileName);
                if (Directory.Exists(fileInfo.DirectoryName))
                {
                    Thread writeReport = new Thread(() => {
                        CsvConfiguration config = new CsvConfiguration()
                        {
                            HasHeaderRecord = true,
                            Delimiter       = ",",
                            Encoding        = System.Text.Encoding.UTF8
                        };
                        config.RegisterClassMap(new DataMigrationHeaderMap());
                        int total = model.Contents.Count;
                        using (CsvWriter writer = new CsvWriter(new StreamWriter(model.OutputFileName), config))
                        {
                            writer.WriteHeader <DataMigrationHeaderRecord>();
                            for (int i = 0; i < model.Contents.Count; i++)
                            {
                                ContentDisplayListViewItemModel lvItem = model.Contents[i];
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.OwnerName) ? lvItem.OwnerName : "");
                                writer.WriteField <string>(lvItem.Email);
                                writer.WriteField <string>(lvItem.ItemPathDisplay);
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.ItemPathId) ? lvItem.ItemPathId : "");
                                writer.WriteField <string>(lvItem.ItemName);
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.ItemId) ? lvItem.ItemId : "");
                                writer.WriteField <string>(lvItem.ItemType);
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.ItemSize) ? lvItem.ItemSize : "");
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.Created) ? lvItem.Created : "");
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.LastModified) ? lvItem.LastModified : "");
                                writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.Uploaded) ? lvItem.Uploaded : "");
                                writer.NextRecord();

                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate
                                    {
                                        presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (i + 1), total));
                                    }, null);
                                }
                            }
                        }
                        if (SyncContext != null)
                        {
                            SyncContext.Post(delegate {
                                presenter.EnableControl(true);
                                presenter.ActivateSpinner(false);
                                presenter.UpdateProgressInfo("Completed");
                            }, null);
                        }
                    });
                    writeReport.Start();
                }
                else
                {
                    throw new InvalidDataException(ErrorMessages.INVALID_EXPORT_FOLDER);
                }
            }
            catch (Exception ex)
            {
                if (SyncContext != null)
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("Completed with exception: " + ex.Message);
                    }, null);
                }
            }
        }
        private void OnCommandDisplayContent(object sender, System.EventArgs e)
        {
            IDataMigrationView  view  = base._view as IDataMigrationView;
            IDataMigrationModel model = base._model as IDataMigrationModel;
            IList <ContentDisplayListViewItemModel> items = model.Contents;

            if (items != null)
            {
                IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

                // lock UI
                if (SyncContext != null)
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(false);
                        presenter.ActivateSpinner(true);
                        presenter.UpdateProgressInfo("Searching...");
                    }, null);
                }

                Thread search = new Thread(() => {
                    TimerUtils util = new TimerUtils();
                    util.Start();
                    if (string.IsNullOrEmpty(model.AccessToken))
                    {
                        presenter.ShowErrorMessage(ErrorMessages.INVALID_TOKEN, ErrorMessages.DLG_DEFAULT_TITLE);
                        presenter.UpdateProgressInfo("");
                        presenter.ActivateSpinner(false);
                        presenter.EnableControl(true);
                    }
                    else
                    {
                        MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);
                        // search all owners first.
                        IList <TeamListViewItemModel> owners = SearchOwner(model, presenter);
                        model.Contents.Clear(); // clear existing contents
                        Parallel.ForEach(owners, (owner) =>
                        {
                            if (SyncContext != null)
                            {
                                SyncContext.Post(delegate
                                {
                                    presenter.UpdateProgressInfo(string.Format("Retrieving Owner's Content: {0}", owner.Email));
                                }, null);
                            }
                            SearchItems(service, owner, model, presenter);
                        });
                        // compute folder size.
                        if (SyncContext != null)
                        {
                            SyncContext.Post(delegate
                            {
                                presenter.UpdateProgressInfo(string.Format("Sorting Data..."));
                            }, null);
                        }
                        // sort by email then by folder path
                        model.Contents = model.Contents.OrderBy(s => s.Email).ThenBy(s => s.ItemPathDisplay).ToList();
                        ContentDisplayListViewItemModel currentFolderSelected = null;
                        foreach (ContentDisplayListViewItemModel lvItem in model.Contents)
                        {
                            if (lvItem.ItemType.ToLower().Equals("folder"))
                            {
                                if (currentFolderSelected != null)
                                {
                                    // had previously selected folder.
                                    currentFolderSelected.ItemSize = FileUtil.FormatFileSize(currentFolderSelected.ItemSizeByte);
                                    if (SyncContext != null)
                                    {
                                        SyncContext.Post(delegate {
                                            presenter.UpdateProgressInfo(string.Format("Calculating Folder Size: {0}", currentFolderSelected.ItemName));
                                        }, null);
                                    }
                                }
                                currentFolderSelected = lvItem;
                            }
                            else if (lvItem.ItemType.ToLower().Equals("file"))
                            {
                                if (currentFolderSelected != null)
                                {
                                    currentFolderSelected.ItemSizeByte += lvItem.ItemSizeByte;
                                }
                            }
                        }
                    }
                    if (SyncContext != null)
                    {
                        TimeSpan diff = util.Stop();

                        SyncContext.Post(delegate {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IDataMigrationView, IDataMigrationModel>(
                                ref view, model
                                );
                            view.RenderContentSearchResult();
                            view.EnableExportControl(true);
                            presenter.UpdateProgressInfo(
                                string.Format("Completed. Total Content Count: {0} Elapsed Time: {1}", model.Contents.Count, TimerUtils.ToTimeStamp(diff))
                                );
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                        }, null);
                    }
                });
                search.Start();
            }
        }
Esempio n. 22
0
        private void OnCommandExportPaper(object sender, System.EventArgs e)
        {
            IPaperView     view      = base._view as IPaperView;
            IPaperModel    model     = base._model as IPaperModel;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread exportpapertocsv = new Thread(() => {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            PresenterBase.SetViewPropertiesFromModel <IPaperView, IPaperModel>(
                                ref view, model
                                );
                            string sPath = string.Empty;

                            if (model.Paper.Count > 0)
                            {
                                //create CSV file in My Documents folder
                                sPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PaperDocExport.csv";
                                CsvConfiguration config = new CsvConfiguration()
                                {
                                    HasHeaderRecord = true,
                                    Delimiter       = ",",
                                    Encoding        = System.Text.Encoding.UTF8
                                };
                                config.RegisterClassMap(new PaperHeaderMap());
                                int total = model.Paper.Count;
                                using (CsvWriter writer = new CsvWriter(new StreamWriter(sPath), config))
                                {
                                    writer.WriteHeader <PaperHeaderRecord>();
                                    int count = 0;
                                    foreach (var item in model.Paper)
                                    {
                                        writer.WriteField <string>(item.PaperName);
                                        writer.WriteField <string>(item.PaperId);
                                        writer.WriteField <string>(item.FolderPath);
                                        writer.WriteField <string>(item.Status);
                                        writer.WriteField <string>(item.Owner);
                                        writer.WriteField <string>(item.CreatedDate.ToString());
                                        writer.WriteField <string>(item.LastUpdatedDate.ToString());
                                        writer.WriteField <string>(item.LastEditor);
                                        writer.WriteField <string>(item.Revision.ToString());
                                        count++;
                                        if (SyncContext != null)
                                        {
                                            SyncContext.Post(delegate
                                            {
                                                presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (count), total));
                                            }, null);
                                        }
                                        writer.NextRecord();
                                    }
                                }
                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate
                                    {
                                        presenter.UpdateProgressInfo("Completed. Exported file located at " + sPath);
                                    }, null);
                                }
                            }
                            if (model.Paper.Count == 0)
                            {
                                presenter.UpdateProgressInfo("No Paper docs were chosen to export.");
                            }
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                        }, null);
                    }
                }
            });

            exportpapertocsv.Start();
        }
        private void OnCommandContextMenuClicked(object sender, Common.DataExchange.DataUpdatedEventArgs e)
        {
            MenuItem selectedContextMenuItem = sender as MenuItem;

            if (selectedContextMenuItem != null)
            {
                if (selectedContextMenuItem.Text.ToLower().Equals(LIST_FILES, StringComparison.CurrentCultureIgnoreCase))
                {
                    if (e.Data != null)
                    {
                        IDumpUserContentView          view            = base._view as IDumpUserContentView;
                        IDumpUserContentModel         model           = base._model as IDumpUserContentModel;
                        IMainPresenter                presenter       = SimpleResolver.Instance.Get <IMainPresenter>();
                        ArrayList                     list            = (ArrayList)e.Data;
                        IList <TeamListViewItemModel> selectedLvItems = list.Cast <TeamListViewItemModel>().ToList();
                        if (selectedLvItems != null && selectedLvItems.Count > 0)
                        {
                            // lock UI
                            if (SyncContext != null)
                            {
                                SyncContext.Post(delegate
                                {
                                    presenter.EnableControl(false);
                                    presenter.ActivateSpinner(true);
                                    presenter.UpdateProgressInfo("Preparing Search...");
                                }, null);
                            }

                            Thread search = new Thread(() =>
                            {
                                if (string.IsNullOrEmpty(model.UserAccessToken))
                                {
                                    SyncContext.Post(delegate
                                    {
                                        presenter.ShowErrorMessage(ErrorMessages.INVALID_TOKEN, ErrorMessages.DLG_DEFAULT_TITLE);
                                        presenter.UpdateProgressInfo("");
                                        presenter.ActivateSpinner(false);
                                        presenter.EnableControl(true);
                                    }, null);
                                }
                                else
                                {
                                    MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);
                                    model.MemberList.Clear();
                                    foreach (TeamListViewItemModel item in selectedLvItems)
                                    {
                                        SearchFiles(service, item, model, presenter);
                                    }

                                    // complete.
                                    if (SyncContext != null)
                                    {
                                        SyncContext.Post(delegate
                                        {
                                            // update result and update view.
                                            PresenterBase.SetViewPropertiesFromModel <IDumpUserContentView, IDumpUserContentModel>(
                                                ref view, model
                                                );
                                            //view.ShowGroups(true);
                                            view.RenderMembersFileSearchResult();
                                            view.EnableDumpControl(true);
                                            presenter.UpdateProgressInfo("Completed");
                                            presenter.ActivateSpinner(false);
                                            presenter.EnableControl(true);
                                        }, null);
                                    }
                                }
                            });
                            search.Start();
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        private void OnCommandGetPaper(object sender, System.EventArgs e)
        {
            IPaperView     view      = base._view as IPaperView;
            IPaperModel    model     = base._model as IPaperModel;
            IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

            if (SyncContext != null)
            {
                SyncContext.Post(delegate {
                    presenter.EnableControl(false);
                    presenter.ActivateSpinner(true);
                    presenter.UpdateProgressInfo("Processing...");
                }, null);
            }
            Thread getpaperdocs = new Thread(() => {
                if (string.IsNullOrEmpty(model.AccessToken))
                {
                    SyncContext.Post(delegate {
                        presenter.EnableControl(true);
                        presenter.ActivateSpinner(false);
                        presenter.UpdateProgressInfo("");
                    }, null);
                }
                else
                {
                    // clear existing data first
                    model.Paper.Clear();

                    //get members first
                    IList <TeamListViewItemModel> members = SearchOwners(model, presenter);
                    //get Paper Ids
                    Parallel.ForEach(members, (member) =>
                    {
                        if (SyncContext != null)
                        {
                            SyncContext.Post(delegate
                            {
                                presenter.UpdateProgressInfo(string.Format("Retrieving member's Paper docs: {0}", member.Email));
                            }, null);
                        }
                        IList <PaperListViewItemModel> docIds = new List <PaperListViewItemModel>();

                        docIds = this.GetPaperDocs(model, presenter, member);

                        //get metadata from ids
                        foreach (PaperListViewItemModel item in docIds)
                        {
                            this.GetPaperMetadata(model, presenter, item.PaperId, item.MemberId);
                        }
                    });
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            presenter.UpdateProgressInfo(string.Format("Sorting Paper docs..."));
                        }, null);
                    }
                    // sort by email then by folder path
                    model.Paper = model.Paper.OrderBy(s => s.Owner).ThenBy(s => s.LastUpdatedDate).ToList();
                    if (SyncContext != null)
                    {
                        SyncContext.Post(delegate
                        {
                            // update result and update view.
                            PresenterBase.SetViewPropertiesFromModel <IPaperView, IPaperModel>(
                                ref view, model
                                );
                            // update result and update view.
                            view.RenderPaperList();
                            presenter.ActivateSpinner(false);
                            presenter.EnableControl(true);
                            presenter.UpdateProgressInfo("Paper doc list completed. Total Docs [" + model.Paper.Count.ToString() + "]");
                        }, null);
                    }
                }
            });

            getpaperdocs.Start();
        }