/// <summary>
        /// a bit of Linq magic to find the organization id for a particular state
        /// from the jurisdictions response data.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public string FindJurisdictionId(Newtonsoft.Json.Linq.JArray array, string state)
        {
            Newtonsoft.Json.Linq.JObject jo2 = array.Children <Newtonsoft.Json.Linq.JObject>()
                                               .FirstOrDefault(o => o["node"]["name"].ToString() != null && o["node"]["name"].ToString() == state);

            string StateOrg = jo2["node"]["id"].ToString();

            return(StateOrg);
        }
Пример #2
0
        public static String getNewAdvert()
        {
            string errDesc      = "";
            string htmlResponse = "";

            try
            {
                Web WebResponse = new Web(45000, 2, "");
                htmlResponse = WebResponse.GetURL("/terminal/general/get-advert");
                WebResponse  = null;

                if (htmlResponse != "")
                {
                    Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(htmlResponse);

                    if (!String.IsNullOrEmpty((string)json["err"]))
                    {
                        errDesc = (string)json["err"];
                    }
                    else
                    {
                        globalSettings.advert_id   = (string)json["ad_id"];
                        globalSettings.advert_data = (string)json["ad_data"];

                        globalSettings.SaveAdvert();

                        Newtonsoft.Json.Linq.JArray a = (Newtonsoft.Json.Linq.JArray)json["images"];

                        foreach (var item in a.Children())
                        {
                            byte[] data = Convert.FromBase64String(item["img_data"].ToString().Replace("\"", ""));
                            Util.WriteAllBytes(globalSettings.app_path + @"\ads\" + item["img_name"].ToString().Replace("\"", ""), data);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errDesc = e.Message;
            }

            return(errDesc);
        }
Пример #3
0
        public async Task <List <JObject> > acquireAllChildren(string path)
        {
            int ipage = 1;

            Newtonsoft.Json.Linq.JArray listOb = null;
            int onePageSize = 20;
            var list        = new List <JObject>();

            do
            {
                var result = await acquireChildren_byPage(path, ipage, onePageSize);

                listOb = result["list"].ToObject <Newtonsoft.Json.Linq.JArray>();
                foreach (var o in listOb.Children <JObject>())
                {
                    list.Add(o);
                }
            } while (listOb.Count == onePageSize);
            return(list);
        }
Пример #4
0
        public DataTable DBQuery(string Query)
        {
            collectionName = GetCollectionName(Query);
            var           DB         = mMongoClient.GetDatabase(DbName);
            DataTable     dt         = new DataTable();
            var           collection = DB.GetCollection <BsonDocument>(collectionName);
            List <object> list       = new List <object>();

            if (Query.Contains("insertMany"))
            {
                string queryParam = GetUpdateQueryParams(Query).ToString();
                Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.Linq.JArray.Parse(queryParam);
                List <BsonDocument>         documents = new List <BsonDocument>();
                foreach (Newtonsoft.Json.Linq.JObject obj in jsonArray.Children <Newtonsoft.Json.Linq.JObject>())
                {
                    BsonDocument document = BsonDocument.Parse(obj.ToString());
                    documents.Add(document);
                }
                collection.InsertMany(documents);
            }
            else if (Query.Contains("insertOne") || Query.Contains("insert"))
            {
                BsonDocument insertDocumnet = BsonDocument.Parse(GetUpdateQueryParams(Query));
                collection.InsertOne(insertDocumnet);
            }
            else
            {
                var result = collection.Find(GetQueryParamater(Query, "find")).
                             Project(Builders <BsonDocument> .Projection.Exclude("_id").Exclude(GetQueryParamater(Query, "projection"))).
                             Sort(BsonDocument.Parse(GetQueryParamater(Query, "sort"))).
                             Limit(Convert.ToInt32(GetQueryParamater(Query, "limit"))).
                             ToList();

                var json = result.ToJson();
                dt = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));

                //Act.ParseJSONToOutputValues(obj.ToString(), 1);
            }

            return(dt);
        }
 private void DisplaySchedule(Newtonsoft.Json.Linq.JArray o)
 {
     scheduleTableView.LeftEntries.Clear();
     scheduleTableView.RightEntries.Clear();
     try
     {
         foreach (var schoolClass in o.Children())
         {
             //var itemProperties = schoolClass.Children<Newtonsoft.Json.Linq.JProperty>();
             string title     = schoolClass["CourseTitle"].ToString();
             string startTime = schoolClass["MyDayStartTime"].ToString();
             string endTime   = schoolClass["MyDayEndTime"].ToString();
             string room      = schoolClass["RoomNumber"].ToString();
             //ScheduleTableView.entries.Add(startTime + " - " + endTime + " " + title + " (" + room + ")");
             scheduleTableView.LeftEntries.Add(startTime + " - " + endTime);
             scheduleTableView.RightEntries.Add(title + (String.IsNullOrEmpty(room) ? "" : " (" + room + ")"));
         }
         scheduleTableView.ReloadData();
     }
     catch (Exception e)
     {
     }
 }
