Ejemplo n.º 1
0
        public override string ToString()
        {
            string val = string.Empty;

            switch (Type)
            {
            case ValueType.Boolean:
                val = BoolValue.ToString();
                break;

            case ValueType.Integer:
                val = IntValue.ToString();
                break;

            case ValueType.Null:
                break;

            case ValueType.Process:
                val = ProcessValue.ToString();
                break;

            case ValueType.String:
                val = '"' + Regex.Escape(StringValue) + '"';
                break;

            case ValueType.SshConnection:
                val = SshValue.Info.Host;
                break;
            }

            return($"[{Type}] {val}");
        }
        /// <summary>
        /// Listing 5-14
        /// </summary>
        static void ParallelLoopBodyAnalysis()
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            //Perform simple Parallel Loop
            Parallel.For(0, resultData.Length, (index) =>
            {
                resultData[index] = Math.Pow(index, 2);
                //Console.WriteLine("Value:{0} -- Square: {1}", index, Math.Pow(index, 2));
            });
            watch.Stop();
            Console.WriteLine("Simple Parallel Loop took {0} Milliseconds", watch.ElapsedMilliseconds);

            //Perform Parallel Loop But make delegate explicit
            watch = System.Diagnostics.Stopwatch.StartNew();
            Parallel.For(0, resultData.Length, delegate(int index) { resultData[index] = Math.Pow(index, 2); });
            watch.Stop();
            Console.WriteLine("Parallel Loop But make delegate explicit took {0} Milliseconds", watch.ElapsedMilliseconds);


            //Perform Loop with Declared Delegate and Action
            watch = System.Diagnostics.Stopwatch.StartNew();
            ProcessValue pdel    = new ProcessValue(ComputeSquare);
            Action <int> paction = new Action <int>(pdel);

            Parallel.For(0, resultData.Length, paction);
            watch.Stop();
            Console.WriteLine("Parallel Loop with Declared Delegate and Action took {0} Milliseconds", watch.ElapsedMilliseconds);
        }
Ejemplo n.º 3
0
    public void StopListen(ProcessValue callback)
    {
        ListenHandler handler;

        if (m_Listeners.TryGetValue(callback, out handler))
        {
            m_Database.Child(handler.dbPath).ValueChanged -= handler.handler;
        }
    }
        public ProcessValueViewModel()
        {
            ProcessValue = new ProcessValue();
            DbProcessValue      pv         = new DbProcessValue();
            List <ProcessValue> processLst = pv.FindAllMechanismBySectionAndEvent();

            ProcessValues = new ObservableCollection <ProcessValue>();
            foreach (var item in processLst)
            {
                ProcessValues.Add(item);
            }

            ProcessValues.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ProcessValues_CollectionChanged);
        }
Ejemplo n.º 5
0
    public void Listen(string dbPath, ProcessValue callback)
    {
        ListenHandler handler = new ListenHandler()
        {
            dbPath  = dbPath,
            handler = (object sender, ValueChangedEventArgs e) => {
                callback(e.Snapshot.Value);
            }
        };

        m_Listeners.Add(callback, handler);

        m_Database.Child(dbPath).ValueChanged += handler.handler;
    }
Ejemplo n.º 6
0
 public void GetValueAsync(string dbPath, ProcessValue callback)
 {
     m_Database.Child(dbPath).GetValueAsync().ContinueWith(
         task => {
         if (task.IsFaulted)
         {
             // Handle the error...
         }
         else if (task.IsCompleted)
         {
             DataSnapshot snapshot = task.Result;
             callback(snapshot.Value);
         }
     }
         );
 }
Ejemplo n.º 7
0
        public List <ProcessValue> FindAllMechanismBySectionAndEvent()
        {
            SqlConnection con = null;

            DataSet             ds          = null;
            List <ProcessValue> processList = null;

            try
            {
                con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ToString());
                SqlCommand cmd = new SqlCommand("PR_AP_SEL_MECHANISM", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@idProcessType", 1);
                cmd.Parameters.AddWithValue("@idEvent", 1);

                con.Open();
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;

                ds = new DataSet();
                da.Fill(ds);

                processList = new List <ProcessValue>();


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ProcessValue pobj = new ProcessValue();

                    pobj.fTotals = int.Parse(ds.Tables[0].Rows[i]["fTotEv"].ToString());
                    pobj.fTotEv  = int.Parse(ds.Tables[0].Rows[i]["fTotals"].ToString());
                    pobj.tmpName = ds.Tables[0].Rows[i]["vcName"].ToString();

                    processList.Add(pobj);
                }
                return(processList);
            }
            catch
            {
                return(processList);
            }
            finally
            {
                con.Close();
            }
        }
