Beispiel #1
0
        private Bitmap makeAnimationWithReapeat(BlockingCollection <Bitmap> pathImageList)
        {
            Bitmap bm = null;

            if (pathImageList.Count != 0 && lastIndex > pathImageList.Count - 1)
            {
                lastIndex = 0;
                bm        = pathImageList.ElementAt(lastIndex);
            }
            else
            {
                bm = pathImageList.ElementAt(lastIndex);
            }
            lastIndex++;
            return(bm);
        }
Beispiel #2
0
 /// <summary>
 /// Starts at the top of the BlockingCollection, breaks as soon as it finds an instance where the predicate is true.
 /// </summary>
 /// <returns>Removes each instance of the blocking collection, ceases execution once it finds a true instance.</returns>
 public static void TakeAndBreak <T>(this BlockingCollection <T> collection, Func <T, bool> predicate)
 {
     while (true)
     {
         try
         {
             if (collection == null || collection.Count == 0)
             {
                 break;
             }
             T value = collection.ElementAt <T>(0);
             if (!predicate(value))  //evaluate the item at the top of the list against the predicate, determine if it needs to be removed.
             {
                 collection.TryTake(out value);
             }
             else
             {
                 break; //When the predicate ceases to be true, end execution early.
             }
         }
         catch
         {
             break;
         }
     }
 }
Beispiel #3
0
        public void TestCancellationApi()
        {
            IHostEnvironment env = new MLContext(seed: 42);
            var mainHost         = env.Register("Main");
            var children         = new ConcurrentDictionary <IHost, List <IHost> >();
            var hosts            = new BlockingCollection <Tuple <IHost, int> >();

            hosts.Add(new Tuple <IHost, int>(mainHost.Register("1"), 1));
            hosts.Add(new Tuple <IHost, int>(mainHost.Register("2"), 1));
            hosts.Add(new Tuple <IHost, int>(mainHost.Register("3"), 1));
            hosts.Add(new Tuple <IHost, int>(mainHost.Register("4"), 1));
            hosts.Add(new Tuple <IHost, int>(mainHost.Register("5"), 1));

            for (int i = 0; i < 5; i++)
            {
                var tuple   = hosts.ElementAt(i);
                var newHost = tuple.Item1.Register((tuple.Item2 + 1).ToString());
                hosts.Add(new Tuple <IHost, int>(newHost, tuple.Item2 + 1));
            }

            ((MLContext)env).CancelExecution();

            //Ensure all created hosts are canceled.
            //5 parent and one child for each.
            Assert.Equal(10, hosts.Count);

            foreach (var host in hosts)
            {
                Assert.True((host.Item1 as ICancelable).IsCanceled);
            }
        }
