コード例 #1
0
        public async Task <bool> SaveAsAsync(string saveAsNewFileName = null,
                                             AdminShellPackageEnv.SerializationFormat prefFmt = AdminShellPackageEnv.SerializationFormat.None,
                                             PackCntRuntimeOptions runtimeOptions             = null)
        {
            try
            {
                await Container.SaveToSourceAsync(saveAsNewFileName, prefFmt, runtimeOptions);

                return(true);
            }
            catch (Exception ex)
            {
                throw new PackageCentralException(
                          $"PackageCentral: while saving {"" + Container?.ToString()} " +
                          $"with new filename {"" + saveAsNewFileName}" +
                          $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
            }
        }
コード例 #2
0
        public override async Task SaveToSourceAsync(string saveAsNewFileName = null,
                                                     AdminShellPackageEnv.SerializationFormat prefFmt = AdminShellPackageEnv.SerializationFormat.None,
                                                     PackCntRuntimeOptions runtimeOptions             = null)
        {
            // apply possible new source name directly
            if (saveAsNewFileName != null)
            {
                SetNewLocation(saveAsNewFileName);
            }

            // check extension
            if (IsFormat == Format.Unknown)
            {
                throw new PackageContainerException(
                          "While saving aasx, unknown file format/ extension was encountered!");
            }

            // check open package
            if (Env == null)
            {
                Env = null;
                throw new PackageContainerException(
                          "While saving aasx, package was indeed not existng!");
            }

            // divert on indirect load/ save, to have dedicated try&catch
            if (IndirectLoadSave)
            {
                // the container or package might be new
                if (!Env.IsOpen || TempFn == null)
                {
                    TempFn = CreateNewTempFn(Location, IsFormat);
                    Env.SaveAs(TempFn, prefFmt: prefFmt);
                }

                // do a close, execute and re-open cycle
                try
                {
                    Env.TemporarilySaveCloseAndReOpenPackage(
                        prefFmt: prefFmt, lambda: () =>
                    {
                        System.IO.File.Copy(Env.Filename, Location, overwrite: true);
                    });
                }
                catch (Exception ex)
                {
                    throw new PackageContainerException(
                              $"While indirect-saving aasx to source {this.ToString()} " +
                              $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
                }
            }
            else
            {
                // new file?
                if (saveAsNewFileName != null)
                {
                    // save as
                    try
                    {
                        Env.SaveAs(saveAsNewFileName, prefFmt: prefFmt);
                    }
                    catch (Exception ex)
                    {
                        throw new PackageContainerException(
                                  $"While saving aasx to new source {saveAsNewFileName} " +
                                  $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
                    }
                }
                else
                {
                    // just save
                    try
                    {
                        Env.SaveAs(Location);
                    }
                    catch (Exception ex)
                    {
                        throw new PackageContainerException(
                                  $"While direct-saving aasx to source {this.ToString()} " +
                                  $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
                    }
                }
            }

            // fake async
            await Task.Yield();
        }
コード例 #3
0
        public override async Task SaveToSourceAsync(string saveAsNewFileName = null,
                                                     AdminShellPackageEnv.SerializationFormat prefFmt = AdminShellPackageEnv.SerializationFormat.None,
                                                     PackCntRuntimeOptions runtimeOptions             = null)
        {
            // check extension
            if (IsFormat == Format.Unknown)
            {
                throw new PackageContainerException(
                          "While saving aasx, unknown file format/ extension was encountered!");
            }

            // check open package
            if (Env == null || !Env.IsOpen)
            {
                Env = null;
                throw new PackageContainerException(
                          "While saving aasx, package was indeed not existng or not open!");
            }

            // will use an file-copy for upload
            var copyFn = CreateNewTempFn(Env.Filename, IsFormat);

            // divert on indirect load/ save, to have dedicated try&catch
            if (IndirectLoadSave)
            {
                // do a close, execute and re-open cycle
                try
                {
                    Env.TemporarilySaveCloseAndReOpenPackage(() =>
                    {
                        System.IO.File.Copy(Env.Filename, copyFn, overwrite: true);
                    });
                }
                catch (Exception ex)
                {
                    throw new PackageContainerException(
                              $"While indirect-saving aasx to temp-file {copyFn} " +
                              $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
                }
            }
            else
            {
                // just save as a copy
                try
                {
                    Env.SaveAs(copyFn, saveOnlyCopy: true);
                }
                catch (Exception ex)
                {
                    throw new PackageContainerException(
                              $"While direct-saving aasx to temp-file {copyFn} " +
                              $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
                }
            }

            // now, try to upload this
            try
            {
                await UploadToServerAsync(copyFn, new Uri(Location), runtimeOptions);
            }
            catch (Exception ex)
            {
                throw new PackageContainerException(
                          $"While uploading to {Location} from temp-file {copyFn} " +
                          $"at {AdminShellUtil.ShortLocation(ex)} gave: {ex.Message}");
            }
        }
コード例 #4
0
 public virtual async Task SaveToSourceAsync(string saveAsNewFileName = null,
                                             AdminShellPackageEnv.SerializationFormat prefFmt = AdminShellPackageEnv.SerializationFormat.None,
                                             PackCntRuntimeOptions runtimeOptions             = null)
 {
     await Task.Yield();
 }