예제 #1
0
        /// <summary>
        /// Initialize.
        /// </summary>
        public static void Initialize
        (
            [CanBeNull] AbstractOutput output
        )
        {
            Output = output;

            Configuration = JObject.Parse
                            (
                File.ReadAllText("osmi.json")
                            );

            ConnectionString = CM.AppSettings["connectionString"];

            string baseUri = CM.AppSettings["baseUri"];
            string apiId   = CM.AppSettings["apiID"];
            string apiKey  = CM.AppSettings["apiKey"];

//            try
//            {
            Client = new OsmiCardsClient
                     (
                baseUri,
                apiId,
                apiKey
                     );

            TemplateName = CM.AppSettings["template"];
            WriteLine("Reading OSMI template: {0}", TemplateName);
            Template = Client.GetTemplateInfo(TemplateName);
//            }
//            catch (Exception inner)
//            {
//                Encoding encoding = Encoding.UTF8;
//                ArsMagnaException outer = new ArsMagnaException("OSMI error", inner);
//                outer.Attach(new BinaryAttachment("baseUri", encoding.GetBytes(baseUri)));
//                outer.Attach(new BinaryAttachment("apiId", encoding.GetBytes(apiId)));
//                outer.Attach(new BinaryAttachment("apiKey", encoding.GetBytes(apiKey)));
//
//                throw outer;
//            }
        }
예제 #2
0
        static void Main()
        {
            Console.WriteLine(new string('=', 80));
            Console.WriteLine("Start: {0}", DateTime.Now);
            deadline = DateTime.Today.AddDays(-1.0);

            try
            {
                string baseUri          = CM.AppSettings["baseUri"];
                string apiID            = CM.AppSettings["apiID"];
                string apiKey           = CM.AppSettings["apiKey"];
                string connectionString = CM.AppSettings["connectionString"];
                string messageText      = CM.AppSettings["message"];

                client = new OsmiCardsClient
                         (
                    baseUri,
                    apiID,
                    apiKey
                         );

                Console.WriteLine("PING:");
                JObject ping = client.Ping();
                Console.WriteLine(ping);

                string[] cards = client.GetCardList();
                Console.Write("CARDS: {0}", cards.Length);

                List <string> recipients = new List <string>();
                using (connection = new IrbisConnection(connectionString))
                {
                    IEnumerable <MarcRecord> batch = BatchRecordReader.Search
                                                     (
                        connection,
                        "RDR",
                        "RB=$",
                        1000
                                                     );

                    foreach (MarcRecord record in batch)
                    {
                        ReaderInfo reader = ReaderInfo.Parse(record);
                        string     ticket = reader.Ticket;
                        if (!ticket.OneOf(cards))
                        {
                            continue;
                        }
                        VisitInfo[] outdated = reader.Visits
                                               .Where(v => !v.IsVisit)
                                               .Where(v => !v.IsReturned)
                                               .Where(v => v.DateExpected < deadline)
                                               .ToArray();
                        if (outdated.Length != 0)
                        {
                            Console.WriteLine
                            (
                                "[{0}] {1}: {2} book(s)",
                                reader.Ticket,
                                reader.FullName,
                                outdated.Length
                            );
                            recipients.Add(reader.Ticket);
                        }
                    }
                }

                Console.WriteLine();
                Console.WriteLine("Total recipient(s): {0}", recipients.Count);

                if (recipients.Count != 0)
                {
                    client.SendPushMessage
                    (
                        recipients.ToArray(),
                        messageText
                    );
                    Console.WriteLine("Send OK");
                }

                Console.WriteLine("Finish: {0}", DateTime.Now);
                Console.WriteLine(new string('=', 80));
                Console.WriteLine();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
예제 #3
0
        static void Main()
        {
            try
            {
                string          baseUri = CM.AppSettings["baseUri"];
                string          apiID   = CM.AppSettings["apiID"];
                string          apiKey  = CM.AppSettings["apiKey"];
                OsmiCardsClient client  = new OsmiCardsClient
                                          (
                    baseUri,
                    apiID,
                    apiKey
                                          );

                Console.WriteLine("PING:");
                JObject ping = client.Ping();
                Console.WriteLine(ping);

                Console.WriteLine();
                Console.WriteLine("DEFAULTS:");
                JObject defaults = client.GetDefaults();
                Console.WriteLine(defaults);

                Console.WriteLine();
                Console.WriteLine("TEMPLATE LIST:");
                string[] templates = client.GetTemplateList();
                Console.WriteLine
                (
                    StringUtility.Join
                    (
                        ", ",
                        templates
                    )
                );

                Console.WriteLine();
                Console.WriteLine("TEMPLATE INFO:");
                JObject chb = client.GetTemplateInfo("chb");
                Console.WriteLine(chb);

                Console.WriteLine();
                Console.WriteLine("CARD LIST:");
                string[] cards = client.GetCardList();
                Console.WriteLine
                (
                    StringUtility.Join
                    (
                        ", ",
                        cards
                    )
                );

                Console.WriteLine();
                Console.WriteLine("CARD INFO:");
                OsmiCard card = client.GetCardInfo("4433AD69");
                Console.WriteLine(card);

                Console.WriteLine();
                Console.WriteLine("GET CARD LINK:");
                string link = client.GetCardLink("4433AD69");
                Console.WriteLine(link);

                Console.WriteLine();
                Console.WriteLine("GET IMAGES");
                OsmiImage[] images = client.GetImages();
                Console.WriteLine
                (
                    StringUtility.Join
                    (
                        ", ",
                        images
                    )
                );
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }