Exemplo n.º 1
0
            public override VariableInfoType[] GetVariableInfoObject(VariableParam[] variables)
            {
                BaseRestClient restServiceClient = GetNewBaseClient();

                string[] parameters;

                {
                    restServiceClient.PathFormat = "Meth={0}&variable={1}";


                    Type vType = typeof(VariablesResponseType);
                    restServiceClient.ResponseType = vType;
                    parameters    = new string[5];
                    parameters[0] = "getVariableInfo";
                    if (variables == null || variables.Length == 0)
                    {
                        parameters[1] = String.Empty;
                    }
                    else
                    {
                        parameters[1] = variables[0].Code;
                    }

                    VariablesResponseType res = (VariablesResponseType)restServiceClient.GetResponseAsObject(parameters);
                    return(res.variables);
                }
            }
Exemplo n.º 2
0
        public string GetVariableInfo(string Variable, String authToken)
        {
            VariablesResponseType aVType = GetVariableInfoObject(Variable, null);
            string xml = WSUtils.ConvertToXml(aVType, typeof(VariablesResponseType));

            return(xml);
        }
            public VariablesResponseType GetVariableInfoObject(string Variable, String authToken)
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

                queryLog2.LogStart(Logging.Methods.GetVariables, Variable,
                                   Context.Request.UserHostName);

                try
                {
                    VariableParam[] vars = null;
                    if (!String.IsNullOrEmpty(Variable))
                    {
                        vars = new VariableParam[1];

                        VariableParam vp = new VariableParam(Variable);
                        vars[0] = vp;
                    }
                    VariablesResponseType res = ODws.GetVariables(vars);

                    // don't always have variables
                    if (res.variables != null)
                    {
                        queryLog2.LogEnd(Logging.Methods.GetVariables,
                                         Variable,
                                         timer.ElapsedMilliseconds.ToString(),
                                         res.variables.Length.ToString(),
                                         Context.Request.UserHostName);
                    }
                    else
                    {
                        queryLog2.LogEnd(Logging.Methods.GetVariables,
                                         Variable,
                                         timer.ElapsedMilliseconds.ToString(),
                                         "0",
                                         Context.Request.UserHostName);
                    }


                    return(res);
                }
                catch (Exception we)
                {
                    log.Warn(we.Message);
                    queryLog2.LogEnd(Logging.Methods.GetVariables,
                                     Variable,
                                     timer.ElapsedMilliseconds.ToString(),
                                     "-9999",
                                     Context.Request.UserHostName);

                    throw SoapExceptionGenerator.WOFExceptionToSoapException(we);
                }
            }
        public VariablesResponseType GetVariableInfo(string Variable)
        {
            VariableInfoType[] variableList;
            if (String.IsNullOrEmpty(Variable))
            {
                variableList = ODvariables.getVariables(new VariableParam[0], Variables);
            }
            else
            {
                VariableParam vp;
                vp           = new VariableParam(Variable);
                variableList = ODvariables.getVariable(vp, Variables);
            }

            if (variableList == null)
            {
                throw new WaterOneFlowException("Variable Not Found");
            }
            VariablesResponseType Response = new VariablesResponseType();

            Response.variables = variableList;

            if (Response.queryInfo == null)
            {
                Response.queryInfo          = new QueryInfoType();
                Response.queryInfo.criteria = new QueryInfoTypeCriteria();
            }
            Response.queryInfo.creationTime          = DateTime.UtcNow;
            Response.queryInfo.creationTimeSpecified = true;
            if (String.IsNullOrEmpty(Variable))
            {
                Response.queryInfo.criteria.variableParam = "NULL (Request for all variables";
            }
            else
            {
                Response.queryInfo.criteria.variableParam = Variable;
            }

            NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");

            Response.queryInfo.note = CuahsiBuilder.addNote(Response.queryInfo.note,
                                                            sourceNote);
            return(Response);
        }
Exemplo n.º 5
0
            public VariablesResponseType GetVariableInfo(String VariableParameter)
            {
                Stopwatch      timer = System.Diagnostics.Stopwatch.StartNew();
                GetVariablesOD obj   = new GetVariablesOD();

                queryLog2.LogStart(Logging.Methods.GetVariables, VariableParameter,
                                   appContext.Request.UserHostName);

                VariablesResponseType resp = obj.GetVariableInfo(VariableParameter);

                queryLog2.LogEnd(Logging.Methods.GetVariables,
                                 VariableParameter,
                                 timer.ElapsedMilliseconds.ToString(),
                                 resp.variables.Length.ToString(),
                                 appContext.Request.UserHostName);


                return(resp);
            }