Ejemplo n.º 8
0
        public static void UsingChunkPartitioningStrategy()
        {
            Parallel.For(0, resultData.Length, (int index) =>
            {
                resultData[index] = Math.Pow(index, 2);
            });

            Parallel.For(0, resultData.Length, delegate(int index)
            {
                resultData[index] = Math.Pow((double)index, 2);
            });

            ProcessValue pdel    = new ProcessValue(computeResultValue);
            Action <int> paction = new Action <int>(pdel);

            Parallel.For(0, resultData.Length, paction);

            Console.WriteLine("result : {0}", resultData[40000]);
            EndOfProgram();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            // perform the parallel loop
            Parallel.For(0, resultData.Length, (int index) => {
                // compuute the result for the current index
                resultData[index] = Math.Pow(index, 2);
            });

            // perform the loop again, but make the delegate explicit
            Parallel.For(0, resultData.Length, delegate(int index) {
                resultData[index] = Math.Pow((double)index, 2);
            });

            // perform the loop once more, but this time using
            // a declared delegate and action
            ProcessValue pdel = new ProcessValue(computeResultValue);
            Action<int> paction = new Action<int>(pdel);
            Parallel.For(0, resultData.Length, paction);

            // wait for input before exiting
            Console.WriteLine("Press enter to finish");
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        static void Main87(string[] args)
        {
            // When using lambda expressions, it is easy to forget that the compiler is creating an anonymous delegate
            Parallel.For(0, resultData.Length, (int index) =>
            {
                // compuute the result for the current index
                resultData[index] = Math.Pow(index, 2);
            });
            // perform the loop again, but make the delegate explicit
            Parallel.For(0, resultData.Length, delegate(int index)
            {
                resultData[index] = Math.Pow((double)index, 2);
            });
            // perform the loop once more, but this time using
            // a declared delegate and action
            ProcessValue pdel    = new ProcessValue(computeResultValue);
            Action <int> paction = new Action <int>(pdel);

            Parallel.For(0, resultData.Length, paction);
            // wait for input before exiting
            Console.WriteLine("Press enter to finish");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            // Perform the parallel loop
            stopwatch.Start();
            Parallel.For(0, resultData.Length, index =>
            {
                // Compute the result for the current index
                resultData[index] = Math.Pow(index, 2);
            });
            stopwatch.Stop();
            Console.WriteLine("Loop takes {0} seconds", stopwatch.Elapsed.TotalSeconds);

            // Perform the loop again, but make the delegate explicit
            stopwatch.Restart();
            Parallel.For(0, resultData.Length, delegate(int index)
            {
                resultData[index] = Math.Pow(index, 2);
            });
            stopwatch.Stop();
            Console.WriteLine("Loop with delegate takes {0} seconds", stopwatch.Elapsed.TotalSeconds);

            // Perform the loop once more, but this time using the declared delegate action
            ProcessValue pdel    = new ProcessValue(ComputeResultValue);
            Action <int> paction = new Action <int>(pdel);

            stopwatch.Restart();
            Parallel.For(0, resultData.Length, paction);
            stopwatch.Stop();
            Console.WriteLine("Loop with delegate action takes {0} seconds", stopwatch.Elapsed.TotalSeconds);

            // Wait for input before exiting
            Console.WriteLine("Press enter to finish");
            Console.ReadLine();
        }
Ejemplo n.º 12
0
 public BinPkgFile()
 {
     _processValue = new ProcessValue();
 }
Ejemplo n.º 13
0
 public string Prepare(string body, ProcessValue process, TokensSet[] tokens)
 {
     return _prepare != null ? _prepare(body, process, tokens) : body;
 }