Ejemplo n.º 1
0
        public void StartImport()
        {
            // Create a new study.
            Study study = new Study(Global.Core.Studies);

            study.Status = StudyStatus.ImportFailed;

            // Set the name of the study.
            study.Name = this.StudyName;

            // Set the creation date of the study.
            study.CreationDate = DateTime.Now;

            study.IdUser = Global.User.Id;

            study.IdHierarchy = this.IdHierarchy;

            study.Insert();

            this.IdStudy = study.Id;

            this.StatusFileName = Path.Combine(
                HttpContext.Current.Request.PhysicalApplicationPath,
                "Fileadmin",
                "RunningImports",
                study.Id.ToString()
                );

            File.WriteAllText(this.StatusFileName, "Step2|0");

            InitFile();

            File.WriteAllText(this.StatusFileName, "Step3|0");

            this.Reader.Study = study;

            /*ParameterizedThreadStart threadStart = new ParameterizedThreadStart(StartImportAsync);
             *
             * Thread thread = new Thread(threadStart);
             *
             * Global.RunningImports.Add(study.Id, this);
             *
             * thread.Start(new object[] {
             *  HttpContext.Current.Session,
             *  study.Id
             * });*/

            try
            {
                Process app = new Process();
                app.StartInfo.FileName = ConfigurationManager.AppSettings["DataImportApplication"];

                app.StartInfo.Arguments = string.Format(
                    "IdStudy={0} Provider={1} DatabaseProvider={2} ConnectionString={3} FileName={4} RespondentVariable={5} ApplicationPath={6} Language={7} IdLanguage={8} Debug=true",
                    study.Id,
                    this.Provider,
                    HttpUtility.UrlEncode(Global.Core.DatabaseProvider),
                    HttpUtility.UrlEncode(Global.Core.ConnectionString),
                    HttpUtility.UrlEncode(this.FileName),
                    this.RespondentVariable,
                    HttpUtility.UrlEncode(HttpContext.Current.Request.PhysicalApplicationPath),
                    Global.Language,
                    this.IdLanguage
                    );

                app.Start();
            }
            catch (Exception ex)
            {
                Log(string.Format(
                        "An error occurred while starting the import app. {0}",
                        ex.Message
                        ));
            }
        }