public string Get(Boolean IsGolden, string Tag, string AssayVersion, string SoftwareVersion, int AssayID)
        {
            long   AssayDBID;
            string AssayName = "";

            //Assay name is specified
            if (AssayID != -1)
            {
                using (var repo = new AssayRepository())
                {
                    AssayDBID = repo.GetTypeIdWithID(AssayID);
                    AssayName = repo.GetAssayName(AssayID);
                }
            }
            else
            {
                AssayDBID = -1;
            }
            var files = new List <Pair>();

            if (Tag == "undefined")
            {
                Tag = "";
            }
            if (AssayVersion == "undefined")
            {
                AssayVersion = "";
            }
            if (SoftwareVersion == "undefined")
            {
                SoftwareVersion = "";
            }

            using (var repo = new CurveFilesRepository())
            {
                var tempContainer = repo.GetSpecifiedFile(IsGolden, Tag, AssayVersion, SoftwareVersion, AssayDBID);
                if (tempContainer.Count <CurveFile>() == 0)
                {
                    return(JsonConvert.SerializeObject("No Matching Curve File Found"));
                }
                else
                {
                    var service   = new CurveDataPointService();
                    var assayRepo = new AssayRepository();


                    foreach (var temp in tempContainer)
                    {
                        var container = service.getCurveData(temp.Data, temp.FullFileName);

                        if (AssayDBID == -1)
                        {
                            AssayName = assayRepo.GetAssayNameUsingTypeID(temp.AssayDBID);
                        }

                        files.Add(new Pair
                        {
                            AssayName = AssayName,
                            curveFile = temp,
                            data      = container.dataSet,
                            FileType  = container.FileType
                        });
                    }
                }
            }
            return(JsonConvert.SerializeObject(files));
        }
Exemplo n.º 2
0
        public string getAssayFromFile(Byte[] byteFile, string fileName)
        {
            var delim = new[] { '"' };

            fileName = Regex.Unescape(fileName);
            fileName = fileName.TrimEnd(delim).TrimStart(delim);

            var tempPath     = Path.GetTempPath();
            var tempPathFile = Path.Combine(tempPath, fileName);

            File.WriteAllBytes(tempPathFile, byteFile);

            var repo = new AssayRepository();

            var typeID = "";

            using (var streamReader = new StreamReader(tempPathFile))
            {
                var firstLine  = streamReader.ReadLine();
                var secondLine = streamReader.ReadLine();

                if (firstLine == null || secondLine == null)
                {
                    return("Invalid");
                }

                var lowerFirstLine = firstLine.ToLower();

                string[] seperatedValueFirst = lowerFirstLine.Split(',');

                if (lowerFirstLine.Contains("sampleid") &&
                    (lowerFirstLine.Contains("testorderid") || lowerFirstLine.Contains("testorder id")))
                {
                    //RPTool files
                    if (seperatedValueFirst.Length == 9)
                    {
                        List <string> firstColHolder = new List <string>();
                        var           newStream      = new StreamReader(tempPathFile);
                        while (!newStream.EndOfStream)
                        {
                            var      newLine      = newStream.ReadLine();
                            String[] seperatedVal = newLine.Split(',');
                            firstColHolder.Add(seperatedVal[0]);
                        }

                        //check the string with number
                        for (var index = 0; index < firstColHolder.Count; index++)
                        {
                            var charArr = firstColHolder[index].ToCharArray();
                            if (Char.IsNumber(charArr[0]))
                            {
                                typeID = charArr[0].ToString();
                                typeID = typeID.Insert(1, charArr[1].ToString());
                                var toReturn = repo.GetAssayNameUsingTypeID(Int32.Parse(typeID));
                                return(toReturn);
                            }
                        }
                    }
                    //TCycle and some versions of .curve
                    if (lowerFirstLine.Contains("cyclenum"))
                    {
                        String[] seperatedValue = secondLine.Split(',');
                        //TCYC
                        if (seperatedValue.Length != 15)
                        {
                            typeID = seperatedValue[7];
                        }
                        //.Curve
                        else
                        {
                            typeID = seperatedValue[6];
                        }
                        var toReturn = repo.GetAssayNameUsingTypeID(Int32.Parse(typeID));
                        //If assay are outdated
                        if (toReturn == "")
                        {
                            return("Invalid-Outdated");
                        }
                        return(toReturn);
                    }
                    //Fluorescence curve
                    else if (lowerFirstLine.Contains("rtf"))
                    {
                        String[] seperatedValue = secondLine.Split(';');

                        var Assay = seperatedValue[2];

                        String[] assayNumber = seperatedValue[2].Split(',');

                        var AssayDBID = assayNumber[0];

                        var toReturn = repo.GetAssayNameUsingTypeID(Int32.Parse(AssayDBID));
                        //If assay are outdated
                        if (toReturn == "")
                        {
                            return("Invalid-Outdated");
                        }
                        return(toReturn);
                    }
                }
                //validates FLUO.csv file
                else if (seperatedValueFirst.Length == 19)
                {
                    var typeIDStr = seperatedValueFirst[8];
                    var toReturn  = repo.GetAssayNameUsingTypeID(Int32.Parse(typeIDStr));
                    //If assay are outdated
                    if (toReturn == "")
                    {
                        return("Invalid-Outdated");
                    }
                    return(toReturn);
                }
                //validates LUMI.csv file
                else
                {
                    var typeIDStr = "";
                    if (seperatedValueFirst.Length > 5)
                    {
                        if (seperatedValueFirst[5] != null)
                        {
                            var numOfDataPts = seperatedValueFirst[5];
                            typeIDStr = seperatedValueFirst[Int32.Parse(numOfDataPts) + 8];
                        }
                        else
                        {
                            return("Invalid");
                        }
                        var toReturn = repo.GetAssayNameUsingTypeID(Int32.Parse(typeIDStr));
                        //If assay are outdated
                        if (toReturn == "")
                        {
                            return("Invalid-Outdated");
                        }
                        return(toReturn);
                    }
                }
            }
            return("Invalid");
        }