示例#1
0
        static void MainOLD(string[] args)
        {
            string funText;
            string[] lineS;
            using (StreamReader reader = File.OpenText(args[0]))
                while (!reader.EndOfStream)
                {
                    //string[] temp;
                    string line = reader.ReadLine();
                    if (null == line)
                        continue;

                    //string[] PressXtoJSON = new string[] line;

                    List<String> elements = new List<String>();
                    List<String> moreElements = new List<String>();
                    List<String> PressXtoJSON = new List<String>();


                    elements.Add("key");
                    elements.Add("mealList");
                    elements.Add("datemaj");
                    elements.Add("validityBegin");
                    elements.Add("validityEnd");
                    elements.Add("caterer");
                    elements.Add("departureArrivalList");
                    elements.Add("pairingGrid");
                    elements.Add("cycle");
                    elements.Add("state");
                    elements.Add("version");
                    elements.Add("language");
                    elements.Add("classCodeList");
                    elements.Add("mealType");
                    elements.Add("menusList");

                    moreElements.Add("label");
                    moreElements.Add("content");
                    moreElements.Add("sequence");

                    List<int> commas = new List<int>();

                    commas.Add(0);
                    int temp, firstComma=0;

                    for (int x=0; x < line.Length; x++){
                        temp = line.IndexOf(',',x);
                        //nevermind

                    }

                    //line.Sub

                    lineS = line.Split(',');

                    PressXtoJSON = parseObject(line, elements);

                    String temp1 = PressXtoJSON[14].Substring(PressXtoJSON[14].IndexOf("\"coursesList\""), PressXtoJSON[14].Length - PressXtoJSON[14].IndexOf("\"coursesList\""));

                    //PressXtoJSON = parseObject(temp1, moreElements);

                    foreach (String moo in PressXtoJSON)
                    {
                        Console.WriteLine(moo);
                    }

                    string[] foo = new string[] { "loo" };

                    String ben = "waterloovilage";

                    ben.Split(foo, StringSplitOptions.None);

                    int fromHere, toHere, thisLength;

                    fromHere = PressXtoJSON[14].IndexOf('[', 20);
                    toHere = PressXtoJSON[14].LastIndexOf(']', PressXtoJSON[14].Length-1);
                    thisLength = toHere - fromHere;



                    theList test = new theList();
                    test = JsonConvert.DeserializeObject<theList>(line);
                    
                    //something = JsonConvert.DeserializeObject(line);



                    Console.ReadLine();
                }

        }
