Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (m_Popfrm == null)
            {
                m_Popfrm         = new frmLoading();
                m_Popfrm.m_nType = 2;
                m_Popfrm.Show();
                backgroundWorker2.RunWorkerAsync();
            }

            //IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass();
            //IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName("C:\\Drawing1.dwg"), 0) as IFeatureWorkspace;
            //IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName("C:\\Drawing1.dwg"));
            //IFeatureClassContainer pFeatClassContainer = pFeatureDataset as IFeatureClassContainer;

            //for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)
            //{
            //    IFeatureLayer pFeatureLayer;
            //    IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
            //   if (pFeatClass.FeatureType == esriFeatureType.esriFTAnnotation)
            //    {
            //        //如果是注记,则添加注记层
            //        pFeatureLayer = new CadAnnotationLayerClass();
            //    }
            //    else//如果是点、线、面,则添加要素层
            //    {
            //        pFeatureLayer = new FeatureLayerClass();

            //    }
            //   pFeatureLayer.Name = pFeatClass.AliasName;
            //   pFeatureLayer.FeatureClass = pFeatClass;

            //    //this.axmc_Main.Map.AddLayer(pFeatureLayer);
            //    //this.axmc_Main.ActiveView.**();
            //}
        }
Example #2
0
        private async Task <MyUserState> ShareSingleChummer()
        {
            string hash = "";

            try
            {
                using (var op_shareChummer = Timekeeper.StartSyncron("Share Chummer", null,
                                                                     CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                {
                    MyUserState       myState = new MyUserState(this);
                    CharacterExtended ce      = null;
                    var    client             = StaticUtils.GetClient();
                    string sinnerid           = "";
                    Guid   SINid = Guid.Empty;

                    async Task <CharacterExtended> GetCharacterExtended(CustomActivity parentActivity)
                    {
                        using (var op_prepChummer = Timekeeper.StartSyncron("Loading Chummerfile", parentActivity,
                                                                            CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                        {
                            Character c = new Character()
                            {
                                FileName = MyCharacterCache.FilePath
                            };
                            var foundchar = (from a in PluginHandler.MainForm.OpenCharacters
                                             where a.FileName == MyCharacterCache.FilePath
                                             select a).ToList();
                            if (foundchar?.Any() == true)
                            {
                                c = foundchar?.FirstOrDefault();
                            }
                            else
                            {
                                using (frmLoading frmLoadingForm = new frmLoading
                                {
                                    CharacterFile = MyCharacterCache.FilePath
                                })
                                {
                                    frmLoadingForm.Reset(36);
                                    frmLoadingForm.TopMost = true;
                                    frmLoadingForm.Show();
                                    myState.StatusText       = "Loading chummer file...";
                                    myState.CurrentProgress += 10;
                                    ReportProgress(myState.CurrentProgress, myState);
                                    await c.Load(frmLoadingForm, false).ConfigureAwait(true);
                                }
                            }

                            if (c == null)
                            {
                                throw new ArgumentNullException("Could not load Character file " +
                                                                MyCharacterCache.FilePath +
                                                                ".");
                            }
                            ce = new CharacterExtended(c, null, null, MyCharacterCache);
                            if (ce?.MySINnerFile?.Id != null)
                            {
                                sinnerid = ce.MySINnerFile.Id.ToString();
                            }
                            hash = ce?.MySINnerFile?.MyHash;
                            return(ce);
                        }
                    }


                    if (MyCharacterCache.MyPluginDataDic.TryGetValue("SINnerId", out Object sinneridobj))
                    {
                        sinnerid = sinneridobj?.ToString();
                    }
                    else
                    {
                        ce = await GetCharacterExtended(op_shareChummer).ConfigureAwait(true);

                        sinnerid = ce.MySINnerFile.Id.ToString();
                        hash     = ce?.MySINnerFile?.MyHash;
                    }


                    if (string.IsNullOrEmpty(sinnerid) || !Guid.TryParse(sinnerid, out SINid))
                    {
                        myState.StatusText = "SINner Id is unknown or not issued!";
                        ReportProgress(30, myState);
                    }
                    else
                    {
                        myState.StatusText      = "SINner Id is " + SINid + ".";
                        myState.CurrentProgress = 30;
                        ReportProgress(myState.CurrentProgress, myState);
                    }


                    HttpOperationResponse <ResultSinnerGetSINById> checkresult = null;
                    //check if char is already online and updated
                    using (var op_checkOnlineVersionChummer = Timekeeper.StartSyncron(
                               "check if online", op_shareChummer,
                               CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                    {
                        checkresult = await client.GetSINByIdWithHttpMessagesAsync(SINid).ConfigureAwait(true);

                        if (checkresult == null)
                        {
                            throw new ArgumentException("Could not parse result from SINners Webservice!");
                        }
                        if (checkresult.Response.StatusCode != HttpStatusCode.NotFound)
                        {
                            if (checkresult.Body.CallSuccess != true)
                            {
                                if (checkresult.Body.MyException is Exception myException)
                                {
                                    throw new ArgumentException(
                                              "Error from SINners Webservice: " + checkresult.Body.ErrorText,
                                              myException);
                                }
                                throw new ArgumentException("Error from SINners Webservice: " +
                                                            checkresult.Body.ErrorText);
                            }
                            hash = checkresult.Body.MySINner.MyHash;
                        }
                    }


                    var lastWriteTimeUtc = System.IO.File.GetLastWriteTimeUtc(MyCharacterCache.FilePath);
                    if (checkresult.Response.StatusCode == HttpStatusCode.NotFound ||
                        checkresult.Body.MySINner.LastChange < lastWriteTimeUtc)
                    {
                        if (ce == null)
                        {
                            myState.StatusText      = "The Chummer is newer and has to be uploaded again.";
                            myState.CurrentProgress = 30;
                            ReportProgress(myState.CurrentProgress, myState);
                            ce = await GetCharacterExtended(op_shareChummer).ConfigureAwait(true);
                        }

                        using (var op_uploadChummer = Timekeeper.StartSyncron(
                                   "Uploading Chummer", op_shareChummer,
                                   CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                        {
                            myState.StatusText      = "Checking SINner availability (and if necessary upload it).";
                            myState.CurrentProgress = 35;
                            ReportProgress(myState.CurrentProgress, myState);
                            myState.ProgressSteps = 10;
                            var uploadtask = await ce.Upload(myState, op_uploadChummer).ConfigureAwait(true);

                            SINid = ce.MySINnerFile.Id.Value;
                            var result = await client.GetSINByIdWithHttpMessagesAsync(SINid).ConfigureAwait(true);

                            if (result == null)
                            {
                                throw new ArgumentException("Could not parse result from SINners Webservice!");
                            }
                            if (result.Body?.CallSuccess != true)
                            {
                                if (result.Body?.MyException is Exception myException)
                                {
                                    throw new ArgumentException(
                                              "Error from SINners Webservice: " + result.Body?.ErrorText,
                                              myException);
                                }
                                throw new ArgumentException(
                                          "Error from SINners Webservice: " + result.Body?.ErrorText);
                            }
                            hash = result.Body.MySINner.MyHash;
                        }
                    }

                    myState.StatusText      = "SINner is online available.";
                    myState.CurrentProgress = 90;
                    ReportProgress(myState.CurrentProgress, myState);

                    string url = client.BaseUri + "O";
                    url += "/" + hash;
                    if (Properties.Settings.Default.OpenChummerFromSharedLinks == true)
                    {
                        url += "?open=true";
                    }

                    myState.LinkText = url;
                    ReportProgress(100, myState);
                    RunWorkerCompleted(myState);
                    return(myState);
                }
            }
            catch (Exception exception)
            {
                Log.Warn(exception);
                throw;
            }
        }
Example #3
0
        static void Show()
        {
            frmLoading frm = new frmLoading();

            frm.ShowDialog();
        }
Example #4
0
        private async Task <MyUserState> ShareSingleChummer()
        {
            if (MyCharacterCache == null)
            {
                throw new ArgumentNullException(nameof(MyCharacterCache));
            }
            string hash = string.Empty;

            try
            {
                using (var op_shareChummer = Timekeeper.StartSyncron("Share Chummer", null,
                                                                     CustomActivity.OperationType.DependencyOperation, MyCharacterCache.FilePath))
                {
                    MyUserState       myState = new MyUserState(this);
                    CharacterExtended ce      = null;
                    var    client             = StaticUtils.GetClient();
                    string sinnerid           = string.Empty;
                    Guid   SINid = Guid.Empty;

                    try
                    {
                        async Task <CharacterExtended> GetCharacterExtended(CustomActivity parentActivity)
                        {
                            using (_ = Timekeeper.StartSyncron("Loading Chummerfile", parentActivity,
                                                               CustomActivity.OperationType.DependencyOperation, MyCharacterCache.FilePath))
                            {
                                Character c          = PluginHandler.MainForm.OpenCharacters.FirstOrDefault(a => a.FileName == MyCharacterCache.FilePath);
                                bool      blnSuccess = true;
                                if (c == null)
                                {
                                    c = new Character {
                                        FileName = MyCharacterCache.FilePath
                                    };
                                    using (frmLoading frmLoadingForm = new frmLoading {
                                        CharacterFile = MyCharacterCache.FilePath
                                    })
                                    {
                                        frmLoadingForm.Reset(36);
                                        frmLoadingForm.Show();
                                        myState.StatusText       = "Loading chummer file...";
                                        myState.CurrentProgress += 10;
                                        ReportProgress(myState.CurrentProgress, myState);
                                        blnSuccess = await c.LoadAsync(frmLoadingForm, false);
                                    }
                                }

                                if (!blnSuccess)
                                {
                                    throw new ArgumentNullException("Could not load Character file " +
                                                                    MyCharacterCache.FilePath +
                                                                    ".");
                                }
                                ce = new CharacterExtended(c, null, null, MyCharacterCache);
                                if (ce?.MySINnerFile?.Id != null)
                                {
                                    sinnerid = ce.MySINnerFile.Id.ToString();
                                }
                                hash = ce?.MySINnerFile?.MyHash;
                                return(ce);
                            }
                        }

                        if (MyCharacterCache.MyPluginDataDic.TryGetValue("SINnerId", out object sinneridobj))
                        {
                            sinnerid = sinneridobj?.ToString() ?? string.Empty;
                        }
                        else
                        {
                            ce = await GetCharacterExtended(op_shareChummer);

                            sinnerid = ce.MySINnerFile.Id.ToString();
                            hash     = ce?.MySINnerFile?.MyHash ?? string.Empty;
                        }


                        if (string.IsNullOrEmpty(sinnerid) || !Guid.TryParse(sinnerid, out SINid))
                        {
                            myState.StatusText = "SINner Id is unknown or not issued!";
                            ReportProgress(30, myState);
                        }
                        else
                        {
                            myState.StatusText      = "SINner Id is " + SINid + ".";
                            myState.CurrentProgress = 30;
                            ReportProgress(myState.CurrentProgress, myState);
                        }


                        try
                        {
                            //check if char is already online and updated
                            ResultSinnerGetSINById checkresult;
                            using (_ = Timekeeper.StartSyncron(
                                       "check if online", op_shareChummer,
                                       CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                            {
                                checkresult = await client.GetSINByIdAsync(SINid);

                                if (checkresult == null)
                                {
                                    throw new ArgumentException("Could not parse result from SINners Webservice!");
                                }
                                if (checkresult.CallSuccess != true)
                                {
                                    if (checkresult.MyException != null)
                                    {
                                        throw new ArgumentException(
                                                  "Error from SINners Webservice: " + checkresult.ErrorText,
                                                  checkresult.MyException.ToString());
                                    }
                                    throw new ArgumentException("Error from SINners Webservice: " +
                                                                checkresult.ErrorText);
                                }

                                hash = checkresult.MySINner.MyHash;
                            }


                            var lastWriteTimeUtc = MyCharacterCache != null?File.GetLastWriteTimeUtc(MyCharacterCache.FilePath) : DateTime.MinValue;

                            if (checkresult.MySINner.LastChange < lastWriteTimeUtc)
                            {
                                if (ce == null)
                                {
                                    myState.StatusText      = "The Chummer is newer and has to be uploaded again.";
                                    myState.CurrentProgress = 30;
                                    ReportProgress(myState.CurrentProgress, myState);
                                    ce = await GetCharacterExtended(op_shareChummer);
                                }

                                if (ce != null)
                                {
                                    using (var op_uploadChummer = Timekeeper.StartSyncron(
                                               "Uploading Chummer", op_shareChummer,
                                               CustomActivity.OperationType.DependencyOperation, MyCharacterCache?.FilePath))
                                    {
                                        myState.StatusText      = "Checking SINner availability (and if necessary upload it).";
                                        myState.CurrentProgress = 35;
                                        ReportProgress(myState.CurrentProgress, myState);
                                        myState.ProgressSteps = 10;
                                        await ce.Upload(myState, op_uploadChummer);

                                        if (ce.MySINnerFile.Id != null)
                                        {
                                            SINid = ce.MySINnerFile.Id.Value;
                                        }
                                        var result = await client.GetSINByIdAsync(SINid);

                                        {
                                            if (result == null)
                                            {
                                                throw new ArgumentException("Could not parse result from SINners Webservice!");
                                            }
                                            if (result?.CallSuccess != true)
                                            {
                                                if (result?.MyException != null)
                                                {
                                                    throw new ArgumentException(
                                                              "Error from SINners Webservice: " + result.ErrorText,
                                                              result?.MyException.ToString());
                                                }
                                                throw new ArgumentException(
                                                          "Error from SINners Webservice: " + result.ErrorText);
                                            }

                                            hash = result.MySINner.MyHash;
                                        }
                                    }
                                }
                            }
                        }
                        finally
                        {
                            //checkresult?.Dispose();
                        }
                    }
                    finally
                    {
                        ce?.Dispose();
                    }

                    myState.StatusText      = "SINner is online available.";
                    myState.CurrentProgress = 90;
                    ReportProgress(myState.CurrentProgress, myState);

                    string url = client.BaseUrl + "O";
                    url += "/" + hash;
                    if (Settings.Default.OpenChummerFromSharedLinks)
                    {
                        url += "?open=true";
                    }

                    myState.LinkText = url;
                    ReportProgress(100, myState);
                    RunWorkerCompleted(myState);
                    return(myState);
                }
            }
            catch (Exception exception)
            {
                Log.Warn(exception);
                throw;
            }
        }
Example #5
0
        public static void ModifyPackageLoadZIP(Form parent, string zipPath)
        {
            string    _namespace = MethodBase.GetCurrentMethod().ToLogFormatFullName();
            Exception outEx;

            if (Directory.Exists(PMFileSystem.PackMan_TempMakeDir) && Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempMakeDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG) == DeleteFolderResult.UserCancelled)
            {
                Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_TEMP_DIR_ERR, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Helper.CreateFolderSafely(PMFileSystem.PackMan_TempMakeDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_CREATE_TEMP_DIR_ARG) == CreateFolderResult.UserCancelled)
            {
                Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_TEMP_DIR_ERR, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ArchiveManagement.ChecksumStatus archCheckStat = ArchiveManagement.ChecksumStatus.NoStoredChecksum;
            try
            {
                archCheckStat = ArchiveManagement.PerformArchiveChecksumCheck(zipPath);
            }
            catch (Exception ex)
            {
                Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Misc.Error.UnableReadArchStatus(zipPath), _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                return;
            }

            if (archCheckStat == ArchiveManagement.ChecksumStatus.ChecksumMatchFailed)
            {
                Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Misc.Error.FailedChecksumZip(zipPath), _namespace, null, BasicDebugLogger.DebugErrorType.Error);
                return;
            }
            else if (archCheckStat == ArchiveManagement.ChecksumStatus.NoStoredChecksum)
            {
                if (Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_ARCH_NO_CHECK, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            frmLoading loadingForm = new frmLoading(StringConst.frmLoading.EXTRACTING_ARCH + zipPath + ".");
            bool       error       = false;
            Thread     thread      = new Thread(delegate()
            {
                try
                {
                    ArchiveManagement.ExtractZip(zipPath, PMFileSystem.PackMan_TempMakeDir, _namespace, false);
                }
                catch (Exception ex)
                {
                    Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Misc.Error.UnableExtractZip(zipPath, PMFileSystem.PackMan_TempMakeDir), _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    error = true;
                    loadingForm.SafeClose();
                    return;
                }
                loadingForm.SafeClose();
            });

            thread.Start();
            loadingForm.ShowDialog();

            if (error)
            {
                Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempMakeDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG);
                return;
            }

            string      xmlPath = PMFileSystem.PackMan_TempMakeDir + "\\" + Vars.INSTALL_FILE_DEFAULT_FILENAME;
            RMPackage   package = null;
            LogDataList log     = null;

            if (!File.Exists(xmlPath))
            {
                Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Misc.Error.ZipExtractInstallXmlNull(zipPath), _namespace, null, BasicDebugLogger.DebugErrorType.Error);
                Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempMakeDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG);
                return;
            }


            loadingForm = new frmLoading(StringConst.frmLoading.PARSING_MANIFEST + xmlPath + ".");
            thread      = new Thread(delegate()
            {
                try
                {
                    package = new RMPackage(xmlPath, _namespace, out log, NoAssetProbing: true);
                }
                catch (Exception ex)
                {
                    Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Misc.Error.ZipExtractInstallXMLErr(zipPath), _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    error = true;
                    loadingForm.SafeClose();
                    return;
                }
                loadingForm.SafeClose();
            });
            thread.Start();
            loadingForm.ShowDialog();

            if (error)
            {
                Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempMakeDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG);
                return;
            }


            package.Implicit = false;

            LogDataList outLog = null;

            loadingForm = new frmLoading(StringConst.frmLoading.RETRIEVING_ASSETS_DIR + PMFileSystem.PackMan_TempMakeDir + ".");
            thread      = new Thread(delegate()
            {
                try
                {
                    RMImplicit.RetrievePackFromDir(PMFileSystem.PackMan_TempMakeDir, _namespace, false, out outLog, ref package);
                }
                catch (Exception ex)
                {
                    Helper.ShowMessageBox(MessageBoxStrings.GUI.MODIFY_PACK_ZIP_GEN, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Logger.WriteErrorLog(LoggerMessages.GUI.BGWorker.Misc.Error.ZipExtractUnableRetrieveAsset(zipPath), _namespace, ex, BasicDebugLogger.DebugErrorType.Error);
                    error = true;
                    loadingForm.SafeClose();
                    return;
                }
                loadingForm.SafeClose();
            });
            thread.Start();
            loadingForm.ShowDialog();

            if (error)
            {
                Helper.DeleteFolderSafely(PMFileSystem.PackMan_TempMakeDir, _namespace, out outEx, LoggerMessages.GeneralError.UNABLE_DELETE_TEMP_DIR_ARG);
                return;
            }

            if (outLog != null)
            {
                log.Logs.AddRange(outLog.Logs);
            }

            if (log != null && log.HasErrorsOrWarnings())
            {
                Helper.ShowMessageBox(MessageBoxStrings.General.HAS_ERRORS_WARNINGS, MessageBoxStrings.MESSAGEBOX_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                frmLogger loggerForm = new frmLogger(_logList: log);
                loggerForm.StartPosition = FormStartPosition.CenterParent;
                loggerForm.ShowDialog();
            }

            frmPropPack loadPackDlg = new frmPropPack(package, PMFileSystem.PackMan_TempMakeDir, true);

            loadPackDlg.Text = Vars.FRMPROPPACK_MODFY_TITLE;
            loadPackDlg.ShowDialog(parent);
        }
Example #6
0
        private void btnBanVe_Click(object sender, EventArgs e)
        {
            frmLoading f2 = new frmLoading(txtMaSanPham.Text, txtPath_MaSP.Text);

            f2.Show();
        }