public CSVThread ParseLine(string aLine) { CSVThread ret = null; // Match m = KParserRegEx.Match(aLine); if (m.Success) { ret = CSVThread.New(); // string[] items = m.Value.Split(','); if (items.Length >= KExpectedItemCount) { // Ensure each item is trimmed before processing for (int i = 0; i < items.Length; i++) { items[i] = items[i].Trim(); } try { // THREAD ret.ThreadName = items[0]; // CHUNK ret.ChunkName = items[1]; ret.ChunkBaseAddress = ParseHexValue(items[2]); // HEAP ret.SizeCurrent = ParseDecimalValue(items[3]); ret.SizeMin = ParseDecimalValue(items[4]); ret.SizeMax = ParseDecimalValue(items[5]); // FIRST FREE CELL ret.FirstFreeCellAddress = ParseHexValue(items[6]); ret.FirstFreeCellLength = ParseDecimalValue(items[7]); // OTHER FREE CELL INFO ret.FreeCellCount = ParseDecimalValue(items[8]); ret.FreeSpaceTotal = ParseDecimalValue(items[9]); ret.FreeSpaceSlack = ParseDecimalValue(items[10]); ret.FreeCellLargest = ParseDecimalValue(items[11]); // ALLOC CELL INFO ret.AllocCellLargest = ParseDecimalValue(items[12]); ret.AllocCellCount = ParseDecimalValue(items[13]); ret.AllocSpaceTotal = ParseDecimalValue(items[15]); // MISC ret.MinCellSize = ParseDecimalValue(items[14]); } catch (Exception) { ret = null; } } } return(ret); }
protected void CompareAndWriteItems(CSVThread aItem1, long aItemVal1, CSVThread aItem2, long aItemVal2, int aColumn, int aGrowColour, int aShrinkColour) { // First write the values to the columns if (!aItem1.IsDefault) { Utils.SetValue(Row, aColumn, Sheet, aItemVal1.ToString()); } if (!aItem2.IsDefault) { Utils.SetValue(Row, aColumn + 1, Sheet, aItemVal2.ToString()); } // Delta long delta = aItemVal1 - aItemVal2; Utils.SetValue(Row, aColumn + 2, Sheet, (delta * -1).ToString()); // Colour code accordingly int colour = 0x000000; // black if (aItemVal1 < aItemVal2) { colour = aGrowColour; // 0x0000FF; // red } else if (aItemVal1 > aItemVal2) { colour = aShrinkColour; // 0x00FF00; // green } Utils.SetRangeFontColour(Row, aColumn + 2, Row, aColumn + 2, Sheet, colour); }
private bool TryToParseEntry(string aLine) { Match matchEntry = KRegExEntry.Match(aLine); if (matchEntry.Success) { // Check if it's an opening or closing tag. bool isOpen = string.IsNullOrEmpty(matchEntry.Groups["TagType"].Value); int index = int.Parse(matchEntry.Groups["Index"].Value); if (isOpen) { // Opening tag - starting a new entry, save entry id ChangeState(TState.EStateSeenEntryStart); SaveCurrentEntryIfValidState(); iCurrentEntryId = index; iWorkInProgressThread = CSVThread.New(); } else { // Closing tag, we should've finished an entry now. // Validate the index is as we expect CheckExpectedIndexId(index); ChangeState(TState.EStateSeenEntryEnd); SaveCurrentEntryIfValidState(); } } return(matchEntry.Success); }
public override void Compare(CSVThread aMaster, CSVThread aOther) { Utils.SetValue(Row, 1, Sheet, aMaster.FullName); // float frag1Value = (float)aMaster.FreeSpaceTotal / (float)aMaster.SizeCurrent; string frag1 = "=" + aMaster.FreeSpaceTotal.ToString() + " / " + aMaster.SizeCurrent.ToString(); if (aMaster.SizeCurrent == 0) { frag1Value = 0.0F; frag1 = "=0"; } if (!aMaster.IsDefault) { Utils.SetValue(Row, 2, Sheet, frag1); } // float frag2Value = (float)aOther.FreeSpaceTotal / (float)aOther.SizeCurrent; string frag2 = "=" + aOther.FreeSpaceTotal.ToString() + " / " + aOther.SizeCurrent.ToString(); if (aOther.SizeCurrent == 0) { frag2Value = 0.0F; frag2 = "=0"; } if (!aOther.IsDefault) { Utils.SetValue(Row, 3, Sheet, frag2); } if (aMaster.IsDefault || aOther.IsDefault) { Utils.GetRangeByColumnAndRow(Row, 1, Row, 1, Sheet).Font.Bold = true; } // Delta float delta = frag1Value - frag2Value; Utils.SetValue(Row, 4, Sheet, (delta * -1.0).ToString()); // Colourise line according to difference int colour = 0x000000; // black if (frag2Value > frag1Value) { // Original size was smaller than new size => heap has grown colour = 0x0000FF; // red } else if (frag2Value < frag1Value) { // Original size was bigger than new size => heap has shrunk colour = 0xFF0000; // blue } Utils.SetRangeFontColour(Row, 4, Row, 4, Sheet, colour); // NextRow(); }
public override void Compare(CSVThread aMaster, CSVThread aOther) { // Set thread and make bold if one of the entries is just a default // i.e. blank placeholder (occurs when a thread doesn't exist in one or // other comparsion lists) Range threadName = Utils.SetValue(Row, 1, Sheet, aMaster.FullName); if (aMaster.IsDefault || aOther.IsDefault) { Utils.GetRangeByColumnAndRow(Row, 1, Row, 1, Sheet).Font.Bold = true; } if (aMaster.IsSharedHeap) { long chunkHandle = aMaster.ChunkHandle; Color backColour = ColourForChunkHandle(chunkHandle); threadName.Interior.Color = backColour.ToArgb(); // Check text will be legible Color foreColour = Color.Black; float lum = backColour.GetBrightness(); if (lum < 0.5) { foreColour = Color.White; } threadName.Font.Color = foreColour.ToArgb(); } // Column 2 -> Column 4 ====> Heap size comparsion CreateComparsion(2, aMaster, aOther, aMaster.SizeCurrent, aOther.SizeCurrent, -1); // Column 5 is a spacer // Column 6 -> Column 8 ====> Free space comparsion CreateComparsion(6, aMaster, aOther, aMaster.FreeSpaceTotal, aOther.FreeSpaceTotal, 1); // Column 9 is a spacer // Column 10 -> Column 12 ====> Alloc space comparsion CreateComparsion(10, aMaster, aOther, aMaster.AllocSpaceTotal, aOther.AllocSpaceTotal, -1); // Column 13 is a spacer // Max heap size is the same for both Utils.SetValue(Row, 14, Sheet, aOther.SizeMax.ToString()); // Next comes the free cell size NextRow(); }
public override void Compare(CSVThread aMaster, CSVThread aOther) { Utils.SetValue(Row, 1, Sheet, aMaster.FullName); // if (aMaster.IsDefault || aOther.IsDefault) { Utils.GetRangeByColumnAndRow(Row, 1, Row, 1, Sheet).Font.Bold = true; } // CompareAndWriteItems(aMaster, aMaster.FreeCellLargest, aOther, aOther.FreeCellLargest, 2, 0xFF0000, 0x0000FF); CompareAndWriteItems(aMaster, aMaster.AllocCellLargest, aOther, aOther.AllocCellLargest, 6, 0x0000FF, 0xFF0000); // NextRow(); }
private void CreateComparsion(int aStartCol, CSVThread aMaster, CSVThread aOther, long aMasterVal, long aOtherVal, int aMultiplier) { if (!aMaster.IsDefault) { Utils.SetValue(Row, aStartCol, Sheet, aMasterVal.ToString()); } if (!aOther.IsDefault) { Utils.SetValue(Row, aStartCol + 1, Sheet, aOtherVal.ToString()); } // Delta long delta = 0; int colour = 0x000000; // black if (aMultiplier < 0) { delta = aMasterVal - aOtherVal; if (delta < 0) { // Original size was smaller than new size => heap has grown colour = 0x0000FF; // red } else if (delta > 0) { // Original size was bigger than new size => heap has shrunk colour = 0xFF0000; // blue } } else if (aMultiplier > 0) { delta = (aMasterVal - aOtherVal) * -1; if (delta < 0) { // Original size was smaller than new size => heap has grown colour = 0x0000FF; // red } else if (delta > 0) { // Original size was bigger than new size => heap has shrunk colour = 0xFF0000; // blue } } Utils.SetValue(Row, aStartCol + 2, Sheet, (delta * aMultiplier).ToString()); Utils.SetRangeFontColour(Row, aStartCol + 2, Row, aStartCol + 2, Sheet, colour); }
public CSVThread ParseLine(string aLine) { if (!TryToParseEntry(aLine)) { if (!TryToParseTimestamp(aLine)) { TryToParseSupportedTags(aLine); } } // Return a constructed entry (or null) if we have one ready CSVThread ret = iConstructedEntry; iConstructedEntry = null; return(ret); }
public override void Compare(CSVThread aMaster, CSVThread aOther) { Utils.SetValue(Row, 1, Sheet, aMaster.FullName); if (!aMaster.IsDefault) { Utils.SetValue(Row, 2, Sheet, aMaster.FreeSpaceSlack.ToString()); } if (!aOther.IsDefault) { Utils.SetValue(Row, 3, Sheet, aOther.FreeSpaceSlack.ToString()); } // if (aMaster.IsDefault || aOther.IsDefault) { Utils.GetRangeByColumnAndRow(Row, 1, Row, 1, Sheet).Font.Bold = true; } long delta = aMaster.FreeSpaceSlack - aOther.FreeSpaceSlack; Utils.SetValue(Row, 4, Sheet, (delta * -1).ToString()); // Colourise line according to difference int colour = 0x000000; // black if (aOther.FreeSpaceSlack > aMaster.FreeSpaceSlack) { colour = 0x0000FF; // red } else if (aOther.FreeSpaceSlack < aMaster.FreeSpaceSlack) { colour = 0xFF0000; // blue } Utils.SetRangeFontColour(Row, 4, Row, 4, Sheet, colour); // NextRow(); }
static void Main() { serializer = new RestSharp.Serialization.Json.JsonSerializer(); var connection = new ConnectionBuilder() .WithLogging() .Build(); // expects a request named "greeting" with a string argument and returns a string connection.On <string, string>("login", data => { /** * client_id * client_secret * username * password * path to file * login url * **/ string[] args = JsonConvert.DeserializeObject <string[]>(data); ////check number of arguments passed to applicaiton if (args.Length < 6) { ////Console.WriteLine("You dind't pass all necessary parameters"); throw new ArgumentException(Help()); } String Username = args[0]; String Password = args[1]; String ClientID = args[2]; String ClientSecret = args[3]; String LoginUrl = args[4]; csv = args[5]; //create necessary directories SetupDirs(); if (!File.Exists(csv)) { throw new FileNotFoundException("The file was not found!", csv); } Logger = new FileLogger("logs"); SFDC = new Salesforce.Salesforce(ClientID, ClientSecret, Username, Password, LoginUrl, Logger); SFDC.Login(); parser = new CSVThread(csv, Logger, SFDC); return($"Logged to salesforce instance: {SFDC.InstanceUrl}"); }); connection.On <string, string>("initialize", data => { /** * token * instance_url * file_path **/ string[] args = JsonConvert.DeserializeObject <string[]>(data); //check number of arguments passed to applicaiton if (args.Length < 3) { throw new ArgumentException("Caramba, not enough parameters"); } String Token = args[0]; String InstanceUrl = args[1]; String CSV = args[2]; if (!File.Exists(CSV)) { throw new FileNotFoundException("The file was not found!", CSV); } SetupDirs(); Logger = new FileLogger("logs"); SFDC = new Salesforce.Salesforce(Token, InstanceUrl, Logger); parser = new CSVThread(CSV, Logger, SFDC); return($"Logged to salesforce instance: {SFDC.InstanceUrl}"); }); connection.On <string>("getSFDCObjects", () => { List <Sobject> sobjects = SFDC.RetrieveObjects(); return(serializer.Serialize(sobjects)); }); connection.On <string>("getHeaderRow", () => { return(serializer.Serialize(parser.Header.Values.ToList())); }); connection.On <string, string>("getMetadata", fields => { string[] args = JsonConvert.DeserializeObject <string[]>(fields); foreach (string name in args) { SFDC.RetrieveMetadata(name); } Dictionary <String, List <string> > data = SFDC.getMetadata(); return(serializer.Serialize(data)); }); connection.On <string, string>("parse", mapping => { SFDC.SetMapping(mapping, parser.Header); parser.Parse(); return("{\"x\":" + Salesforce.Salesforce.BatchSize + "}"); }); connection.On <string>("getStatus", () => { bool ready = parser.IsReady(); Dictionary <string, string> response = new Dictionary <string, string>(); //Boolean x = false; //response.Add("isReady", x.ToString()); //response.Add("all", "100"); //response.Add("error", "10"); //response.Add("success", "90"); response.Add("isReady", ready.ToString()); response.Add("all", parser.Size.ToString()); response.Add("processed", parser.Processed.ToString()); return(serializer.Serialize(response)); }); connection.On <string>("saveLogs", () => { Logger.Save(); return("{}"); }); // wait for incoming requests connection.Listen(); }
static void Main(string[] args) { /** * client_id * client_secret * username * password * path to file * login url * **/ //check number of arguments passed to applicaiton if (args.Length < 6) { Console.WriteLine("You dind't pass all necessary parameters"); Help(); } Console.WriteLine("Ok, let's rock!"); //create necessary directories if (!Directory.Exists("results")) { Directory.CreateDirectory("results"); } if (!Directory.Exists("tmp")) { Directory.CreateDirectory("tmp"); } if (!Directory.Exists("logs")) { Directory.CreateDirectory("logs"); } String ClientID = args[0]; String ClientSecret = args[1]; String Username = args[2]; String Password = args[3]; String csv = args[4]; String LoginUrl = args[5]; if (!File.Exists(csv)) { throw new FileNotFoundException("The file was not found!", csv); } Console.WriteLine("Create logs..."); FileLogger Logger = new FileLogger("logs"); Salesforce.Salesforce SFDC = new Salesforce.Salesforce(ClientID, ClientSecret, Username, Password, LoginUrl, Logger); Console.WriteLine("Parsing file \"{0}\" started...", csv); CSVThread parser = new CSVThread(csv, Logger, SFDC); parser.Parse(); Logger.Save(); //Console.WriteLine("XXX {0}", parser.RowsParsed); //Dictionary<string, List<string>> fields = parser.GetHeader(); //foreach (KeyValuePair<string, List<string>> entry in fields) //{ // Console.WriteLine("Object [{0}]: ", entry.Key); // foreach (string field in entry.Value) { // Console.WriteLine("field: {0}", field); // } //} //foreach (KeyValuePair<string, List<string>> entry in parser.Relations) //{ // Console.WriteLine("Rel [{0}]: ", entry.Key); // foreach (string field in entry.Value) // { // Console.WriteLine("obj: {0}", field); // } //} //get metadada from saleforce based on header //parse file labels/header -> class //prepare threads and copy file -> class //login salesforce -> salesfore class //get metadata of objects in salesforce -> sfdc class //parse file in threads -> class //store logs -> class }
public abstract void Compare(CSVThread aOther, CSVThread aMaster);