コード例 #1
0
ファイル: DRPDrive.cs プロジェクト: shailesh-vaidya/cortx
        protected override bool IsValidPath(string path)
        {
            bool isValidPath = false;

            string[] pathArray = ChunkPath(path);
            if (pathArray.Length == 0)
            {
                return(true);
            }
            else
            {
                // Send cmd to DRP broker
                string   drpURL        = pathArray[0];
                string[] remainingPath = pathArray.Skip(1).ToArray();

                DRP_Client myDRPClient = new DRP_Client(drpURLHash[drpURL]);

                while (myDRPClient.wsConn.ReadyState != WebSocketSharp.WebSocketState.Open)
                {
                    System.Threading.Thread.Sleep(100);
                }

                JObject returnedData = myDRPClient.SendCmd("cliGetItem", remainingPath);

                if (returnedData["item"].Value <string>() != null)
                {
                    isValidPath = true;
                }

                myDRPClient.CloseSession();
            }

            return(isValidPath);
        }
コード例 #2
0
ファイル: DRPDrive.cs プロジェクト: shailesh-vaidya/cortx
        protected override void GetItem(string path)
        {
            string[] pathArray = ChunkPath(path);
            if (pathArray.Length == 0)
            {
                // Do nothing
            }
            else
            {
                string   drpAlias      = pathArray[0];
                string[] remainingPath = pathArray.Skip(1).ToArray();

                DRP_Client myDRPClient = new DRP_Client(drpURLHash[drpAlias]);
                if (!myDRPClient.Open().GetAwaiter().GetResult())
                {
                    return;
                }

                //Console.WriteLine("Connected to DRP Broker, sending pathCmd");
                JObject returnedData = myDRPClient.SendCmd_Async("DRP", "pathCmd", new Dictionary <string, object>()
                {
                    { "method", "cliGetPath" }, { "pathList", remainingPath }, { "listOnly", false }
                }).GetAwaiter().GetResult();

                if (returnedData != null && returnedData["pathItem"] != null)
                {
                    string returnJSONString;
                    string itemType = returnedData["pathItem"].GetType().ToString();
                    object returnObj;
                    if (itemType.Equals("Newtonsoft.Json.Linq.JValue"))
                    {
                        returnObj        = returnedData["pathItem"].Value <string>();
                        returnJSONString = returnedData["pathItem"].Value <string>();
                    }
                    else
                    {
                        returnObj        = returnedData["pathItem"];
                        returnJSONString = returnedData["pathItem"].ToString();
                    }
                    if (returnObj != null)
                    {
                        WriteItemObject(returnJSONString, this.ProviderInfo + "::" + path, false);
                    }
                    else
                    {
                        Console.WriteLine("Returned value is null!");
                    }
                }

                //WriteItemObject(returnedData, this.ProviderInfo + "::" + path, true);

                myDRPClient.CloseSession();
            }
        }
コード例 #3
0
ファイル: DRPDrive.cs プロジェクト: shailesh-vaidya/cortx
        private string GetItemReturnJSONString(string path)
        {
            string returnJSONString = null;

            string[] pathArray = ChunkPath(path);
            if (pathArray.Length == 0)
            {
                // Do nothing
            }
            else
            {
                string   drpURL        = pathArray[0];
                string[] remainingPath = pathArray.Skip(1).ToArray();

                DRP_Client myDRPClient = new DRP_Client(drpURLHash[drpURL]);
                while (myDRPClient.wsConn.ReadyState != WebSocketSharp.WebSocketState.Open)
                {
                    System.Threading.Thread.Sleep(100);
                }

                //Console.WriteLine("Connected to DRP Broker!");
                JObject returnedData = myDRPClient.SendCmd("pathCmd", new Dictionary <string, object>()
                {
                    { "method", "cliGetPath" }, { "pathList", remainingPath }, { "listOnly", false }
                });

                if (returnedData != null && returnedData["pathItem"] != null)
                {
                    //string itemType = returnedData["pathItem"].GetType().ToString();
                    returnJSONString = returnedData["pathItem"].ToString();

                    /*
                     * switch (itemType) {
                     *  case "Newtonsoft.Json.Linq.JObject":
                     *      returnJSONString =
                     *      break;
                     *  case "Newtonsoft.Json.Linq.JArray":
                     *      break;
                     *  case "Newtonsoft.Json.Linq.JValue":
                     *      break;
                     *  default:
                     *      break;
                     * }
                     */
                }

                //WriteItemObject(returnedData, this.ProviderInfo + "::" + path, true);

                myDRPClient.CloseSession();
            }
            return(returnJSONString);
        }
