Clone() public method

public Clone ( ) : Object
return Object
Esempio n. 1
0
        public Gfa(ArrayList X, int S, int S0, ArrayList F, ArrayList[,] I)
        {
            setType(TYPE.Gfa);

            this.X = (ArrayList)X.Clone();
            if (!X.Contains(EPSILON))
                this.X.Add(EPSILON);

            this.Read = (ArrayList)X.Clone();
            this.S = S;
            this.S0 = S0;
            this.F = (ArrayList)F.Clone();
            InitI(I);
        }
        public void filterExceptions(int filterLength)
        {
            ArrayList cleanedWhiteList = new ArrayList();
            for (int i = 0; i < WhiteList.Count; i++)
            {
                bool contained = false;
                String exception = WhiteList[i].ToString();

                if (exception.Length > filterLength)
                {
                    exception = exception.Substring(0, filterLength);
                }

                for (int x = 0; x < cleanedWhiteList.Count; x++)
                {
                    if (cleanedWhiteList[x].ToString().StartsWith(exception))
                    {
                        contained = true;
                    }
                }
                if (!contained)
                {
                    cleanedWhiteList.Add(WhiteList[i]);
                }
            }
            WhiteList = (ArrayList)cleanedWhiteList.Clone();
            cleanedWhiteList.Clear();
            cleanedWhiteList = null;
        }
        public System.Collections.ArrayList Recombine(System.Collections.ArrayList maleGenes, System.Collections.ArrayList femaleGenes)
        {
            ArrayList child;

            if (maleGenes.Count < femaleGenes.Count)
            {
                child = femaleGenes.Clone() as ArrayList;
                for (int i = 0; i < maleGenes.Count; i++)
                {
                    if (!Convert.ToBoolean(i % 2))
                    {
                        child[i] = maleGenes[i];
                    }
                    // Deep Copy
                    child[i] = (child[i] as IGene).Clone();
                }
            }
            else
            {
                child = maleGenes.Clone() as ArrayList;
                for (int i = 0; i < femaleGenes.Count; i++)
                {
                    if (!Convert.ToBoolean(i % 2))
                    {
                        child[i] = femaleGenes[i];
                    }
                    // Deep Copy
                    child[i] = (child[i] as IGene).Clone();
                }
            }
            return(child);
        }
Esempio n. 4
0
        private void BusinessChange_Load(object sender, EventArgs e)
        {
            beList = (ArrayList)this.Tag;
            origin=(ArrayList)beList.Clone();
            user = ((BusinessEmployee)beList[0]).EmployeeId;
            dept = user.Kdid;
            business = ((BusinessEmployee)beList[0]).BusinessId;

            foreach (BusinessEmployee be in beList)
            {
                ListViewItem item = new ListViewItem();
                item.Text = be.EmployeeId.KuName;
                item.Tag = be;
                listView1.Items.Add(item);
            }

            IList udList=getUserByDept(dept);
            foreach (WkTUser ud in udList)
            {
                ListViewItem item = new ListViewItem();
                item.Text = ud.KuName;
                item.Tag = ud;
                listView2.Items.Add(item);
            }
        }
Esempio n. 5
0
        private void ThreadFunc()
        {
            ArrayList sockets = new ArrayList(2);
            sockets.Add(mClientSocket);
            sockets.Add(mServerSocket);

            while (mRunning)
            {
                IList readsockets = (IList)sockets.Clone();
                Socket.Select(readsockets, null, null, 1000000);
                foreach (Socket s in readsockets)
                {
                    int length = 0;
                    try
                    {
                        length = s.Receive(mBuffer);
                    } catch { }
                    if (length == 0)
                    {
                        mRunning = false;
                        if (ProxyDisconnected != null) ProxyDisconnected(this);
                        break;
                    }
                    Socket dest = (s == mServerSocket) ? mClientSocket : mServerSocket;
                    dest.Send(mBuffer, length, SocketFlags.None);
                }
            }
        }
