Example #1
0
        /// <summary>
        /// Gets the field names from a workbook and stores them in a list.
        /// </summary>
        /// <param name="fieldNames">list where field names will be stored</param>
        /// <param name="workbook">workbook from which field names will be extracted</param>
        public static void GetFieldNames(ImportData data, XSSFWorkbook workbook)
        {
            ISheet sheet = workbook.GetSheetAt(0);
            bool reading = true;
            int rindex = sheet.FirstRowNum;

            while (reading) {
                IRow row = sheet.GetRow(rindex);

                if (row != null) {
                    ICell cell = row.GetCell(0);

                    if (cell != null) {
                        string s = CellValueAsString(cell);

                        if (s != "" && s[0] == '[') {
                            for (int i = 0; i < row.LastCellNum; i++) {
                                s = CellValueAsString(row.GetCell(i)).TrimEnd(']').TrimStart('['); ;
                                data.fieldNames.Add(s);
                            }

                            // don't read more than one row of field names
                            reading = false;
                        }
                    }
                }

                rindex++;

                if (rindex > sheet.LastRowNum) {
                    reading = false;
                }
            }
        }
Example #2
0
    public void ReadXlsxTest()
    {
        ExcelReader reader = new ExcelReader();
        ImportData data = new ImportData();
        string testDataLocation = "/Assets/Vendor/DataHelpers/Editor/Tests/Fixtures/TestData.xlsx";

        reader.ReadAsset(testDataLocation, ref data);

        Assert.AreEqual(2, data.vars.Count, "it should load 2 variables");
        Assert.AreEqual("100", data.vars["foo1"]);
        Assert.AreEqual("200", data.vars["foo2"]);

        Assert.AreEqual(2, data.meta.Count, "it should load 2 meta values");
        Assert.AreEqual("foo author", data.meta["author"]);
        Assert.AreEqual("foo description", data.meta["description"]);

        Assert.AreEqual(3, data.fieldNames.Count, "it should load 3 field names");
        Assert.AreEqual("Foo", data.fieldNames[0]);
        Assert.AreEqual("Bar", data.fieldNames[1]);
        Assert.AreEqual("Baz", data.fieldNames[2]);

        Assert.AreEqual(2, data.rows.Count, "it should load 2 rows of data");
        Assert.AreEqual("1", data.rows[0].fields["Foo"].value);
        Assert.AreEqual("2", data.rows[0].fields["Bar"].value);
        Assert.AreEqual("3", data.rows[0].fields["Baz"].value);
        Assert.AreEqual("4", data.rows[1].fields["Foo"].value);
        Assert.AreEqual("5", data.rows[1].fields["Bar"].value);
        Assert.AreEqual("6", data.rows[1].fields["Baz"].value);
    }
