Example #1
0
        protected override object GetValue(LogPacket p)
        {
            DataNode node = p.Frame.Root.SelectSingleNode(SelectionPath);

            if (node == null)
            {
                node = new StringDataValue("", "");
            }

            if (FormatExpression.IsValid)
            {
                ExpressionResolver          _resolver = new ExpressionResolver(typeof(LogPacket));
                Dictionary <string, object> extras    = new Dictionary <string, object>();
                extras["value"] = node;

                try
                {
                    return(_resolver.Resolve(p, _formatExpression, extras) ?? String.Empty);
                }
                catch (Exception)
                {
                    return(String.Empty);
                }
            }
            else
            {
                return(RawValue ? node.Value : node);
            }
        }
Example #2
0
        public void TestStringBackCoverter(string inputValue, string format, string expectedDisplayValue)
        {
            var varInfo = new StringDataValue(new DataValue(new Variant((Int64)0)));

            varInfo.FormatSelectedItem = format;
            varInfo.ConvertValueBack(inputValue);
            Assert.AreEqual(varInfo.GetRawValue(), expectedDisplayValue);
        }
Example #3
0
        public void TestStringCoverter(string inputValue, string format, string expectedDisplayValue)
        {
            var varInfo = new StringDataValue(new DataValue(new Variant(inputValue)));

            varInfo.FormatSelectedItem = format;
            var convVal = varInfo.ConvertValue();

            Assert.AreEqual(convVal, expectedDisplayValue);
        }
