Ejemplo n.º 1
0
        public string SerializeObject(ObjectToSerialize obj)
        {
            var options = new JsonSerializerOptions();

            options.Converters.Add(new DoubleConverter());
            return(System.Text.Json.JsonSerializer.Serialize(obj, options));
        }
Ejemplo n.º 2
0
    public void LoadGame()
    {
        if (!PlayerPrefs.HasKey("saveData"))
        {
            return;
        }

        foreach (var srlObj in placedPrefabList)
        {
            if (srlObj.gObject != null)
            {
                Destroy(srlObj.gObject);
            }
        }

        placedPrefabList.Clear();
        foreach (var stringObject in PlayerPrefs.GetString("saveData").Split('&'))
        {
            Debug.Log(stringObject);
            var newSpawnedObject = ObjectToSerialize.fromString(stringObject);
            Debug.Log(string.Format("({0}, {1}, {2}, {3})", newSpawnedObject.x, newSpawnedObject.y, newSpawnedObject.z, newSpawnedObject.prefabType));

            spawnedObject            = Instantiate(getPrefabByID(newSpawnedObject.prefabType), new Vector3(newSpawnedObject.x, newSpawnedObject.y, newSpawnedObject.z), Quaternion.identity);
            newSpawnedObject.gObject = spawnedObject;
            placedPrefabList.Add(newSpawnedObject);
        }
    }
Ejemplo n.º 3
0
 public PropertyNames()
 {
     _toTest         = new ObjectToSerialize();
     _db             = new ArangoDatabase();
     _docSerializer  = new DocumentSerializer(_db);
     _jsonSerializer = _docSerializer.CreateJsonSerializer();
 }