Beispiel #4
0
        public static void SwitchBufer(string message)
        {
            int nodeOut;

            try
            {
                int start  = message.IndexOf("<port>");
                int number = Int32.Parse(message.Substring(start + 6, 4));
                Console.WriteLine("Port: " + number);

                int linkOut = linkDictionary[number];
                //chodzi o to ze jak portOut ma format 4 cyfrowy to w port_In 2 pierwsze cyfry to skad idzie, a w port_out dokad
                //zatem w port out musimy wyluskac tysiace i sprowadzic je do jednosci
                nodeOut = (linkOut - (linkOut % 100)) / 100 - 10;
                if (nodeOut < 80)
                {
                    Console.WriteLine("Przełączam węzły: " + nodeOut);
                }
                else
                {
                    Console.WriteLine("Przełączam na klienta: " + (nodeOut - 80));
                }

                if (nodeOut < 80)
                {
                    lock (nodeCollection.ElementAt(nodeOut - 1))
                    {
                        nodeCollection.ElementAt(nodeOut - 1).Add(message);
                    }
                }
                else
                {
                    lock (clientCollection.ElementAt(nodeOut - 81))
                    {
                        clientCollection.ElementAt(nodeOut - 81).Add(message);
                        //     Console.WriteLine(clientCollection.ElementAt(nodeOut - 81).Last());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Nie znaleziono połączenia, ex:" + ex.ToString());
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            const int ACCOUNT_COUNT = 100;
            const int THREAD_COUNT  = 1000;
            var       accounts      = new BlockingCollection <Account>();

            for (var i = 0; i < ACCOUNT_COUNT; i++)
            {
                var account = new Account();
                accounts.Add(account);
            }

            for (var i = 0; i < THREAD_COUNT; i++)
            {
                if (i % 2 == 0)
                {
                    var random  = new Random();
                    var index   = random.Next(0, accounts.Count);
                    var account = accounts.ElementAt(index);
                    lock (account)
                    {
                        ThreadPool.QueueUserWorkItem(account.ChangeBalance, 100);
                        Console.WriteLine($"Счёт пополнен на 100, баланс равен {accounts.ElementAt(index).Balance}");
                    }
                }
                else
                {
                    var random  = new Random();
                    var index   = random.Next(0, accounts.Count);
                    var account = accounts.ElementAt(index);
                    lock (account)
                    {
                        ThreadPool.QueueUserWorkItem(account.ChangeBalance, -100);
                        Console.WriteLine($"Со счёта снято 100, баланс равен {account.Balance}");
                    }
                }
            }
            foreach (var account in accounts)
            {
                Console.WriteLine(account.Id + " - " + account.Balance);
            }
        }
        private void bw2_DoWork(object sender, DoWorkEventArgs e)
        {
            if (selectedTarget != -1)
            {
                if (workerAction == "add")
                {
                    try
                    {
                        Form1.Target myTarget = Targets.ElementAt(selectedTarget);

                        string coURL        = GetServiceUrl(myTarget.targetService.Device.DocumentURL);
                        string serviceIdent = myTarget.targetService.ServiceTypeIdentifier;

                        addPortMapping(coURL, serviceIdent, remoteHostEntry.Text, externalPortEntry.Text, protocolEntry.Text, internalPortEntry.Text, internalClientEntry.Text, enabledEntry.Text, portMappingDescEntry.Text, leaseDurationEntry.Text);
                    }
                    catch
                    {
                    }
                }

                if (workerAction == "del")
                {
                    try
                    {
                        Form1.Target myTarget = Targets.ElementAt(selectedTarget);

                        string coURL        = GetServiceUrl(myTarget.targetService.Device.DocumentURL);
                        string serviceIdent = myTarget.targetService.ServiceTypeIdentifier;

                        deletePortMapping(coURL, serviceIdent, remoteHostEntry.Text, externalPortEntry.Text, protocolEntry.Text);
                    }
                    catch
                    {
                    }
                }
            }
        }
Beispiel #7
0
        private Bitmap makeAnimation(BlockingCollection <Bitmap> pathImageList, ref bool animationCompleate)
        {
            Bitmap bm = null;

            if (pathImageList.Count != 0 && lastIndex > pathImageList.Count - 1)
            {
                animationCompleate = true;
            }
            else
            {
                bm = pathImageList.ElementAt(lastIndex);
            }
            lastIndex++;
            return(bm);
        }
 public NodeInfo GetNodeInfo()
 {
     return(new NodeInfo
     {
         About = _nodeSettings.About,
         NodeId = _nodeSettings.NodeId,
         ChainId = _chain.ElementAt(0).DataHash.ToHex(),
         NodeUrl = _nodeSettings.NodeUrl,
         Peers = _peerSynchronizationService.GetPeersCount(),
         CurrentDifficulty = _nodeSettings.CurrentDifficulty,
         BlocksCount = _chain.Count,
         CumulativeDifficulty = GetCumulativeDifficulty(),
         ConfirmedTransactions = _confirmedTransactions.Count,
         PendingTransactions = _pendingTransactions.Count
     });
 }
Beispiel #9
0
        static void Main(string[] args)
        {
            //object syncObject = new object();

            BlockingCollection <Account> accounts = new BlockingCollection <Account>()
            {
                new Account
                {
                    Name          = "Пупкин А. В.",
                    AccountNumber = "KZ74155898RB0000345",
                    Cash          = 10000
                },
                new Account
                {
                    Name          = "Сидоров О. С.",
                    AccountNumber = "KZ71114528RB0000345",
                    Cash          = 10000
                },
                new Account
                {
                    Name          = "Федоров Ф. В.",
                    AccountNumber = "KZ78876966RB0000345",
                    Cash          = 10000
                },
                new Account
                {
                    Name          = "Бугарин У. В.",
                    AccountNumber = "KZ78985532RB0000345",
                    Cash          = 10000
                },
                new Account
                {
                    Name          = "Петров А. Л.",
                    AccountNumber = "KZ77855654RB0000345",
                    Cash          = 10000
                },
            };

            for (int i = 0; i < 1000; i++)
            {
                lock (accounts)
                {
                    if (i % 2 == 0)
                    {
                        for (int j = 0; j < accounts.Count; j++)
                        {
                            ThreadPool.QueueUserWorkItem(accounts.ElementAt(j).AddMoney, 100);
                        }
                    }
                    else
                    {
                        for (int j = 0; j < accounts.Count; j++)
                        {
                            ThreadPool.QueueUserWorkItem(accounts.ElementAt(j).WithDrawMoney, 100);
                        }
                    }
                    Thread.Sleep(5);
                }
            }

            foreach (var account in accounts)
            {
                Console.WriteLine(account.Name + " - " + account.Cash);
            }
            Console.ReadLine();
        }
Beispiel #10
0
        public void TestCancellation()
        {
            IHostEnvironment env = new MLContext(seed: 42);

            for (int z = 0; z < 1000; z++)
            {
                var mainHost = env.Register("Main");
                var children = new ConcurrentDictionary <IHost, List <IHost> >();
                var hosts    = new BlockingCollection <Tuple <IHost, int> >();
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("1"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("2"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("3"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("4"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("5"), 1));

                int    iterations = 100;
                Random rand       = new Random();
                var    addThread  = new Thread(
                    () =>
                {
                    for (int i = 0; i < iterations; i++)
                    {
                        var randHostTuple = hosts.ElementAt(rand.Next(hosts.Count - 1));
                        var newHost       = randHostTuple.Item1.Register((randHostTuple.Item2 + 1).ToString());
                        hosts.Add(new Tuple <IHost, int>(newHost, randHostTuple.Item2 + 1));
                        if (!children.ContainsKey(randHostTuple.Item1))
                        {
                            children[randHostTuple.Item1] = new List <IHost>();
                        }
                        else
                        {
                            children[randHostTuple.Item1].Add(newHost);
                        }
                    }
                });
                addThread.Start();
                Queue <IHost> queue = new Queue <IHost>();
                for (int i = 0; i < 5; i++)
                {
                    IHost rootHost = null;
                    var   index    = 0;
                    do
                    {
                        index = rand.Next(hosts.Count);
                    } while ((hosts.ElementAt(index).Item1 as ICancelable).IsCanceled ||
                             // use 2 instead of 3 here as there is no guarantee there is always level 2 children
                             hosts.ElementAt(index).Item2 < 2);
                    (hosts.ElementAt(index).Item1 as ICancelable).CancelExecution();
                    rootHost = hosts.ElementAt(index).Item1;
                    queue.Enqueue(rootHost);

                    // all children has been canceled, we should stop looking
                    if (hosts.Count(q => (q.Item1 as ICancelable).IsCanceled) == hosts.Count - 5)
                    {
                        break;
                    }
                }
                addThread.Join();
                while (queue.Count > 0)
                {
                    var currentHost = queue.Dequeue();
                    Assert.True((currentHost as ICancelable).IsCanceled);

                    if (children.ContainsKey(currentHost))
                    {
                        children[currentHost].ForEach(x => queue.Enqueue(x));
                    }
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// Gets the random item.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="items">The items.</param>
 /// <returns></returns>
 public static T GetRandomItem <T>(this BlockingCollection <T> items) where T : class
 {
     return(items.ElementAt(DummyDataProvider.Instance.GetRandomNumber(items.Count())));
 }
Beispiel #12
0
 public Block GetBlock(int index)
 {
     return(_blocks.ElementAt(index));
 }
Beispiel #13
0
        public static void wysylaj()
        {
            while (true)
            {
                while (kolejkaWiadomosci.Count == 0)
                {
                }
                string nowaWiadomosc;
                string wiadomosc = kolejkaWiadomosci.ElementAt(0);
                kolejkaWiadomosci.Take();
                string[] words = wiadomosc.Split(' ');
                switch (wiadomosc.Length)
                {
                case 10:     //kolor

                    Uzytkownik temp;
                    polaczenia.TryGetValue(int.Parse(words[0]), out temp);
                    temp.ustawKolor(int.Parse(words[1]), int.Parse(words[2]), int.Parse(words[3]));
                    Console.WriteLine("{0} {1} {2}", int.Parse(words[1]), int.Parse(words[2]), int.Parse(words[3]));
                    break;

                case 3:    // zakonczenie
                    nowaWiadomosc = words[0].ToString();
                    Byte[] sendBytes2 = Encoding.ASCII.GetBytes(nowaWiadomosc);
                    foreach (Uzytkownik osoba in polaczenia.Values)
                    {
                        udpRysowanie.Send(sendBytes2, sendBytes2.Length, osoba.getAdres());
                    }
                    while (piszacyUzytkownicy.ContainsKey(int.Parse(words[0])))
                    {
                        piszacyUzytkownicy.Remove(int.Parse(words[0]));
                    }
                    break;

                default:
                    if (!piszacyUzytkownicy.ContainsKey(int.Parse(words[0])))
                    {
                        Uzytkownik chwilowy;
                        String     info;
                        polaczenia.TryGetValue(int.Parse(words[0]), out chwilowy);
                        piszacyUzytkownicy.Add(int.Parse(words[0]), int.Parse(words[0]));
                        info = chwilowy.getR().ToString();

                        nowaWiadomosc = words[0].ToString() + ' ' + words[1].ToString() + ' ' + words[2].ToString() + ' ' + chwilowy.getR().ToString() + ' ' + chwilowy.getG().ToString() + ' ' + chwilowy.getB().ToString();



                        Byte[] sendBytes = Encoding.ASCII.GetBytes(nowaWiadomosc);
                        foreach (Uzytkownik osoba in polaczenia.Values)
                        {
                            Console.WriteLine("Info {0}", info);
                            udpRysowanie.Send(sendBytes, sendBytes.Length, osoba.getAdres());
                        }
                    }
                    else
                    {
                        nowaWiadomosc = words[0] + " " + words[1] + ' ' + words[2];


                        Byte[] sendBytes = Encoding.ASCII.GetBytes(nowaWiadomosc);
                        foreach (Uzytkownik osoba in polaczenia.Values)
                        {
                            udpRysowanie.Send(sendBytes, sendBytes.Length, osoba.getAdres());
                        }
                    }
                    break;
                }
            }
        }
Beispiel #14
0
        public void TestCancellation()
        {
            IHostEnvironment env = new MLContext(seed: 42);

            for (int z = 0; z < 1000; z++)
            {
                var mainHost = env.Register("Main");
                var children = new ConcurrentDictionary <IHost, List <IHost> >();
                var hosts    = new BlockingCollection <Tuple <IHost, int> >();
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("1"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("2"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("3"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("4"), 1));
                hosts.Add(new Tuple <IHost, int>(mainHost.Register("5"), 1));

                int    iterations = 100;
                Random rand       = new Random();
                var    addThread  = new Thread(
                    () =>
                {
                    for (int i = 0; i < iterations; i++)
                    {
                        var randHostTuple = hosts.ElementAt(rand.Next(hosts.Count - 1));
                        var newHost       = randHostTuple.Item1.Register((randHostTuple.Item2 + 1).ToString());
                        hosts.Add(new Tuple <IHost, int>(newHost, randHostTuple.Item2 + 1));
                        if (!children.ContainsKey(randHostTuple.Item1))
                        {
                            children[randHostTuple.Item1] = new List <IHost>();
                        }
                        else
                        {
                            children[randHostTuple.Item1].Add(newHost);
                        }
                    }
                });
                addThread.Start();
                Queue <IHost> queue = new Queue <IHost>();
                for (int i = 0; i < 5; i++)
                {
                    IHost rootHost = null;
                    var   index    = 0;
                    do
                    {
                        index = rand.Next(hosts.Count);
                    } while (hosts.ElementAt(index).Item1.IsCancelled || hosts.ElementAt(index).Item2 < 3);
                    hosts.ElementAt(index).Item1.StopExecution();
                    rootHost = hosts.ElementAt(index).Item1;
                    queue.Enqueue(rootHost);
                }
                addThread.Join();
                while (queue.Count > 0)
                {
                    var currentHost = queue.Dequeue();
                    Assert.True(currentHost.IsCancelled);

                    if (children.ContainsKey(currentHost))
                    {
                        children[currentHost].ForEach(x => queue.Enqueue(x));
                    }
                }
            }
        }
        internal void Sort(BlockingCollection <SpecProcess> unsortedQuery)
        {
            IEnumerable <SpecProcess> sortedQuery;

            switch (parent.SortIndex)
            {
            case 0:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.InnerProcess.ProcessName
                    select SpecProcess;
                break;

            case 1:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.InnerProcess.Id
                    select SpecProcess;
                break;

            case 2:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.InnerProcess.Responding
                    select SpecProcess;
                break;

            case 3:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.PercentCPULoad
                    select SpecProcess;
                break;

            case 4:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.PercentRAMLoad
                    select SpecProcess;
                break;

            case 5:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.InnerProcess.StartTime
                    select SpecProcess;
                break;

            case 6:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.InnerProcess.Threads.Count
                    select SpecProcess;
                break;

            case 7:
                sortedQuery =
                    from SpecProcess in unsortedQuery
                    orderby SpecProcess.UserName
                    select SpecProcess;
                break;

            default:
                sortedQuery = unsortedQuery;
                break;
            }
            BlockingCollection <SpecProcess> processes = new BlockingCollection <SpecProcess>();

            for (int i = 0; i < unsortedQuery.Count; i++)
            {
                processes.Add(sortedQuery.ElementAt(i));
                if (sortedQuery.ElementAt(i).InnerProcess.Id == parent.selectedProcess.Id)
                {
                    parent.RowIndex = i;
                }
            }
            parent.ProcessQuery = processes;
            parent.NotifyPropertyChanged("ProcessQuery");
        }
Beispiel #16
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            treeData = new BlockingCollection<TreeNode>();
            RootNodes.Clear();
            
            int i = -1;
            int j = 0;

            targetDoneCount = Targets.Count();

            foreach (Target myTarget in Targets)
            {

                if (!RootNodes.Contains(myTarget.documentURL))
                {
                    i++;
                    j = 0;

                    TreeNode newNode = new TreeNode();
                    newNode.Name = myTarget.targetId.ToString();

                    Font boldFont = new Font(treeView1.Font, FontStyle.Bold);
                    newNode.NodeFont = boldFont;

                    newNode.Text = myTarget.friendlyName;
                    newNode.Text = newNode.Text;

                    newNode.ToolTipText = "Device Description:\r\n" + myTarget.friendlyName +
                         "\r\nDocument URL:\r\n" + myTarget.documentURL +
                        "\r\nControl URL:\r\n" + myTarget.controlURL + "\r\n";
                    newNode.Tag = myTarget;

                    treeData.Add(newNode);

                    RootNodes.Add(myTarget.documentURL);
                }
                else
                {
                    i = RootNodes.IndexOf(myTarget.documentURL);
                    j = treeData.ElementAt(i).GetNodeCount(false);
                }

                string makeSOAPRequest = "<?xml version=\"1.0\"?>\r\n" +
                                         "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" +
                                         "<s:Body>\r\n" +
                                         "<m:" + myTarget.actionDesc.Name + " xmlns:m=\"" + myTarget.ServiceTypeIdentifier + "\">\r\n";

                string makeSOAPResponse = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
                                          "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" +
                                          "<s:Body>\r\n" +
                                          "<u:" + myTarget.actionDesc.Name + " xmlns:u=\"" + myTarget.ServiceTypeIdentifier + "\">";

                List<String> collectDataType = new List<string>();


                bool alreadyHasAction = false;

                foreach (TreeNode checkNode in treeData.ElementAt(i).Nodes)
                {
                    if (checkNode.Text == myTarget.actionDesc.Name)
                    {
                        alreadyHasAction = true;
                    }
                }

                if (!alreadyHasAction)
                {
                    treeData.ElementAt(i).Nodes.Add(myTarget.targetId.ToString(), myTarget.actionDesc.Name);
                    treeData.ElementAt(i).Nodes[j].Tag = myTarget;

                    foreach (ArgumentDescription nArg in myTarget.actionDesc.Arguments.Values)
                    {
                        if (nArg.Direction == "in")
                        {
                            TreeNode argumentNode = treeData.ElementAt(i).Nodes[j].Nodes.Add(myTarget.targetId.ToString(), String.Format("->{0}", nArg.Name));
                            argumentNode.Tag = myTarget;

                            argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Data Type: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType));
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Default Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                int av = 1;
                                foreach (string allowedValue in myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues)
                                {
                                    argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Allowed Value {0}: {1}", av.ToString(), allowedValue));
                                    av++;
                                }
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Minimum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Maximum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum));
                            }

                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue + "</" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum + "</" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues[0] + "</" + nArg.Name + ">\r\n";
                            }
                            else
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + "?" + "</" + nArg.Name + ">\r\n";
                            }

                        }
                        else
                        {
                            TreeNode argumentNode = treeData.ElementAt(i).Nodes[j].Nodes.Add(myTarget.targetId.ToString(), String.Format("<-{0}", nArg.Name));

                            argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Data Type: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType));
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Default Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                int av = 1;
                                foreach (string allowedValue in myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues)
                                {
                                    argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Allowed Value {0}: {1}", av.ToString(), allowedValue));
                                    av++;
                                }
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Minimum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Maximum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum));
                            }

                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + "><DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue + "<DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE></" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + "><DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum + "<DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE></" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + "><DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues[0] + "<DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE></" + nArg.Name + ">\r\n";
                            }
                            else
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + ">" + "<FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + "</" + nArg.Name + ">\r\n";
                            }

                            collectDataType.Add(myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType);

                        }
                    }
                    j++;
                }

                makeSOAPRequest = makeSOAPRequest + "</m:" + myTarget.actionDesc.Name + ">\r\n" +
                                                    "</s:Body>\r\n" +
                                                    "</s:Envelope>\r\n";

                makeSOAPResponse = makeSOAPResponse + "</u:" + myTarget.actionDesc.Name + ">\r\n" +
                                                    "</s:Body>\r\n" +
                                                    "</s:Envelope>\r\n";

                myTarget.soapRequest = makeSOAPRequest;
                myTarget.soapResponse = makeSOAPResponse;
                myTarget.dataTypes = collectDataType;

            }

            foreach (Device quickListDevice in Devices)
            {
                if (!RootNodes.Contains(quickListDevice.DocumentURL))
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text = quickListDevice.FriendlyName;
                    newNode.ToolTipText = "Device Description:\r\n" + quickListDevice.FriendlyName +
                        "\r\nDocument URL:\r\n" + quickListDevice.DocumentURL + "\r\n";

                    Target deviceTarget = new Target();

                    deviceTarget.friendlyName = quickListDevice.FriendlyName;
                    deviceTarget.controlURL = "";
                    deviceTarget.documentURL = quickListDevice.DocumentURL;
                    deviceTarget.soapRequest = "";
                    deviceTarget.soapResponse = "";
                    deviceTarget.notEnum = true;
                    deviceTarget.thisDevice = quickListDevice;
                    newNode.Tag = deviceTarget;

                    if (devicesWithError.Contains(quickListDevice.DocumentURL))
                    {
                        newNode.ForeColor = System.Drawing.Color.Red;
                        newNode.Text = newNode.Text + " (error)";
                    }


                    treeData.Add(newNode);

                    RootNodes.Add(quickListDevice.DocumentURL);
                }
            }
            deviceFoundCount = RootNodes.Count();
        }
