// ------[ UPDATE ]------ public void OnUpdate() { if (File.Exists(logoLocation)) { try { FileInfo imageInfo = new FileInfo(logoLocation); if (lastLogoWriteTime < imageInfo.LastWriteTime) { byte[] data = null; data = File.ReadAllBytes(logoLocation); if (data != null) { logoTexture = IOUtilities.ParseImageData(data); lastLogoWriteTime = imageInfo.LastWriteTime; isRepaintRequired = true; } } } catch (Exception e) { Debug.LogWarning("[mod.io] Unable to read updates to the logo image file.\n\n" + Utility.GenerateExceptionDebugString(e)); } } }
/// <summary> /// Creates the tables and data for the database /// </summary> protected virtual void InitializeDatabase() { if (Options.Database == UmbracoTestOptions.Database.None || Options.Database == UmbracoTestOptions.Database.NewEmptyPerTest) { return; } //create the schema and load default data if: // - is the first test in the session // - NewDbFileAndSchemaPerTest // - _isFirstTestInFixture + DbInitBehavior.NewDbFileAndSchemaPerFixture if (_databaseBytes == null && (FirstTestInSession || Options.Database == UmbracoTestOptions.Database.NewSchemaPerTest || FirstTestInFixture && Options.Database == UmbracoTestOptions.Database.NewSchemaPerFixture)) { using (var scope = ScopeProvider.CreateScope()) { var schemaHelper = new DatabaseSchemaCreator(scope.Database, Logger); //Create the umbraco database and its base data schemaHelper.InitializeDatabaseSchema(); //Special case, we need to create the xml cache tables manually since they are not part of the default //setup. //TODO: Remove this when we update all tests to use nucache schemaHelper.CreateTable <ContentXmlDto>(); schemaHelper.CreateTable <PreviewXmlDto>(); scope.Complete(); } _databaseBytes = File.ReadAllBytes(_databasePath); } }
/// <summary> /// /// </summary> public NotificationManager() { if (_push == null) { Console.WriteLine("Constructor fired."); LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Notification constructor is running."); try { _push = new PushBroker(); //Registring events. _notificationMsgLength = 0; _push.OnNotificationSent += NotificationSent; _push.OnChannelException += ChannelException; _push.OnServiceException += ServiceException; _push.OnNotificationFailed += NotificationFailed; _push.OnNotificationRequeue += NotificationRequeue; _push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired; _push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged; _push.OnChannelCreated += ChannelCreated; _push.OnChannelDestroyed += ChannelDestroyed; var appleCertificate = File.ReadAllBytes(ConfigurationManager.AppSettings[NeeoConstants.AppleCertificatePath]); var channelSettings = new ApplePushChannelSettings(true, appleCertificate, ConfigurationManager.AppSettings[NeeoConstants.AppleCertificatePwd]); channelSettings.ConnectionTimeout = 36000; _push.RegisterAppleService(channelSettings); _push.RegisterGcmService( new GcmPushChannelSettings(ConfigurationManager.AppSettings[NeeoConstants.GoogleApiKey])); } catch (Exception exception) { Console.WriteLine(exception); } } }
/// <summary> /// Creates the tables and data for the database /// </summary> protected virtual void InitializeDatabase() { if (Options.Database == UmbracoTestOptions.Database.None || Options.Database == UmbracoTestOptions.Database.NewEmptyPerTest) { return; } //create the schema and load default data if: // - is the first test in the session // - NewDbFileAndSchemaPerTest // - _isFirstTestInFixture + DbInitBehavior.NewDbFileAndSchemaPerFixture if (_databaseBytes == null && (FirstTestInSession || Options.Database == UmbracoTestOptions.Database.NewSchemaPerTest || FirstTestInFixture && Options.Database == UmbracoTestOptions.Database.NewSchemaPerFixture)) { using (var scope = ScopeProvider.CreateScope()) { var schemaHelper = new DatabaseSchemaCreator(scope.Database, Logger); //Create the umbraco database and its base data schemaHelper.InitializeDatabaseSchema(); scope.Complete(); } _databaseBytes = File.ReadAllBytes(_databasePath); } }
static string read_text(string path) { var bytes = File.ReadAllBytes(path); var encoding = new UTF8Encoding(); return(encoding.GetString(bytes)); }
private Texture2D GetGalleryImageByIndex(int index) { string imageFileName = GetGalleryImageFileName(index); GalleryImageLocator imageLocator = null; if (this.profile != null && this.profile.media != null) { imageLocator = this.profile.media.GetGalleryImageWithFileName(imageFileName); } Texture2D texture; if (String.IsNullOrEmpty(imageFileName)) { return(null); } // - Get - else if (this.textureCache.TryGetValue(imageFileName, out texture)) { return(texture); } // - LoadOrDownload - else if (imageLocator != null) { this.textureCache.Add(imageFileName, EditorImages.LoadingPlaceholder); ModManager.GetModGalleryImage(this.profile.id, imageLocator, IMAGE_PREVIEW_SIZE, (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; }, null); return(this.textureCache[imageFileName]); } // - Load - else { string imageSource = GetGalleryImageSource(index); byte[] data = null; Texture2D imageData = null; data = File.ReadAllBytes(imageSource); if (data != null) { imageData = IOUtilities.ParseImageData(data); } this.textureCache.Add(imageFileName, imageData); return(this.textureCache[imageFileName]); } }
/// <summary> /// Downloads the file. /// </summary> /// <returns>A <see cref="Task"/> representing any asynchronous operation.</returns> // ReSharper disable once UnusedMember.Global protected async Task DownloadFile() { try { var fileData = IoFile.ReadAllBytes(this.File.FilePath); await this.JavascriptRuntime.InvokeAsync <string>("window.downloadHelper.downloadFile", fileData, this.File.FileName, this.File.Type); } catch (Exception ex) { await this.TryLogError(ex); } }
// ------[ INITIALIZATION ]------ public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user) { this.profile = baseProfile; this.youTubeURLsProp = serializedEditableModProfile.FindPropertyRelative("youTubeURLs"); this.sketchfabURLsProp = serializedEditableModProfile.FindPropertyRelative("sketchfabURLs"); this.galleryImagesProp = serializedEditableModProfile.FindPropertyRelative("galleryImageLocators"); this.isYouTubeExpanded = false; this.isSketchFabExpanded = false; this.isImagesExpanded = false; // Initialize textureCache int arraySize = galleryImagesProp.FindPropertyRelative("value").arraySize; this.textureCache = new Dictionary <string, Texture2D>(arraySize); for (int i = 0; i < arraySize; ++i) { string imageFileName = GetGalleryImageFileName(i); string imageURL = GetGalleryImageSource(i); if (!String.IsNullOrEmpty(imageFileName) && !String.IsNullOrEmpty(imageURL)) { GalleryImageLocator imageLocator = baseProfile.media.GetGalleryImageWithFileName(imageFileName); this.textureCache[imageFileName] = EditorImages.LoadingPlaceholder; if (imageLocator != null) { ModManager.GetModGalleryImage(baseProfile.id, imageLocator, IMAGE_PREVIEW_SIZE, (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; }, null); } else { byte[] data = null; data = File.ReadAllBytes(imageURL); if (data != null) { this.textureCache[imageFileName] = IOUtilities.ParseImageData(data); } } } } }
private IEnumerable <(int id, byte[] data)> GetFiles(INode root) { foreach (var node in Traverse(root)) { if (!TryGetPrefixedPath(root, node.Id, out var path)) { continue; } if (File.Exists(path)) { yield return(node.Id, File.ReadAllBytes(path)); } } }
public async Task DiscordAuthAsync(string prefix) { Process.Start( "https://discord.com/api/oauth2/authorize?client_id=770277582460551178&redirect_uri=http%3A%2F%2Flocalhost%3A8910%2Fcallback%2F&response_type=code&scope=identify"); // Create a listener. HttpListener listener = new HttpListener(); listener.Prefixes.Add(prefix); // Start listening listener.Start(); HttpListenerContext context = await listener.GetContextAsync(); // Get request from context HttpListenerRequest request = context.Request; // Get token from code GetAccessToken(request.QueryString["code"]); while (_token is null) { // Slow polling await Task.Delay(25); } GetCurrentUser(); while (DiscordTag is null) { // Slow polling await Task.Delay(25); } // Obtain a response object. HttpListenerResponse response = context.Response; // Construct a response. byte[] buffer = File.ReadAllBytes("Assets/Labyrinth - Authorized.html"); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; await response.OutputStream.WriteAsync(buffer, 0, buffer.Length); response.OutputStream.Close(); listener.Close(); }
// ------[ INITIALIZATION ]------ public void OnEnable(SerializedProperty serializedEditableModProfile, ModProfile baseProfile, UserProfile user) { this.editableProfileProperty = serializedEditableModProfile; this.profile = baseProfile; this.isUndoEnabled = (baseProfile != null); isTagsExpanded = false; isKVPsExpanded = false; // - Game Profile - ModManager.GetGameProfile((g) => { this.gameProfile = g; isRepaintRequired = true; }, null); // - Configure Properties - logoProperty = editableProfileProperty.FindPropertyRelative("logoLocator"); // - Load Textures - if (logoProperty.FindPropertyRelative("isDirty").boolValue == true) { logoLocation = logoProperty.FindPropertyRelative("value.url").stringValue; byte[] data = null; data = File.ReadAllBytes(logoLocation); if (data != null) { lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime; logoTexture = IOUtilities.ParseImageData(data); } } else if (profile != null) { logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE); logoTexture = EditorImages.LoadingPlaceholder; ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE, (t) => { logoTexture = t; isRepaintRequired = true; }, null); } else { logoLocation = string.Empty; logoTexture = null; } }
internal void Actual_ShouldCompileWithResource() { var outputFileLocation = rootFolder + "\\temp.exe"; string resourceDirectory = rootFolder + "\\WithReference\\CSharp"; string resourceFile = resourceDirectory + "\\test.resource"; System.IO.Directory.CreateDirectory(resourceDirectory); File.Create(resourceFile).Dispose(); Task.Build.Csc.Target.Library(x => x.AddSources(GetBasicSources()) .AddResource(resourceFile) .OutputFileTo(outputFileLocation)); Assert.That(File.Exists(outputFileLocation)); Assembly assembly = Assembly.Load(File.ReadAllBytes(outputFileLocation)); Assert.That(assembly.GetManifestResourceNames().Contains("test.resource"), Is.True); }
public void PollForAppointmentReminderViaFax() { var eventRepository = IoC.Resolve <IEventRepository>(); var customerRepository = IoC.Resolve <ICustomerRepository>(); var smsNotificationFactory = IoC.Resolve <IPhoneNotificationModelsFactory>(); var customerRessultRepository = IoC.Resolve <IEventCustomerResultRepository>(); var pcpc = IoC.Resolve <IPrimaryCarePhysicianRepository>(); var settings = IoC.Resolve <ISettings>(); var theevent = eventRepository.GetById(33062); var customer = customerRepository.GetCustomer(645103); var notificationModel = smsNotificationFactory.GetScreeningReminderSmsNotificationModel(customer, theevent); var media = settings.MediaLocation + "//temp//" + ConfigurationManager.AppSettings.Get("FaxTestPDF"); if (!IoFile.Exists(media)) { return; } var bytes = IoFile.ReadAllBytes(media); _notifier.NotifyViaFax(NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification, NotificationTypeAlias.PhysicianPartnerCustomerResultFaxNotification, new PhoneNumber(CountryCode.UnitedStatesAndCanada, "111", "1111111", PhoneNumberType.Unknown), bytes, customer.UserLogin.Id, "integration test"); }
public async Task Copies_file_to_destination() { var source = CreateRandomFile(0x10000); var copy = new FileCopy(0x1000); copy.ProgressChanged += (o, e) => { Console.WriteLine(e.Percent); }; var destination = Guid.NewGuid().ToString(); await copy.CopyAsync(source, destination, CancellationToken.None); var sourceBytes = F.ReadAllBytes(source); var destBytes = F.ReadAllBytes(destination); destBytes.ShouldBeEquivalentTo(sourceBytes, o => o.WithStrictOrdering()); F.Delete(destination); F.Delete(source); }
protected override IndirectDataSet BuildDataset(DataSetBuilder builder) { Utils.CheckFileExists(DataFile); byte[] data = File.ReadAllBytes(DataFile); return((builder as BuildFromBuffer).Build(data)); }
/// <summary>Keep reference to target "extension" files.</summary> /// <param name="ObjectProp">The serializedProperty from UnityEngine.Object.</param> /// <param name="extension">The file extension, within project folder.</param> /// <param name="title">The message wanted to display when developer click on file panel button.</param> /// <param name="OnBecomeNull">The callback while ObjectField become Null.</param> /// <param name="OnSuccess">The callback while ObjectField assign correct file type.</param> /// <param name="OnSuccessReadText"> /// The callback while ObjectField assign correct file type. /// this will try to read all text from target file. /// </param> /// <param name="OnSuccessReadBytes"> /// The callback while ObjectField assign correct file type. /// this will try to read all data as bytes[] from target file. /// </param> public static void ProjectFileField(SerializedProperty ObjectProp, string extension = "txt", string title = "", System.Action OnBecomeNull = null, System.Action OnSuccess = null, System.Action <string> OnSuccessReadText = null, System.Action <byte[]> OnSuccessReadBytes = null) { if (ObjectProp.propertyType != SerializedPropertyType.ObjectReference) { EditorGUILayout.HelpBox("Only available for Object field.", MessageType.Error); return; } // necessary infos. string oldAssetPath = ObjectProp.objectReferenceValue ? AssetDatabase.GetAssetPath(ObjectProp.objectReferenceValue) : null; extension = extension.TrimStart('.').ToLower(); // Editor draw EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(ObjectProp, true); if (GUILayout.Button("*." + extension, GUILayout.Width(80f))) { // Locate file by file panel. title = string.IsNullOrEmpty(title) ? "Open *." + extension + " file" : title; oldAssetPath = string.IsNullOrEmpty(oldAssetPath) ? Application.dataPath : Path.GetDirectoryName(oldAssetPath); string path = EditorUtility.OpenFilePanel(title, oldAssetPath, extension); string assetPath = string.IsNullOrEmpty(path) ? null : FileUtil.GetProjectRelativePath(path); if (!string.IsNullOrEmpty(assetPath)) { Object obj = AssetDatabase.LoadAssetAtPath <Object>(assetPath); if (obj == null) { throw new System.InvalidProgramException(); } ObjectProp.objectReferenceValue = obj; ObjectProp.serializedObject.ApplyModifiedProperties(); } // else cancel } EditorGUILayout.EndHorizontal(); // Change check. if (EditorGUI.EndChangeCheck()) { Object obj = ObjectProp.objectReferenceValue; string assetPath = obj ? AssetDatabase.GetAssetPath(obj) : null; string fileExt = string.IsNullOrEmpty(assetPath) ? null : Path.GetExtension(assetPath); // we got things, so what is that ? bool match = obj != null; // vaild path if (match) { match &= !string.IsNullOrEmpty(assetPath); if (!match) { throw new System.InvalidProgramException("Error: " + obj + " have invalid path."); } } // vaild extension if (match) { match &= fileExt.TrimStart('.').ToLower() == extension; if (!match) { EditorUtility.DisplayDialog("Wrong file type", "Wrong file assigned !" + "\n\t" + ObjectProp.serializedObject.targetObject.name + " > " + ObjectProp.displayName + "\n\tCan only accept [*." + extension + "] asset.", "Ok !"); } // Debug.LogError("Wrong file type, only accept [*." + extension + "] asset.", ObjectProp.serializedObject.targetObject); } if (match) { // seem like we got what we needed. ObjectProp.serializedObject.ApplyModifiedProperties(); if (OnSuccess != null) { OnSuccess(); } if (OnSuccessReadText != null) { string txt = File.ReadAllText(assetPath); OnSuccessReadText(txt); } if (OnSuccessReadBytes != null) { byte[] bytes = File.ReadAllBytes(assetPath); OnSuccessReadBytes(bytes); } } else { ObjectProp.objectReferenceValue = null; ObjectProp.serializedObject.ApplyModifiedProperties(); if (OnBecomeNull != null) { OnBecomeNull(); } return; } } }
protected virtual void LayoutLogoField() { bool doBrowse = false; // - Browse Field - EditorGUILayout.BeginHorizontal(); doBrowse |= EditorGUILayoutExtensions.BrowseButton(logoLocation, new GUIContent("Logo")); bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled); EditorGUILayout.EndHorizontal(); // - Draw Texture - if (logoTexture != null) { Rect logoRect = EditorGUILayout.GetControlRect(false, LOGO_PREVIEW_HEIGHT); EditorGUI.DrawPreviewTexture(new Rect((logoRect.width - LOGO_PREVIEW_WIDTH) * 0.5f, logoRect.y, LOGO_PREVIEW_WIDTH, logoRect.height), logoTexture, null, ScaleMode.ScaleAndCrop); doBrowse |= GUI.Button(logoRect, "", GUI.skin.label); } if (doBrowse) { EditorApplication.delayCall += () => { string path = EditorUtility.OpenFilePanelWithFilters("Select Mod Logo", "", IMAGE_FILE_FILTER); byte[] data = null; data = File.ReadAllBytes(path); if (data != null) { logoProperty.FindPropertyRelative("value.url").stringValue = path; logoProperty.FindPropertyRelative("value.fileName").stringValue = Path.GetFileName(path); logoProperty.FindPropertyRelative("isDirty").boolValue = true; logoProperty.serializedObject.ApplyModifiedProperties(); logoTexture = IOUtilities.ParseImageData(data); logoLocation = path; lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime; } }; } if (isUndoRequested) { logoProperty.FindPropertyRelative("value.url").stringValue = profile.logoLocator.GetURL(); logoProperty.FindPropertyRelative("value.fileName").stringValue = profile.logoLocator.GetFileName(); logoProperty.FindPropertyRelative("isDirty").boolValue = false; logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE); logoTexture = EditorImages.LoadingPlaceholder; ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE, (t) => { logoTexture = t; isRepaintRequired = true; }, null); } }
public byte[] Load() { return(File.ReadAllBytes(_filePath)); }
// - Image Locator Layouting - private void LayoutGalleryImageProperty(int elementIndex, SerializedProperty elementProperty) { bool doBrowse = false; bool doClear = false; string imageFileName = elementProperty.FindPropertyRelative("fileName").stringValue; string imageSource = elementProperty.FindPropertyRelative("url").stringValue; // - Browse Field - EditorGUILayout.BeginHorizontal(); doBrowse |= EditorGUILayoutExtensions.BrowseButton(imageSource, new GUIContent("Image " + elementIndex)); doClear = EditorGUILayoutExtensions.ClearButton(); EditorGUILayout.EndHorizontal(); // - Draw Texture - Texture2D imageTexture = GetGalleryImageByIndex(elementIndex); if (imageTexture != null) { EditorGUI.indentLevel += 2; EditorGUILayout.LabelField("File Name", imageFileName); Rect imageRect = EditorGUILayout.GetControlRect(false, 180.0f); imageRect = EditorGUI.IndentedRect(imageRect); EditorGUI.DrawPreviewTexture(new Rect(imageRect.x, imageRect.y, 320.0f, imageRect.height), imageTexture, null, ScaleMode.ScaleAndCrop); doBrowse |= GUI.Button(imageRect, "", GUI.skin.label); EditorGUI.indentLevel -= 2; } if (doBrowse) { EditorApplication.delayCall += () => { string path = EditorUtility.OpenFilePanelWithFilters("Select Gallery Image", "", ModMediaViewPart.IMAGE_FILE_FILTER); byte[] data = null; data = File.ReadAllBytes(path); Texture2D newTexture = null; if (data != null) { newTexture = IOUtilities.ParseImageData(data); } if (newTexture != null) { string fileName = GenerateUniqueFileName(path); elementProperty.FindPropertyRelative("url").stringValue = path; elementProperty.FindPropertyRelative("fileName").stringValue = fileName; galleryImagesProp.FindPropertyRelative("isDirty").boolValue = true; galleryImagesProp.serializedObject.ApplyModifiedProperties(); textureCache.Add(fileName, newTexture); } }; } if (doClear) { elementProperty.FindPropertyRelative("url").stringValue = string.Empty; elementProperty.FindPropertyRelative("fileName").stringValue = string.Empty; galleryImagesProp.FindPropertyRelative("isDirty").boolValue = true; galleryImagesProp.serializedObject.ApplyModifiedProperties(); } }