Пример #1
0
        private void DoPullArtifact()
        {
            Artifact       selectedArtifact = (Artifact)this.versionsLB.SelectedItem;
            Type           type             = (Type)this.archetypesLB.SelectedItem;
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(new Uri(XowlUtils.xowlApi + "services/storage/sparql?store=longTerm"));

            req.CookieContainer = XowlUtils.cookies;
            req.ContentType     = "application/sparql-query";
            req.Accept          = "application/json";
            req.Method          = "POST";
            string sparqlRequest = XowlUtils.ToSparqlQuery(type, selectedArtifact);

            byte[] bytes = Encoding.UTF8.GetBytes(sparqlRequest);
            req.ContentLength = bytes.Length;
            System.IO.Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);
            os.Close();
            try
            {
                HttpWebResponse        resp = (HttpWebResponse)req.GetResponse();
                System.IO.StreamReader sr   = new System.IO.StreamReader(resp.GetResponseStream());
                string r = sr.ReadToEnd().Trim();
                processJsonResponse(r, type);
                System.Diagnostics.Debug.WriteLine(r);
            }
            catch (WebException ex)
            {
                //TODO: take into account the code of the exception to execute appropriate actions
                XowlUtils.Connect();
                //DoPullArtifact();//FIXME: improve management of cookies
            }
        }
Пример #2
0
        private void DoPushArtifact()
        {
            System.Diagnostics.Debug.WriteLine("Pushing data to collaboration");
            Type   type      = (Type)this.archetypesLB.SelectedItem;
            string archetype = "org.xowl.platform.kernel.artifacts.ArtifactArchetypeFree";
            //FIXME: ensure unicity of version for the same name and within the same base
            string baseUri      = (string)Properties.Settings.Default["baseUri"];
            string name         = type.Name.ToLower();
            string baseArtifact = baseUri + name;
            string version      = this.artifactVersionTB.Text.Trim();
            string parameters;

            if (this.supersededLB.SelectedIndex == -1)
            {
                parameters = $"name={name}&base={baseArtifact}&version={version}&archetype={archetype}";
            }
            else
            {
                string superseded = this.supersededLB.SelectedItem.ToString();
                parameters = $"name={name}&base={baseArtifact}&version={version}&archetype={archetype}&superseded={superseded}";
            }
            HttpWebRequest xowlReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(XowlUtils.xowlApi + "connectors/generics/sw?" + parameters));

            xowlReq.CookieContainer = XowlUtils.cookies;
            xowlReq.ContentType     = "application/ld+json";
            xowlReq.Accept          = "application/json";
            xowlReq.Method          = "POST";
            string body = this.ToJsonLD(type);

            byte[] bytes = Encoding.UTF8.GetBytes(body);
            xowlReq.ContentLength = bytes.Length;
            System.IO.Stream os = xowlReq.GetRequestStream();
            os.Write(bytes, 0, bytes.Length);
            os.Close();
            try
            {
                HttpWebResponse        resp = (HttpWebResponse)xowlReq.GetResponse();
                System.IO.StreamReader sr   = new System.IO.StreamReader(resp.GetResponseStream());
                string r = sr.ReadToEnd().Trim();
                System.Diagnostics.Debug.WriteLine(r);
                xowlReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(XowlUtils.xowlApi + "connectors/generics/pull"));
                xowlReq.CookieContainer = XowlUtils.cookies;
                xowlReq.ContentType     = "application/ld+json";
                xowlReq.Accept          = "application/json";
                xowlReq.Method          = "POST";
                resp = (HttpWebResponse)xowlReq.GetResponse();
            }
            catch (WebException ex)
            {
                //TODO: take into account the code of the exception to execute appropriate actions
                XowlUtils.Connect();
                //DoPushArtifact();//FIXME: improve management of cookies
            }
            //FIXME: improve scheduling of notifications
            ActivitiProcessManager pm = new ActivitiProcessManager();

            pm.CompleteTaskForData(type);
        }
Пример #3
0
        public string ToJsonLD()
        {
            StringBuilder sb        = new StringBuilder();
            Type          type      = this.GetType();
            string        className = type.Name;
            string        baseUri   = XowlUtils.GetBaseUri(type);

            PropertyInfo[] properties = this.GetType().GetProperties().OrderBy(p => p.MetadataToken).ToArray();
            sb.Append("{");
            sb.Append($"\"@id\":\"{baseUri}");
            sb.Append(this.UUID);
            sb.Append("\", \"@type\":\"");
            sb.Append(baseUri + className);
            sb.Append("\",");
            PropertyInfo property;
            Type         propertyType;

            for (int i = 1; i < properties.Length; i++)
            {
                property     = properties[i];
                propertyType = property.PropertyType;
                string name     = property.Name.ToLower();
                string value    = property.GetValue(this).ToString();
                string typeName = property.PropertyType.Name;
                if (typeName.Equals("Double"))
                {
                    value = value.Replace(',', '.');
                }
                if (typeName.Equals("Boolean"))
                {
                    if (value.Equals("True"))
                    {
                        value = "true";
                    }
                    else
                    {
                        value = "false";
                    }
                }
                if (typeName.Equals("String"))
                {
                    sb.Append($"\"{baseUri}{name}\":\"{value}\"");
                }
                else
                {
                    sb.Append($"\"{baseUri}{name}\":{value}");
                }
                if (i == properties.Length - 1)
                {
                    sb.Append("}");
                }
                else
                {
                    sb.Append(",");
                }
            }
            return(sb.ToString());
        }
Пример #4
0
 public PushWizard()
 {
     InitializeComponent();
     if (XowlUtils.cookies == null)
     {
         XowlUtils.Connect();
     }
     this.artifacts = XowlUtils.RetrieveArtifacts(false);
     this.archetypesLB.DataSource    = XowlUtils.GetClassesFromNameSpace("BusinessData");
     this.archetypesLB.DisplayMember = "Name";
     this.archetypesLB.SelectedIndex = 0;
 }