示例#1
0
        protected override void OnReceive(object message)
        {
            switch (message)
            {
            case Sync_Document_Message sync_document_message:


                var sync_document = new mmria.server.util.c_sync_document(sync_document_message.document_id, sync_document_message.document_json, sync_document_message.method);

                try
                {
                    sync_document.executeAsync().Wait();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Synchronize_Case exception: {ex}");
                }

                break;

            case Sync_All_Documents_Message sync_all_documents_message:

                mmria.server.util.c_document_sync_all sync_all = new mmria.server.util.c_document_sync_all(
                    Program.config_couchdb_url,
                    Program.config_timer_user_name,
                    Program.config_timer_password
                    );

                sync_all.executeAsync().Wait();

                break;
            }
        }
示例#2
0
        public virtual Task Execute(IJobExecutionContext context)
        {
            //Common.Logging.ILog log = Common.Logging.LogManager.GetCurrentClassLogger();
            //log.Debug("IJob.Execute");

            JobKey jobKey = context.JobDetail.Key;

            //log.DebugFormat("iCIMS_Data_Call_Job says: Starting {0} executing at {1}", jobKey, DateTime.Now.ToString("r"));
            mmria.server.model.couchdb.c_change_result latest_change_set = GetJobInfo(Program.Last_Change_Sequence);

            Dictionary <string, KeyValuePair <string, bool> > response_results = new Dictionary <string, KeyValuePair <string, bool> > (StringComparer.OrdinalIgnoreCase);

            if (Program.Last_Change_Sequence != latest_change_set.last_seq)
            {
                foreach (mmria.server.model.couchdb.c_seq seq in latest_change_set.results)
                {
                    if (response_results.ContainsKey(seq.id))
                    {
                        if
                        (
                            seq.changes.Count > 0 &&
                            response_results [seq.id].Key != seq.changes [0].rev
                        )
                        {
                            if (seq.deleted == null)
                            {
                                response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, false);
                            }
                            else
                            {
                                response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, true);
                            }
                        }
                    }
                    else
                    {
                        if (seq.deleted == null)
                        {
                            response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, false));
                        }
                        else
                        {
                            response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, true));
                        }
                    }
                }
            }


            if (Program.Change_Sequence_Call_Count < int.MaxValue)
            {
                Program.Change_Sequence_Call_Count++;
            }

            if (Program.DateOfLastChange_Sequence_Call.Count > 9)
            {
                Program.DateOfLastChange_Sequence_Call.Clear();
            }

            Program.DateOfLastChange_Sequence_Call.Add(DateTime.Now);

            Program.Last_Change_Sequence = latest_change_set.last_seq;

            foreach (KeyValuePair <string, KeyValuePair <string, bool> > kvp in response_results)
            {
                System.Threading.Tasks.Task.Run
                (
                    new Action(() =>
                {
                    if (kvp.Value.Value)
                    {
                        try
                        {
                            mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, null, "DELETE");
                            sync_document.executeAsync();
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine("Sync Delete case");
                            System.Console.WriteLine(ex);
                        }
                    }
                    else
                    {
                        string document_url  = Program.config_couchdb_url + "/mmrds/" + kvp.Key;
                        var document_curl    = new cURL("GET", null, document_url, null, Program.config_timer_user_name, Program.config_timer_password);
                        string document_json = null;

                        try
                        {
                            document_json = document_curl.execute();
                            if (!string.IsNullOrEmpty(document_json) && document_json.IndexOf("\"_id\":\"_design/") < 0)
                            {
                                mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, document_json);
                                sync_document.executeAsync();
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine("Sync PUT case");
                            System.Console.WriteLine(ex);
                        }
                    }
                })
                );
            }



            //Program.JobInfoList = GetJobInfo();

            /*
             * if (Program.NumberOfJobInfoList_Call_Count < int.MaxValue)
             * {
             * Program.NumberOfJobInfoList_Call_Count++;
             * }
             *
             * if (Program.DateOfLastJobInfoList_Call.Count >10)
             * {
             * Program.DateOfLastJobInfoList_Call.Clear();
             * }
             *
             * Program.DateOfLastJobInfoList_Call.Add(DateTime.Now);
             */

            //log.DebugFormat("iCIMS_Data_Call_Job says: finishing {0} executing at {1}", jobKey, DateTime.Now.ToString("r"));
            return(Task.CompletedTask);
        }