示例#2
0
        public async void import(string[] args)
        {
            // get the specs to be imported
            String       lineS  = "";
            StreamReader reader = File.OpenText(args[0]);

            lineS = reader.ReadToEnd();

            List <String> errors = new List <String>();
            String        error;

            theList test = new theList();

            test = JsonConvert.DeserializeObject <theList>(lineS);

            bool VERBOSE = true; // when set to true it will give more info on each specITem imported



            foreach (DataList m in test.menuDataList)
            {
                // build code string
                for (int x = 0; x < m.mealList.Count; x++)
                {
                    m.newCode += m.mealList[x].code;
                    if (x + 1 != m.mealList.Count)
                    {
                        m.newCode += "/";
                    }
                }

                // build class string
                for (int x = 0; x < m.classCodeList.Count; x++)
                {
                    m.newClass += m.classCodeList[x].code;
                    if (x + 1 != m.classCodeList.Count)
                    {
                        m.newClass += "/";
                    }
                }

                // build station string
                for (int x = 0; x < m.departureArrivalList.Count; x++)
                {
                    m.newStation += m.departureArrivalList[x].departure.code;
                    if (m.departureArrivalList[x].arrival != null)
                    {
                        m.newStation += "(" + m.departureArrivalList[x].arrival.code + ")";
                    }
                    if (x + 1 != m.departureArrivalList.Count)
                    {
                        m.newStation += "/";
                    }
                }

                m.specMatchKey = m.newCode +
                                 m.validityBegin + m.pairingGrid + m.cycle + m.newStation +
                                 m.newClass;

                if (m.OSCid > -1)
                {
                    m.tempSpecID = m.OSCid;
                }
            }

            //assign temporary specIDs
            int tempSpecCounter = -2;

            for (int y = 0; y < test.menuDataList.Count(); y++)
            {
                if (test.menuDataList[y].tempSpecID == -1)
                {
                    test.menuDataList[y].tempSpecID = tempSpecCounter;

                    bool found = false;
                    for (int x3 = y + 1; x3 < test.menuDataList.Count(); x3++)
                    {
                        //test.menuDataList[x3].tempSpecID = --tempSpecCounter;

                        if (test.menuDataList[x3].tempSpecID == -1)
                        {
                            if (test.menuDataList[y].specMatchKey == test.menuDataList[x3].specMatchKey)
                            {
                                test.menuDataList[x3].tempSpecID = test.menuDataList[y].tempSpecID;
                                found = true;
                            }
                        }
                    }
                    if (found)
                    {
                        tempSpecCounter--;
                    }
                }
            }

            foreach (DataList m in test.menuDataList)
            {
                Console.WriteLine(m.specMatchKey + " : " + m.tempSpecID);
            }


            // get Token
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            Console.WriteLine("Getting token");

            HttpClient client   = new HttpClient();
            string     OscToken = string.Empty;

            // Uncomment this to use a fresh token
            //OscToken = "Bearer " + await GetAuthToken();
            //OscToken = OscToken.Replace("#access_token=", "");

            // FrankAF -----
            //OscToken = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL29zY2lkLm9zYy1pdC5jb20vdHJ1c3QvSWRlbnRpdHlTZXJ2ZXIiLCJhdWQiOiJ1cm46Q29udGVudENlbnRyZVdlYiIsIm5iZiI6MTQzOTQ5NDc5NCwiZXhwIjoxNDQwNzA0Mzk0LCJuYW1laWQiOiJmcmFua0FGIiwidW5pcXVlX25hbWUiOiJmcmFua0FGIiwiYXV0aG1ldGhvZCI6Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9hdXRoZW50aWNhdGlvbm1ldGhvZC9wYXNzd29yZCIsImF1dGhfdGltZSI6IjIwMTUtMDgtMTNUMTk6Mzk6NTMuNzA4WiIsImVtYWlsIjoiZnJhbmtBRkBhaXJsaW5lbWVudXMuY29tIiwicm9sZSI6WyJBaXIgRnJhbmNlIC0gRm9vZCBEZXNpZ25lciIsIkFpciBGcmFuY2UgLSBJbmZvcm1hdGlvbiBUZWNobm9sb2d5Il0sImh0dHA6Ly9pZGVudGl0eXNlcnZlci50aGlua3RlY3R1cmUuY29tL2NsYWltcy9wcm9maWxlY2xhaW1zL2NvbXBhbnlpZCI6IjEifQ.VPR4WbFPW7t5YFRcAZ-TbmPf9HtvZfr_wNFVwKaNoTM";
            //FrankOSC -----
            OscToken = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL29zY2lkLm9zYy1pdC5jb20vdHJ1c3QvSWRlbnRpdHlTZXJ2ZXIiLCJhdWQiOiJ1cm46Q29udGVudENlbnRyZVdlYiIsIm5iZiI6MTQzOTQ5NTAxOCwiZXhwIjoxNDQwNzA0NjE4LCJuYW1laWQiOiJmcmFua09TQyIsInVuaXF1ZV9uYW1lIjoiZnJhbmtPU0MiLCJhdXRobWV0aG9kIjoiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2F1dGhlbnRpY2F0aW9ubWV0aG9kL3Bhc3N3b3JkIiwiYXV0aF90aW1lIjoiMjAxNS0wOC0xM1QxOTo0MzozOC43NDZaIiwiZW1haWwiOiJmcmFua09TQ0BvbmV3b3JsZG9uZXN0b3AuY29tIiwicm9sZSI6WyJPU0MgLSBBaXIgRnJhbmNlIFRlYW0gTWVtYmVyIiwiT1NDIC0gQnJpdGlzaCBBaXJ3YXlzIFRlYW0gTWVtYmVyIiwiT1NDIC0gSVQgQWRtaW4iLCJPU0MgLSBVbml0ZWQgVGVhbSBNZW1iZXIiLCJPU0MgLSBWaXJnaW4gQXRsYW50aWMgVGVhbSBNZW1iZXIiXSwiaHR0cDovL2lkZW50aXR5c2VydmVyLnRoaW5rdGVjdHVyZS5jb20vY2xhaW1zL3Byb2ZpbGVjbGFpbXMvY29tcGFueWlkIjoiNSJ9.xmwOfF7yn_4S6oXL2wF5m9A246czE2SIN0y4xIF6CRk";
            client.DefaultRequestHeaders.Add("Authorization", OscToken);
            client.DefaultRequestHeaders.Referrer = new System.Uri("http://ifonlythiswasarealsite.com/JSONimporter.txt");
            //client.DefaultRequestHeaders.Add("


            Console.WriteLine("token Retrieved");

            // this is where the magic happens.....
            List <MealTypeTransferObject>      MealTypes    = getIDs <MealTypeTransferObject>(client, "getAllMealTypes", "Meal Types", errors).Result;
            List <StatusTransferObject>        SpecStatuses = getIDs <StatusTransferObject>(client, "getAllStatuses", "Status", errors).Result;
            List <RotationGrillTransferObject> Rotations    = getIDs <RotationGrillTransferObject>(client, "getRotationByName", "Rotation Grill", errors).Result;
            List <LanguageTransferObject>      Languages    = getIDs <LanguageTransferObject>(client, "getAllLanguages", "Languages", errors).Result;
            List <AllergenTransferObject>      Allergens    = getIDs <AllergenTransferObject>(client, "getAllAllergens", "Allergens", errors).Result;


            String ajaxURI = ConfigurationManager.AppSettings["SpecWebApi"];

            HttpResponseMessage httpResponse;

            bool loadError = false;

            if (MealTypes.Count == 0)
            {
                loadError = true;
            }
            if (SpecStatuses.Count == 0)
            {
                loadError = true;
            }
            if (Rotations.Count == 0)
            {
                loadError = true;
            }
            if (Languages.Count == 0)
            {
                loadError = true;
            }
            if (Allergens.Count == 0)
            {
                loadError = true;
            }


            // display the specs for verification

            if (!loadError)
            {
                String   str       = "";
                DateTime startTime = new DateTime();
                TimeSpan diffTime  = new TimeSpan();
                startTime = DateTime.Now;
                int start = 0, howMany = 100; //9
                if (howMany + start > test.menuDataList.Count)
                {
                    howMany = test.menuDataList.Count - start;
                }
                for (int xList = start; xList < howMany + start; xList++)
                {
                    DataList           temp    = new DataList();
                    SpecTransferObject newSpec = new SpecTransferObject();

                    // The AccountContext is set here
                    Content_Centre_API_CORS.Templates.AccountContext GlobalContext = new Content_Centre_API_CORS.Templates.AccountContext();
                    GlobalContext.AccountID = 1;
                    GlobalContext.Role      = "OSC - Air France Team Member";

                    newSpec.Context = GlobalContext;

                    DateTime nowTime = new DateTime();

                    nowTime  = DateTime.Now;
                    diffTime = nowTime - startTime;

                    String strTemp = "";
                    nowTime = startTime + TimeSpan.FromMilliseconds((diffTime.TotalMilliseconds / (xList + 1)) * howMany);


                    strTemp += "Start:" + startTime.ToShortTimeString() +
                               " " + (xList + 1) + "\\" + howMany + "(" + String.Format("{0:p}", ((xList + 1.0) / howMany)) + ") done at " +
                               nowTime.ToShortTimeString();
                    Console.Clear();
                    Console.WriteLine(strTemp);

                    bool IDError = false;

                    temp = test.menuDataList[xList];


                    //newSpec.AccountID = "1"; // Air France
                    newSpec.Rotation    = temp.cycle;
                    newSpec.ValidDate   = temp.validityBegin;
                    newSpec.CatererName = temp.caterer;


                    //until parsed is fixed

                    if (temp.state == null)
                    {
                        temp.state = "Proofing";
                    }



                    // Check if spec exists

                    newSpec.Class   = temp.newClass;
                    newSpec.Code    = temp.newCode;
                    newSpec.Station = temp.newStation;


                    // get MealType
                    newSpec.MealTypeID = getMealTypeID(MealTypes, temp.mealType);
                    if (newSpec.MealTypeID == -1) //new mealType?
                    {
                        IDError = true;
                        error   = "-> mealType \"" + temp.mealType + "\" not found";
                        errors.Add(newSpec.SpecID + ":" + temp.specMatchKey + ">>\n" + error);
                        Console.WriteLine(error);
                    }

                    // get Status Code
                    newSpec.StatusID = getStatusID(SpecStatuses, temp.state);
                    if (newSpec.StatusID == -1) //new Status?
                    {
                        IDError = true;
                        error   = "-> Status \"" + temp.state + "\" not found";
                        errors.Add(newSpec.SpecID + ":" + temp.specMatchKey + ">>\n" + error);
                        Console.WriteLine(error);
                    }

                    // Get Rotation ID?
                    newSpec.RotationID = getRotationGrillID(Rotations, temp.pairingGrid);
                    if (temp.pairingGrid == "X")
                    {
                        newSpec.RotationID = -1;
                    }
                    else if (newSpec.RotationID == -1) //new Rotation?
                    {
                        IDError = true;
                        error   = "-> Rotation \"" + temp.pairingGrid + "\" not found";
                        errors.Add(newSpec.SpecID + ":" + temp.specMatchKey + ">>\n" + error);
                        Console.WriteLine(error);
                    }

                    // ----------- insert NEW and Get Spec ID .......

                    if (!IDError)
                    {
                        if (temp.tempSpecID > -1) // check if spec exists
                        {
                            SpecTransferObject checkSpec = new SpecTransferObject();
                            checkSpec.SpecID  = temp.tempSpecID;
                            checkSpec.Context = GlobalContext;


                            httpResponse = client.PostAsJsonAsync <SpecTransferObject>(ajaxURI + "/getSpecByID", checkSpec).Result;
                            if (VERBOSE)
                            {
                                Console.WriteLine("\n|--------------------|");
                                Console.WriteLine("... Checking if Spec Exists");
                                Console.WriteLine("Data Sent.. did it work? ....");
                            }

                            if (httpResponse.StatusCode == (HttpStatusCode)200)
                            {
                                SpecResponseObject PressXtoJSON = new SpecResponseObject();
                                try
                                {
                                    PressXtoJSON = await httpResponse.Content.ReadAsAsync <SpecResponseObject>();

                                    if (PressXtoJSON.Error)
                                    {
                                        Console.WriteLine("the faiL, has arrived :(");
                                        foreach (Content_Centre_API_CORS.ErrorHandling.SpecificationError m in PressXtoJSON.ErrorList)
                                        {
                                            error = "-> " + m.ErrorMessage;
                                            errors.Add("Check Spec " + error);
                                            Console.WriteLine(error);
                                        }
                                    }
                                    else
                                    {
                                        if (VERBOSE)
                                        {
                                            Console.WriteLine("SpecCheck was a GREAT SUCCESS");
                                        }
                                        DataTable tempResponse = new DataTable();
                                        tempResponse = JsonConvert.DeserializeObject <DataTable>(PressXtoJSON.JsonResults);
                                        try
                                        {
                                            newSpec.SpecID = Convert.ToInt32(tempResponse.Rows[0].ItemArray[0]);
                                        }

                                        catch (SystemException e)
                                        {
                                            error = e.Message.ToString();
                                            errors.Add("Get SpecID " + error);
                                            Console.WriteLine(error);
                                        }
                                        if (newSpec.SpecID < 0)
                                        {
                                            Console.WriteLine("no, no, no.... it's not there... can't update");
                                            errors.Add("Can't Update Spec " + checkSpec.SpecID + ":  " + temp.specMatchKey);
                                            newSpec.SpecID = 0;
                                        }
                                        // check if there are matching spec and assign the new spec ID
                                    }
                                }
                                catch (Newtonsoft.Json.JsonSerializationException e)
                                {
                                    Console.WriteLine("the faiL, has arrived :(");
                                    error = e.Message.ToString();
                                    errors.Add("JSON? " + error);
                                    Console.WriteLine(error);
                                }
                                //SpecRes = JsonConvert.DeserializeObject<List<SpecTransferObject>>(PressXtoJSON.JsonResults);
                            }
                            else
                            {
                                Console.WriteLine("nope, wrong again!");
                                error = "--> " + httpResponse.StatusCode + " : " + httpResponse.ReasonPhrase;
                                errors.Add("Get Spec ID (API Call) " + error);
                                Console.WriteLine(error);
                            }
                        }

                        if (temp.tempSpecID < 0) // INSERT
                        {
                            httpResponse = client.PostAsJsonAsync <SpecTransferObject>(ajaxURI + "/insertSpec", newSpec).Result;
                            if (VERBOSE)
                            {
                                Console.WriteLine("\n|--------------------|");
                                Console.WriteLine("... Getting Spec ID for new Spec");
                                Console.WriteLine("Data Sent.. did it work? ....");
                            }

                            if (httpResponse.StatusCode == (HttpStatusCode)200)
                            {
                                //Console.WriteLine("yes....yes it did");
                                SpecResponseObject PressXtoJSON = new SpecResponseObject();
                                try
                                {
                                    PressXtoJSON = await httpResponse.Content.ReadAsAsync <SpecResponseObject>();

                                    if (PressXtoJSON.Error)
                                    {
                                        Console.WriteLine("the faiL, has arrived :(");
                                        foreach (Content_Centre_API_CORS.ErrorHandling.SpecificationError m in PressXtoJSON.ErrorList)
                                        {
                                            error = "-> " + m.ErrorMessage;
                                            errors.Add(temp.specMatchKey + " failed on insert " + error);
                                            Console.WriteLine(error);
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("Spec was a GREAT SUCCESS");
                                        newSpec.SpecID = PressXtoJSON.SpecID;
                                        int toChange = test.menuDataList[xList].tempSpecID;
                                        test.menuDataList[xList].tempSpecID = PressXtoJSON.SpecID;
                                        // check if there are matching spec and assign the new spec ID



                                        for (int xUpdate = xList + 1; xUpdate < howMany + start; xUpdate++)
                                        {
                                            if (test.menuDataList[xUpdate].tempSpecID == toChange)
                                            {
                                                test.menuDataList[xUpdate].tempSpecID = newSpec.SpecID;
                                            }
                                        }
                                    }
                                }
                                catch (Newtonsoft.Json.JsonSerializationException e)
                                {
                                    Console.WriteLine("the faiL, has arrived :(");
                                    error = "-> " + e.Message;
                                    errors.Add("JSon!!!! " + error);
                                    Console.WriteLine(error);
                                }
                                //SpecRes = JsonConvert.DeserializeObject<List<SpecTransferObject>>(PressXtoJSON.JsonResults);
                            }
                            else
                            {
                                Console.WriteLine("nope, wrong again!");
                                error = "--> " + httpResponse.StatusCode + " : " + httpResponse.ReasonPhrase;
                                errors.Add("Insert Spec ID (API Call) " + error);
                                Console.WriteLine(error);
                            }
                        }
                        else if (temp.tempSpecID != 0)
                        { // UPDATE!!!!
                            httpResponse = client.PostAsJsonAsync <SpecTransferObject>(ajaxURI + "/updateSpec", newSpec).Result;
                            if (VERBOSE)
                            {
                                Console.WriteLine("\n|--------------------|");
                                Console.WriteLine("... Getting Spec ID for new Spec");
                                Console.WriteLine("Data Sent.. did it work? ....");
                            }

                            if (httpResponse.StatusCode == (HttpStatusCode)200)
                            {
                                //Console.WriteLine("yes....yes it did");
                                SpecResponseObject PressXtoJSON = new SpecResponseObject();
                                try
                                {
                                    PressXtoJSON = await httpResponse.Content.ReadAsAsync <SpecResponseObject>();

                                    if (PressXtoJSON.Error)
                                    {
                                        Console.WriteLine("the faiL, has arrived :(");
                                        foreach (Content_Centre_API_CORS.ErrorHandling.SpecificationError m in PressXtoJSON.ErrorList)
                                        {
                                            error = "-> " + m.ErrorMessage;
                                            errors.Add("update error " + error);
                                            Console.WriteLine(error);
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("Spec was a GREAT SUCCESS");
                                    }
                                }
                                catch (Newtonsoft.Json.JsonSerializationException e)
                                {
                                    Console.WriteLine("the faiL, has arrived :(");
                                    error = "-> " + e.Message;
                                    errors.Add("JSON!!! " + error);
                                    Console.WriteLine(error);
                                }
                                //SpecRes = JsonConvert.DeserializeObject<List<SpecTransferObject>>(PressXtoJSON.JsonResults);
                            }
                            else
                            {
                                Console.WriteLine("nope, wrong again!");
                                error = "--> " + httpResponse.StatusCode + " : " + httpResponse.ReasonPhrase;
                                errors.Add("Update Spec (API Call) " + error);
                                Console.WriteLine(error);
                            }
                        }
                        else
                        {
                            error = "Spec ID is invalid, i don't know what to do";
                            errors.Add(newSpec.SpecID + ": " + error);
                            Console.WriteLine(error);
                        }

                        str  = "\n";
                        str += newSpec.Code + " : "
                               + newSpec.Class + " : "
                               + newSpec.RotationID + " : "
                               + newSpec.MealTypeID + " : "
                               + newSpec.StatusID + " : "
                               + newSpec.Station;

                        Console.WriteLine(str);

                        bool abortTheMission = false; // if there're any errors in the spec Items

                        if (newSpec.SpecID > 0)
                        {
                            List <SpecificationItemTransferObject> courses = new List <SpecificationItemTransferObject>();

                            int headerCounter = 1, subItemCounter = 1;

                            for (int x = 0; x < temp.menusList[0].coursesList.Count; x++) // <--- why zero?
                            {
                                COURSE m = temp.menusList[0].coursesList[x];
                                SpecificationItemTransferObject tempCourse = new SpecificationItemTransferObject();
                                tempCourse.AccountID = "1"; // Air France
                                int xID = x + 1;

                                tempCourse.SpecificationItemID = -(courses.Count + 1);
                                tempCourse.LanguageID          = getLanguageID(Languages, temp.language);
                                if (tempCourse.LanguageID == -1) //new language?
                                {
                                    abortTheMission = true;
                                    error           = "-> language \"" + temp.language + "\" not found";
                                    errors.Add(newSpec.SpecID + ":" + temp.specMatchKey + ">>\n" + error);
                                    Console.WriteLine(error);
                                }
                                tempCourse.SpecificationID = newSpec.SpecID;


                                if (m.label != null)
                                {
                                    tempCourse.ParentID    = 0; // this is a header
                                    tempCourse.Value       = m.label;
                                    tempCourse.OrderNumber = headerCounter++;
                                    subItemCounter         = 1;
                                }
                                else
                                {
                                    if (x > 0)
                                    {
                                        int parentX = 0;
                                        while (courses[(courses.Count - 1) - parentX].ParentID != 0)
                                        {
                                            parentX++;
                                        }
                                        tempCourse.ParentID    = courses[(courses.Count - 1) - parentX].SpecificationItemID;
                                        tempCourse.Value       = m.content;
                                        tempCourse.OrderNumber = subItemCounter++;
                                    }
                                }

                                // get Allergen IDs and apply to specItem
                                foreach (ALLERGEN m2 in m.allergens)
                                {
                                    AllergenTransferObject tempAlly = new AllergenTransferObject();

                                    tempAlly.AccountID  = Convert.ToInt32(tempCourse.AccountID);
                                    tempAlly.LanguageID = tempCourse.LanguageID;
                                    tempAlly.AllergenID = getAllergenID(Allergens, m2.allergen, tempAlly.LanguageID);
                                    if (tempAlly.AllergenID == -1) //new allergen?
                                    {
                                        abortTheMission = true;
                                        error           = "-> allergen \"" + m2.allergen + "\" not found";
                                        errors.Add(newSpec.SpecID + ":" + tempCourse.Value + " " + error + " for " + temp.language);
                                        Console.WriteLine(error);
                                    }
                                    tempCourse.Allergens.Add(tempAlly);
                                }


                                courses.Add(tempCourse);

                                // Check for children
                                if (m.label != null)
                                {
                                    if (m.content != "") // feed the children
                                    {
                                        SpecificationItemTransferObject courseRei = new SpecificationItemTransferObject();
                                        //xID = x + 2;
                                        courseRei.SpecificationItemID = -(courses.Count + 1);
                                        courseRei.LanguageID          = getLanguageID(Languages, temp.language);

                                        // if i used Linq...
                                        //int x2222 = Languages.Where(lester => lester.LanguageCode == temp.language).Select(y => y.LanguageID).Single();

                                        courseRei.SpecificationID = newSpec.SpecID;
                                        courseRei.ParentID        = courses[courses.Count - 1].SpecificationItemID;
                                        courseRei.Value           = m.content;
                                        courseRei.OrderNumber     = subItemCounter++;

                                        // move allergens from the header
                                        courseRei.Allergens  = tempCourse.Allergens;
                                        tempCourse.Allergens = new List <AllergenTransferObject>();
                                        courses.Add(courseRei);
                                    }
                                }
                            }

                            if (abortTheMission)
                            {
                                errors.Add("Spec Item Error/s, " + newSpec.SpecID + ": cannot attach specItems for this spec, one more more allergens are invalid");
                                Console.WriteLine(errors[errors.Count - 1]);
                            }


                            if (VERBOSE)
                            {
                                foreach (SpecificationItemTransferObject m in courses)
                                {
                                    str  = "";
                                    str += m.OrderNumber + ":"
                                           + m.ParentID + ":"
                                           + m.SpecificationID + ":"
                                           + m.SpecificationItemID + ":  ";
                                    if (m.ParentID != 0)
                                    {
                                        str += " ";
                                    }
                                    str += m.Value;
                                    Console.WriteLine(str);
                                }



                                Console.WriteLine("enter? the attachments have beeeguuuun");
                                Console.ReadLine();
                            }


                            if (!abortTheMission)
                            {
                                // ----------- Process the Spec Items .......
                                SpecificationItemTransferObjects SpecItemDTO = new SpecificationItemTransferObjects();
                                SpecificationItemTransferObject  tempSpecGet = new SpecificationItemTransferObject();
                                //SpecItemDTO.data = courses;

                                //SpecItemDTO

                                tempSpecGet.SpecificationID = newSpec.SpecID;
                                SpecItemDTO.Context         = GlobalContext;
                                tempSpecGet.Context         = GlobalContext;
                                //SpecItemDTO.data[0].SpecificationID = newSpec.SpecID;

                                //DataTable tempResponse = new DataTable();
                                //SpecificationItemResponseObject SpecTemp = new SpecificationItemResponseObject();
                                //SpecTemp = await httpResponse.Content.ReadAsAsync<SpecificationItemResponseObject>();

                                //SpecItemDTO = JsonConvert.DeserializeObject<SpecificationItemTransferObjects>(SpecTemp.JsonResults);
                                // nuke old all specItems
                                // will take longer but checking, updating and deleting would be better, but slower for

                                //get old Specs
                                httpResponse = client.PostAsJsonAsync <SpecificationItemTransferObject>(ajaxURI + "/getSpecificationItemsBySpecID", tempSpecGet).Result;
                                SpecificationItemResponseObject        toJSON  = new SpecificationItemResponseObject();
                                List <SpecificationItemTransferObject> CorSair = new List <SpecificationItemTransferObject>();
                                toJSON = await httpResponse.Content.ReadAsAsync <SpecificationItemResponseObject>();

                                CorSair = JsonConvert.DeserializeObject <List <SpecificationItemTransferObject> >(toJSON.JsonResults);


                                // mark all as toDelete
                                foreach (SpecificationItemTransferObject m in CorSair)
                                {
                                    if (m.LanguageID == courses[0].LanguageID)
                                    {
                                        m.ToBeDeleted = true;
                                    }
                                }


                                // append to courses
                                courses.AddRange(CorSair);
                                SpecItemDTO.data = courses;



                                httpResponse = client.PostAsJsonAsync <SpecificationItemTransferObjects>(ajaxURI + "/ProcessSpecificationItems", SpecItemDTO).Result;
                                if (VERBOSE)
                                {
                                    Console.WriteLine("\n|--------------------|");
                                    Console.WriteLine("... Attaching SpecItems for new Spec");
                                    Console.WriteLine("Data Sent.. did it work? ....");
                                }

                                if (httpResponse.StatusCode == (HttpStatusCode)200)
                                {
                                    //Console.WriteLine("yes....yes it did");
                                    SpecificationItemResponseObject PressXtoJSON = new SpecificationItemResponseObject();
                                    try
                                    {
                                        PressXtoJSON = await httpResponse.Content.ReadAsAsync <SpecificationItemResponseObject>();
                                    }
                                    catch (Newtonsoft.Json.JsonSerializationException e)
                                    {
                                        Console.WriteLine("the faiL, has arrived :(");
                                        error = "-> " + e.Message;
                                        errors.Add("JSON!!! " + error);
                                        Console.WriteLine(error);
                                    }
                                    //SpecRes = JsonConvert.DeserializeObject<List<SpecTransferObject>>(PressXtoJSON.JsonResults);
                                }
                                else
                                {
                                    Console.WriteLine("nope, wrong again!");
                                    error = "--> " + httpResponse.StatusCode + " : " + httpResponse.ReasonPhrase;
                                    errors.Add("Cant Process Items for " + newSpec.SpecID + ":" + temp.specMatchKey + ": " + error);
                                    Console.WriteLine(error);
                                }
                            }
                        }
                        else
                        {
                            error = "--> can't add specs without ID";
                            errors.Add("Cant Process Items: " + newSpec.SpecID + ":" + temp.specMatchKey + error);
                            Console.WriteLine(error);
                        }
                    }//Console.Clear();
                }
            }
            Console.WriteLine("one more ENTER");
            Console.ReadLine();


            if (errors.Count > 0)
            {
                Console.WriteLine("Yay, errors have occured");
                Console.WriteLine("-----------------------------------\n");
                foreach (string m in errors)
                {
                    Console.WriteLine(m);
                }
                Console.ReadLine();
            }
        }
示例#3
0
        static void MainOLD(string[] args)
        {
            string funText;

            string[] lineS;
            using (StreamReader reader = File.OpenText(args[0]))
                while (!reader.EndOfStream)
                {
                    //string[] temp;
                    string line = reader.ReadLine();
                    if (null == line)
                    {
                        continue;
                    }

                    //string[] PressXtoJSON = new string[] line;

                    List <String> elements     = new List <String>();
                    List <String> moreElements = new List <String>();
                    List <String> PressXtoJSON = new List <String>();


                    elements.Add("key");
                    elements.Add("mealList");
                    elements.Add("datemaj");
                    elements.Add("validityBegin");
                    elements.Add("validityEnd");
                    elements.Add("caterer");
                    elements.Add("departureArrivalList");
                    elements.Add("pairingGrid");
                    elements.Add("cycle");
                    elements.Add("state");
                    elements.Add("version");
                    elements.Add("language");
                    elements.Add("classCodeList");
                    elements.Add("mealType");
                    elements.Add("menusList");

                    moreElements.Add("label");
                    moreElements.Add("content");
                    moreElements.Add("sequence");

                    List <int> commas = new List <int>();

                    commas.Add(0);
                    int temp, firstComma = 0;

                    for (int x = 0; x < line.Length; x++)
                    {
                        temp = line.IndexOf(',', x);
                        //nevermind
                    }

                    //line.Sub

                    lineS = line.Split(',');

                    PressXtoJSON = parseObject(line, elements);

                    String temp1 = PressXtoJSON[14].Substring(PressXtoJSON[14].IndexOf("\"coursesList\""), PressXtoJSON[14].Length - PressXtoJSON[14].IndexOf("\"coursesList\""));

                    //PressXtoJSON = parseObject(temp1, moreElements);

                    foreach (String moo in PressXtoJSON)
                    {
                        Console.WriteLine(moo);
                    }

                    string[] foo = new string[] { "loo" };

                    String ben = "waterloovilage";

                    ben.Split(foo, StringSplitOptions.None);

                    int fromHere, toHere, thisLength;

                    fromHere   = PressXtoJSON[14].IndexOf('[', 20);
                    toHere     = PressXtoJSON[14].LastIndexOf(']', PressXtoJSON[14].Length - 1);
                    thisLength = toHere - fromHere;



                    theList test = new theList();
                    test = JsonConvert.DeserializeObject <theList>(line);

                    //something = JsonConvert.DeserializeObject(line);



                    Console.ReadLine();
                }
        }