Example #3
0
        /// <summary>
        /// Read an excel file and extract the meta, variables, and parsable rows.
        /// </summary>
        /// <param name="assetPath"></param>
        public void ReadAsset(string assetPath, ref ImportData data)
        {
            Debug.Log("START IMPORT PROCESS FOR XLSX");

            // get an absolute path to the asset
            string absolutePath = System.IO.Directory.GetCurrentDirectory() + "/" + assetPath;

            // open a file stream to the asset
            using (FileStream fs = new FileStream(absolutePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {

                // get workbook
                XSSFWorkbook wb = new XSSFWorkbook(fs);

                // get field names
                GetFieldNames(data, wb);

                // get key/value meta data
                GetKeyValData(ref data.meta, wb, "#");

                // get key/value
                GetKeyValData(ref data.vars, wb, "$");

                // get the parsable rows
                GetRows(data, wb);
            }
        }
Example #4
0
    public ImportData()
    {
        instance = this;
        containers =  new List<ImportedDataContainer>();

        foreach(string file in importNames){
            ImportedTable _table = ImportedTable.LoadFromFile(file) ;
            if(_table != null){
                containers.AddRange(  getDataFromTable( _table) );
            } else {
                Debug.LogWarning("Could not import data from "+file);
            }
        }

        Debug.Log("- DataContainers Configured:"+containers.Count );
    }
Example #5
0
        public void Import()
        {
            Dictionary <string, int> result = new ImportData().AutoImportData();

            MessageBox.Show(string.Format("处方数:{0},处方明细数:{1}", result["处方数"], result["处方明细数"]), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //OpenFileDialog ofd = new OpenFileDialog()
            //{
            //    Filter = "XML文件|*.xml",
            //    InitialDirectory = @"\\172.20.81.139\chufang"
            //};
            //DialogResult dr = ofd.ShowDialog();
            //if (dr == DialogResult.OK)
            //{
            //    //string info = ImportData(ofd.FileName);
            //    //MessageBox.Show(info, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    Dictionary<string, int> result = new ImportData().Import(ofd.FileName);
            //    MessageBox.Show(string.Format("处方数:{0},处方明细数{1}", result["处方数"], result["处方明细数"]), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
        }
Example #6
0
        /// <summary>
        /// Opens a JSON file that contains a Bullion account.
        /// File dialog will open to this projects directory where the account file can be located.
        /// </summary>
        /// <remarks>
        /// <para>If the data imported for a property equals zero, then the content will be "0".</para>
        /// <para>If there is a selected item in the resourceComboBox, then the selection will be reset.</para>
        /// <para>If there is a value in the amountTextBox, then the text will be cleared.</para>
        /// </remarks>>
        private void Import_Data_Click(object sender, RoutedEventArgs e)
        {
            ImportData idata = new ImportData();

            account = idata.Import(account, cipher);

            DataValidation data = new DataValidation();

            if (data.ValidateDouble(account.Savings))
            {
                savingsAmountLabel.Content = account.Savings.ToString("N");
            }
            else
            {
                savingsAmountLabel.Content = 0;
            }
            if (data.ValidateDouble(account.Cash))
            {
                cashAmountLabel.Content = account.Cash.ToString("N");
            }
            else
            {
                cashAmountLabel.Content = 0;
            }
            if (data.ValidateDouble(account.Crypto))
            {
                cryptoAmountLabel.Content = account.Crypto.ToString("N");
            }
            else
            {
                cryptoAmountLabel.Content = 0;
            }
            if (data.ValidateDouble(account.Savings + account.Cash))
            {
                totalAmountLabel.Content = (account.Savings + account.Cash).ToString("N");
            }
            else
            {
                totalAmountLabel.Content = 0;
            }

            DataContext = account;
        }
Example #7
0
        public ImportData Patch(ImportData request)
        {
            if (true != (request?.Id > 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the ImportData to patch.");
            }

            request.Select = request.Select ?? new List <string>();

            ImportData ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    ret = _AssignValues(request, DocConstantPermission.EDIT, ssn);
                });
            }
            return(ret);
        }
Example #8
0
    public ImportData()
    {
        instance   = this;
        containers = new List <ImportedDataContainer>();

        foreach (string file in importNames)
        {
            ImportedTable _table = ImportedTable.LoadFromFile(file);
            if (_table != null)
            {
                containers.AddRange(getDataFromTable(_table));
            }
            else
            {
                Debug.LogWarning("Could not import data from " + file);
            }
        }

        Debug.Log("- DataContainers Configured:" + containers.Count);
    }
Example #9
0
        public string Import(string clipUrl, string thumbUrl, string title, string description, int categoryId = 713, int privacy = 0)
        {
            try {
                var postUrl     = $"https://api-v2.medal.tv/users/{UserId.ToString ( )}/content";
                var contentType = "application/json";

                var http = WebRequest.CreateHttp(postUrl);
                http.ContentType       = contentType;
                http.Method            = "POST";
                http.AllowAutoRedirect = true;
                http.CachePolicy       = new RequestCachePolicy(RequestCacheLevel.BypassCache);
                http.Referer           = "no-referrer";
                http.UserAgent         = "Medal Overlay for Streamlabs Chatbot";
                http.Headers.Add("X-Authentication", $"{UserId.ToString ( )},{AuthKey}");

                var data = new ImportData {
                    ContentUrl         = clipUrl,
                    CategoryId         = categoryId,
                    Privacy            = privacy,
                    ContentDescription = description,
                    ContentTitle       = title,
                    ThumbnailUrl       = thumbUrl
                };

                var body = Newtonsoft.Json.JsonConvert.SerializeObject(data, Formatting.None);
                using (var reqs = http.GetRequestStream( )) {
                    var unicodeEncoding = new UnicodeEncoding( );
                    var bytesData       = unicodeEncoding.GetBytes(body);
                    reqs.Write(bytesData, 0, bytesData.Length);
                }

                var resp = http.GetResponse( );
                using (var resps = resp.GetResponseStream( )) {
                    using (var sr = new StreamReader(resps)) {
                        return(sr.ReadToEnd( ));
                    }
                }
            } catch (Exception e) {
                return($"{{ \"error\": \"{e.Message.Replace ( "\r", "" ).Replace ( "\n", "\\n" )}\", \"stack\": \"{e.StackTrace.Replace ( "\r", "" ).Replace ( "\n", "\\n" )}\" }}");
            }
        }
Example #10
0
        private bool execCreateTable(String inSqlStmt)
        {
            bool       curReturnValue = true;
            int        curDelimIdx, curDelimIdx2, curValueLen;
            ImportData curImportData = new ImportData();

            String[] curTableName = new String[1];

            try {
                curDelimIdx = inSqlStmt.ToUpper().IndexOf("TABLE ");
                if (curDelimIdx > 0)
                {
                    curDelimIdx2 = inSqlStmt.IndexOf(" ", curDelimIdx + 6);
                    if (curDelimIdx2 < 0)
                    {
                        curValueLen = inSqlStmt.Length - curDelimIdx - 6;
                    }
                    else
                    {
                        curValueLen = curDelimIdx2 - curDelimIdx - 6;
                    }
                    curTableName[0] = inSqlStmt.Substring(curDelimIdx + 6, curValueLen);
                    String curFileRef = Application.StartupPath + "\\" + curTableName[0] + ".tmp";

                    if (execSchemaCmd(inSqlStmt))
                    {
                        if (!(curTableName[0].EndsWith("Backup")))
                        {
                            curImportData.importData((curFileRef));
                            deleteTempFile(curFileRef);
                        }
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("Error: Executing drop table command " + inSqlStmt
                                + "\n\nException: " + ex.Message
                                );
                curReturnValue = false;
            }
            return(curReturnValue);
        }
Example #11
0
        /// <summary>
        /// Gets the field names from a workbook and stores them in a list.
        /// </summary>
        /// <param name="fieldNames">list where field names will be stored</param>
        /// <param name="workbook">workbook from which field names will be extracted</param>
        public static void GetFieldNames(ImportData data, XSSFWorkbook workbook)
        {
            ISheet sheet   = workbook.GetSheetAt(0);
            bool   reading = true;
            int    rindex  = sheet.FirstRowNum;

            while (reading)
            {
                IRow row = sheet.GetRow(rindex);

                if (row != null)
                {
                    ICell cell = row.GetCell(0);

                    if (cell != null)
                    {
                        string s = CellValueAsString(cell);

                        if (s != "" && s[0] == '[')
                        {
                            for (int i = 0; i < row.LastCellNum; i++)
                            {
                                s = CellValueAsString(row.GetCell(i)).TrimEnd(']').TrimStart('[');
                                ;
                                data.fieldNames.Add(s);
                            }

                            // don't read more than one row of field names
                            reading = false;
                        }
                    }
                }

                rindex++;

                if (rindex > sheet.LastRowNum)
                {
                    reading = false;
                }
            }
        }
Example #12
0
        public Task <ImportData> SaveAsync(ImportData data, CancellationToken token = default(CancellationToken))
        {
            var query = @"
INSERT INTO [dbo].[ImportData]
(       [CompanyId]
,       [FileName]
,       [FileSize]
,       [CreateBy]
,       [CreateAt]
)
OUTPUT inserted.*
VALUES
(       @CompanyId
,       @FileName
,       @FileSize
,       @CreateBy
,       GETDATE() /*@CreateAt*/
)";

            return(dbHelper.ExecuteAsync <ImportData>(query, data, token));
        }
Example #13
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (_worker != null && _worker.IsBusy)
            {
                return;
            }

            _waitCursor = new WaitCursor();

            EnableDisable(false);

            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
            progressBar1.Value   = 0;

            _worker = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };
            _worker.ProgressChanged    += (o, args) => progressBar1.Value = args.ProgressPercentage;
            _worker.DoWork             += backgroundWorker_DoWork;
            _worker.RunWorkerCompleted += backgroundWorker_Completed;

            var addresses = new List <string>();

            foreach (ListViewItem item in listItems.Items)
            {
                addresses.Add(item.Text);
            }

            var data = new ImportData()
            {
                Addresses = addresses,
                DeleteRecipientsNotInImportFile = ucDeleteRecipientsNotInList.Checked
            };

            _worker.RunWorkerAsync(data);
        }
Example #14
0
        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "导入Excel表格";
            ofd.Filter = "2007Excel(*.xlsx)|*.xlsx|2003Excel(*.xls)|*.xls";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                lblFilePath.Text = ofd.FileName;
                try
                {
                    this.dgvScore.DataSource = ImportData.getScoreList(ofd.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "发生错误,错误提示:");
                }
            }

            //
        }
        /// <summary>Process the import data line.</summary>
        /// <param name="dataLine">Data line to be processed.</param>
        /// <returns>Returns the imported data information.</returns>
        ImportData ProcessImportDataLine(string dataLine)
        {
            if (string.IsNullOrEmpty(dataLine))
            {
                return(null);
            }
            string[] importData = dataLine.Split(',');
            // Validate the data length and starting value
            if ((importData.Length != 3) || (importData[0].ToUpper() == "FIRSTNAME"))
            {
                return(null);
            }
            // Build the resonse data
            var result = new ImportData
            {
                FirstName = importData[0],
                LastName  = importData[1],
                Address   = importData[2],
            };

            return(result);
        }