Beispiel #17
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            treeData = new BlockingCollection <TreeNode>();
            RootNodes.Clear();

            int i = -1;
            int j = 0;

            targetDoneCount = Targets.Count();

            foreach (Target myTarget in Targets)
            {
                if (!RootNodes.Contains(myTarget.documentURL))
                {
                    i++;
                    j = 0;

                    TreeNode newNode = new TreeNode();
                    newNode.Name = myTarget.targetId.ToString();

                    Font boldFont = new Font(treeView1.Font, FontStyle.Bold);
                    newNode.NodeFont = boldFont;

                    newNode.Text = myTarget.friendlyName;
                    newNode.Text = newNode.Text;

                    newNode.ToolTipText = "Device Description:\r\n" + myTarget.friendlyName +
                                          "\r\nDocument URL:\r\n" + myTarget.documentURL +
                                          "\r\nControl URL:\r\n" + myTarget.controlURL + "\r\n";
                    newNode.Tag = myTarget;

                    treeData.Add(newNode);

                    RootNodes.Add(myTarget.documentURL);
                }
                else
                {
                    i = RootNodes.IndexOf(myTarget.documentURL);
                    j = treeData.ElementAt(i).GetNodeCount(false);
                }

                string makeSOAPRequest = "<?xml version=\"1.0\"?>\r\n" +
                                         "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" +
                                         "<s:Body>\r\n" +
                                         "<m:" + myTarget.actionDesc.Name + " xmlns:m=\"" + myTarget.ServiceTypeIdentifier + "\">\r\n";

                string makeSOAPResponse = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
                                          "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" +
                                          "<s:Body>\r\n" +
                                          "<u:" + myTarget.actionDesc.Name + " xmlns:u=\"" + myTarget.ServiceTypeIdentifier + "\">";

                List <String> collectDataType = new List <string>();


                bool alreadyHasAction = false;

                foreach (TreeNode checkNode in treeData.ElementAt(i).Nodes)
                {
                    if (checkNode.Text == myTarget.actionDesc.Name)
                    {
                        alreadyHasAction = true;
                    }
                }

                if (!alreadyHasAction)
                {
                    treeData.ElementAt(i).Nodes.Add(myTarget.targetId.ToString(), myTarget.actionDesc.Name);
                    treeData.ElementAt(i).Nodes[j].Tag = myTarget;

                    foreach (ArgumentDescription nArg in myTarget.actionDesc.Arguments.Values)
                    {
                        if (nArg.Direction == "in")
                        {
                            TreeNode argumentNode = treeData.ElementAt(i).Nodes[j].Nodes.Add(myTarget.targetId.ToString(), String.Format("->{0}", nArg.Name));
                            argumentNode.Tag = myTarget;

                            argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Data Type: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType));
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Default Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                int av = 1;
                                foreach (string allowedValue in myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues)
                                {
                                    argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Allowed Value {0}: {1}", av.ToString(), allowedValue));
                                    av++;
                                }
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Minimum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Maximum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum));
                            }

                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue + "</" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum + "</" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues[0] + "</" + nArg.Name + ">\r\n";
                            }
                            else
                            {
                                makeSOAPRequest = makeSOAPRequest + "<" + nArg.Name + ">" + "?" + "</" + nArg.Name + ">\r\n";
                            }
                        }
                        else
                        {
                            TreeNode argumentNode = treeData.ElementAt(i).Nodes[j].Nodes.Add(myTarget.targetId.ToString(), String.Format("<-{0}", nArg.Name));

                            argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Data Type: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType));
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Default Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                int av = 1;
                                foreach (string allowedValue in myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues)
                                {
                                    argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Allowed Value {0}: {1}", av.ToString(), allowedValue));
                                    av++;
                                }
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Minimum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Minimum));
                            }
                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                argumentNode.Nodes.Add(myTarget.targetId.ToString(), String.Format("Maximum Value: {0}", myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum));
                            }

                            if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue != "")
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + "><DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DefaultValue + "<DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE></" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum != "")
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + "><DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedRange.Maximum + "<DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE></" + nArg.Name + ">\r\n";
                            }
                            else if (myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues.Count > 0)
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + "><DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].AllowedValues[0] + "<DEFAULT-FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE></" + nArg.Name + ">\r\n";
                            }
                            else
                            {
                                makeSOAPResponse = makeSOAPResponse + "<" + nArg.Name + ">" + "<FUZZ-" + myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType + "-HERE>" + "</" + nArg.Name + ">\r\n";
                            }

                            collectDataType.Add(myTarget.targetServiceDesc.StateVariables[nArg.RelatedStateVariable].DataType);
                        }
                    }
                    j++;
                }

                makeSOAPRequest = makeSOAPRequest + "</m:" + myTarget.actionDesc.Name + ">\r\n" +
                                  "</s:Body>\r\n" +
                                  "</s:Envelope>\r\n";

                makeSOAPResponse = makeSOAPResponse + "</u:" + myTarget.actionDesc.Name + ">\r\n" +
                                   "</s:Body>\r\n" +
                                   "</s:Envelope>\r\n";

                myTarget.soapRequest  = makeSOAPRequest;
                myTarget.soapResponse = makeSOAPResponse;
                myTarget.dataTypes    = collectDataType;
            }

            foreach (Device quickListDevice in Devices)
            {
                if (!RootNodes.Contains(quickListDevice.DocumentURL))
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Text        = quickListDevice.FriendlyName;
                    newNode.ToolTipText = "Device Description:\r\n" + quickListDevice.FriendlyName +
                                          "\r\nDocument URL:\r\n" + quickListDevice.DocumentURL + "\r\n";

                    Target deviceTarget = new Target();

                    deviceTarget.friendlyName = quickListDevice.FriendlyName;
                    deviceTarget.controlURL   = "";
                    deviceTarget.documentURL  = quickListDevice.DocumentURL;
                    deviceTarget.soapRequest  = "";
                    deviceTarget.soapResponse = "";
                    deviceTarget.notEnum      = true;
                    deviceTarget.thisDevice   = quickListDevice;
                    newNode.Tag = deviceTarget;

                    if (devicesWithError.Contains(quickListDevice.DocumentURL))
                    {
                        newNode.ForeColor = System.Drawing.Color.Red;
                        newNode.Text      = newNode.Text + " (error)";
                    }


                    treeData.Add(newNode);

                    RootNodes.Add(quickListDevice.DocumentURL);
                }
            }
            deviceFoundCount = RootNodes.Count();
        }