Esempio n. 6
0
		/// <summary>
		/// Constructor: Initialises with the specified initial members 
		/// </summary>
		/// <param name="initial_members">Initial members of the membership</param>
		public Membership(ArrayList initial_members)
		{
			members=new ArrayList();
			if(initial_members != null)
				members = (ArrayList)initial_members.Clone();
			members = ArrayList.Synchronized(members);
		}
Esempio n. 7
0
 public PivotCommand(ArrayList objects, float X, float Y, float Z)
 {
     this.objects =(ArrayList)objects.Clone();
     this.X = X;
     this.Y = Y;
     this.Z = Z;
     pivotPoints = new ArrayList();
 }
Esempio n. 8
0
		protected BinaryPriorityQueue(ArrayList Core, IComparer Comp, bool Copy)
		{
			if(Copy)
				InnerList = Core.Clone() as ArrayList;
			else
				InnerList = Core;
			Comparer = Comp;
		}
Esempio n. 9
0
        public void TestGetItems()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            //
            // Construct array list.
            //
            arrList = new ArrayList();

            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
            {
                arrList.Add(strHeroes[ii]);
            }

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, arrList.Count);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                        (ArrayList)arrList.Clone(),
                                        (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                        (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                        (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                                        (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                        (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;
                //
                // []  Verify get method.
                //
                // Search and verify selected items.
                for (int ii = 0; ii < strHeroes.Length; ++ii)
                {
                    // Verify get.
                    Assert.Equal(0, ((string)arrList[ii]).CompareTo(strHeroes[ii]));
                }

                //
                // []  Invalid Index.
                //
                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    string str = (string)arrList[(int)arrList.Count];
                });

                Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    string str = (string)arrList[-1];
                });
            }
        }
Esempio n. 10
0
 public PGfa(ArrayList X, int S)
 {
     setType(TYPE.PGfa);
     if (!X.Contains(EPSILON))
         this.X.Add(EPSILON);
     this.X = (ArrayList)X.Clone();
     this.S = S;
     InitI();
 }
Esempio n. 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="groups"></param>
 /// <param name="strict"></param>
 public DataAffinity(ArrayList groups, bool strict)
 {
     if (groups != null)
     {
         _groups = (ArrayList) groups.Clone();
         _groups.Sort();
     }
     _strict = strict;
 }
Esempio n. 12
0
 /// <summary>
 /// initialisation de la grammaire
 /// </summary>
 /// <param name="X">l'alphabet</param>
 /// <param name="V">les variables</param>
 /// <param name="S">l'axiome</param>
 public Grammer(ArrayList X, ArrayList V, char S)
 {
     this.X = (ArrayList)X.Clone();
     this.V = V;
     this.S = S;
     this.P = new ArrayList[V.Count];
     for (int i = 0; i < V.Count; i++)
         P[i] = new ArrayList();
 }
Esempio n. 13
0
        public frmFRelatoriosTeclasAtalho(ref mdlTratamentoErro.clsTratamentoErro cls_ter_tratadorErro, string strEnderecoExecutavel, ref System.Collections.ArrayList arlTeclasAtalhoNomes, ref System.Collections.ArrayList arlTeclasAtalhoTeclas, ref System.Collections.ArrayList arlTeclasAtalhoNomesNoIni, ref System.Collections.ArrayList arlTeclasAtalhoAcoes)
        {
            m_cls_ter_tratadorErro      = cls_ter_tratadorErro;
            m_strEnderecoExecutavel     = strEnderecoExecutavel;
            m_arlTeclasAtalhoNomes      = arlTeclasAtalhoNomes;
            m_arlTeclasAtalhoTeclas     = arlTeclasAtalhoTeclas;
            m_arlTeclasAtalhoTeclasTemp = (System.Collections.ArrayList)m_arlTeclasAtalhoTeclas.Clone();
            m_arlTeclasAtalhoNomesNoIni = arlTeclasAtalhoNomesNoIni;
            m_arlTeclasAtalhoAcoes      = arlTeclasAtalhoAcoes;

            InitializeComponent();
        }
