Exemplo n.º 1
0
        private void NextButton_Click(object sender, EventArgs e)
        {
            switch (current_step)
            {
            case WizardStep.Introduction:
                ResetForm();
                SetupForm(WizardStep.ChooseAssemblies);
                break;

            case WizardStep.ChooseAssemblies:
                string msg = VerifyValidAssemblies();

                if (!string.IsNullOrEmpty(msg))
                {
                    MessageBox.Show(msg);
                }

                if (AssemblyListView.Items.Count == 0)
                {
                    MessageBox.Show("Please choose at least one assembly to analyze.");
                    return;
                }
                if (MonoVersionCombo.Items.Count == 0)
                {
                    MessageBox.Show("No definition files could be found.  Please try to download the latest definition file.");
                    return;
                }

                ScanningLabel.Visible   = true;
                ScanningSpinner.Visible = true;
                NextButton.Enabled      = false;
                BackButton.Enabled      = false;

                async_definitions = (FileDefinition)MonoVersionCombo.SelectedItem;
                async_assemblies  = (ListViewItem[])new ArrayList(AssemblyListView.Items).ToArray(typeof(ListViewItem));

                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork             += new DoWorkEventHandler(bw_DoWork);
                bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
                bw.RunWorkerAsync();

                return;

            case WizardStep.ViewResults:
                ResetForm();
                SetupForm(WizardStep.SubmitResults);
                break;

            case WizardStep.SubmitResults:
                ResetForm();
                SetupForm(WizardStep.WhatsNext);
                break;

            case WizardStep.WhatsNext:
                Application.Exit();
                break;
            }

            BackButton.Enabled = true;
        }
        public override FileActionStatus Save(FileDefinition fileDefinition, ContainerDefinition containerDefinition,
                                              FileCreateOptions fileCreateOptions,
                                              ContainerCreateOptions containerCreateOptions)
        {
            var status = new FileActionStatus();

            // If we aren't allowing auto creation of directories, fail
            if (!Directory.Exists(containerDefinition.Path) && !_createPathsAutomatically)
            {
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.NoAction +
                                 " Path does not exist, and config to create paths automatically is false.";
                return(status);
            }

            // Create directory if it doesn't exist
            Directory.CreateDirectory(containerDefinition.Path);

            var path = GetFullFilePath(fileDefinition, containerDefinition);

            // Overwrite based on provided option
            if (!fileCreateOptions.OverwriteExisting && File.Exists(path))
            {
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.NoAction +
                                 " File already exists; must explicitly set option to overwrite.";
                return(status);
            }

            SaveFile(path, fileDefinition.Data).Wait();

            status.Status  = Status.Success;
            status.Message = Constants.Messages.Success;
            return(status);
        }
        public override FileActionStatus Delete(FileDefinition fileDefinition, ContainerDefinition containerDefinition)
        {
            var status = new FileActionStatus();
            var path   = GetFullFilePath(fileDefinition, containerDefinition);

            // Fail early if file doesn't exist
            if (!File.Exists(path))
            {
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.FileDoesNotExist;
                return(status);
            }

            try
            {
                File.Delete(path);
                if (_removeEmptyPathsOnDelete)
                {
                    RemoveEmptyDirectories(containerDefinition.Path);
                }
            }
            catch (Exception)
            {
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.NoAction;
            }

            status.Status  = Status.Success;
            status.Message = Constants.Messages.Success;
            return(status);
        }
Exemplo n.º 4
0
 public GameMetadata(IGame gameData, FileDefinition icon, FileDefinition image, string background)
 {
     GameData        = gameData;
     Icon            = icon;
     Image           = image;
     BackgroundImage = background;
 }
Exemplo n.º 5
0
        private static void PopulateFileDefinition(XmlNode FileNode, FileDefinition fd, bool LoadOnlyFile)
        {
            fd.Label = AttributeValue(FileNode, "label");

            // set the column delimiter. requires special handling for TAB
            string ColumnDelimiter = AttributeValue(FileNode, "column-delimiter", "\t");

            if (ColumnDelimiter.Equals("\\t"))
            {
                ColumnDelimiter = "\t";
            }

            fd.ColumnDelimiter = Char.Parse(ColumnDelimiter);

            fd.CompressWhitespace = bool.Parse(AttributeValue(FileNode, "compress-whitespace", "false"));
            fd.IgnoreEmptyRows    = bool.Parse(AttributeValue(FileNode, "ignore-empty-rows", "true"));
            fd.TrimSpaces         = bool.Parse(AttributeValue(FileNode, "trim-spaces", "true"));
            fd.TrimSpaces         = bool.Parse(AttributeValue(FileNode, "strip-quotes", "true"));
            fd.SkipRows           = int.Parse(AttributeValue(FileNode, "skip-rows", "0"));

            // get the encoding text and lookup the encoding object
            string EncodingText = AttributeValue(FileNode, "encoding", "ISO-8859-1");

            fd.Encoding = System.Text.Encoding.GetEncoding(EncodingText);

            if (!LoadOnlyFile)
            {
                foreach (XmlNode RowNode in FileNode.SelectNodes("row"))
                {
                    RowDefinition rd = new RowDefinition(fd);
                    PopulateRowDefinition(RowNode, rd);
                    fd.RowDefinitions.Add(rd);
                }
            }
        }
