Ejemplo n.º 1
0
        /// <summary>
        /// Checks for a started file and a valid save path.
        /// </summary>
        public void SaveFile_Button()
        {
            try
            {
                if (IsFileOpen)
                {
                    if (FileCheck.CheckFile(MainFileName))
                    {
                        SaveFile();
                    }
                    else
                    {
                        SaveFileAs();
                    }
                }
                else
                {
                    // Testing the XMLWriter Exception handling:
                    SaveFileBad(false);

                    //SaveFileAs();
                }
            }
            catch (XMLParseException e)
            {
                MessageManager.DisplayMessage($"TESTING** Was not able to save. {e.Message}", "ERROR!");
                e.CompileErrorData();
            }
        }
Ejemplo n.º 2
0
        private static bool SaveTddSpec(string filePath, plotData[] tdd11, plotData[] tdd22)
        {
            if (!FileCheck.FilePrepare(filePath))
            {
                return(false);
            }
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            FileStream   fs = new FileStream(filePath, FileMode.Create);
            StreamWriter sw = new StreamWriter(new BufferedStream(fs), System.Text.Encoding.Default);

            System.Globalization.NumberFormatInfo numberFormatInfo =
                (System.Globalization.NumberFormatInfo)System.Globalization.NumberFormatInfo.CurrentInfo.Clone();
            numberFormatInfo.NaNSymbol = "NaN";
            string header = "TDD11_UPPER\tTDD11_LOWER\tTDD22_UPPER\tTDD22_LOWER" + Environment.NewLine;

            sw.Write(header);
            int length = tdd11[0].yData.Length;

            for (int i = 0; i < length; i++)
            {
                string line = tdd11[0].yData[i].ToString(numberFormatInfo) + "\t" + tdd11[1].yData[i].ToString(numberFormatInfo)
                              + "\t" + tdd22[0].yData[i].ToString(numberFormatInfo) + "\t" + tdd22[1].yData[i].ToString(numberFormatInfo) +
                              Environment.NewLine;
                sw.Write(line);
            }
            sw.Close();
            fs.Close();
            return(true);
        }
Ejemplo n.º 3
0
        private void btnSync_MouseUp(object sender, MouseEventArgs e)
        {
            btnSync.Image = Properties.Resources.sync_normal;

            panelSettings.Visible = false;

            UpdateProgress(0, "Starting Re-Sync");

            UpdateProgressCallback callback = UpdateProgress;

            FileCheck.GetHashList(callback, true);
        }
Ejemplo n.º 4
0
 public void SaveSubs_Button()
 {
     if (IsSubFileOpen)
     {
         if (FileCheck.CheckFile(CategoryFileName))
         {
             SaveSubs();
         }
         else
         {
             SaveSubsAs();
         }
     }
     else
     {
         SaveSubsAs();
     }
 }
Ejemplo n.º 5
0
        public static string GetSingularSourcePath()
        {
            // bit of a hack, but source code folder for the assembly is only
            // .. available from the filename of the .dll
            FileCheck fc          = new FileCheck();
            Assembly  singularDll = Assembly.GetExecutingAssembly();
            FileInfo  fi          = new FileInfo(singularDll.Location);
            int       len         = fi.Name.LastIndexOf("_");
            string    folderName  = fi.Name.Substring(0, len);

            folderName = Path.Combine(Styx.Helpers.GlobalSettings.Instance.CombatRoutinesPath, folderName);

            // now check if relative path and if so, append to honorbuddy folder
            if (!Path.IsPathRooted(folderName))
            {
                folderName = Path.Combine(GetHonorBuddyFolder(), folderName);
            }

            return(folderName);
        }