Exemplo n.º 6
0
        public void testVariablesAll2()
        {
            restServiceClient.PathFormat = "Meth={0}";

            string varCode = ""; // prep for many test

            Type vType = typeof(VariablesResponseType);

            restServiceClient.ResponseType = vType;
            parameters    = new string[2];
            parameters[0] = "getVariableInfo";
            parameters[1] = varCode;

            object res = restServiceClient.GetResponseAsObject(parameters);

            Assert.IsInstanceOfType(vType, res);
            VariablesResponseType variablesResponse = (VariablesResponseType)res;

            Assert.That(variablesResponse.variables.Length > 0, "Should return more than 1 variable");
        }
            public VariablesResponseType GetVariableInfo(string Variable)
            {
                VariableInfoType[] variableList;
                if (String.IsNullOrEmpty(Variable))
                {
                    variableList = ODvariables.getVariables(new VariableParam[0], Variables);
                }
                else
                {
                    VariableParam vp;
                    vp           = new VariableParam(Variable);
                    variableList = ODvariables.getVariable(vp, Variables);
                }

                if (variableList == null)
                {
                    throw new WaterOneFlowException("Variable Not Found");
                }
                VariablesResponseType Response = new VariablesResponseType();

                Response.variables = variableList;

                Response.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetVariableInfo", null, null,
                                                                       new string[] { Variable }, null, null);

                if (String.IsNullOrEmpty(Variable))
                {
                    CuahsiBuilder.addNote(Response.queryInfo.note,
                                          CuahsiBuilder.createNote("(Request for all variables"));
                }
                else
                {
                    Response.queryInfo.criteria.variableParam = Variable;
                }
                NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");

                Response.queryInfo.note = CuahsiBuilder.addNote(Response.queryInfo.note,
                                                                sourceNote);

                return(Response);
            }
Exemplo n.º 8
0
        public void testVariables()
        {
            restServiceClient.PathFormat = "Meth={0}&variable={1}";

            string varCode = "HG"; // prep for many test

            Type vType = typeof(VariablesResponseType);

            restServiceClient.ResponseType = vType;
            parameters    = new string[2];
            parameters[0] = "getVariableInfo";
            parameters[1] = varCode;

            object res = restServiceClient.GetResponseAsObject(parameters);

            Assert.IsInstanceOfType(vType, res);
            VariablesResponseType variablesResponse = (VariablesResponseType)res;

            Assert.That(variablesResponse.variables.Length == 1, "Should only return 1 variable");
            Assert.That(variablesResponse.variables[0].variableCode[0].Value.Equals(varCode));
        }
            public object GetResponseAsObject(object[] queryParameters)
            {
                /*
                 * there really is not any good way to test this.
                 * Everything comes back as tex/plain
                 * So, if the XML deserialier fails... well
                 * */

                string      url    = createUrl(queryParameters);
                XmlReader   reader = Utility.RestByUrl(url);
                XmlDocument doc    = new XmlDocument();

                doc.Load(reader);
                VariablesResponseType response;

                if (doc.GetElementsByTagName("variables", WaterOneFlowImpl.Constants.XML_SCHEMA_NAMSPACE).Count > 0)
                {
                    try
                    {
                        //TextReader reader2 = new StringReader(doc.DocumentElement.OuterXml);
                        // response = (VariablesResponseType)tsSerializer.Deserialize(reader2);
                        response           = new VariablesResponseType();
                        response.variables = FixVariablesResponse(doc);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(
                                  "Error. Possible bad station or variable, or the  service could be down. It is hard to tell");
                    }
                }
                else
                {
                    response           = new VariablesResponseType();
                    response.variables = FixVariablesResponse(doc);
                }



                return(response);
            }