Esempio n. 14
0
 static public int Clone(IntPtr l)
 {
     try {
         System.Collections.ArrayList self = (System.Collections.ArrayList)checkSelf(l);
         var ret = self.Clone();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
		public void EqualsCollection()
		{
			ArrayList value1 = new ArrayList();
			value1.Add(10);
			value1.Add(20);

			ArrayList value2 = (ArrayList) value1.Clone();

			TypedValue t1 = new TypedValue(NHibernateUtil.Int32, value1, EntityMode.Poco);
			TypedValue t2 = new TypedValue(NHibernateUtil.Int32, value2, EntityMode.Poco);

			Assert.IsTrue(t1.Equals(t2));
		}
        public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes)
        {
            ArrayList Child = maleGenes.Clone() as ArrayList;

            bool usingMale = true;
            for (int i = 0; i < maleGenes.Count; i++)
            {
                Child[i] = usingMale ? ((IGene)maleGenes[i]).Clone() : Child[i] = ((IGene)femaleGenes[i]).Clone();
                if (i % GenesPerCrossover == 0) usingMale = !usingMale;
            }

            return Child;
        }
Esempio n. 17
0
 public RArray(NetRuby rb, ArrayList a, bool clone) :
     base(rb, rb.cArray)
 {
     if (clone)
     {
         // but it creates only a shallow copy.
         ptr = (ArrayList)a.Clone();
     }
     else
     {
         ptr = a;
     }
 }
Esempio n. 18
0
        /**
           * Takes an array of items and returns an new array of any that are
           * NOT currently in cache.
           */
        public ArrayList ItemsNotInCache(ArrayList items)
        {
            // First build a list of "new" items to add to cache
            if (!HasDataFromServer) {
                return items.Clone () as ArrayList;
            }

            var batch = new ArrayList ();
            for (int i=0; i<items.Count; i++)
                if (!Has ((items [i] as string)))
                    batch.Add (items [i]);

            return batch;
        }
Esempio n. 19
0
        /// <summary> Retransmission task:<br>
        /// For each interval, call the retransmission callback command
        /// </summary>
        public override void Run()
        {
            ArrayList cloned;

            lock (this)
            {
                cloned = (ArrayList)list.Clone();
            }
            for (int i = 0; i < cloned.Count; i += 2)
            {
                long loBound = (long)cloned[i];
                long hiBound = (long)cloned[i + 1];
                enclosingInstance.cmd.retransmit(loBound, hiBound, enclosingInstance.sender);
            }
        }
Esempio n. 20
0
        private void appendGroupFooters(Page page, ArrayList groups)
        {
            var reversedGroups = (ArrayList)groups.Clone();
            reversedGroups.Reverse();

            foreach (Group g in reversedGroups)
            {
                var o = calculator.EvaluateVariable(g.Invariant);

                if (Equals(o, g.Value) || !g.IsOpen) continue;

                g.IsOpen = false;
                PutBands(page,g.GroupFooter);
            }
        }
Esempio n. 21
0
 static int Clone(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.Collections.ArrayList obj = (System.Collections.ArrayList)ToLua.CheckObject(L, 1, typeof(System.Collections.ArrayList));
         object o = obj.Clone();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 22
0
        static void Main(string[] args)
        {
            ArrayList slot_data_list_ = new ArrayList();

            slot_data_list_.Add(new SlotData(1, "explosion", "slot_explosion"));
            slot_data_list_.Add(new SlotData(2, "steal", "slot_steal"));
            slot_data_list_.Add(new SlotData(3, "find", "slot_find"));
            slot_data_list_.Add(new SlotData(4, "crisis", "slot_crisis"));
            slot_data_list_.Add(new SlotData(5, "rest", "slot_rest"));

            ArrayList slot_data_list_copy = new ArrayList();
            slot_data_list_copy = (ArrayList)slot_data_list_.Clone();

            Console.WriteLine("Before Change Value");

            foreach (SlotData slot_data in slot_data_list_)
            {
                Console.Write("{0} ", slot_data.no_);
            }
            Console.WriteLine();

            foreach (SlotData slot_data in slot_data_list_copy)
            {
                Console.Write("{0} ", slot_data.no_);
            }
            Console.WriteLine();

            Console.WriteLine("Change Value");
            // ArrayList 의 아이템 하나의 값을 변경
            SlotData temp_slot_data = (SlotData)slot_data_list_[0];
            temp_slot_data.no_ = 99;
            slot_data_list_[0] = temp_slot_data;

            Console.WriteLine("After Change Value");
            foreach (SlotData slot_data in slot_data_list_)
            {
                Console.Write("{0} ", slot_data.no_);
            }
            Console.WriteLine();

            foreach (SlotData slot_data in slot_data_list_copy)
            {
                Console.Write("{0} ", slot_data.no_);
            }
            Console.WriteLine();
        }
Esempio n. 23
0
		public static int Main () {
			ArrayList tlist=new ArrayList(), newlist;
			T[] tarray = new T [2];
			T t1=new T("t1");
			T t2=new T("t2");
			tlist.Add(t1);
			tlist.Add(t2);

			newlist=(ArrayList)tlist.Clone();
			newlist.CopyTo (tarray);

			if (tarray [0].name != "t1")
				return 1;
			if (tarray [1].name != "t2")
				return 2;
			
			return 0;
		}
Esempio n. 24
0
        public ArrayListBattle()
        {
            var x = new ArrayList(Program.TestCollectionSize);
            for (int i = 0; i < Program.TestCollectionSize; i++)
            {
                x.Add(i);
            }

            _collectionOfItems = x;

            _alphabetCollection = new ArrayList();
            foreach (var item in Program.AlphabetBase)
            {
                _alphabetCollection.Add(item);
            }

            _insertZeroCollection = _collectionOfItems.Clone() as ArrayList;
        }
Esempio n. 25
0
		public virtual void  fireEvents(int type, ArrayList listeners)
		{
			ArrayList targets = null;
			Listener l = null;
			
			lock(this)
			{
				if (listeners == null)
					return ;
				targets = (ArrayList) listeners.Clone();
			}
			
			if (targets != null)
				 for (int i = 0; i < targets.Count; i++)
				{
					l = (Listener) targets[i];
					fireEvent(type, l);
				}
		}
Esempio n. 26
0
        public static int coinChangeRec(int sum, int[] coins,int start,ArrayList notes)
        {
            if(start>=coins.Length || sum<0){
                return 0;
            }
            if(sum==0){

                notesAll.AddLast((ArrayList)notes.Clone());
                return 1;
            }

            int noFirst=coinChangeRec(sum, coins,start+1,notes);

            notes.Add(coins[start]);
            int withFirst=coinChangeRec(sum-coins[start],coins, start,notes);
            notes.RemoveAt(notes.Count-1);

            return noFirst+withFirst;
        }
Esempio n. 27
0
		private void Walk(int index,IActionExaminer examiner,ArrayList visitedLabels) {
						
			while (index<actionRec.Count) {
				
				BaseAction a = (BaseAction)actionRec[index];
				
				if (a is ActionLabel) {
					ActionLabel l = a as ActionLabel;						
					if (visitedLabels.Contains(l.LabelId)) {
						//examiner.End();
						return;	
						
					} else {
						visitedLabels.Add(l.LabelId);
					}
				}
				
				examiner.Examine(index,a);
				
				if (a is ActionJump) {
						
					ActionJump j = a as ActionJump;
					index = (int)labelIndexTable[j.LabelId]-1;
				}				
				
				if (a is ActionIf) {
					ActionIf ai = a as ActionIf;
					if (!visitedLabels.Contains(ai.LabelId)) {
						Walk( (int)labelIndexTable[ai.LabelId], examiner.Clone(), (ArrayList)visitedLabels.Clone() );	
					}
				}
				
				if (a is ActionReturn) {
					//examiner.End();
					return;
				}
	
				index++;				
			}
			
			//examiner.End();
		}
Esempio n. 28
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="groups"></param>
        /// <param name="strict"></param>
        public DataAffinity(ArrayList groups, ArrayList allBindedGroups, ArrayList unbindGroups, bool strict)
        {
            if (groups != null)
            {
                _groups = (ArrayList) groups.Clone();
                _groups.Sort();
            }
            if (allBindedGroups != null)
            {
                _allBindedGroups = (ArrayList) allBindedGroups.Clone();
                _allBindedGroups.Sort();
            }
            if (unbindGroups != null)
            {
                _unbindedGroups = (ArrayList) unbindGroups.Clone();
                _unbindedGroups.Sort();
            }

            _strict = strict;
        }
Esempio n. 29
0
        public MazeSpace(ArrayList walls)
            : base()
        {
            this.Walls = (ArrayList)walls.Clone();
            BorderNodes = new ArrayList();

            BuildPolygon();

            ExpectedPersonCount = (int)(Area * random.NextDouble());

            int doorCount = 0;
            foreach (MazeWall wall in Walls)
                if (wall.MazeWallType == MazeWallType.gate)
                    doorCount++;

            if (doorCount > 2)
            {
                MazeRoomType = MazeEditor.MazeSpaceType.corridor;
                ExpectedPersonCount = 0;
            }
        }
Esempio n. 30
0
        public void TestArrayList()
        {
            ArrayList oriList = new ArrayList { "cheka", "KGB", "Stasi" };
            int oriCount = oriList.Count;
            ArrayList cpyList = (ArrayList)oriList.Clone();

            Assert.AreNotSame(cpyList, oriList);
            Assert.AreEqual(oriCount, cpyList.Count);

            // just a shallow copy for each element
            for (int index = 0; index < oriList.Count; ++index)
            {
                Assert.AreSame(cpyList[index], oriList[index]);
            }

            // but the two list it self pointing to different place
            // so remove or add one will not affect the other
            cpyList.RemoveAt(cpyList.Count - 1);
            Assert.AreEqual(oriCount - 1, cpyList.Count);
            Assert.AreEqual(oriCount, oriList.Count);
        }
Esempio n. 31
0
        /// <summary> Selects a random subset of members according to subset_percentage and returns them.
        /// Picks no member twice from the same membership. If the percentage is smaller than 1 -> picks 1 member.
        /// </summary>
        public static System.Collections.ArrayList pickSubset(System.Collections.ArrayList members, double subset_percentage)
        {
            System.Collections.ArrayList ret = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)), tmp_mbrs;
            int num_mbrs = members.Count, subset_size, index;

            if (num_mbrs == 0)
            {
                return(ret);
            }
            subset_size = (int)System.Math.Ceiling(num_mbrs * subset_percentage);

            tmp_mbrs = (System.Collections.ArrayList)members.Clone();

            for (int i = subset_size; i > 0 && tmp_mbrs.Count > 0; i--)
            {
                index = (int)((Global.Random.NextDouble() * num_mbrs) % tmp_mbrs.Count);
                ret.Add(tmp_mbrs[index]);
                tmp_mbrs.RemoveAt(index);
            }

            return(ret);
        }
