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
                );
        }
        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 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
                );
        }
Пример #4
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);
                }
            }
        }
        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);
                }
            }
        }