Exemplo n.º 10
0
            /// <summary>
            /// GetVariableInfo
            /// </summary>
            /// <param name="VariableParameter">full variable code in format vocabulary:VariableCode</param>
            /// <returns>the VariableInfo object</returns>
            public VariablesResponseType GetVariableInfo(String VariableParameter)
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();


                queryLog2.LogStart(CustomLogging.Methods.GetVariables, VariableParameter,
                                   appContext.Request.UserHostName);

                VariablesResponseType resp;

                if (string.IsNullOrEmpty(VariableParameter))
                {
                    resp           = new VariablesResponseType();
                    resp.variables = WebServiceUtils.GetVariablesFromDb();

                    //setup query info
                    resp.queryInfo = CuahsiBuilder.CreateQueryInfoType
                                         ("GetVariableInfo", null, null, new string[] { string.Empty }, null, null);
                    CuahsiBuilder.addNote(resp.queryInfo.note,
                                          CuahsiBuilder.createNote("(Request for all variables"));
                }
                else
                {
                    resp              = new VariablesResponseType();
                    resp.variables    = new VariableInfoType[1];
                    resp.variables[0] = WebServiceUtils.GetVariableInfoFromDb(VariableParameter);
                    //setup query info
                    resp.queryInfo = CuahsiBuilder.CreateQueryInfoType
                                         ("GetVariableInfo", null, null, new string[] { VariableParameter }, null, null);
                }

                queryLog2.LogEnd(CustomLogging.Methods.GetVariables,
                                 VariableParameter,
                                 timer.ElapsedMilliseconds.ToString(),
                                 resp.variables.Length.ToString(),
                                 appContext.Request.UserHostName);


                return(resp);
            }
Exemplo n.º 11
0
            public VariablesResponseType GetVariableInfo(string Variable)
            {
                VariableInfoType[] variableList;
                if (String.IsNullOrEmpty(Variable))
                {
                    variableList = ODvariables.getVariables(new VariableParam[0], Variables);

                }
                else
                {
                    VariableParam vp;
                    vp = new VariableParam(Variable);
                    variableList = ODvariables.getVariable(vp, Variables);
                }

                if (variableList == null)
                {
                    throw new WaterOneFlowException("Variable Not Found");
                }
                VariablesResponseType Response = new VariablesResponseType();
                Response.variables = variableList;

                Response.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetVariableInfo", null, null,
                                                                       new string[] {Variable}, null, null);

                if (String.IsNullOrEmpty(Variable))
                {
                  CuahsiBuilder.addNote(Response.queryInfo.note,
                      CuahsiBuilder.createNote("(Request for all variables")) ;
                }
                else
                {
                    Response.queryInfo.criteria.variableParam = Variable;
                }
                NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");
                Response.queryInfo.note = CuahsiBuilder.addNote(Response.queryInfo.note,
                                                                sourceNote);

                return Response;
            }
Exemplo n.º 12
0
        public VariablesResponseType GetVariableInfo(String VariableParameter)
        {
            Stopwatch      timer = System.Diagnostics.Stopwatch.StartNew();
            GetVariablesOD obj   = new GetVariablesOD();

            //queryLog.InfoFormat("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}",
            //   System.Configuration.ConfigurationManager.AppSettings["network"], // network
            //   "GetVariableInfo", // method
            //   null, //locaiton
            //   VariableParameter, //variable
            //   null, // startdate
            //   null, //enddate
            //  String.Empty, // processing time
            //   String.Empty // count
            //   );
            queryLog2.LogStart(Logging.Methods.GetVariables, VariableParameter,
                               appContext.Request.UserHostName);

            VariablesResponseType resp = obj.GetVariableInfo(VariableParameter);

            queryLog2.LogEnd(Logging.Methods.GetVariables,
                             VariableParameter,
                             timer.ElapsedMilliseconds.ToString(),
                             resp.variables.Length.ToString(),
                             appContext.Request.UserHostName);

            //           queryLog.InfoFormat("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}",
            //System.Configuration.ConfigurationManager.AppSettings["network"], // network
            //"GetValues", // method
            //null, //locaiton
            //VariableParameter, //variable
            //null, // startdate
            //null, //enddate
            //timer.ElapsedMilliseconds, // processing time
            //resp.variables.Length // count
            //);

            return(resp);
        }
Exemplo n.º 13
0
            /// <summary>
            /// Creates A set of variables.
            /// </summary>
            /// <param name="numberOFVariables">The number OF variables.</param>
            /// <returns></returns>
            public static VariablesResponseType CreateASetOfVariables(int numberOFVariables)
            {
                //VariablesTypeVariable Response = new VariablesTypeVariable();
                //Response.variable = new VariablesTypeVariable[numberOFVariables];
                VariablesResponseType Response = new VariablesResponseType();

                Response.variables = new VariableInfoType[numberOFVariables];

                // pre-populate the variableID for ease of use
                for (int count = 0; count < numberOFVariables; count++)
                {
                    Response.variables[count] = CreateVariableDescriptionType();

                    /*
                     * Response.variables[count] = new VariableDescriptionType();
                     * VariableDescriptionTypeVariableID[] var = new VariableDescriptionTypeVariableID[1];
                     * var[0] = new VariableDescriptionTypeVariableID();
                     * Response.variables[count].variableCode = var;
                     */
                }

                return(Response);
            }
