public void DeleteEntryThreadSafety()
        {
            var binaryFileManager = new BinaryFileManager();

            var listOfTasks = new List <Task>();

            var entries = binaryFileManager.GetAll();

            var listOfObjects = new List <PhoneEntryModel>
            {
                new PhoneEntryModel
                {
                    Id          = 2,
                    FirstName   = "Orges",
                    LastName    = "Kreka",
                    PhoneNumber = "+355682024896",
                    EntryType   = PhoneEntryType.WORK
                }
            };

            foreach (var model in listOfObjects)
            {
                var addTask = new Task <bool>(() => binaryFileManager.Delete(model));
                listOfTasks.Add(addTask);
            }

            listOfTasks.ForEach(x => x.Start());
            Task.WaitAll(listOfTasks.ToArray());

            var tmp = binaryFileManager.GetAll();

            Assert.IsTrue(tmp.Count == (entries.Count - listOfObjects.Count));
        }
示例#2
0
        public static Mother3Project CreateNew(IFileSystem fileSystem, string romDataPath,
                                               string romConfigPath)
        {
            var binaryManager = new BinaryFileManager(fileSystem);
            var jsonManager   = new JsonFileManager(fileSystem);

            var romData         = binaryManager.ReadFile <Block>(romDataPath);
            var romConfig       = jsonManager.ReadJson <Mother3RomConfig>(romConfigPath);
            var projectSettings = Mother3ProjectSettings.CreateDefault();

            var project = new Mother3Project(romData, romConfig, projectSettings);

            // Do some ROM config prep before reading the modules
            if (romConfig.IsJapanese)
            {
                romConfig.AddJapaneseCharsToLookup(romData);
            }

            if (romConfig.ScriptEncodingParameters != null)
            {
                romConfig.ReadEncodingPadData(romData);
            }

            romConfig.UpdateLookups();

            foreach (var module in project.Modules)
            {
                module.ReadFromRom(romData);
            }

            return(project);
        }
        public void AddEntryNullException()
        {
            BinaryFileManager binaryFile = new BinaryFileManager();
            PhoneEntryModel   model      = new PhoneEntryModel();

            model = null;
            Assert.Throws <ArgumentNullException>(() => { throw new ArgumentNullException(); });
        }
        public void OpenFileTest()
        {
            BinaryFileManager binaryfile = new BinaryFileManager();

            if (File.Exists(Constants.FilePath))
            {
                var file = File.Open(Constants.FilePath, FileMode.Append);
                file.Close();
            }
            Assert.IsTrue(File.Exists(Constants.FilePath));
        }
示例#5
0
        public void Compile(IFileSystem fileSystem)
        {
            var allocator     = new RangeAllocator(RomConfig.FreeRanges);
            var outputRomData = new Block(RomData);
            var compiler      = Compiler.Create(outputRomData, allocator, Modules);

            compiler.Compile();

            var binaryManager = new BinaryFileManager(fileSystem);

            binaryManager.WriteFile(ProjectSettings.OutputRomPath, outputRomData);
        }
        public void CreateFileTest()
        {
            BinaryFileManager binaryfile = new BinaryFileManager();

            if (!File.Exists(Constants.FilePath))
            {
                var file = File.Create(Constants.FilePath);
                file.Close();
            }

            Assert.IsTrue(File.Exists(Constants.FilePath));
        }
