Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            IntList intlist = new IntList();

            intlist.Add(1);
            intlist.Add(2);
            intlist.Add(3);

            MessageBox.Show(intlist[0].ToString());

            泛型.StringList slist = new StringList();
            slist.Add("100");


            MyList <int> glist = new MyList <int>();

            glist.Add(200);
            MessageBox.Show(glist.ToString());

            MyList <string> glist1 = new MyList <string>();

            glist1.Add("200");
            MessageBox.Show(glist1.ToString());

            //缓存泛型方法的调用演示
            Pig pig = CacheMgr.GetData <Pig>("pigkey");
        }
Ejemplo n.º 2
0
        public void TestRemove()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (int j = 0; j < 1000; j++)
            {
                Assert.AreEqual(j, list.Remove(0));
                Assert.AreEqual(999 - j, list.Count);
            }
            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (int j = 0; j < 1000; j++)
            {
                Assert.AreEqual(999 - j, list.Remove(999 - j));
                Assert.AreEqual(999 - j, list.Count);
            }
            try
            {
                list.Remove(0);
                Assert.Fail("should have caught IndexOutOfBoundsException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
        }
Ejemplo n.º 3
0
        public void GivenAPopulatedList_WhenCallWithInvalidIndex_ThenThrowInvalidListIndexException()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            Assert.Throws <InvalidListIndexException>(() => l.Get(10));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Adds a new range from one of the merged sequences or from the common
 /// predecessor.
 /// </summary>
 /// <remarks>
 /// Adds a new range from one of the merged sequences or from the common
 /// predecessor. This method can add conflicting and non-conflicting ranges
 /// controlled by the conflictState parameter
 /// </remarks>
 /// <param name="srcIdx">
 /// determines from which sequence this range comes. An index of
 /// x specifies the x+1 element in the list of sequences
 /// specified to the constructor
 /// </param>
 /// <param name="begin">
 /// the first element from the specified sequence which should be
 /// included in the merge result. Indexes start with 0.
 /// </param>
 /// <param name="end">
 /// specifies the end of the range to be added. The element this
 /// index points to is the first element which not added to the
 /// merge result. All elements between begin (including begin) and
 /// this element are added.
 /// </param>
 /// <param name="conflictState">
 /// when set to NO_CONLICT a non-conflicting range is added.
 /// This will end implicitly all open conflicts added before.
 /// </param>
 public virtual void Add(int srcIdx, int begin, int end, MergeChunk.ConflictState
                         conflictState)
 {
     chunks.Add((int)(conflictState));
     chunks.Add(srcIdx);
     chunks.Add(begin);
     chunks.Add(end);
     if (conflictState != MergeChunk.ConflictState.NO_CONFLICT)
     {
         containsConflicts = true;
     }
 }
Ejemplo n.º 5
0
        public void GivenAnNonEmptyList_WhenCallCount_ThenReturnCountOfItems()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);

            Assert.Equal(5, l.Count);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            IntList il = new IntList();

            il.Add(1);
            il.Add(2);
            il.Add(3);
            il.Add(4);

            foreach (int i in il.BidirectionalSubrange(false, 1, 3))
            {
                Console.WriteLine(i);
            }
        }
Ejemplo n.º 7
0
        public void GivenAnEmptyList_WhenCallAddMultipleTimes_ThenCallPopWithIndexReturnCorrectItem()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            Assert.Equal(5, l.Count);
            Assert.Equal(1, l.Pop(0));
            Assert.Equal(4, l.Count);
            Assert.Equal(2, l.Pop(0));
            Assert.Equal(3, l.Count);
        }
Ejemplo n.º 8
0
        public void TestConstructors()
        {
            IntList list = new IntList();

            Assert.IsTrue(list.IsEmpty());
            list.Add(0);
            list.Add(1);
            IntList list2 = new IntList(list);

            //Assert.AreEqual(list, list2);
            Assert.IsTrue(list.Equals(list2));
            IntList list3 = new IntList(2);

            Assert.IsTrue(list3.IsEmpty());
        }