Ejemplo n.º 6
0
        public void LoadSaveIdentical()
        {
            // read each test NIF and make sure writing it back results in identical data
            nifly.NifLoadOptions loadOptions = new NifLoadOptions();
            loadOptions.isTerrain = false;

            nifly.NifSaveOptions saveOptions = new NifSaveOptions();
            saveOptions.optimize   = false;
            saveOptions.sortBlocks = false;

            int failed         = 0;
            int matched        = 0;
            int newIsSubstring = 0;

            foreach (string fileName in Directory.EnumerateFiles(dataFileLocation, "*.nif"))
            {
                // Files that differ appear to have been cleaned up by the round trip. Spot checking a couple
                // in Nifskope shows no information loss.
                var       nifFile    = new nifly.NifFile(true);
                int       loadResult = nifFile.Load(fileName, loadOptions);
                int       saveResult = nifFile.Save(fileName + ".new", saveOptions);
                FileCheck match      = CompareFiles(fileName, fileName + ".new");
                switch (match)
                {
                case FileCheck.Exact:
                    ++matched;
                    break;

                case FileCheck.MatchTruncated:
                    myContext.WriteLine(String.Format("Truncate {0}", fileName));
                    ++newIsSubstring;
                    break;

                case FileCheck.NoMatch:
                    myContext.WriteLine(String.Format("Mismatch {0}", fileName));
                    ++failed;
                    break;
                }
            }
            myContext.WriteLine(String.Format("NIF Files {0} failed, {1} truncated, {2} exact", failed, newIsSubstring, matched));
        }
