public void DownloadAndApplyArchive()
        {
            using (var stream = typeof(ExtractorTest).GetEmbedded("testArchive.zip"))
            using (var microServer = new MicroServer("archive.zip", stream))
            {
                var archive = new Archive {Href = microServer.FileUri};
                archive.DownloadAndApply(new SilentTaskHandler()).Dispose();

                Assert.AreEqual(Archive.MimeTypeZip, archive.MimeType);
                Assert.AreEqual(stream.Length, archive.Size);
            }
        }
Exemple #2
0
    public static void GetResourcesFrameRender(Dictionary<string, string> taskdetails)
    {
        FileStream fs;
        BinaryWriter bw;

        Dictionary<string, string> response = XMLRPC.Instance.getFrameRenderResources(Convert.ToInt32(taskdetails["projid"]));

        string resourcefilepath = "resources" + Config.Instance.Slash() + response["filename"];

        //Open File for writing
        fs = new FileStream(resourcefilepath, FileMode.OpenOrCreate, FileAccess.Write);
        bw = new BinaryWriter(fs);

        bw.Write(Convert.FromBase64String(response["data"]));
        bw.Flush();
        bw.Close();
        fs.Close();

        //Is the file a archive.. then unpack it
        if (Path.GetExtension(response["filename"]) == ".zip")
        {
            Archive oArchive = new Archive(resourcefilepath);
            oArchive.Extract("resources");
        }
    }
 /// <summary>
 /// Constructs project manager with OutputPrx writing to console.
 /// </summary>
 /// <param name="args">A string[] representing arguments from command line.</param>
 /// <param name="options">A <see cref="T:Ferda.ProjectManager.ProjectManagerOptions"/>
 /// representing options for ProjectManaget</param>
 public ProjectManager(string[] args, ProjectManagerOptions options)
 {
     this.options = options;
     if(options.StartIceGridLocaly) StartIceGrid(options.IceBinPath, options.IceGridAsService, options.IceGridWorkingDirectory, options.IceGridApplicationXmlFilePath);
     modulesManager = new Ferda.ModulesManager.ModulesManager(args, options.LocalePrefs);
     archive = new Archive(views);
 }
 public RestoreProgramHandler(Archive archive, ALocationsHandler loc)
     : base(loc)
 {
     this._program_title = Strings.GetLabelString("IsRestoring",
         this._program_title.ToString());
     this.archive = archive;
 }
 internal MainWindow(Archive a)
 {
     InitializeComponent();
       archive = a;
       if(!string.IsNullOrWhiteSpace(archive.settings.sound.backgroundSoundLoc)) {
     main = new SoundPlayer();
     main.SoundLocation = archive.settings.sound.backgroundSoundLoc.RelativeTo(Program.ArchivePath(archive));
     main.PlayLooping();
       }
       if(!string.IsNullOrWhiteSpace(archive.settings.sound.correctSoundLoc)) {
     yes = new SoundPlayer();
     yes.SoundLocation = archive.settings.sound.correctSoundLoc.RelativeTo(Program.ArchivePath(archive));
     yes.LoadAsync();
       }
       if(!string.IsNullOrWhiteSpace(archive.settings.sound.wrongSoundLoc)) {
     no = new SoundPlayer();
     no.SoundLocation = archive.settings.sound.wrongSoundLoc.RelativeTo(Program.ArchivePath(archive));
     no.LoadAsync();
       }
       Text = a.name;
       BackColor = archive.settings.backgroundColor;
       if(!string.IsNullOrWhiteSpace(archive.settings.backgroundLoc)) {
     BackgroundImage = archive.settings.background ?? Extensions.LoadImage(Program.ArchivePath(archive), archive.settings.backgroundLoc);
       }
       Current = new ModeSelect();
 }
Exemple #6
0
 public void TestNormalizeLocalPath()
 {
     var archive = new Archive {Href = new Uri("test.zip", UriKind.Relative), MimeType = Archive.MimeTypeZip, Size = 128};
     archive.Normalize(new FeedUri(Path.Combine(WindowsUtils.IsWindows ? @"C:\some\dir" : "/some/dir", "feed.xml")));
     archive.Href.Should().Be(
         new Uri(WindowsUtils.IsWindows ? "file:///C:/some/dir/test.zip" : "file:///some/dir/test.zip"),
         because: "Normalize() should make relative local paths absolute");
 }
 public RestoreWindow(Archive archive, ACommunicationWindow owner)
     : base(new RestoreProgramHandler(archive, new Location.LocationsHandler()), owner)
 {
     InitializeComponent();
     Translator.WPF.TranslationHelpers.translateWindow(this);
     default_progress_color = restoreProgress.Foreground;
     this.archive = archive;
 }
Exemple #8
0
        public MainForm()
        {
            InitializeComponent();

            m_PlayListListViewModel = new PlayListListViewModel(listViewPlayList);
            m_ArchiveComboModel = new ArchiveComboModel(comboBoxArchive, m_PlayListListViewModel);
            m_Archive = new RestArchive("http://127.0.0.1:3000", new SynchronizeRestArchiveListener(this, m_ArchiveComboModel));
        }
Exemple #9
0
 private List<UTF8String> DecompressStringList(Archive archive)
 {
     List<UTF8String> list = new List<UTF8String>();
     string stringList = Decompress(archive);
     foreach (string s in stringList.Split('\0'))
     {
         list.Add(s);
     }
     return list;
 }
Exemple #10
0
 internal FetchData(Archive matchingArchive, FetchRequest request)
 {
     this.matchingArchive = matchingArchive;
     this.dsNames = request.Filter;
     if(this.dsNames == null)
     {
         this.dsNames = matchingArchive.ParentDb.DsNames;
     }
     this.request = request;
 }
Exemple #11
0
        /// <summary>
        /// 文档发布时候发生
        /// </summary>
        /// <param name="archive"></param>
        static void WatchService_OnArchivePublished(Archive archive)
        {
            return;
            if (archive == null) return;

            //更新标签链接
            ArchiveUtility.UpdateArchiveTagLinks("/tags/{0}",archive,true);
            Category category = new CategoryBLL().Get(a => a.ID == archive.Cid);
            PageGenerator.Generate(PageGeneratorObject.ArchivePage,category,archive);
        
        }
Exemple #12
0
		internal Robin(Archive parentArc, int rows, bool shouldInitialize)
		{
			this.parentArc = parentArc;
			pointer = new RrdInt(this);
			values = new RrdDoubleArray(this, rows);
			this.rows = rows;
			if (shouldInitialize)
			{
				pointer.Set(0);
				values.Set(0, Double.NaN, rows);
			}
		}
    private Communicator()
    {
        _user = new User();
        _contacts = new Contacts();
        _contacts.loadFromFile(contactFile);

        _archive = new Archive();

        //_archive.createNewTalk("a", 3);
        //_archive.addMessage(3, "a", "a", "A", new System.DateTime(), "nowa wiadomo<b>a</b>sc\n\ndef");
        //_archive.addMessage(3, "a", "x", "X", new System.DateTime(), "nowa wiadomo<b>a</b>sc\n\ndef");
    }
        public void DownloadAndApplyArchive()
        {
            using (var stream = typeof(ArchiveExtractorTest).GetEmbeddedStream("testArchive.zip"))
            using (var microServer = new MicroServer("archive.zip", stream))
            {
                var archive = new Archive {Href = microServer.FileUri};
                archive.DownloadAndApply(new SilentTaskHandler()).Dispose();

                archive.MimeType.Should().Be(Archive.MimeTypeZip);
                archive.Size.Should().Be(stream.Length);
            }
        }
Exemple #15
0
		public FetchData(Archive matchingArchive, FetchRequest request)
		{
			this.matchingArchive = matchingArchive;
			arcStep = matchingArchive.TimeStep;
			arcEndTime = matchingArchive.GetEndTime();
			dsNames = request.GetFilter();
			if (dsNames == null)
			{
				dsNames = matchingArchive.ParentDb.DataSourceNames;
			}
			this.request = request;
		}
            public override ArchiveBase ResolveToArchive()
            {
                if (!this.Parameters["Input"].GetType().IsSubclassOf(typeof(Stream)))
                    throw new InvalidOperationException();

                string password = null;
                if (Parameters.ContainsKey("password") && !string.IsNullOrEmpty(Parameters["password"].ToString()))
                    password = Parameters["password"].ToString();

                var archive = new Archive(((Stream)this.Parameters["Input"]), password);

                return archive;
            }
Exemple #17
0
 internal Robin(Archive parentArc, int rows)
 {
     this.parentArc = parentArc;
     this.rows = rows;
     if (RrdFile.RrdMode == RrdFile.MODE_CREATE)
     {
         pointer = new RrdInt(0,this);
         values = new RrdDoubleArray(this, rows, Double.NaN);
     }
     else
     {
         pointer = new RrdInt(this);
         values = new RrdDoubleArray(this, rows);
     }
 }
 public static void SaveArchiveToDir(string to, Archive arc)
 {
     File.WriteAllText(to + @"\info.json", JsonConvert.SerializeObject(arc, settings));
       File.WriteAllText(to + @"\settings.json", JsonConvert.SerializeObject(arc.settings, settings));
       foreach(var t in arc.topics) {
     var n = to + '\\' + t.name;
     Directory.CreateDirectory(to + '\\' + t.name);
     var content = new List<Question>();
     foreach(var qList in t.questions.Values) {
       foreach(var q in qList) {
     content.Add(q);
       }
     }
     File.WriteAllText(n + @"\questions.json", JsonConvert.SerializeObject(content, settings));
       }
 }
            public override ArchiveBase ResolveToArchive()
            {
                OnStatusChanged(0);

                if (!this.Input.GetType().IsSubclassOf(typeof(Stream)))
                    throw new InvalidOperationException();

                string password = null;
                if (resolverNode.SelectSingleNode("child::password") != null)
                    password = Expand(resolverNode.SelectSingleNode("child::password").InnerText);

                var archive = new Archive(((Stream)this.Input), password);
                OnStatusChanged(1, StatusType.Finished);

                return archive;
            }