Esempio n. 32
0
        private void cmdShuffle_Click(object sender, EventArgs e)
        {
            bmpsave1 = new Bitmap(pnlSort1.Width, pnlSort1.Height);
            g1 = Graphics.FromImage(bmpsave1);

            bmpsave2 = new Bitmap(pnlSort2.Width, pnlSort2.Height);
            g2 = Graphics.FromImage(bmpsave2);

            pnlSort1.Image = bmpsave1;
            pnlSort2.Image = bmpsave2;

            array1 = new ArrayList(tbSamples.Value);
            array2 = new ArrayList(tbSamples.Value);
            for (int i = 0; i < array1.Capacity; i++)
            {
                int y = (int)((double)i / array1.Capacity * pnlSort1.Height);
                array1.Add(y);
            }
            Randomize(array1);
            array2 = (ArrayList)array1.Clone();
            DrawSamples();
        }
Esempio n. 33
0
        public void Test()
        {
            ArrayList arrayList1 = new ArrayList();

            arrayList1.Add("A");
            arrayList1.Add("B");

            Console.WriteLine("Clone之前的ArrayList1");
            foreach (string s in arrayList1)
            {
                Console.WriteLine(s);
            }
            //ICloneable ic;
            //ic = arrayList1;

            ArrayList arrayList2 = arrayList1.Clone() as ArrayList;
            //ArrayList arrayList2 = arrayList1;

            Console.WriteLine("Clone出来的ArrayList2");
            foreach (string s in arrayList2)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("修改之后的ArrayList1");
            arrayList1[0] = "C";

            foreach (string s in arrayList1)
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("修改之后的ArrayList2");
            foreach (string s in arrayList2)
            {
                Console.WriteLine(s);
            }
        }