Exemplo n.º 6
0
        public void FileDefinition_Constructor_PassingEmptyRootWorks()
        {
            var cfgTemplate = new DbTemplate("SitemapFileDefinition", FileDefinition.SitemapFileDefinitionID)
            {
                "FilenameToGenerate", "SourceDatabase", "RootItem", "LanguagesToInclude", "TemplatesToInclude"
            };
            var cfgItem = new DbItem("ExampleSitemapFileDefinition")
            {
                TemplateID = FileDefinition.SitemapFileDefinitionID,
                Fields     =
                {
                    { "FilenameToGenerate", "xyz" },
                    { "SourceDatabase",     ""    },
                    { "RootItem",           ""    },
                    { "LanguagesToInclude", ""    },
                    { "TemplatesToInclude", ""    }
                }
            };

            using (Db db = new Db
            {
                cfgTemplate,
                cfgItem
            })
            {
                Item cfg = db.GetItem("/sitecore/content/ExampleSitemapFileDefinition");
                Assert.IsNotNull(cfg);

                var sfd = new FileDefinition(cfg);

                Assert.AreEqual(Guid.Empty, sfd.RootItem);
            }
        }
Exemplo n.º 7
0
        public void FileDefinition_Constructor_LanguagesResolvedStartsFalseWhenParsing()
        {
            var cfgTemplate = new DbTemplate("SitemapFileDefinition", FileDefinition.SitemapFileDefinitionID)
            {
                "FilenameToGenerate", "SourceDatabase", "RootItem", "LanguagesToInclude", "TemplatesToInclude"
            };
            var home    = new DbItem("Home");
            var cfgItem = new DbItem("ExampleSitemapFileDefinition")
            {
                TemplateID = FileDefinition.SitemapFileDefinitionID,
                Fields     =
                {
                    { "FilenameToGenerate", "xyz"              },
                    { "SourceDatabase",     ""                 },
                    { "RootItem",           home.ID.ToString() },
                    { "LanguagesToInclude", ""                 },
                    { "TemplatesToInclude", ""                 }
                }
            };

            using (Db db = new Db
            {
                cfgTemplate,
                home,
                cfgItem
            })
            {
                Item cfg = db.GetItem("/sitecore/content/ExampleSitemapFileDefinition");
                Assert.IsNotNull(cfg);

                var sfd = new FileDefinition(cfg);

                Assert.AreEqual(false, sfd.LanguagesResolved);
            }
        }