Exemplo n.º 14
0
            private VariableInfoType[] FixVariablesResponse(XmlDocument xdoc)
            {
                XmlRootAttribute root = new XmlRootAttribute("variable");

                Type[]                  types                 = new Type[0];
                XmlSerializer           varSerializar         = new XmlSerializer(typeof(VariableInfoType), null, types, root, WaterOneFlowImpl.Constants.XML_SCHEMA_NAMSPACE);
                List <VariableInfoType> vars                  = new List <VariableInfoType>();
                VariablesResponseType   variablesResponseType = new VariablesResponseType();

                foreach (XmlNode v in xdoc.GetElementsByTagName("variable", WaterOneFlowImpl.Constants.XML_SCHEMA_NAMSPACE))
                {
                    try
                    {
                        TextReader reader = new StringReader(v.OuterXml);


                        VariableInfoType variableInfoType = (VariableInfoType)varSerializar.Deserialize(reader);
                        vars.Add(variableInfoType);
                    } catch {
                        log.Debug("error serializing variable");
                    }
                }
                return(vars.ToArray());
            }
Exemplo n.º 15
0
            public override object GetVariableInfoObject(string variable, String authToken)
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

                queryLog2.LogStart(Logging.Methods.GetVariables, variable,
                                   Context.Request.UserHostName);

                try
                {
                    VariableParam[] vars = null;
                    if (!String.IsNullOrEmpty(variable))
                    {
                        vars = new VariableParam[1];

                        VariableParam vp = new VariableParam(variable);
                        vars[0] = vp;
                    }
                    VariablesResponseType res = ODws.GetVariables(vars);

                    // don't always have variables
                    if (res.variables != null)
                    {
                        queryLog2.LogEnd(Logging.Methods.GetVariables,
                                         variable,
                                         timer.ElapsedMilliseconds.ToString(),
                                         res.variables.Length.ToString(),
                                         Context.Request.UserHostName);
                    }
                    else
                    {
                        queryLog2.LogEnd(Logging.Methods.GetVariables,
                                         variable,
                                         timer.ElapsedMilliseconds.ToString(),
                                         "0",
                                         Context.Request.UserHostName);
                    }
                    WaterOneFlow.Service.v1_0.xsd.VariablesResponse obj =
                        new WaterOneFlow.Service.v1_0.xsd.VariablesResponse(res);
                    // if (DEBUG) {
                    // XmlSerializer xs = new XmlSerializer(
                    //     typeof (WaterOneFlow.Service.v1_0.xsd.VariablesResponse));
                    // StringBuilder sb = new StringBuilder();
                    // XmlWriterSettings settings = new XmlWriterSettings();

                    // settings.OmitXmlDeclaration = true;
                    //// settings.ConformanceLevel = ConformanceLevel.Fragment;
                    // XmlWriter writer = XmlWriter.Create(sb, settings);
                    // xs.Serialize(writer, obj);
                    //}
                    //return res;
                    return(new WaterOneFlow.Service.v1_0.xsd.VariablesResponse(res));
                }
                catch (Exception we)
                {
                    log.Warn(we.Message);
                    queryLog2.LogEnd(Logging.Methods.GetVariables,
                                     variable,
                                     timer.ElapsedMilliseconds.ToString(),
                                     "-9999",
                                     Context.Request.UserHostName);

                    throw SoapExceptionGenerator.WOFExceptionToSoapException(we);
                }
            }