Esempio n. 34
0
		public static string CombinePaths(string path1, string path2)
		{
			if (path1 == null)
			{
				throw new ArgumentNullException("path1");
			}
			if (path2 == null)
			{
				throw new ArgumentNullException("path2");
			}

			if (Path.IsPathRooted(path2))
			{
				return path2;
			}

			char separatorChar = Path.DirectorySeparatorChar;
			char[] splitChars = new char[] {'/', separatorChar};

			// Now we split the Path by the Path Separator
			String[] path2Parts = path2.Split(splitChars);

			ArrayList arList = new ArrayList();

			// for each Item in the path that differs from ".." we just add it 
			// to the ArrayList, but skip empty parts
			for (int iCount = 0; iCount < path2Parts.Length; iCount++)
			{
				string currentPart = path2Parts[iCount];

				// skip empty parts or single dot parts
				if (currentPart.Length == 0 || currentPart == ".")
				{
					continue;
				}

				// if we get a ".." Try to remove the last item added (as if 
				// going up in the Directory Structure)
				if (currentPart == "..")
				{
					if (arList.Count > 0 && ((string) arList[arList.Count - 1] != ".."))
					{
						arList.RemoveAt(arList.Count - 1);
					}
					else
					{
						arList.Add(currentPart);
					}
				}
				else
				{
					arList.Add(currentPart);
				}
			}

			bool trailingSeparator = (path1.Length > 0 && path1.IndexOfAny(splitChars, path1.Length - 1) != -1);

			// if the first path ends in directory seperator character, then 
			// we need to omit that trailing seperator when we split the path
			string[] path1Parts;
			if (trailingSeparator)
			{
				path1Parts = path1.Substring(0, path1.Length - 1).Split(splitChars);
			}
			else
			{
				path1Parts = path1.Split(splitChars);
			}

			int counter = path1Parts.Length;

			// if the second path starts with parts to move up the directory tree, 
			// then remove corresponding parts in the first path
			//
			// eg. path1 = d:\whatever\you\want\to\do 
			//     path2 = ../../test
			//     
			//     ->
			//
			//     path1 = d:\whatever\you\want
			//     path2 = test
			ArrayList arList2 = (ArrayList) arList.Clone();
			for (int i = 0; i < arList2.Count; i++)
			{
				// never discard first part of path1
				if ((string) arList2[i] != ".." || counter < 2)
				{
					break;
				}

				// skip part of current directory
				counter--;

				arList.RemoveAt(0);
			}

			string separatorString = separatorChar.ToString(CultureInfo.InvariantCulture);

			// if path1 only has one remaining part, and the original path had
			// a trailing separator character or the remaining path had multiple
			// parts (which were discarded by a relative path in path2), then
			// add separator to remaining part
			if (counter == 1 && (trailingSeparator || path1Parts.Length > 1))
			{
				path1Parts[0] += separatorString;
			}

			string combinedPath = Path.Combine(string.Join(separatorString, path1Parts,
			                                               0, counter), string.Join(separatorString, (String[]) arList.ToArray(typeof (String))));

			// if path2 ends in directory separator character, then make sure
			// combined path has trailing directory separator character
			if (path2.EndsWith("/") || path2.EndsWith(separatorString))
			{
				combinedPath += Path.DirectorySeparatorChar;
			}

			return combinedPath;
		}