Exemple #20
0
        public ViewModel()
        {
            m_genderFilterOptions = new string[] { "All", "Male", "Female" };

            m_archive = new Archive("students.xml");

            IEnumerable<Student> initStudents = m_archive.Load();
            m_students = initStudents == null ?
                new ObservableCollection<Student>() : new ObservableCollection<Student>(initStudents);

            m_view = CollectionViewSource.GetDefaultView(m_students);

            m_saveCommand = new SaveCommand(this);
            m_removeCommand = new RemoveCommand(this);

            this.CurrentSelectGender = "All";
        }
Exemple #21
0
		internal ArcState(Archive parentArc, bool shouldInitialize)
		{
			this.parentArc = parentArc;
			accumumatedValue = new RrdDouble(this);
			nanSteps = new RrdLong(this);
			if (shouldInitialize)
			{
				Header header = parentArc.ParentDb.Header;
				long step = header.Step;
				long lastUpdateTime = header.LastUpdateTime;
				long arcStep = parentArc.TimeStep;
				long initNanSteps = (Util.Normalize(lastUpdateTime, step) -
				                     Util.Normalize(lastUpdateTime, arcStep))/step;
				accumumatedValue.Set(Double.NaN);
				nanSteps.Set(initNanSteps);
			}
		}
Exemple #22
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="parentArc"></param>
 public ArcState(Archive parentArc)
 {
     this.parentArc = parentArc;
     if(RrdFile.RrdMode == RrdFile.MODE_CREATE)
     {
         // should initialize
         Header header = parentArc.ParentDb.Header;
         long step = header.Step;
         long lastUpdateTime = header.LastUpdateTime;
         long arcStep = parentArc.ArcStep;
         long nan = (Util.Normalize(lastUpdateTime, step) -
             Util.Normalize(lastUpdateTime, arcStep)) / step;
         accumValue = new RrdDouble(Double.NaN, this);
         nanSteps = new RrdLong(nan, this);
     }
     else
     {
         accumValue = new RrdDouble(this);
         nanSteps = new RrdLong(this);
     }
 }
Exemple #23
0
        /// <summary>
        /// Read game/machine information
        /// </summary>
        /// <param name="reader">XmlReader to use to parse the machine</param>
        /// <param name="dirs">List of dirs to prepend to the game name</param>
        /// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
        /// <param name="filename">Name of the file to be parsed</param>
        /// <param name="indexId">Index ID for the DAT</param>
        /// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
        private void ReadMachine(
            XmlReader reader,
            List <string> dirs,
            bool statsOnly,

            // Standard Dat parsing
            string filename,
            int indexId,

            // Miscellaneous
            bool keep)
        {
            // If we have an empty machine, skip it
            if (reader == null)
            {
                return;
            }

            // Otherwise, add what is possible
            reader.MoveToContent();

            bool containsItems = false;

            // Create a new machine
            MachineType machineType = 0x0;

            if (reader.GetAttribute("isbios").AsYesNo() == true)
            {
                machineType |= MachineType.Bios;
            }

            if (reader.GetAttribute("isdevice").AsYesNo() == true) // Listxml-specific, used by older DATs
            {
                machineType |= MachineType.Device;
            }

            if (reader.GetAttribute("ismechanical").AsYesNo() == true) // Listxml-specific, used by older DATs
            {
                machineType |= MachineType.Mechanical;
            }

            string  dirsString = (dirs != null && dirs.Count() > 0 ? string.Join("/", dirs) + "/" : string.Empty);
            Machine machine    = new Machine
            {
                Name        = dirsString + reader.GetAttribute("name"),
                Description = dirsString + reader.GetAttribute("name"),
                SourceFile  = reader.GetAttribute("sourcefile"),
                Board       = reader.GetAttribute("board"),
                RebuildTo   = reader.GetAttribute("rebuildto"),
                Runnable    = reader.GetAttribute("runnable").AsRunnable(), // Used by older DATs

                CloneOf  = reader.GetAttribute("cloneof"),
                RomOf    = reader.GetAttribute("romof"),
                SampleOf = reader.GetAttribute("sampleof"),

                MachineType = (machineType == 0x0 ? MachineType.NULL : machineType),
            };

            if (Header.Type == "SuperDAT" && !keep)
            {
                string tempout = Regex.Match(machine.Name, @".*?\\(.*)").Groups[1].Value;
                if (!string.IsNullOrWhiteSpace(tempout))
                {
                    machine.Name = tempout;
                }
            }

            while (!reader.EOF)
            {
                // We only want elements
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                    continue;
                }

                // Get the roms from the machine
                switch (reader.Name)
                {
                case "comment":     // There can be multiple comments by spec
                    machine.Comment += reader.ReadElementContentAsString();
                    break;

                case "description":
                    machine.Description = reader.ReadElementContentAsString();
                    break;

                case "year":
                    machine.Year = reader.ReadElementContentAsString();
                    break;

                case "manufacturer":
                    machine.Manufacturer = reader.ReadElementContentAsString();
                    break;

                case "publisher":     // Not technically supported but used by some legacy DATs
                    machine.Publisher = reader.ReadElementContentAsString();
                    break;

                case "category":     // Not technically supported but used by some legacy DATs
                    machine.Category = reader.ReadElementContentAsString();
                    break;

                case "trurip":     // This is special metadata unique to EmuArc
                    ReadTruRip(reader.ReadSubtree(), machine);

                    // Skip the trurip node now that we've processed it
                    reader.Skip();
                    break;

                case "archive":
                    containsItems = true;

                    DatItem archive = new Archive
                    {
                        Name = reader.GetAttribute("name"),

                        Source = new Source
                        {
                            Index = indexId,
                            Name  = filename,
                        },
                    };

                    archive.CopyMachineInformation(machine);

                    // Now process and add the archive
                    ParseAddHelper(archive, statsOnly);

                    reader.Read();
                    break;

                case "biosset":
                    containsItems = true;

                    DatItem biosSet = new BiosSet
                    {
                        Name        = reader.GetAttribute("name"),
                        Description = reader.GetAttribute("description"),
                        Default     = reader.GetAttribute("default").AsYesNo(),

                        Source = new Source
                        {
                            Index = indexId,
                            Name  = filename,
                        },
                    };

                    biosSet.CopyMachineInformation(machine);

                    // Now process and add the biosSet
                    ParseAddHelper(biosSet, statsOnly);

                    reader.Read();
                    break;

                case "disk":
                    containsItems = true;

                    DatItem disk = new Disk
                    {
                        Name       = reader.GetAttribute("name"),
                        MD5        = reader.GetAttribute("md5"),
                        SHA1       = reader.GetAttribute("sha1"),
                        MergeTag   = reader.GetAttribute("merge"),
                        ItemStatus = reader.GetAttribute("status").AsItemStatus(),

                        Source = new Source
                        {
                            Index = indexId,
                            Name  = filename,
                        },
                    };

                    disk.CopyMachineInformation(machine);

                    // Now process and add the disk
                    ParseAddHelper(disk, statsOnly);

                    reader.Read();
                    break;

                case "media":
                    containsItems = true;

                    DatItem media = new Media
                    {
                        Name    = reader.GetAttribute("name"),
                        MD5     = reader.GetAttribute("md5"),
                        SHA1    = reader.GetAttribute("sha1"),
                        SHA256  = reader.GetAttribute("sha256"),
                        SpamSum = reader.GetAttribute("spamsum"),

                        Source = new Source
                        {
                            Index = indexId,
                            Name  = filename,
                        },
                    };

                    media.CopyMachineInformation(machine);

                    // Now process and add the media
                    ParseAddHelper(media, statsOnly);

                    reader.Read();
                    break;

                case "release":
                    containsItems = true;

                    DatItem release = new Release
                    {
                        Name     = reader.GetAttribute("name"),
                        Region   = reader.GetAttribute("region"),
                        Language = reader.GetAttribute("language"),
                        Date     = reader.GetAttribute("date"),
                        Default  = reader.GetAttribute("default").AsYesNo(),
                    };

                    release.CopyMachineInformation(machine);

                    // Now process and add the release
                    ParseAddHelper(release, statsOnly);

                    reader.Read();
                    break;

                case "rom":
                    containsItems = true;

                    DatItem rom = new Rom
                    {
                        Name       = reader.GetAttribute("name"),
                        Size       = Utilities.CleanLong(reader.GetAttribute("size")),
                        CRC        = reader.GetAttribute("crc"),
                        MD5        = reader.GetAttribute("md5"),
                        SHA1       = reader.GetAttribute("sha1"),
                        SHA256     = reader.GetAttribute("sha256"),
                        SHA384     = reader.GetAttribute("sha384"),
                        SHA512     = reader.GetAttribute("sha512"),
                        SpamSum    = reader.GetAttribute("spamsum"),
                        MergeTag   = reader.GetAttribute("merge"),
                        ItemStatus = reader.GetAttribute("status").AsItemStatus(),
                        Date       = CleanDate(reader.GetAttribute("date")),
                        Inverted   = reader.GetAttribute("inverted").AsYesNo(),

                        Source = new Source
                        {
                            Index = indexId,
                            Name  = filename,
                        },
                    };

                    rom.CopyMachineInformation(machine);

                    // Now process and add the rom
                    ParseAddHelper(rom, statsOnly);

                    reader.Read();
                    break;

                case "sample":
                    containsItems = true;

                    DatItem sample = new Sample
                    {
                        Name = reader.GetAttribute("name"),

                        Source = new Source
                        {
                            Index = indexId,
                            Name  = filename,
                        },
                    };

                    sample.CopyMachineInformation(machine);

                    // Now process and add the sample
                    ParseAddHelper(sample, statsOnly);

                    reader.Read();
                    break;

                default:
                    reader.Read();
                    break;
                }
            }

            // If no items were found for this machine, add a Blank placeholder
            if (!containsItems)
            {
                Blank blank = new Blank()
                {
                    Source = new Source
                    {
                        Index = indexId,
                        Name  = filename,
                    },
                };

                blank.CopyMachineInformation(machine);

                // Now process and add the rom
                ParseAddHelper(blank, statsOnly);
            }
        }