Example #16
0
        public ImportFile Import(Guid importFileId)
        {
            ImportFile file = _importFileService.FindById(importFileId);
            ImportMap  map  = _importMapService.FindById(file.ImportMapId);
            var        data = new List <dynamic>().DeserializeFromJson(file.Content);

            this.ImportCore(file, map, data, (rowIndex, d, rowError, errorType, recordId) =>
            {
                var importDataEntity = new ImportData
                {
                    Data         = ((JArray)d).ToString(),
                    ErrorMessage = rowError.ToString(),
                    HasError     = rowError.Length > 0,
                    ImportFileId = file.ImportFileId,
                    LineNumber   = rowIndex,
                    RecordId     = recordId,
                    ErrorType    = errorType
                };
                _importDataService.Create(importDataEntity);
            });
            return(file);
        }
Example #17
0
        /// <summary>
        /// Get the parsable rows from a workbook
        /// </summary>
        /// <param name="rows">a reference to an object that will contain parsable rows</param>
        /// <param name="workbook">the workbook to extract rows from</param>
        private void GetRows(ImportData data, XSSFWorkbook workbook)
        {
            ISheet sheet = workbook.GetSheetAt(0);

            bool reading  = true;
            int  rowIndex = sheet.FirstRowNum;

            while (reading)
            {
                IRow row = sheet.GetRow(rowIndex);

                if (RowIsParsable(row))
                {
                    var validatorRow = new Row();
                    validatorRow.lineNumber = rowIndex;

                    for (int i = 0; i < data.fieldNames.Count; ++i)
                    {
                        var fieldName = data.fieldNames[i];
                        var field     = new Field()
                        {
                            value = CellValueAsString(row.GetCell(i))
                        };

                        validatorRow.fields.Add(fieldName, field);
                    }

                    data.rows.Add(validatorRow);
                }

                rowIndex++;

                if (rowIndex > sheet.LastRowNum)
                {
                    reading = false;
                }
            }
        }
Example #18
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (thread == null || thread.ThreadState == ThreadState.Stopped)
            {
                lblStatus.Text = "Chuẩn bị nhập dữ liệu...";
                Memory.Instance.SetMemory("UserAbort", false);
                EnableControl(false);
                txtErrorOutput.Clear();
                progressBar1.Value = 0;
                if (txtDB.Text.Trim().EndsWith("xls"))
                {
                    import = new ImportData(txtDB.Text, "Table1");
                }
                else
                {
                    import = new ImportData(txtDB.Text, "", "");
                }
                import.OnStart     += new EventHandler(import_OnStart);
                import.OnExecuting += new EventHandler(import_OnImporting);
                import.OnError     += new CancelEventHandler(import_OnError);
                import.OnFinished  += new EventHandler(import_OnFinished);

                ThreadStart threadStart = new ThreadStart(import.Execute);
                thread = new Thread(threadStart);
                thread.Start();
            }
            else if (thread.ThreadState == ThreadState.Suspended)
            {
                thread.Resume();
                btnStart.Text = "Tạm &dừng";
            }
            else if (thread.ThreadState == ThreadState.Running)
            {
                thread.Suspend();
                btnStart.Text = "Tiếp &tục";
            }
        }
Example #19
0
        internal DataSet ReadXmlToDataSet(string file, ref ImportData importData)
        {
            DataSet dataSet = new DataSet();

            if (File.Exists(file))
            {
                try
                {
                    int num = (int)dataSet.ReadXml(file);
                }
                catch
                {
                    importData.Errors.ErrorCode = ErrorCode.DataMissing;
                    importData.Errors.ErrorInfo = "Writing changes data to dataset failed";
                    return((DataSet)null);
                }
            }
            else
            {
                importData.Errors.ErrorCode = ErrorCode.DataMissing;
                importData.Errors.ErrorInfo = "Changes data missing";
            }
            return(dataSet);
        }