Ejemplo n.º 7
0
        private static bool SaveFreSpec(string filePath, DataTable dt)
        {
            if (!FileCheck.FilePrepare(filePath))
            {
                return(false);
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            int          column = dt.Columns.Count;
            FileStream   fs     = new FileStream(filePath, FileMode.Create);
            StreamWriter sw     = new StreamWriter(new BufferedStream(fs), System.Text.Encoding.Default);

            string header = "";

            for (int i = 1; i < column; i++)
            {
                header = header + dt.Columns[i] + "\t";
            }

            header = header.Trim() + Environment.NewLine;
            sw.Write(header);

            foreach (DataRow variable in dt.Rows)
            {
                string line = "";
                for (int i = 1; i < column; i++)
                {
                    line = line + variable[i] + "\t";
                }

                line = line.Substring(0, line.Length - 1) + Environment.NewLine;
                sw.Write(line);
            }
            sw.Close();
            fs.Close();
            return(true);
        }
Ejemplo n.º 8
0
        public void SaveSubs()
        {
            if (FileCheck.CheckDirectory(CategoryFileName))
            {
                IXMLDataSub data = new XMLData()
                {
                    IncomeSubCategories  = Income.AllIncomeCategories,
                    ExpenseSubCategories = Expense.AllExpenseCategories
                };

                XMLWrtier wrtier = new XMLWrtier(CategoryFileName, data);
                wrtier.WriteSubFile(MessageManager.DisplayMessage);

                IsSubFileSaved = true;

                SetSubFileSaveState();
            }
            else
            {
                SaveSubsAs();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Test the back end structurs
        /// </summary>
        static void test()
        {
            /// TESTS BDD - EXAMPLE ///


            //         /// MARQUES
            Control.MarqueControl MCont = new Control.MarqueControl();
            //         HashSet<Model.Marque> List = MCont.GetAll();
            //         if(List != null)    // Display all Marques
            //         {
            //             foreach (Model.Marque Brand in List)
            //             {
            //                 // Display all differents brands
            //                 Console.WriteLine(Brand.Nom);
            //             }
            //         }
            //         // Display Marque name with id = 1
            //         //Console.WriteLine("find name with id 1 : " + MCont.FindByRef(1).Nom);
            //         // Create a new marque in the model
            //         Model.Marque m = new Model.Marque("Kingston");
            //         // Insert this new marque into the DB
            //         MCont.Insert(m);
            //         // Update the marque in the model with the new attributed id
            //         m = MCont.FindByRef(MCont.GetMaxRef());
            //         Console.WriteLine("Insert : " + m.Nom);
            //         // Change the name in the model
            //         m.Nom = "QueenStone";
            //         // Update the name in the DB
            //         bool u = MCont.Update(m);
            //         Console.WriteLine("Update : " + MCont.FindByRef(MCont.GetMaxRef()).Nom);
            //         // Delete the marque
            //         bool r = MCont.Delete(m);

            //         /// FAMILLE
            FamilleControl FCont = new FamilleControl();
            //         HashSet<Famille> ListF = FCont.GetAll();
            //         if (ListF != null)    // Display all
            //         {
            //             foreach (Famille Fami in ListF)
            //             {
            //                 // Display all differents
            //                 Console.WriteLine(Fami.Nom);
            //             }
            //         }
            //         FCont.Insert(new Famille("Grande"));
            //         FCont.Insert(new Famille("Moyenne"));
            //         FCont.Insert(new Famille("Petite"));
            //         Console.WriteLine("max : " + FCont.GetMaxRef());
            //         ListF = FCont.GetAll();
            //         if (ListF != null)    // Display all
            //         {
            //             foreach (Famille Fami in ListF)
            //             {
            //                 // Display all differents
            //                 Console.WriteLine(Fami.RefFamille + " " + Fami.Nom);
            //                 Fami.Nom = "Changed";
            //                 FCont.Update(Fami);
            //                 Famille Fam2 = FCont.FindByRef(Fami.RefFamille);
            //                 Console.WriteLine(Fam2.RefFamille + " " + Fam2.Nom);
            //                 FCont.Delete(Fami);
            //             }
            //         }
            //         Console.WriteLine("max : " + FCont.GetMaxRef());

            //         /// SS-FAMILLE
            SousFamilleControl SFCont = new SousFamilleControl();
            //         Console.WriteLine("\nMax sous-famille : " + SFCont.GetMaxRef());
            //         Famille f = new Famille("La Ch-tite Famille");
            //         FCont.Insert(f);
            //         f = FCont.FindByRef(FCont.GetMaxRef());
            //         SousFamille sf = new SousFamille("Sous race 1", f);
            //         SousFamille sfb = new SousFamille("Sous race 2", f);
            //         r = SFCont.Insert(sf);
            //         r = SFCont.Insert(sfb);
            //         Console.WriteLine("Inserts\nMax sous-famille : " + SFCont.GetMaxRef());
            //         HashSet<SousFamille> ListSF = SFCont.GetAll();
            //         if (ListSF != null)    // Display all
            //         {
            //             foreach (SousFamille SFam in ListSF)
            //             {
            //                 // Display all differents
            //                 Console.WriteLine(SFam.RefSousFamille + " " + SFam.Nom);
            //                 SFam.Nom = "Changed";
            //                 SFCont.Update(SFam);
            //                 SousFamille SFam2 = SFCont.FindByRef(SFam.RefSousFamille);
            //                 Console.WriteLine(SFam2.RefSousFamille + " " + SFam2.Nom);

            //		// Test of the GetByName on a SF
            //		SousFamille SFMock = SFCont.GetByName(SFam);
            //		Console.WriteLine("test Get FullObject \n SFMock name = " + SFMock.Nom);
            //		SFam.Nom = "Not In the Database";
            //		SFMock = SFCont.GetByName(SFam);
            //		if (SFMock == null) Console.WriteLine("Done");
            //		SFCont.Delete(SFam);
            //             }
            //         }


            //FCont.Delete(f);
            //         Console.WriteLine("Deletes\nMax sous-famille : " + SFCont.GetMaxRef());

            //         /// ARTICLES
            ArticleControl ACont = new ArticleControl();

            //         // Create famille first
            //         Famille Fam = new Famille("Pere");
            //         FCont.Insert(Fam);
            //         Fam.RefFamille = FCont.GetMaxRef();
            //         // Then create SousFamilles
            //         SousFamille sf1 = new SousFamille("Fils",Fam);
            //         SousFamille sf2 = new SousFamille("Fille",Fam);
            //         SFCont.Insert(sf1);
            //         sf1.RefSousFamille = SFCont.GetMaxRef();
            //         SFCont.Insert(sf2);
            //         sf2.RefSousFamille = SFCont.GetMaxRef();
            //         //Create Marque
            //         Marque Mark = new Marque("Vroom");
            //         MCont.Insert(Mark);
            //         Mark.RefMarque = MCont.GetCountRef();
            //         Marque Mark2 = new Marque("Nitro");
            //         MCont.Insert(Mark2);
            //         Mark2.RefMarque = MCont.GetMaxRef();
            //         Console.WriteLine("\nArticle :\n" + MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles");
            //         //Articles
            //         Article a1 = new Article("007","Secret Pen",88,2,Mark,sf1);
            //         ACont.Insert(a1);
            //         Article ac = new Article("008", "Secret copieur", 71, 12, Mark2, sf2);
            //         ACont.Insert(ac);
            //         HashSet<Article> Alist = ACont.GetAll();
            //         if(Alist != null)
            //         {
            //             foreach(Article Art in Alist)
            //             {
            //                 Console.WriteLine(Art.RefArticle + " " + Art.Description + " " + Art.Marque.Nom + " " + Art.SousFamille.Nom);
            //                 Art.Description = "Secret changed ";
            //                 Art.Marque = Mark2;
            //                 Art.SousFamille = sf2;
            //                 ACont.Update(Art);
            //                 Article Updated = ACont.FindByRef(Art.RefArticle);
            //                 Console.WriteLine(Updated.RefArticle + " " + Updated.Description + " " + Updated.Marque.Nom + " " + Updated.SousFamille.Nom);
            //                 ACont.Delete(Updated);
            //             }
            //         }


            ////Delete

            //ACont.Insert(a1);

            //ACont.Insert(ac);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //MCont.Delete(Mark);
            //         MCont.Delete(Mark2);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //FCont.Delete(Fam);
            //

            ////Delete

            //ACont.Insert(a1);

            //ACont.Insert(ac);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //MCont.Delete(Mark);
            //         MCont.Delete(Mark2);
            //Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
            //FCont.Delete(Fam);
            //         Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");

            /*
             * Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
             * FileControl.ImportFile("C:\\Users\\Foxinow\\Desktop\\net\\.Net-Project\\Bacchus\\Bacchus\\Data_to_integrate.csv");
             * Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
             * FileControl.ExportFile(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\toto.csv");
             * ACont.FlushTable();
             * MCont.FlushTable();
             * FCont.FlushTable();
             * Console.WriteLine(MCont.GetCountRef() + " Marques / " + SFCont.GetCountRef() + " ssFamilles / " + FCont.GetCountRef() + " Familles / " + ACont.GetCountRef() + " Articles ");
             */
            try
            {
                FileCheck.CheckFile("E:\\Bureau\\toto.csv");
                Console.WriteLine("Lefichier est bon");
            }
            catch (ExceptionFile Xceptio)
            {
                Console.WriteLine(Xceptio.FileErrorMsg);
            }
        }
Ejemplo n.º 10
0
        private void OnReceivedPacket(object sender, PacketEventArgs e)
        {
            int    nBytesUsed = 0;
            ushort nRecvType  = 0;

            while (nBytesUsed < e.Length)
            {
                nRecvType   = BitConverter.ToUInt16(e.Data, nBytesUsed);
                nBytesUsed += 2;
                switch (nRecvType)
                {
                case Protocols.T_PC_CONNECT_GET_SERVER_GROUP_LIST_OK:
                {
                    MSG_PC_CONNECT_GET_SERVER_GROUP_LIST_OK Info = Operations.ByteArrayToStruct <MSG_PC_CONNECT_GET_SERVER_GROUP_LIST_OK>(e.Data, ref nBytesUsed);

                    if (Info.NumOfServerGroup == 0)
                    {
                        MessageBox.Show("Gameserver is offline!\nPlease check [http://ace.gaming-paradise.net] for further information!");
                        Exit();
                    }

                    if (Info.ServerGroup.Crowdedness <= 0)
                    {
                        UpdateProgress(0, "Gameserver offline", false);

                        System.Threading.Thread.Sleep(5000);

                        m_Sock.SendPacket(Protocols.T_PC_CONNECT_GET_SERVER_GROUP_LIST);

                        continue;
                    }

                    m_ServerGroup = Info.ServerGroup;

                    MSG_PC_CONNECT_SINGLE_FILE_VERSION_CHECK Msg = new MSG_PC_CONNECT_SINGLE_FILE_VERSION_CHECK();
                    Msg.DeleteFileListVersion = new ushort[] { 0, 0, 0, 0 };
                    Msg.NoticeVersion         = new ushort[] { 0, 0, 0, 0 };

                    m_Sock.SendPacket(Protocols.T_PC_CONNECT_SINGLE_FILE_VERSION_CHECK, Msg);
                }
                break;

                case Protocols.T_PC_CONNECT_SINGLE_FILE_UPDATE_INFO:
                {
                    MSG_PC_CONNECT_SINGLE_FILE_UPDATE_INFO Msg = Operations.ByteArrayToStruct <MSG_PC_CONNECT_SINGLE_FILE_UPDATE_INFO>(e.Data, ref nBytesUsed);

                    MSG_PC_CONNECT_VERSION SendMsg = new MSG_PC_CONNECT_VERSION();
                    SendMsg.ClientVersion = new ushort[] { 0, 0, 0, 0 };

                    m_Sock.SendPacket(Protocols.T_PC_CONNECT_VERSION, SendMsg);
                }
                break;

                case Protocols.T_PC_CONNECT_SINGLE_FILE_VERSION_CHECK_OK:
                {
                    MSG_PC_CONNECT_VERSION SendMsg = new MSG_PC_CONNECT_VERSION();
                    SendMsg.ClientVersion = new ushort[] { 0, 0, 0, 0 };

                    m_Sock.SendPacket(Protocols.T_PC_CONNECT_VERSION, SendMsg);
                }
                break;

                case Protocols.T_PC_CONNECT_REINSTALL_CLIENT:
                {
                    MSG_PC_CONNECT_REINSTALL_CLIENT Msg = Operations.ByteArrayToStruct <MSG_PC_CONNECT_REINSTALL_CLIENT>(e.Data, ref nBytesUsed);

                    // Use current version, we don't need the update thingy
                    MSG_PC_CONNECT_VERSION SendMsg = new MSG_PC_CONNECT_VERSION();
                    SendMsg.ClientVersion = Msg.LatestVersion;

                    m_Sock.SendPacket(Protocols.T_PC_CONNECT_VERSION, SendMsg);
                }
                break;

                case Protocols.T_PC_CONNECT_VERSION_OK:
                {
                    UpdateProgressCallback callback = UpdateProgress;
                    FileCheck.GetHashList(callback);
                }
                break;

                case Protocols.T_PC_CONNECT_LOGIN_OK:
                {
                    MSG_PC_CONNECT_LOGIN_OK Msg = Operations.ByteArrayToStruct <MSG_PC_CONNECT_LOGIN_OK>(e.Data, ref nBytesUsed);

                    if (Properties.Settings.Default.StoreLogins)
                    {
                        Properties.Settings.Default.AccountName = tbAccount.Text;
                        Properties.Settings.Default.Password    = tbPassword.Text;
                        Properties.Settings.Default.Save();
                    }

                    string Args = String.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}"
                                                , Msg.FieldServerIP.ToManagedString()
                                                , Msg.FieldServerPort
                                                , Msg.IMServerIP.ToManagedString()
                                                , Msg.IMServerPort

                                                , Msg.AccountName.ToManagedString()
                                                , BitConverter.ToString(MD5Lib.GetPasswordMD5(tbPassword.Text)).Replace("-", "").ToLowerInvariant()

                                                , (Properties.Settings.Default.Fullscreen) ? 1 : 0
                                                , Properties.Settings.Default.Width
                                                , Properties.Settings.Default.Height
                                                , 2

                                                , (Msg.ConnectToTestServer) ? 1 : 0

                                                , (Properties.Settings.Default.UseVSync) ? 1 : 0);

                    ProcessStartInfo pInfo = new ProcessStartInfo();
                    pInfo.FileName  = "ca.exe";
                    pInfo.Arguments = Args;

                    Process.Start(pInfo);

                    Environment.Exit(0);
                }
                break;

                case Protocols.T_PC_CONNECT_LOGIN_BLOCKED:
                {
                    MSG_PC_CONNECT_LOGIN_BLOCKED Msg = Operations.ByteArrayToStruct <MSG_PC_CONNECT_LOGIN_BLOCKED>(e.Data, ref nBytesUsed);

                    if (Msg.IsMacBlocked)
                    {
                        MessageBox.Show("Your account is blocked presently.\n If you believe this is an error please Contact Customer Support at [http://gaming-paradise.net/support/] for further details");
                    }
                    else
                    {
                        string BlockedMsg = String.Format("{0}\'s account is blocked presently.\n  Reason: {1}\n  Period: {2} ~ {3}\n\nContact Customer Support at [http://gaming-paradise.net/support/] for further details."
                                                          , Msg.szAccountName.ToManagedString()
                                                          , Msg.szBlockedReasonForUser.ToManagedString()
                                                          , Msg.atimeStart.ToString()
                                                          , Msg.atimeEnd.ToString());
                        MessageBox.Show(BlockedMsg);
                    }
                }
                break;

                case Protocols.T_ERROR:
                {
                    MSG_ERROR ErrorMsg = Operations.ByteArrayToStruct <MSG_ERROR>(e.Data, ref nBytesUsed);

                    string Msg = Operations.GetChatMessageFromPacket(e.Data, ref nBytesUsed, ErrorMsg.StringLength);

                    ShowError(ErrorMsg, Msg);
                }
                break;

                default:
                {
                    MessageBox.Show("Got unknown data from server!");
                    Exit();
                }
                break;
                }
            }
        }
    static void Main()
    {
        try{
            String[] configs       = File.ReadAllText(Directory.GetCurrentDirectory() + @"/configs.csv").Split(',');
            var      email         = configs[0];
            var      password      = configs[1];
            var      finalLocation = configs[2];
            var      smtpUser      = configs[3];
            var      smtpPass      = configs[4];
            var      alertEmail    = configs[5];
            var      phone         = configs[6];

            var location = Directory.GetCurrentDirectory() + "/";

            //Json copy pasted from a "get all" request to MISO's api
            var json = "{\"QueryValues\":{\"rctype\":\"Load Pocket Report\"},\"NavigationItem\":{\"ParentPropertyValue\":\"Load Pocket Report\",\"ChildPropertySystemName\":null,\"DisplayResultInGrid\":false,\"GridMetadataColumns\":[],\"ResultSortField\":null,\"ResultSortDirection\":null,\"UseDynamicChoiceMode\":null,\"UseDynamicDateNavigation\":false,\"UseDynamicYearNavigation\":false,\"UseDynamicQuarterNavigation\":false,\"UseDynamicMonthNavigation\":false,\"UseDynamicDayNavigation\":false,\"ChildDocumentNavigationItems\":null,\"Title\":\"\",\"Summary\":\"<p><a title=\\\"MISO Load Pocket Report Readers Guide\\\" href=\\\"/api/documents/getbyguid/c35f6b50-fdc2-5742-bd3c-cf185c23ee57\\\">MISO Load Pocket Report Readers Guide</a></p>\",\"LoadedNavigableDocuments\":[{\"FileName\":\"Load_Pocket_20171121.zip\",\"Name\":\"Load Pocket 20171121\",\"Url\":\"/api/documents/getbymediaid/129294\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129294,\"Uploaded\":\"2018-02-26T19:42:50Z\",\"UploadedBy\":34,\"ObjectId\":137504,\"Created\":\"2018-02-26T19:43:06Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:10Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"221e5d05-c71b-5d66-996c-d9c22d10437c\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171122.zip\",\"Name\":\"Load Pocket 20171122\",\"Url\":\"/api/documents/getbymediaid/129295\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129295,\"Uploaded\":\"2018-02-26T19:42:56Z\",\"UploadedBy\":34,\"ObjectId\":137505,\"Created\":\"2018-02-26T19:43:12Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:15Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"e3aaf099-2679-5c51-a1d3-5d309a0447be\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171123.zip\",\"Name\":\"Load Pocket 20171123\",\"Url\":\"/api/documents/getbymediaid/129233\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129233,\"Uploaded\":\"2018-02-26T19:27:55Z\",\"UploadedBy\":34,\"ObjectId\":137443,\"Created\":\"2018-02-26T19:28:11Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:17Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"018ab122-2ac6-52cc-a241-9f033d9b5143\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171124.zip\",\"Name\":\"Load Pocket 20171124\",\"Url\":\"/api/documents/getbymediaid/129234\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129234,\"Uploaded\":\"2018-02-26T19:28:05Z\",\"UploadedBy\":34,\"ObjectId\":137444,\"Created\":\"2018-02-26T19:28:21Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:27Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"f026d520-5e27-51c1-9858-a08fea7fefdd\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171125.zip\",\"Name\":\"Load Pocket 20171125\",\"Url\":\"/api/documents/getbymediaid/129235\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129235,\"Uploaded\":\"2018-02-26T19:28:16Z\",\"UploadedBy\":34,\"ObjectId\":137445,\"Created\":\"2018-02-26T19:28:31Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:38Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"2f4ae535-4c20-57b1-9060-c63a5298229b\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171126.zip\",\"Name\":\"Load Pocket 20171126\",\"Url\":\"/api/documents/getbymediaid/129296\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129296,\"Uploaded\":\"2018-02-26T19:43:02Z\",\"UploadedBy\":34,\"ObjectId\":137506,\"Created\":\"2018-02-26T19:43:18Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:21Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"7763eb39-3bd5-53da-a29a-91be0327d7e2\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171127.zip\",\"Name\":\"Load Pocket 20171127\",\"Url\":\"/api/documents/getbymediaid/129297\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129297,\"Uploaded\":\"2018-02-26T19:43:08Z\",\"UploadedBy\":34,\"ObjectId\":137507,\"Created\":\"2018-02-26T19:43:24Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:27Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"eb27d73c-aa3a-5820-98c8-23fd308d5d18\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171128.zip\",\"Name\":\"Load Pocket 20171128\",\"Url\":\"/api/documents/getbymediaid/129236\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129236,\"Uploaded\":\"2018-02-26T19:28:26Z\",\"UploadedBy\":34,\"ObjectId\":137446,\"Created\":\"2018-02-26T19:28:42Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:47Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"1e6b4040-2c1b-538f-8091-82f51514dcd4\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171129.zip\",\"Name\":\"Load Pocket 20171129\",\"Url\":\"/api/documents/getbymediaid/129237\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129237,\"Uploaded\":\"2018-02-26T19:28:36Z\",\"UploadedBy\":34,\"ObjectId\":137447,\"Created\":\"2018-02-26T19:28:51Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:28:57Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"c9e3df76-6555-5ba6-8f1a-a1476c7a5a1f\",\"accesstype\":\"Visitors-RA\"}},{\"FileName\":\"Load_Pocket_20171130.zip\",\"Name\":\"Load Pocket 20171130\",\"Url\":\"/api/documents/getbymediaid/129298\",\"MimeType\":\"application/zip\",\"MimeTypeName\":\"Compressed archive\",\"MediaId\":129298,\"Uploaded\":\"2018-02-26T19:43:14Z\",\"UploadedBy\":34,\"ObjectId\":137508,\"Created\":\"2018-02-26T19:43:30Z\",\"CreatedBy\":34,\"Updated\":\"2018-02-26T19:43:33Z\",\"UpdatedBy\":34,\"IsFollowing\":false,\"CategoryId\":26,\"AuthorizedRoles\":[\"Visitors-RA\"],\"Metadata\":{\"guid\":\"48c75229-1268-5621-8353-57cc4e89cad6\",\"accesstype\":\"Visitors-RA\"}}],\"TotalAvailableResults\":98},\"Filters\":[{\"PropertyName\":\"rctype\",\"Value\":\"\"}],\"EnableFollowDocuments\":null,\"Top\":null,\"Skip\":10}";

            //Stops from running if files for the current date already exist
            if (FileCheck.Check(finalLocation))
            {
                return;
            }

            var webClient = new CookieAwareWebClient();


            var collection = new NameValueCollection();
            collection.Add("Email", email);
            collection.Add("Password", password);



            Console.Write("Attempting to log in to MISO website... \n");
            webClient.Login("https://www.misoenergy.org/Account/Login", collection);

            //Post JSON using cookie authenticated client and JSON from standard request
            Console.Write("Acquiring document list from MISO... \n");
            var response = webClient.PostPage("https://www.misoenergy.org/api/documents/getnavigabledocuments", json);

            //Parse the response JSON
            JObject parsedResponse = JObject.Parse(response);
            var     list           = parsedResponse["documents"].OrderByDescending(t => t["FileName"]).ToList();
            var     single         = list.FirstOrDefault();
            var     url            = "https://www.misoenergy.org" + single["Url"];
            var     filename       = single["FileName"].ToString();

            //Make sure that the load pocket file that is the "latest" is from the current date.
            if (filename != "Load_Pocket_" + DateTime.Now.ToString("yyyyMMdd") + ".zip")
            {
                throw new Exception("The current load pocket file is not from the current date.");
            }

            //Download zip file, store temporarily in location and the extract to finalLocation before deleting zip from location
            webClient.GetFileAndMove(url, filename, location, finalLocation);


            //Used to send alert on working instance
            if (FileCheck.Check(finalLocation))
            {
                Console.Write("Attempting to send email notifications... \n");
                MailHelper.SendAlert(smtpUser, smtpPass, alertEmail, phone);
            }

            Console.Write(filename + " was extracted to " + finalLocation + "");
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }