public static List <ImportExportOptions> ValidateImportFile(string filePath)
        {
            if (!Path.GetExtension(filePath).Equals(ImportExportFileExtension))
            {
                throw new ImportFileNotValidException();
            }

            List <ImportExportOptions> importOptions = new List <ImportExportOptions>();

            using (ZipArchive zipArchive = ZipFile.OpenRead(filePath))
            {
                foreach (ZipArchiveEntry zipArchiveEntry in zipArchive.Entries)
                {
                    ImportExportOptions importOption = GetImportExportOption(zipArchiveEntry.Name);

                    if (importOption != ImportExportOptions.None)
                    {
                        importOptions.Add(importOption);
                    }
                }
            }

            if (importOptions.Count == 0)
            {
                throw new ImportFileNotValidException();
            }
            else
            {
                return(importOptions);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the sheet data.
        /// </summary>
        /// <param name="worksheet">The sheet.</param>
        /// <param name="rowIndex">The row index.</param>
        /// <param name="columnIndex">The column index.</param>
        /// <param name="data">The data.</param>
        /// <param name="flags">The import flags.</param>
        public static void SetSheetData(Worksheet worksheet, int rowIndex, int columnIndex, List <List <string> > data, TextFileOpenFlags flags)
        {
            int num       = data.Count;
            int maxLength = GetMaxLength(data);

            if ((num != 0) && (maxLength != 0))
            {
                ImportExportOptions opt = new ImportExportOptions(flags);
                opt.FixOptions(worksheet);
                int columnCount = opt.RowHeader ? worksheet.RowHeaderColumnCount : 0;
                int num4        = opt.ColumnHeader ? worksheet.ColumnHeaderRowCount : 0;
                int num5        = 0;
                maxLength -= columnCount;
                if (maxLength <= 0)
                {
                    maxLength = 0;
                }
                num -= num4;
                if (num <= 0)
                {
                    num5 = 0;
                }
                num -= num5;
                if (num <= 0)
                {
                    num = 0;
                }
                if (opt.ExpandRows && ((rowIndex + num) > worksheet.RowCount))
                {
                    worksheet.RowCount = rowIndex + num;
                }
                if (opt.ExpandColumns && ((columnIndex + maxLength) > worksheet.ColumnCount))
                {
                    worksheet.ColumnCount = columnIndex + maxLength;
                }
                int num6 = 0;
                for (int i = 0; num6 < data.Count; i++)
                {
                    List <string> rowData = data[num6];
                    if (rowData.Count > 0)
                    {
                        if ((num4 > 0) && (num6 < num4))
                        {
                            SetRowData(worksheet, rowData, i, columnIndex, maxLength, SheetArea.ColumnHeader, opt);
                        }
                        else if ((num > 0) && (i < worksheet.GetRowCount(SheetArea.Cells)))
                        {
                            if (num6 == num4)
                            {
                                i = rowIndex;
                            }
                            SetRowData(worksheet, rowData, i, 0, columnCount, SheetArea.CornerHeader | SheetArea.RowHeader, opt);
                            rowData.RemoveRange(0, columnCount);
                            SetRowData(worksheet, rowData, i, columnIndex, maxLength, SheetArea.Cells, opt);
                        }
                    }
                    num6++;
                }
            }
        }
        private static string GetImportExportOptionFilePath(ImportExportOptions importExportOption)
        {
            switch (importExportOption)
            {
            case ImportExportOptions.ApplicationSettings:
                return(SettingsManager.GetSettingsFilePath());

            case ImportExportOptions.NetworkInterfaceProfiles:
                return(NetworkInterfaceProfileManager.GetProfilesFilePath());

            case ImportExportOptions.IPScannerProfiles:
                return(IPScannerProfileManager.GetProfilesFilePath());

            case ImportExportOptions.WakeOnLANClients:
                return(WakeOnLANClientManager.GetClientsFilePath());

            case ImportExportOptions.PortScannerProfiles:
                return(PortScannerProfileManager.GetProfilesFilePath());

            case ImportExportOptions.RemoteDesktopSessions:
                return(RemoteDesktopSessionManager.GetSessionsFilePath());
            }

            return(string.Empty);
        }
Esempio n. 4
0
        private static string GetImportExportOptionFilePath(ImportExportOptions importExportOption)
        {
            switch (importExportOption)
            {
            case ImportExportOptions.Settings:
                return(SettingsManager.GetSettingsFilePath());

            case ImportExportOptions.Profiles:
                return(ProfileManager.GetProfilesFilePath());
            }

            return(string.Empty);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the sheet data.
        /// </summary>
        /// <param name="worksheet">The sheet.</param>
        /// <param name="rowStartIndex">Start index of the row.</param>
        /// <param name="rowEndIndex">End index of the row.</param>
        /// <param name="columnStartIndex">Start index of the column.</param>
        /// <param name="columnEndIndex">End index of the column.</param>
        /// <param name="flags">The save flags.</param>
        /// <returns></returns>
        public static List <List <object> > GetSheetData(Worksheet worksheet, int rowStartIndex, int rowEndIndex, int columnStartIndex, int columnEndIndex, TextFileSaveFlags flags)
        {
            List <List <object> > list = new List <List <object> >();
            ImportExportOptions   opt  = new ImportExportOptions(flags);

            opt.FixOptions(worksheet);
            if (opt.ColumnHeader)
            {
                list.AddRange((IEnumerable <List <object> >)GetPartData(worksheet, 0, worksheet.GetRowCount(SheetArea.ColumnHeader) - 1, columnStartIndex, columnEndIndex, SheetArea.ColumnHeader, opt));
            }
            list.AddRange((IEnumerable <List <object> >)GetPartData(worksheet, rowStartIndex, rowEndIndex, columnStartIndex, columnEndIndex, SheetArea.Cells, opt));
            return(list);
        }
        private static string GetImportExportOptionFileName(ImportExportOptions importExportOption)
        {
            switch (importExportOption)
            {
            case ImportExportOptions.ApplicationSettings:
                return(SettingsManager.GetSettingsFileName());

            case ImportExportOptions.NetworkInterfaceProfiles:
                return(NetworkInterfaceProfileManager.ProfilesFileName);

            case ImportExportOptions.WakeOnLANClients:
                return(WakeOnLANClientManager.ClientsFileName);
            }

            return(string.Empty);
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the part data.
        /// </summary>
        /// <param name="worksheet">The sheet</param>
        /// <param name="rowStartIndex">Start index of the row</param>
        /// <param name="rowEndIndex">End index of the row</param>
        /// <param name="columnStartIndex">Start index of the column</param>
        /// <param name="columnEndIndex">End index of the column</param>
        /// <param name="area">The area</param>
        /// <param name="opt">The opt</param>
        /// <returns></returns>
        static List <List <object> > GetPartData(Worksheet worksheet, int rowStartIndex, int rowEndIndex, int columnStartIndex, int columnEndIndex, SheetArea area, ImportExportOptions opt)
        {
            if (!opt.IncludeSheetArea(area))
            {
                return(null);
            }
            List <List <object> > list = new List <List <object> >();
            bool actualVisible         = true;

            for (int i = rowStartIndex; i <= rowEndIndex; i++)
            {
                if (area == SheetArea.ColumnHeader)
                {
                    actualVisible = worksheet.ColumnHeader.Rows[i].ActualVisible;
                }
                else
                {
                    actualVisible = worksheet.Rows[i].ActualVisible;
                }
                if (actualVisible || !opt.AsViewed)
                {
                    List <object> list2 = new List <object>();
                    if (opt.RowHeader && (area == SheetArea.Cells))
                    {
                        for (int k = 0; k < worksheet.GetColumnCount(SheetArea.CornerHeader | SheetArea.RowHeader); k++)
                        {
                            if (worksheet.GetActualColumnVisible(k, SheetArea.CornerHeader | SheetArea.RowHeader) || !opt.AsViewed)
                            {
                                list2.Add(GetCellData(worksheet, SheetArea.CornerHeader | SheetArea.RowHeader, i, k, opt));
                            }
                        }
                    }
                    for (int j = columnStartIndex; j <= columnEndIndex; j++)
                    {
                        if (worksheet.GetActualColumnVisible(j, SheetArea.Cells) || !opt.AsViewed)
                        {
                            list2.Add(GetCellData(worksheet, area, i, j, opt));
                        }
                    }
                    list.Add(list2);
                }
            }
            return(list);
        }
Esempio n. 8
0
        /// <summary>
        /// Sets the row data.
        /// </summary>
        /// <param name="worksheet">The sheet</param>
        /// <param name="rowData">The row data</param>
        /// <param name="sheetRowIndex">Index of the sheet row</param>
        /// <param name="columnIndex">Index of the column</param>
        /// <param name="columnCount">The column count</param>
        /// <param name="area">The area</param>
        /// <param name="opt">The opt</param>
        static void SetRowData(Worksheet worksheet, List <string> rowData, int sheetRowIndex, int columnIndex, int columnCount, SheetArea area, ImportExportOptions opt)
        {
            int num = 0;

            for (int i = columnIndex; num < rowData.Count; i++)
            {
                if ((columnCount > 0) && (i < worksheet.GetColumnCount(area)))
                {
                    SetCellData(worksheet, area, sheetRowIndex, i, rowData[num], opt);
                }
                num++;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Sets the cell data.
        /// </summary>
        /// <param name="worksheet">The sheet</param>
        /// <param name="area">The area</param>
        /// <param name="rowIndex">Index of the row</param>
        /// <param name="columnIndex">Index of the column</param>
        /// <param name="value">The value</param>
        /// <param name="opt">The opt</param>
        static void SetCellData(Worksheet worksheet, SheetArea area, int rowIndex, int columnIndex, string value, ImportExportOptions opt)
        {
            object           obj2       = value;
            GeneralFormatter gformatter = null;

            if (!opt.UnFormatted)
            {
                gformatter = new GeneralFormatter().GetPreferredDisplayFormatter(value, out obj2) as GeneralFormatter;
            }
            if (obj2 == null)
            {
                worksheet.SetValue(rowIndex, columnIndex, area, obj2);
            }
            else if (!object.Equals(value, ""))
            {
                if (!opt.Formula || !value.StartsWith("="))
                {
                    StyleInfo info = worksheet.GetActualStyleInfo(rowIndex, columnIndex, area);
                    if (info != null)
                    {
                        if (!opt.UnFormatted)
                        {
                            if (info.Formatter == null)
                            {
                                SetFormatter(worksheet, rowIndex, columnIndex, area, gformatter);
                            }
                            else if (info.Formatter.FormatString == "@")
                            {
                                obj2 = value.ToString();
                            }
                        }
                        else if (info.Formatter != null)
                        {
                            if (area == SheetArea.Cells)
                            {
                                worksheet.Cells[rowIndex, columnIndex].ResetFormatter();
                            }
                            if (area == (SheetArea.CornerHeader | SheetArea.RowHeader))
                            {
                                worksheet.RowHeader.Cells[rowIndex, columnIndex].ResetFormatter();
                            }
                            if (area == SheetArea.ColumnHeader)
                            {
                                worksheet.ColumnHeader.Cells[rowIndex, columnIndex].ResetFormatter();
                            }
                        }
                    }
                    worksheet.SetValue(rowIndex, columnIndex, area, obj2);
                }
                else
                {
                    try
                    {
                        worksheet.SetFormula(rowIndex, columnIndex, area, value.Substring(1));
                    }
                    catch
                    {
                        worksheet.SetText(rowIndex, columnIndex, area, value);
                    }
                }
            }
            else
            {
                worksheet.SetValue(rowIndex, columnIndex, area, null);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the cell data.
        /// </summary>
        /// <param name="worksheet">The sheet</param>
        /// <param name="area">The area</param>
        /// <param name="rowIndex">Index of the row</param>
        /// <param name="columnIndex">Index of the column</param>
        /// <param name="opt">The opt</param>
        /// <returns></returns>
        static object GetCellData(Worksheet worksheet, SheetArea area, int rowIndex, int columnIndex, ImportExportOptions opt)
        {
            if (opt.Formula && (area == SheetArea.Cells))
            {
                string formula = worksheet.GetFormula(rowIndex, columnIndex);
                if (!string.IsNullOrEmpty(formula))
                {
                    return(string.Format("={0}", (object[])new object[] { formula }));
                }
            }
            if (!opt.UnFormatted)
            {
                IFormatter formatter = worksheet.GetActualFormatter(rowIndex, columnIndex, area);
                if (formatter != null)
                {
                    return(worksheet.Value2Text(worksheet.GetValue(rowIndex, columnIndex, area), formatter));
                }
            }
            object columnLabel = worksheet.GetValue(rowIndex, columnIndex, area);

            if ((columnLabel == null) && (area == SheetArea.ColumnHeader))
            {
                columnLabel = worksheet.GetColumnLabel(rowIndex, columnIndex);
            }
            if ((columnLabel == null) && (area == (SheetArea.CornerHeader | SheetArea.RowHeader)))
            {
                columnLabel = worksheet.GetRowLabel(rowIndex, columnIndex);
            }
            return(columnLabel);
        }