Example #20
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                string strConnectionString = "data source=" + tePath.Text;

                AddMsg(new KeyValuePair <ImportData.MsgState, string>(ImportData.MsgState.Info, "Получение данных для дальнейшей обработки из импортируемой базы..."));

                m_dictRefs   = null;
                m_listChecks = null;
                KeyValuePair <ImportData.MsgState, string> Msg = ImportData.LoadData(strConnectionString, ref m_listImportData, ref m_listChecks, ref m_dictRefs);
                AddMsg(Msg);
                if (Msg.Key == 0)
                {
                    return;
                }

                AddMsg(new KeyValuePair <ImportData.MsgState, string>(ImportData.MsgState.Info, "Получение данных для дальнейшей обработки из текущей базы..."));
                m_dictRefs   = new Dictionary <string, Dictionary <KeyValuePair <long, string>, long> >();
                m_listChecks = new List <ImportData.CheckInfo>();
                Msg          = ImportData.LoadData(global::DiarMain.Properties.Settings.Default.diarConnectionString, ref m_listData, ref m_listChecks, ref m_dictRefs);
                AddMsg(Msg);
                if (Msg.Key == 0)
                {
                    return;
                }

                AnalizeData();

                AddMsg(new KeyValuePair <ImportData.MsgState, string>(ImportData.MsgState.Info, "Загрузка данных завершена"));
            }
            catch (Exception ex)
            {
                AddMsg(new KeyValuePair <ImportData.MsgState, string>(ImportData.MsgState.Error, ex.Message));
            }
        }
Example #21
0
 public ImportData Put(ImportData request)
 {
     return(Patch(request));
 }
Example #22
0
        public ImportData Post(ImportDataCopy request)
        {
            ImportData ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityImportData.Get(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pCompletedOn = entity.CompletedOn;
                    var pDataSets    = entity.DataSets.ToList();
                    var pDocument    = entity.Document;
                    var pErrorData   = entity.ErrorData;
                    var pExtractUrl  = entity.ExtractUrl;
                    if (!DocTools.IsNullOrEmpty(pExtractUrl))
                    {
                        pExtractUrl += " (Copy)";
                    }
                    var pHighPriority   = entity.HighPriority;
                    var pImportFr       = entity.ImportFr;
                    var pImportLocation = entity.ImportLocation;
                    var pImportNewName  = entity.ImportNewName;
                    var pImportTable    = entity.ImportTable;
                    var pImportText     = entity.ImportText;
                    var pImportType     = entity.ImportType;
                    var pIsLegacy       = entity.IsLegacy;
                    var pOrder          = entity.Order;
                    var pReferenceId    = entity.ReferenceId;
                    var pRequestedBy    = entity.RequestedBy;
                    var pRequestedOn    = entity.RequestedOn;
                    var pStartedOn      = entity.StartedOn;
                    var pStatus         = entity.Status;
                    var copy            = new DocEntityImportData(ssn)
                    {
                        Hash             = Guid.NewGuid()
                        , CompletedOn    = pCompletedOn
                        , Document       = pDocument
                        , ErrorData      = pErrorData
                        , ExtractUrl     = pExtractUrl
                        , HighPriority   = pHighPriority
                        , ImportFr       = pImportFr
                        , ImportLocation = pImportLocation
                        , ImportNewName  = pImportNewName
                        , ImportTable    = pImportTable
                        , ImportText     = pImportText
                        , ImportType     = pImportType
                        , IsLegacy       = pIsLegacy
                        , Order          = pOrder
                        , ReferenceId    = pReferenceId
                        , RequestedBy    = pRequestedBy
                        , RequestedOn    = pRequestedOn
                        , StartedOn      = pStartedOn
                        , Status         = pStatus
                    };
                    foreach (var item in pDataSets)
                    {
                        entity.DataSets.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
Example #23
0
        private ImportData _AssignValues(ImportData request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "ImportData"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            ImportData ret = null;

            request = _InitAssignValues <ImportData>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <ImportData>(DocConstantModelName.IMPORTDATA, nameof(ImportData), request);

            //First, assign all the variables, do database lookups and conversions
            var pCompletedOn  = request.CompletedOn;
            var pDataSets     = GetVariable <Reference>(request, nameof(request.DataSets), request.DataSets?.ToList(), request.DataSetsIds?.ToList());
            var pDocument     = DocEntityDocument.Get(request.Document?.Id, true, Execute) ?? DocEntityDocument.Get(request.DocumentId, true, Execute);
            var pErrorData    = request.ErrorData;
            var pExtractUrl   = request.ExtractUrl;
            var pHighPriority = request.HighPriority;
            var pImportFr     = request.ImportFr;
            DocEntityLookupTable pImportLocation = GetLookup(DocConstantLookupTable.STUDYIMPORTLOCATION, request.ImportLocation?.Name, request.ImportLocation?.Id);
            var pImportNewName = request.ImportNewName;
            var pImportTable   = request.ImportTable;
            var pImportText    = request.ImportText;
            DocEntityLookupTable pImportType = GetLookup(DocConstantLookupTable.STUDYIMPORTTYPE, request.ImportType?.Name, request.ImportType?.Id);
            var pIsLegacy                = request.IsLegacy;
            var pOrder                   = request.Order;
            var pReferenceId             = request.ReferenceId;
            var pRequestedBy             = DocEntityUser.Get(request.RequestedBy?.Id, true, Execute) ?? DocEntityUser.Get(request.RequestedById, true, Execute);
            var pRequestedOn             = request.RequestedOn;
            var pStartedOn               = request.StartedOn;
            DocEntityLookupTable pStatus = GetLookup(DocConstantLookupTable.IMPORTSTATUS, request.Status?.Name, request.Status?.Id);
            var pArchived                = true == request.Archived;
            var pLocked                  = request.Locked;

            var entity = InitEntity <DocEntityImportData, ImportData>(request, permission, session);

            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <ImportData, DateTime?>(request, DocConstantModelName.IMPORTDATA, pCompletedOn, permission, nameof(request.CompletedOn), pCompletedOn != entity.CompletedOn))
            {
                entity.CompletedOn = pCompletedOn;
            }
            if (AllowPatchValue <ImportData, DocEntityDocument>(request, DocConstantModelName.IMPORTDATA, pDocument, permission, nameof(request.Document), pDocument != entity.Document))
            {
                entity.Document = pDocument;
            }
            if (AllowPatchValue <ImportData, string>(request, DocConstantModelName.IMPORTDATA, pErrorData, permission, nameof(request.ErrorData), pErrorData != entity.ErrorData))
            {
                entity.ErrorData = pErrorData;
            }
            if (AllowPatchValue <ImportData, string>(request, DocConstantModelName.IMPORTDATA, pExtractUrl, permission, nameof(request.ExtractUrl), pExtractUrl != entity.ExtractUrl))
            {
                entity.ExtractUrl = pExtractUrl;
            }
            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pHighPriority, permission, nameof(request.HighPriority), pHighPriority != entity.HighPriority))
            {
                entity.HighPriority = pHighPriority;
            }
            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pImportFr, permission, nameof(request.ImportFr), pImportFr != entity.ImportFr))
            {
                entity.ImportFr = pImportFr;
            }
            if (AllowPatchValue <ImportData, DocEntityLookupTable>(request, DocConstantModelName.IMPORTDATA, pImportLocation, permission, nameof(request.ImportLocation), pImportLocation != entity.ImportLocation))
            {
                entity.ImportLocation = pImportLocation;
            }
            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pImportNewName, permission, nameof(request.ImportNewName), pImportNewName != entity.ImportNewName))
            {
                entity.ImportNewName = pImportNewName;
            }
            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pImportTable, permission, nameof(request.ImportTable), pImportTable != entity.ImportTable))
            {
                entity.ImportTable = pImportTable;
            }
            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pImportText, permission, nameof(request.ImportText), pImportText != entity.ImportText))
            {
                entity.ImportText = pImportText;
            }
            if (AllowPatchValue <ImportData, DocEntityLookupTable>(request, DocConstantModelName.IMPORTDATA, pImportType, permission, nameof(request.ImportType), pImportType != entity.ImportType))
            {
                entity.ImportType = pImportType;
            }
            if (AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pIsLegacy, permission, nameof(request.IsLegacy), pIsLegacy != entity.IsLegacy))
            {
                entity.IsLegacy = pIsLegacy;
            }
            if (AllowPatchValue <ImportData, int?>(request, DocConstantModelName.IMPORTDATA, pOrder, permission, nameof(request.Order), pOrder != entity.Order))
            {
                entity.Order = pOrder;
            }
            if (AllowPatchValue <ImportData, int?>(request, DocConstantModelName.IMPORTDATA, pReferenceId, permission, nameof(request.ReferenceId), pReferenceId != entity.ReferenceId))
            {
                if (null != pReferenceId)
                {
                    entity.ReferenceId = (int)pReferenceId;
                }
            }
            if (AllowPatchValue <ImportData, DocEntityUser>(request, DocConstantModelName.IMPORTDATA, pRequestedBy, permission, nameof(request.RequestedBy), pRequestedBy != entity.RequestedBy))
            {
                entity.RequestedBy = pRequestedBy;
            }
            if (AllowPatchValue <ImportData, DateTime?>(request, DocConstantModelName.IMPORTDATA, pRequestedOn, permission, nameof(request.RequestedOn), pRequestedOn != entity.RequestedOn))
            {
                entity.RequestedOn = pRequestedOn;
            }
            if (AllowPatchValue <ImportData, DateTime?>(request, DocConstantModelName.IMPORTDATA, pStartedOn, permission, nameof(request.StartedOn), pStartedOn != entity.StartedOn))
            {
                entity.StartedOn = pStartedOn;
            }
            if (AllowPatchValue <ImportData, DocEntityLookupTable>(request, DocConstantModelName.IMPORTDATA, pStatus, permission, nameof(request.Status), pStatus != entity.Status))
            {
                entity.Status = pStatus;
            }
            if (request.Locked && AllowPatchValue <ImportData, bool>(request, DocConstantModelName.IMPORTDATA, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <ImportData, DocEntityImportData, Reference, DocEntityDataSet>(request, entity, pDataSets, permission, nameof(request.DataSets)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.IMPORTDATA);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <ImportData>(currentUser, nameof(ImportData), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.IMPORTDATA);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.IMPORTDATA, cacheExpires);

            return(ret);
        }