Пример #6
0
        public override void PerformDBAction()
        {
            ValueExpression VE = new ValueExpression(Db.ProjEnvironment, Db.BusinessFlow, Db.DSList);

            VE.Value = Act.SQL;
            string SQLCalculated  = VE.ValueCalculated;
            string collectionName = "";

            if (Action == Actions.ActDBValidation.eDBValidationType.SimpleSQLOneValue)
            {
                collectionName = Act.Table;
            }
            else
            {
                collectionName = GetCollectionName(SQLCalculated);
            }
            var DB         = mMongoClient.GetDatabase(DbName);
            var collection = DB.GetCollection <BsonDocument>(collectionName);

            try
            {
                switch (Action)
                {
                case Actions.ActDBValidation.eDBValidationType.FreeSQL:

                    if (SQLCalculated.Contains("insertMany"))
                    {
                        string queryParam = GetUpdateQueryParams(SQLCalculated).ToString();
                        Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.Linq.JArray.Parse(queryParam);
                        List <BsonDocument>         documents = new List <BsonDocument>();
                        foreach (Newtonsoft.Json.Linq.JObject obj in jsonArray.Children <Newtonsoft.Json.Linq.JObject>())
                        {
                            BsonDocument document = BsonDocument.Parse(obj.ToString());
                            documents.Add(document);
                        }
                        collection.InsertMany(documents);
                    }
                    else if (SQLCalculated.Contains("insertOne") || SQLCalculated.Contains("insert"))
                    {
                        BsonDocument insertDocumnet = BsonDocument.Parse(GetUpdateQueryParams(SQLCalculated));
                        collection.InsertOne(insertDocumnet);
                    }
                    else
                    {
                        var result = collection.Find(GetQueryParamater(SQLCalculated, "find")).
                                     Project(Builders <BsonDocument> .Projection.Exclude("_id").Exclude(GetQueryParamater(SQLCalculated, "projection"))).
                                     Sort(BsonDocument.Parse(GetQueryParamater(SQLCalculated, "sort"))).
                                     Limit(Convert.ToInt32(GetQueryParamater(SQLCalculated, "limit"))).
                                     ToList();

                        var obj = result.ToJson();
                        Act.ParseJSONToOutputValues(obj.ToString(), 1);
                    }
                    break;

                case Actions.ActDBValidation.eDBValidationType.RecordCount:
                    var count = collection.Count(new BsonDocument());
                    Act.AddOrUpdateReturnParamActual("Record Count", count.ToString());
                    break;

                case Actions.ActDBValidation.eDBValidationType.UpdateDB:

                    //do commit
                    if (Act.CommitDB_Value == true)
                    {
                        var session = mMongoClient.StartSession();
                        session.StartTransaction();
                        UpdateCollection(SQLCalculated, collection);
                        session.CommitTransaction();
                    }
                    else
                    {
                        UpdateCollection(SQLCalculated, collection);
                    }
                    break;

                case Actions.ActDBValidation.eDBValidationType.SimpleSQLOneValue:
                    string col = Act.Column;
                    string where = Act.Where;
                    string filter    = "";
                    var    isNumeric = double.TryParse(where, out double n);

                    //Simply matches on specific column type int
                    //For ex where contains any int value
                    if (isNumeric)
                    {
                        filter = "{" + col + ":" + where + "}";
                    }
                    else
                    {
                        //Equality matches on the whole embedded document require an exact match of the specified <value> document, including the field order
                        //For ex where contains value = {field1:_value1,field2:_value2,field3:"_value3",...}
                        if (where.Contains(","))
                        {
                            filter = "{" + col + ":" + where + "}";
                        }
                        //Simply matches on specific column
                        //For ex where contains any string value
                        else
                        {
                            filter = "{" + col + ":\"" + where + "\"}";
                        }
                    }
                    var resultSimpleSQLOne = collection.Find(filter).Project(Builders <BsonDocument> .Projection.Exclude("_id")).ToList().ToJson();
                    Act.ParseJSONToOutputValues(resultSimpleSQLOne.ToString(), 1);
                    break;

                default:
                    Act.Error += "Operation Type " + Action + " is not yes supported for Mongo DB";
                    break;
                }
            }
            catch (Exception e)
            {
                Act.Error = "Failed to execute. Error :" + e.Message;
                Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}", e);
            }
            if (!Db.KeepConnectionOpen)
            {
                Disconnect();
            }
        }