Exemplo n.º 1
0
 /// <summary>
 /// Must be used only for InputItems created by own constructor
 /// if InputItem was created by own constructor, its base parameters should be set
 /// </summary>
 /// <typeparam name="ItemT"></typeparam>
 /// <param name="parent_item"></param>
 /// <param name="item"></param>
 /// <returns></returns>
 static internal bool Add2Queue <ItemT>(InputItemQueue queue, InputItem parent_item, ItemT item) where ItemT : InputItem
 {
     item.set_parent_members(parent_item);
     item.set_tag_item_members();
     typeof(Item).GetField("__Id", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(item, Session.This.GetNewItemId());
     return(item.add2queue(queue));
 }
Exemplo n.º 2
0
        void read_input_file()
        {
            Type           start_input_item_type  = (from t in Assembly.GetEntryAssembly().GetTypes() where t.IsSubclassOf(typeof(InputItem)) && !t.IsGenericType select t).First();
            InputItemQueue start_input_item_queue = GetInputItemQueue(start_input_item_type.Name);

            CustomizationApi.FillStartInputItemQueue(start_input_item_queue, start_input_item_type);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This is the ONLY method to add a queue!
        /// When a queue is constructed dynamicly, it is possible to set its order.
        /// </summary>
        /// <param name="queue_name"></param>
        /// <param name="position"></param>
        static public void SetInputItemQueuePosition(string queue_name, int position)
        {
            lock (This.input_item_queue_name2input_item_queues)
            {
                InputItemQueue iiq = (InputItemQueue)This.input_item_queue_name2input_item_queues[queue_name];
                if (iiq == null)
                {
                    iiq = new InputItemQueue(queue_name);
                }
                else
                {
                    iiq = (InputItemQueue)This.input_item_queue_name2input_item_queues[queue_name];
                    int p = iiq.Position;
                    if (p == position)
                    {
                        return;
                    }
                    This.input_item_queue_name2input_item_queues.RemoveAt(p);
                    position--;
                }
                This.input_item_queue_name2input_item_queues.Insert(position, queue_name, iiq);

                for (int i = 0; i < This.input_item_queue_name2input_item_queues.Count; i++)
                {
                    ((InputItemQueue)This.input_item_queue_name2input_item_queues[i]).Position = i;
                }
                This.LogInputItemQueuePosition(iiq);
            }
        }
Exemplo n.º 4
0
        virtual public void __FillStartInputItemQueue(InputItemQueue start_input_item_queue, Type start_input_item_type)
        {
            Log.Main.Write("Filling queue of " + start_input_item_queue.Name + " with input file.");

            if (!File.Exists(Settings.Input.File))
            {
                throw (new Exception("Input file " + Settings.Input.File + " does not exist."));
            }

            if (Path.GetExtension(Settings.Input.File).StartsWith(".xls", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception("Reading excel is not supported");
            }

            FileReader fr = new FileReader(Settings.Input.File, Settings.Input.FileFormat);

            for (FileReader.Row r = fr.ReadLine(); r != null; r = fr.ReadLine())
            {
                InputItem.Add2QueueBeforeStart(start_input_item_queue, start_input_item_type, r.Headers.ToDictionary(x => x, x => r[x]));
            }

            if (start_input_item_queue.CountOfNew < 1)
            {
                LogMessage.Error("Input queue is empty so nothing is to do. Check your input data.");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Must be used ONLY before bot cycle started as no parent item is accepted. Usually used while feeding by input file.
        /// </summary>
        /// <param name="item_type"></param>
        /// <param name="field_value_pairs"></param>
        /// <returns></returns>
        static internal bool Add2QueueBeforeStart(InputItemQueue queue, Type item_type, Dictionary <string, string> field2value)
        {
            InputItem item = (InputItem)FormatterServices.GetUninitializedObject(item_type);
            Dictionary <string, FieldInfo> serialized_field_name2serialized_field_fis = item_types2serialized_field_names2serialized_field_fi[item_type];

            foreach (string field in field2value.Keys)
            {
                try
                {
                    FieldInfo fi = serialized_field_name2serialized_field_fis[field];
                    fi.SetValue(item, Convert.ChangeType(field2value[field], fi.FieldType));
                }
                catch (Exception e)
                {
                    throw new Exception("Field '" + field + "' does not exist.\n" + e.Message);
                }
            }

            ConstructorInfo ci;

            if (item_types2constructor_info.TryGetValue(item_type, out ci))
            {
                ci.Invoke(item, new object[] {});
            }

            typeof(Item).GetField("__Id", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(item, Session.This.GetNewItemId());
            return(item.add2queue(queue));
        }
Exemplo n.º 6
0
        void read_input_file()
        {
            Log.Main.Write("Loading InputItems from the input file.");
            Type           start_input_item_type  = (from t in Assembly.GetEntryAssembly().GetTypes() where t.IsSubclassOf(typeof(InputItem)) && !t.IsGenericType select t).First();
            InputItemQueue start_input_item_queue = GetInputItemQueue(start_input_item_type.Name);

            __FillStartInputItemQueue(start_input_item_queue, start_input_item_type);
        }
Exemplo n.º 7
0
 internal static void FillStartInputItemQueue(InputItemQueue start_input_item_queue, Type start_input_item_type)
 {
     fill_start_input_item_queue.Invoke(start_input_item_queue, start_input_item_type);
     if (start_input_item_queue.CountOfNew < 1)
     {
         LogMessage.Error("Input queue is empty so nothing is to do. Check your input data.");
     }
 }
Exemplo n.º 8
0
        static internal bool Add2Queue <ItemT>(InputItemQueue queue, InputItem parent_item, object anonymous_object) where ItemT : InputItem
        {
            ItemT item = Item.Create <ItemT>(anonymous_object);

            item.set_parent_members(parent_item);
            item.set_tag_item_members();
            return(item.add2queue(queue));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Add item to queue. It is possible to create a named queue.
        /// Preferred method for adding items.
        /// </summary>
        /// <param name="queue_name"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Add(string queue_name, InputItem item)
        {
            if (queue_name == null)
            {
                queue_name = item.GetType().Name;
            }
            InputItemQueue iiq = Session.GetInputItemQueue(queue_name);

            return(InputItem.Add2Queue(iiq, current_item, item));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Add item to queue. It is possible to create a named queue.
        /// It is the same like BotCycle.Add() but not so efficient.
        /// </summary>
        /// <param name="queue_name"></param>
        /// <param name="item"></param>
        static public bool Add(string queue_name, InputItem item)
        {
            if (queue_name == null)
            {
                queue_name = item.GetType().Name;
            }
            InputItemQueue iiq = Session.GetInputItemQueue(queue_name);

            return(InputItem.Add2Queue(iiq, BotCycle.GetCurrentInputItemForThisThread(), item));
        }
Exemplo n.º 11
0
        internal static InputItem Restore(InputItemQueue queue, Type item_type, string item_seed, int item_id, InputItem parent_item, Dictionary <string, TagItem> field2tag_items)
        {
            InputItem item = (InputItem)Item.Restore(item_type, item_seed, item_id);

            item.set_parent_members(parent_item);
            foreach (KeyValuePair <string, TagItem> kv in field2tag_items)
            {
                item_type.GetField(kv.Key).SetValue(item, kv.Value);
            }
            item.add2queue(queue);
            return(item);
        }
Exemplo n.º 12
0
            internal void WriteInputItemQueuePosition(InputItemQueue queue)
            {
                if (!Settings.Engine.WriteSessionRestoringLog)
                {
                    return;
                }

                if (!restoring)
                {
                    writeElement(QueueTag, new { name = queue.Name, position = queue.Position });
                }
            }
Exemplo n.º 13
0
 static public InputItemQueue GetInputItemQueue(string queue_name)
 {
     lock (This.input_item_queue_name2input_item_queues)
     {
         InputItemQueue iiq = (InputItemQueue)This.input_item_queue_name2input_item_queues[queue_name];
         if (iiq == null)
         {
             SetInputItemQueuePosition(queue_name, 0);
             iiq = (InputItemQueue)This.input_item_queue_name2input_item_queues[queue_name];
         }
         return(iiq);
     }
 }
Exemplo n.º 14
0
        static public void FillStartInputItemQueue(InputItemQueue start_input_item_queue, Type start_input_item_type)
        {
            Log.Main.Write("Filling queue of " + start_input_item_queue.Name + " with input file.");

            if (!File.Exists(Properties.Input.Default.InputFile))
            {
                throw (new Exception("Input file " + Properties.Input.Default.InputFile + " does not exist."));
            }

            if (Path.GetExtension(Properties.Input.Default.InputFile).StartsWith(".xls", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception("Reading excel was not implemented");
            }

            FileReader fr = new FileReader(Properties.Input.Default.InputFile, Properties.Input.Default.InputFieldSeparator);

            for (FileReader.Row r = fr.ReadLine(); r != null; r = fr.ReadLine())
            {
                InputItem.Add2QueueBeforeStart(start_input_item_queue, start_input_item_type, r.Headers.ToDictionary(x => x, x => r[x]));
            }
        }
Exemplo n.º 15
0
        //internal void LogInputItemQueueOrder()
        //{
        //    if (items_xtw == null)
        //        return;

        //    lock (this)
        //    {
        //        try
        //        {
        //            items_xtw.WriteStartElement("__QueueOrder");
        //            List<string> iiqns = new List<string>();
        //            foreach (string iiqn in input_item_queue_name2input_item_queues.Keys)
        //                iiqns.Add(iiqn);
        //            items_xtw.WriteString(string.Join("\n", iiqns));
        //            items_xtw.WriteEndElement();
        //        }
        //        catch (Exception e)
        //        {
        //            LogMessage.Exit(e);
        //        }
        //        items_xtw.Flush();
        //    }
        //}

        internal void LogInputItemQueuePosition(InputItemQueue queue)
        {
            if (items_xtw == null)
            {
                return;
            }

            lock (this)
            {
                try
                {
                    items_xtw.WriteStartElement("__Queue");
                    items_xtw.WriteAttributeString("name", queue.Name);
                    items_xtw.WriteAttributeString("position", queue.Position.ToString());
                    items_xtw.WriteEndElement();
                }
                catch (Exception e)
                {
                    LogMessage.Exit(e);
                }
                items_xtw.Flush();
            }
        }
Exemplo n.º 16
0
 void Session_InputItemQueueProgress(InputItemQueue input_item_queue, int total_item_count, int processed_item_count)
 {
     This.DisplayStatus(input_item_queue.Name, "taken " + processed_item_count.ToString() + " /remain " + (total_item_count - processed_item_count).ToString());
     if (ProgressBarInputItemQueueName == input_item_queue.Name)
         This.display_progress(total_item_count, processed_item_count);
 }
Exemplo n.º 17
0
 internal static void FillStartInputItemQueue(InputItemQueue start_input_item_queue, Type start_input_item_type)
 {
     fill_start_input_item_queue.Invoke(start_input_item_queue, start_input_item_type);
     if (start_input_item_queue.CountOfNew < 1)
         LogMessage.Error("Input queue is empty so nothing is to do. Check your input data.");
 }
Exemplo n.º 18
0
        /// <summary>
        /// Add item as dynamic object to queue. It is possible to create a named queue.
        /// It is the same like BotCycle.Add() but not so efficient and safe.
        /// </summary>
        /// <typeparam name="ItemT"></typeparam>
        /// <param name="queue_name"></param>
        /// <param name="anonymous_object"></param>
        /// <returns></returns>
        static public bool Add <ItemT>(string queue_name, object anonymous_object) where ItemT : InputItem
        {
            InputItemQueue iiq = Session.GetInputItemQueue(queue_name);

            return(InputItem.Add2Queue <ItemT>(iiq, BotCycle.GetCurrentInputItemForThisThread(), anonymous_object));
        }
Exemplo n.º 19
0
        void close()
        {
            lock (This_)
            {
                BotCycle.Abort();

                if (This.items_xtw != null)
                {
                    This.items_xtw.WriteEndElement();
                    This.items_xtw.WriteEndDocument();
                    This.items_xtw.Close();
                }

                if (This.input_item_queue_name2input_item_queues.Count > 0)
                {
                    if (This.IsUnprocessedInputItem)
                    {
                        This.set_session_state(SessionState.ABORTED);
                    }
                    else if (This.IsItem2Restore)
                    {
                        This.set_session_state(SessionState.UNCOMPLETED);
                    }
                    else
                    {
                        This.set_session_state(SessionState.COMPLETED);
                    }
                }
                This.workflow_xtw.WriteEndElement();
                This.workflow_xtw.WriteEndDocument();
                This.workflow_xtw.Close();

                try
                {
                    CustomizationApi.SessionClosing();
                }
                catch (Exception e)
                {
                    LogMessage.Error(e);
                }

                try
                {
                    if (Closing != null)
                    {
                        Closing.Invoke();
                    }
                }
                catch (Exception e)
                {
                    LogMessage.Error(e);
                }

                InputItemQueue.Close();
                FileWriter.ClearSession();
                Cache.ClearSession();
                Proxies.ClearSession();
                WebRoutine.ClearSession();
                Log.Main.Write("Closing session.");
                Cliver.Log.ClearSession();

                This_ = null;
            }
        }
Exemplo n.º 20
0
 bool add2queue(InputItemQueue queue)
 {
     __State = InputItemState.NEW;
     this.GetType().GetField("__Queue", BindingFlags.Instance | BindingFlags.Public).SetValue(this, queue);
     return(__Queue.Enqueue(this));
 }
Exemplo n.º 21
0
        void close()
        {
            lock (This_)
            {
                try
                {
                    Log.Main.Write("Closing the bot session: " + Session.State.ToString());
                    BotCycle.Abort();

                    if (This.IsUnprocessedInputItem)
                    {
                        State = SessionState.BROKEN;
                    }
                    else if (This.IsItem2Restore)
                    {
                        State = SessionState.UNCOMPLETED;
                    }
                    else
                    {
                        State = SessionState.COMPLETED;
                    }

                    This.Storage.WriteState(State, new { });

                    try
                    {
                        __Closing();
                    }
                    catch (Exception e)
                    {
                        Session.State = SessionState.FATAL_ERROR;
                        This.Storage.WriteState(State, new { });
                        LogMessage.Error(e);
                        __ErrorClosing(e.Message);
                    }

                    try
                    {
                        Closing?.Invoke();
                    }
                    catch (Exception e)
                    {
                        Session.State = SessionState.FATAL_ERROR;
                        This.Storage.WriteState(State, new { });
                        LogMessage.Error(e);
                        __ErrorClosing(e.Message);
                    }

                    InputItemQueue.Close();
                    FileWriter.ClearSession();
                }
                catch (ThreadAbortException)
                {
                }
                catch (Exception e)
                {
                    Session.State = SessionState.FATAL_ERROR;
                    This.Storage.WriteState(State, new { });
                    LogMessage.Error(e);
                    __ErrorClosing(e.Message);
                }
                finally
                {
                    Storage.Close();
                    switch (State)
                    {
                    case SessionState.NULL:
                    case SessionState.STARTING:
                    case SessionState.COMPLETED:
                    case SessionState.FATAL_ERROR:
                        Directory.Move(Dir, Dir + "_" + TimeMark + "_" + State);
                        break;

                    case SessionState.RESTORING:
                    case SessionState.RUNNING:
                    case SessionState.CLOSING:
                    case SessionState.UNCOMPLETED:
                    case SessionState.BROKEN:
                    case SessionState.NONFATAL_ERROR:
                        break;

                    default:
                        throw new Exception("Unknown option: " + State);
                    }
                    This_ = null;
                    Cliver.Log.Head.Close(false);
                }
            }

            try
            {
                Closed?.Invoke();
            }
            catch (Exception e)
            {
                LogMessage.Error(e);
                __ErrorClosing(e.Message);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Add item as dynamic object to queue. It is possible to create a named queue.
        /// Preferred method for adding items.
        /// </summary>
        /// <typeparam name="ItemT"></typeparam>
        /// <param name="queue_name"></param>
        /// <param name="anonymous_object"></param>
        /// <returns></returns>
        public bool Add <ItemT>(string queue_name, object anonymous_object) where ItemT : InputItem
        {
            InputItemQueue iiq = Session.GetInputItemQueue(queue_name);

            return(InputItem.Add2Queue <ItemT>(iiq, current_item, anonymous_object));
        }
Exemplo n.º 23
0
            internal void WriteInputItemQueuePosition(InputItemQueue queue)
            {
                if (!Settings.Engine.WriteSessionRestoringLog)
                    return;

                if (!restoring)
                    writeElement("__Queue", new { name = queue.Name, position = queue.Position });
            }
Exemplo n.º 24
0
        public static int CountOfProcessed <InputItemT>() where InputItemT : InputItem
        {
            InputItemQueue iiq = Session.GetInputItemQueue(typeof(InputItemT).Name);

            return(iiq.CountOfProcessed);
        }