Example #24
0
 public object Get(ImportData request) => GetEntityWithCache <ImportData>(DocConstantModelName.IMPORTDATA, request, GetImportData);
        public void GenerateImports()
        {
            _imports.Clear();
            Dictionary<uint, ImportData> data = new Dictionary<uint, ImportData>();
            foreach (ModuleSectionNode s in _sections)
            {
                foreach (ImportData e in data.Values)
                {
                    e._first = true;
                    e._lastOffset = 0;
                }
                uint i = 0;
                uint offset = 0;
                List<RELLink> cmds;
                foreach (Relocation loc in s._relocations)
                {
                    if (loc.Command != null)
                    {
                        RelCommand cmd = loc.Command;
                        ImportData d;
                        uint id = cmd._moduleID;

                        if (_imports.ContainsKey(id))
                        {
                            cmds = _imports[id];
                            d = data[id];
                        }
                        else
                        {
                            _imports.Add(id, cmds = new List<RELLink>());
                            data.Add(id, d = new ImportData() { _first = true, _lastOffset = 0 });
                        }

                        if (d._first)
                        {
                            cmds.Add(new RELLink() { _type = RELLinkType.Section, _section = (byte)s.Index });
                            d._first = false;
                        }

                        offset = i * 4 + (cmd.IsHalf ? 2u : 0);
                        uint diff = offset - d._lastOffset;
                        while (offset - d._lastOffset > 0xFFFF)
                        {
                            d._lastOffset += 0xFFFF;
                            cmds.Add(new RELLink() { _type = RELLinkType.IncrementOffset, _section = 0, _value = 0, _prevOffset = 0xFFFF });
                        }

                        byte targetSection = (byte)cmd._targetSectionId;
                        RELLinkType type = (RELLinkType)cmd._command;
                        uint val = cmd._addend;

                        cmds.Add(new RELLink() { _type = type, _section = targetSection, _value = val, _prevOffset = (ushort)diff });

                        d._lastOffset = offset;
                    }
                    i++;
                }
            }

            foreach (List<RELLink> cmds in _imports.Values)
                cmds.Add(new RELLink() { _type = RELLinkType.End });
        }