Exemplo n.º 16
0
        public VariablesResponseType GetVariables(VariableParam[] variables)
        {
            UsgsDbDailyValues.VariablesDataTable vDs = new UsgsDbDailyValues.VariablesDataTable();

            UsgsDbDailyValuesTableAdapters.VariablesTableAdapter TableAdapter = new VariablesTableAdapter();

            List <VariableInfoType> vList = new List <VariableInfoType>();

            // if nothing. get it all
            if (variables == null || variables.Length == 0)
            {
                try
                {
                    TableAdapter.Fill(vDs);
                } catch
                {
                    log.Error("Cannot connect to USGS Database");
                    throw new WaterOneFlowServerException("Server Error: Cannot Connect to Database");
                }

                if (vDs.Rows.Count > 0)
                {
                    foreach (UsgsDbDailyValues.VariablesRow vRow
                             in vDs)
                    {
                        VariableInfoType vit = RowToVariable(vRow);

                        if (vit != null)
                        {
                            vList.Add(vit);
                        }
                    }
                }
            }
            else
            {
                foreach (VariableParam v in variables)
                {
                    UsgsDbDailyValues.VariablesRow[] vRows;
                    try
                    {
                        TableAdapter.FillByVariableCode(vDs, v.Code);

                        string where = VariableOptions2WhereClause(v); /* Use Caution, where clause not SQL inject safe. */
                        vRows        = (UsgsDbDailyValues.VariablesRow[])
                                       vDs.Select(where);
                    }
                    catch
                    {
                        log.Error("Cannot connect to USGS Database");
                        throw new WaterOneFlowServerException("Server Error: Cannot Connect to Database");
                    }
                    if (vRows.Length > 0)
                    {
                        foreach (UsgsDbDailyValues.VariablesRow vRow
                                 in vRows)
                        {
                            VariableInfoType vit = RowToVariable(vRow);

                            if (vit != null)
                            {
                                vList.Add(vit);
                            }
                        }
                    }
                }
            }

            //if (vDs.Rows.Count > 0)
            //{
            //    foreach (UsgsDbDailyValues.VariablesRow vRow
            //        in vDs)
            //    {


            //            VariableInfoType v = RowToVariable(vRow);

            //        if (v != null) vList.Add(v);

            //    }
            //}
            VariablesResponseType vRes = new VariablesResponseType();

            if (vList != null && vList.Count > 0)
            {
                // build response

                vRes.variables = vList.ToArray();
            }
            else
            {
                log.Info("User Error: No Variables Returned");
                throw new WaterOneFlowException("No Variables Returned. Submit with no values to get full list.");
            }
            return(vRes);
        }
Exemplo n.º 17
0
            /// <summary>
            /// GetVariableInfo
            /// </summary>
            /// <param name="VariableParameter">full variable code in format vocabulary:VariableCode</param>
            /// <returns>the VariableInfo object</returns>
            public VariablesResponseType GetVariableInfo(String VariableParameter)
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

                queryLog2.LogStart(CustomLogging.Methods.GetVariables, VariableParameter,
                      appContext.Request.UserHostName);

                VariablesResponseType resp;
                if(string.IsNullOrEmpty(VariableParameter))
                {
                    resp = new VariablesResponseType();
                    resp.variables = WebServiceUtils.GetVariablesFromDb();

                    //setup query info
                    resp.queryInfo = CuahsiBuilder.CreateQueryInfoType
                        ("GetVariableInfo", null, null, new string[] { string.Empty }, null, null);
                    CuahsiBuilder.addNote(resp.queryInfo.note,
                        CuahsiBuilder.createNote("(Request for all variables"));
                }
                else
                {
                    resp = new VariablesResponseType();
                    resp.variables = new VariableInfoType[1];
                    resp.variables[0] = WebServiceUtils.GetVariableInfoFromDb(VariableParameter);
                    //setup query info
                    resp.queryInfo = CuahsiBuilder.CreateQueryInfoType
                        ("GetVariableInfo", null, null, new string[] { VariableParameter }, null, null);
                }

                queryLog2.LogEnd(CustomLogging.Methods.GetVariables,
                    VariableParameter,
                    timer.ElapsedMilliseconds.ToString(),
                    resp.variables.Length.ToString(),
                      appContext.Request.UserHostName);

                return resp;
            }
            /// <summary>
            /// Creates A set of variables.
            /// </summary>
            /// <param name="numberOFVariables">The number OF variables.</param>
            /// <returns></returns>
            public static VariablesResponseType CreateASetOfVariables(int numberOFVariables)
            {
                //VariablesTypeVariable Response = new VariablesTypeVariable();
                //Response.variable = new VariablesTypeVariable[numberOFVariables];
                VariablesResponseType Response = new VariablesResponseType();
                Response.variables = new VariableInfoType[numberOFVariables];

                // pre-populate the variableID for ease of use
                for (int count = 0; count < numberOFVariables; count++)
                {
                Response.variables[count] = CreateVariableDescriptionType();
                /*
                 Response.variables[count] = new VariableDescriptionType();
                VariableDescriptionTypeVariableID[] var = new VariableDescriptionTypeVariableID[1];
                var[0] = new VariableDescriptionTypeVariableID();
                Response.variables[count].variableCode = var;
                 */
                }

                return Response;
            }