Exemple #24
0
 public Archive Single(Archive archive)
 {
     return(Archives.SingleOrDefault(a => a.Month == archive.Month &&
                                     a.Year == archive.Year &&
                                     a.MonthYear == archive.MonthYear));
 }
Exemple #25
0
 /// <summary>
 ///   Handles the <see cref="TreeView.BeforeExpand" /> event of the source tree view.
 /// </summary>
 /// <remarks>
 ///   This handles retrieving the sub-files and sub-folders to display in the tree view.
 /// </remarks>
 /// <param name="sender">The object that triggered the event.</param>
 /// <param name="e">A <see cref="TreeViewCancelEventArgs" /> that describes the event arguments.</param>
 private void tvwSource_BeforeExpand(object sender, TreeViewCancelEventArgs e)
 {
   var crsOldCursor = Cursor;
   Cursor = Cursors.WaitCursor;
   foreach (FileSystemTreeNode tndFolder in e.Node.Nodes)
   {
     if (tndFolder.LastSource.IsLoaded || !tndFolder.IsDirectory)
     {
       continue;
     }
     tndFolder.LastSource.IsLoaded = true;
     string strPath = tndFolder.LastSource;
     if (strPath.StartsWith(Archive.ARCHIVE_PREFIX))
     {
       var kvpPath = Archive.ParseArchivePath(strPath);
       var arcArchive = new Archive(kvpPath.Key);
       var strFolders = arcArchive.GetDirectories(kvpPath.Value);
       foreach (var folder in strFolders)
       {
         addSourceFile(tndFolder, Archive.GenerateArchivePath(kvpPath.Key, folder));
       }
       var strFiles = arcArchive.GetFiles(kvpPath.Value);
       foreach (var file in strFiles)
       {
         addSourceFile(tndFolder, Archive.GenerateArchivePath(kvpPath.Key, file));
       }
     }
     else if (!strPath.StartsWith(FileSystemTreeNode.NEW_PREFIX))
     {
       var strFolders = Directory.GetDirectories(strPath);
       foreach (var folder in strFolders)
       {
         addSourceFile(tndFolder, folder);
       }
       var strFiles = Directory.GetFiles(strPath);
       foreach (var file in strFiles)
       {
         addSourceFile(tndFolder, file);
       }
     }
   }
   Cursor = crsOldCursor;
 }