Ejemplo n.º 9
0
        public void TestRetainAll()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            IntList listCopy = new IntList(list);
            IntList listOdd  = new IntList();
            IntList listEven = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                if (j % 2 == 0)
                {
                    listEven.Add(j);
                }
                else
                {
                    listOdd.Add(j);
                }
            }
            list.RetainAll(listOdd);
            //Assert.AreEqual(list, listOdd);
            Assert.IsTrue(list.Equals(listOdd));
            list.RetainAll(listEven);
            Assert.IsTrue(list.IsEmpty());
            listCopy.RetainAll(listEven);
            //Assert.AreEqual(listCopy, listEven);
            Assert.IsTrue(listCopy.Equals(listEven));
            listCopy.RetainAll(listOdd);
            Assert.IsTrue(listCopy.IsEmpty());
        }
Ejemplo n.º 10
0
        public void TestSet()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (int j = 0; j < 1001; j++)
            {
                try
                {
                    list.Set(j, j + 1);
                    if (j == 1000)
                    {
                        Assert.Fail("Should have gotten exception");
                    }
                    Assert.AreEqual(j + 1, list.Get(j));
                }
                catch (IndexOutOfRangeException)
                {
                    if (j != 1000)
                    {
                        Assert.Fail("premature exception");
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void CompleteTests()
        {
            var array = new IntList();

            Assert.Equal(0, array.Count);

            array = AddArray(1, 2, 3, 4);
            Assert.Equal(4, array.Count);

            array.Add(5);
            Assert.Equal(5, array.Count);
            Assert.Equal(5, array[4]);

            array[4] = 220;
            Assert.Equal(220, array[4]);

            Assert.True(array.Contains(3));
            Assert.False(array.Contains(10));

            Assert.Equal(-1, array.IndexOf(100));

            array.Insert(5, 100);
            Assert.Equal(5, array.IndexOf(100));
            Assert.Equal(6, array.Count);

            array.Remove(100);
            Assert.Equal(-1, array.IndexOf(100));
            Assert.Equal(5, array.Count);


            array.RemoveAt(4);
            Assert.Equal(4, array[3]);
            Assert.Equal(4, array.Count);
        }
Ejemplo n.º 12
0
        public void TestGet()
        {
            IntList list = new IntList();

            for (int j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (int j = 0; j < 1001; j++)
            {
                try
                {
                    Assert.AreEqual(j, list.Get(j));
                    if (j == 1000)
                    {
                        Assert.Fail("should have gotten exception");
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    if (j != 1000)
                    {
                        Assert.Fail("unexpected IndexOutOfBoundsException");
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private IntList LineMap(int ptr, int end)
        {
            // Experimentally derived from multiple source repositories
            // the average number of bytes/line is 36. Its a rough guess
            // to initially size our map close to the target.
            //
            IntList map = new IntList((end - ptr) / 36);

            map.FillTo(1, int.MinValue);
            for (; ptr < end; ptr = NextLF(ptr))
            {
                map.Add(ptr);
            }
            map.Add(end);
            return(map);
        }
Ejemplo n.º 14
0
        static void NoReallocationTime()
        {
            int size = 512 * 424 * 1000;

            IntList   list = new IntList(size);
            Stopwatch sw   = new Stopwatch();

            sw.Start();
            for (int c = 0; c < size; c++)
            {
                list.Add(c);
            }
            sw.Stop();
            Console.WriteLine("IntList Time: " + sw.ElapsedMilliseconds / 1000.0f + " ms");

            List <int> list2 = new List <int>(size);
            Stopwatch  sw2   = new Stopwatch();

            sw2.Start();
            for (int c = 0; c < size; c++)
            {
                list2.Add(c);
            }
            sw2.Stop();
            Console.WriteLine("List<int> Time: " + sw2.ElapsedMilliseconds / 1000.0f + "ms");
        }
Ejemplo n.º 15
0
        public void GivenAnEmptyList_WhenCallAppend_ThenCallPopReturnAppendedItem()
        {
            IntList l = new IntList();

            l.Add(5);
            Assert.Equal(5, l.Pop());
        }
Ejemplo n.º 16
0
        public void Test_Add_Should_Correctly_Add_One_Element_For_One_Integer_Array()
        {
            var array = new IntList();

            array.Add(1);
            Assert.Equal(1, array.Count);
        }
        public void SerializeParameters(UIElementCollection parameterGrid, string shaderName)
        {
            ShaderName = shaderName;

            ClearLists();

            foreach (var p in parameterGrid)
            {
                if (p is BoolView)
                {
                    var vm = (p as BoolView).DataContext as BoolViewModel;
                    BoolList.Add(new SerializeHolder <bool>(vm.ShaderName, vm.ContentValue));
                }
                else if (p is IntView)
                {
                    var vm = (p as IntView).DataContext as IntViewModel;
                    IntList.Add(new SerializeHolder <int>(vm.ShaderName, vm.ContentValue));
                }
                else if (p is FloatView)
                {
                    var vm = (p as FloatView).DataContext as FloatViewModel;
                    FloatList.Add(new SerializeHolder <float>(vm.ShaderName, vm.ContentValue));
                }
                else if (p is Float2View)
                {
                    var vm = (p as Float2View).DataContext as Float2ViewModel;
                    Float2List.Add(new SerializeHolder <Float2>(vm.ShaderName, vm.ContentValue));
                }
                else if (p is Float3View)
                {
                    var vm = (p as Float3View).DataContext as Float3ViewModel;
                    Float3List.Add(new SerializeHolder <Float3>(vm.ShaderName, vm.ContentValue));
                }
                else if (p is Float4View)
                {
                    var vm = (p as Float4View).DataContext as Float4ViewModel;
                    Float4List.Add(new SerializeHolder <Float4>(vm.ShaderName, vm.ContentValue));
                }
                else if (p is Texture2DView)
                {
                    var vm = (p as Texture2DView).DataContext as Texture2DViewModel;
                    Texture2DList.Add(new SerializeHolder <string>(vm.ShaderName, vm.FileName));
                }
            }

            var    ofd           = new SaveFileDialog();
            string baseDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

            ofd.InitialDirectory = baseDirectory;
            ofd.DefaultExt       = ".xml";
            ofd.Filter           = "XML files (.xml)|*.xml";
            if (ofd.ShowDialog() == true)
            {
                using (var f = File.Create(ofd.FileName))
                {
                    XmlSer.Serialize(f, this);
                }
            }
        }
Ejemplo n.º 18
0
    public void OnButtonClicked()
    {
        IntList unlockedLevels = AssetBundleManager.Instance.GetAsset <IntList>("configs", "Unlocked Levels");

        if (!unlockedLevels.Contains(0))
        {
            unlockedLevels.Add(0);
        }
        if (!unlockedLevels.Contains(1))
        {
            unlockedLevels.Add(1);
        }
        if (!unlockedLevels.Contains(2))
        {
            unlockedLevels.Add(2);
        }
    }
Ejemplo n.º 19
0
 public void AddDbcell(int cell)
 {
     if (field_5_dbcells == null)
     {
         field_5_dbcells = new IntList();
     }
     field_5_dbcells.Add(cell);
 }
Ejemplo n.º 20
0
        public void GivenAnEmptyList_WhenCallAddMultipleTimes_ThenCallGetWithIndexReturnCorrectItemAndMaintainOriginalCount()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            Assert.Equal(5, l.Count);
            Assert.Equal(1, l.Get(0));
            Assert.Equal(2, l.Get(1));
            Assert.Equal(3, l.Get(2));
            Assert.Equal(4, l.Get(3));
            Assert.Equal(5, l.Get(4));
            Assert.Equal(5, l.Count);
        }
    public static void Main()
    {
        IntList list = new IntList();

        list.Add(1);
        list.Add(55);
        list.Add(43);

        foreach (int value in list)
        {
            Console.WriteLine("Value = {0}", value);
        }

        foreach (int value in list)
        {
            Console.WriteLine("Value = {0}", value);
            list.Add(124);
        }
    }
Ejemplo n.º 22
0
        public Grid()
        {
            Numbers = new IntList();
            for (int i = 1; i < 10; i++)
                Numbers.Add(i);

            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                    Possibilities[i, j] = new IntList(Numbers);
        }
Ejemplo n.º 23
0
        public IntList CompareTo(string other)
        {
            var results = new IntList();

            foreach (var v in this)
            {
                results.Add(string.CompareOrdinal(v.ToString(), other));
            }
            return(results);
        }
        private IntList CreateTestList()
        {
            var list = new IntList();

            for (var i = 0; i < 25; i++)
            {
                list.Add(i);
            }

            return(list);
        }
Ejemplo n.º 25
0
        public void TestContainsAll()
        {
            IntList list = new IntList();

            Assert.IsTrue(list.ContainsAll(list));
            for (int j = 0; j < 10; j++)
            {
                list.Add(j);
            }
            IntList list2 = new IntList(list);

            Assert.IsTrue(list2.ContainsAll(list));
            Assert.IsTrue(list.ContainsAll(list2));
            list2.Add(10);
            Assert.IsTrue(list2.ContainsAll(list));
            Assert.IsTrue(!list.ContainsAll(list2));
            list.Add(11);
            Assert.IsTrue(!list2.ContainsAll(list));
            Assert.IsTrue(!list.ContainsAll(list2));
        }
Ejemplo n.º 26
0
        private IntList AddArray(params int[] values)
        {
            IntList array = new IntList();

            foreach (var value in values)
            {
                array.Add(value);
            }

            return(array);
        }
Ejemplo n.º 27
0
        protected IntList AddedArray(params int[] numbers)
        {
            IntList array = new IntList();

            foreach (var number in numbers)
            {
                array.Add(number);
            }

            return(array);
        }
Ejemplo n.º 28
0
        public void TestClear()
        {
            IntList list = new IntList();

            for (int j = 0; j < 500; j++)
            {
                list.Add(j);
            }
            Assert.AreEqual(500, list.Count);
            list.Clear();
            Assert.AreEqual(0, list.Count);
            for (int j = 0; j < 500; j++)
            {
                list.Add(j + 1);
            }
            Assert.AreEqual(500, list.Count);
            for (int j = 0; j < 500; j++)
            {
                Assert.AreEqual(j + 1, list.Get(j));
            }
        }
Ejemplo n.º 29
0
        public void GivenAnEmptyList_WhenCallAppendMultipleTimes_ThenCallPopReturnAppendedItemsInReverseOrder()
        {
            IntList l = new IntList();

            l.Add(1);
            l.Add(2);
            l.Add(3);
            l.Add(4);
            l.Add(5);
            Assert.Equal(5, l.Count);
            Assert.Equal(5, l.Pop());
            Assert.Equal(4, l.Count);
            Assert.Equal(4, l.Pop());
            Assert.Equal(3, l.Count);
            Assert.Equal(3, l.Pop());
            Assert.Equal(2, l.Count);
            Assert.Equal(2, l.Pop());
            Assert.Equal(1, l.Count);
            Assert.Equal(1, l.Pop());
            Assert.Equal(0, l.Count);
            Assert.Throws <EmptyListException>(() => l.Pop());
        }
Ejemplo n.º 30
0
        public void Test_Insert_Should_Correctly_Insert_Element_Array_Has_Exactly_3_elements()
        {
            //Given
            IntList array = AddedArray(1, 2, 3);

            //When
            array.Insert(1, 100);
            //Then
            array.Add(10);
            Assert.Equal(1, array.IndexOf(100));
            Assert.Equal(3, array.IndexOf(3));
            Assert.Equal(5, array.Count);
        }
Ejemplo n.º 31
0
 static public int Add(IntPtr l)
 {
     try {
         IntList      self = (IntList)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         self.Add(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 32
0
    private static void allTests(Ice.Communicator communicator)
    {
        Console.Out.Write("testing equals() for Slice structures... ");
        Console.Out.Flush();

        //
        // Define some default values.
        //
        C def_cls = new C(5);
        S1 def_s = new S1("name");
        string[] def_ss = new string[]{ "one", "two", "three" };
        IntList def_il = new IntList();
        def_il.Add(1);
        def_il.Add(2);
        def_il.Add(3);
        Dictionary<string, string> def_sd = new Dictionary<string, string>();
        def_sd.Add("abc", "def");
        Ice.ObjectPrx def_prx = communicator.stringToProxy("test");
        S2 def_s2 = new S2(true, (byte)98, (short)99, 100, 101, (float)1.0, 2.0, "string", def_ss, def_il, def_sd,
                           def_s, def_cls, def_prx);

        //
        // Compare default-constructed structures.
        //
        {
            test(new S2().Equals(new S2()));
        }

        //
        // Change one primitive member at a time.
        //
        {
            S2 v;

            v = (S2)def_s2.Clone();
            test(v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.bo = false;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.by--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.sh--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.i--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.l--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.f--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.d--;
            test(!v.Equals(def_s2));

            v = (S2)def_s2.Clone();
            v.str = "";
            test(!v.Equals(def_s2));
        }

        //
        // String member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.str = (string)def_s2.str.Clone();
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.str = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.str = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.str = null;
            v2.str = null;
            test(v1.Equals(v2));
        }

        //
        // Sequence member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.ss = (string[])def_s2.ss.Clone();
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.ss = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.ss = null;
            test(!v1.Equals(v2));
        }

        //
        // Custom sequence member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.il = (IntList)def_s2.il.Clone();
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v1.il = new IntList();
            test(!v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.il = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.il = null;
            test(!v1.Equals(v2));
        }

        //
        // Dictionary member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.sd = new Dictionary<string, string>(def_s2.sd);
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v1.sd = new Dictionary<string, string>();
            test(!v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.sd = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.sd = null;
            test(!v1.Equals(v2));
        }

        //
        // Struct member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.s = (S1)def_s2.s.Clone();
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v1.s = new S1("name");
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v1.s = new S1("noname");
            test(!v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.s = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.s = null;
            test(!v1.Equals(v2));
        }

        //
        // Class member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.cls = (C)def_s2.cls.Clone();
            test(!v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.cls = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.cls = null;
            test(!v1.Equals(v2));
        }

        //
        // Proxy member
        //
        {
            S2 v1, v2;

            v1 = (S2)def_s2.Clone();
            v1.prx = communicator.stringToProxy("test");
            test(v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v1.prx = communicator.stringToProxy("test2");
            test(!v1.Equals(def_s2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v1.prx = null;
            test(!v1.Equals(v2));

            v1 = (S2)def_s2.Clone();
            v2 = (S2)def_s2.Clone();
            v2.prx = null;
            test(!v1.Equals(v2));
        }

        Console.Out.WriteLine("ok");
    }
Ejemplo n.º 33
0
        public void SessionAuthUserAccessTest()
        {
            SessionAuthUser authUser = new SessionAuthUser("UNIT_TEST", 1, "Tester", "Mr. Tester", 1);
            Assert.IsNotNull(authUser);

            IntList allAcceessLevelIds = new IntList();
            allAcceessLevelIds.Add(CoreConstants.MODULE_ADMINISTRATION_ACCESS_NONE);
            allAcceessLevelIds.Add(CoreConstants.MODULE_ADMINISTRATION_ACCESS_READ_ONLY);
            allAcceessLevelIds.Add(CoreConstants.MODULE_ADMINISTRATION_ACCESS_EDIT);
            allAcceessLevelIds.Add(CoreConstants.MODULE_ADMINISTRATION_ACCESS_FULL);

            allAcceessLevelIds.Add(CoreConstants.MODULE_AUTH_ACCESS_NONE);
            allAcceessLevelIds.Add(CoreConstants.MODULE_AUTH_ACCESS_READ_ONLY);
            allAcceessLevelIds.Add(CoreConstants.MODULE_AUTH_ACCESS_EDIT);
            allAcceessLevelIds.Add(CoreConstants.MODULE_AUTH_ACCESS_FULL);

            allAcceessLevelIds.Add(CoreConstants.MODULE_BILLING_ACCESS_NONE);
            allAcceessLevelIds.Add(CoreConstants.MODULE_BILLING_ACCESS_READ_ONLY);
            allAcceessLevelIds.Add(CoreConstants.MODULE_BILLING_ACCESS_EDIT);
            allAcceessLevelIds.Add(CoreConstants.MODULE_BILLING_ACCESS_FULL);

            allAcceessLevelIds.Add(CoreConstants.MODULE_SAAS_ACCESS_NONE);
            allAcceessLevelIds.Add(CoreConstants.MODULE_SAAS_ACCESS_READ_ONLY);
            allAcceessLevelIds.Add(CoreConstants.MODULE_SAAS_ACCESS_EDIT);
            allAcceessLevelIds.Add(CoreConstants.MODULE_SAAS_ACCESS_FULL);

            allAcceessLevelIds.Add(CoreConstants.MODULE_GLOBAL_ACCESS_NONE);
            allAcceessLevelIds.Add(CoreConstants.MODULE_GLOBAL_ACCESS_READ_ONLY);
            allAcceessLevelIds.Add(CoreConstants.MODULE_GLOBAL_ACCESS_EDIT);
            allAcceessLevelIds.Add(CoreConstants.MODULE_GLOBAL_ACCESS_FULL);

            IntList acceessLevelIds = new IntList();
            authUser.AccessLevels = new IntList();
            foreach (int acceessLevelID in acceessLevelIds)
                Assert.IsFalse(authUser.IsAuthorized(acceessLevelID), "Default access should be off");

            #region Administrator Check
            authUser.IsAdministrator = true;
            foreach (int acceessLevelID in allAcceessLevelIds)
                Assert.IsTrue(authUser.IsAuthorized(acceessLevelID), "IsAdministrator should have access to all");

            authUser.IsAdministrator = false;
            foreach (int acceessLevelID in allAcceessLevelIds)
                Assert.IsFalse(authUser.IsAuthorized(acceessLevelID), "IsAdministrator turned off should disable access to all");

            #endregion

            #region Limited Access Check
            authUser.AccessLevels = new IntList();
            authUser.AccessLevels.Add(CoreConstants.MODULE_AUTH_ACCESS_NONE);
            authUser.AccessLevels.Add(CoreConstants.MODULE_AUTH_ACCESS_READ_ONLY);
            authUser.AccessLevels.Add(CoreConstants.MODULE_AUTH_ACCESS_EDIT);

            foreach (int acceessLevelIDtoCheck in allAcceessLevelIds)
            {
                bool isAuthorized = authUser.IsAuthorized(acceessLevelIDtoCheck);
                bool shouldBeAuthorized = (
                    (acceessLevelIDtoCheck == CoreConstants.MODULE_AUTH_ACCESS_NONE) ||
                    (acceessLevelIDtoCheck == CoreConstants.MODULE_AUTH_ACCESS_READ_ONLY) ||
                    (acceessLevelIDtoCheck == CoreConstants.MODULE_AUTH_ACCESS_EDIT)
                    );

                Assert.AreEqual(isAuthorized, shouldBeAuthorized, "Failed to correctly authorize the only set item.");
            }
            #endregion
        }
Ejemplo n.º 34
0
        public static void Main(string[] args)
        {
            try {
                PlatformManager.Services.MaxSequenceSize = int.MaxValue;
                PlatformManager.Services.DefaultBufferSize = 4096;
                PlatformManager.Services.Is64BitProcessType = true;

                if (args.Length > 4) {
                    Console.WriteLine ("Too many arguments");
                    DisplayHelp ();
                } else if (args.Length < 4) {
                    Console.WriteLine ("Not enough arguments");
                    DisplayHelp();
                }else if (args [0] == "h" || args [0] == "help" || args [0] == "?" || args [0] == "-h") {
                    DisplayHelp ();
                } else {

                    string subreads_name = args [0];
                    string ccs_name = args [1];
                    string ref_name = args [2];
                    string zmw = args[3];

                    // Validate files exist
                    for(int i = 0; i < 3; i++) {
                        var fname = args[i];
                        if (!File.Exists(fname)) {
                            Console.WriteLine ("Can't find file: " + fname);
                            return;
                        }
                        if (i < 2) {
                            //TODO: Add code to ensure BAM exists here
                        }
                    }

                    // Validate ZMW Number
                    int holeNumber;
                    bool converted = int.TryParse(zmw, out holeNumber);
                    if (!converted || holeNumber < 0) {
                        Console.WriteLine("Could not convert " + zmw +" into hole number >= 0");
                    }

                    Console.WriteLine("Loading Data ...");

                    // Get CCS Read
                    IntList zmws = new IntList();
                    zmws.Add(holeNumber);
                    //zmws.Add(133403);
                    DataSet dt = new DataSet(ccs_name);
                    var query = new ZmwQuery(zmws, dt);
                    var ccs = query.FirstOrDefault();
                    if (ccs == null) {
                        Console.WriteLine("Could not query hole number " + holeNumber + " from file " + ccs_name);
                        return;
                    }
                    var seq_str = ccs.Sequence();
                    var sequence = new Sequence(DnaAlphabet.Instance, seq_str);
                    sequence.ID = ccs.FullName();
                    //Clean up
                    query.Dispose(); query = null;
                    ccs.Dispose(); ccs = null;
                    dt.Dispose(); dt = null;

                    Console.WriteLine("Aligning Data ... ");
                    BWAPairwiseAligner bwa = new BWAPairwiseAligner(ref_name, false);

                    // Now get initial alignment and variants
                    BWAPairwiseAlignment aln =  bwa.AlignRead(sequence) as BWAPairwiseAlignment;
                    if (aln == null) {
                        Console.WriteLine("Consensus read did not align");
                        return;
                    }

                    // Now get all the subreads
                    dt = new DataSet(subreads_name);
                    query = new ZmwQuery(zmws, dt);
                    // We must copy the data right away, or we wind up with a bunch of pointers that all hit the same thing
                    var subreads = query.Select(s => new Sequence(DnaAlphabet.Instance, s.Sequence()) {ID = s.FullName()}).ToList();
                    if (subreads.Count == 0 )
                    {
                        Console.WriteLine("Did not find any subreads from " + holeNumber + " in file " + subreads_name);
                        return;
                    }
                    subreads.ForEach( s => {
                        var split = s.ID.Split('/');
                        s.ID = String.Join("/", split.Skip(1)); });

                    zmws.Dispose(); zmws = null;
                    query.Dispose(); query = null;

                    // Now generate the dataset
                    var data = new CCSDataSet(sequence, subreads, aln);

                    Application.Init ();
                    MainWindow win = new MainWindow (data);
                    win.Show ();
                    Application.Run ();

                }

            }
            catch(DllNotFoundException thrown) {
                Console.WriteLine ("Error thrown when attempting to generate the CCS results.");
                Console.WriteLine("A shared library was not found.  To solve this, please add the folder" +
                    " with the downloaded files *.so and *.dylib " +
                    "to your environmental variables (LD_LIBRARY_PATH on Ubuntu, DYLD_LIBRARY_PATH on Mac OS X).");
                Console.WriteLine ("Error: " + thrown.Message);
                Console.WriteLine (thrown.StackTrace);

            }
            catch(Exception thrown) {
                Console.WriteLine ("Error thrown when attempting to generate the CCS results");
                Console.WriteLine ("Error: " + thrown.Message);
                Console.WriteLine (thrown.StackTrace);
                while (thrown.InnerException != null) {
                    Console.WriteLine ("Inner Exception: " + thrown.InnerException.Message);
                    thrown = thrown.InnerException;
                }
            }
        }