Esempio n. 35
0
    /**
    <summary>The _listen_threads method, reads from sockets and let's the node
    handle the incoming data.</summary>
    */
    protected void Listen() {
      if (Thread.CurrentThread.Name == null) {
        Thread.CurrentThread.Name = "iphandler_thread";
      }
      ArrayList sockets = new ArrayList();
      sockets.Add(_uc);
      if(_mc != null) {
        sockets.Add(_mc);
      }

      byte[] buffer =  new byte[Int16.MaxValue];
      DateTime last_debug = DateTime.UtcNow;
      TimeSpan debug_period = TimeSpan.FromSeconds(5);
      while(1 == _running) {
        if (ProtocolLog.Monitor.Enabled) {
          DateTime now = DateTime.UtcNow;
          if (now - last_debug > debug_period) {
            last_debug = now;
            ProtocolLog.Write(ProtocolLog.Monitor, String.Format("I am alive: {0}", now));
          }
        }
        try {
          ArrayList readers = (ArrayList) sockets.Clone();
          Socket.Select(readers, null, null, 10000000); //10 seconds
          foreach(Socket socket in readers) {
            EndPoint ep = new IPEndPoint(IPAddress.Any, 0);
            int rec_bytes = socket.ReceiveFrom(buffer, ref ep);
            Subscriber s = _sub;
            //s can't change once we've read it.
            if( s != null && rec_bytes > 0) {
              MemBlock packet = MemBlock.Copy(buffer, 0, rec_bytes);
              MemBlock cookie = packet.Slice(0, 4);
              if(cookie.Equals(MagicCookie)) {
                packet = packet.Slice(4);
                ISender sender = CreateUnicastSender(ep);
                s.Handle(packet, sender);
              }
            }
          }
        }
        catch(ObjectDisposedException odx) {
          //If we are no longer running, this is to be expected.
          if(1 == _running) {
          //If we are running print it out
            ProtocolLog.WriteIf(ProtocolLog.Exceptions, odx.ToString());
          }
          break;
        }
        catch(Exception x) {
          if(0 == _running) {
            ProtocolLog.WriteIf(ProtocolLog.Exceptions, x.ToString());
          }
        }
      }
    }