Exemplo n.º 8
0
        public async Task <List <AddedFileDto> > AddUserPlantMediaAsync(List <AddFileDto> files, string userPlantId, string userId)
        {
            var path = $"{userId}\\{userPlantId}";

            var addedFiles = new List <AddedFileDto>();

            foreach (var file in files)
            {
                var fileName = $"{Guid.NewGuid().ToString()}{file.FileExtension}";

                var containerDefinition = new ContainerDefinition {
                    Name = "UserPlants", Path = path
                };
                var fileDefinition = new FileDefinition {
                    Name = fileName, Data = file.File
                };

                await _fileClient.SaveFile(containerDefinition, fileDefinition);

                var addedFile = new AddedFileDto
                {
                    FileName = fileName,
                    FilePath = path
                };
                addedFiles.Add(addedFile);
            }

            return(addedFiles);
        }
        private List <FileDefinition> LoadFileDefinitions(ProjectDefinition projectDefinition, XElement includeElement)
        {
            List <FileDefinition> list = new List <FileDefinition>();

            foreach (XElement file in includeElement.Descendants(PROJECT_FILE))
            {
                FileDefinition fileDefinition = new FileDefinition();

                fileDefinition.Enabled = bool.Parse(file.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...

                string tmpPath = file.Attribute(XName.Get(PROJECT_PATH)).Value;
                if (string.IsNullOrEmpty(tmpPath))
                {
                    Log.Warning("Empty file defined in project '" + projectDefinition.Name + "'.");
                    continue;
                }

                string path = null;
                if (tmpPath.StartsWith("*"))
                {
                    tmpPath = tmpPath.TrimStart('*');
                    path    = string.IsNullOrEmpty(tmpPath) ? projectDefinition.RootDirectory.Path : Path.GetFullPath(projectDefinition.RootDirectory.Path + tmpPath);

                    if (!File.Exists(path))
                    {
                        Log.Warning("Unable to find file '" + path + "' in project '" + projectDefinition.Name + "'.");
                        continue;
                    }
                }
                fileDefinition.Path = path;
                list.Add(fileDefinition);
            }
            return(list);
        }
Exemplo n.º 10
0
        public int AnalyzeNoGui()
        {
            RemoveIgnoredAssemblies();
            string msg = VerifyValidAssemblies();

            if (!string.IsNullOrEmpty(msg))
            {
                Console.WriteLine(msg);
            }

            async_definitions = (FileDefinition)MonoVersionCombo.SelectedItem;
            if (async_definitions == null)
            {
                Console.WriteLine("No language definition file found! Please run the GUI-version " +
                                  "to download the latest definition files.");
                return(1);
            }
            async_assemblies = (ListViewItem[])new ArrayList(AssemblyListView.Items).ToArray(typeof(ListViewItem));

            ScanningCompletedEventArgs e = AnalyzeAssemblies();
            int totalIssues = e.MissingMethodTotal + e.MonoTodoTotal + e.NotImplementedExceptionTotal + e.PInvokeTotal;

            if (totalIssues > 0)
            {
                Console.WriteLine(e.MissingMethodTotal + " Missing, " + e.MonoTodoTotal + " ToDo, " + e.NotImplementedExceptionTotal + " NotImplemented, " + e.PInvokeTotal + " PInvoke ");
                return(1);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 11
0
        public UrlSet Generate(FileDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            if (!definition.LanguagesResolved)
            {
                throw new ArgumentException("The SitemapFileDefinition passed has not resolved languages prior to sitemap generation.", "definition");
            }

            UrlSet urlSet = new UrlSet();

            if (definition.RootItem != Guid.Empty)
            {
                Database db = Sitecore.Configuration.Factory.GetDatabase(definition.SourceDatabase);

                Item rootItem = db.GetItem(new ID(definition.RootItem));

                process(rootItem, urlSet, definition);
            }

            return(urlSet);
        }
Exemplo n.º 12
0
        private static FileDefinition LoadFromXmlDocument(XmlDocument XmlDoc, bool LoadOnlyFile)
        {
            FileDefinition fd       = new FileDefinition();
            XmlNode        FileNode = XmlDoc.SelectSingleNode("file");

            PopulateFileDefinition(FileNode, fd, LoadOnlyFile);

            return(fd);
        }
Exemplo n.º 13
0
        public static FileDefinition CheckLatestVersionFromInternet()
        {
            MoMAWebService.MoMASubmit ws = new MoMA.Analyzer.MoMAWebService.MoMASubmit ();

            string result = ws.GetLatestDefinitionsVersion ();
            string[] results = result.Split ('|');

            FileDefinition fd = new FileDefinition (results[0], results[1], results[2]);

            return fd;
        }
Exemplo n.º 14
0
        public GameMetadata GetGameData(string gameId)
        {
            var            game  = GetParsedGame(ulong.Parse(gameId));
            FileDefinition image = null;

            if (!string.IsNullOrEmpty(game.Image))
            {
                var name = Path.GetFileName(game.Image);
                image = new FileDefinition($"images/custom/{name}", name, Web.DownloadData(game.Image));
            }

            return(new GameMetadata(game, null, image, string.Empty));
        }
Exemplo n.º 15
0
        internal void AddDocument(string filePath, string fileName)
        {
            Document = new FileDefinition()
            {
                FileName = fileName,
                Path     = filePath
            };

            if (!File.Exists(Document.Path))
            {
                Notify($"'{ Document.Path ?? "EMPTY" }' does not exist");
            }
        }
Exemplo n.º 16
0
        public void AnalyzeNoGui()
        {
            string msg = VerifyValidAssemblies();

            if (!string.IsNullOrEmpty(msg))
            {
                Console.WriteLine(msg);
            }

            async_definitions = (FileDefinition)MonoVersionCombo.SelectedItem;
            async_assemblies  = (ListViewItem[])new ArrayList(AssemblyListView.Items).ToArray(typeof(ListViewItem));

            ScanningCompletedEventArgs e = AnalyzeAssemblies();
        }
        private List <FileDefinition> LoadFileDefinitions(XElement includeElement)
        {
            List <FileDefinition> list = new List <FileDefinition>();

            foreach (XElement file in includeElement.Descendants(PROJECT_FILE))
            {
                FileDefinition fileDefinition = new FileDefinition();

                fileDefinition.Enabled = bool.Parse(file.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
                fileDefinition.Path    = file.Attribute(XName.Get(PROJECT_PATH)).Value;

                list.Add(fileDefinition);
            }
            return(list);
        }
Exemplo n.º 18
0
        public void FileDefinition_Constructor_PassingWrongItemTypeThrows()
        {
            using (Db db = new Db
            {
                new DbItem("Home")
                {
                    { "Title", "Welcome!" }
                }
            })
            {
                Item home = db.GetItem("/sitecore/content/home");

                var sfd = new FileDefinition(home);
            }
        }
Exemplo n.º 19
0
        private void process(Item itm, UrlSet urlSet, FileDefinition definition)
        {
            if (definition.TemplatesToInclude.Count == 0 || definition.TemplatesToInclude.Contains(itm.TemplateID.ToGuid()))
            {
                if (definition.LanguageCodesToInclude.Count == 0 || hasAValidLanguage(itm, definition.LanguageCodesToInclude))
                {
                    var url = makeUrl(itm, definition);
                    urlSet.Add(url);
                }
            }

            foreach (Item child in itm.Children)
            {
                process(child, urlSet, definition);
            }
        }
Exemplo n.º 20
0
        public override FileActionStatus Move(FileDefinition fileDefinition, ContainerDefinition containerDefinition,
                                              ContainerDefinition newContainerDefinition, string newFileName = null)
        {
            var status            = new FileActionStatus();
            var newFileDefinition = new FileDefinition {
                Name = newFileName ?? fileDefinition.Name
            };
            // Don't clone fileDefinition since we don't need the data here, just the name

            var oldPath = GetFullFilePath(fileDefinition, containerDefinition);
            var newPath = GetFullFilePath(newFileDefinition, newContainerDefinition);

            // Fail early if file doesn't exist
            if (!File.Exists(oldPath))
            {
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.FileDoesNotExist;
                return(status);
            }

            try
            {
                // If we aren't allowing auto creation of directories, fail
                if (!Directory.Exists(newContainerDefinition.Path) && !_createPathsAutomatically)
                {
                    status.Status  = Status.NoAction;
                    status.Message = Constants.Messages.NoAction +
                                     " Destination path does not exist, and config to create paths automatically is false.";
                    return(status);
                }
                Directory.CreateDirectory(newContainerDefinition.Path);
                File.Move(oldPath, newPath);
                if (_removeEmptyPathsOnMove)
                {
                    RemoveEmptyDirectories(containerDefinition.Path);
                }
            }
            catch (Exception)
            {
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.NoAction;
            }

            status.Status  = Status.Success;
            status.Message = Constants.Messages.Success;
            return(status);
        }
Exemplo n.º 21
0
        public DatFile(byte[] fileContents, FileDefinition fileDefinition)
        {
            FileDefinition = fileDefinition;
            using MemoryStream memoryStream = new MemoryStream(fileContents);
            using BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.Unicode);

            Count = binaryReader.ReadInt32();

            var recordLength      = FindRecordLength(binaryReader, Count);
            var dataSectionOffset = 4 + (Count * recordLength);

            binaryReader.BaseStream.Seek(dataSectionOffset, SeekOrigin.Begin);
            if (binaryReader.ReadUInt64() != MagicNumber)
            {
                throw new Exception($"Missing magic number after records.");
            }

            binaryReader.BaseStream.Seek(4, SeekOrigin.Begin);
            var records = new List <DatRecord>(Count);

            for (int i = 0; i < Count; i++)
            {
                Dictionary <string, object> values = new Dictionary <string, object>();
                for (int j = 0; j < fileDefinition.Fields.Length; j++)
                {
                    FieldDefinition fieldDefinition = fileDefinition.Fields[j];
                    try
                    {
                        values[fieldDefinition.ID] = fieldDefinition.DataType.ReadData(binaryReader, dataSectionOffset);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"Error: Row '{i}' FieldID '{fieldDefinition.ID}' DataType '{fieldDefinition.DataType.Name}',\n Message:{ex.Message}\n Stacktrace: {ex.StackTrace}");
                    }
                }
                int remainder = (int)(((4 + (i * recordLength)) + recordLength) - binaryReader.BaseStream.Position);
                if (remainder > 0)
                {
                    values["_Remainder"] = binaryReader.ReadBytes(remainder);
                }
                records.Add(new DatRecord(values));
            }

            Records = records;
        }
Exemplo n.º 22
0
        private void CheckUpdateLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FileDefinition fd = DefinitionHandler.CheckLatestVersionFromInternet();

            if (MonoVersionCombo.Items.Count == 0 || fd.Date > (MonoVersionCombo.Items[0] as FileDefinition).Date)
            {
                DefinitionDownloader dd = new DefinitionDownloader();
                dd.LoadDefinitionFile(fd);
                if (dd.ShowDialog() == DialogResult.OK)
                {
                    SetupMonoVersion();
                }
            }
            else
            {
                MessageBox.Show(string.Format("You have the most recent version: {0}", (MonoVersionCombo.Items[0] as FileDefinition).Version));
            }
        }
Exemplo n.º 23
0
        public void ExecuteTryReadExample()
        {
            // Create definitions
            var file = new FileDefinition {
                Name = "output.jpg"
            };
            var container = new ContainerDefinition {
                Path = @"C:/temp/nstore-test/photos"
            };

            // Save file
            byte[] output;
            var    status = _fileSystemRepository.TryRead(file, container, out output);

            // Done!
            Console.WriteLine("Attempting to read file \"{0}\" in {1}", file.Name, container.Path);
            Console.WriteLine("Read file from repository, total {0} KB", output.LongLength / 1024);
            Console.WriteLine(status.Message);
        }
Exemplo n.º 24
0
        public IEnumerable <FileDefinition> Fetch(Sitecore.Data.Database db)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            List <FileDefinition> defs = new List <FileDefinition>();

            Item definitionFolder = db.GetItem(SitemapDefinitionsFolderID);

            foreach (Item definition in definitionFolder.Children)
            {
                FileDefinition sd = new FileDefinition(definition);
                defs.Add(sd);
            }

            return(defs);
        }