Example #26
0
        private void Engine(object sender, EventArgs e)
        {
            this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Reading N and C files... (Task 0/6)"; }));
            ImportData import   = new ImportData(backgroundWorker1);
            List <PSM> MMOutput = new List <PSM>();
            List <TheoreticalProtein> database = new List <TheoreticalProtein>();
            bool passedFileIO = true;

            {
                MMOutput = import.ImportPSMs(nFileName, cFileName, out string error_message);
                if (error_message.Length > 0)
                {
                    MessageBox.Show(error_message);
                }

                this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Reading database... (Task 1/6)"; }));
                ClearProgress();
                database = import.ImportDatabase(databaseFileName, out string error_message2);
                if (error_message2.Length > 0)
                {
                    MessageBox.Show(error_message2);
                }
            }
            if (passedFileIO)
            {
                this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Splicing peptides... (Task 2/6)"; }));
                ClearProgress();
                SpliceFragments sf         = new SpliceFragments(backgroundWorker1);
                List <PSM>      candidates = sf.ExperimentalTheoreticalMatching(MMOutput, out string error_message);
                if (error_message.Length > 0)
                {
                    MessageBox.Show(error_message);
                }
                ClearProgress();
                AlternativeSequences altSeq = new AlternativeSequences(backgroundWorker1);

                this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Finding ambiquity... (Task 3/6)"; }));
                ClearProgress();
                altSeq.FindAmbiguity(candidates, database, out string error_message2);
                if (error_message2.Length > 0)
                {
                    MessageBox.Show(error_message2);
                }
                FalsePositives.generateDecoys = false;
                this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Recording variants... (Task 4/6)"; }));
                ClearProgress();
                FalsePositives rfp = new FalsePositives(backgroundWorker1);
                rfp.FindCommonFalsePositives(candidates, database, out string error_message3);
                if (error_message3.Length > 0)
                {
                    MessageBox.Show(error_message3);
                }
                this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Exporting results... (Task 5/6)"; }));
                ClearProgress();
                ExportData ed = new ExportData(backgroundWorker1);
                string     e3 = ed.ExportAll(candidates, databaseFileName);
                if (e3.Length > 0)
                {
                    MessageBox.Show(e3);
                }

                this.Invoke(new MethodInvoker(delegate { StatustxtBox.Text = "Complete! (6/6)"; }));

                MessageBox.Show("Complete!");
            }
        }
Example #27
0
        public void GenerateImports()
        {
            _imports.Clear();
            Dictionary <uint, ImportData> data = new Dictionary <uint, ImportData>();

            foreach (ModuleSectionNode s in _sections)
            {
                foreach (ImportData e in data.Values)
                {
                    e._first      = true;
                    e._lastOffset = 0;
                }
                uint           i      = 0;
                uint           offset = 0;
                List <RELLink> cmds;
                foreach (Relocation loc in s._relocations)
                {
                    if (loc.Command != null)
                    {
                        RelCommand cmd = loc.Command;
                        ImportData d;
                        uint       id = cmd._moduleID;

                        if (_imports.ContainsKey(id))
                        {
                            cmds = _imports[id];
                            d    = data[id];
                        }
                        else
                        {
                            _imports.Add(id, cmds = new List <RELLink>());
                            data.Add(id, d        = new ImportData()
                            {
                                _first = true, _lastOffset = 0
                            });
                        }

                        if (d._first)
                        {
                            cmds.Add(new RELLink()
                            {
                                _type = RELLinkType.Section, _section = (byte)s.Index
                            });
                            d._first = false;
                        }

                        offset = i * 4 + (cmd.IsHalf ? 2u : 0);
                        uint diff = offset - d._lastOffset;
                        while (offset - d._lastOffset > 0xFFFF)
                        {
                            d._lastOffset += 0xFFFF;
                            cmds.Add(new RELLink()
                            {
                                _type = RELLinkType.IncrementOffset, _section = 0, _value = 0, _prevOffset = 0xFFFF
                            });
                        }

                        byte        targetSection = (byte)cmd._targetSectionId;
                        RELLinkType type          = (RELLinkType)cmd._command;
                        uint        val           = cmd._addend;

                        cmds.Add(new RELLink()
                        {
                            _type = type, _section = targetSection, _value = val, _prevOffset = (ushort)diff
                        });

                        d._lastOffset = offset;
                    }
                    i++;
                }
            }

            foreach (List <RELLink> cmds in _imports.Values)
            {
                cmds.Add(new RELLink()
                {
                    _type = RELLinkType.End
                });
            }
        }
Example #28
0
        /// <summary>
        /// Get the parsable rows from a workbook
        /// </summary>
        /// <param name="rows">a reference to an object that will contain parsable rows</param>
        /// <param name="workbook">the workbook to extract rows from</param>
        private void GetRows(ImportData data, XSSFWorkbook workbook)
        {
            ISheet sheet = workbook.GetSheetAt(0);

            bool reading = true;
            int rowIndex = sheet.FirstRowNum;

            while (reading) {
                IRow row = sheet.GetRow(rowIndex);

                if (RowIsParsable(row)) {

                    var validatorRow = new Row();
                    validatorRow.lineNumber = rowIndex;

                    for (int i = 0; i < data.fieldNames.Count; ++i) {
                        var fieldName = data.fieldNames[i];
                        var field = new Field() { value = CellValueAsString(row.GetCell(i)) };

                        validatorRow.fields.Add(fieldName, field);
                    }

                    data.rows.Add(validatorRow);
                }

                rowIndex++;

                if (rowIndex > sheet.LastRowNum) {
                    reading = false;
                }
            }
        }
Example #29
0
 public JsonResult Content(ImportData data)
 {
     return(TryImportContent(data));
 }
Example #30
0
        public bool Update(ImportData entity)
        {
            var flag = _importDataRepository.Update(entity);

            return(flag);
        }
Example #31
0
        public bool Create(ImportData entity)
        {
            bool flag = _importDataRepository.Create(entity);

            return(flag);
        }