コード例 #4
0
ファイル: DRPDrive.cs プロジェクト: shailesh-vaidya/cortx
        protected override void SetItem(string path, object value)
        {
            string[] pathArray = ChunkPath(path);
            if (pathArray.Length == 0)
            {
                // Do nothing
            }
            else
            {
                //base.SetItem(path, value);
                string   drpAlias      = pathArray[0];
                string[] remainingPath = pathArray.Skip(1).ToArray();

                DRP_Client myDRPClient = new DRP_Client(drpURLHash[drpAlias]);
                while (myDRPClient.wsConn.ReadyState != WebSocketSharp.WebSocketState.Open && !myDRPClient.clientConnected)
                {
                    System.Threading.Thread.Sleep(100);
                }
                //JObject returnedData = myDRPClient.SendDRPCmd("cliSetItem", new List<Object> { ChunkPath(path), value });
                JObject returnedData = myDRPClient.SendCmd("pathCmd", new Dictionary <string, object>()
                {
                    { "method", "cliSetPath" }, { "pathList", remainingPath }, { "objData", value }
                });

                if (returnedData["success"] != null)
                {
                    object returnObj;
                    string itemType = returnedData["pathItem"].GetType().ToString();
                    if (itemType.Equals("Newtonsoft.Json.Linq.JValue"))
                    {
                        returnObj = returnedData["pathItem"].Value <string>();
                    }
                    else
                    {
                        returnObj = returnedData["pathItem"];
                    }
                    if (returnObj != null)
                    {
                        Console.WriteLine("cliSetPath returned status = [" + returnObj + "]");
                        //WriteItemObject(returnObj, this.ProviderInfo + "::" + path, false);
                    }
                    else
                    {
                        Console.WriteLine("cliSetPath returned status is null!");
                    }
                }

                //WriteItemObject(returnedData, this.ProviderInfo + "::" + path, true);

                myDRPClient.CloseSession();
            }
        }
コード例 #5
0
ファイル: DRPDrive.cs プロジェクト: shailesh-vaidya/cortx
        protected override void GetChildItems(string path, bool recurse)
        {
            string[] pathArray = ChunkPath(path);
            if (pathArray.Length == 0)
            {
                // Return base Objects
                DataTable returnTable = new DataTable();
                returnTable.Columns.Add(new DataColumn("Alias", typeof(string)));
                returnTable.Columns.Add(new DataColumn("URL", typeof(string)));
                returnTable.Columns.Add(new DataColumn("User", typeof(string)));
                returnTable.Columns.Add(new DataColumn("ProxyAddress", typeof(string)));
                //returnTable.Columns.Add(new DataColumn("ProxyUser", typeof(string)));

                foreach (string key in drpURLHash.Keys)
                {
                    DataRow newRow = returnTable.NewRow();
                    newRow.SetField("Alias", key);
                    newRow.SetField("URL", drpURLHash[key].URL);
                    newRow.SetField("User", drpURLHash[key].User);
                    newRow.SetField("ProxyAddress", drpURLHash[key].ProxyAddress);
                    //newRow.SetField("ProxyUser", drpURLHash[key].ProxyUser);
                    returnTable.Rows.Add(newRow);
                }

                if (returnTable != null)
                {
                    WriteItemObject(returnTable, this.ProviderInfo + "::" + path, true);
                }
            }
            else
            {
                string   drpAlias      = pathArray[0];
                string[] remainingPath = pathArray.Skip(1).ToArray();

                DRP_Client myDRPClient = new DRP_Client(drpURLHash[drpAlias]);
                if (!myDRPClient.Open().GetAwaiter().GetResult())
                {
                    return;
                }

                //Console.WriteLine("Connected to DRP Broker, sending pathCmd");
                JObject returnedData = myDRPClient.SendCmd_Async("DRP", "pathCmd", new Dictionary <string, object>()
                {
                    { "method", "cliGetPath" }, { "pathList", remainingPath }, { "listOnly", true }
                }).GetAwaiter().GetResult();

                if (returnedData != null && returnedData.ContainsKey("pathItemList"))
                {
                    // Return base Objects
                    DataTable returnTable = null;

                    foreach (JObject objData in (JArray)returnedData["pathItemList"])
                    {
                        var fields = new List <Field>();

                        // Create table if null
                        if (returnTable == null)
                        {
                            returnTable = ReturnTable(objData);
                        }

                        DataRow newRow = returnTable.NewRow();
                        foreach (JProperty thisProperty in objData.Properties())
                        {
                            newRow.SetField(thisProperty.Name, thisProperty.Value.ToString());
                        }
                        returnTable.Rows.Add(newRow);
                    }

                    if (returnTable != null)
                    {
                        WriteItemObject(returnTable, this.ProviderInfo + "::" + path, true);
                    }
                }

                myDRPClient.CloseSession();
            }
        }