Exemplo n.º 25
0
        public override FileActionStatus TryRead(FileDefinition fileDefinition, ContainerDefinition containerDefinition,
                                                 out byte[] data)
        {
            var status = new FileActionStatus();
            var path   = GetFullFilePath(fileDefinition, containerDefinition);

            try
            {
                data           = File.ReadAllBytes(path);
                status.Status  = Status.Success;
                status.Message = Constants.Messages.Success;
            }
            catch (Exception)
            {
                data           = null;
                status.Status  = Status.NoAction;
                status.Message = Constants.Messages.NoAction;
            }
            return(status);
        }
Exemplo n.º 26
0
        public void ExecuteSaveExample()
        {
            // Get some data
            var data = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "example-files/mountain-fog.jpg");

            // Create definitions
            var file = new FileDefinition {
                Name = "output.jpg", Data = data
            };
            var container = new ContainerDefinition {
                Path = @"C:/temp/nstore-test/photos"
            };

            // Save file
            var status = _fileSystemRepository.Save(file, container);

            // Done!
            Console.WriteLine("Attempting to save file \"{0}\" in {1}", file.Name, container.Path);
            Console.WriteLine(status.Message);
        }
Exemplo n.º 27
0
        public void ExecuteSaveExample()
        {
            // Get some data
            var data = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "example-files/mountain-fog.jpg");

            // Create definitions
            var file = new FileDefinition {
                Name = "output.jpg", Data = data
            };
            var container = new ContainerDefinition {
                Path = @"C:/temp/nstore-test/photos"
            };

            // File and container options
            var fileCreateOptions = Defaults <FileCreateOptions> .GetDefault();

            fileCreateOptions.OverwriteExisting = true;
            var containerCreateOptions = Defaults <ContainerCreateOptions> .GetDefault();

            containerCreateOptions.MakeFilesPublic = true;

            // Save file
            var status = _fileSystemRepository.Save(file, container, fileCreateOptions);

            Console.WriteLine("Attempting to save file \"{0}\" in {1}", file.Name, container.Path);
            Console.WriteLine(status.Message);

            // Let's move it too by specifying a new container (a clone of our container, actually) and a new name for the file
            var newContainer = new ContainerDefinition(container)
            {
                Path = "C:/temp/nstore-test2/photos"
            };
            var newFileName = "output-new.jpg";

            status = _fileSystemRepository.Move(file, container, newContainer, newFileName);

            Console.WriteLine("Attempting to move file \"{0}\" to {1} with new name \"{2}\"", file.Name,
                              newContainer.Path, newFileName);
            Console.WriteLine(status.Message);
        }