Exemple #26
0
        private void downloadPage_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            var fileName = checkLocalCopy.Checked ? textBoxLocalPath.Text : textBoxDownloadUrl.Text;

            try
            {
                if (fileName.EndsWithIgnoreCase(@".exe"))
                {
                    switch (Msg.YesNoCancel(this, Resources.AskInstallerEXE, MsgSeverity.Info, Resources.YesInstallerExe, Resources.NoSingleExecutable))
                    {
                    case DialogResult.Yes:
                        OnInstaller();
                        break;

                    case DialogResult.No:
                        OnSingleFile();
                        break;

                    default:
                        e.Cancel = true;
                        break;
                    }
                }
                else
                {
                    switch (Archive.GuessMimeType(fileName))
                    {
                    case Archive.MimeTypeMsi:
                        OnInstaller();
                        break;

                    case null:
                        OnSingleFile();
                        break;

                    default:
                        OnArchive();
                        break;
                    }
                }
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                e.Cancel = true;
            }
            catch (ArgumentException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            catch (IOException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            catch (UnauthorizedAccessException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            catch (WebException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            catch (NotSupportedException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            #endregion
        }
Exemple #27
0
        public async Task ExecuteAsync(ICommandBuildMessage command)
        {
            Message message = new Message();

            MessageBuildModel messageBuildModel = command.ContentType.ContentTypeValue;
            MessageModel      messageModel      = messageBuildModel.Message;

            IdWorkflowActivity = messageBuildModel.IdWorkflowActivity;
            try
            {
                if (RetryPolicyEvaluation != null && !string.IsNullOrEmpty(RetryPolicyEvaluation.ReferenceModel))
                {
                    messageModel = JsonConvert.DeserializeObject <MessageModel>(RetryPolicyEvaluation.ReferenceModel, _serializerSettings);
                }

                else
                {
                    RetryPolicyEvaluation = new EvaluationModel();
                }


                //Attraverso le WebAPI comunicando col verbo POST col controller Rest Message creare l'entità Message con Status=MessageStatus.Draft
                #region Creazione Message in stato bozza


                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "ENTITY"))
                {
                    foreach (MessageContactModel model in messageModel.MessageContacts)
                    {
                        ICollection <MessageContactEmail> messageContactEmails = new List <MessageContactEmail>();
                        foreach (MessageContactEmailModel messageContactEmailModel in model.MessageContactEmail)
                        {
                            messageContactEmails.Add(new MessageContactEmail()
                            {
                                Description = messageContactEmailModel.Description,
                                Email       = messageContactEmailModel.Email,
                                User        = messageContactEmailModel.User
                            });
                        }
                        message.MessageContacts.Add(new MessageContact()
                        {
                            ContactPosition     = (MessageContactPosition)model.ContactPosition,
                            ContactType         = (DocSuiteWeb.Entity.Messages.MessageContactType)model.ContactType,
                            Description         = model.Description,
                            MessageContactEmail = messageContactEmails
                        });
                    }
                    foreach (MessageEmailModel model in messageModel.MessageEmails)
                    {
                        message.MessageEmails.Add(new MessageEmail()
                        {
                            Body                      = model.Body,
                            EmlDocumentId             = model.EmlDocumentId,
                            IsDispositionNotification = model.IsDispositionNotification,
                            Priority                  = model.Priority,
                            SentDate                  = model.SentDate,
                            Subject                   = model.Subject
                        });
                    }
                    message.MessageType = (DocSuiteWeb.Entity.Messages.MessageType)messageModel.MessageType;
                    message.Status      = DocSuiteWeb.Entity.Messages.MessageStatus.Draft;
                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = "ENTITY",
                        LocalReference = JsonConvert.SerializeObject(message, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == "ENTITY"); //Posso fare first direttamente perche sono nell else
                    message = JsonConvert.DeserializeObject <Message>(messageStatus.LocalReference);
                }
                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "ENTITY_CREATED"))
                {
                    message = await _webApiClient.PostEntityAsync(message);

                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = "ENTITY_CREATED",
                        LocalReference = JsonConvert.SerializeObject(message, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == "ENTITY_CREATED"); //Posso fare first direttamente perche sono nell else
                    message = JsonConvert.DeserializeObject <Message>(messageStatus.LocalReference);
                }

                #endregion

                //Attraverso il layer di BiblosDS salvare tutti gli allegati con relativa segnatura (metadato)

                #region Creazione Documenti Allegati (Attachments OPTIONAL)

                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "CREATE_ATTACHMENTS") && messageModel.MessageAttachments.Any(f => f.Document != null && f.Document.DocumentToStoreId.HasValue))
                {
                    //CREO CATENA IDENTIFICATIVA
                    Guid?   documentChainId;
                    Content documentContent;
                    List <AttributeValue> attachmentAttributeValues;

                    Archive messageArchive = _biblosArchives.Single(f => f.Name.Equals(_attachementLocation.ProtocolArchive, StringComparison.InvariantCultureIgnoreCase));
                    _logger.WriteDebug(new LogMessage($"biblos attachment archive name is {messageArchive.Name}"), LogCategories);

                    List <BiblosDS.BiblosDS.Attribute> attachmentAttributes = _biblosClient.Document.GetAttributesDefinition(messageArchive.Name);
                    int index = 0;

                    foreach (MessageAttachmentModel messageAttachmentModel in messageModel.MessageAttachments.Where(f => f.Document != null && !f.Document.DocumentId.HasValue && f.Document.DocumentToStoreId.HasValue))
                    {
                        //CREO CATENA IDENTIFICATIVA
                        documentChainId = messageAttachmentModel.Document.ChainId; //Fix

                        if (!documentChainId.HasValue)
                        {
                            documentChainId = _biblosClient.Document.CreateDocumentChain(messageArchive.Name, new List <AttributeValue>());
                        }

                        messageAttachmentModel.Document.ChainId = documentChainId;

                        if (!messageAttachmentModel.Document.DocumentId.HasValue)
                        {
                            attachmentAttributeValues = new List <AttributeValue>()
                            {
                                new AttributeValue()
                                {
                                    Attribute = attachmentAttributes.Single(f => f.Name.Equals(AttributeHelper.AttributeName_Filename, StringComparison.InvariantCultureIgnoreCase)),
                                    Value     = messageAttachmentModel.Document.FileName,
                                },
                                new AttributeValue()
                                {
                                    Attribute = attachmentAttributes.Single(f => f.Name.Equals(AttributeHelper.AttributeName_Signature, StringComparison.InvariantCultureIgnoreCase)),
                                    Value     = messageAttachmentModel.Document.Segnature,
                                }
                            };

                            _logger.WriteInfo(new LogMessage($"reading document content {messageAttachmentModel.Document.DocumentToStoreId} ..."), LogCategories);
                            documentContent = RetryingPolicyAction(() => _biblosClient.Document.GetDocumentContentById(messageAttachmentModel.Document.DocumentToStoreId.Value));

                            //CREO IL DOCUMENTO
                            Document attachmentCollaborationDocument = new Document
                            {
                                Archive = messageArchive,
                                Content = new Content {
                                    Blob = documentContent.Blob
                                },
                                Name            = messageAttachmentModel.Document.FileName,
                                IsVisible       = true,
                                AttributeValues = attachmentAttributeValues
                            };

                            //ASSOCIO IL DOCUMENTO ALLA SUA CATENA DI COMPETENZA
                            attachmentCollaborationDocument            = _biblosClient.Document.AddDocumentToChain(attachmentCollaborationDocument, documentChainId, ContentFormat.Binary);
                            messageAttachmentModel.Document.DocumentId = attachmentCollaborationDocument.IdDocument;
                            messageAttachmentModel.Archive             = messageArchive.Name;
                            messageAttachmentModel.DocumentEnum        = index++;

                            _logger.WriteDebug(new LogMessage($"biblos document {messageAttachmentModel.Document.FileName} archived into {messageArchive.Name}"), LogCategories);

                            message.MessageAttachments.Add(new MessageAttachment()
                            {
                                Archive      = messageAttachmentModel.Archive,
                                ChainId      = attachmentCollaborationDocument.IdBiblos.Value,
                                DocumentEnum = messageAttachmentModel.DocumentEnum,
                                Extension    = messageAttachmentModel.Extension
                            });

                            _logger.WriteInfo(new LogMessage($"reading document content {messageAttachmentModel.Document.DocumentToStoreId} ..."), LogCategories);
                            documentContent = RetryingPolicyAction(() => _biblosClient.Document.GetDocumentContentById(messageAttachmentModel.Document.DocumentToStoreId.Value));

                            //CREO IL DOCUMENTO
                            Document attachmentMessageDocument = new Document
                            {
                                Archive = messageArchive,
                                Content = new Content {
                                    Blob = documentContent.Blob
                                },
                                Name            = messageAttachmentModel.Document.FileName,
                                IsVisible       = true,
                                AttributeValues = attachmentAttributeValues
                            };

                            message.MessageLogs.Add(new MessageLog()
                            {
                                LogType = MessageLogType.Created, LogDescription = $"Allegato (Add): {messageAttachmentModel.Document.FileName}"
                            });
                        }
                    }
                    RetryPolicyEvaluation.Steps.Add(new StepModel()

                    {
                        Name           = "CREATE_ATTACHMENTS",
                        LocalReference = JsonConvert.SerializeObject(message, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.FirstOrDefault(f => f.Name == "CREATE_ATTACHMENTS");
                    if (messageStatus != null)
                    {
                        message = JsonConvert.DeserializeObject <Message>(messageStatus.LocalReference);
                    }
                }

                #endregion

                #region Aggiornare Message

                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "ENTITY_UPDATED"))
                {
                    message.Status = DocSuiteWeb.Entity.Messages.MessageStatus.Active;
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == "ENTITY_UPDATED");
                    message = JsonConvert.DeserializeObject <Message>(messageStatus.LocalReference);
                }
                if (!RetryPolicyEvaluation.Steps.Any(f => f.Name == "ENTITY_UPDATED"))
                {
                    message.WorkflowName         = messageBuildModel.WorkflowName;
                    message.IdWorkflowActivity   = messageBuildModel.IdWorkflowActivity;
                    message.WorkflowAutoComplete = messageBuildModel.WorkflowAutoComplete;
                    foreach (IWorkflowAction workflowAction in messageBuildModel.WorkflowActions)
                    {
                        message.WorkflowActions.Add(workflowAction);
                    }
                    message = await _webApiClient.PutEntityAsync(message);

                    RetryPolicyEvaluation.Steps.Add(new StepModel()
                    {
                        Name           = "ENTITY_UPDATED",
                        LocalReference = JsonConvert.SerializeObject(message, _serializerSettings)
                    });
                }
                else
                {
                    StepModel messageStatus = RetryPolicyEvaluation.Steps.First(f => f.Name == "ENTITY_UPDATED");
                    message = JsonConvert.DeserializeObject <Message>(messageStatus.LocalReference);
                }

                #endregion

                #region [ EventCompleteMessageBuild ]
                messageBuildModel.Message = messageModel;
                IEventCompleteMessageBuild eventCompleteMessageBuild = new EventCompleteMessageBuild(Guid.NewGuid(), messageBuildModel.UniqueId,
                                                                                                     command.TenantName, command.TenantId, command.TenantAOOId, command.Identity, messageBuildModel, null);
                if (!await _webApiClient.PushEventAsync(eventCompleteMessageBuild))
                {
                    _logger.WriteError(new LogMessage($"EventCompleteMessageBuild {message.GetTitle()} has not been sended"), LogCategories);
                    throw new Exception("IEventCompleteMessageBuild not sended");
                }
                _logger.WriteInfo(new LogMessage($"EventCompleteMessageBuild {eventCompleteMessageBuild.Id} has been sended"), LogCategories);
                #endregion

                #region Detach documenti archivio workflow
                foreach (MessageAttachmentModel attachment in messageModel.MessageAttachments.Where(f => f.Document != null && f.Document.DocumentToStoreId.HasValue))
                {
                    _logger.WriteInfo(new LogMessage($"detaching workflow document {attachment.Document.DocumentToStoreId} ..."), LogCategories);
                    RetryingPolicyAction(() => _biblosClient.Document.DocumentDetach(new Document()
                    {
                        IdDocument = attachment.Document.DocumentToStoreId.Value
                    }));
                }
                #endregion
            }
            catch (Exception ex)
            {
                RetryPolicyEvaluation.ReferenceModel = JsonConvert.SerializeObject(messageModel, _serializerSettings);

                _logger.WriteError(ex, LogCategories);
                throw new ServiceBusEvaluationException(RetryPolicyEvaluation);
            }
        }
