コード例 #1
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);
        }
コード例 #2
0
 private void PushArtifact_Click(object sender, EventArgs e)
 {
     if (this.ValidateChildren())
     {
         Type type = (Type)this.archetypesLB.SelectedItem;
         this.DoPushArtifact(type);
         ActivitiProcessManager pm = new ActivitiProcessManager();
         pm.CompleteTaskForData(type);
         this.Close();
     }
 }