Exemplo n.º 28
0
        private Url makeUrl(Item itm, FileDefinition definition)
        {
            string url = LinkManager.GetItemUrl(itm);

            var u = new Url(url);

            foreach (var language in itm.Languages)
            {
                if (language.Name != itm.Language.Name)
                {
                    if (definition.LanguageCodesToInclude.Contains(language.Name))
                    {
                        var lngItm = itm.Database.GetItem(itm.ID, language);
                        if (lngItm != null && lngItm.Versions.Count > 0)
                        {
                            var alt = createAltUrl(itm, language);
                            u.AlternateUrls.Add(alt);
                        }
                    }
                }
            }

            ChangeFrequency cf;

            tryParseEnumField(itm, ChangeFrequencyFieldID, ChangeFrequency.Daily, out cf);
            u.ChangeFrequency = cf;

            float p;

            tryParseFloatField(itm, PriorityFieldID, 0.5f, out p);
            u.Priority = p;

            DateTime dt = DateTime.MinValue;

            tryParseDateTimeField(itm, FieldIDs.Updated, DateTime.MinValue, out dt);
            u.LastModified = dt;

            return(u);
        }
Exemplo n.º 29
0
        public int AnalyzeNoGui()
        {
            RemoveIgnoredAssemblies();
            string msg = VerifyValidAssemblies ();

            if (!string.IsNullOrEmpty (msg))
                Console.WriteLine (msg);

            async_definitions = (FileDefinition)MonoVersionCombo.SelectedItem;
            if (async_definitions == null){
                Console.WriteLine("No language definition file found! Please run the GUI-version "+
                                  "to download the latest definition files.");
                return 1;
            }
            async_assemblies = (ListViewItem[])new ArrayList (AssemblyListView.Items).ToArray (typeof (ListViewItem));

            ScanningCompletedEventArgs e = AnalyzeAssemblies ();
            int totalIssues = e.MissingMethodTotal + e.MonoTodoTotal + e.NotImplementedExceptionTotal + e.PInvokeTotal;
            if (totalIssues > 0){
                Console.WriteLine(e.MissingMethodTotal+" Missing, "+ e.MonoTodoTotal+" ToDo, " + e.NotImplementedExceptionTotal+" NotImplemented, "+e.PInvokeTotal+" PInvoke ");
                return 1;
            }
            else{
                return 0;
            }
        }
Exemplo n.º 30
0
        private static FileDefinition GetDefinitionFromFile(string s)
        {
            ZipInputStream zs = new ZipInputStream (File.OpenRead (s));
            ZipEntry ze;

            while ((ze = zs.GetNextEntry()) != null)
            {
                if (ze.Name == "version.txt")
                {
                    StreamReader sr = new StreamReader (zs);

                    FileDefinition fd = new FileDefinition ();

                    fd.Version = sr.ReadLine ();
                    string date = sr.ReadLine();

                    // Yes, this will fail in the year 2100, find one of my grandchildren to complain to...
                    fd.Date = new DateTime(int.Parse(date.Substring(6, 2)) + 2000, int.Parse(date.Substring(0, 2)), int.Parse(date.Substring(3, 2)));

                    fd.FileName = s;

                    sr.Close ();
                    zs.Close ();

                    return fd;
                }
            }

            return null;
        }
Exemplo n.º 31
0
        private void NextButton_Click(object sender, EventArgs e)
        {
            switch (current_step) {
                case WizardStep.Introduction:
                    ResetForm ();
                    SetupForm (WizardStep.ChooseAssemblies);
                    break;
                case WizardStep.ChooseAssemblies:
                    string msg = VerifyValidAssemblies ();

                    if (!string.IsNullOrEmpty (msg))
                        MessageBox.Show (msg);

                    if (AssemblyListView.Items.Count == 0) {
                        MessageBox.Show ("Please choose at least one assembly to analyze.");
                        return;
                    }
                    if (MonoVersionCombo.Items.Count == 0) {
                        MessageBox.Show ("No definition files could be found.  Please try to download the latest definition file.");
                        return;
                    }

                    ScanningLabel.Visible = true;
                    ScanningSpinner.Visible = true;
                    NextButton.Enabled = false;
                    BackButton.Enabled = false;

                    async_definitions = (FileDefinition)MonoVersionCombo.SelectedItem;
                    async_assemblies = (ListViewItem[])new ArrayList (AssemblyListView.Items).ToArray (typeof (ListViewItem));

                    BackgroundWorker bw = new BackgroundWorker();
                    bw.DoWork += new DoWorkEventHandler (bw_DoWork);
                    bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler (bw_RunWorkerCompleted);
                    bw.RunWorkerAsync ();

                    return;
                case WizardStep.ViewResults:
                    ResetForm ();
                    SetupForm (WizardStep.SubmitResults);
                    break;
                case WizardStep.SubmitResults:
                    ResetForm ();
                    SetupForm (WizardStep.WhatsNext);
                    break;
                case WizardStep.WhatsNext:
                    Application.Exit ();
                    break;
            }

            BackButton.Enabled = true;
        }