Ejemplo n.º 4
0
        private void ExecuteDelete(object parameter)
        {
            if (MessageBox.Show("Do you want to delete this nozzle pattern?", "Delete Nozzle Pattern", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK)
            {
                string _selectednozzle = (string)parameter;

                _nozzlepatterns.RemoveAt(FindNozzleIndex((string)_selectednozzle));
                //save entire list
                ObjectToSerialize objectToSerialize = new ObjectToSerialize
                {
                    NozzlePatterns = _nozzlepatterns
                };
                Serializer serializer = new Serializer();
                serializer.SerializeObject <ObjectToSerialize>(Constants._nozzlefilename, objectToSerialize);

                _nozzlenames.Remove(_selectednozzle);
                SprayDesigner = new YankeeShower.Views.SprayDesigner(100, 100, 30);

                NozzleType _t = new NozzleType();
                foreach (NozzleType n in NozzleTypes)
                {
                    if (n.NozzleTypeName == _selectednozzle)
                    {
                        _t = n;
                        break;
                    }
                }
                NozzleTypes.Remove(_t);

                //  NozzleTypes.Remove()
                // StaticData.CreateNozzleList();
                //      ViewModels.ShowerVM.UpdateNozzleTypes();
                //ViewModels.NozzleSettingsVM.UpdateNozzleTypes();
            }
        }
 public void SerializeObject(string filename, ObjectToSerialize objectToSerialize)
 {
     Stream stream = File.Open(filename, FileMode.Create);
     BinaryFormatter bFormatter = new BinaryFormatter();
     bFormatter.Serialize(stream, objectToSerialize);
     stream.Close();
 }
Ejemplo n.º 6
0
    private void SpawnPrefab(Vector3 position, bool onRayCast)
    {
        var newPosition = new Vector3(
            Mathf.Round(position.x / this.gridSize.x) * this.gridSize.x,
            position.y,
            Mathf.Round(position.z / this.gridSize.z) * this.gridSize.z
            );

        if (!onRayCast)
        {
            if (this.baseY == null)
            {
                this.baseY = position.y;
            }
            newPosition.y = (float)this.baseY + 0.1F;
        }

        spawnedObject = Instantiate(placablePrefab, newPosition, Quaternion.identity);

        var serializedSpawnedObject = new ObjectToSerialize(newPosition, this.prefabID);

        serializedSpawnedObject.SetGameObject(spawnedObject);

        placedPrefabList.Add(serializedSpawnedObject);
        placedPrefabCount++;
    }
Ejemplo n.º 7
0
    public void SerializeObject(string filename, ObjectToSerialize objectToSerialize)
    {
        Stream          stream     = File.Open(filename, FileMode.Create);
        BinaryFormatter bFormatter = new BinaryFormatter();

        bFormatter.Serialize(stream, objectToSerialize);
        stream.Close();
    }
Ejemplo n.º 8
0
        public string SerializeObject(ObjectToSerialize obj)
        {
#if NETCORE3_0 || NETCORE3_1
            return(System.Text.Json.JsonSerializer.Serialize(obj));
#endif
#if NETCORE2_1
            return(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
#endif
        }
        public static void SaveMedia(List <Media> mediaList)
        {
            List <Media> newMediaList = mediaList;

            ObjectSerializer  serializer         = new ObjectSerializer();
            ObjectToSerialize newSerializedMedia = new ObjectToSerialize();

            newSerializedMedia.Media = newMediaList;
            serializer.SerializeObject("media.txt", newSerializedMedia);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// When the main form closes the settings data is serialised.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ObjectToSerialize objectToSerialize = new ObjectToSerialize();

            objectToSerialize.Queries.Add(this.localityQuerySetupPanel1.Settings);
            objectToSerialize.Queries.Add(this.localityQuerySetupPanel2.Settings);

            Serializer serializer = new Serializer();

            serializer.SerializeObject(USER_SETTINGS_PATH, objectToSerialize);
        }
Ejemplo n.º 11
0
        public void loadList()
        {
            // Get history
            downloadedTrailers = new List<string>();
            trailerDBobject = new ObjectToSerialize();
            Serializer serializer = new Serializer();
            trailerDBobject = serializer.DeSerializeObject(Application.StartupPath + "\\trailerDB.txt");
            downloadedTrailers = trailerDBobject.DownloadedTrailers;

            historyListBox.DataSource = downloadedTrailers;
        }
Ejemplo n.º 12
0
        public void loadList()
        {
            // Get history
            downloadedTrailers = new List <string>();
            trailerDBobject    = new ObjectToSerialize();
            Serializer serializer = new Serializer();

            trailerDBobject    = serializer.DeSerializeObject(Application.StartupPath + "\\trailerDB.txt");
            downloadedTrailers = trailerDBobject.DownloadedTrailers;

            historyListBox.DataSource = downloadedTrailers;
        }
        public static List <Media> GetMediaList()
        {
            ObjectSerializer  serializer      = new ObjectSerializer();
            ObjectToSerialize serializedMedia = new ObjectToSerialize();

            serializedMedia = serializer.DeSerializeObject("media.txt");

            List <Media> mediaFromFile = new List <Media>();

            mediaFromFile = serializedMedia.Media;

            return(mediaFromFile);
        }
Ejemplo n.º 14
0
        public NozzlePatternVM(FullyObservableCollection <NozzleType> _noztypes)
        {
            _nozzlepatterns = new List <Pattern>();
            _nozzlenames    = new ObservableCollection <string>();
            NozzleTypes     = _noztypes;

            try
            {
                if (File.Exists(Constants._nozzlefilename))
                {
                    ObjectToSerialize objectToSerialize = new ObjectToSerialize();
                    Serializer        serializer        = new Serializer();
                    objectToSerialize = serializer.DeSerializeObject <ObjectToSerialize>(Constants._nozzlefilename);
                    _nozzlepatterns   = objectToSerialize.NozzlePatterns;

                    if (_nozzlepatterns.Count > 0)
                    {
                        _spraydesigner = new YankeeShower.Views.SprayDesigner(100, 100, 30)
                        {
                            Spray = (int[])_nozzlepatterns[0].PPattern.Clone()
                        };

                        SprayDesigner = _spraydesigner;

                        //populate combo

                        for (int i = 0; i < _nozzlepatterns.Count; i++)
                        {
                            _nozzlenames.Add(_nozzlepatterns[i].PName);
                        }
                        SelectedNozzle = _nozzlepatterns[0].PName;
                    }
                }
                else
                {
                    MessageBox.Show("The nozzle pattern file cannot be found.", "File missing", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    CloseWindowFlag = true;
                }
            }
            catch
            {
                MessageBox.Show("The nozzle pattern file cannot be loaded.", "Unable to load file", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                CloseWindowFlag = true;
            }

            NewSprayPattern    = new RelayCommand(ExecuteNew, CanExecuteNew);
            SaveSprayPattern   = new RelayCommand(ExecuteSave, CanExecuteSave);
            SaveAsSprayPattern = new RelayCommand(ExecuteSaveAs, CanExecuteSaveAs);
            DeleteSprayPattern = new RelayCommand(ExecuteDelete, CanExecuteDelete);
        }
Ejemplo n.º 15
0
 public static void RunFile(string filePath, int times)
 {
     try
     {
         isCancel = false;
         ObjectToSerialize ots    = DeSerializeObject(filePath);
         Thread            thread = new Thread(() => WorkThreadFunction(ots.Events, times));
         thread.Start();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 16
0
        private void DeserializeSettings()
        {
            Serializer serializer = new Serializer();

            try
            {
                ObjectToSerialize objectToSerialize = serializer.DeSerializeObject(USER_SETTINGS_PATH);

                this.localityQuerySetupPanel1.Settings = (UserQuerySettings)objectToSerialize.Queries[0];
                this.localityQuerySetupPanel2.Settings = (UserQuerySettings)objectToSerialize.Queries[1];
            }
            catch (System.Runtime.Serialization.SerializationException)
            {
                Console.WriteLine("There was an error reading the user settings file. \nDefault settings have been used instead.");
            }
        }
        public static bool AddMediaToNewList(Media m)
        {
            bool         success  = false;
            List <Media> mediaNew = new List <Media>();

            mediaNew.Add(m);

            ObjectSerializer  serializer     = new ObjectSerializer();
            ObjectToSerialize serializeMedia = new ObjectToSerialize();

            serializeMedia.Media = mediaNew;
            serializer.SerializeObject("media.txt", serializeMedia);
            success = true;

            return(success);
        }
        public string Serialize()
        {
            var hostObject = new ObjectToSerialize
            {
                StringProperty = "Some string",
                IntProperty    = 999,
                DoubleProperty = 4336.99d
            };

            try
            {
                return(this.plugin.SerializeObject(hostObject));
            }
            catch (NotSupportedException nex)
            {
                return(nex.Message);
            }
        }
Ejemplo n.º 19
0
        private Pattern SaveNozzlePattern(string _nozzlename, int _indx)
        {
            if (_nozzlepatterns == null)
            {
                _nozzlepatterns = new List <Pattern>();
            }

            Pattern p = new Pattern();

            if (_indx > -1)
            {
                p = _nozzlepatterns[_indx];
            }
            p.PName = _nozzlename;

            int[] _spray = new int[SprayDesigner.Spray.Length];  //??
            _spray = SprayDesigner.Spray;

            for (int i = 0; i < _spray.Length; i++)
            {
                p.PPattern[i] = _spray[i];
            }

            if (_indx == -1)
            {
                _nozzlepatterns.Add(p);
            }

            //save entire list
            ObjectToSerialize objectToSerialize = new ObjectToSerialize
            {
                NozzlePatterns = _nozzlepatterns
            };
            Serializer serializer = new Serializer();

            serializer.SerializeObject <ObjectToSerialize>(Constants._nozzlefilename, objectToSerialize);

            return(p);
        }
 public string SerializeObject(ObjectToSerialize obj)
 {
     return(System.Text.Json.JsonSerializer.Serialize(obj));
 }
Ejemplo n.º 21
0
        // Thread to scan
        private void runwork()
        {
            // Log in again
            if (!login())
            {
                SetStatus(statusWindow, "Will try to log on again in 10 seconds");
                hourTimer.Change(10000, 1000 * 60 * 60 * 4);
                scanner.Abort();
            }

            try
            {
                // List to save movies to db file
                List<string> downloadedTrailers = new List<string>();
                ObjectToSerialize trailerDBobject = new ObjectToSerialize();
                trailerDBobject.DownloadedTrailers = downloadedTrailers;

                // Scan for trailers
                SetStatus(statusWindow, "Scanning for new Trailers");
                string URL = "http://www.trailerfreaks.com/";
                HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(new System.Uri(URL));
                HttpWebResponse webres = (HttpWebResponse)webreq.GetResponse();
                Stream resStream = webres.GetResponseStream();
                string response = new StreamReader(resStream).ReadToEnd();
                // Find trailer
                string trailerStart = "a href =\"trai"; string toFind; string trailerName; string trailerDescription;
                string trailerDate; string trailerActors; string trailerNameClean; string trailerDetailsURL;
                int startindex, endindex;
                //int numToGet = 10000;
                //if (!numTrailersToGet.Equals("All"))
                //    numToGet = int.Parse(numTrailersToGet);
                //int count = 0;
                //while ((startindex = response.IndexOf(trailerStart)) > -1 && count < numToGet)
                while ((startindex = response.IndexOf(trailerStart)) > -1)
                {
                    bool skip = false;

                    if (startindex > -1)
                    {
                        response = response.Substring(startindex);
                    }
                    else
                    {
                        SetStatus(statusWindow, "Error Finding Trailer Page Links");
                        SetStatus(statusWindow, "Scanning aborted.");
                        enableControls(true);
                        scanner.Abort();
                    }
                    toFind = "title=\"";
                    startindex = response.IndexOf(toFind);
                    if (startindex > -1)
                    {
                        startindex += toFind.Length; // Move to starting position of new Trailer
                    }
                    else
                    {
                        SetStatus(statusWindow, "Error parsing for Trailer Name");
                        continue;
                    }
                    endindex = response.IndexOf("\"", startindex);
                    trailerName = response.Substring(startindex, endindex - startindex).Trim();
                    // Remove Year
                    trailerName = trailerName.Remove(trailerName.LastIndexOf(" "));
                    trailerNameClean = replaceSpecials(trailerName);
                    trailerNameClean = trailerNameClean.Remove(trailerNameClean.LastIndexOf(" "));
                    SetStatus(statusWindow, "Found Trailer: " + trailerName);
                    response = response.Substring(endindex);

                    // Check if it exists already in flat file
                    string trailerDB = Application.StartupPath + "\\trailerDB.txt";
                    if (!File.Exists(trailerDB))
                    {
                        if (verbose)
                            SetStatus(statusWindow, "New DB Created and will add Trailer after successfull download");
                    }
                    else
                    {
                        Serializer serializer = new Serializer();
                        trailerDBobject = serializer.DeSerializeObject(Application.StartupPath + "\\trailerDB.txt");
                        downloadedTrailers = trailerDBobject.DownloadedTrailers;
                        if (downloadedTrailers.Contains(trailerName + GetText(formatBox)))
                        {
                            SetStatus(statusWindow, "Already Downloaded, Skipping Trailer");
                            skip = true;
                        }
                        else
                        {
                            if (verbose)
                                SetStatus(statusWindow, "Not in DB will add Trailer after successfull download");
                        }
                    }

                    if (!skip)
                    {
                        // Get description
                        toFind = "<a href=\"";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Details URL");
                            continue;
                        }
                        endindex = response.IndexOf("\"", startindex);
                        trailerDetailsURL = "http://www.trailerfreaks.com/" + response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                            SetStatus(statusWindow, "Found Detailed Page URL: " + trailerDetailsURL);
                        response = response.Substring(endindex);
                        // Open new URL to get description
                        HttpWebRequest webreqDesc = (HttpWebRequest)WebRequest.Create(new System.Uri(trailerDetailsURL));
                        HttpWebResponse webresDesc = (HttpWebResponse)webreqDesc.GetResponse();
                        Stream resStreamDesc = webresDesc.GetResponseStream();
                        string responseDesc = new StreamReader(resStreamDesc).ReadToEnd();
                        toFind = "class=\"plot\">";
                        int startindexDesc = responseDesc.IndexOf(toFind);
                        if (startindexDesc > -1)
                        {
                            startindexDesc += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Description");
                            continue;
                        }
                        int endindexDesc = responseDesc.IndexOf("</td>", startindexDesc);
                        trailerDescription = responseDesc.Substring(startindexDesc, endindexDesc - startindexDesc).Trim();

                        // Find date
                        toFind = "trailer\" title=\"";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Date");
                            continue;
                        }
                        endindex = startindex + 10;
                        trailerDate = response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                            SetStatus(statusWindow, "Found Date: " + trailerDate);
                        response = response.Substring(endindex);

                        // Find Actors
                        toFind = "trailer\" alt=\"";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Actors");
                            continue;
                        }
                        endindex = response.IndexOf("\"", startindex);
                        trailerActors = response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                            SetStatus(statusWindow, "Found Actors: " + trailerActors);
                        response = response.Substring(endindex);

                        // Find MOV file
                        toFind = "class=\"trailerlink\">" + GetText(formatBox).ToUpper() + "</a>";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex -= 250; // Move to starting position of new Trailer file
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer File");
                            continue;
                        }
                        toFind = "<a href=\"";
                        startindex = response.IndexOf(toFind, startindex);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer File");
                            continue;
                        }
                        endindex = response.IndexOf("\"", startindex);
                        trailerURL = response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                            SetStatus(statusWindow, "Found URL: " + trailerURL);
                        response = response.Substring(endindex + 250);

                        movFile = GetText(locationBox) + "\\" + trailerNameClean + "." + GetText(formatBox) + ".mov";
                        string mp4File = GetText(locationBox) + "\\" + trailerNameClean + "." + GetText(formatBox) + ".mp4";
                        if (verbose)
                            SetStatus(statusWindow, "Downloading Trailer File");
                        //WebClient Client = new WebClient();
                        //bool downloadSuccess = true;
                        //try
                        //{
                        //    Client.DownloadFile(trailerURL, movFile);
                        //}
                        //catch (Exception e)
                        //{
                        //    SetStatus(statusWindow, "Error Downloading.  Try again next time.");
                        //    downloadSuccess = false;
                        //}
                        downloader = new Thread(new ThreadStart(DownloadFile));
                        downloader.Start();
                        SetStatus(statusWindow, "\r\nDownloading");
                        while (downloader.IsAlive)
                        {
                            Thread.Sleep(1000);
                            SetStatusDownloading(statusWindow, ".");
                            if (GetText(scanButton) == "Scan")
                            {
                                SetStatus(statusWindow, "Download canceled");
                                downloader.Abort();
                                break;
                            }
                        }
                        downloader.Join();
                        downloader = null;
                        if (downloadSuccess)
                        {
                            SetStatus(statusWindow, "\r\nDownload Completed");
                            if (verbose)
                                SetStatus(statusWindow, "Converting to MP4");
                            // Convert using ffmpeg to mp4
                            string ffmpegPath = Application.StartupPath + "\\ffmpeg.exe";
                            string ffmpegParams = " -y -i \"" + movFile + "\" -vcodec copy -acodec copy \"" + mp4File + "\"";
                            if (verbose)
                            {
                                SetStatus(statusWindow, ffmpegPath);
                                SetStatus(statusWindow, ffmpegParams);
                            }
                            Process ffmpeg = new Process();
                            ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            ffmpeg.StartInfo.FileName = ffmpegPath;
                            ffmpeg.StartInfo.Arguments = ffmpegParams;
                            //ffmpeg.StartInfo.FileName = "cmd.exe";
                            //ffmpeg.StartInfo.Arguments = "/k " + ffmpegPath + " " + ffmpegParams;
                            ffmpeg.Start();
                            ffmpeg.WaitForExit();
                            System.IO.File.Delete(@movFile);
                            if (verbose)
                                SetStatus(statusWindow, "Conversion Completed");

                            // Add to database file
                            downloadedTrailers.Add(trailerName + GetText(formatBox));
                            Serializer serializer = new Serializer();
                            serializer.SerializeObject(Application.StartupPath + "\\trailerDB.txt", trailerDBobject);

                            // Wait for 5 seconds
                            Thread.Sleep(5000);

                            // Import metadata
                            // Find file
                            library = new BTVLibrary();
                            library.Url = "http://" + serverURL + ":" + port + "/wsdl/BTVLibrary.asmx";
                            PVSPropertyBag[] unknownFiles = library.GetItemsBySeries(auth, "Unknown");
                            foreach (PVSPropertyBag mediafile in unknownFiles)
                            {
                                foreach (PVSProperty pvp1 in mediafile.Properties)
                                {
                                    if (pvp1.Name.Equals("FullName"))
                                    {
                                        string filename = pvp1.Value;
                                        if (filename.Equals(mp4File))
                                        {
                                            if (verbose)
                                                SetStatus(statusWindow, "Found File in BTV Library");
                                            List<PVSProperty> propList = new List<PVSProperty>();

                                            PVSProperty pTitle = new PVSProperty();
                                            pTitle.Name = "Title";
                                            pTitle.Value = "Movie Trailers";
                                            propList.Add(pTitle);

                                            PVSProperty pEpisodeTitle = new PVSProperty();
                                            pEpisodeTitle.Name = "EpisodeTitle";
                                            pEpisodeTitle.Value = String.Empty;
                                            propList.Add(pEpisodeTitle);

                                            PVSProperty pDisplayTitle = new PVSProperty();
                                            pDisplayTitle.Name = "DisplayTitle";
                                            pDisplayTitle.Value = trailerName;
                                            propList.Add(pDisplayTitle);
                                            if (verbose)
                                                SetStatus(statusWindow, "Injected Title: " + pDisplayTitle.Value);

                                            PVSProperty pEpisodeDescription = new PVSProperty();
                                            pEpisodeDescription.Name = "EpisodeDescription";
                                            pEpisodeDescription.Value = "[" + GetText(formatBox) + "] " + trailerDescription;
                                            propList.Add(pEpisodeDescription);

                                            PVSProperty pActors = new PVSProperty();
                                            pActors.Name = "Actors";
                                            pActors.Value = trailerActors;
                                            propList.Add(pActors);

                                            PVSProperty pDate = new PVSProperty();
                                            pDate.Name = "OriginalAirDate";
                                            pDate.Value = trailerDate.Replace("-", "");
                                            propList.Add(pDate);
                                            if (verbose)
                                                SetStatus(statusWindow, "Injected Date: " + pDate.Value);

                                            PVSPropertyBag bag = new PVSPropertyBag();
                                            bag.Properties = (PVSProperty[])propList.ToArray();

                                            library.EditMedia(auth, @filename, bag);
                                            if (verbose)
                                                SetStatus(statusWindow, "Metadata Injected");
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Abort if unchecked
                    if (GetText(scanButton) == "Scan")
                    {
                        SetStatus(statusWindow, "Scanning aborted.");
                        enableControls(true);
                        scanner.Abort();
                    }

                    count++;
                }
            }
            catch (Exception e)
            {
                SetStatus(statusWindow, "Major Error: " + e.ToString());
            }

            // Done, for now
            SetStatus(statusWindow, "Scanning Completed.  Waiting 8 hours to scan again.  Force restart by clicking Scan button");
        }
        void start()
        {
            DirectoryInfo dirInfo = new DirectoryInfo(@"E:\Work\Work apps\Antony\IFI_DB");

            info = dirInfo.GetFiles("*.jpg");
            //info.Length
            numberofimages = info.Length;

            numOfClasses = numberofimages / ImagePerClass;
            mymat = new List<double[]>();
            List<string> filenames = new List<string>();
            for (int i = 0; i < numberofimages; i++)
            {
                if (info[i].Name.Substring(3, 2) != "07")
                {

                    filenames.Add(info[i].Name.Substring(0, 3));
                    var img = BitmapFactory.New(1, 1).FromStream(info[i].OpenRead());
                    if (img.PixelWidth != 100 || img.PixelHeight != 150)
                    {
                        img = img.Resize(100, 150, WriteableBitmapExtensions.Interpolation.Bilinear);
                    }
                    mymat.Add(helper.imgtomat(img.ToByteArray()));

                }
            }
            GC.Collect();
              if (decide == 0)
             {
                 pca = new PCA(mymat.ToArray(), filenames, filenames.Count);
             }
             else
             {
                 if (File.Exists(@"E:\Work\Work apps\lda pca face rec\outputFile.txt"))
                 {
                     ObjectToSerialize objectToSerialize = Serializer.DeSerializeObject(@"E:\Work\Work apps\lda pca face rec\outputFile.txt");
                     lda = objectToSerialize.Lda;

                 }
                 else
                 {
                     lda = new LDA(mymat.ToArray(), filenames, filenames.Count);

                     ObjectToSerialize objectToSerialize = new ObjectToSerialize();
                     objectToSerialize.Lda = lda ;

                     Serializer serializer = new Serializer();
                     serializer.SerializeObject(@"E:\Work\Work apps\lda pca face rec\outputFile.txt", objectToSerialize);
                 }
             }
        }
 public string SerializeObject(ObjectToSerialize obj)
 {
     return(XmlSerializerUtil.SerializeToXml <ObjectToSerialize>(obj));
 }
Ejemplo n.º 24
0
        // Thread to scan
        private void runwork()
        {
            // Log in again
            if (!login())
            {
                SetStatus(statusWindow, "Will try to log on again in 10 seconds");
                hourTimer.Change(10000, 1000 * 60 * 60 * 4);
                scanner.Abort();
            }

            try
            {
                // List to save movies to db file
                List <string>     downloadedTrailers = new List <string>();
                ObjectToSerialize trailerDBobject    = new ObjectToSerialize();
                trailerDBobject.DownloadedTrailers = downloadedTrailers;

                // Scan for trailers
                SetStatus(statusWindow, "Scanning for new Trailers");
                string          URL       = "http://www.trailerfreaks.com/";
                HttpWebRequest  webreq    = (HttpWebRequest)WebRequest.Create(new System.Uri(URL));
                HttpWebResponse webres    = (HttpWebResponse)webreq.GetResponse();
                Stream          resStream = webres.GetResponseStream();
                string          response  = new StreamReader(resStream).ReadToEnd();
                // Find trailer
                string trailerStart = "a href =\"trai"; string toFind; string trailerName; string trailerDescription;
                string trailerDate; string trailerActors; string trailerNameClean; string trailerDetailsURL;
                int    startindex, endindex;
                //int numToGet = 10000;
                //if (!numTrailersToGet.Equals("All"))
                //    numToGet = int.Parse(numTrailersToGet);
                //int count = 0;
                //while ((startindex = response.IndexOf(trailerStart)) > -1 && count < numToGet)
                while ((startindex = response.IndexOf(trailerStart)) > -1)
                {
                    bool skip = false;

                    if (startindex > -1)
                    {
                        response = response.Substring(startindex);
                    }
                    else
                    {
                        SetStatus(statusWindow, "Error Finding Trailer Page Links");
                        SetStatus(statusWindow, "Scanning aborted.");
                        enableControls(true);
                        scanner.Abort();
                    }
                    toFind     = "title=\"";
                    startindex = response.IndexOf(toFind);
                    if (startindex > -1)
                    {
                        startindex += toFind.Length; // Move to starting position of new Trailer
                    }
                    else
                    {
                        SetStatus(statusWindow, "Error parsing for Trailer Name");
                        continue;
                    }
                    endindex    = response.IndexOf("\"", startindex);
                    trailerName = response.Substring(startindex, endindex - startindex).Trim();
                    // Remove Year
                    trailerName      = trailerName.Remove(trailerName.LastIndexOf(" "));
                    trailerNameClean = replaceSpecials(trailerName);
                    trailerNameClean = trailerNameClean.Remove(trailerNameClean.LastIndexOf(" "));
                    SetStatus(statusWindow, "Found Trailer: " + trailerName);
                    response = response.Substring(endindex);

                    // Check if it exists already in flat file
                    string trailerDB = Application.StartupPath + "\\trailerDB.txt";
                    if (!File.Exists(trailerDB))
                    {
                        if (verbose)
                        {
                            SetStatus(statusWindow, "New DB Created and will add Trailer after successfull download");
                        }
                    }
                    else
                    {
                        Serializer serializer = new Serializer();
                        trailerDBobject    = serializer.DeSerializeObject(Application.StartupPath + "\\trailerDB.txt");
                        downloadedTrailers = trailerDBobject.DownloadedTrailers;
                        if (downloadedTrailers.Contains(trailerName + GetText(formatBox)))
                        {
                            SetStatus(statusWindow, "Already Downloaded, Skipping Trailer");
                            skip = true;
                        }
                        else
                        {
                            if (verbose)
                            {
                                SetStatus(statusWindow, "Not in DB will add Trailer after successfull download");
                            }
                        }
                    }

                    if (!skip)
                    {
                        // Get description
                        toFind     = "<a href=\"";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Details URL");
                            continue;
                        }
                        endindex          = response.IndexOf("\"", startindex);
                        trailerDetailsURL = "http://www.trailerfreaks.com/" + response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                        {
                            SetStatus(statusWindow, "Found Detailed Page URL: " + trailerDetailsURL);
                        }
                        response = response.Substring(endindex);
                        // Open new URL to get description
                        HttpWebRequest  webreqDesc    = (HttpWebRequest)WebRequest.Create(new System.Uri(trailerDetailsURL));
                        HttpWebResponse webresDesc    = (HttpWebResponse)webreqDesc.GetResponse();
                        Stream          resStreamDesc = webresDesc.GetResponseStream();
                        string          responseDesc  = new StreamReader(resStreamDesc).ReadToEnd();
                        toFind = "class=\"plot\">";
                        int startindexDesc = responseDesc.IndexOf(toFind);
                        if (startindexDesc > -1)
                        {
                            startindexDesc += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Description");
                            continue;
                        }
                        int endindexDesc = responseDesc.IndexOf("</td>", startindexDesc);
                        trailerDescription = responseDesc.Substring(startindexDesc, endindexDesc - startindexDesc).Trim();

                        // Find date
                        toFind     = "trailer\" title=\"";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Date");
                            continue;
                        }
                        endindex    = startindex + 10;
                        trailerDate = response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                        {
                            SetStatus(statusWindow, "Found Date: " + trailerDate);
                        }
                        response = response.Substring(endindex);


                        // Find Actors
                        toFind     = "trailer\" alt=\"";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer Actors");
                            continue;
                        }
                        endindex      = response.IndexOf("\"", startindex);
                        trailerActors = response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                        {
                            SetStatus(statusWindow, "Found Actors: " + trailerActors);
                        }
                        response = response.Substring(endindex);

                        // Find MOV file
                        toFind     = "class=\"trailerlink\">" + GetText(formatBox).ToUpper() + "</a>";
                        startindex = response.IndexOf(toFind);
                        if (startindex > -1)
                        {
                            startindex -= 250; // Move to starting position of new Trailer file
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer File");
                            continue;
                        }
                        toFind     = "<a href=\"";
                        startindex = response.IndexOf(toFind, startindex);
                        if (startindex > -1)
                        {
                            startindex += toFind.Length; // Move to starting position of new Trailer
                        }
                        else
                        {
                            SetStatus(statusWindow, "Error parsing for Trailer File");
                            continue;
                        }
                        endindex   = response.IndexOf("\"", startindex);
                        trailerURL = response.Substring(startindex, endindex - startindex).Trim();
                        if (verbose)
                        {
                            SetStatus(statusWindow, "Found URL: " + trailerURL);
                        }
                        response = response.Substring(endindex + 250);

                        movFile = GetText(locationBox) + "\\" + trailerNameClean + "." + GetText(formatBox) + ".mov";
                        string mp4File = GetText(locationBox) + "\\" + trailerNameClean + "." + GetText(formatBox) + ".mp4";
                        if (verbose)
                        {
                            SetStatus(statusWindow, "Downloading Trailer File");
                        }
                        //WebClient Client = new WebClient();
                        //bool downloadSuccess = true;
                        //try
                        //{
                        //    Client.DownloadFile(trailerURL, movFile);
                        //}
                        //catch (Exception e)
                        //{
                        //    SetStatus(statusWindow, "Error Downloading.  Try again next time.");
                        //    downloadSuccess = false;
                        //}
                        downloader = new Thread(new ThreadStart(DownloadFile));
                        downloader.Start();
                        SetStatus(statusWindow, "\r\nDownloading");
                        while (downloader.IsAlive)
                        {
                            Thread.Sleep(1000);
                            SetStatusDownloading(statusWindow, ".");
                            if (GetText(scanButton) == "Scan")
                            {
                                SetStatus(statusWindow, "Download canceled");
                                downloader.Abort();
                                break;
                            }
                        }
                        downloader.Join();
                        downloader = null;
                        if (downloadSuccess)
                        {
                            SetStatus(statusWindow, "\r\nDownload Completed");
                            if (verbose)
                            {
                                SetStatus(statusWindow, "Converting to MP4");
                            }
                            // Convert using ffmpeg to mp4
                            string ffmpegPath   = Application.StartupPath + "\\ffmpeg.exe";
                            string ffmpegParams = " -y -i \"" + movFile + "\" -vcodec copy -acodec copy \"" + mp4File + "\"";
                            if (verbose)
                            {
                                SetStatus(statusWindow, ffmpegPath);
                                SetStatus(statusWindow, ffmpegParams);
                            }
                            Process ffmpeg = new Process();
                            ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            ffmpeg.StartInfo.FileName    = ffmpegPath;
                            ffmpeg.StartInfo.Arguments   = ffmpegParams;
                            //ffmpeg.StartInfo.FileName = "cmd.exe";
                            //ffmpeg.StartInfo.Arguments = "/k " + ffmpegPath + " " + ffmpegParams;
                            ffmpeg.Start();
                            ffmpeg.WaitForExit();
                            System.IO.File.Delete(@movFile);
                            if (verbose)
                            {
                                SetStatus(statusWindow, "Conversion Completed");
                            }

                            // Add to database file
                            downloadedTrailers.Add(trailerName + GetText(formatBox));
                            Serializer serializer = new Serializer();
                            serializer.SerializeObject(Application.StartupPath + "\\trailerDB.txt", trailerDBobject);

                            // Wait for 5 seconds
                            Thread.Sleep(5000);

                            // Import metadata
                            // Find file
                            library     = new BTVLibrary();
                            library.Url = "http://" + serverURL + ":" + port + "/wsdl/BTVLibrary.asmx";
                            PVSPropertyBag[] unknownFiles = library.GetItemsBySeries(auth, "Unknown");
                            foreach (PVSPropertyBag mediafile in unknownFiles)
                            {
                                foreach (PVSProperty pvp1 in mediafile.Properties)
                                {
                                    if (pvp1.Name.Equals("FullName"))
                                    {
                                        string filename = pvp1.Value;
                                        if (filename.Equals(mp4File))
                                        {
                                            if (verbose)
                                            {
                                                SetStatus(statusWindow, "Found File in BTV Library");
                                            }
                                            List <PVSProperty> propList = new List <PVSProperty>();

                                            PVSProperty pTitle = new PVSProperty();
                                            pTitle.Name  = "Title";
                                            pTitle.Value = "Movie Trailers";
                                            propList.Add(pTitle);

                                            PVSProperty pEpisodeTitle = new PVSProperty();
                                            pEpisodeTitle.Name  = "EpisodeTitle";
                                            pEpisodeTitle.Value = String.Empty;
                                            propList.Add(pEpisodeTitle);

                                            PVSProperty pDisplayTitle = new PVSProperty();
                                            pDisplayTitle.Name  = "DisplayTitle";
                                            pDisplayTitle.Value = trailerName;
                                            propList.Add(pDisplayTitle);
                                            if (verbose)
                                            {
                                                SetStatus(statusWindow, "Injected Title: " + pDisplayTitle.Value);
                                            }

                                            PVSProperty pEpisodeDescription = new PVSProperty();
                                            pEpisodeDescription.Name  = "EpisodeDescription";
                                            pEpisodeDescription.Value = "[" + GetText(formatBox) + "] " + trailerDescription;
                                            propList.Add(pEpisodeDescription);

                                            PVSProperty pActors = new PVSProperty();
                                            pActors.Name  = "Actors";
                                            pActors.Value = trailerActors;
                                            propList.Add(pActors);

                                            PVSProperty pDate = new PVSProperty();
                                            pDate.Name  = "OriginalAirDate";
                                            pDate.Value = trailerDate.Replace("-", "");
                                            propList.Add(pDate);
                                            if (verbose)
                                            {
                                                SetStatus(statusWindow, "Injected Date: " + pDate.Value);
                                            }

                                            PVSPropertyBag bag = new PVSPropertyBag();
                                            bag.Properties = (PVSProperty[])propList.ToArray();

                                            library.EditMedia(auth, @filename, bag);
                                            if (verbose)
                                            {
                                                SetStatus(statusWindow, "Metadata Injected");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Abort if unchecked
                    if (GetText(scanButton) == "Scan")
                    {
                        SetStatus(statusWindow, "Scanning aborted.");
                        enableControls(true);
                        scanner.Abort();
                    }

                    count++;
                }
            }
            catch (Exception e)
            {
                SetStatus(statusWindow, "Major Error: " + e.ToString());
            }

            // Done, for now
            SetStatus(statusWindow, "Scanning Completed.  Waiting 8 hours to scan again.  Force restart by clicking Scan button");
        }