示例#7
0
        /// <summary>
        /// Gets a Static Content Item for a given URL path.
        /// </summary>
        /// <param name="urlPath">The URL path (unescaped).</param>
        /// <param name="localization">The context Localization.</param>
        /// <returns>The Static Content Item.</returns>
        public virtual StaticContentItem GetStaticContentItem(string urlPath, Localization localization)
        {
            using (new Tracer(urlPath, localization))
            {
                if (WebRequestContext.IsSessionPreview)
                {
                    // If running under an XPM session preview go directly to BinaryProvider and avoid any
                    // caching logic provided by the BinaryFileManager. We still need to perform image
                    // resizing due to responsive image urls.
                    BinaryFileManager.Dimensions dims;
                    urlPath = BinaryFileManager.StripDimensions(urlPath, out dims);
                    var    binary     = BinaryFileManager.Provider.GetBinary(localization, urlPath);
                    byte[] binaryData = binary.Item1;
                    if (dims != null && (dims.Width > 0 || dims.Height > 0))
                    {
                        ImageFormat imgFormat = BinaryFileManager.GetImageFormat(binary.Item2);
                        if (imgFormat != null)
                        {
                            binaryData = BinaryFileManager.ResizeImage(binaryData, dims, imgFormat);
                        }
                    }

                    return(new StaticContentItem(
                               new MemoryStream(binaryData),
                               MimeMapping.GetMimeMapping(binary.Item2),
                               DateTime.Now,
                               Encoding.UTF8));
                }

                MemoryStream memoryStream;
                Stream       dataStream;
                string       localFilePath =
                    BinaryFileManager.Instance.GetCachedFile(urlPath, localization, out memoryStream);

                if (memoryStream == null)
                {
                    dataStream = new FileStream(localFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096,
                                                FileOptions.SequentialScan);
                }
                else
                {
                    dataStream = memoryStream;
                }

                return(new StaticContentItem(
                           dataStream,
                           MimeMapping.GetMimeMapping(localFilePath),
                           File.GetLastWriteTime(localFilePath),
                           Encoding.UTF8
                           ));
            }
        }
        public void IterateListByLastName()
        {
            bool orderByFirstName        = false;
            BinaryFileManager binaryFile = new BinaryFileManager();
            var phoneEntries             = binaryFile.GetAll();
            var orderList = new List <PhoneEntryModel>();

            if (orderByFirstName)
            {
                orderList = phoneEntries.OrderBy(p => p.LastName).ToList();
            }
            Assert.That(orderList, Is.Ordered.By("LastName"));
        }
        public void DeleteAndCreateFileTest()
        {
            BinaryFileManager binaryfile = new BinaryFileManager();
            FileInfo          fi         = new FileInfo(Constants.FilePath);

            if (fi.Length > Constants.FileMaxSize)
            {
                File.Delete(Constants.FilePath);
                var file = File.Create(Constants.FilePath);
                file.Close();
            }
            Assert.IsTrue(File.Exists(Constants.FilePath));
        }
        /// <summary>
        /// Main method handling requests to the specified resource.
        /// </summary>
        /// <param name="o">Current HttpApplication</param>
        /// <param name="eventArgs">Current event arguments</param>
        public void DistributionModule_OnPreRequestHandlerExecute(object o, EventArgs eventArgs)
        {
            DateTime        start       = DateTime.Now;
            HttpApplication application = (HttpApplication)o;
            HttpContext     context     = application.Context;
            HttpRequest     request     = context.Request;
            HttpResponse    response    = context.Response;
            string          urlPath     = request.Url.AbsolutePath;

            Regex binaryRegex = new Regex(ConfigurationManager.AppSettings["BinaryUrlPattern"]);

            if (!binaryRegex.IsMatch(urlPath))
            {
                LoggerService.Debug("url {0} does not match binary url pattern, ignoring it", urlPath);
                return;
            }

            if (!BinaryFileManager.ProcessRequest(request))
            {
                LoggerService.Debug("Url {0} not found. Returning 404 Not Found.", urlPath);
                //the 404 should be handled by the default handler
                return;
            }
            // if we got here, the file was successfully created on file-system
            DateTime ifModifiedSince = Convert.ToDateTime(request.Headers["If-Modified-Since"]);

            LoggerService.Debug("If-Modified-Since: " + ifModifiedSince);

            DateTime fileLastModified = File.GetLastWriteTime(request.PhysicalPath);

            LoggerService.Debug("File last modified: " + fileLastModified);

            if (fileLastModified.Subtract(ifModifiedSince).TotalSeconds < 1)
            {
                LoggerService.Debug("Sending 304 Not Modified");
                response.StatusCode      = 304;
                response.SuppressContent = true;
                application.CompleteRequest();
            }

            // Note: if the file was just created, an empty dummy might still be served by IIS
            // To make sure the right file is sent, we will transmit the file directly within the first second of the creation
            if (fileLastModified.AddSeconds(1).CompareTo(DateTime.Now) > 0)
            {
                LoggerService.Debug("file was created less than 1 second ago, transmitting content directly");
                response.Clear();
                response.TransmitFile(request.PhysicalPath);
            }
        }
        public void AddEntryToPhoneBook()
        {
            BinaryFileManager binaryFile = new BinaryFileManager();
            PhoneEntryModel   model      = new PhoneEntryModel
            {
                Id          = 4,
                FirstName   = "Mario",
                LastName    = "Coku",
                PhoneNumber = "+355682024896",
                EntryType   = PhoneEntryType.WORK
            };

            binaryFile.Add(model);

            Assert.IsTrue(binaryFile.GetAll().Any(x => x.FirstName.Equals("Mario") && x.LastName.Equals("Coku")));
        }
        public void EditEntryToPhoneBook()
        {
            BinaryFileManager binaryFile = new BinaryFileManager();
            PhoneEntryModel   model      = new PhoneEntryModel
            {
                Id          = 3,
                FirstName   = "Endi",
                LastName    = "Koci",
                PhoneNumber = "+355682024896",
                EntryType   = PhoneEntryType.WORK
            };

            var result = binaryFile.Edit(model);

            Assert.IsTrue(result == true && binaryFile.GetAll().Any(x => x.FirstName.Equals("Endi") && x.LastName.Equals("Koci")));
        }
        public void DeleteEntryFromPhoneBook()
        {
            PhoneEntryModel model = new PhoneEntryModel
            {
                Id          = 1,
                FirstName   = "Kristi",
                LastName    = "Mone",
                PhoneNumber = "+355682024896",
                EntryType   = PhoneEntryType.WORK
            };

            var binaryFileManager = new BinaryFileManager();
            var result            = binaryFileManager.Delete(model);

            Assert.IsTrue(result && !binaryFileManager.GetAll().Any(x => x.Id == model.Id));
        }
