Ejemplo n.º 1
0
        public static IList <TsharkModel> Deserialize(string csv)
        {
            List <TsharkModel> ret = new List <TsharkModel>();

            string[] arr = csv.Split('\n');
            if (arr.Length > 1)
            {
                for (int j = 1; j < arr.Length; ++j)//header' ı atayıruz.
                {
                    string item = arr[j];
                    if (!String.IsNullOrEmpty(item))
                    {
                        string[] fields = item.Split(';');
                        if (fields.Length == props.Count)
                        {
                            TsharkModel model = new TsharkModel();
                            for (int k = 0; k < fields.Length; ++k)
                            {
                                PropertyInfo pi = props[k];
                                pi.SetValue(model, fields[k]);
                            }
                            ret.Add(model);
                        }
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
        protected override async Task <object> Run_Internal(IObserver observer, string asset, IScanRepository repository, object args)
        {
            List <TsharkModel> ret = new List <TsharkModel>();

            if (!String.IsNullOrEmpty(asset) && args is IDictionary <string, object> dic)
            {
                string deviceId     = asset;
                string fileTemplate = dic[nameof(fileTemplate)]?.ToString();
                string tsharkPath   = dic[nameof(tsharkPath)]?.ToString();//Belki linux' te vermiyoruzdur.
                string duration     = dic[nameof(duration)]?.ToString();

                if (String.IsNullOrEmpty(fileTemplate))
                {
                    fileTemplate = "tshark";
                }
                if (String.IsNullOrEmpty(tsharkPath) || !int.TryParse(tsharkPath, out int d))
                {
                    duration = "60";
                }

                EnsureIsListining(fileTemplate, deviceId, tsharkPath, int.Parse(duration));

                //
                var files = await ReadFiles(fileTemplate, tsharkPath);

                foreach (string csv in files)
                {
                    IList <TsharkModel> modelList = TsharkModel.Deserialize(csv);
                    ret.AddRange(modelList);
                    observer?.Notify(deviceId, "Network Monitored", modelList);
                }
                //
            }

            return(ret);
        }