예제 #1
0
        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("———————————————————————————————");
            }
        }
예제 #2
0
        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");
        }
예제 #3
0
        /// <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);
                }
            }
        }
예제 #4
0
        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]);
        }
예제 #5
0
        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))));
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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();
            }
        }
예제 #8
0
        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);
                }
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
        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();
                }
            }
        }
예제 #11
0
        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);
                }
            }
        }