예제 #1
0
        static public bool ReprocessTillComplete <T>(this IEnumerable <T> item, TryProcess <T> process)
        {
            if (item != null)
            {
                int total_number          = 0;
                int previous_total_number = 0;

                int number_failed          = 0;
                int previous_number_failed = 0;

                do
                {
                    previous_total_number  = total_number;
                    previous_number_failed = number_failed;

                    number_failed = item.Count(i => process(i) == false, out total_number);
                } while (number_failed > 0 || total_number != previous_total_number);

                if (number_failed <= 0)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
            public MessageProcessor(Syncronizer s, TryProcess <Buffer> r)
            {
                message_queue           = new List <Buffer>();
                sequenced_message_queue = new Dictionary <int, Buffer>();
                ordered_message_queue   = new Dictionary <int, List <Buffer> >();

                read_process = r;

                syncronizer = s;
            }
예제 #3
0
        public void Touch(string label, TryProcess process, bool create_undo_state)
        {
            if (target_type.CanBeTreatedAs <UnityEngine.Object>())
            {
                if (create_undo_state)
                {
                    Undo.RecordObjects(
                        objects.Convert <UnityEngine.Object>().ToArray(),
                        label
                        );
                }

                if (process())
                {
                    objects
                    .Convert <IEditSerializationCallbackReciever>()
                    .Process(r => r.OnBeforeEditSerialize());

                    objects
                    .Convert <ISerializationCallbackReceiver>()
                    .Process(r => r.OnBeforeSerialize());

                    objects
                    .Convert <UnityEngine.Object>()
                    .Narrow(o => o.IsPrefabInstance())
                    .Process(o => PrefabUtility.RecordPrefabInstancePropertyModifications(o));

                    objects
                    .Convert <UnityEngine.Object>()
                    .Skip(o => o.IsSceneObject())
                    .Process(o => EditorUtility.SetDirty(o));
                }

                if (create_undo_state)
                {
                    Undo.FlushUndoRecordObjects();
                }
            }
            else
            {
                if (parent != null)
                {
                    parent.Touch(label, process, create_undo_state);
                }
                else
                {
                    process();
                }
            }
        }
예제 #4
0
        static public bool ProcessOR <T>(this IEnumerable <T> item, TryProcess <T> process)
        {
            bool return_value = false;

            if (item != null)
            {
                foreach (T sub_item in item)
                {
                    return_value |= process(sub_item);
                }
            }

            return(return_value);
        }
예제 #5
0
        static public AttemptResult AttemptRead(this StreamSystem item, string path, TryProcess <Stream> process, long milliseconds = StreamSystem.DEFAULT_WAIT)
        {
            Stream        stream;
            AttemptResult result = item.OpenStreamForReading(path, out stream, milliseconds);

            using (stream)
            {
                if (result.IsDesired())
                {
                    if (process(stream) == false)
                    {
                        result = AttemptResult.Failed;
                    }
                }
            }

            return(result);
        }
예제 #6
0
        static public bool ProcessTillComplete <T>(this IEnumerable <T> item, TryProcess <T> process)
        {
            if (item != null)
            {
                List <T> failed = new List <T>(item);

                do
                {
                    failed.RemoveAll(delegate(T sub_item) {
                        return(process(sub_item));
                    });
                }while (failed.IsNotEmpty());

                if (failed.IsEmpty())
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
 static public AttemptResult AttemptRead(this StreamSystemStream item, TryProcess <Stream> process, long milliseconds = StreamSystem.DEFAULT_WAIT)
 {
     return(item.GetStreamSystem().AttemptRead(item.GetPath(), process, milliseconds));
 }
예제 #8
0
        protected Message CreateMessage(MessageType type, NetDeliveryMethod delivery_method, TryProcess <Buffer> process)
        {
            bool is_valid = false;

            Message message = CreateMessage(type, delivery_method, delegate(Buffer buffer) {
                is_valid = process(buffer);
            });

            if (is_valid)
            {
                return(message);
            }

            return(null);
        }
예제 #9
0
        static public bool ProcessTillCompleteOrStagnated <T>(this IEnumerable <T> item, TryProcess <T> process)
        {
            if (item != null)
            {
                int      old_count;
                List <T> failed = new List <T>(item);

                do
                {
                    old_count = failed.Count;

                    failed.RemoveAll(delegate(T sub_item) {
                        return(process(sub_item));
                    });
                }while (failed.IsNotEmpty() && old_count != failed.Count);

                if (failed.IsEmpty())
                {
                    return(true);
                }
            }

            return(false);
        }