Exemplo n.º 32
0
        private List<FileDefinition> LoadFileDefinitions(ProjectDefinition projectDefinition, XElement includeElement)
        {
            List<FileDefinition> list = new List<FileDefinition>();

              foreach (XElement file in includeElement.Descendants(PROJECT_FILE))
              {
            FileDefinition fileDefinition = new FileDefinition();

            fileDefinition.Enabled = bool.Parse(file.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...

                string tmpPath = file.Attribute(XName.Get(PROJECT_PATH)).Value;
                if (string.IsNullOrEmpty(tmpPath))
                {
                    Log.Warning("Empty file defined in project '" + projectDefinition.Name + "'.");
                    continue;
                }

                string path = null;
                if (tmpPath.StartsWith("*"))
                {
                    tmpPath = tmpPath.TrimStart('*');
                    path = string.IsNullOrEmpty(tmpPath) ? projectDefinition.RootDirectory.Path : Path.GetFullPath(projectDefinition.RootDirectory.Path + tmpPath);

                    if (!File.Exists(path))
              {
                  Log.Warning("Unable to find file '" + path + "' in project '" + projectDefinition.Name + "'.");
                  continue;
              }
              }
              fileDefinition.Path = path;
                list.Add(fileDefinition);
              }
              return list;
        }
Exemplo n.º 33
0
        private List<FileDefinition> LoadFileDefinitions(XElement includeElement)
        {
            List<FileDefinition> list = new List<FileDefinition>();

              foreach (XElement file in includeElement.Descendants(PROJECT_FILE))
              {
            FileDefinition fileDefinition = new FileDefinition();

            fileDefinition.Enabled = bool.Parse(file.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
            fileDefinition.Path = file.Attribute(XName.Get(PROJECT_PATH)).Value;

            list.Add(fileDefinition);
              }
              return list;
        }
Exemplo n.º 34
0
        public async Task SkipExistingTest()
        {
            var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                db.AddGame(new Game("Game1")
                {
                    Description = "Description",
                    Developers  = new ComparableList <string>()
                    {
                        "Developers"
                    },
                    Genres = new ComparableList <string>()
                    {
                        "Genres"
                    },
                    Links = new ObservableCollection <Link>()
                    {
                        new Link("Link", "URL")
                    },
                    Publishers = new ComparableList <string>()
                    {
                        "Publishers"
                    },
                    ReleaseDate = new DateTime(2012, 6, 6),
                    Tags        = new ComparableList <string>()
                    {
                        "Tags"
                    },
                    Icon            = "Icon",
                    Image           = "Image",
                    BackgroundImage = "BackgroundImage",
                    UserScore       = 1,
                    CommunityScore  = 2,
                    CriticScore     = 3
                });

                var igdbProvider = new MockMetadataProvider
                {
                    GetSupportsIdSearchHandler = () => false,
                    GetGameDataHandler         = gameId =>
                    {
                        var game = new Game("IGDB Game " + gameId)
                        {
                            Description = $"IGDB Description {gameId}",
                            Developers  = new ComparableList <string>()
                            {
                                $"IGDB Developer {gameId}"
                            },
                            Genres = new ComparableList <string>()
                            {
                                $"IGDB Genre {gameId}"
                            },
                            Links = new ObservableCollection <Link>()
                            {
                                new Link($"IGDB link {gameId}", $"IGDB link url {gameId}")
                            },
                            Publishers = new ComparableList <string>()
                            {
                                $"IGDB publisher {gameId}"
                            },
                            ReleaseDate = new DateTime(2012, 6, 6),
                            Tags        = new ComparableList <string>()
                            {
                                $"IGDB Tag {gameId}"
                            }
                        };
                        var icon  = new FileDefinition($"IGDBIconPath{gameId}.file", $"IGDBIconName{gameId}.file", randomFile);
                        var image = new FileDefinition($"IGDBImagePath{gameId}.file", $"IGDBImageName{gameId}.file", randomFile);
                        return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}"));
                    },
                    SearchGamesHandler = gameName =>
                    {
                        return(new List <MetadataSearchResult>()
                        {
                            new MetadataSearchResult("igdbid1", "Game1", DateTime.Now)
                        });
                    }
                };

                var downloader = new MockMetadataDownloader(null, null, null, null, igdbProvider);
                var settings   = new MetadataDownloaderSettings()
                {
                    SkipExistingValues = true
                };

                // No download - all values are kept
                settings.ConfigureFields(MetadataSource.IGDB, true);
                await downloader.DownloadMetadata(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings);

                var dbGames = db.GamesCollection.FindAll().ToList();
                Assert.AreEqual(0, downloader.CallCount);

                var game1 = dbGames[0];
                Assert.AreEqual("Description", game1.Description);
                Assert.AreEqual("Developers", game1.Developers[0]);
                Assert.AreEqual("Genres", game1.Genres[0]);
                Assert.AreEqual("Link", game1.Links[0].Name);
                Assert.AreEqual("URL", game1.Links[0].Url);
                Assert.AreEqual("Publishers", game1.Publishers[0]);
                Assert.AreEqual("Tags", game1.Tags[0]);
                Assert.AreEqual(2012, game1.ReleaseDate.Value.Year);
                Assert.AreEqual("BackgroundImage", game1.BackgroundImage);
                Assert.AreEqual("Icon", game1.Icon);
                Assert.AreEqual("Image", game1.Image);

                // Single download - values are changed even when present
                settings.SkipExistingValues = false;
                await downloader.DownloadMetadata(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings);

                dbGames = db.GamesCollection.FindAll().ToList();
                Assert.AreEqual(1, downloader.CallCount);

                game1 = dbGames[0];
                Assert.AreEqual("IGDB Description igdbid1", game1.Description);
                Assert.AreEqual("IGDB Developer igdbid1", game1.Developers[0]);
                Assert.AreEqual("IGDB Genre igdbid1", game1.Genres[0]);
                Assert.AreEqual("IGDB link igdbid1", game1.Links[0].Name);
                Assert.AreEqual("IGDB link url igdbid1", game1.Links[0].Url);
                Assert.AreEqual("IGDB publisher igdbid1", game1.Publishers[0]);
                Assert.AreEqual("IGDB Tag igdbid1", game1.Tags[0]);
                Assert.AreEqual(2012, game1.ReleaseDate.Value.Year);
                Assert.AreEqual("IGDB backgournd igdbid1", game1.BackgroundImage);
                Assert.AreEqual($"IGDBIconPathigdbid1.file", game1.Icon);
                Assert.AreEqual($"IGDBImagePathigdbid1.file", game1.Image);

                // Single download - values are changed when skip enabled and values are not present
                downloader.CallCount        = 0;
                settings.SkipExistingValues = true;
                db.DeleteGame(game1);
                db.AddGame(new Game("Game1"));

                await downloader.DownloadMetadata(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings);

                dbGames = db.GamesCollection.FindAll().ToList();
                Assert.AreEqual(1, downloader.CallCount);

                game1 = dbGames[0];
                Assert.AreEqual("IGDB Description igdbid1", game1.Description);
                Assert.AreEqual("IGDB Developer igdbid1", game1.Developers[0]);
                Assert.AreEqual("IGDB Genre igdbid1", game1.Genres[0]);
                Assert.AreEqual("IGDB link igdbid1", game1.Links[0].Name);
                Assert.AreEqual("IGDB link url igdbid1", game1.Links[0].Url);
                Assert.AreEqual("IGDB publisher igdbid1", game1.Publishers[0]);
                Assert.AreEqual("IGDB Tag igdbid1", game1.Tags[0]);
                Assert.AreEqual(2012, game1.ReleaseDate.Value.Year);
                Assert.AreEqual("IGDB backgournd igdbid1", game1.BackgroundImage);
                Assert.AreEqual($"IGDBIconPathigdbid1.file", game1.Icon);
                Assert.AreEqual($"IGDBImagePathigdbid1.file", game1.Image);
            }
        }
