Esempio n. 1
0
        private void btnCacheServiceTest_Click(object sender, EventArgs e)
        {
            List<TimeSpan> times = new List<TimeSpan>();
            List<System.Threading.Thread> threads = new List<System.Threading.Thread>();
            int max = 100;
            for (int i = 0; i < max; i++)
            {
                System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(
                () =>
                {
                    int k = i;
                    Random r = new Random();
                    //System.Threading.Thread.Sleep(r.Next(300));
                    DateTime now = DateTime.Now;
                    sr.CacheServiceClient c = new NetSqlAzMan_WinTest.sr.CacheServiceClient();
                    c.Open();
                    KeyValuePair<string, string>[] attributes;
                    string user = WindowsIdentity.GetCurrent().GetUserBinarySSid();
                    string[] groups = WindowsIdentity.GetCurrent().GetGroupsBinarySSid();
                    AuthorizationType auth = c.CheckAccessForWindowsUsersWithAttributesRetrieve(out attributes, "Italferr", "CartaDeiServizi", "Visualizza Dettagli Richiesta", user, groups, DateTime.Now, false, null);
                    c.Close();
                    TimeSpan ts = DateTime.Now.Subtract(now);
                    if (auth != AuthorizationType.Allow)
                    {
                        throw new Exception("Error");
                    }
                    times.Add(ts);
                }));
                threads.Add(t);
                t.Start();
            }
            foreach (System.Threading.Thread t in threads)
            {
                t.Join();
            }
            this.textBox1.Text = String.Empty;
            int cc = 0;
            foreach (TimeSpan ts in times)
            {
                this.textBox1.Text += String.Format("{0}) {1}\r\n",++cc, ts);
            }
            MessageBox.Show("Done");

            //DateTime now = DateTime.Now;
            //NetSqlAzMan.Cache.StorageCache sc = new StorageCache("data source=.;initial catalog=NetSqlAzManStorage;user id=sa;password="******"Italferr", "CartaDeiServizi");
            //WindowsIdentity wid = WindowsIdentity.GetCurrent();
            //string user = wid.GetUserBinarySSid(); //using NetSqlAzMan.Cache needed
            //string[] groups = wid.GetGroupsBinarySSid(); //using NetSqlAzMan.Cache needed
            //AuthorizationType au = sc.CheckAccess("Italferr", "CartaDeiServizi", "Approvatore Sistemi Informativi", user, groups, DateTime.Now, false);
            //MessageBox.Show(au.ToString());
            //return;

            //int max = 100;

            //sr.CacheServiceClient client = new NetSqlAzMan_WinTest.sr.CacheServiceClient();
            //for (int i = 0; i < max; i++)
            //{
            //    KeyValuePair<string, string>[] attributes;
            //    auth = client.CheckAccessForWindowsUsersWithAttributesRetrieve(out attributes, "Italferr", "CartaDeiServizi", "Visualizza Dettagli Richiesta", user, groups, DateTime.Now, false, null);
            //}
            //client.Close();
            //MessageBox.Show(auth.ToString());
            //TimeSpan ts = DateTime.Now.Subtract(now);
            //MessageBox.Show(String.Format("Total: {0} - Single: {1}", ts.TotalMilliseconds, ts.TotalMilliseconds / (double)max));

            //NetSqlAzMan.Cache.StorageCache sc = new NetSqlAzMan.Cache.StorageCache("data source=.;initial catalog=NetSqlAzManStorage;user id=sa;password="******"ItalferR", "CartadeiServizi", "Visualizza dettagli Richiesta ", wid.User, wid.Groups, DateTime.Now, false, out attributes);
            //DateTime now = DateTime.Now;
            //int max = 10000;
            //string user = wid.GetUserBinarySSid();
            //string[] groups = wid.GetGroupsBinarySSid();
            //for (int i = 0; i < max; i++)
            //{
            //    AuthorizationType auth = sc.CheckAccess("Italferr", "CartaDeiServizi", "visualizza dettagli richiesta", user, groups, DateTime.Now, false, out attributes);
            //}
            //TimeSpan ts = DateTime.Now.Subtract(now);
            //MessageBox.Show(String.Format("Total: {0} - Single: {1}",ts.TotalMilliseconds, ts.TotalMilliseconds/(double)max));
        }