public static void ShowActualAlerts(this CropioApi cropio, Int32 recordsPerPage = 200) { MassResponse <Int32> alertTypesIds = cropio.GetObjectsIds <CO_AlertType>(); if (alertTypesIds.Data == null) { Console.WriteLine("Identifiers not found"); return; } MassResponse <CO_AlertType> alertTypes = cropio.GetObjects <CO_AlertType>(alertTypesIds.Data); HashSet <Int32> valuableAlertTypesIds = new HashSet <int> (alertTypes.Data.Where(x => x.AdditionalInfo.Contains("[#Run in ELMA]")).Select(x => x.Id)); List <CO_Alert> activeAlerts = new List <CO_Alert>(); MassResponse <Int32> alertsIds = cropio.GetObjectsIds <CO_Alert>(); if (alertsIds.Data == null) { Console.WriteLine("Identifiers not found"); return; } foreach (var idsPage in alertsIds.Data.Paginate(recordsPerPage)) { MassResponse <CO_Alert> objs = cropio.GetObjects <CO_Alert>(idsPage); activeAlerts.AddRange(objs.Data.Where(x => x.Status != CE_StatusOfAllert.Closed && valuableAlertTypesIds.Contains(x.Id_AlertType))); } foreach (CO_Alert alert in activeAlerts) { Console.WriteLine(alert); Console.WriteLine("———————————————————————————————"); } }
public static void ShowAllObjectTypes(this CropioApi cropio) { MassResponse <Int32> ids = cropio.GetObjectsIds <CO_Version>(); HashSet <String> typeNames = new HashSet <String>(); Int32 itemNo = 0; foreach (IEnumerable <Int32> page in ids.Data.Paginate(1000)) { MassResponse <CO_Version> objects = cropio.GetObjects <CO_Version>(page); if (!objects.CropioResponse.IsSuccess) { continue; } foreach (CO_Version obj in objects.Data) { if (typeNames.Contains(obj.ItemType)) { continue; } typeNames.Add(obj.ItemType); Console.Write("\n{0:00} {1,-100} ", ++itemNo, obj.ItemType); } Console.Write("."); } Console.WriteLine("Finished"); }
/// <summary> Сохранить докумен, прикрепленный к тревоге </summary> public static void SaveAlertRelatedDocuments(Int32 idAlertWithDocument = 498) { CropioApi cropio = GetCropioClient(); // String fileFullName = ""; //Int32 idAlertWithoutoDcuments = 507; MassResponse <CO_Document> doc = cropio.ObjRelatedDocument <CO_Alert>(idAlertWithDocument); //Console.WriteLine(doc); if (doc.Data.Count == 0) { return; } foreach (CO_Document document in doc.Data) { //Console.WriteLine(document.DocumentUrl); Console.WriteLine(Path.GetFileName(Uri.UnescapeDataString(document.DocumentUrl))); if (!String.IsNullOrWhiteSpace(fileFullName)) { Byte[] fileBody = cropio.DownloadDocumentFile(document.Id); File.WriteAllBytes(fileFullName, fileBody); } } }
public static void ShowItemNo <T>(this CropioApi cropio, Int32 itemNo) where T : ICropioRegularObject { MassResponse <Int32> ids = cropio.GetObjectsIds <T>(); if (ids.Data == null) { Console.WriteLine("Data == null"); return; } cropio.ShowObject <T>(ids.Data[itemNo]); }
public static void ShowIds <T>(this CropioApi cropio) where T : ICropioRegularObject { Console.WriteLine(CropioDataModel.Name <T>()); MassResponse <Int32> ids = cropio.GetObjectsIds <T>(); if (ids.Data == null) { Console.WriteLine("Data == null"); return; } Console.WriteLine(String.Join(", ", ids.Data.Select(x => x.ToString().PadLeft(8)))); }
public static void ShowObjects <T>(this CropioApi cropio, params Int32[] objIds) where T : ICropioRegularObject { MassResponse <T> result = cropio.GetObjects <T>(objIds); if (result.Data == null) { Console.WriteLine("Data == null"); return; } foreach (T obj in result.Data) { Console.WriteLine("\n\n————— {0,6} ({1}) ——————————————————————————————————————", obj.Id, CropioDataModel.Name <T>()); Console.WriteLine(obj); } }
public static void ShowAllObjects_Slowly <T>(this CropioApi cropio, Boolean showNextItemAutomated = false) where T : ICropioRegularObject { MassResponse <Int32> ids = cropio.GetObjectsIds <T>(); if (ids.Data == null) { Console.WriteLine("Identifiers not found"); return; } foreach (Int32 id in ids.Data) { Response <T> resp = cropio.GetObject <T>(id); Console.WriteLine(resp.Data); if (showNextItemAutomated) { continue; } Console.ReadKey(); Console.Clear(); } }
public static void ShowHistoryInventoryItemTypes(this CropioApi cropio) { Console.WriteLine("Получение идентификаторов для для таблицы CO_History_InventoryItem"); IEnumerable <IEnumerable <Int32> > ids = cropio.GetObjectsIds <CO_History_InventoryItem>().Data.Paginate(500); HashSet <CE_HistoryableType> historyableTypes = new HashSet <CE_HistoryableType>(); Int32 itemNo = 0; foreach (IEnumerable <Int32> page in ids) { MassResponse <CO_History_InventoryItem> objects = cropio.GetObjects <CO_History_InventoryItem>(page); foreach (CO_History_InventoryItem obj in objects.Data) { if (historyableTypes.Contains(obj.HistoryableType)) { continue; } historyableTypes.Add(obj.HistoryableType); Console.WriteLine("{0, 4} {1}", itemNo, obj.HistoryableType); } } }
public static HashSet <T2> GetUniqueValues <T, T2>(this CropioApi cropio, Func <T, T2> selector) where T : ICropioRegularObject { HashSet <T2> uniqueValues = new HashSet <T2>(); const Int32 recordsPerPage = 200; MassResponse <Int32> ids = cropio.GetObjectsIds <T>(); if (ids.Data == null) { Console.WriteLine("Identifiers not found"); return(uniqueValues); } // foreach (var page in ids.Data.Paginate(recordsPerPage)) { MassResponse <T> objects = cropio.GetObjects <T>(page); IEnumerable <T2> values = objects.Data.DistinctValues(selector); foreach (T2 value in values) { uniqueValues.Add(value); } } return(uniqueValues); }
public static void ShowAllObjects <T>(this CropioApi cropio, Boolean showNextItemAutomated = false) where T : ICropioRegularObject { const Int32 recordsPerPage = 200; MassResponse <Int32> ids = cropio.GetObjectsIds <T>(); if (ids.Data == null) { Console.WriteLine("Identifiers not found"); return; } Int32 pagesCount = (Int32)Math.Ceiling((Double)ids.Data.Count / (Double)recordsPerPage); Int32 recordNo = 0; for (Int32 pageNumber = 0; pageNumber < pagesCount; pageNumber++) { Int32 startIndex = pageNumber * recordsPerPage; Int32 recordsCount = (startIndex + recordsPerPage) < ids.Data.Count ? recordsPerPage : ids.Data.Count - startIndex; List <Int32> idsSubSet = ids.Data.GetRange(startIndex, recordsCount); // MassResponse <T> result = cropio.GetObjects <T>(idsSubSet); if (result.Data == null) { Console.WriteLine("Data == null"); break; } foreach (T obj in result.Data) { Console.WriteLine("\n─────{0}───────────────────────────────────────────────────────", (recordNo++).ToString().PadLeft(10, '─')); Console.WriteLine(obj); if (showNextItemAutomated) { continue; } Console.ReadKey(); Console.Clear(); } } }
public static void ShowAllObjectsOlderThan <T>(this CropioApi cropio, DateTime time) where T : ICropioRegularObject { MassResponse_Changes res = cropio.GetChangedObjectsIds <T>(time); if (!res.CropioResponse.IsSuccess) { Console.WriteLine("error"); return; } Int32 recordNo = 0; foreach (var page in res.Data.Select(x => x.Id).Paginate(200)) { MassResponse <T> ret = cropio.GetObjects <T>(page); if (!ret.CropioResponse.IsSuccess) { Console.WriteLine("error"); return; } foreach (var obj in ret.Data) { Console.WriteLine("\n─────{0}───────────────────────────────────────────────────────", (recordNo++).ToString().PadLeft(10, '─')); Console.WriteLine(obj); } } }