Example #32
0
        public void GenerateImports()
        {
            _imports.Clear();
            Dictionary <uint, ImportData> tempImports = new Dictionary <uint, ImportData>();

            foreach (ModuleSectionNode s in _sections)
            {
                foreach (ImportData e in tempImports.Values)
                {
                    e._newSection = true;
                    e._lastOffset = 0;
                }

                uint           offset = 0;
                List <RELLink> links;

                //Iterate through each command in the section
                var commands = s._manager.GetCommands();
                foreach (var r in commands)
                {
                    RelCommand command = r.Value;
                    int        index   = r.Key;

                    ImportData impData;
                    uint       moduleID = command._moduleID;

                    //Check if an import has been created for the target module.
                    if (_imports.ContainsKey(moduleID))
                    {
                        //An import already exists, so we'll add to it.
                        links   = _imports[moduleID];
                        impData = tempImports[moduleID];
                    }
                    else
                    {
                        //An import does not exist, so it must be made.
                        _imports.Add(moduleID, links = new List <RELLink>());

                        //Create new temporary import data
                        tempImports.Add(moduleID, impData = new ImportData()
                        {
                            _newSection = true, _lastOffset = 0
                        });
                    }

                    //This is true when a new section is being evaluated.
                    if (impData._newSection)
                    {
                        links.Add(new RELLink()
                        {
                            _type = RELLinkType.Section, _section = (byte)s.Index
                        });
                        impData._newSection = false;
                    }

                    //Get the offset of the command within the section.
                    offset = (uint)index * 4 + (command.IsHalf ? 2u : 0);

                    //Get the offset to this address relative to the last written link offset.
                    uint diff = offset - impData._lastOffset;

                    //If the difference is greater than ushort allows,
                    //add increment links until the difference works
                    while (diff > 0xFFFF)
                    {
                        impData._lastOffset += 0xFFFF;
                        diff = offset - impData._lastOffset;

                        links.Add(new RELLink()
                        {
                            _type = RELLinkType.IncrementOffset, _section = 0, _value = 0, _prevOffset = 0xFFFF
                        });
                    }

                    //Gather the link information
                    byte        targetSection = (byte)command._targetSectionId;
                    RELLinkType type          = (RELLinkType)command._command;
                    uint        val           = command._addend;

                    //Write command link
                    links.Add(new RELLink()
                    {
                        _type = type, _section = targetSection, _value = val, _prevOffset = (ushort)diff
                    });

                    //Don't bother adding the difference,
                    //just set the exact offset as the last offset
                    impData._lastOffset = offset;
                }
            }

            foreach (List <RELLink> cmds in _imports.Values)
            {
                cmds.Add(new RELLink()
                {
                    _type = RELLinkType.End
                });
            }
        }
Example #33
0
        void m_Worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            ImportData data       = (ImportData)e.Argument;
            String     tagsDbFile = String.Empty;

            using (ZipInputStream stream = new ZipInputStream(new System.IO.BufferedStream(FileHelpers.GetFileContentStream(data.ImportFile))))
            {
                ZipEntry entry;
                byte[]   buffer      = new byte[4096];
                long     writtenSize = 0;
                int      lastPercent = -1;
                String   lastFile    = String.Empty;
                while ((entry = stream.GetNextEntry()) != null)
                {
                    bool   isTagsDBFile;
                    String fileName = GetFileName(entry, out isTagsDBFile);
                    if (fileName == String.Empty)
                    {
                        fileName = data.TargetFile;
                    }
                    else if (isTagsDBFile)
                    {
                        tagsDbFile = fileName;
                    }
                    else if (!data.Overwrite && FileHelpers.FileExists(fileName))
                    {
                        continue;
                    }
                    String directoryName = FileHelpers.GetDirectory(fileName);
                    if (directoryName.Length > 0)
                    {
                        FileHelpers.CreateDirectory(directoryName);
                    }
                    using (var fileStream = FileHelpers.CreateFileOutputStream(fileName))
                    {
                        StreamUtils.Copy(stream, fileStream, buffer, new ProgressHandler((object o, ProgressEventArgs e2) =>
                        {
                            long currentSize   = writtenSize + e2.Processed;
                            int currentPercent = (int)(((double)currentSize / (double)data.OverallSize) * 100.0);
                            if (currentPercent != lastPercent || e2.Name != lastFile)
                            {
                                lastPercent = currentPercent;
                                lastFile    = e2.Name;
                                m_Worker.ReportProgress(currentPercent, lastFile);
                                e2.ContinueRunning = !m_Worker.CancellationPending;
                            }
                        }), TimeSpan.FromMilliseconds(50), entry, fileName, entry.Size);
                    }
                    writtenSize += entry.Size;
                    if (m_Worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }
                }
            }
            if (!String.IsNullOrEmpty(tagsDbFile))
            {
                String logFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "arestagsdbimport.log");
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(logFileName))
                {
                    Ares.Tags.TagsModule.GetTagsDB().FilesInterface.ImportDatabase(tagsDbFile, writer);
                }
            }
        }
		public override void AddNewImport (string name, MSBuildImport beforeImport = null)
		{
			var data = new ImportData {
				Target = name
			};
			if (beforeImport != null) {
				var other = (ImportData)beforeImport;
				int i = imports.IndexOf (other);
				if (i != -1) {
					imports.Insert (i, data);
					return;
				}
			}
			imports.Add (data);
		}
Example #35
0
        /// <summary>取込処理</summary>
        public async Task <AccountTransferImportResult> ReadAsync(AccountTransferImportSource source, CancellationToken token = default(CancellationToken))
        {
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask  = companyGetByIdQueryProcessor.GetByIdsAsync(new[] { source.CompanyId }, token);
            var currencyTask = currencyQueryProcessor.GetAsync(new CurrencySearch {
                CompanyId = source.CompanyId, Codes = new[] { DefaultCurrencyCode },
            }, token);
            var agencyTask = paymentAgencyGetByIdsQueryProcessor.GetByIdsAsync(new[] { source.PaymentAgencyId }, token);

            await Task.WhenAll(companyTask, currencyTask, agencyTask);

            var company  = companyTask.Result.First();
            var currency = currencyTask.Result.First();
            var agency   = agencyTask.Result.First();

            var helper = new Helper {
                GetBillingsAsync  = async(companyId, paymentAgencyId, dueAt) => (await billingQueryProcessor.GetAccountTransferMatchingTargetListAsync(paymentAgencyId, dueAt, currency.Id)).ToList(),
                GetCustomersAsync = async(ids) => (await customerQueryProcessor.GetAsync(new CustomerSearch {
                    Ids = ids,
                }, token)).ToDictionary(x => x.Id),
            };
            var reader = helper.CreateReader((AccountTransferFileFormatId)agency.FileFormatId);

            reader.CompanyId         = company.Id;
            reader.AggregateBillings = company.TransferAggregate == 1;
            reader.PaymentAgencyId   = agency.Id;
            reader.TransferYear      = source.TransferYear;
            reader.Encoding          = encoding;
            reader.FileName          = source.FileName;
            reader.IsAsync           = true;
            reader.IsPlainText       = true;

            var sources = await reader.ReadAsync(csv);

            var data = new ImportData {
                CompanyId = source.CompanyId,
                FileName  = source.FileName,
                FileSize  = encoding.GetByteCount(csv),
                CreateBy  = source.LoginUserId,
            };

            data.Details = sources.Select(x => new ImportDataDetail {
                ObjectType = 0,
                RecordItem = serializer.PackSingleObject(x),
            }).ToArray();

            var dataSaved = await importDataProcessor.SaveAsync(data, token);

            var result = new AccountTransferImportResult {
                ImportData    = dataSaved,
                ProcessResult = new ProcessResult {
                    Result = true
                },
            };

            for (var i = 0; i < sources.Count; i++)
            {
                result.ReadCount++;
                if (sources[i].TransferResultCode == 0)
                {
                    result.ValidCount++;
                    result.ValidAmount += sources[i].TransferAmount;
                }
                else
                {
                    result.InvalidCount++;
                    result.InvalidAmount += sources[i].TransferAmount;
                }
            }
            result.InvalidSources = sources.Where(x => x.TransferResultCode != 0 || !(x.Billings?.Any() ?? false)).ToList();
            result.Logs           = sources.SelectMany(x => x.GetInvalidLogs()).ToList();

            return(result);
        }
Example #36
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (_worker != null && _worker.IsBusy)
             {
            return;
             }

             _waitCursor = new WaitCursor();

             EnableDisable(false);

             progressBar1.Minimum = 0;
             progressBar1.Maximum = 100;
             progressBar1.Value = 0;

             _worker = new BackgroundWorker
            {
               WorkerReportsProgress = true,
               WorkerSupportsCancellation = true

            };
             _worker.ProgressChanged += (o, args) => progressBar1.Value = args.ProgressPercentage;
             _worker.DoWork += backgroundWorker_DoWork;
             _worker.RunWorkerCompleted += backgroundWorker_Completed;

             var addresses = new List<string>();
             foreach (ListViewItem item in listItems.Items)
             {
            addresses.Add(item.Text);
             }

             var data = new ImportData()
            {
               Addresses = addresses,
               DeleteRecipientsNotInImportFile = ucDeleteRecipientsNotInList.Checked
            };

             _worker.RunWorkerAsync(data);
        }
Example #37
0
        private void DoImport(IProgressMonitor monitor,
                              String importFileName, String targetFileName,
                              bool silent, IMessageBoxProvider messageBoxProvider,
                              System.Action <Exception, bool> dataLoaded)
        {
            m_Monitor        = monitor;
            m_DataLoadedFunc = dataLoaded;
            try
            {
                long overallSize          = 0;
                bool overWrite            = true;
                bool hasAskedForOverwrite = silent;
                bool hasInnerFile         = false;
                using (ZipFile file = CreateZipFile(importFileName))
                {
                    for (int i = 0; i < file.Count; ++i)
                    {
                        ZipEntry entry = file[i];
                        if (entry.IsDirectory)
                        {
                            continue;
                        }
                        bool   isTagsDbFile;
                        String fileName = GetFileName(entry, out isTagsDbFile);
                        if (fileName == String.Empty)
                        {
                            if (hasInnerFile)
                            {
                                throw new ArgumentException(StringResources.InvalidImportFile);
                            }
                            else
                            {
                                hasInnerFile = true;
                                overallSize += entry.Size;
                            }
                        }
                        else if (isTagsDbFile)
                        {
                            overallSize += entry.Size;
                        }
                        else if (FileHelpers.FileExists(fileName))
                        {
                            if (!hasAskedForOverwrite)
                            {
                                switch (messageBoxProvider.ShowYesNoCancelBox(StringResources.ImportOverwrite))
                                {
                                case MessageBoxResult.Yes:
                                    overWrite            = true;
                                    hasAskedForOverwrite = true;
                                    break;

                                case MessageBoxResult.No:
                                    overWrite            = false;
                                    hasAskedForOverwrite = true;
                                    break;

                                default:
                                    return;
                                }
                            }
                            if (overWrite)
                            {
                                overallSize += entry.Size;
                            }
                        }
                        else
                        {
                            overallSize += entry.Size;
                        }
                    }
                    if (!hasInnerFile)
                    {
                        throw new ArgumentException(StringResources.InvalidImportFile);
                    }
                }
                ImportData data = new ImportData();
                data.Overwrite   = overWrite;
                data.ImportFile  = importFileName;
                data.TargetFile  = targetFileName;
                data.OverallSize = overallSize;
                m_Worker         = new System.ComponentModel.BackgroundWorker();
                m_Worker.WorkerReportsProgress      = true;
                m_Worker.WorkerSupportsCancellation = true;
                m_Worker.DoWork             += new System.ComponentModel.DoWorkEventHandler(m_Worker_DoWork);
                m_Worker.ProgressChanged    += new System.ComponentModel.ProgressChangedEventHandler(m_Worker_ProgressChanged);
                m_Worker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(m_Worker_RunWorkerCompleted);
                m_Monitor.SetProgress(0, String.Empty);
                m_Worker.RunWorkerAsync(data);
            }
            catch (Exception ex)
            {
                if (dataLoaded != null)
                {
                    dataLoaded(ex, false);
                }
            }
        }
Example #38
0
        public void GetData(ITable table)
        {
            var wizrd = new ImportData(table);

            wizrd.ShowDialog();
        }