Example #4
0
        /// <summary>
        /// Extend selection syntax for nodes to handle global and meta parameters through
        /// # and $ prefixes
        /// </summary>
        /// <param name="path">The path to select</param>
        /// <param name="frame">The data frame to select off</param>
        /// <param name="node">The current node</param>
        /// <param name="globalMeta">Global meta</param>
        /// <param name="properties">Property bag</param>
        /// <param name="uuid">The uuid for private names</param>
        /// <param name="meta">Meta</param>
        /// <returns>An array of nodes</returns>
        public static DataNode[] SelectNodes(string path, DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, 
            PropertyBag properties, Guid uuid, BasePipelineNode node)
        {
            DataNode[] nodes = new DataNode[0];

            path = path.Trim();

            if (path.StartsWith("#"))
            {
                if (meta != null)
                {
                    string name = path.Substring(1);
                    object n = meta.GetMeta(MakePrivateMetaName(uuid, name));
                    if(n == null)
                    {
                        n = meta.GetMeta(name);
                    }

                    if (n != null)
                    {
                        nodes = new DataNode[1];
                        nodes[0] = new StringDataValue(path, n.ToString());
                    }
                }
            }
            else if (path.StartsWith("$"))
            {
                if (globalMeta != null)
                {
                    string name = path.Substring(1);
                    object n = globalMeta.GetMeta(MakePrivateMetaName(uuid, name));
                    if (n == null)
                    {
                        n = globalMeta.GetMeta(name);
                    }

                    if (n != null)
                    {
                        nodes = new DataNode[1];
                        nodes[0] = new StringDataValue(path, n.ToString());
                    }
                }
            }
            else if (path.StartsWith("~"))
            {
                if(properties != null)
                {
                    string name = path.Substring(1);
                    dynamic val = properties.GetRelativeValue(name);

                    if (val != null)
                    {
                        nodes = new DataNode[1];
                        nodes[0] = new StringDataValue(path, val.ToString());
                    }
                }
            }
            else if (path.StartsWith("&"))
            {
                DataNode n = null;

                if (path.Equals("&incount", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<int>(path, node != null ? node.InputPacketCount : 0);
                }
                else if (path.Equals("&outcount", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<int>(path, node != null ? node.OutputPacketCount : 0);
                }
                else if (path.Equals("&bytecount", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<long>(path, node != null ? node.ByteCount : 0);
                }
                else if (path.Equals("&length", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<long>(path, frame.Length);
                }
                else if (path.Equals("&md5", StringComparison.OrdinalIgnoreCase))
                {
                    n = new StringDataValue(path, frame.Hash);
                }
                else if (path.Equals("&display", StringComparison.OrdinalIgnoreCase))
                {
                    n = new StringDataValue(path, frame.ToString());
                }

                if (n != null)
                {
                    nodes = new DataNode[1];
                    nodes[0] = n;
                }
            }
            else
            {
                nodes = frame.SelectNodes(path);
            }

            return nodes;
        }
Example #5
0
        private static DataNode GetNode(string name, object o, Dictionary <Type, Guid> derivedTypes, bool readOnly)
        {
            DataNode ret = null;

            if (o != null)
            {
                Type t = o.GetType();

                if (o is DataNode)
                {
                    ret = ((DataNode)o).CloneNode();
                }
                else if (t.IsEnum)
                {
                    ret = new EnumDataValue(name, (Enum)o);
                }
                else if (t.IsPrimitive)
                {
                    ret = GetPrimitiveType(name, t, o);
                }
                else if (o is IPrimitiveValue)
                {
                    object v = ((IPrimitiveValue)o).Value;

                    ret = GetPrimitiveType(name, v.GetType(), v);
                }
                else if (t == typeof(DateTime))
                {
                    // Use a unix datetime, doesn't _really_ matter
                    ret = new UnixDateTimeDataValue(name, false, (DateTime)o);
                }
                else if (t == typeof(string))
                {
                    ret = new StringDataValue(name, (string)o);
                }
                else if (t == typeof(BigInteger))
                {
                    ret = new BigIntegerDataValue(name, (BigInteger)o);
                }
                else if (t.IsArray)
                {
                    if (t.GetElementType() == typeof(byte))
                    {
                        byte[] newArr = (byte[])((byte[])o).Clone();
                        ret = new ByteArrayDataValue(name, (byte[])o);
                    }
                    else if (t.GetElementType() == typeof(char))
                    {
                        ret = new StringDataValue(name, new string((char[])o));
                    }
                    else
                    {
                        DataKey key = new DataKey(name);

                        GetArrayType(key, t, o, derivedTypes, readOnly);

                        ret = key;
                    }
                }
                else if (t == typeof(IPAddress))
                {
                    ret = new IPAddressDataValue(name, (IPAddress)o);
                }
                else
                {
                    INodeConverter converter = o as INodeConverter;

                    if (converter != null)
                    {
                        ret = converter.ToNode(name);
                    }
                    else
                    {
                        DataKey key = new DataKey(name);

                        GetComplexType(key, t, o, derivedTypes);

                        ret = key;
                    }
                }

                if (ret != null)
                {
                    ret.Readonly = readOnly;
                }
            }

            return(ret);
        }
Example #6
0
        private void stackedChartWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState));
                this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults));

                RequestUpdateStatusDelegate requestUpdateStatus = new RequestUpdateStatusDelegate(RequestUpdateStatusMessage);
                CheckForCancellationDelegate checkForCancellation = new CheckForCancellationDelegate(IsCancelled);

                GadgetOptions.GadgetStatusUpdate += new GadgetStatusUpdateHandler(requestUpdateStatus);
                GadgetOptions.GadgetCheckForCancellation += new GadgetCheckForCancellationHandler(checkForCancellation);

                DataTable data = GetStackedColumnData();
                if (data == null || data.Rows.Count == 0)
                {
                    this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.NO_RECORDS_SELECTED);
                    this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                    return;
                }
                else if (worker.CancellationPending)
                {
                    this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED);
                    this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                    System.Diagnostics.Debug.Print("Stacked chart thread was cancelled");
                    return;
                }
                else if (data != null && data.Rows.Count > 0)
                {
                    //DataRow[] allRows;

                    //if (dashboardHelper.IsUsingEpiProject && data.Rows[0][0].ToString().Equals(dashboardHelper.Config.Settings.RepresentationOfYes) && (dashboardHelper.IsColumnYesNo(data.Columns[0].ColumnName) || dashboardHelper.IsColumnBoolean(data.Columns[0].ColumnName)))
                    //{
                    //    allRows = data.Select(string.Empty, "[" + data.Columns[0].ColumnName + "] DESC");
                    //}
                    //else
                    //{
                    //    allRows = data.Select(string.Empty, "[" + data.Columns[0].ColumnName + "]");
                    //}

                    List<List<StringDataValue>> dataValues = new List<List<StringDataValue>>();
                    for (int i = 1; i < data.Columns.Count; i++)
                    {
                        List<StringDataValue> values = new List<StringDataValue>();
                        foreach (DataRow row in data.Rows)
                        {
                            StringDataValue val = new StringDataValue();
                            if (row[i] != DBNull.Value)
                            {
                                val.DependentValue = (int)row[i];
                            }
                            else
                            {
                                val.DependentValue = 0;
                            }
                            val.IndependentValue = row[0].ToString();
                            values.Add(val);
                        }
                        dataValues.Add(values);
                    }

                    object[] result = new object[] { dataValues, data };
                    e.Result = result;

                    this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish));
                }
            }
            catch (Exception ex)
            {
                this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message);
            }
        }
