예제 #1
0
        private void backgroundWorkerPublish_DoWork(object sender, DoWorkEventArgs e)
        {
            // connect to server
            this.m_exception = null;
            try
            {
                if (this.m_download)
                {
                    switch (this.m_protocol)
                    {
                    case 0:
                        //...
                        break;

                    case 1:
                    case 2:
                        DataDictionary.Download(this.m_project, this.backgroundWorkerPublish, this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text, this.m_views.ToArray());
                        break;
                    }
                }
                else
                {
                    switch (this.m_protocol)
                    {
                    case 0:
                    {
                        WebRequest request = HttpWebRequest.Create(this.textBoxUrl.Text);
                        request.Method = "POST";

                        using (FileStream streamFile = new FileStream(this.m_localpath, FileMode.Open))
                        {
                            request.ContentLength = streamFile.Length;
                            request.ContentType   = "application/step";
                            request.Headers[HttpRequestHeader.ContentLocation] = System.IO.Path.GetFileName(this.m_localpath);

                            // for now, treat content type as opaque document attachment (don't set Content-Type to 'application/step')
                            // future: treat as project file that be merged and compared

                            using (Stream streamWeb = request.GetRequestStream())
                            {
                                {
                                    byte[] buffer = new byte[8192];
                                    int    len    = 0;
                                    do
                                    {
                                        len = streamFile.Read(buffer, 0, buffer.Length);
                                        if (len > 0)
                                        {
                                            streamWeb.Write(buffer, 0, len);
                                            this.backgroundWorkerPublish.ReportProgress((int)(100L * streamFile.Position / streamFile.Length));
                                        }
                                    } while (len > 0);
                                }
                            }
                        }
                    }
                    break;

                    case 1:
                    case 2:
                        //if (this.treeViewContainer.SelectedNode.Tag is IfdConcept)
                    {
                        //IfdConcept ifdConcept = (IfdConcept)this.treeViewContainer.SelectedNode.Tag;
                        DataDictionary.Upload(this.m_project, this.backgroundWorkerPublish, this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text, String.Empty, this.m_views.ToArray());
                    }
                    break;
                    }
                }
            }
            catch (Exception x)
            {
                this.m_exception = x;
            }
        }
예제 #2
0
        private void backgroundWorkerContexts_DoWork(object sender, DoWorkEventArgs e)
        {
            ResponseContext response = DataDictionary.GetContexts(this.m_project, this.backgroundWorkerContexts, this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text);

            e.Result = response;
        }
예제 #3
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            this.buttonLogin.Enabled      = false;
            this.comboBoxProtocol.Enabled = false;
            this.textBoxUsername.Enabled  = false;
            this.textBoxPassword.Enabled  = false;

            try
            {
                this.progressBar.Visible = true;
                this.progressBar.Style   = ProgressBarStyle.Marquee;

                this.m_dictionary = DataDictionary.Connect(this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text);

                this.comboBoxContext.Items.Clear();
                this.m_contexts = this.m_dictionary.ReadContexts(!this.m_download);
                if (this.m_contexts != null)
                {
                    foreach (string key in this.m_contexts.Keys)
                    {
                        string val = this.m_contexts[key];
                        this.comboBoxContext.Items.Add(val);
                    }
                    if (this.comboBoxContext.Items.Count > 0)
                    {
                        this.comboBoxContext.SelectedIndex = 0;
                        this.comboBoxContext.Enabled       = true;
                        this.textBoxNamespace.Enabled      = true;
                        this.buttonSearch.Enabled          = (this.m_download);
                    }
                }
                else
                {
                    this.errorProvider.SetError(this.labelError, "The account provided does not have any write access.");
                }


                if (this.m_download)
                {
                    Requery();
                }
                else
                {
                    // generate types
                    this.m_typeProject = Compiler.CompileProject(this.m_project, true);
                    if (this.m_typeProject != null)
                    {
                        // get the root type -- only write types that derive from the semantic base class (IfcRoot)
                        Type typeBase = m_typeProject;
                        while (typeBase.BaseType != null)
                        {
                            typeBase = typeBase.BaseType;
                        }

                        // publish types
                        SortedDictionary <string, SortedDictionary <string, Type> > mapNamespace = new SortedDictionary <string, SortedDictionary <string, Type> >();

                        Type[] types = m_typeProject.Assembly.GetTypes();

                        this.progressBar.Style = ProgressBarStyle.Continuous;

                        foreach (Type t in types)
                        {
                            if (t.IsClass)
                            {
                                SortedDictionary <string, Type> listNS = null;
                                if (!mapNamespace.TryGetValue(t.Namespace, out listNS))
                                {
                                    listNS = new SortedDictionary <string, Type>();
                                    mapNamespace.Add(t.Namespace, listNS);
                                }
                                listNS.Add(t.Name, t);
                            }
                        }

                        foreach (string ns in mapNamespace.Keys)
                        {
                            TreeNode tn = new TreeNode();
                            tn.Tag                = ns;
                            tn.Text               = ns;
                            tn.ImageIndex         = 24;
                            tn.SelectedImageIndex = 24;
                            this.treeViewContainer.Nodes.Add(tn);

                            SortedDictionary <string, Type> listNS = mapNamespace[ns];
                            foreach (string typename in listNS.Keys)
                            {
                                Type     t      = listNS[typename];
                                TreeNode tnType = new TreeNode();
                                tnType.Tag                = t;
                                tnType.Text               = t.Name;
                                tnType.ImageIndex         = 5;
                                tnType.SelectedImageIndex = 5;

                                tn.Nodes.Add(tnType);
                            }
                        }
                    }
                    else
                    {
                        this.errorProvider.SetError(this.labelError, "No data has been defined that can be uploaded.");
                    }
                }
            }
            catch (Exception xx)
            {
                this.progressBar.Style   = ProgressBarStyle.Continuous;
                this.progressBar.Visible = false;
                this.errorProvider.SetError(this.labelError, xx.Message);
            }


            this.buttonOK.Enabled = true;
        }