Esempio n. 36
0
		public static PointF[] MakePtsUnique( PointF[] iPoints)
		{
			PointF [] result = null;
			PointF last_pt = PointF.Empty;
			ArrayList ar = null;
			bool MoveElement = false;

			ar  = new ArrayList();
			foreach ( PointF pt in iPoints)
			{
				MoveElement = true;
			
				if ( pt == last_pt )
					MoveElement = false;

				if ( MoveElement )
					ar.Add(pt);

				last_pt = pt;

			}

			if ( (PointF) ar[0] == (PointF) ar[ar.Count-1] )
				ar.RemoveAt(ar.Count-1);

			result = (PointF[]) (ar.Clone() as ArrayList).ToArray(typeof(PointF));
			
			return result;	
						
		}
Esempio n. 37
0
        public override void  handleSuspect(Address mbr)
        {
            System.Collections.ArrayList suspects = null;

            lock (this)
            {
                if (mbr == null)
                {
                    return;
                }
                if (!suspected_mbrs.Contains(mbr))
                {
                    Address sameNode = null;

                    if (gms.isPartReplica)
                    {
                        Membership mbrShip = gms.members.copy();

                        if (mbrShip.contains(mbr))
                        {
                            for (int i = 0; i < mbrShip.size(); i++)
                            {
                                Address other = mbrShip.elementAt(i);
                                if (other != null && !other.Equals(mbr))
                                {
                                    if (other.IpAddress.Equals(mbr.IpAddress))
                                    {
                                        sameNode = other;
                                        break;
                                    }
                                }
                            }
                        }
                    }


                    if (sameNode != null && !sameNode.IpAddress.Equals(gms.local_addr.IpAddress))
                    {
                        if (sameNode.Port > mbr.Port)
                        {
                            suspected_mbrs.Add(sameNode);
                            suspected_mbrs.Add(mbr);
                        }
                        else
                        {
                            suspected_mbrs.Add(mbr);
                            suspected_mbrs.Add(sameNode);
                        }
                    }
                    else
                    {
                        suspected_mbrs.Add(mbr);
                    }
                }



                if (gms.Stack.NCacheLog.IsInfoEnabled)
                {
                    gms.Stack.NCacheLog.Info("suspected mbr=" + mbr + ", suspected_mbrs=" + Global.CollectionToString(suspected_mbrs));
                }

                if (!leaving)
                {
                    if (wouldIBeCoordinator() && !gms.IsCoordinator)
                    {
                        suspects = (System.Collections.ArrayList)suspected_mbrs.Clone();
                        suspected_mbrs.Clear();
                        gms.becomeCoordinator();

                        foreach (Address leavingMbr in suspects)
                        {
                            if (!gms.members.Members.Contains(leavingMbr))
                            {
                                gms.Stack.NCacheLog.Debug("pbcast.PariticipantGmsImpl.handleSuspect()", "mbr " + leavingMbr + " is not a member !");
                                continue;
                            }
                            if (gms.Stack.NCacheLog.IsInfoEnabled)
                            {
                                gms.Stack.NCacheLog.Info("suspected mbr=" + leavingMbr + "), members are " + gms.members + ", coord=" + gms.local_addr + ": I'm the new coord !");
                            }
                            //=====================================================
                            //update gms' subgroupMbrMap.
                            string subGroup = (string)gms._mbrSubGroupMap[leavingMbr];
                            if (subGroup != null)
                            {
                                lock (gms._mbrSubGroupMap.SyncRoot)
                                {
                                    gms._mbrSubGroupMap.Remove(leavingMbr);
                                }
                                lock (gms._subGroupMbrsMap.SyncRoot)
                                {
                                    System.Collections.ArrayList subGroupMbrs = (System.Collections.ArrayList)gms._subGroupMbrsMap[subGroup];
                                    if (subGroupMbrs != null)
                                    {
                                        subGroupMbrs.Remove(leavingMbr);
                                        if (subGroupMbrs.Count == 0)
                                        {
                                            gms._subGroupMbrsMap.Remove(subGroup);
                                        }
                                    }
                                }
                            }
                            //=====================================================
                            ArrayList list = new ArrayList(1);
                            list.Add(leavingMbr);
                            gms.acquireHashmap(list, false, subGroup, false);
                        }
                        gms.castViewChange(null, null, suspects, gms._hashmap);
                    }
                    else
                    {
                        if (gms.IsCoordinator)
                        {
                            sendMemberLeftNotificationToCoordinator(mbr, gms.local_addr);
                        }
                        else
                        {
                            sendMemberLeftNotificationToCoordinator(mbr, gms.determineCoordinator());
                        }
                    }
                }
            }
        }