Example #1
0
        /*Takes a form, adds it to the map of active forms*/
        public static IActionResult InitialiseForm(InitializeFormInput input)
        {
            string itemkey = Guid.NewGuid().ToString();

            try
            {
                if (ActiveForms == null)
                {
                    ActiveForms = new ConcurrentDictionary <string, Graph>();
                }
                if (input.Xml != null && input.Xml != "") //If given xml
                {
                    XDocument xmlInput = XDocument.Parse(input.Xml);
                    Graph     graph    = Graph.FromXml(xmlInput);
                    graph.Initialise();
                    while (!ActiveForms.TryAdd(itemkey, graph))
                    {
                        ;
                    }
                }
                else
                { //if given Guid
                    string xml = getXmlFromGuid(input);
                    if (xml != null)
                    {
                        XDocument xmlInput = XDocument.Parse(xml);
                        Graph     graph    = Graph.FromXml(xmlInput);
                        graph.Initialise();
                        while (!ActiveForms.TryAdd(itemkey, graph))
                        {
                            ;
                        }
                    }
                }

                return(new CreatedResult("", itemkey));
            }
            catch (RestRequestException e)
            {
                System.Net.HttpStatusCode code = e.statusCode;
                var st = 500;
                if (code == System.Net.HttpStatusCode.Forbidden)
                {
                    st = 401;
                }
                else if (code == System.Net.HttpStatusCode.Unauthorized)
                {
                    st = 403;
                }

                Errors.Add(new Error("InitialiseForm", st, "Internal Error", e.Message));
                return(new StatusCodeResult(st));
            }
        }
Example #2
0
        public static string getXmlFromGuid(InitializeFormInput input)
        {
            try
            {
                _dataModelManager.GetDefaultDataModel(Enums.SQLOperation.SELECT, Enums.Tables.DCR_Subscription.ToString());
                _dataModelManager.AddResultSet(new List <String> {
                    "SubscriptionGUID", "DCRGraphID", "DCRUserName", "DCRPassword"
                });
                _dataModelManager.AddFilter("SubscriptionGUID", Enums.ParameterType._string, input.Guid, Enums.CompareOperator.equal, Enums.LogicalOperator.none);
                var data = _sqlManager.SelectData(_dataModelManager.DataModel);

                if (data.Rows.Count == 0)
                {
                    Errors.Add(new Error("getXmlFromGuid", 404, "Internal Error", input.Guid + " not found in database", new Input(input.Guid)));
                    return(null);
                }
                else
                {
                    try
                    {
                        var graphID  = data.Rows[0]["DCRGraphID"].ToString();
                        var username = data.Rows[0]["DCRUserName"].ToString();
                        var password = data.Rows[0]["DCRPassword"].ToString();
                        //HERE: search repository given the graphID. Parse XML and add to activeforms.
                        var xml = _dcrService.GetProcess(graphID, username, password);
                        return(xml);
                    }
                    catch (RestRequestException e)
                    {
                        System.Net.HttpStatusCode code = e.statusCode;
                        var st = 500;
                        if (code == System.Net.HttpStatusCode.Forbidden)
                        {
                            st = 401;
                        }
                        else if (code == System.Net.HttpStatusCode.Unauthorized)
                        {
                            st = 403;
                        }

                        Errors.Add(new Error("getXmlFromGuid", st, "Internal Error", e.Message, new Input(input.Guid)));
                        return(null);
                    }
                }
            }
            catch (SqlCommandException e)
            {
                Errors.Add(new Error("getXmlFromGuid", 500, "Sql error: " + e.command, e.Message));
                return(null);
            }
        }
Example #3
0
        public static IActionResult InitialiseAndGetFormAndFields(InitializeFormInput input)
        {
            try
            {
                string guid = Guid.NewGuid().ToString();
                if (input.Xml != null && input.Xml != "") //if called with xml
                {
                    XDocument xmlInput = XDocument.Parse(input.Xml);
                    Graph     graph    = Graph.FromXml(xmlInput);
                    graph.Initialise();
                    while (!ActiveForms.TryAdd(guid, graph))
                    {
                        ;
                    }
                    StringWriter sw = new StringWriter();
                    Form.getFormAndFields(graph, guid, sw);
                    return(new OkObjectResult(sw.ToString()));
                }
                else   //if called with guid
                {
                    string xml = getXmlFromGuid(input);
                    if (xml != null)
                    {
                        XDocument xmlInput = XDocument.Parse(xml);
                        Graph     graph    = Graph.FromXml(xmlInput);
                        graph.Initialise();

                        while (!ActiveForms.TryAdd(guid, graph))
                        {
                            ;
                        }
                        StringWriter sw = new StringWriter();
                        Form.getFormAndFields(graph, guid, sw);
                        return(new OkObjectResult(sw.ToString()));
                    }
                    else
                    {
                        Errors.Add(new Error("InitialiseAndGetFormFields", 500, "Internal Error", "xml was null", new Input(input.Guid)));
                        return(new StatusCodeResult(500));
                    }
                }
            }
            catch (Exception e)
            {
                Errors.Add(new Error("InitialiseAndGetFormFields", 500, "Internal Error: " + e.StackTrace.ToString(), e.Message));
                return(new StatusCodeResult(500));
            }
        }