Exemple #1
0
        public bool Connect()
        {
            try
            {
                XElement xSystem;

                //if online
                //connection = new SqlConnection(connectionString);
                //xSystem = GetGnosisSystemXML(xSystemRequest);

                // using (Stream stream = new FileStream(GlobalData.Singleton.IOHelper.GetXMLFilePath("system-september.xml"), FileMode.Create))
                //{
                //   using (StreamWriter sw = new StreamWriter(stream))
                //  {
                //   sw.Write(xSystem.ToString());

                //    }
                // }
                //else
                using (Stream stream = new FileStream(GlobalData.Singleton.IOHelper.GetXMLFilePath("system-september.xml"), FileMode.Open))
                {
                    xSystem = XElement.Load(stream);
                }

                //end if


                if (xSystem == null)
                {
                    return(false);
                }

                GnosisSystem           system           = (GnosisSystem)GnosisXMLHelper.GnosisDeserializeXML(xSystem);//.LoadGnosisSystem(xSystem);
                GnosisSystemController systemController = new GnosisSystemController(system, xSystem);
                GlobalData.Singleton.SystemController = systemController;

                connected = true;
            }
            catch (SqlException ex)
            {
                GlobalData.Singleton.ErrorHandler.HandleError(ex.Message, ex.StackTrace);
                connection = null;

                connected = false;
            }

            return(connected);
        }
Exemple #2
0
        public GnosisInstance GetGnosisInstance(XElement xRequest)
        {
            GnosisInstance instance = null;

            if (xRequest.Attribute("Action") == null)
            {
                XAttribute att = new XAttribute("Action", "Search");
                xRequest.Add(att);
            }

            //remove any results content
            xRequest.Descendants("Result").Remove();

            string input = xRequest.ToString();

            //offline
            if (xRequest.Attribute("EntityID").Value.Equals("2247"))
            {
                using (Stream stream = new FileStream(GlobalData.Singleton.IOHelper.GetXMLFilePath("instance-2247-global.xml"), FileMode.Open))
                {
                    XElement xInstance = XElement.Load(stream);
                    instance         = (GnosisInstance)GnosisXMLHelper.GnosisDeserializeXML(xInstance);
                    instance.Content = xInstance;
                }
            }
            else if (xRequest.Attribute("EntityID").Value.Equals("91"))
            {
                using (Stream stream = new FileStream(GlobalData.Singleton.IOHelper.GetXMLFilePath("instance-91.xml"), FileMode.Open))
                {
                    XElement xInstance = XElement.Load(stream);
                    instance         = (GnosisInstance)GnosisXMLHelper.GnosisDeserializeXML(xInstance);
                    instance.Content = xInstance;
                }
            }
            //end offline

            //online
            //try
            //    {
            //        connection.Open();

            //        using (SqlCommand command = new SqlCommand("gnosis.xml_instance", connection))
            //        {
            //            command.CommandType = System.Data.CommandType.StoredProcedure;
            //            command.Parameters.Add(new SqlParameter("input", input));
            //            string res = (string)command.ExecuteScalar();

            //            using (StringReader sr = new StringReader(res))
            //            {
            //                XElement xInstance = XElement.Load(sr);
            //                instance = (GnosisInstance)GnosisXMLHelper.GnosisDeserializeXML(xInstance);
            //                instance.Content = xInstance;
            //            }


            //        }
            //    }
            //    catch (SqlException ex)
            //    {
            //        GlobalData.Singleton.ErrorHandler.HandleError(ex.Message, ex.StackTrace);
            //    }
            //    catch (Exception ex)
            //    {
            //        GlobalData.Singleton.ErrorHandler.HandleError(ex.Message, ex.StackTrace);
            //    }
            //    finally
            //    {
            //        connection.Close();
            //    }

            //end online

            return(instance);
        }