Esempio n. 1
0
        static void Main(string[] args)
        {
            System.Collections.Queue queue = new System.Collections.Queue();
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);

            Console.WriteLine("1 in Queue:{0}", queue.Contains(1));

            Console.WriteLine("Remove 1:{0}", queue.Dequeue());

            Console.WriteLine("Peek1:{0}", queue.Peek());

            object[] numArray = queue.ToArray();
            Console.WriteLine(string.Join(", ", numArray));
        }
Esempio n. 2
0
        public static System.Collections.Queue SortQueue(System.Collections.Queue pila, Boolean Order)
        {
            object[] vectorA = pila.ToArray();

            int aux1;

            if (Order)
            {
                for (int i = 0; i < vectorA.Length - 1; i++)
                {
                    for (int j = i + 1; j < vectorA.Length; j++)
                    {
                        if ((int)vectorA[i] < (int)vectorA[j])
                        {
                            aux1       = (int)vectorA[i];
                            vectorA[i] = vectorA[j];
                            vectorA[j] = aux1;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < vectorA.Length - 1; i++)
                {
                    for (int j = i + 1; j < vectorA.Length; j++)
                    {
                        if ((int)vectorA[i] > (int)vectorA[j])
                        {
                            aux1       = (int)vectorA[i];
                            vectorA[i] = vectorA[j];
                            vectorA[j] = aux1;
                        }
                    }
                }
            }

            System.Collections.Queue pila1 = new System.Collections.Queue();

            for (int i = 0; i < vectorA.Length - 1; i++)
            {
                pila1.Enqueue((int)vectorA[i]);
            }

            return(pila1);
        }
Esempio n. 3
0
        /// <summary>
        /// Registers the index of the and starting offset.
        /// </summary>
        /// <returns>System.Int32.</returns>
        private int RegisterAndStartingOffsetIndex()
        {
            lock (CurrentlyVisible)
            {
                CurrentlyVisible.Enqueue(Frm);

                if (CurrentlyVisible.Count <= 1)
                {
                    return(0);
                }

                bool[] Poss = new bool[GetFreeCount()];
                for (int Idx = 0; Idx < Poss.Length; Idx++)
                {
                    Poss[Idx] = true;
                }

                foreach (TrayBalloonFrm XFrm in CurrentlyVisible.ToArray())
                {
                    if (!(XFrm == Frm))
                    {
                        if (XFrm.StartingOffsetIndex < Poss.Length)
                        {
                            Poss[XFrm.StartingOffsetIndex] = false;
                        }
                    }
                }

                for (int Idx = 0; Idx < Poss.Length; Idx++)
                {
                    if (Poss[Idx] == true)
                    {
                        return(Idx);
                    }
                }

                return(Poss.Length - 1);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor</summary>
        static Resources()
        {
            // Because GUI framework-specific dependencies have been removed from Atf.Gui, resource
            // registration has been moved to another assembly on which we cannot be dependent.  Use
            // reflection to locate and invoke the "unknown" registration method.
            //
            // Create LINQ expression to collect all implementations of method
            //   public static void Register(Type type);
            // defined in classes named "ResourceUtil"
            var methodInfos = from assembly in AppDomain.CurrentDomain.GetAssemblies()
                              where assembly.FullName.StartsWith("Atf.Gui.WinForms")
                              from type in assembly.GetExportedTypes()
                              where type.Name == "ResourceUtil"
                              from methodInfo in type.GetMethods()
                              where methodInfo.Name == "Register" &&
                              methodInfo.IsStatic &&
                              methodInfo.IsPublic &&
                              methodInfo.ReturnType == typeof(void) &&
                              methodInfo.GetParameters().Length == 1 &&
                              methodInfo.GetParameters()[0].ParameterType == typeof(Type)
                              select methodInfo;

            // Invoke the first found implementation of "public static void Register(Type type)"
            // throw an assertion if there is more than one found
            bool registerCalled = false;

            foreach (var methodInfo in methodInfos)
            {
                if (registerCalled)
                {
                    throw new InvalidOperationException("More than one implementation of ResourceUtil.Register(Type type) has been found.  Only the first one will be called.");
                }

                var paramQueue = new System.Collections.Queue(1);
                paramQueue.Enqueue(typeof(Resources));
                methodInfo.Invoke(null, paramQueue.ToArray());
                registerCalled = true;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Constructor</summary>
        static Resources()
        {
            // GUI framework-specific registration is done in assemblies on which this library shouldn't depend.
            // Regardless, said assemblies still need to register the resources defined in here.
            //
            // Use reflection to:
            //   - locate the any registration classes (hopefully there's at least one)
            //   - determine whether they've begun registration (then nothing needs be done here)
            //   - if they haven't, call their registration method from here

            const string kRegistrationStarted = "RegistrationStarted";
            const string kRegister            = "Register";

            // all types named ResourceUtil
            var types = (from a in AppDomain.CurrentDomain.GetAssemblies()
                         where !a.IsDynamic
                         from t in a.GetExportedTypes()
                         where t.Name == "ResourceUtil"
                         select t).ToArray();

            // the results of calling ResourceUtil.RegistrationStarted, for each type
            var regStarted = from t in types
                             from p in t.GetProperties()
                             where
                             p.Name == kRegistrationStarted &&
                             p.PropertyType == typeof(bool) &&
                             p.GetGetMethod().IsPublic&&
                             p.GetGetMethod().IsStatic
                             select(bool)(p.GetGetMethod().Invoke(null, new object[] {}));

            // if registration has already begun in one of these, we don't need to initiate it
            if (regStarted.Any(p => p))
            {
                return;
            }

            // otherwise, get the registration methods
            var registerMethods = (from t in types
                                   from m in t.GetMethods()
                                   where m.Name == kRegister &&
                                   m.IsStatic &&
                                   m.IsPublic &&
                                   m.ReturnType == typeof(void) &&
                                   m.GetParameters().Length == 1 &&
                                   m.GetParameters()[0].ParameterType == typeof(Type)
                                   select m).ToArray();

            // if there's more than one registration method available, we have no idea which should be used.
            // The application will have to determine this, by calling one of the methods explicitly,
            // before execution arrives at this call path.
            if (registerMethods.Length > 1)
            {
                throw new InvalidOperationException(
                          "More than one library has implemented a ResourceUtil.Register(Type type).\n" +
                          "This is allowed, but one or the other method must be called explicitly,\n" +
                          "before the app calls this static constructor.");
            }

            // Initiate registration. Set the RegistrationStarted property so we only auto-initiate once.
            var setRegStarted = from t in types
                                from p in t.GetProperties()
                                where
                                p.Name == kRegistrationStarted &&
                                p.PropertyType == typeof(bool) &&
                                p.GetSetMethod().IsPublic&&
                                p.GetSetMethod().IsStatic
                                select p;

            setRegStarted.First().GetSetMethod().Invoke(null, new object[] { true });

            var paramQueue = new System.Collections.Queue(1);

            paramQueue.Enqueue(typeof(Resources));
            registerMethods.First().Invoke(null, paramQueue.ToArray());
        }
Esempio n. 6
0
        /// <summary>
        /// Constructor</summary>
        static Resources()
        {
            // Because GUI framework-specific dependencies have been removed from Atf.Gui, resource
            // registration has been moved to another assembly on which we cannot be dependent.  Use
            // reflection to locate and invoke the "unknown" registration method.
            //
            // Create LINQ expression to collect all implementations of method 
            //   public static void Register(Type type);
            // defined in classes named "ResourceUtil"
            var methodInfos = from assembly in AppDomain.CurrentDomain.GetAssemblies()
                              where assembly.FullName.StartsWith("Atf.Gui.WinForms")
                              from type in assembly.GetExportedTypes()
                              where type.Name == "ResourceUtil"
                              from methodInfo in type.GetMethods()
                              where methodInfo.Name == "Register"
                                  && methodInfo.IsStatic
                                  && methodInfo.IsPublic
                                  && methodInfo.ReturnType == typeof(void)
                                  && methodInfo.GetParameters().Length == 1
                                  && methodInfo.GetParameters()[0].ParameterType == typeof(Type)
                              select methodInfo;

            // Invoke the first found implementation of "public static void Register(Type type)"
            // throw an assertion if there is more than one found
            bool registerCalled = false;
            foreach (var methodInfo in methodInfos)
            {
                if (registerCalled)
                    throw new InvalidOperationException("More than one implementation of ResourceUtil.Register(Type type) has been found.  Only the first one will be called.");

                var paramQueue = new System.Collections.Queue(1);
                paramQueue.Enqueue(typeof(Resources));
                methodInfo.Invoke(null, paramQueue.ToArray());
                registerCalled = true;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Constructor</summary>
        static Resources()
        {
            // GUI framework-specific registration is done in assemblies on which this library shouldn't depend.
            // Regardless, said assemblies still need to register the resources defined in here.
            //
            // Use reflection to:
            //   - locate the any registration classes (hopefully there's at least one)
            //   - determine whether they've begun registration (then nothing needs be done here)
            //   - if they haven't, call their registration method from here

            const string kRegistrationStarted = "RegistrationStarted";
            const string kRegister = "Register";

            // all types named ResourceUtil
            var types = (from a in AppDomain.CurrentDomain.GetAssemblies()
                        where !a.IsDynamic
                        from t in a.GetExportedTypes()
                        where t.Name == "ResourceUtil"
                        select t).ToArray();

            // the results of calling ResourceUtil.RegistrationStarted, for each type
            var regStarted =    from t in types 
                                from p in t.GetProperties()
                                where 
                                    p.Name == kRegistrationStarted &&
                                    p.PropertyType == typeof(bool) &&
                                    p.GetGetMethod().IsPublic &&
                                    p.GetGetMethod().IsStatic
                                select (bool)(p.GetGetMethod().Invoke(null, new object[] {}));

            // if registration has already begun in one of these, we don't need to initiate it
            if (regStarted.Any(p => p))
                return;

            // otherwise, get the registration methods
            var registerMethods =   (from t in types
                                    from m in t.GetMethods()
                                    where m.Name == kRegister &&
                                            m.IsStatic &&
                                            m.IsPublic &&
                                            m.ReturnType == typeof(void) &&
                                            m.GetParameters().Length == 1 &&
                                            m.GetParameters()[0].ParameterType == typeof(Type)
                                    select m).ToArray();

            // if there's more than one registration method available, we have no idea which should be used.
            // The application will have to determine this, by calling one of the methods explicitly,
            // before execution arrives at this call path.
            if (registerMethods.Length > 1)
            {
                throw new InvalidOperationException(
                    "More than one library has implemented a ResourceUtil.Register(Type type).\n" +
                    "This is allowed, but one or the other method must be called explicitly,\n" +
                    "before the app calls this static constructor.");
            }

            // Initiate registration. Set the RegistrationStarted property so we only auto-initiate once.
            var setRegStarted = from t in types
                                from p in t.GetProperties()
                                where
                                     p.Name == kRegistrationStarted &&
                                     p.PropertyType == typeof(bool) &&
                                     p.GetSetMethod().IsPublic &&
                                     p.GetSetMethod().IsStatic
                                select p;
            setRegStarted.First().GetSetMethod().Invoke(null, new object[] { true });

            var paramQueue = new System.Collections.Queue(1);
            paramQueue.Enqueue(typeof(Resources));
            registerMethods.First().Invoke(null, paramQueue.ToArray());
        }
Esempio n. 8
0
        /// <summary>
        /// Writes buffered text to file
        /// </summary>
        /// <returns></returns>
        public bool WriteToFile()
        {
            //Write text to output file
            bool result = true;

            System.IO.StreamWriter file = null;
            try
            {
                //Delete existing file if required
                if (OutputStyle == WriteStyle.Overwrite)
                {
                    if (System.IO.File.Exists(OutputFileName))
                    {
                        try
                        {
                            System.IO.File.Delete(OutputFileName);
                        }
                        catch { }
                    }
                }

                //Create output folder if required
                string outputFolder = System.IO.Path.GetDirectoryName(OutputFileName);
                if (!System.IO.Directory.Exists(outputFolder))
                {
                    System.IO.Directory.CreateDirectory(outputFolder);
                }

                //Open file
                file = new System.IO.StreamWriter(OutputFileName, true);

                //Get sync locked queue
                System.Collections.Queue syncQueue = Synchronized(this);

                //Copy queue to array
                object[] textList = syncQueue.ToArray();

                //Construct output text
                System.Text.StringBuilder outputText = new StringBuilder();
                if (OutputStyle == WriteStyle.Append)
                {
                    //Add each text string in queue
                    foreach (string textEntry in textList)
                    {
                        outputText.Append(textEntry);
                    }
                }
                else
                {
                    //Add last text string in queue
                    outputText.Append(textList[textList.Length - 1]);
                }

                //Write to file
                file.Write(outputText.ToString());

                //Empty array
                syncQueue.Clear();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                result = false;
            }
            finally
            {
                if (file != null)
                {
                    file.Dispose();
                }
            }
            return(result);
        }
Esempio n. 9
0
 public System.Object[] ToArray()
 {
     CreateQueue();
     return(Queue.ToArray());
 }