Exemple #28
0
        private void buttonMnistTest_Click(object sender, EventArgs e)
        {
            if ((_bTestingThreadRuning == false) && (_bTrainingThreadRuning == false))
            {
                var  mutexs           = new List <Mutex>(2);
                int  theadsNum        = (int)numericUpDownThreads.Value;
                var  nnTesting        = (NNTestPatterns)null;;
                var  nnNetwork        = new NeuralNetwork();
                bool bDatabaseforTest = false;
                //create neural network
                try
                {
                    CreateNNNetWork(nnNetwork);
                    //initialize weight parameters to the network
                    if (_mnistWeightsFile != "")
                    {
                        _MainMutex.WaitOne();
                        var fsIn = new FileStream(_mnistWeightsFile, FileMode.Open);
                        var arIn = new Archive(fsIn, ArchiveOp.load);
                        nnNetwork.Serialize(arIn);
                        fsIn.Close();
                        _MainMutex.ReleaseMutex();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
                //
                if (radioButtonTestingdatabase.Checked)
                {
                    if (_bTestingDataReady)
                    {
                        nnTesting        = new NNTestPatterns(nnNetwork, _MinstTestingDatabase, _Preference, _bTestingDataReady, _EventTestingStopThread, _EventTestingThreadStopped, this, mutexs);
                        bDatabaseforTest = _bTestingDataReady;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (_bTrainingDataReady)
                    {
                        nnTesting        = new NNTestPatterns(nnNetwork, _MnistTrainingDatabase, _Preference, _bTrainingDataReady, _EventTestingStopThread, _EventTestingThreadStopped, this, mutexs);
                        bDatabaseforTest = _bTrainingDataReady;
                    }
                    else
                    {
                        return;
                    }
                }
                if (bDatabaseforTest)
                {
                    //
                    listBox2.Items.Clear();
                    for (int i = 0; i < 2; i++)
                    {
                        var mutex = new Mutex();
                        mutexs.Add(mutex);
                    }
                    _EventTestingStopThread.Reset();
                    _EventTestingThreadStopped.Reset();
                    _testing_threads = new List <Thread>(2);

                    try
                    {
                        for (int i = 0; i < theadsNum; i++)
                        {
                            var thread = new Thread(delegate()
                            {
                                nnTesting.PatternsTestingThread((int)numericUpDownNumberofTestPattern.Value);
                            });
                            _testing_threads.Add(thread);
                            thread.Start();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return;
                    }
                    _bTestingThreadRuning = true;
                    radioButtonTestingdatabase.Enabled  = false;
                    radioButtonTrainingdatabase.Enabled = false;
                    buttonMnistTest.Enabled             = false;
                }
            }
        }
Exemple #29
0
        private bool StartBackpropagation(uint iStartPattern /* =0 */, uint iNumThreads /* =2 */, double initialEta /* =0.005 */, double minimumEta /* =0.000001 */, double etaDecay /* =0.990 */,
                                          uint nAfterEvery /* =1000 */, bool bDistortPatterns /* =TRUE */, double estimatedCurrentMSE /* =1.0 */)
        {
            if (iNumThreads < 1)
            {
                iNumThreads = 1;
            }
            if (iNumThreads > 10)  // 10 is arbitrary upper limit
            {
                iNumThreads = 10;
            }
            //initialize BackPropagation before process
            _NN.m_etaLearningRate         = initialEta;
            _NN.m_etaLearningRatePrevious = initialEta;

            //run thread here
            _EventTrainingStopThread.Reset();
            _EventTrainingThreadStopped.Reset();
            _trainer_threads = new List <Thread>(2);
            _MnistTrainingDatabase.RandomizePatternSequence();
            //cleare mutex before run threads.
            var mutexs = new List <Mutex>(2);

            for (int i = 0; i < 4; i++)
            {
                Mutex mutex = new Mutex();
                mutexs.Add(mutex);
            }

            //create neural network
            try
            {
                CreateNNNetWork(_TrainingNN);
                //initialize weight parameters to the network
                if (_mnistWeightsFile != "")
                {
                    _MainMutex.WaitOne();
                    var fsIn = new FileStream(_mnistWeightsFile, FileMode.Open);
                    var arIn = new Archive(fsIn, ArchiveOp.load);
                    _TrainingNN.Serialize(arIn);
                    fsIn.Close();
                    _MainMutex.ReleaseMutex();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
            //
            var ntraining = new NNTrainPatterns(_TrainingNN, _MnistTrainingDatabase, _Preference, _bTrainingDataReady, _EventTrainingStopThread,
                                                _EventTrainingThreadStopped, this, mutexs)
            {
                m_dMinimumEta      = minimumEta, m_dEtaDecay = etaDecay, m_nAfterEveryNBackprops = nAfterEvery,
                m_bDistortPatterns = bDistortPatterns, m_dEstimatedCurrentMSE = estimatedCurrentMSE
                                                                                /* estimated number that will define whether a forward calculation's error is significant enough to warrant backpropagation*/ };

            for (int i = 0; i < iNumThreads; i++)
            {
                var trainer_thread = new Thread(ntraining.BackpropagationThread);
                trainer_thread.Name = String.Format("Thread{0}", i + 1);
                _trainer_threads.Add(trainer_thread);
                trainer_thread.Start();
            }

            return(true);
        }
 static bool CompareArchive(Archive a1, Archive a2)
 {
     return(a1.Hash.Equals(a2.Hash));
 }
 public void Remove(Archive archive)
 {
     Repo.Remove(archive);
 }
Exemple #32
0
        public static async Task <DownloadResult> DownloadWithPossibleUpgrade(Archive archive, AbsolutePath destination)
        {
            if (await Download(archive, destination))
            {
                var downloadedHash = await destination.FileHashCachedAsync();

                if (downloadedHash == archive.Hash || archive.Hash == default)
                {
                    return(DownloadResult.Success);
                }
            }


            if (await DownloadFromMirror(archive, destination))
            {
                await destination.FileHashCachedAsync();

                return(DownloadResult.Mirror);
            }

            if (!(archive.State is IUpgradingState))
            {
                Utils.Log($"Download failed for {archive.Name} and no upgrade from this download source is possible");
                return(DownloadResult.Failure);
            }

            Utils.Log($"Trying to find solution to broken download for {archive.Name}");

            var result = await FindUpgrade(archive);

            if (result == default)
            {
                result = await AbstractDownloadState.ServerFindUpgrade(archive);

                if (result == default)
                {
                    Utils.Log(
                        $"No solution for broken download {archive.Name} {archive.State.PrimaryKeyString} could be found");
                    return(DownloadResult.Failure);
                }
            }

            Utils.Log($"Looking for patch for {archive.Name} ({(long)archive.Hash} {archive.Hash.ToHex()} -> {(long)result.Archive!.Hash} {result.Archive!.Hash.ToHex()})");
            var patchResult = await ClientAPI.GetModUpgrade(archive, result.Archive !);

            Utils.Log($"Downloading patch for {archive.Name} from {patchResult}");

            var tempFile = new TempFile();

            if (WabbajackCDNDownloader.DomainRemaps.TryGetValue(patchResult.Host, out var remap))
            {
                var builder = new UriBuilder(patchResult)
                {
                    Host = remap
                };
                patchResult = builder.Uri;
            }

            using var response = await(await ClientAPI.GetClient()).GetAsync(patchResult);

            await tempFile.Path.WriteAllAsync(await response.Content.ReadAsStreamAsync());

            response.Dispose();

            Utils.Log($"Applying patch to {archive.Name}");
            await using (var src = await result.NewFile.Path.OpenShared())
                await using (var final = await destination.Create())
                {
                    Utils.ApplyPatch(src, () => tempFile.Path.OpenShared().Result, final);
                }

            var hash = await destination.FileHashCachedAsync();

            if (hash != archive.Hash && archive.Hash != default)
            {
                Utils.Log("Archive hash didn't match after patching");
                return(DownloadResult.Failure);
            }

            return(DownloadResult.Update);
        }
 public ControlDocumentFilesExists(Archive archive)
 {
     _workingDirectory = archive.WorkingDirectory.Content().DirectoryInfo();
 }
Exemple #34
0
 public override string GetManifestURL(Archive a)
 {
     return(Url);
 }
Exemple #35
0
 public override async Task <bool> Verify(Archive a, CancellationToken?token)
 {
     return(true);
 }
 public ControlExtraOrMissingFiles(AddmlDefinition addmlDefinition, Archive archive)
 {
     _addmlDefinition = addmlDefinition;
     _archive         = archive;
 }
Exemple #37
0
        private void InitUI()
        {
            //Populate selector for boot scripts
            BaseField field = Fields["bootFile"];
            var options = (UI_ChooseOption)field.uiControlEditor;

            var bootFiles = new List<string>();

            var temp = new Archive();
            var files = temp.GetFileList();
            var maxchoice = 0;
            bootFiles.Add("None");
            foreach (FileInfo file in files)
            {
                if (!file.Name.StartsWith("boot", StringComparison.InvariantCultureIgnoreCase)) continue;
                bootFiles.Add(file.Name);
                maxchoice++;
            }
            //no need to show the control if there are no files starting with boot
            options.controlEnabled = maxchoice > 0;
            field.guiActiveEditor = maxchoice > 0;
            options.options = bootFiles.ToArray();

            //populate diskSpaceUI selector
            diskSpaceUI = diskSpace.ToString();
            field = Fields["diskSpaceUI"];
            options = (UI_ChooseOption)field.uiControlEditor;
            var sizeOptions = new string[3];
            sizeOptions[0] = baseDiskSpace.ToString();
            sizeOptions[1] = (baseDiskSpace * 2).ToString();
            sizeOptions[2] = (baseDiskSpace * 4).ToString();
            options.options = sizeOptions;
        }
Exemple #38
0
        public void InitObjects()
        {
            shared = new SharedObjects();
            CreateFactory();

            shared.Vessel          = vessel;
            shared.Processor       = this;
            shared.KSPPart         = part;
            shared.UpdateHandler   = new UpdateHandler();
            shared.BindingMgr      = new BindingManager(shared);
            shared.Interpreter     = shared.Factory.CreateInterpreter(shared);
            shared.Screen          = shared.Interpreter;
            shared.ScriptHandler   = new KSScript();
            shared.Logger          = new KSPLogger(shared);
            shared.VolumeMgr       = shared.Factory.CreateVolumeManager(shared);
            shared.ConnectivityMgr = shared.Factory.CreateConnectivityManager();
            shared.ProcessorMgr    = new ProcessorManager();
            shared.FunctionManager = new FunctionManager(shared);
            shared.TransferManager = new TransferManager(shared);
            shared.Cpu             = new CPU(shared);
            shared.SoundMaker      = Sound.SoundMaker.Instance;
            shared.AddonManager    = new AddOns.AddonManager(shared);

            // Make the window that is going to correspond to this kOS part:
            var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow));

            DontDestroyOnLoad(gObj);
            shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow));
            shared.Window.AttachTo(shared);

            // initialize archive
            Archive = shared.Factory.CreateArchive();
            shared.VolumeMgr.Add(Archive);

            Messages = new MessageQueue();

            // initialize harddisk
            if (HardDisk == null)
            {
                HardDisk = new Harddisk(Mathf.Min(diskSpace, PROCESSOR_HARD_CAP));

                if (!string.IsNullOrEmpty(Tag))
                {
                    HardDisk.Name = Tag;
                }

                var path = BootFilePath;
                // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation:
                if (vessel.situation == Vessel.Situations.PRELAUNCH && path != null && !SafeHouse.Config.StartOnArchive)
                {
                    var bootVolumeFile = Archive.Open(BootFilePath) as VolumeFile;
                    if (bootVolumeFile != null)
                    {
                        if (HardDisk.SaveFile(BootFilePath, bootVolumeFile.ReadAll()) == null)
                        {
                            // Throwing an exception during InitObjects will break the initialization and won't show
                            // the error to the user.  So we just log the error instead.  At some point in the future
                            // it would be nice to queue up these init errors and display them to the user somewhere.
                            SafeHouse.Logger.LogError("Error copying boot file to local volume: not enough space.");
                        }
                    }
                }
            }

            shared.VolumeMgr.Add(HardDisk);

            // process setting
            if (!SafeHouse.Config.StartOnArchive)
            {
                shared.VolumeMgr.SwitchTo(HardDisk);
            }

            // initialize processor mode if different than READY
            if (ProcessorMode != ProcessorModes.READY)
            {
                ProcessorModeChanged();
            }

            InitProcessorTracking();
        }
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                var newApps     = new List <IApplication>();
                var newGestures = GestureManager.Instance.Gestures.ToList();
                try
                {
                    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                    foreach (var file in files)
                    {
                        switch (Path.GetExtension(file).ToLower())
                        {
                        case GestureSign.Common.Constants.ActionExtension:
                            var apps = FileManager.LoadObject <List <IApplication> >(file, false, true);
                            if (apps != null)
                            {
                                newApps.AddRange(apps);
                            }
                            break;

                        case ".exe":
                            lstAvailableApplication.SelectedItem = ApplicationManager.Instance.AddApplication(new UserApp(), file);
                            break;

                        case ".lnk":
                            WshShell     shell = new WshShell();
                            IWshShortcut link  = (IWshShortcut)shell.CreateShortcut(file);
                            if (Path.GetExtension(link.TargetPath).ToLower() == ".exe")
                            {
                                lstAvailableApplication.SelectedItem = ApplicationManager.Instance.AddApplication(new UserApp(), link.TargetPath);
                            }
                            break;

                        case GestureSign.Common.Constants.ArchivesExtension:
                        {
                            IEnumerable <IApplication> applications;
                            IEnumerable <IGesture>     gestures;
                            Archive.LoadFromArchive(file, out applications, out gestures);

                            if (applications != null)
                            {
                                newApps.AddRange(applications);
                            }
                            if (gestures != null)
                            {
                                foreach (var gesture in gestures)
                                {
                                    if (newGestures.Find(g => g.Name == gesture.Name) == null)
                                    {
                                        newGestures.Add(gesture);
                                    }
                                }
                            }
                            break;
                        }
                        }
                    }
                }
                catch (Exception exception)
                {
                    UIHelper.GetParentWindow(this).ShowModalMessageExternal(exception.GetType().Name, exception.Message);
                }
                if (newApps.Count != 0)
                {
                    Dispatcher.InvokeAsync(() =>
                    {
                        ExportImportDialog exportImportDialog = new ExportImportDialog(false, false, newApps, newGestures);
                        exportImportDialog.ShowDialog();
                    }, DispatcherPriority.Background);
                }
            }
            e.Handled = true;
        }