Example #7
0
        void singleChartWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                GadgetParameters GadgetOptions = (GadgetParameters)((object[])e.Argument)[0];
                string varName = GadgetOptions.MainVariableName;//((object[])e.Argument)[1].ToString();
                string singleChartType = string.Empty;
                if (GadgetOptions.InputVariableList.ContainsKey("charttype"))
                {
                    singleChartType = GadgetOptions.InputVariableList["charttype"];
                }

                this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState));
                this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults));

                RequestUpdateStatusDelegate requestUpdateStatus = new RequestUpdateStatusDelegate(RequestUpdateStatusMessage);
                CheckForCancellationDelegate checkForCancellation = new CheckForCancellationDelegate(IsCancelled);

                GadgetOptions.GadgetStatusUpdate += new GadgetStatusUpdateHandler(requestUpdateStatus);
                GadgetOptions.GadgetCheckForCancellation += new GadgetCheckForCancellationHandler(checkForCancellation);

                Dictionary<DataTable, List<DescriptiveStatistics>> res = DashboardHelper.GenerateFrequencyTable(GadgetOptions);

                if (res == null || res.Count == 0)
                {
                    this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.NO_RECORDS_SELECTED);
                    this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                    return;
                }
                else if (worker.CancellationPending)
                {
                    this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED);
                    this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                    System.Diagnostics.Debug.Print("Single chart thread was cancelled");
                    return;
                }
                else
                {
                    DataTable frequencies = new DataTable();
                    List<List<StringDataValue>> stratifiedValues = new List<List<StringDataValue>>();
                    axisLabelMaxLength = 0;

                    //if (GadgetStatusUpdate != null)
                    //{
                        //this.Dispatcher.BeginInvoke(GadgetStatusUpdate, SharedStrings.DASHBOARD_GADGET_STATUS_DISPLAYING_OUTPUT);
                        System.Threading.Thread.Sleep(150); // necessary to prevent this message from overriding the 'no records selected'
                    //}

                        if (res.Count == 1 && !singleChartType.Equals("pie") && !singleChartType.Equals("pareto") && DashboardHelper.IsUsingEpiProject && DashboardHelper.View.Fields.Contains(GadgetOptions.MainVariableName) && (DashboardHelper.View.Fields[GadgetOptions.MainVariableName] is YesNoField || DashboardHelper.View.Fields[GadgetOptions.MainVariableName] is CheckBoxField))
                    {
                        IsBooleanWithNoStratas = true;
                    }
                    else
                    {
                        IsBooleanWithNoStratas = false;
                    }

                    foreach (KeyValuePair<DataTable, List<DescriptiveStatistics>> tableKvp in res)
                    {
                        string strataValue = tableKvp.Key.TableName;

                        double count = 0;
                        foreach (DescriptiveStatistics ds in tableKvp.Value)
                        {
                            count = count + ds.observations;
                        }

                        if (count == 0)
                        {
                            continue;
                        }

                        frequencies = tableKvp.Key;

                        List<StringDataValue> dataValues = new List<StringDataValue>();
                        int maxLegendItems = 15;
                        object[] itemArray = null;

                        if (singleChartType.Equals("pie") && !frequencies.Columns[0].DataType.ToString().Equals("System.DateTime") && !frequencies.Columns[0].DataType.ToString().Equals("System.Double") && !frequencies.Columns[0].DataType.ToString().Equals("System.Single") && !frequencies.Columns[0].DataType.ToString().Equals("System.Int32"))
                        {
                            int rowStoppedAt = 0;
                            DataTable condensedTable = new DataTable(frequencies.TableName);
                            condensedTable = frequencies.Clone();

                            for (int i = 0; i < frequencies.Rows.Count; i++)
                            {
                                if (i < maxLegendItems)
                                {
                                    condensedTable.Rows.Add(frequencies.Rows[i].ItemArray);
                                }
                                else if (i == maxLegendItems)
                                {
                                    condensedTable.Rows.Add("All others", frequencies.Rows[i][1]);
                                    rowStoppedAt = i;
                                }
                                else
                                {
                                    condensedTable.Rows[maxLegendItems][1] = (double)condensedTable.Rows[rowStoppedAt][1] + (double)frequencies.Rows[i][1];
                                }
                            }

                            if (condensedTable.Rows.Count > maxLegendItems)
                            {
                                itemArray = condensedTable.Rows[maxLegendItems].ItemArray;
                                DataRow rowToRemove = condensedTable.Rows[maxLegendItems];
                                condensedTable.Rows.Remove(rowToRemove);
                            }

                            frequencies = condensedTable.Copy();

                            if (!DashboardHelper.IsColumnYesNo(GadgetOptions.MainVariableName) && !DashboardHelper.IsColumnBoolean(GadgetOptions.MainVariableName))
                            {
                                frequencies = frequencies.Select(string.Empty, frequencies.Columns[0].ColumnName).CopyToDataTable().DefaultView.ToTable(frequencies.TableName);
                            }

                            if (itemArray != null)
                            {
                                frequencies.Rows.Add(itemArray);
                            }
                        }

                        double sum = 0;
                        double runningTotal = 0;
                        double maxValue = 0;

                        foreach (DataRow row in frequencies.Rows)
                        {
                            double value = (double)row["freq"];
                            sum = sum + value;
                            if (value > maxValue)
                            {
                                maxValue = value;
                            }
                        }

                        if (IsBooleanWithNoStratas)
                        {
                            foreach (DataRow row in frequencies.Rows)
                            {
                                runningTotal = runningTotal + (double)row["freq"];
                                double currentTotal = (runningTotal / sum) * maxValue;
                                StringDataValue sdv = new StringDataValue() { DependentValue = (double)row["freq"], IndependentValue = strataValue, StratificationValue = row[varName].ToString(), CurrentMeanValue = currentTotal };
                                List<StringDataValue> listSdv = new List<StringDataValue>();
                                listSdv.Add(sdv);
                                //    dataValues.Add(new StringDataValue() { DependentValue = (double)row["freq"], IndependentValue = row[varName].ToString(), StratificationValue = string.Empty });
                                if (row[varName].ToString().Length > axisLabelMaxLength)
                                {
                                    axisLabelMaxLength = row[varName].ToString().Length;
                                }
                                stratifiedValues.Add(listSdv);
                            }
                        }
                        else
                        {
                            foreach (DataRow row in frequencies.Rows)
                            {
                                runningTotal = runningTotal + (double)row["freq"];
                                double currentTotal = (runningTotal / sum) * maxValue;
                                dataValues.Add(new StringDataValue() { DependentValue = (double)row["freq"], IndependentValue = row[varName].ToString(), StratificationValue = strataValue, CurrentMeanValue = currentTotal });
                                if (row[varName].ToString().Length > axisLabelMaxLength)
                                {
                                    axisLabelMaxLength = row[varName].ToString().Length;
                                }
                            }
                            stratifiedValues.Add(dataValues);
                        }
                    }
                    e.Result = stratifiedValues;

                    if (stratifiedValues.Count == 0)
                    {
                        this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.NO_RECORDS_SELECTED);
                    }
                    else
                    {
                        this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish));
                    }
                }
            }
            catch (Exception ex)
            {
                this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message);
            }
        }
