Exemplo n.º 1
0
        private void LoadLine()
        {
            if (tt.Stations.Count != 0)
            {
                return;
            }
            if (info.Timetable.Type == TimetableType.Network)
            {
                throw new Exception("Streckendateien können bei Netzwerk-Fahrplänen nicht geladen werden!");
            }

            IImport timport = new XMLImport();
            IImport simport = new NonDefaultFiletypes.XMLStationsImport();

            using (var ofd = new OpenFileDialog())
            {
                ofd.AddLegacyFilter(timport.Filter, simport.Filter);

                if (ofd.ShowDialog(this) == DialogResult.Ok)
                {
                    IImport import = Path.GetExtension(ofd.FileName) == ".fpl" ? timport : simport;
                    var     ntt    = import.Import(ofd.FileName, info);
                    foreach (var station in ntt.Stations)
                    {
                        tt.AddStation(station, Timetable.LINEAR_ROUTE_ID);
                    }
                    // ntt will be destroyed by decoupling stations, do not use afterwards!
                }
            }

            UpdateStations();
        }
Exemplo n.º 2
0
        public HttpResponseMessage Upload()
        {
            HttpPostedFile file = HttpContext.Current.Request.Files["school"];

            ErrMsg         msg    = new ErrMsg();
            IImport        import = ExcelFactory.Instance().GetExcelImporter(new eh.impls.configurations.ExcelConfiguration(1, 0, 0), msg);
            IList <School> list   = SchoolDto.ToList(import.Import <SchoolDto>(file.InputStream));

            if (msg.Count != 0)
            {
                return(ToJson(msg.GetErrors(), status_code: 0, msg: "fail"));
            }
            else
            {
                try
                {
                    Service.Add(list);
                    return(ToJson("success"));
                }
                catch (SqlException ex)
                {
                    msg.AddErrMsg(ex.Message);
                    return(ToJson(msg.GetErrors(), status_code: 0, msg: "fail"));
                }
            }
        }
Exemplo n.º 3
0
        internal void Import()
        {
            var importers = info.GetRegistered <IImport>();

            if (importers.Length == 0)
            {
                info.Logger.Error("Keine Importer gefunden, Import nicht möglich!");
                return;
            }

            if (!NotifyIfUnsaved())
            {
                return;
            }
            if (importFileDialog.ShowDialog(parent) == DialogResult.Ok)
            {
                IImport import = importers[importFileDialog.CurrentFilterIndex - 1];
                info.Logger.Info("Öffne Datei " + importFileDialog.FileName);
                Timetable = import.Import(importFileDialog.FileName, info);
                if (Timetable == null)
                {
                    return;
                }
                info.Logger.Info("Datei erfolgeich geöffnet!");
                FileState.Opened   = true;
                FileState.Saved    = true;
                FileState.FileName = importFileDialog.FileName;
                undo.ClearHistory();
            }
        }
Exemplo n.º 4
0
 internal void InternalOpen(string filename)
 {
     info.Logger.Info("Öffne Datei " + filename);
     Timetable = open.Import(filename, info);
     if (Timetable == null)
     {
         info.Logger.Error("Fehler beim Öffnen der Datei!");
     }
     else
     {
         info.Logger.Info("Datei erfolgeich geöffnet!");
     }
     if (Timetable?.UpgradeMessage != null)
     {
         info.Logger.Warning(Timetable.UpgradeMessage);
     }
     FileState.Opened   = Timetable != null;
     FileState.Saved    = Timetable != null;
     FileState.FileName = Timetable != null ? filename : null;
     undo.ClearHistory();
     if (Timetable != null)
     {
         FileOpened?.Invoke(this, null);
     }
 }
Exemplo n.º 5
0
 public static Timetable?SafeImport(this IImport imp, string filename, IReducedPluginInterface pluginInterface, ILog?replaceLog = null)
 {
     try
     {
         using (var stream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read))
             return(imp.Import(stream, pluginInterface, replaceLog));
     }
     catch (Exception ex)
     {
         var log = replaceLog ?? pluginInterface.Logger;
         log.Error(imp.GetType().Name + ": " + ex.Message);
         log.LogException(ex);
         return(null);
     }
 }
Exemplo n.º 6
0
        public void TestImport()
        {
            ErrMsg         msg    = new ErrMsg();
            IImport        import = ExcelFactory.Instance().GetExcelImporter(new ExcelConfiguration(1, 0, 0), msg);
            FileStream     fs     = new FileStream(@"D:\projects\yueyouyuebei\src\TravelAgent.Web\TravelAgent.WebAPI\template\school.xls", FileMode.Open);
            IList <School> list   = import.Import <School>(fs);

            if (msg.Count != 0)
            {
                msg.GetErrors().ForEach(s => { Console.WriteLine(s); });
                return;
            }

            foreach (School item in list)
            {
                Console.WriteLine(item.ToString());
            }
        }
Exemplo n.º 7
0
        private static async Task <bool> RunImport(IImport operation, bool depends = true)
        {
            var name = operation.GetType().GetCustomAttributes(typeof(OperationAttribute), true).FirstOrDefault() as OperationAttribute;

            var start = DateTime.UtcNow;

            Logger.Info("**************************************************************");
            Logger.Info($"   Running operation {name.Name}");
            Logger.Info("**************************************************************");


            if (!await operation.Import().ConfigureAwait(false))
            {
                Logger.Info("ERROR - Failed to seed entities!");
                return(false);
            }

            Logger.Info("**************************************************************");
            Logger.Info($"   Finished operation {name.Name} in {DateTime.UtcNow - start}");
            Logger.Info("**************************************************************");

            return(true);
        }
Exemplo n.º 8
0
 /// <summary>
 /// インポート実行
 /// </summary>
 /// <param name="import"></param>
 public bool Import(IImport import) => import.Import(_Model);