Exemplo n.º 35
0
        public async Task IGDBSourceTest()
        {
            var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                var games = new List <Game>()
                {
                    new Game("Game1"),
                    new Game("Game2")
                    {
                        Provider = Provider.Steam, ProviderId = "Game2"
                    },
                    new Game("Game3") // just to test that nonexistent game doesn't throw exception
                };

                db.AddGames(games);

                var igdbProvider = new MockMetadataProvider
                {
                    GetSupportsIdSearchHandler = () => false,
                    GetGameDataHandler         = gameId =>
                    {
                        var game = new Game("IGDB Game " + gameId)
                        {
                            Description = $"IGDB Description {gameId}",
                            Developers  = new ComparableList <string>()
                            {
                                $"IGDB Developer {gameId}"
                            },
                            Genres = new ComparableList <string>()
                            {
                                $"IGDB Genre {gameId}"
                            },
                            Links = new ObservableCollection <Link>()
                            {
                                new Link($"IGDB link {gameId}", $"IGDB link url {gameId}")
                            },
                            Publishers = new ComparableList <string>()
                            {
                                $"IGDB publisher {gameId}"
                            },
                            ReleaseDate = new DateTime(2012, 6, 6),
                            Tags        = new ComparableList <string>()
                            {
                                $"IGDB Tag {gameId}"
                            }
                        };
                        var icon  = new FileDefinition($"IGDBIconPath{gameId}.file", $"IGDBIconName{gameId}.file", randomFile);
                        var image = new FileDefinition($"IGDBImagePath{gameId}.file", $"IGDBImageName{gameId}.file", randomFile);
                        return(new GameMetadata(game, icon, image, $"IGDB backgournd {gameId}"));
                    },
                    SearchGamesHandler = gameName =>
                    {
                        return(new List <MetadataSearchResult>()
                        {
                            new MetadataSearchResult("igdbid1", "Game1", DateTime.Now),
                            new MetadataSearchResult("igdbid2", "Game2", DateTime.Now)
                        });
                    }
                };

                var storeProvider = new MockMetadataProvider
                {
                    GetSupportsIdSearchHandler = () => true,
                    GetGameDataHandler         = (gameId) =>
                    {
                        var game = new Game(gameId);
                        return(new GameMetadata(game, null, null, string.Empty));
                    }
                };

                var downloader = new MockMetadataDownloader(storeProvider, storeProvider, storeProvider, storeProvider, igdbProvider);
                var settings   = new MetadataDownloaderSettings()
                {
                    SkipExistingValues = false
                };
                settings.ConfigureFields(MetadataSource.IGDB, true);
                await downloader.DownloadMetadata(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings);

                var dbGames = db.GamesCollection.FindAll().ToList();
                Assert.AreEqual(3, downloader.CallCount);
                var game1 = dbGames[0];
                Assert.AreEqual("IGDB Description igdbid1", game1.Description);
                Assert.AreEqual("IGDB Developer igdbid1", game1.Developers[0]);
                Assert.AreEqual("IGDB Genre igdbid1", game1.Genres[0]);
                Assert.AreEqual("IGDB link igdbid1", game1.Links[0].Name);
                Assert.AreEqual("IGDB link url igdbid1", game1.Links[0].Url);
                Assert.AreEqual("IGDB publisher igdbid1", game1.Publishers[0]);
                Assert.AreEqual("IGDB Tag igdbid1", game1.Tags[0]);
                Assert.AreEqual(2012, game1.ReleaseDate.Value.Year);
                Assert.AreEqual("IGDB backgournd igdbid1", game1.BackgroundImage);
                Assert.AreEqual($"IGDBIconPathigdbid1.file", game1.Icon);
                Assert.AreEqual($"IGDBImagePathigdbid1.file", game1.Image);
                var game2 = dbGames[1];
                Assert.AreEqual("IGDB Description igdbid2", game2.Description);

                Assert.AreEqual(4, db.Database.FileStorage.FindAll().Count());
            }
        }
Exemplo n.º 36
0
        public async Task StoreSourceTest()
        {
            var path = Path.Combine(PlayniteTests.TempPath, "metadownload.db");

            FileSystem.DeleteFile(path);

            var db = new GameDatabase(null);

            using (db.OpenDatabase(path))
            {
                var games = new List <Game>()
                {
                    new Game("Game1"),
                    new Game("Game2")
                    {
                        Provider = Provider.Steam, ProviderId = "storeId"
                    },
                    new Game("Game3") // just to test that nonexistent game doesn't throw exception
                };

                db.AddGames(games);

                var igdbProvider  = new MockMetadataProvider();
                var storeProvider = new MockMetadataProvider
                {
                    GetSupportsIdSearchHandler = () => true,
                    GetGameDataHandler         = (gameId) =>
                    {
                        var game = new Game("Store Game " + gameId)
                        {
                            Description = $"Store Description {gameId}",
                            Developers  = new ComparableList <string>()
                            {
                                $"Store Developer {gameId}"
                            },
                            Genres = new ComparableList <string>()
                            {
                                $"Store Genre {gameId}"
                            },
                            Links = new ObservableCollection <Link>()
                            {
                                new Link($"Store link {gameId}", $"Store link url {gameId}")
                            },
                            Publishers = new ComparableList <string>()
                            {
                                $"Store publisher {gameId}"
                            },
                            ReleaseDate = new DateTime(2016, 2, 2),
                            Tags        = new ComparableList <string>()
                            {
                                $"Store Tag {gameId}"
                            }
                        };
                        var icon  = new FileDefinition($"StoreIconPath{gameId}.file", $"StoreIconName{gameId}.file", randomFile);
                        var image = new FileDefinition($"StoreImagePath{gameId}.file", $"StoreImageName{gameId}.file", randomFile);
                        return(new GameMetadata(game, icon, image, $"Store backgournd {gameId}"));
                    }
                };

                var downloader = new MockMetadataDownloader(storeProvider, storeProvider, storeProvider, storeProvider, igdbProvider);
                var settings   = new MetadataDownloaderSettings()
                {
                    SkipExistingValues = false
                };
                settings.ConfigureFields(MetadataSource.Store, true);
                await downloader.DownloadMetadata(
                    db.GamesCollection.FindAll().ToList(),
                    db, settings);

                var dbGames = db.GamesCollection.FindAll().ToList();
                Assert.AreEqual(1, downloader.CallCount);
                var game2 = dbGames[1];
                Assert.AreEqual("Store Description storeId", game2.Description);
                Assert.AreEqual("Store Developer storeId", game2.Developers[0]);
                Assert.AreEqual("Store Genre storeId", game2.Genres[0]);
                Assert.AreEqual("Store link storeId", game2.Links[0].Name);
                Assert.AreEqual("Store link url storeId", game2.Links[0].Url);
                Assert.AreEqual("Store publisher storeId", game2.Publishers[0]);
                Assert.AreEqual("Store Tag storeId", game2.Tags[0]);
                Assert.AreEqual(2016, game2.ReleaseDate.Value.Year);
                Assert.AreEqual("Store backgournd storeId", game2.BackgroundImage);
                Assert.AreEqual($"StoreIconPathstoreId.file", game2.Icon);
                Assert.AreEqual($"StoreImagePathstoreId.file", game2.Image);
                var game1 = dbGames[0];
                Assert.IsNull(game1.Description);

                Assert.AreEqual(2, db.Database.FileStorage.FindAll().Count());
            }
        }
Exemplo n.º 37
0
 /// <summary>
 ///     Constructor used for cloning
 /// </summary>
 /// <param name="fileDefinition"></param>
 public FileDefinition(FileDefinition fileDefinition)
 {
     Name = fileDefinition.Name;
     Data = fileDefinition.Data;
 }
Exemplo n.º 38
0
        public void AnalyzeNoGui()
        {
            string msg = VerifyValidAssemblies ();

            if (!string.IsNullOrEmpty (msg))
                Console.WriteLine (msg);

            async_definitions = (FileDefinition)MonoVersionCombo.SelectedItem;
            async_assemblies = (ListViewItem[])new ArrayList (AssemblyListView.Items).ToArray (typeof (ListViewItem));

            ScanningCompletedEventArgs e = AnalyzeAssemblies ();
        }