示例#14
0
        public static Mother3Project Load(IFileSystem fileSystem, string projectSettingsPath)
        {
            var jsonManager     = new JsonFileManager(fileSystem);
            var projectSettings = jsonManager.ReadJson <Mother3ProjectSettings>(projectSettingsPath);
            var romConfig       = jsonManager.ReadJson <Mother3RomConfig>(projectSettings.RomConfigPath);

            var binaryManager = new BinaryFileManager(fileSystem);
            var romData       = binaryManager.ReadFile <Block>(projectSettings.BaseRomPath);

            var project = new Mother3Project(romData, romConfig, projectSettings);

            foreach (var module in project.Modules)
            {
                module.ReadFromFiles(fileSystem);
            }

            return(project);
        }
        public void DeleteEntryDifferentId_FromFile()
        {
            BinaryFileManager binaryFile = new BinaryFileManager();
            var             phoneEntries = binaryFile.GetAll();
            PhoneEntryModel model        = new PhoneEntryModel
            {
                Id          = 7,
                FirstName   = "Orges",
                LastName    = "Kreka",
                PhoneNumber = "+355682323896",
                EntryType   = PhoneEntryType.WORK
            };

            if (!phoneEntries.Any(x => x.Id == model.Id))
            {
                Assert.IsFalse(false);
            }
        }
        public void AddEntryToPhoneBookReturnFalse()
        {
            BinaryFileManager binaryFile = new BinaryFileManager();
            PhoneEntryModel   model      = new PhoneEntryModel
            {
                Id          = 4,
                FirstName   = "Mario",
                LastName    = "Coku",
                PhoneNumber = "+355682024896",
                EntryType   = PhoneEntryType.WORK
            };

            var phoneEntries = binaryFile.GetAll();

            if (phoneEntries.Any(x => x.Id == model.Id))
            {
                Assert.IsFalse(false);
            }
        }
