Ejemplo n.º 1
0
        public ActionResult RawData(RawDataDocument document)
        {
            if (ModelState.IsValid)
            {
                document.DateStored = DateTime.Now;
                if (document.Public)
                {
                    document.DataDocuments = new List <DataDocument>();

                    if (document.File != null && string.IsNullOrWhiteSpace(document.Data))
                    {
                        document.Data = "";
                        using (StreamReader reader = new StreamReader(document.File.InputStream)) {
                            document.Header = reader.ReadLine() + Environment.NewLine;
                            while (!reader.EndOfStream)
                            {
                                document.Data += reader.ReadLine() + Environment.NewLine;
                            }
                        }
                    }

                    string[] hs = document.Header.Split(document.Separator.ToCharArray());
                    string[] ds = document.Data.Split(new[] { '\r', '\n' });
                    foreach (var d in ds)
                    {
                        string[] s = d.Split(document.Separator.ToCharArray());
                        for (int i = 0; i < hs.Length; i++)
                        {
                            DataDocument dataDocument = new DataDocument();
                            //if (i != document.TimeColumn)
                            if (s.Length == hs.Length)
                            {
                                dataDocument.Row    = s[document.RowColumn];
                                dataDocument.Value  = s[i];
                                dataDocument.Column = hs[i];
                                document.DataDocuments.Add(dataDocument);
                            }
                        }
                    }
                    Saver.Save(document);

                    ViewBag.ModelStatus = "Success";
                    return(View("RawData"));
                }
                else
                {
                    ViewBag.ModelStatus = "You cannot upload data that is not public";
                }
            }
            else
            {
                ViewBag.ModelStatus = "Something went wrong";
            }
            return(View("RawData", document));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves a document to the proper collection. This is overloaded to handle different objects.
        /// </summary>
        /// <param name="document"></param>
        public static void Save(RawDataDocument document)
        {
            string id = string.Empty;

            if (!string.IsNullOrEmpty(document.Id))
            {
                id = document.Id;
            }
            BsonDocument bdoc = document.ToBsonDocument();

            Save(bdoc, System.Configuration.ConfigurationManager.AppSettings["DataCollection"], id);
        }