示例#3
0
        public virtual Task Execute(IJobExecutionContext context)
        {
            //Common.Logging.ILog log = Common.Logging.LogManager.GetCurrentClassLogger();
            //log.Debug("IJob.Execute");

            JobKey jobKey = context.JobDetail.Key;


            //if (!Program.is_processing_export_queue)
            {
                System.Threading.Tasks.Task.Run
                (
                    new Action(() =>
                {
                    //System.Console.WriteLine ("{0} Beginning Export Queue Item Processing", System.DateTime.Now);
                    try
                    {
                        Process_Export_Queue_Item();
                    }
                    catch (Exception ex)
                    {
                        // to nothing for now
                        System.Console.WriteLine("{0} check_for_changes_job.Process_Export_Queue_Item: error\n{1}", System.DateTime.Now, ex);
                    }

                    try
                    {
                        Process_Export_Queue_Delete();
                    }
                    catch (Exception ex)
                    {
                        // to nothing for now
                        System.Console.WriteLine("{0} check_for_changes_job.Process_Export_Queue_Delete: error\n{1}", System.DateTime.Now, ex);
                    }

                    //System.Console.WriteLine ("{0} Ending Export Queue Item Processing", System.DateTime.Now);
                })
                );
            }


            //if (!Program.is_processing_syncronization)
            {
                //System.Console.WriteLine ("{0} Beginning Change Synchronization.", System.DateTime.Now);
                //log.DebugFormat("iCIMS_Data_Call_Job says: Starting {0} executing at {1}", jobKey, DateTime.Now.ToString("r"));
                mmria.server.model.couchdb.c_change_result latest_change_set = get_changes(Program.Last_Change_Sequence);

                Dictionary <string, KeyValuePair <string, bool> > response_results = new Dictionary <string, KeyValuePair <string, bool> > (StringComparer.OrdinalIgnoreCase);

                if (Program.Last_Change_Sequence != latest_change_set.last_seq)
                {
                    foreach (mmria.server.model.couchdb.c_seq seq in latest_change_set.results)
                    {
                        if (response_results.ContainsKey(seq.id))
                        {
                            if (
                                seq.changes.Count > 0 &&
                                response_results [seq.id].Key != seq.changes [0].rev)
                            {
                                if (seq.deleted == null)
                                {
                                    response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, false);
                                }
                                else
                                {
                                    response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, true);
                                }
                            }
                        }
                        else
                        {
                            if (seq.deleted == null)
                            {
                                response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, false));
                            }
                            else
                            {
                                response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, true));
                            }
                        }
                    }
                }


                if (Program.Change_Sequence_Call_Count < int.MaxValue)
                {
                    Program.Change_Sequence_Call_Count++;
                }

                if (Program.DateOfLastChange_Sequence_Call.Count > 9)
                {
                    Program.DateOfLastChange_Sequence_Call.Clear();
                }

                Program.DateOfLastChange_Sequence_Call.Add(DateTime.Now);

                Program.Last_Change_Sequence = latest_change_set.last_seq;

                //List<System.Threading.Tasks.Task> TaskList = new List<System.Threading.Tasks.Task> ();

                foreach (KeyValuePair <string, KeyValuePair <string, bool> > kvp in response_results)
                {
                    System.Threading.Tasks.Task.Run
                    (
                        new Action(async() =>
                    {
                        if (kvp.Value.Value)
                        {
                            try
                            {
                                mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, null, "DELETE");
                                await sync_document.executeAsync();
                            }
                            catch (Exception ex)
                            {
                                //System.Console.WriteLine ("Sync Delete case");
                                //System.Console.WriteLine (ex);
                            }
                        }
                        else
                        {
                            string document_url  = Program.config_couchdb_url + "/mmrds/" + kvp.Key;
                            var document_curl    = new cURL("GET", null, document_url, null, Program.config_timer_user_name, Program.config_timer_password);
                            string document_json = null;

                            try
                            {
                                document_json = await document_curl.executeAsync();
                                if (!string.IsNullOrEmpty(document_json) && document_json.IndexOf("\"_id\":\"_design/") < 0)
                                {
                                    mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, document_json);
                                    await sync_document.executeAsync();
                                }
                            }
                            catch (Exception ex)
                            {
                                //System.Console.WriteLine ("Sync PUT case");
                                //System.Console.WriteLine (ex);
                            }
                        }
                    })
                    );
                }
                //System.Threading.Tasks.Task.WhenAll (TaskList);

                try
                {
                    HashSet <string> mmrds_id_set   = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    HashSet <string> de_id_set      = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    HashSet <string> report_id_set  = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    HashSet <string> deleted_id_set = null;

                    string json = null;
                    mmria.server.model.couchdb.c_all_docs all_docs = null;
                    cURL curl = null;

                    // get all non deleted cases in mmrds
                    curl     = new cURL("GET", null, Program.config_couchdb_url + "/mmrds/_all_docs", null, Program.config_timer_user_name, Program.config_timer_password);
                    json     = curl.execute();
                    all_docs = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.server.model.couchdb.c_all_docs> (json);
                    foreach (mmria.server.model.couchdb.c_all_docs_row all_doc_row in all_docs.rows)
                    {
                        mmrds_id_set.Add(all_doc_row.id);
                    }


                    // get all non deleted cases in de_id
                    curl     = new cURL("GET", null, Program.config_couchdb_url + "/de_id/_all_docs", null, Program.config_timer_user_name, Program.config_timer_password);
                    json     = curl.execute();
                    all_docs = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.server.model.couchdb.c_all_docs> (json);
                    foreach (mmria.server.model.couchdb.c_all_docs_row all_doc_row in all_docs.rows)
                    {
                        de_id_set.Add(all_doc_row.id);
                    }

                    deleted_id_set = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    deleted_id_set.Union(de_id_set.Except(mmrds_id_set));
                    foreach (string id in deleted_id_set)
                    {
                        string rev = all_docs.rows.Where(r => r.id == id).FirstOrDefault().rev.rev;
                        curl = new cURL("DELETE", null, Program.config_couchdb_url + "/de_id/" + id + "?rev=" + rev, null, Program.config_timer_user_name, Program.config_timer_password);
                        json = curl.execute();
                    }

                    // get all non deleted cases in report
                    curl     = new cURL("GET", null, Program.config_couchdb_url + "/report/_all_docs", null, Program.config_timer_user_name, Program.config_timer_password);
                    json     = curl.execute();
                    all_docs = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.server.model.couchdb.c_all_docs> (json);
                    foreach (mmria.server.model.couchdb.c_all_docs_row all_doc_row in all_docs.rows)
                    {
                        report_id_set.Add(all_doc_row.id);
                    }
                    deleted_id_set = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    deleted_id_set.Union(report_id_set.Except(mmrds_id_set));
                    foreach (string id in deleted_id_set)
                    {
                        string rev = all_docs.rows.Where(r => r.id == id).FirstOrDefault().rev.rev;
                        curl = new cURL("DELETE", null, Program.config_couchdb_url + "/report/" + id + "?rev=" + rev, null, Program.config_timer_user_name, Program.config_timer_password);
                        json = curl.execute();
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Delete sync error:\n{0}", ex);
                }

                //System.Console.WriteLine ("{0}- Ending Change Synchronization.", System.DateTime.Now);
            }

            return(Task.CompletedTask);
        }
        protected override void OnReceive(object message)
        {
            Console.WriteLine($"Process_DB_Synchronization_Set {System.DateTime.Now}");

            switch (message)
            {
            case ScheduleInfoMessage scheduleInfo:
                //System.Console.WriteLine ("{0} Beginning Change Synchronization.", System.DateTime.Now);
                //log.DebugFormat("iCIMS_Data_Call_Job says: Starting {0} executing at {1}", jobKey, DateTime.Now.ToString("r"));
                mmria.server.model.couchdb.c_change_result latest_change_set = get_changes(Program.Last_Change_Sequence, scheduleInfo);

                Dictionary <string, KeyValuePair <string, bool> > response_results = new Dictionary <string, KeyValuePair <string, bool> > (StringComparer.OrdinalIgnoreCase);

                if (Program.Last_Change_Sequence != latest_change_set.last_seq)
                {
                    foreach (mmria.server.model.couchdb.c_seq seq in latest_change_set.results)
                    {
                        if (response_results.ContainsKey(seq.id))
                        {
                            if (
                                seq.changes.Count > 0 &&
                                response_results [seq.id].Key != seq.changes [0].rev)
                            {
                                if (seq.deleted == null)
                                {
                                    response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, false);
                                }
                                else
                                {
                                    response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, true);
                                }
                            }
                        }
                        else
                        {
                            if (seq.deleted == null)
                            {
                                response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, false));
                            }
                            else
                            {
                                response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, true));
                            }
                        }
                    }
                }


                if (Program.Change_Sequence_Call_Count < int.MaxValue)
                {
                    Program.Change_Sequence_Call_Count++;
                }

                if (Program.DateOfLastChange_Sequence_Call.Count > 9)
                {
                    Program.DateOfLastChange_Sequence_Call.Clear();
                }

                Program.DateOfLastChange_Sequence_Call.Add(DateTime.Now);

                Program.Last_Change_Sequence = latest_change_set.last_seq;

                //List<System.Threading.Tasks.Task> TaskList = new List<System.Threading.Tasks.Task> ();

                foreach (KeyValuePair <string, KeyValuePair <string, bool> > kvp in response_results)
                {
                    System.Threading.Tasks.Task.Run
                    (
                        new Action(async() =>
                    {
                        if (kvp.Value.Value)
                        {
                            try
                            {
                                mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, null, "DELETE");
                                await sync_document.executeAsync();
                            }
                            catch (Exception ex)
                            {
                                //System.Console.WriteLine ("Sync Delete case");
                                //System.Console.WriteLine (ex);
                            }
                        }
                        else
                        {
                            string document_url  = Program.config_couchdb_url + "/mmrds/" + kvp.Key;
                            var document_curl    = new cURL("GET", null, document_url, null, Program.config_timer_user_name, Program.config_timer_password);
                            string document_json = null;

                            try
                            {
                                document_json = await document_curl.executeAsync();
                                if (!string.IsNullOrEmpty(document_json) && document_json.IndexOf("\"_id\":\"_design/") < 0)
                                {
                                    mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, document_json);
                                    await sync_document.executeAsync();
                                }
                            }
                            catch (Exception ex)
                            {
                                //System.Console.WriteLine ("Sync PUT case");
                                //System.Console.WriteLine (ex);
                            }
                        }
                    })
                    );
                }
                //System.Threading.Tasks.Task.WhenAll (TaskList);

                try
                {
                    HashSet <string> mmrds_id_set   = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    HashSet <string> de_id_set      = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    HashSet <string> report_id_set  = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    HashSet <string> deleted_id_set = null;

                    string json = null;
                    mmria.server.model.couchdb.c_all_docs all_docs = null;
                    cURL curl = null;

                    // get all non deleted cases in mmrds
                    curl     = new cURL("GET", null, Program.config_couchdb_url + "/mmrds/_all_docs", null, Program.config_timer_user_name, Program.config_timer_password);
                    json     = curl.execute();
                    all_docs = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.server.model.couchdb.c_all_docs> (json);
                    foreach (mmria.server.model.couchdb.c_all_docs_row all_doc_row in all_docs.rows)
                    {
                        mmrds_id_set.Add(all_doc_row.id);
                    }


                    // get all non deleted cases in de_id
                    curl     = new cURL("GET", null, Program.config_couchdb_url + "/de_id/_all_docs", null, Program.config_timer_user_name, Program.config_timer_password);
                    json     = curl.execute();
                    all_docs = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.server.model.couchdb.c_all_docs> (json);
                    foreach (mmria.server.model.couchdb.c_all_docs_row all_doc_row in all_docs.rows)
                    {
                        de_id_set.Add(all_doc_row.id);
                    }

                    deleted_id_set = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    deleted_id_set.Union(de_id_set.Except(mmrds_id_set));
                    foreach (string id in deleted_id_set)
                    {
                        string rev = all_docs.rows.Where(r => r.id == id).FirstOrDefault().rev.rev;
                        curl = new cURL("DELETE", null, Program.config_couchdb_url + "/de_id/" + id + "?rev=" + rev, null, Program.config_timer_user_name, Program.config_timer_password);
                        json = curl.execute();
                    }

                    // get all non deleted cases in report
                    curl     = new cURL("GET", null, Program.config_couchdb_url + "/report/_all_docs", null, Program.config_timer_user_name, Program.config_timer_password);
                    json     = curl.execute();
                    all_docs = Newtonsoft.Json.JsonConvert.DeserializeObject <mmria.server.model.couchdb.c_all_docs> (json);
                    foreach (mmria.server.model.couchdb.c_all_docs_row all_doc_row in all_docs.rows)
                    {
                        report_id_set.Add(all_doc_row.id);
                    }
                    deleted_id_set = new HashSet <string> (StringComparer.OrdinalIgnoreCase);
                    deleted_id_set.Union(report_id_set.Except(mmrds_id_set));
                    foreach (string id in deleted_id_set)
                    {
                        string rev = all_docs.rows.Where(r => r.id == id).FirstOrDefault().rev.rev;
                        curl = new cURL("DELETE", null, Program.config_couchdb_url + "/report/" + id + "?rev=" + rev, null, Program.config_timer_user_name, Program.config_timer_password);
                        json = curl.execute();
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Delete sync error:\n{0}", ex);
                }

                //System.Console.WriteLine ("{0}- Ending Change Synchronization.", System.DateTime.Now);
                break;
            }
        }
        protected override void OnReceive(object message)
        {
            Console.WriteLine($"Synchronize_Deleted_Case_Records Baby {System.DateTime.Now}");


            switch (message)
            {
            case ScheduleInfoMessage scheduleInfo:
                mmria.server.model.couchdb.c_change_result latest_change_set = GetJobInfo(Program.Last_Change_Sequence, scheduleInfo);

                Dictionary <string, KeyValuePair <string, bool> > response_results = new Dictionary <string, KeyValuePair <string, bool> > (StringComparer.OrdinalIgnoreCase);

                if (Program.Last_Change_Sequence != latest_change_set.last_seq)
                {
                    foreach (mmria.server.model.couchdb.c_seq seq in latest_change_set.results)
                    {
                        if (response_results.ContainsKey(seq.id))
                        {
                            if
                            (
                                seq.changes.Count > 0 &&
                                response_results [seq.id].Key != seq.changes [0].rev
                            )
                            {
                                if (seq.deleted == null)
                                {
                                    response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, false);
                                }
                                else
                                {
                                    response_results [seq.id] = new KeyValuePair <string, bool> (seq.changes [0].rev, true);
                                }
                            }
                        }
                        else
                        {
                            if (seq.deleted == null)
                            {
                                response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, false));
                            }
                            else
                            {
                                response_results.Add(seq.id, new KeyValuePair <string, bool> (seq.changes [0].rev, true));
                            }
                        }
                    }
                }


                if (Program.Change_Sequence_Call_Count < int.MaxValue)
                {
                    Program.Change_Sequence_Call_Count++;
                }

                if (Program.DateOfLastChange_Sequence_Call.Count > 9)
                {
                    Program.DateOfLastChange_Sequence_Call.Clear();
                }

                Program.DateOfLastChange_Sequence_Call.Add(DateTime.Now);

                Program.Last_Change_Sequence = latest_change_set.last_seq;

                foreach (KeyValuePair <string, KeyValuePair <string, bool> > kvp in response_results)
                {
                    System.Threading.Tasks.Task.Run
                    (
                        new Action(async() =>
                    {
                        if (kvp.Value.Value)
                        {
                            try
                            {
                                mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, null, "DELETE");
                                await sync_document.executeAsync();
                            }
                            catch (Exception ex)
                            {
                                System.Console.WriteLine("Sync Delete case");
                                System.Console.WriteLine(ex);
                            }
                        }
                        else
                        {
                            string document_url  = Program.config_couchdb_url + "/mmrds/" + kvp.Key;
                            var document_curl    = new cURL("GET", null, document_url, null, Program.config_timer_user_name, Program.config_timer_password);
                            string document_json = null;

                            try
                            {
                                document_json = document_curl.execute();
                                if (!string.IsNullOrEmpty(document_json) && document_json.IndexOf("\"_id\":\"_design/") < 0)
                                {
                                    mmria.server.util.c_sync_document sync_document = new mmria.server.util.c_sync_document(kvp.Key, document_json);
                                    await sync_document.executeAsync();
                                }
                            }
                            catch (Exception ex)
                            {
                                System.Console.WriteLine("Sync PUT case");
                                System.Console.WriteLine(ex);
                            }
                        }
                    })
                    );
                }

                break;
            }
        }