Exemple #40
0
            private async Task <Stream?> ResolveDownloadStream(Archive a)
            {
TOP:
                string url;

                if (IsAttachment)
                {
                    url = FullURL;
                }
                else
                {
                    var csrfURL = FileID == null
                        ? $"{Site}/files/file/{FileName}/?do=download"
                        : $"{Site}/files/file/{FileName}/?do=download&r={FileID}";
                    var html = await Downloader.AuthedClient.GetStringAsync(csrfURL);

                    var pattern = new Regex("(?<=csrfKey=).*(?=[&\"\'])|(?<=csrfKey: \").*(?=[&\"\'])");
                    var matches = pattern.Matches(html).Cast <Match>();

                    var csrfKey = matches.Where(m => m.Length == 32).Select(m => m.ToString()).FirstOrDefault();

                    if (csrfKey == null)
                    {
                        return(null);
                    }

                    var sep = Site.EndsWith("?") ? "&" : "?";
                    url = FileID == null
                        ? $"{Site}/files/file/{FileName}/{sep}do=download&confirm=1&t=1&csrfKey={csrfKey}"
                        : $"{Site}/files/file/{FileName}/{sep}do=download&r={FileID}&confirm=1&t=1&csrfKey={csrfKey}";
                }

                var streamResult = await Downloader.AuthedClient.GetAsync(url);

                if (streamResult.StatusCode != HttpStatusCode.OK)
                {
                    Utils.ErrorThrow(new InvalidOperationException(), $"{Downloader.SiteName} servers reported an error for file: {FileID}");
                }

                var contentType = streamResult.Content.Headers.ContentType;

                if (contentType.MediaType != "application/json")
                {
                    var  headerVar         = a.Size == 0 ? "1" : a.Size.ToString();
                    long headerContentSize = 0;
                    if (streamResult.Content.Headers.Contains("Content-Length"))
                    {
                        headerVar = streamResult.Content.Headers.GetValues("Content-Length").FirstOrDefault();
                        if (headerVar != null)
                        {
                            long.TryParse(headerVar, out headerContentSize);
                        }
                    }


                    if (a.Size != 0 && headerContentSize != 0 && a.Size != headerContentSize)
                    {
                        return(null);
                    }

                    return(await streamResult.Content.ReadAsStreamAsync());
                }

                // Sometimes LL hands back a json object telling us to wait until a certain time
                var times = (await streamResult.Content.ReadAsStringAsync()).FromJsonString <WaitResponse>();
                var secs  = times.Download - times.CurrentTime;

                for (int x = 0; x < secs; x++)
                {
                    Utils.Status($"Waiting for {secs} at the request of {Downloader.SiteName}", Percent.FactoryPutInRange(x, secs));
                    await Task.Delay(1000);
                }
                streamResult.Dispose();
                Utils.Status("Retrying download");
                goto TOP;
            }
Exemple #41
0
 /// <inheritdoc cref="IArchiveSerialization"/>
 /// <summary>
 /// Serializes the archive.
 /// </summary>
 /// <param name="archive">The archive.</param>
 /// <seealso cref="IArchiveSerialization"/>
 public void Serialize(Archive archive)
 {
 }
Exemple #42
0
 public override string GetManifestURL(Archive a)
 {
     return(IsAttachment ? FullURL : $"{Site}/files/file/{FileName}/?do=download&r={FileID}");
 }
Exemple #43
0
        private static void UnbundleTaskInner(string path, string outpath,
                                              string hash, string pattern, string regex)
        {
            #region checks

            if (string.IsNullOrEmpty(path))
            {
                logger.LogString("Please fill in an input path", Logtype.Error);
                return;
            }

            var inputFileInfo = new FileInfo(path);
            var inputDirInfo  = new DirectoryInfo(path);


            if (!inputFileInfo.Exists && !inputDirInfo.Exists)
            {
                logger.LogString("Input path does not exist", Logtype.Error);
                return;
            }

            if (inputFileInfo.Exists && inputFileInfo.Extension != ".archive")
            {
                logger.LogString("Input file is not an .archive", Logtype.Error);
                return;
            }
            else if (inputDirInfo.Exists && inputDirInfo.GetFiles().All(_ => _.Extension != ".archive"))
            {
                logger.LogString("No .archive file to process in the input directory", Logtype.Error);
                return;
            }

            var isDirectory = !inputFileInfo.Exists;
            var basedir     = inputFileInfo.Exists ? new FileInfo(path).Directory : inputDirInfo;

            #endregion

            List <FileInfo> archiveFileInfos;
            if (isDirectory)
            {
                var archiveManager = new ArchiveManager(basedir);
                // TODO: use the manager here?
                archiveFileInfos = archiveManager.Archives.Select(_ => new FileInfo(_.Value.ArchiveAbsolutePath)).ToList();
            }
            else
            {
                archiveFileInfos = new List <FileInfo> {
                    inputFileInfo
                };
            }


            foreach (var processedarchive in archiveFileInfos)
            {
                // get outdirectory
                DirectoryInfo outDir;
                if (string.IsNullOrEmpty(outpath))
                {
                    outDir = Directory.CreateDirectory(Path.Combine(
                                                           basedir.FullName,
                                                           processedarchive.Name.Replace(".archive", "")));
                }
                else
                {
                    outDir = new DirectoryInfo(outpath);
                    if (!outDir.Exists)
                    {
                        outDir = Directory.CreateDirectory(outpath);
                    }

                    if (inputDirInfo.Exists)
                    {
                        outDir = Directory.CreateDirectory(Path.Combine(
                                                               outDir.FullName,
                                                               processedarchive.Name.Replace(".archive", "")));
                    }
                }

                // read archive
                var ar = new Archive(processedarchive.FullName);

                var isHash = ulong.TryParse(hash, out ulong hashNumber);

                // run
                if (!isHash && File.Exists(hash))
                {
                    var hashlist = File.ReadAllLines(hash)
                                   .ToList().Select(_ => ulong.TryParse(_, out ulong res) ? res : 0);
                    logger.LogString($"Extracing all files from the hashlist ({hashlist.Count()}hashes) ...",
                                     Logtype.Normal);
                    foreach (var hash_num in hashlist)
                    {
                        ar.ExtractSingle(hash_num, outDir);
                        logger.LogString($" {ar.ArchiveAbsolutePath}: Extracted one file: {hash_num}", Logtype.Success);
                    }

                    logger.LogString($"Bulk extraction from hashlist file completed!", Logtype.Success);
                }
                else if (isHash && hashNumber != 0)
                {
                    ar.ExtractSingle(hashNumber, outDir);
                    logger.LogString($" {ar.ArchiveAbsolutePath}: Extracted one file: {hashNumber}", Logtype.Success);
                }
                else
                {
                    var r = ar.ExtractAll(outDir, pattern, regex);
                    logger.LogString($"{ar.ArchiveAbsolutePath}: Extracted {r.Item1.Count}/{r.Item2} files.",
                                     Logtype.Success);
                }
            }

            return;
        }
Exemple #44
0
        private IEnumerable<VolumePath> BootDirectoryFiles()
        {
            var result = new List<VolumePath>();

            var archive = new Archive(SafeHouse.ArchiveFolder);

            var path = VolumePath.FromString(BootDirectoryName);

            var bootDirectory = archive.Open(path) as VolumeDirectory;

            if (bootDirectory == null)
            {
                return result;
            }

            var files = bootDirectory.List();

            foreach (KeyValuePair<string, VolumeItem> pair in files)
            {
                if (pair.Value is VolumeFile && (pair.Value.Extension.Equals(Volume.KERBOSCRIPT_EXTENSION)
                    || pair.Value.Extension.Equals(Volume.KOS_MACHINELANGUAGE_EXTENSION)))
                {
                    result.Add(pair.Value.Path);
                }
            }

            return result;
        }
        protected virtual void Dispose(bool dispose)
        {
            AddManifest();

            Archive.Dispose();
        }
Exemple #46
0
 public PlayList(PlayListContent content, Archive archive)
 {
     Content = content;
     m_Archive = archive;
 }
Exemple #47
0
        private void buttonSelectArchivePath_Click(object sender, EventArgs e)
        {
            string filter = StringUtils.Join(@"|",
                                             ArchiveGenerator.SupportedMimeTypes.Select(x => string.Format(
                                                                                            @"{0} archive (*{0})|*{0}",
                                                                                            Archive.GetDefaultExtension(x))));

            using (var saveFileDialog = new SaveFileDialog {
                Filter = filter, FileName = textBoxArchivePath.Text
            })
            {
                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    textBoxArchivePath.Text = saveFileDialog.FileName;
                }
            }
        }
        public void CheckModArchives()
        {
            string[] modCacheArchives = null;
            string[] modRootArchives  = null;

            FileInfo fInfo = null;

            if (Directory.Exists(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory))
            {
                var DirectoriesList = Directory.EnumerateDirectories(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory, "*.*", SearchOption.AllDirectories).ToList();

                foreach (string DirRemoved in lstDirectories)
                {
                    if (!string.IsNullOrEmpty(DirRemoved))
                    {
                        DirectoriesList.RemoveAll(x => x.StartsWith(DirRemoved, StringComparison.InvariantCultureIgnoreCase));
                    }
                }

                foreach (string dir in DirectoriesList)
                {
                    if (!lstDirectories.Contains(dir))
                    {
                        var modArchives = Directory.EnumerateFiles(dir, "*.*", SearchOption.TopDirectoryOnly);

                        foreach (string archive in modArchives)
                        {
                            if (Archive.IsArchive(archive))
                            {
                                string[] result = archive.Split(new string[] { ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory + Path.DirectorySeparatorChar }, StringSplitOptions.None);
                                fInfo           = new FileInfo(archive);
                                ModArchivesSize = ModArchivesSize + fInfo.Length;
                                lstModArchives.Add(new BackupInfo(result[1], archive, "", Path.GetFileName(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory), fInfo.Length));
                            }
                        }
                    }
                }

                if (Directory.Exists(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory))
                {
                    modRootArchives = Directory.GetFiles(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory, "*.*", SearchOption.TopDirectoryOnly);
                }

                if (modRootArchives != null)
                {
                    foreach (string archive in modRootArchives)
                    {
                        if (Archive.IsArchive(archive))
                        {
                            fInfo           = new FileInfo(Path.Combine(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory, archive));
                            ModArchivesSize = ModArchivesSize + fInfo.Length;
                            lstModArchives.Add(new BackupInfo(Path.GetFileName(archive), Path.Combine(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory, archive), "", Path.GetFileName(ModManager.GameMode.GameModeEnvironmentInfo.ModDirectory), fInfo.Length));
                        }
                    }
                }
                if (Directory.Exists(ModManager.GameMode.GameModeEnvironmentInfo.ModCacheDirectory))
                {
                    modCacheArchives = Directory.GetFiles(ModManager.GameMode.GameModeEnvironmentInfo.ModCacheDirectory, "*.*", SearchOption.AllDirectories);
                }

                if (modCacheArchives != null)
                {
                    foreach (string file in modCacheArchives)
                    {
                        string[] result = file.Split(new string[] { ModManager.GameMode.GameModeEnvironmentInfo.ModCacheDirectory + Path.DirectorySeparatorChar }, StringSplitOptions.None);
                        fInfo           = new FileInfo(Path.Combine(ModManager.GameMode.GameModeEnvironmentInfo.ModCacheDirectory, file));
                        ModArchivesSize = ModArchivesSize + fInfo.Length;
                        lstModArchives.Add(new BackupInfo(result[1], file, "", Path.GetFileName(ModManager.GameMode.GameModeEnvironmentInfo.ModCacheDirectory), fInfo.Length));
                    }
                }
            }
        }
Exemple #49
0
 /// <summary>
 /// Downloads this file to the given destination location
 /// </summary>
 /// <param name="destination"></param>
 public abstract Task <bool> Download(Archive a, AbsolutePath destination);
Exemple #50
0
 public ArchiveNode(string text, Archive archive)
 {
     this.Text    = text;
     this.Archive = archive;
 }
 internal static Archive GenerateArchive(string response, int apiKey, string apiSecret, string apiUrl)
 {
     Archive archive = JsonConvert.DeserializeObject<Archive>(response);
     Archive archiveCopy = new Archive(new OpenTok(apiKey, apiSecret, apiUrl));
     archiveCopy.CopyArchive(archive);
     return archiveCopy;
 }
Exemple #52
0
        private static List <ShadowSpline> ReadShadowSplineFile(string fileName)
        {
            if (File.Exists(fileName))
            {
                byte[]       fileContents = File.ReadAllBytes(fileName);
                Archive      shadowDATONE = Archive.FromONEFile(ref fileContents);
                BinaryReader splineReader = null;

                foreach (var file in shadowDATONE.Files)
                {
                    if (file.Name == "PATH.PTP")
                    {
                        splineReader = new BinaryReader(new MemoryStream(file.DecompressThis()));
                        break;
                    }
                }

                if (splineReader == null)
                {
                    return(new List <ShadowSpline>());
                }

                try
                {
                    if (littleEndian)
                    {
                        DontSwitch = true;
                    }

                    List <ShadowSpline> splineList = new List <ShadowSpline>();

                    splineReader.BaseStream.Position = 0x4;
                    int sec5offset = Switch(splineReader.ReadInt32());
                    int sec5length = Switch(splineReader.ReadInt32());

                    splineReader.BaseStream.Position = 0x20;
                    List <int> offsetList = new List <int>();

                    int a = Switch(splineReader.ReadInt32());

                    while (a != 0)
                    {
                        offsetList.Add(a + 0x20);
                        a = Switch(splineReader.ReadInt32());
                    }

                    foreach (int i in offsetList)
                    {
                        splineReader.BaseStream.Position = i;

                        ShadowSpline spline         = new ShadowSpline();
                        int          amountOfPoints = Switch(splineReader.ReadInt32());

                        splineReader.BaseStream.Position += 8;

                        spline.Setting1 = splineReader.ReadByte();
                        spline.Setting2 = splineReader.ReadByte();
                        spline.Setting3 = splineReader.ReadByte();
                        spline.Setting4 = splineReader.ReadByte();

                        splineReader.BaseStream.Position += 0xC;

                        spline.SettingInt = Switch(splineReader.ReadInt32());

                        splineReader.BaseStream.Position += 0xC;

                        int nameOffset = Switch(splineReader.ReadInt32());

                        spline.Vertices = new ShadowSplineVertex[amountOfPoints];

                        for (int j = 0; j < amountOfPoints; j++)
                        {
                            ShadowSplineVertex vertex = new ShadowSplineVertex
                            {
                                Position = new Vector3(Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle())),
                                Rotation = new Vector3(Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle()), Switch(splineReader.ReadSingle()))
                            };
                            splineReader.BaseStream.Position += 0x4;
                            vertex.Unknown = Switch(splineReader.ReadInt32());

                            spline.Vertices[j] = vertex;
                        }

                        splineReader.BaseStream.Position = nameOffset + 0x20;
                        spline.Name = ReadString(splineReader);

                        splineList.Add(spline);
                    }

                    splineReader.BaseStream.Position = sec5offset + 0x20 + splineList.Count;

                    for (int i = 0; i < splineList.Count; i++)
                    {
                        byte byte0 = splineReader.ReadByte();

                        if (byte0 >= 0x80)
                        {
                            byte byte1 = splineReader.ReadByte();
                            splineList[i].UnknownSec5Bytes = new byte[] { byte0, byte1 };
                        }
                        else
                        {
                            splineList[i].UnknownSec5Bytes = new byte[] { byte0 }
                        };

                        splineReader.ReadByte();
                    }

                    splineReader.Close();

                    DontSwitch = false;
                    return(splineList);
                }
                catch
                {
                    littleEndian = true;
                    return(ReadShadowSplineFile(fileName));
                }
            }

            return(new List <ShadowSpline>());
        }
 internal ArchiveControl(Archive a)
 {
     InitializeComponent();
       archive = a;
       LoadFromData();
 }
Exemple #54
0
 public BSAFileEntry(Archive archive, int index)
     : base(archive, index)
 {
 }
Exemple #55
0
        public void InitObjects()
        {
            shared = new SharedObjects();

            shared.Vessel = vessel;
            shared.Processor = this;
            shared.KSPPart = part;
            shared.UpdateHandler = new UpdateHandler();
            shared.BindingMgr = new BindingManager(shared);
            shared.Interpreter = new Screen.ConnectivityInterpreter(shared);
            shared.Screen = shared.Interpreter;
            shared.ScriptHandler = new KSScript();
            shared.Logger = new KSPLogger(shared);
            shared.VolumeMgr = new ConnectivityVolumeManager(shared);
            shared.ProcessorMgr = new ProcessorManager();
            shared.FunctionManager = new FunctionManager(shared);
            shared.TransferManager = new TransferManager(shared);
            shared.Cpu = new CPU(shared);
            shared.AddonManager = new AddOns.AddonManager(shared);

            // Make the window that is going to correspond to this kOS part:
            var gObj = new GameObject("kOSTermWindow", typeof(Screen.TermWindow));
            DontDestroyOnLoad(gObj);
            shared.Window = (Screen.TermWindow)gObj.GetComponent(typeof(Screen.TermWindow));
            shared.Window.AttachTo(shared);
            shared.SoundMaker = shared.Window.GetSoundMaker();

            // initialize archive
            Archive = new Archive(SafeHouse.ArchiveFolder);
            shared.VolumeMgr.Add(Archive);

            Messages = new MessageQueue();

            // initialize harddisk
            if (HardDisk == null)
            {
                HardDisk = new Harddisk(diskSpace);

                if (!string.IsNullOrEmpty(Tag))
                {
                    HardDisk.Name = Tag;
                }

                var path = BootFilePath;
                // populate it with the boot file, but only if using a new disk and in PRELAUNCH situation:
                if (vessel.situation == Vessel.Situations.PRELAUNCH && path != null && !SafeHouse.Config.StartOnArchive)
                {
                    var bootVolumeFile = Archive.Open(BootFilePath) as VolumeFile;
                    if (bootVolumeFile != null)
                    {
                        if (HardDisk.SaveFile(BootFilePath, bootVolumeFile.ReadAll()) == null)
                        {
                            // Throwing an exception during InitObjects will break the initialization and won't show
                            // the error to the user.  So we just log the error instead.  At some point in the future
                            // it would be nice to queue up these init errors and display them to the user somewhere.
                            SafeHouse.Logger.LogError("Error copying boot file to local volume: not enough space.");
                        }
                    }
                }
            }

            shared.VolumeMgr.Add(HardDisk);

            // process setting
            if (!SafeHouse.Config.StartOnArchive)
            {
                shared.VolumeMgr.SwitchTo(HardDisk);
            }

            // initialize processor mode if different than READY
            if (ProcessorMode != ProcessorModes.READY)
            {
                ProcessorModeChanged();
            }

            InitProcessorTracking();
        }
Exemple #56
0
 public static async Task <(Archive?Archive, TempFile NewFile)> FindUpgrade(Archive a, Func <Archive, Task <AbsolutePath> >?downloadResolver = null)
 {
     downloadResolver ??= async a => default;
     return(await a.State.FindUpgrade(a, downloadResolver));
 }
Exemple #57
0
        private void InitUI()
        {
            //Populate selector for boot scripts
            BaseField field = Fields["bootFile"];
            var options = (UI_ChooseOption)field.uiControlEditor;

            var bootFiles = new List<VolumePath>();

            bootFiles.AddRange(BootDirectoryFiles());

            //no need to show the control if there are no available boot files
            options.controlEnabled = bootFiles.Count >= 1;
            field.guiActiveEditor = bootFiles.Count >= 1;
            var availableOptions = bootFiles.Select(e => e.ToString()).ToList();
            var availableDisplays = bootFiles.Select(e => e.Name).ToList();

            availableOptions.Insert(0, "None");
            availableDisplays.Insert(0, "None");

            var bootFilePath = BootFilePath; // store the selected path temporarily
            if (bootFilePath != null && !bootFiles.Contains(bootFilePath))
            {
                // if the path is not null ("None", null, or empty) and if it isn't in list of files
                var archive = new Archive(SafeHouse.ArchiveFolder);
                var file = archive.Open(bootFilePath) as VolumeFile;  // try to open the file as saved
                if (file == null)
                {
                    // check the same file name, but in the boot directory.
                    var path = VolumePath.FromString(BootDirectoryName).Combine(bootFilePath.Name);
                    file = archive.Open(path) as VolumeFile; // try to open the new path
                    if (file == null)
                    {
                        // try the file name without "boot" prefix
                        var name = bootFilePath.Name;
                        if (name.StartsWith("boot", StringComparison.OrdinalIgnoreCase) && name.Length > 4)
                        {
                            // strip the boot prefix and try that file name
                            name = name.Substring(4);
                            path = VolumePath.FromString(BootDirectoryName).Combine(name);
                            file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                            if (file == null)
                            {
                                // try the file name without "boot_" prefix
                                if (name.StartsWith("_", StringComparison.OrdinalIgnoreCase) && name.Length > 1)
                                {
                                    // only need to strip "_" here
                                    name = name.Substring(1);
                                    path = VolumePath.FromString(BootDirectoryName).Combine(name);
                                    file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                                }
                            }
                        }
                    }
                }

                // now, if we have a file object, use its values.
                if (file != null)
                {
                    // store the boot file information
                    bootFile = file.Path.ToString();
                    if (!bootFiles.Contains(file.Path))
                    {
                        availableOptions.Insert(1, bootFile);
                        availableDisplays.Insert(1, "*" + file.Path.Name); // "*" is indication the file is not normally available
                    }
                }
            }
            SafeHouse.Logger.SuperVerbose("bootFile: " + bootFile);

            options.options = availableOptions.ToArray();
            options.display = availableDisplays.ToArray();

            //populate diskSpaceUI selector
            diskSpaceUI = diskSpace.ToString();
            field = Fields["diskSpaceUI"];
            options = (UI_ChooseOption)field.uiControlEditor;
            var sizeOptions = new string[3];
            sizeOptions[0] = baseDiskSpace.ToString();
            sizeOptions[1] = (baseDiskSpace * 2).ToString();
            sizeOptions[2] = (baseDiskSpace * 4).ToString();
            options.options = sizeOptions;
        }
 public async Task Add(Archive archive)
 {
     await Repo.Add(archive);
 }
Exemple #59
0
        private void InitUI()
        {
            //Populate selector for boot scripts
            BaseField field   = Fields["bootFile"];
            var       options = (UI_ChooseOption)field.uiControlEditor;

            var bootFiles = new List <VolumePath>();

            bootFiles.AddRange(BootDirectoryFiles());

            //no need to show the control if there are no available boot files
            options.controlEnabled = bootFiles.Count >= 1;
            field.guiActiveEditor  = bootFiles.Count >= 1;
            var availableOptions  = bootFiles.Select(e => e.ToString()).ToList();
            var availableDisplays = bootFiles.Select(e => e.Name).ToList();

            availableOptions.Insert(0, "None");
            availableDisplays.Insert(0, "None");

            var bootFilePath = BootFilePath; // store the selected path temporarily

            if (bootFilePath != null && !bootFiles.Contains(bootFilePath))
            {
                // if the path is not null ("None", null, or empty) and if it isn't in list of files
                var archive = new Archive(SafeHouse.ArchiveFolder);
                var file    = archive.Open(bootFilePath) as VolumeFile; // try to open the file as saved
                if (file == null)
                {
                    // check the same file name, but in the boot directory.
                    var path = VolumePath.FromString(BootDirectoryName).Combine(bootFilePath.Name);
                    file = archive.Open(path) as VolumeFile; // try to open the new path
                    if (file == null)
                    {
                        // try the file name without "boot" prefix
                        var name = bootFilePath.Name;
                        if (name.StartsWith("boot", StringComparison.OrdinalIgnoreCase) && name.Length > 4)
                        {
                            // strip the boot prefix and try that file name
                            name = name.Substring(4);
                            path = VolumePath.FromString(BootDirectoryName).Combine(name);
                            file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                            if (file == null)
                            {
                                // try the file name without "boot_" prefix
                                if (name.StartsWith("_", StringComparison.OrdinalIgnoreCase) && name.Length > 1)
                                {
                                    // only need to strip "_" here
                                    name = name.Substring(1);
                                    path = VolumePath.FromString(BootDirectoryName).Combine(name);
                                    file = name.StartsWith(".") ? null : archive.Open(path) as VolumeFile;  // try to open the new path
                                }
                            }
                        }
                    }
                }

                // now, if we have a file object, use its values.
                if (file != null)
                {
                    // store the boot file information
                    bootFile = file.Path.ToString();
                    if (!bootFiles.Contains(file.Path))
                    {
                        availableOptions.Insert(1, bootFile);
                        availableDisplays.Insert(1, "*" + file.Path.Name); // "*" is indication the file is not normally available
                    }
                }
            }
            SafeHouse.Logger.SuperVerbose("bootFile: " + bootFile);

            options.options = availableOptions.ToArray();
            options.display = availableDisplays.ToArray();

            //populate diskSpaceUI selector
            diskSpaceUI = diskSpace.ToString();
            field       = Fields["diskSpaceUI"];
            options     = (UI_ChooseOption)field.uiControlEditor;
            var sizeOptions = new string[3];

            sizeOptions[0]  = baseDiskSpace.ToString();
            sizeOptions[1]  = (baseDiskSpace * 2).ToString();
            sizeOptions[2]  = (baseDiskSpace * 4).ToString();
            options.options = sizeOptions;
        }
 public override string?GetManifestURL(Archive a)
 {
     return(Url.ToString());
 }