示例#1
0
        public string GetProcessStream(ref string csv, string uri, ref List <AppCSV.MyData> lstdata, ref List <AppCSV.MyMetric> lstMetric)
        {
            string retorno     = "";
            string line        = "";
            string resultParse = "";

            long Content    = 0;
            long LineLength = 0;

            //int ij = 0;
            //int i = 0;

            try
            {
                Regex CSVParser = new Regex(
                    @"(?<=\r|\n|^)(?!\r|\n|$)" +
                    @"(?:" +
                    @"(?:" +
                    @"""(?<Value>(?:[^""]|"""")*)""|" +
                    @"(?<Value>(?!"")[^,\r\n]+)|" +
                    @"""(?<OpenValue>(?:[^""]|"""")*)(?=\r|\n|$)|" +
                    @"(?<Value>)" +
                    @")" +
                    @"(?:,|(?=\r|\n|$))" +
                    @")+?" +
                    @"(?:(?<=,)(?<Value>))?" +
                    @"(?:\r\n|\r|\n|$)",
                    RegexOptions.Compiled);



                var req = (HttpWebRequest)HttpWebRequest.Create(uri);

                using (var resp = req.GetResponse())
                {
                    using (var stream = resp.GetResponseStream())
                    {
                        Content = resp.ContentLength;

                        using (GZipStream readStreamUZ = new GZipStream(stream, CompressionMode.Decompress, true))
                        {
                            using (StreamReader readStream = new StreamReader(readStreamUZ))
                            {
                                MyMetric myMetric = new MyMetric();
                                myMetric.GroupError = new List <String>();

                                while ((line = readStream.ReadLine()) != null)
                                {
                                    LineLength += line.Length;
                                    ShowProgress("Processing...", LineLength, Content);
                                    ///
                                    MyData myData = new MyData();
                                    resultParse = ParserCSV(ref line, ref myData, ref myMetric, ref CSVParser);
                                    //lstdata.Add(myData);
                                }
                                lstMetric.Add(myMetric);
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                retorno = ex.Message.ToString() + resultParse;
            }

            return(retorno);
        }
示例#2
0
        //RCF_4180
        public string ParserCSV(ref string readUz, ref MyData myData, ref MyMetric myMetric, ref Regex CSVParser)
        {
            string retorno;

            try
            {
                retorno = "";

                MatchCollection CSVRecords = CSVParser.Matches(readUz);


                DateTimeOffset parsedDate;

                Double parseDouble;

                for (Int32 recordIndex = 0; recordIndex < CSVRecords.Count; recordIndex++)
                {
                    Match Record = CSVRecords[recordIndex];
                    for (Int32 valueIndex = 0; valueIndex < Record.Groups["Value"].Captures.Count; valueIndex++)
                    {
                        Capture c = Record.Groups["Value"].Captures[valueIndex];

                        if (c.Value != "")
                        {
                            if ((("V" + (valueIndex + 1)) == "V1"))
                            {
                                myData.user_id = (c.Value).ToString();
                            }
                            else if ((("V" + (valueIndex + 1)) == "V2"))
                            {
                                //if (DateTimeOffset.TryParseExact(c.Value.Trim(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate))
                                if (DateTimeOffset.TryParse(c.Value.Trim(), out parsedDate) == true)
                                {
                                    if (DateTimeOffset.Parse(c.Value).CompareTo(DataJoin) < 0)
                                    {
                                        DataJoin           = DateTimeOffset.Parse((c.Value).ToString());
                                        myData.date_joined = DateTimeOffset.Parse((c.Value).ToString());
                                        myMetric.user_id   = myData.user_id;
                                    }
                                }
                                //else
                                //{
                                //    myMetric.user_id = myData.user_id;
                                //}
                            }
                            else if ((("V" + (valueIndex + 1)) == "V3"))
                            {
                                if (Double.TryParse(c.Value, out parseDouble))
                                {
                                    myData.spend          = Double.Parse((c.Value).ToString());
                                    myMetric.spendDollar += myData.spend;
                                }
                            }
                            else if ((("V" + (valueIndex + 1)) == "V4"))
                            {
                                if (Double.TryParse(c.Value, out parseDouble))
                                {
                                    myData.milliseconds_played = (c.Value).ToString();
                                }
                            }
                            else if ((("V" + (valueIndex + 1)) == "V5"))
                            {
                                myData.device_height = (c.Value).ToString();
                            }
                            else if ((("V" + (valueIndex + 1)) == "V6"))
                            {
                                myData.device_width = (c.Value).ToString();
                            }

                            //contadores
                            if (myData.device_width == "640" && myData.device_height == "960")
                            {
                                myMetric.ResolCount += 1;
                            }
                        }
                    }

                    //contador
                    myMetric.UserCount += 1;

                    foreach (Capture OpenValue in Record.Groups["OpenValue"].Captures)
                    {
                        myMetric.GroupError.Add("ERROR - Open ended quoted value: " + OpenValue.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                retorno = ex.Message.ToString();
            }

            return(retorno);
        }