/// <summary> /// method shows window that informs user about current situation of his synchronization process /// </summary> /// <param name="repository">EA repository</param> public void showCorrectWindow(EA.Repository repository) { User user = getLoggedUser(); if (user == null) { MessageBox.Show("First you must log in and join your colleague to team."); return; } using (WebClient webClient = new WebClient()) { this.user = user; string result = "", result2 = "", result3 = ""; ModelInformation synchronizationData = new ModelInformation(); synchronizationData.token = user.token; EA.Package package = (EA.Package)repository.GetPackageByID(1); synchronizationData.modelGUID = package.PackageGUID; string data = user.token; try { webClient.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8"; data = EncodeNonAsciiCharacters(synchronizationData.serialize()); result = webClient.UploadString(Utils.serviceAddress + "/synchronization", data); BPAddIn.syncProgressWindow = new SynchronizationProgressWindow(repository); BPAddIn.syncProgressWindow.ShowDialog(); } catch (WebException e) { var response = e.Response as HttpWebResponse; int code = (int)response.StatusCode; if (code == 401) { MessageBox.Show("Please, log in once again."); } else if (code == 400) { MessageBox.Show("Currently, you are not a member of any team. First, join your colleague to team."); } else if (code == 405) { MessageBox.Show("Synchronization of this model in your team is not allowed."); } else if (code == 403) { MessageBox.Show("Your colleague in team has not sent data about model yet."); } else if (code == 404) { DialogResult resultWindow = MessageBox.Show("Do you want to synchronise currently opened model? Change of synchronized model in team project is not possible.", "Choice of model for synchronization", MessageBoxButtons.YesNo); if (resultWindow == DialogResult.Yes) { SendingDataWindow sendingDataWindow = new SendingDataWindow(repository); sendingDataWindow.ShowDialog(); } } else if (code == 406) { MessageBox.Show("Your colleague has not joined your team yet."); } } catch (Exception ex) { MessageBox.Show("Unexpected error has occured."); } } }
/// <summary> /// method sends all data about model /// </summary> /// <param name="sendingDataWindow">window for data sending</param> /// <param name="repository">EA repository</param> public void sendDataAboutModel(SendingDataWindow sendingDataWindow, EA.Repository repository) { try { using (WebClient webClient = new WebClient()) { using (var stream = webClient.OpenRead(Utils.serviceAddress)) { stream.Close(); this.sendingDataWindow = sendingDataWindow; ChangeService.newEvent.Set(); changeModelGUID(repository); modelTraverse.sendDataAboutModel(repository); ScenarioChange propertyChange = new ScenarioChange(); propertyChange.modelGUID = repository.GetPackageByID(1).PackageGUID; propertyChange.elementType = 777; modelTraverse.saveCreate(propertyChange, repository); user = getLoggedUser(); modelInformation = new ModelInformation(); modelInformation.modelGUID = repository.GetPackageByID(1).PackageGUID; modelInformation.token = user.token; timer = new System.Timers.Timer(); timer.Elapsed += new System.Timers.ElapsedEventHandler(checkLastCreate); timer.Interval = 5000; timer.Start(); } } } catch (Exception e) { MessageBox.Show("Server is unavailable. Check your internet connection."); } }