Example #8
0
        void epiCurveWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                object[] args = (object[])e.Argument;
                bool byEpiWeek = (bool)args[0];
                string dateVar = args[1].ToString();
                string caseStatusVar = args[2].ToString();
                string dateFormat = args[3].ToString();

                this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState));
                this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults));

                RequestUpdateStatusDelegate requestUpdateStatus = new RequestUpdateStatusDelegate(RequestUpdateStatusMessage);
                CheckForCancellationDelegate checkForCancellation = new CheckForCancellationDelegate(IsCancelled);

                GadgetOptions.GadgetStatusUpdate += new GadgetStatusUpdateHandler(requestUpdateStatus);
                GadgetOptions.GadgetCheckForCancellation += new GadgetCheckForCancellationHandler(checkForCancellation);

                //System.Threading.Thread.Sleep(100);

                DataTable data = GetEpiCurveData(byEpiWeek, dateVar, caseStatusVar);
                if (data != null && data.Rows.Count > 0)
                {
                    DataRow[] allRows = data.Select(string.Empty, "[" + data.Columns[0].ColumnName + "]");
                    List<List<StringDataValue>> dataValues = new List<List<StringDataValue>>();
                    for (int i = 1; i < data.Columns.Count; i++)
                    {
                        List<StringDataValue> values = new List<StringDataValue>();
                        foreach (DataRow row in allRows)
                        {
                            StringDataValue val = new StringDataValue();
                            if (row[i] != DBNull.Value)
                            {
                                val.DependentValue = (int)row[i];
                            }
                            else
                            {
                                val.DependentValue = 0;
                            }
                            if (byEpiWeek)
                            {
                                val.IndependentValue = row[0].ToString();
                            }
                            else
                            {
                                if (dateFormat.ToLower().Equals("hours"))
                                {
                                    val.IndependentValue = ((DateTime)row[0]).ToString("g");
                                }
                                else if (dateFormat.ToLower().Equals("months"))
                                {
                                    val.IndependentValue = ((DateTime)row[0]).ToString("MMM yyyy");
                                }
                                else if (dateFormat.ToLower().Equals("years"))
                                {
                                    val.IndependentValue = ((DateTime)row[0]).ToString("yyyy");
                                }
                                else
                                {
                                    val.IndependentValue = ((DateTime)row[0]).ToShortDateString();
                                }
                            }
                            values.Add(val);
                        }
                        dataValues.Add(values);
                    }
                    object[] retVals = new object[2];
                    retVals[0] = dataValues;
                    retVals[1] = data;
                    e.Result = retVals;
                    this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish));
                }
                else if (data == null || data.Rows.Count == 0)
                {
                    this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.NO_RECORDS_SELECTED);
                }
                else
                {
                    this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish));
                }
            }
            catch (Exception ex)
            {
                this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message);
            }
        }