Beispiel #18
0
        private Thread GenerateMonitorThread()
        {
            return(new Thread(async delegate()
            {
                while (monitor_active)
                {
                    //iterate through the expandermodificationproperties
                    //sort by priority
                    //compile into value to write
                    //write value to the expanders
                    if (expmodprops.Count > 0)
                    {
                        //expmodprops = expmodprops.OrderByDescending(o => o.StackPriority).ToList(); //probably not necessary, priorty is useless right now (and always?)

                        bool[] compiled_exp0mask = { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true };
                        bool[] compiled_exp1mask = { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true };
                        bool[] compiled_exp0vals = expmon.DefaultState.Expander0State;
                        bool[] compiled_exp1vals = expmon.DefaultState.Expander1State;

                        for (int index_counter = expmodprops.Count - 1; index_counter >= 0; index_counter--)
                        {
                            ExpanderModificationProperties expmodprop = expmodprops.ElementAt(index_counter);

                            if (expmodprop.Evaluate()) //true means its still active
                            {
                                for (int bool_counter = 0; bool_counter < 16; bool_counter++)
                                {
                                    if (expmodprop.AssociatedCar == 0)
                                    {
                                        compiled_exp0mask[bool_counter] = index_counter == expmodprops.Count - 1 ? compiled_exp0mask[bool_counter] & expmodprop.Exp0Mask[bool_counter] : compiled_exp0mask[bool_counter] |= expmodprop.Exp0Mask[bool_counter];
                                    }
                                    if (expmodprop.AssociatedCar == 1)
                                    {
                                        compiled_exp1mask[bool_counter] = index_counter == expmodprops.Count - 1 ? compiled_exp1mask[bool_counter] & expmodprop.Exp1Mask[bool_counter] : compiled_exp1mask[bool_counter] |= expmodprop.Exp1Mask[bool_counter];
                                    }

                                    if (expmodprop.AssociatedCar == 0)
                                    {
                                        compiled_exp0vals[bool_counter] |= expmodprop.Exp0Values[bool_counter];
                                    }
                                    if (expmodprop.AssociatedCar == 1)
                                    {
                                        compiled_exp1vals[bool_counter] |= expmodprop.Exp1Values[bool_counter];
                                    }
                                }
                            }
                            else
                            {
                                //if there are remaing items include the mask from the removed item so its values will be restored
                                if (expmodprops.Count > 1)
                                {
                                    for (int bool_counter = 0; bool_counter < 16; bool_counter++)
                                    {
                                        if (expmodprop.AssociatedCar == 0)
                                        {
                                            compiled_exp0mask[bool_counter] = index_counter == expmodprops.Count - 1 ? compiled_exp0mask[bool_counter] & expmodprop.Exp0Mask[bool_counter] : compiled_exp0mask[bool_counter] |= expmodprop.Exp0Mask[bool_counter];
                                        }

                                        if (expmodprop.AssociatedCar == 1)
                                        {
                                            compiled_exp1mask[bool_counter] = index_counter == expmodprops.Count - 1 ? compiled_exp1mask[bool_counter] & expmodprop.Exp1Mask[bool_counter] : compiled_exp1mask[bool_counter] |= expmodprop.Exp1Mask[bool_counter];
                                        }
                                    }
                                }

                                //set the value to null for removal later
                                expmodprops.TryTake(out expmodprop);
                            }
                        }

                        await expmon.WriteExpanders(compiled_exp0mask, compiled_exp1mask, compiled_exp0vals, compiled_exp1vals);
                        Console.WriteLine("wrote expanders from monitor");
                    }

                    Thread.Sleep(100);
                }
            }));
        }