示例#17
0
    private void Start()
    {
        BinaryExampleDataPacket data1 = new BinaryExampleDataPacket(1, "This is data packet 1");

        //Returns false, as we have not created a binary file called "binaryData" with the extension ".custom"
        Debug.Log(BinaryFileManager.DoesBinaryFileExist("/binaryData", ".custom"));

        //Creates a ".custom" binary file at Application.persistentDataPath from the DataPacket data1
        BinaryFileManager.CreateBinaryFile(data1, "/binaryData", ".custom");

        //Returns true, as we just created the file above
        Debug.Log(BinaryFileManager.DoesBinaryFileExist("/binaryData", ".custom"));

        //Displays "This is data packet 1" in the console, as we retrieved the data from the file
        //(Remember to specify the object you want back, in this case, BinaryExampleDataPacket)
        Debug.Log(BinaryFileManager.GetObjectFromBinaryFile <BinaryExampleDataPacket>("/binaryData", ".custom").StringData);

        //Deletes the file "/binaryData.custom" and outputs "DELETED /binaryData.custom" in the console
        BinaryFileManager.DeleteBinaryFile("/binaryData", ".custom");
    }
        public void AddEntriesAndCheckIfListContainsThem()
        {
            var entry1 = new PhoneEntryModel
            {
                Id          = 1,
                FirstName   = "Kristi",
                LastName    = "Mone",
                PhoneNumber = "+355682456321",
                EntryType   = PhoneEntryType.CELLPHONE
            };

            var entry2 = new PhoneEntryModel
            {
                Id          = 2,
                FirstName   = "Orges",
                LastName    = "Kreka",
                PhoneNumber = "+355696054698",
                EntryType   = PhoneEntryType.WORK
            };

            var entry3 = new PhoneEntryModel
            {
                Id          = 3,
                FirstName   = "Ermal",
                LastName    = "Arapi",
                PhoneNumber = "+35542235205",
                EntryType   = PhoneEntryType.HOME
            };

            BinaryFileManager binaryFile = new BinaryFileManager();

            binaryFile.Add(entry1);
            binaryFile.Add(entry2);
            binaryFile.Add(entry3);

            var result = binaryFile.GetAll();

            Assert.IsTrue(result[0].Equals(entry1) && result[1].Equals(entry2) && result[2].Equals(entry3));
        }
        public void EditEntryThreadSafety()
        {
            var binaryFileManager = new BinaryFileManager();

            var listOfTasks = new List <Task>();

            var entries = binaryFileManager.GetAll();

            var listOfObjects = new List <PhoneEntryModel>
            {
                new PhoneEntryModel
                {
                    Id          = 3,
                    FirstName   = "Petrit",
                    LastName    = "Lame",
                    PhoneNumber = "+355682624896",
                    EntryType   = PhoneEntryType.CELLPHONE
                }
            };

            foreach (var model in listOfObjects)
            {
                var addTask = new Task <bool>(() => binaryFileManager.Edit(model));
                listOfTasks.Add(addTask);
            }

            listOfTasks.ForEach(x => x.Start());
            Task.WaitAll(listOfTasks.ToArray());

            var tmp = binaryFileManager.GetAll();

            Assert.IsTrue(tmp.Count == entries.Count);

            for (int i = 0; i < tmp.Count; i++)
            {
                Assert.IsTrue(tmp[i].FirstName != entries[i].FirstName);
                break;
            }
        }
示例#20
0
        static void Main(string[] args)
        {
            var binaryFileManager = new BinaryFileManager();

            if (!binaryFileManager.CreateFile())
            {
                Console.WriteLine("Gabim gjate krijimit te skedarit");
                return;
            }

            binaryFileManager.Add(new PhoneEntryModel
            {
                Id          = 1,
                FirstName   = "Kristi",
                LastName    = "Mone",
                PhoneNumber = "+355682024896",
                EntryType   = PhoneEntryType.WORK
            });


            binaryFileManager.Add(new PhoneEntryModel
            {
                Id          = 2,
                FirstName   = "Ermal",
                LastName    = "Arapi",
                PhoneNumber = "+355695231205",
                EntryType   = PhoneEntryType.CELLPHONE
            });

            binaryFileManager.Add(new PhoneEntryModel
            {
                Id          = 3,
                FirstName   = "Mario",
                LastName    = "Coku",
                PhoneNumber = "+355692465823",
                EntryType   = PhoneEntryType.CELLPHONE
            });

            binaryFileManager.Add(new PhoneEntryModel
            {
                Id          = 4,
                FirstName   = "Gerta",
                LastName    = "Mone",
                PhoneNumber = "+35568602345698",
                EntryType   = PhoneEntryType.WORK
            });

            binaryFileManager.Add(new PhoneEntryModel
            {
                Id          = 5,
                FirstName   = "Elektra",
                LastName    = "Myrto",
                PhoneNumber = "+35542236894",
                EntryType   = PhoneEntryType.HOME
            });


            binaryFileManager.Edit(new PhoneEntryModel
            {
                Id          = 4,
                FirstName   = "Endi",
                LastName    = "Koci",
                PhoneNumber = "+35542354693",
                EntryType   = PhoneEntryType.HOME
            });

            binaryFileManager.Delete(new PhoneEntryModel
            {
                Id          = 2,
                FirstName   = "Ermal",
                LastName    = "Arapi",
                PhoneNumber = "+355695231205",
                EntryType   = PhoneEntryType.CELLPHONE
            });


            foreach (var item in binaryFileManager.Iterate(true))
            {
                Console.WriteLine(item);
            }

            foreach (var item in binaryFileManager.Iterate(false))
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }