示例#1
0
        Session()
        {
            This_ = this;

            Log.Writer.Exitig += ThreadLog_Exitig;

            input_item_type_name2input_item_types = (from t in Assembly.GetEntryAssembly().GetTypes() where t.BaseType == typeof(InputItem) select t).ToDictionary(t => t.Name, t => t);
            Cliver.Bot.InputItem.Initialize(input_item_type_name2input_item_types.Values.ToList());
            work_item_type_name2work_item_types = (from t in Assembly.GetEntryAssembly().GetTypes() where (t.BaseType == typeof(WorkItem) && t.Name != typeof(SingleValueWorkItem <>).Name) || (t.BaseType != null && t.BaseType.Name == typeof(SingleValueWorkItem <>).Name) select t).ToDictionary(t => t.Name, t => t);
            Cliver.Bot.WorkItem.Initialize(work_item_type_name2work_item_types.Values.ToList());
            //tag_item_type_name2tag_item_types = (from t in Assembly.GetEntryAssembly().GetTypes() where (t.BaseType == typeof(TagItem) && t.Name != typeof(SingleValueTagItem<>).Name) || (t.BaseType != null && t.BaseType.Name == typeof(SingleValueTagItem<>).Name) select t).ToDictionary(t => t.Name, t => t);
            tag_item_type_name2tag_item_types = (from t in Assembly.GetEntryAssembly().GetTypes() where t.BaseType == typeof(TagItem) select t).ToDictionary(t => t.Name, t => t);
            Cliver.Bot.TagItem.Initialize(tag_item_type_name2tag_item_types.Values.ToList());
            if (input_item_type_name2input_item_types.Count < 1)
            {
                throw new Exception("No InputItem derive was found");
            }

            workflow_xtw            = new XmlTextWriter(Log.SessionDir + "\\" + STATES_FILE_NAME, Encoding.UTF8);
            workflow_xtw.Formatting = Formatting.Indented;
            workflow_xtw.WriteStartDocument();
            workflow_xtw.WriteStartElement("Session");

            if (Properties.General.Default.WriteSessionRestoringLog)
            {
                items_xtw            = new XmlTextWriter(Log.SessionDir + "\\" + ITEMS_FILE_NAME, Encoding.UTF8);
                items_xtw.Formatting = Formatting.Indented;
                items_xtw.WriteStartDocument();
                items_xtw.WriteStartElement("Items");
            }

            Restored = false;
            if (Properties.General.Default.RestoreBrokenSession && !ProgramRoutines.IsParameterSet(CommandLineParameters.NOT_RESTORE_SESSION))
            {
                Restored = this.restore(ref StartTime);
                if (This == null)
                {
                    return;
                }
            }
            if (!Restored)
            {
                StartTime = DateTime.Now;
                Log.Main.Write("No session was restored so reading input Items from the input file");
                read_input_file();
            }

            try
            {
                CustomizationApi.SessionCreating();
            }
            catch (Exception e)
            {
                LogMessage.Error("SessionCreating: " + Log.GetExceptionMessage(e));
                Close();
                return;
            }

            set_session_state(SessionState.STARTED, "session_start_time", StartTime.ToString("yyyy-MM-dd HH:mm:ss"));
        }
示例#2
0
        static Program()
        {
            Config.Initialize();

            Mode = (ProgramRoutines.IsParameterSet(CommandLineParameters.AUTOMATIC) || Properties.General.Default.RunSilently) ? ProgramMode.AUTOMATIC : ProgramMode.DIALOG;
            LogMessage.DisableStumblingDialogs = Mode == ProgramMode.AUTOMATIC;

            if (ProgramRoutines.IsParameterSet(CommandLineParameters.PRODUCTION))
            {
                Properties.General.Default.RestoreBrokenSession     = true;
                Properties.General.Default.RestoreErrorItemsAsNew   = false;
                Properties.General.Default.WriteSessionRestoringLog = true;
                Properties.Log.Default.LogDownloadedFiles           = false;
                Properties.General.Default.UseFilesFromCache        = false;
            }

            AssemblyName ean = Assembly.GetEntryAssembly().GetName();
            string       customization_title = ean.Name;

            if (ean.Version.Major > 0 || ean.Version.Minor > 0)
            {
                customization_title += ean.Version.Major + "." + ean.Version.Minor;
            }
            //CustomizationModificationTime = File.GetLastWriteTime(Log.AppDir + "\\" + ean);
            AssemblyName can             = Assembly.GetExecutingAssembly().GetName();
            string       CliverBot_title = can.Name;

            if (can.Version.Major > 0 || can.Version.Minor > 0)
            {
                CliverBot_title += can.Version.Major + "." + can.Version.Minor;
            }
            Title = customization_title + @" / " + CliverBot_title;

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }
示例#3
0
        static Program()
        {
            Log.Initialize(Log.Mode.SESSIONS, Cliver.Bot.Properties.Log.Default.PreWorkDir, Cliver.Bot.Properties.Log.Default.WriteLog, Cliver.Bot.Properties.Log.Default.DeleteLogsOlderDays);

            LogMessage.DisableStumblingDialogs = true;

            if (ProgramRoutines.IsParameterSet(CommandLineParameters.PRODUCTION))
            {
                Properties.General.Default.RestoreBrokenSession     = true;
                Properties.General.Default.RestoreErrorItemsAsNew   = false;
                Properties.General.Default.WriteSessionRestoringLog = true;
                Properties.Log.Default.LogDownloadedFiles           = false;
                Properties.General.Default.UseFilesFromCache        = false;
            }

            AssemblyName ean = Assembly.GetEntryAssembly().GetName();
            string       customization_title = ean.Name;

            if (ean.Version.Major > 0 || ean.Version.Minor > 0)
            {
                customization_title += ean.Version.Major + "." + ean.Version.Minor;
            }
            //CustomizationModificationTime = File.GetLastWriteTime(Log.AppDir + "\\" + ean);
            AssemblyName can             = Assembly.GetExecutingAssembly().GetName();
            string       CliverBot_title = can.Name;

            if (can.Version.Major > 0 || can.Version.Minor > 0)
            {
                CliverBot_title += can.Version.Major + "." + can.Version.Minor;
            }
            Title = customization_title + @" / " + CliverBot_title;

            AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args)
            {
                Exception e = (Exception)args.ExceptionObject;
                Log.Main.Exit(e);
            };
        }
示例#4
0
            override protected void Loaded()
            {
                if (FileName == null)
                {
                    if (FileFormat == FileFormatEnum.NULL)
                    {
                        FileFormat = FileFormatEnum.TSV;
                    }
                    string file_name = ProgramRoutines.GetAppName();
                    switch (FileFormat)
                    {
                    case FileFormatEnum.CSV:
                        FileName = file_name + ".csv";
                        break;

                    case FileFormatEnum.TSV:
                        FileName = file_name + ".tsv";
                        break;

                    case FileFormatEnum.XLS:
                        throw new Exception("XLS format not implemented.");

                    default:
                        throw new Exception("Unknown option: " + FileFormat);
                    }
                }
                else
                {
                    if (FileFormat == FileFormatEnum.NULL)
                    {
                        switch (PathRoutines.GetFileExtension(FileName).ToLower())
                        {
                        case "csv":
                            FileFormat = FileFormatEnum.CSV;
                            break;

                        case "txt":
                        case "tsv":
                        case "tab":
                            FileFormat = FileFormatEnum.TSV;
                            break;

                        default:
                            throw new Exception("Unknown option: " + PathRoutines.GetFileExtension(FileName).ToLower());
                        }
                    }
                }
                switch (FileFormat)
                {
                case FileFormatEnum.CSV:
                    FieldSeparator = Cliver.FieldPreparation.FieldSeparator.COMMA;
                    break;

                case FileFormatEnum.TSV:
                    FieldSeparator = Cliver.FieldPreparation.FieldSeparator.TAB;
                    break;

                case FileFormatEnum.XLS:
                    throw new Exception("XLS format not implemented.");

                case FileFormatEnum.NULL:
                    throw new Exception("File format not defined.");

                default:
                    throw new Exception("Unknown option: " + FileFormat);
                }
            }