Ejemplo n.º 1
0
        public void TestExecuteParameterAndResultSetsFirstRow(
            [Values(OutputOption.FirstRow, OutputOption.FirstRowElseEmptyRow)]
            OutputOption outputOption)
        {
            var parameters = DatabaseObjectCreation.CreateParameterAndResultSetsTestProc(this.connectionType);

            try
            {
                List <byte> bytes  = new List <byte>(new byte[] { 1, 2, 3, 4, 5 });
                var         result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, new object[] { 2, 1.0, "Qwer", string.Empty, new DateTime(1987, 1, 24), DatabaseModel.DefaultDateTime, bytes, new List <byte>() }, true, outputOption).Value;

                Assert.AreEqual("Qwer", result.ResultParameters.StringValueOut);
                Assert.AreEqual(new DateTime(1987, 1, 24), result.ResultParameters.DateValueOut);
                Assert.AreEqual(bytes, result.ResultParameters.BytesValueOut);

                Assert.AreEqual("qwer", result.Result1.StringValue);

                Assert.AreEqual(1, result.Result2.Counter);
                Assert.AreEqual("Qwer", result.Result2.StringValue);
            }
            finally
            {
                DatabaseObjectCreation.RemoveTestProc(this.connectionType);
            }
        }
 public Windows.Foundation.IAsyncOperation<Bitmap> GetBitmapAsync(Bitmap bitmap, OutputOption outputOption)
 {
     IImageProvider provider = null;
     if (pipelineEnd == null || !pipelineEnd.TryGetTarget(out provider))
         return null;
     else
         return provider.GetBitmapAsync(bitmap, outputOption);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Benchmarks Coordinate initialization with eager loading settings turned off.
        /// </summary>
        public static void EagerLoadOff_Initilization(OutputOption opt)
        {
            Benchmark(() => {
                EagerLoad eg = new EagerLoad(false);

                var tc = new Coordinate(39.891219, -74.872435, new DateTime(2018, 7, 26, 15, 49, 0), eg);
            }, 100, "Eager Load Off Initialization", opt);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Benchmark magnetic calculations.
        /// </summary>
        /// <param name="opt"></param>
        static void Magnetic_Calculations(OutputOption opt)
        {
            Coordinate c = new Coordinate(45, 45, new DateTime(2021, 1, 1), new EagerLoad(false));

            Benchmarkers.Benchmark(() => {
                Magnetic m = new Magnetic(c, DataModel.WMM2020);
            }, 100, "Magnetic Calculation Times", opt);
        }
        /// <summary>
        /// Renders the IImageProvider into a Bitmap. If the passed Bitmap is non-null, and it matches the passed size and color mode, it will be reused. Otherwise this method creates a new Bitmap.
        /// </summary>
        /// <param name="imageProvider">The image provider to render the image content of.</param>
        /// <param name="bitmap">The Bitmap to reuse, if possible. If null is passed, a new Bitmap is created.</param>
        /// <param name="size">The desired size of the rendered image.</param>
        /// <param name="outputOption">Specifies how to fit the image into the rendered rectangle, if the aspect ratio differs.</param>
        /// <returns>A task resulting in either the reused Bitmap, or a new one if necessary.</returns>
        public static Task<Bitmap> GetBitmapAsync(this IImageProvider imageProvider, Bitmap bitmap, Size size, ColorMode colorMode, OutputOption outputOption)
        {
            if (bitmap == null || bitmap.Dimensions != size || bitmap.ColorMode != colorMode)
            {
                bitmap = new Bitmap(size, colorMode);
            }

            return imageProvider.GetBitmapAsync(bitmap, outputOption).AsTask();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Benchmarks time to change a property of the Coordinate object.
        /// </summary>
        public static void Property_Change(OutputOption opt)
        {
            var tc = new Coordinate(39.891219, -74.872435, new DateTime(2018, 7, 26, 15, 49, 0));

            //Benchmark property change
            Random r = new Random();

            Benchmark(() => { tc.Latitude.DecimalDegree = r.Next(-90, 90); }, 100, "Property Change", opt);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Benchmarks Coordinate Secondary initialization method.
 /// </summary>
 public static void Secondary_Initialization(OutputOption opt)
 {
     Benchmark(() => {
         var tc       = new Coordinate();
         tc.Latitude  = new CoordinatePart(39, 45, 34, CoordinatesPosition.N);
         tc.Longitude = new CoordinatePart(74, 34, 45, CoordinatesPosition.W);
         tc.GeoDate   = new DateTime(2018, 7, 26, 15, 49, 0);
     }, 100, "Secondary Initialization", opt);
 }
        /// <summary>
        /// Renders the IImageProvider into a WriteableBitmap. If the passed WriteableBitmap is non-null, and it matches the passed size, it will be reused. Otherwise this method creates a new WriteableBitmap. Note that this method must be called on the UI thread.
        /// </summary>
        /// <param name="imageProvider">The image provider to render the image content of.</param>
        /// <param name="writeableBitmap">The WriteableBitmap to reuse, if possible. If null is passed, a new WriteableBitmap is created.</param>
        /// <param name="size">The desired size of the rendered image.</param>
        /// <param name="outputOption">Specifies how to fit the image into the rendered rectangle, if the aspect ratio differs.</param>
        /// <returns>A task resulting in either the reused WriteableBitmap, or a new one if necessary.</returns>
        public static Task<WriteableBitmap> GetBitmapAsync(this IImageProvider imageProvider, WriteableBitmap writeableBitmap, Size size, OutputOption outputOption)
        {
            if (writeableBitmap == null || writeableBitmap.PixelWidth != (int)size.Width || writeableBitmap.PixelHeight != (int)size.Height)
            {
                writeableBitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
            }

            return imageProvider.GetBitmapAsync(writeableBitmap, outputOption).AsTask();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Benchmarks all celestial calculations occurring in local time.
        /// </summary>
        public static void Celestial_Calculations_Local_Time_From_Coordinate(OutputOption opt)
        {
            EagerLoad  el = new EagerLoad();
            Coordinate c  = new Coordinate(45, 45, DateTime.Now, el);

            //Benchmark Local Times
            Benchmark(() => {
                Celestial cel = c.Celestial_LocalTime(-7);
            }, 100, "Local Celestial Times From Coordinate", opt);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Benchmarks lunar cycle calculations.
        /// </summary>
        public static void Lunar_Cycle_Calculations(OutputOption opt)
        {
            EagerLoad  el = new EagerLoad();
            Coordinate c  = new Coordinate(45, 45, DateTime.Now, el);

            el.Extensions = new EagerLoad_Extensions(EagerLoad_ExtensionsType.Lunar_Cycle);
            Benchmark(() => {
                Celestial cel = c.Celestial_LocalTime(-7);
            }, 100, "Local Lunar Cycle Only Times From Coordinate", opt);
        }
        /// <summary>
        /// Renders the IImageProvider into a Bitmap. If the passed Bitmap is non-null, and it matches the passed size and color mode, it will be reused. Otherwise this method creates a new Bitmap.
        /// </summary>
        /// <param name="imageProvider">The image provider to render the image content of.</param>
        /// <param name="bitmap">The Bitmap to reuse, if possible. If null is passed, a new Bitmap is created.</param>
        /// <param name="size">The desired size of the rendered image.</param>
        /// <param name="outputOption">Specifies how to fit the image into the rendered rectangle, if the aspect ratio differs.</param>
        /// <returns>A task resulting in either the reused Bitmap, or a new one if necessary.</returns>
        public static async Task<Bitmap> GetBitmapAsync(this IImageProvider imageProvider, Bitmap bitmap, Size size, ColorMode colorMode, OutputOption outputOption)
        {
            if (bitmap == null || bitmap.Dimensions != size || bitmap.ColorMode != colorMode)
            {
                bitmap = new Bitmap(size, colorMode);
            }

            using (var renderer = new BitmapRenderer(imageProvider, bitmap, outputOption))
            {
                return await renderer.RenderAsync().AsTask().ConfigureAwait(false);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Run built in benchmarks.
        /// </summary>
        public static void Run_Benchmarks(OutputOption opt)
        {
            Standard_Initialization(opt);
            Secondary_Initialization(opt);
            EagerLoadOff_Initilization(opt);
            TryParse(opt);
            TryParse_EagerLoad_Off(opt);
            Property_Change(opt);

            Celestial_Calculations(opt);
            Celestial_Calculations_Local_Time_From_Coordinate(opt);
            Solar_Cycle_Calculations(opt);
            Lunar_Cycle_Calculations(opt);
        }
Ejemplo n.º 13
0
        public virtual IPipelineBuilder Configure(PSDocumentOption option)
        {
            Option.Document  = DocumentOption.Combine(option.Document, DocumentOption.Default);
            Option.Execution = ExecutionOption.Combine(option.Execution, ExecutionOption.Default);
            Option.Markdown  = MarkdownOption.Combine(option.Markdown, MarkdownOption.Default);
            Option.Output    = OutputOption.Combine(option.Output, OutputOption.Default);

            if (!string.IsNullOrEmpty(Option.Output.Path))
            {
                OutputVisitor = (o, enumerate) => WriteToFile(o, Option, Writer, ShouldProcess);
            }

            ConfigureCulture();
            return(this);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Output all public property values of a class.
 /// </summary>
 /// <param name="obj">Object</param>
 /// <param name="opt">Output Option</param>
 /// <param name="leadingString">Output Leading String</param>
 public static void Output_Class_Values(object obj, OutputOption opt, string leadingString)
 {
     PropertyInfo[] properties = obj.GetType().GetProperties();
     foreach (PropertyInfo property in properties)
     {
         if (opt == OutputOption.Console)
         {
             Console.WriteLine(leadingString + property.Name + ": " + property.GetValue(obj, null));
         }
         else if (opt == OutputOption.Debugger)
         {
             Debug.WriteLine(leadingString + property.Name + ": " + property.GetValue(obj, null));
         }
     }
 }
Ejemplo n.º 15
0
        public void TestExecuteResultSetFirstRow(
            [Values(OutputOption.FirstRow, OutputOption.FirstRowElseEmptyRow)] OutputOption outputOption)
        {
            var parameters = DatabaseObjectCreation.CreateResultSetTestProc(this.connectionType);

            try
            {
                var result = Execute(this.connectionType, DatabaseHelpers.GetDefaultConnectionString(this.connectionType), "Test Proc", parameters, new object[] { 2 }, true, outputOption).Value;

                Assert.AreEqual(1, result.Result.Counter);
                Assert.AreEqual("one", result.Result.StringValue);
            }
            finally
            {
                DatabaseObjectCreation.RemoveTestProc(this.connectionType);
            }
        }
Ejemplo n.º 16
0
        private static FunctionResult Execute(ConnectionTypeSelection connectionType, Transaction transaction, string connectionString, string storedProcedureName,
                                              DatabaseModel.ProcedureParameters parameters = null, object[] parameterValues = null, DatabaseModel.ResultSets resultSets = null, int?numberOfResultSets = null,
                                              OutputOption outputOption = OutputOption.RowByRow)
        {
            if (parameters == null)
            {
                parameters = new DatabaseModel.ProcedureParameters();
            }
            if (resultSets == null)
            {
                resultSets = new DatabaseModel.ResultSets();
            }

            int i = 0, j = 0;
            var tester = (new FunctionTester <ExecuteStoredProcedure.ExecuteStoredProcedure>()).Compile(new PropertyValue[] {
                new PropertyValue(DbShared.ConnectionTypePropertyName, connectionType),
                new PropertyValue(ExecuteStoredProcedureShared.ParametersPropertyName, parameters),
                new PropertyValue(ExecuteStoredProcedureShared.OutputOptionPropertyName, outputOption),
                new PropertyValue(ExecuteStoredProcedureShared.ResultSetCountPropertyName, (numberOfResultSets.HasValue)? numberOfResultSets.Value : resultSets.Count)
            }.Concat(
                                                                                                            resultSets.Select(r => new PropertyValue(string.Format(ExecuteStoredProcedureShared.ResultSetPropertyNameFormat, ++i), resultSets[j++]))
                                                                                                            ).ToArray());

            i = 0;

            var executeParameters = new ParameterValue[]
            {
                new ParameterValue(ExecuteStoredProcedureShared.StoredProcedurePropertyName, storedProcedureName)
            };

            if (connectionType == ConnectionTypeSelection.UseTransaction)
            {
                executeParameters = executeParameters.Concat(new ParameterValue[] { new ParameterValue(DbShared.TransactionPropertyName, transaction) }).ToArray();
            }
            else
            {
                executeParameters = executeParameters.Concat(new ParameterValue[] { new ParameterValue(DbShared.ConnectionStringPropertyName, connectionString) }).ToArray();
            }

            return(tester.Execute(executeParameters
                                  .Concat(
                                      parameters.Where(p => (p.Direction == DatabaseModel.ParameterDirection.In) || (p.Direction == DatabaseModel.ParameterDirection.InOut))
                                      .Select(p => new ParameterValue(p.DisplayPropertyName, parameterValues[i++]))).ToArray()));
        }
 public Windows.Foundation.IAsyncOperation<Bitmap> GetBitmapAsync(Bitmap bitmap, OutputOption outputOption)
 {
     IImageProvider provider = null;
     if (pipelineEnd == null || !pipelineEnd.TryGetTarget(out provider))
         throw new InvalidOperationException("No image provider in the pipeline.");
     else
         return provider.GetBitmapAsync(bitmap, outputOption);
 }
Ejemplo n.º 18
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            if (m_enabledBundleOptions == null)
            {
                return;
            }

            EditorGUILayout.HelpBox("Build Asset Bundles: Build asset bundles with given asset bundle settings.", MessageType.Info);
            editor.UpdateNodeName(node);

            bool newOverwrite = EditorGUILayout.ToggleLeft("Keep AssetImporter settings for variants", m_overwriteImporterSetting);

            if (newOverwrite != m_overwriteImporterSetting)
            {
                using (new RecordUndoScope("Remove Target Bundle Options", node, true)){
                    m_overwriteImporterSetting = newOverwrite;
                    onValueChanged();
                }
            }

            GUILayout.Space(10f);

            //Show target configuration tab
            editor.DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var disabledScope = editor.DrawOverrideTargetToggle(node, m_enabledBundleOptions.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                    using (new RecordUndoScope("Remove Target Bundle Options", node, true)){
                        if (enabled)
                        {
                            m_enabledBundleOptions[editor.CurrentEditingGroup] = m_enabledBundleOptions.DefaultValue;
                            m_outputDir[editor.CurrentEditingGroup]            = m_outputDir.DefaultValue;
                            m_outputOption[editor.CurrentEditingGroup]         = m_outputOption.DefaultValue;
                            m_manifestName[editor.CurrentEditingGroup]         = m_manifestName.DefaultValue;
                        }
                        else
                        {
                            m_enabledBundleOptions.Remove(editor.CurrentEditingGroup);
                            m_outputDir.Remove(editor.CurrentEditingGroup);
                            m_outputOption.Remove(editor.CurrentEditingGroup);
                            m_manifestName.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    }
                });

                using (disabledScope) {
                    OutputOption opt       = (OutputOption)m_outputOption[editor.CurrentEditingGroup];
                    var          newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt);
                    if (newOption != opt)
                    {
                        using (new RecordUndoScope("Change Output Option", node, true)){
                            m_outputOption[editor.CurrentEditingGroup] = (int)newOption;
                            onValueChanged();
                        }
                    }

                    using (new EditorGUI.DisabledScope(opt == OutputOption.BuildInCacheDirectory)) {
                        var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                                   m_outputDir[editor.CurrentEditingGroup],
                                                                   Application.dataPath + "/../",
                                                                   (string folderSelected) => {
                            var projectPath = Directory.GetParent(Application.dataPath).ToString();

                            if (projectPath == folderSelected)
                            {
                                folderSelected = string.Empty;
                            }
                            else
                            {
                                var index = folderSelected.IndexOf(projectPath);
                                if (index >= 0)
                                {
                                    folderSelected = folderSelected.Substring(projectPath.Length + index);
                                    if (folderSelected.IndexOf('/') == 0)
                                    {
                                        folderSelected = folderSelected.Substring(1);
                                    }
                                }
                            }
                            return(folderSelected);
                        }
                                                                   );
                        if (newDirPath != m_outputDir[editor.CurrentEditingGroup])
                        {
                            using (new RecordUndoScope("Change Output Directory", node, true)){
                                m_outputDir[editor.CurrentEditingGroup] = newDirPath;
                                onValueChanged();
                            }
                        }

                        var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data, false, false);

                        if (opt == OutputOption.ErrorIfNoOutputDirectoryFound &&
                            editor.CurrentEditingGroup != BuildTargetGroup.Unknown &&
                            !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) &&
                            !Directory.Exists(outputDir))
                        {
                            using (new EditorGUILayout.HorizontalScope()) {
                                Debug.LogWarning("BundleBuilder" + outputDir + " does not exist.");
                                EditorGUILayout.LabelField(outputDir + " does not exist.");
                                if (GUILayout.Button("Create directory"))
                                {
                                    Directory.CreateDirectory(outputDir);
                                }
                            }
                            EditorGUILayout.Space();

                            string parentDir = Path.GetDirectoryName(m_outputDir[editor.CurrentEditingGroup]);
                            if (Directory.Exists(parentDir))
                            {
                                EditorGUILayout.LabelField("Available Directories:");
                                string[] dirs = Directory.GetDirectories(parentDir);
                                foreach (string s in dirs)
                                {
                                    EditorGUILayout.LabelField(s);
                                }
                            }
                            EditorGUILayout.Space();
                        }

                        using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                        {
                            using (new EditorGUILayout.HorizontalScope()) {
                                GUILayout.FlexibleSpace();
                                #if UNITY_EDITOR_OSX
                                string buttonName = "Reveal in Finder";
                                #else
                                string buttonName = "Show in Explorer";
                                #endif
                                if (GUILayout.Button(buttonName))
                                {
                                    EditorUtility.RevealInFinder(outputDir);
                                }
                            }
                        }

                        EditorGUILayout.HelpBox("You can use '{Platform}' variable for Output Directory path to include platform name.", MessageType.Info);
                    }

                    GUILayout.Space(8f);

                    var manifestName    = m_manifestName[editor.CurrentEditingGroup];
                    var newManifestName = EditorGUILayout.TextField("Manifest Name", manifestName);
                    if (newManifestName != manifestName)
                    {
                        using (new RecordUndoScope("Change Manifest Name", node, true)){
                            m_manifestName[editor.CurrentEditingGroup] = newManifestName;
                            onValueChanged();
                        }
                    }

                    GUILayout.Space(8f);

                    int bundleOptions = m_enabledBundleOptions[editor.CurrentEditingGroup];

                    bool isDisableWriteTypeTreeEnabled  = 0 < (bundleOptions & (int)BuildAssetBundleOptions.DisableWriteTypeTree);
                    bool isIgnoreTypeTreeChangesEnabled = 0 < (bundleOptions & (int)BuildAssetBundleOptions.IgnoreTypeTreeChanges);

                    // buildOptions are validated during loading. Two flags should not be true at the same time.
                    UnityEngine.Assertions.Assert.IsFalse(isDisableWriteTypeTreeEnabled && isIgnoreTypeTreeChangesEnabled);

                    bool isSomethingDisabled = isDisableWriteTypeTreeEnabled || isIgnoreTypeTreeChangesEnabled;

                    foreach (var option in Model.Settings.BundleOptionSettings)
                    {
                        // contains keyword == enabled. if not, disabled.
                        bool isEnabled = (bundleOptions & (int)option.option) != 0;

                        bool isToggleDisabled =
                            (option.option == BuildAssetBundleOptions.DisableWriteTypeTree && isIgnoreTypeTreeChangesEnabled) ||
                            (option.option == BuildAssetBundleOptions.IgnoreTypeTreeChanges && isDisableWriteTypeTreeEnabled);

                        using (new EditorGUI.DisabledScope(isToggleDisabled)) {
                            var result = EditorGUILayout.ToggleLeft(option.description, isEnabled);
                            if (result != isEnabled)
                            {
                                using (new RecordUndoScope("Change Bundle Options", node, true)){
                                    bundleOptions = (result) ?
                                                    ((int)option.option | bundleOptions) :
                                                    (((~(int)option.option)) & bundleOptions);
                                    m_enabledBundleOptions[editor.CurrentEditingGroup] = bundleOptions;
                                    onValueChanged();
                                }
                            }
                        }
                    }
                    if (isSomethingDisabled)
                    {
                        EditorGUILayout.HelpBox("'Disable Write Type Tree' and 'Ignore Type Tree Changes' can not be used together.", MessageType.Info);
                    }
                }
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Benchmarks Coordinate initialization method,
 /// </summary>
 public static void Standard_Initialization(OutputOption opt)
 {
     Benchmark(() => { var tc = new Coordinate(39.891219, -74.872435, new DateTime(2018, 7, 26, 15, 49, 0)); }, 100, "Standard Initialization", opt);
 }
Ejemplo n.º 20
0
 private static FunctionResult Execute(ConnectionType connectionType, string connectionString, string storedProcedureName, DatabaseModel.ProcedureParameters parameters = null, object[] parameterValues = null, DatabaseModel.ResultSets resultSets = null, OutputOption outputOption = OutputOption.RowByRow)
 {
     return(Execute(connectionType.ToConnectionTypeSelection(), null, connectionString, storedProcedureName, parameters, parameterValues, resultSets, null, outputOption));
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Benchmarke Tool.
        /// </summary>
        /// <param name="act">Action</param>
        /// <param name="iterations">Iterations</param>
        /// <param name="bechmarkName">Benchmark Name</param>
        /// <param name="opt">Output Option</param>
        public static void Benchmark(Action act, int iterations, string bechmarkName, OutputOption opt)
        {
            GC.Collect();
            act.Invoke(); // run once outside of loop to avoid initialization costs
            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < iterations; i++)
            {
                act.Invoke();
            }
            sw.Stop();

            if (opt == OutputOption.Console)
            {
                Console.Write(bechmarkName + ": ");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write((sw.ElapsedMilliseconds / iterations).ToString() + " ms");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
            }
            else if (opt == OutputOption.Debugger)
            {
                Debug.WriteLine($"{bechmarkName}: {(sw.ElapsedMilliseconds / iterations).ToString()} ms");
            }
        }
Ejemplo n.º 22
0
        public override void GenerateCode(IFunctionBuilder functionBuilder)
        {
            ExecuteStoredProcedureX_Gen generator = new ExecuteStoredProcedureX_Gen();

            generator.Session = new Dictionary <string, object>();
            generator.Session.Add("FunctionContextProperty", functionBuilder.ContextParamName);
            ConnectionTypeSelection connectionType = FunctionData.Properties[DbShared.ConnectionTypePropertyName].GetValue <ConnectionTypeSelection>();
            bool useTransaction = connectionType == ConnectionTypeSelection.UseTransaction;

            generator.Session.Add("UseTransaction", useTransaction);
            if (useTransaction)
            {
                generator.Session.Add("TransactionProperty", functionBuilder.GetParamName(DbShared.TransactionPropertyName));
            }
            else
            {
                generator.Session.Add("ConnectionType", connectionType.ToConnectionType());
                generator.Session.Add("ConnectionStringProperty", functionBuilder.GetParamName(DbShared.ConnectionStringPropertyName));
            }
            generator.Session.Add("StoredProcedureProperty", functionBuilder.GetParamName(ExecuteStoredProcedureShared.StoredProcedurePropertyName));
            var parameters = FunctionData.Properties[ExecuteStoredProcedureShared.ParametersPropertyName].GetValue <DatabaseModel.ProcedureParameters>();

            generator.Session.Add("Parameters", parameters);
            generator.Session.Add("GetParamName", new Func <string, string>(functionBuilder.GetParamName));

            generator.Session.Add("OutputTypeName", FunctionData.Output == null ? null : functionBuilder.GetTypeName(FunctionData.Output));
            bool hasOutParameters = parameters.Any(p => (p.Direction != DatabaseModel.ParameterDirection.In) && (p.DataType != DatabaseModel.DataType.RefCursor));

            generator.Session.Add("OutParametersOutputPropertyName", hasOutParameters ? ExecuteStoredProcedureShared.OutParametersOutputPropertyName : null);
            generator.Session.Add("OutParametersOutputTypeName", hasOutParameters ? functionBuilder.GetTypeName(FunctionData.Output.GetProperty(ExecuteStoredProcedureShared.OutParametersOutputPropertyName).TypeReference) : null);

            OutputOption outputOption = FunctionData.Properties[ExecuteStoredProcedureShared.OutputOptionPropertyName].GetValue <OutputOption>();

            generator.Session.Add("OutputOption", outputOption);
            int resultSetCount = FunctionData.Properties[ExecuteStoredProcedureShared.ResultSetCountPropertyName].GetValue <int>();

            generator.Session.Add("ResultSets", Enumerable.Range(0, resultSetCount).Select(i => FunctionData.Properties[string.Format(ExecuteStoredProcedureShared.ResultSetPropertyNameFormat, i + 1)].GetValue <DatabaseModel.ResultSet>()).ToArray());
            if (resultSetCount != 0)
            {
                if (outputOption == OutputOption.RowByRow)
                {
                    string[] executionPathKeys  = Enumerable.Range(0, resultSetCount).Select(i => string.Format(ExecuteStoredProcedureShared.ResultSetExecutionPathNameFormat, i + 1)).ToArray();
                    string[] executionPathNames = resultSetCount == 1 ? new string[] { string.Format(ExecuteStoredProcedureShared.ResultSetExecutionPathNameFormat, string.Empty) } : executionPathKeys;
                    generator.Session.Add("RowTypeNames", executionPathKeys.Select(p => functionBuilder.GetTypeName(FunctionData.ExecutionPaths[p].Output)).ToArray());
                    generator.Session.Add("ExecutionPathOutputName", functionBuilder.ExecutionPathOutParamName);
                    generator.Session.Add("ExecutionPathNames", executionPathNames);
                    generator.Session.Add("ResultSetRowOutputPropertyNames", null);
                }
                else if (outputOption == OutputOption.ListOfRows)
                {
                    string[] resultSetRowOutputPropertyNames = resultSetCount == 1 ? new string[] { string.Format(ExecuteStoredProcedureShared.ResultSetRowsOutputPropertyNameFormat, string.Empty) } : Enumerable.Range(0, resultSetCount).Select(i => string.Format(ExecuteStoredProcedureShared.ResultSetRowsOutputPropertyNameFormat, i + 1)).ToArray();
                    generator.Session.Add("RowTypeNames", resultSetRowOutputPropertyNames.Select(p => functionBuilder.GetTypeName(FunctionData.Output.GetProperty(p).TypeReference.GetEnumerableContentType())).ToArray());
                    generator.Session.Add("ResultSetRowOutputPropertyNames", resultSetRowOutputPropertyNames);
                    generator.Session.Add("ExecutionPathOutputName", null);
                    generator.Session.Add("ExecutionPathNames", null);
                }
                else
                {
                    string[] resultSetRowOutputPropertyNames = resultSetCount == 1 ? new string[] { string.Format(ExecuteStoredProcedureShared.ResultSetRowOutputPropertyNameFormat, string.Empty) } : Enumerable.Range(0, resultSetCount).Select(i => string.Format(ExecuteStoredProcedureShared.ResultSetRowOutputPropertyNameFormat, i + 1)).ToArray();
                    generator.Session.Add("RowTypeNames", resultSetRowOutputPropertyNames.Select(p => functionBuilder.GetTypeName(FunctionData.Output.GetProperty(p).TypeReference)).ToArray());
                    generator.Session.Add("ResultSetRowOutputPropertyNames", resultSetRowOutputPropertyNames);
                    generator.Session.Add("ExecutionPathOutputName", null);
                    generator.Session.Add("ExecutionPathNames", null);
                }
            }

            generator.Initialize();
            functionBuilder.AddCode(generator.TransformText());

            functionBuilder.AddAssemblyReference(typeof(ExecuteStoredProcedure));
            functionBuilder.AddAssemblyReference(typeof(IDbCommand));
        }
Ejemplo n.º 23
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Generate Asset: Generate new asset from incoming asset.", MessageType.Info);
            editor.UpdateNodeName(node);

            GUILayout.Space(8f);

            if (m_popupIcon == null)
            {
                m_popupIcon = EditorGUIUtility.Load(EditorGUIUtility.isProSkin ? "icons/d__Popup.png" : "icons/_Popup.png") as Texture2D;
            }

            editor.DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope()) {
                var disabledScope = editor.DrawOverrideTargetToggle(node, m_outputOption.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                    if (enabled)
                    {
                        m_outputOption[editor.CurrentEditingGroup] = m_outputOption.DefaultValue;
                        m_outputDir[editor.CurrentEditingGroup]    = m_outputDir.DefaultValue;
                    }
                    else
                    {
                        m_outputOption.Remove(editor.CurrentEditingGroup);
                        m_outputDir.Remove(editor.CurrentEditingGroup);
                    }
                    onValueChanged();
                });

                using (disabledScope) {
                    OutputOption opt       = (OutputOption)m_outputOption[editor.CurrentEditingGroup];
                    var          newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt);
                    if (newOption != opt)
                    {
                        using (new RecordUndoScope("Change Output Option", node, true)){
                            m_outputOption[editor.CurrentEditingGroup] = (int)newOption;
                            onValueChanged();
                        }
                        opt = newOption;
                    }
                    if (opt != OutputOption.CreateInCacheDirectory)
                    {
                        EditorGUILayout.HelpBox("When you are not creating assets under cache directory, make sure your generators are not overwriting assets each other.", MessageType.Info);
                    }

                    using (new EditorGUI.DisabledScope(opt == OutputOption.CreateInCacheDirectory)) {
                        var newDirPath = m_outputDir[editor.CurrentEditingGroup];

                        if (opt == OutputOption.CreateInSelectedDirectory)
                        {
                            newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                                   m_outputDir [editor.CurrentEditingGroup],
                                                                   Application.dataPath,
                                                                   (string folderSelected) => {
                                string basePath = Application.dataPath;

                                if (basePath == folderSelected)
                                {
                                    folderSelected = string.Empty;
                                }
                                else
                                {
                                    var index = folderSelected.IndexOf(basePath);
                                    if (index >= 0)
                                    {
                                        folderSelected = folderSelected.Substring(basePath.Length + index);
                                        if (folderSelected.IndexOf('/') == 0)
                                        {
                                            folderSelected = folderSelected.Substring(1);
                                        }
                                    }
                                }
                                return(folderSelected);
                            }
                                                                   );
                        }
                        else if (opt == OutputOption.RelativeToSourceAsset)
                        {
                            newDirPath = EditorGUILayout.TextField("Relative Path", m_outputDir[editor.CurrentEditingGroup]);
                        }

                        if (newDirPath != m_outputDir[editor.CurrentEditingGroup])
                        {
                            using (new RecordUndoScope("Change Output Directory", node, true)){
                                m_outputDir[editor.CurrentEditingGroup] = newDirPath;
                                onValueChanged();
                            }
                        }

                        var dirPath = Path.Combine(Application.dataPath, m_outputDir [editor.CurrentEditingGroup]);

                        if (opt == OutputOption.CreateInSelectedDirectory &&
                            !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) &&
                            !Directory.Exists(dirPath))
                        {
                            using (new EditorGUILayout.HorizontalScope()) {
                                EditorGUILayout.LabelField(m_outputDir[editor.CurrentEditingGroup] + " does not exist.");
                                if (GUILayout.Button("Create directory"))
                                {
                                    Directory.CreateDirectory(dirPath);
                                    AssetDatabase.Refresh();
                                }
                            }
                            EditorGUILayout.Space();

                            string parentDir = Path.GetDirectoryName(m_outputDir[editor.CurrentEditingGroup]);
                            if (Directory.Exists(parentDir))
                            {
                                EditorGUILayout.LabelField("Available Directories:");
                                string[] dirs = Directory.GetDirectories(parentDir);
                                foreach (string s in dirs)
                                {
                                    EditorGUILayout.LabelField(s);
                                }
                            }
                            EditorGUILayout.Space();
                        }

                        if (opt == OutputOption.CreateInSelectedDirectory || opt == OutputOption.CreateInCacheDirectory)
                        {
                            var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data, null);

                            using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f)))
                                    {
                                        var folder = AssetDatabase.LoadMainAssetAtPath(outputDir);
                                        EditorGUIUtility.PingObject(folder);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            GUILayout.Space(8f);

            foreach (var s in m_entries)
            {
                DrawGeneratorSetting(s, node, streamManager, editor, onValueChanged);
                GUILayout.Space(10f);
            }

            if (m_removingEntry != null)
            {
                using (new RecordUndoScope("Remove Generator", node)) {
                    RemoveGeneratorEntry(node, m_removingEntry);
                    m_removingEntry = null;
                    onValueChanged();
                }
            }

            GUILayout.Space(8);

            if (GUILayout.Button("Add Generator"))
            {
                using (new RecordUndoScope("Add Generator", node)) {
                    AddEntry(node);
                    onValueChanged();
                }
            }
        }
        /// <summary>
        /// Renders the IImageProvider into a Bitmap. If the passed Bitmap is non-null, and it matches the passed size and color mode, it will be reused. Otherwise this method creates a new Bitmap.
        /// </summary>
        /// <param name="imageProvider">The image provider to render the image content of.</param>
        /// <param name="bitmap">The Bitmap to reuse, if possible. If null is passed, a new Bitmap is created.</param>
        /// <param name="size">The desired size of the rendered image.</param>
        /// <param name="outputOption">Specifies how to fit the image into the rendered rectangle, if the aspect ratio differs.</param>
        /// <returns>A task resulting in either the reused Bitmap, or a new one if necessary.</returns>
        public static Task <Bitmap> GetBitmapAsync(this IImageProvider imageProvider, Bitmap bitmap, Size size, ColorMode colorMode, OutputOption outputOption)
        {
            if (bitmap == null || bitmap.Dimensions != size || bitmap.ColorMode != colorMode)
            {
                bitmap = new Bitmap(size, colorMode);
            }

            return(imageProvider.GetBitmapAsync(bitmap, outputOption).AsTask());
        }
Ejemplo n.º 25
0
    public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
    {
        if (_enabledOptions == null)
        {
            return;
        }

        EditorGUILayout.HelpBox("Удаляет папку и все файлы в ней", MessageType.Info);
        editor.UpdateNodeName(node);

        GUILayout.Space(10f);

        //Show target configuration tab
        editor.DrawPlatformSelector(node);
        using (new EditorGUILayout.VerticalScope(GUI.skin.box))
        {
            var disabledScope = editor.DrawOverrideTargetToggle(node, _enabledOptions.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) =>
            {
                using (new RecordUndoScope("Remove Target Bundle Options", node, true))
                {
                    if (enabled)
                    {
                        _enabledOptions[editor.CurrentEditingGroup] = _enabledOptions.DefaultValue;
                        _outputDir[editor.CurrentEditingGroup]      = _outputDir.DefaultValue;
                        _outputOption[editor.CurrentEditingGroup]   = _outputOption.DefaultValue;
                    }
                    else
                    {
                        _enabledOptions.Remove(editor.CurrentEditingGroup);
                        _outputDir.Remove(editor.CurrentEditingGroup);
                        _outputOption.Remove(editor.CurrentEditingGroup);
                    }

                    onValueChanged();
                }
            });

            using (disabledScope)
            {
                OutputOption opt       = (OutputOption)_outputOption[editor.CurrentEditingGroup];
                var          newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt);
                if (newOption != opt)
                {
                    using (new RecordUndoScope("Change Output Option", node, true))
                    {
                        _outputOption[editor.CurrentEditingGroup] = (int)newOption;
                        onValueChanged();
                    }
                }

                using (new EditorGUI.DisabledScope(opt == OutputOption.BuildInCacheDirectory || opt == OutputOption.BuildInBundlesCacheDirectory))
                {
                    var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                               _outputDir[editor.CurrentEditingGroup],
                                                               Application.dataPath + "/../",
                                                               (string folderSelected) =>
                    {
                        var projectPath = Directory.GetParent(Application.dataPath).ToString();

                        if (projectPath == folderSelected)
                        {
                            folderSelected = string.Empty;
                        }
                        else
                        {
                            var index = folderSelected.IndexOf(projectPath);
                            if (index >= 0)
                            {
                                folderSelected = folderSelected.Substring(projectPath.Length + index);
                                if (folderSelected.IndexOf('/') == 0)
                                {
                                    folderSelected = folderSelected.Substring(1);
                                }
                            }
                        }

                        return(folderSelected);
                    }
                                                               );

                    if (newDirPath != _outputDir[editor.CurrentEditingGroup])
                    {
                        using (new RecordUndoScope("Change Output Directory", node, true))
                        {
                            _outputDir[editor.CurrentEditingGroup] = newDirPath;



                            onValueChanged();
                        }
                    }

                    var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data);

                    using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            GUILayout.FlexibleSpace();
#if UNITY_EDITOR_OSX
                            string buttonName = "Reveal in Finder";
#else
                            string buttonName = "Show in Explorer";
#endif
                            if (GUILayout.Button(buttonName))
                            {
                                EditorUtility.RevealInFinder(outputDir);
                            }
                        }
                    }

                    EditorGUILayout.HelpBox("You can use '{Platform}' variable for Output Directory path to include platform name.", MessageType.Info);
                }
            }
        }
    }
Ejemplo n.º 26
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Create Prefab From Group: Create prefab from incoming group of assets, using assigned script.", MessageType.Info);
            editor.UpdateNodeName(node);

            var builder = m_instance.Get <IPrefabBuilder>(editor.CurrentEditingGroup);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var map = PrefabBuilderUtility.GetAttributeAssemblyQualifiedNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change PrefabBuilder class", node, true)) {
                                        builder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                        m_instance.Set(editor.CurrentEditingGroup, builder);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                    ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", m_replacePrefabOptions, GUILayout.MinWidth(150f));
                    if (m_replacePrefabOptions != opt)
                    {
                        using (new RecordUndoScope("Change Prefab Replace Option", node, true)) {
                            m_replacePrefabOptions = opt;
                            onValueChanged();
                        }
                        opt = m_replacePrefabOptions;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(m_instance.ClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", m_instance.ClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder script to use this node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1], menuNames[2], menuNames[3]
                                ), MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                            m_outputDir[editor.CurrentEditingGroup]    = m_outputDir.DefaultValue;
                            m_outputOption[editor.CurrentEditingGroup] = m_outputOption.DefaultValue;
                        }
                        else
                        {
                            m_instance.Remove(editor.CurrentEditingGroup);
                            m_outputDir.Remove(editor.CurrentEditingGroup);
                            m_outputOption.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        OutputOption opt       = (OutputOption)m_outputOption[editor.CurrentEditingGroup];
                        var          newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt);
                        if (newOption != opt)
                        {
                            using (new RecordUndoScope("Change Output Option", node, true)){
                                m_outputOption[editor.CurrentEditingGroup] = (int)newOption;
                                onValueChanged();
                            }
                            opt = newOption;
                        }

                        using (new EditorGUI.DisabledScope(opt == OutputOption.CreateInCacheDirectory)) {
                            var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                                       m_outputDir[editor.CurrentEditingGroup],
                                                                       Application.dataPath,
                                                                       (string folderSelected) => {
                                string basePath = Application.dataPath;

                                if (basePath == folderSelected)
                                {
                                    folderSelected = string.Empty;
                                }
                                else
                                {
                                    var index = folderSelected.IndexOf(basePath);
                                    if (index >= 0)
                                    {
                                        folderSelected = folderSelected.Substring(basePath.Length + index);
                                        if (folderSelected.IndexOf('/') == 0)
                                        {
                                            folderSelected = folderSelected.Substring(1);
                                        }
                                    }
                                }
                                return(folderSelected);
                            }
                                                                       );
                            if (newDirPath != m_outputDir[editor.CurrentEditingGroup])
                            {
                                using (new RecordUndoScope("Change Output Directory", node, true)){
                                    m_outputDir[editor.CurrentEditingGroup] = newDirPath;
                                    onValueChanged();
                                }
                            }

                            var dirPath = Path.Combine(Application.dataPath, m_outputDir [editor.CurrentEditingGroup]);

                            if (opt == OutputOption.CreateInSelectedDirectory &&
                                !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) &&
                                !Directory.Exists(dirPath))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    EditorGUILayout.LabelField(m_outputDir[editor.CurrentEditingGroup] + " does not exist.");
                                    if (GUILayout.Button("Create directory"))
                                    {
                                        Directory.CreateDirectory(dirPath);
                                        AssetDatabase.Refresh();
                                    }
                                }
                                EditorGUILayout.Space();

                                string parentDir = Path.GetDirectoryName(m_outputDir[editor.CurrentEditingGroup]);
                                if (Directory.Exists(parentDir))
                                {
                                    EditorGUILayout.LabelField("Available Directories:");
                                    string[] dirs = Directory.GetDirectories(parentDir);
                                    foreach (string s in dirs)
                                    {
                                        EditorGUILayout.LabelField(s);
                                    }
                                }
                                EditorGUILayout.Space();
                            }

                            var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data);

                            using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f)))
                                    {
                                        var folder = AssetDatabase.LoadMainAssetAtPath(outputDir);
                                        EditorGUIUtility.PingObject(folder);
                                    }
                                }
                            }
                        }

                        GUILayout.Space(8f);

                        if (builder != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change PrefabBuilder Setting", node)) {
                                    m_instance.Set(editor.CurrentEditingGroup, builder);
                                    onValueChanged();
                                }
                            };

                            builder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Benchmarks parsers with eagerloading turned off.
 /// </summary>
 public static void TryParse_EagerLoad_Off(OutputOption opt)
 {
     Benchmark(() => { Coordinate.TryParse("39.891219, -74.872435", new DateTime(2010, 7, 26, 15, 49, 0), new EagerLoad(false), out var tc); }, 100, "TryParse() Eager Load Off Initialization", opt);
 }
Ejemplo n.º 28
0
 public Output(string path, OutputOption option)
 {
     _path = path;
     _outputOptions.Add(option);
 }
Ejemplo n.º 29
0
 IAsyncOperation <Bitmap> IImageProvider.GetBitmapAsync(Bitmap bitmap, OutputOption outputOption)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Renders the IImageProvider into a Bitmap. If the passed Bitmap is non-null, and it matches the passed size and color mode, it will be reused. Otherwise this method creates a new Bitmap.
        /// </summary>
        /// <param name="imageProvider">The image provider to render the image content of.</param>
        /// <param name="bitmap">The Bitmap to reuse, if possible. If null is passed, a new Bitmap is created.</param>
        /// <param name="size">The desired size of the rendered image.</param>
        /// <param name="outputOption">Specifies how to fit the image into the rendered rectangle, if the aspect ratio differs.</param>
        /// <returns>A task resulting in either the reused Bitmap, or a new one if necessary.</returns>
        public static async Task <Bitmap> GetBitmapAsync(this IImageProvider imageProvider, Bitmap bitmap, Size size, ColorMode colorMode, OutputOption outputOption)
        {
            if (bitmap == null || bitmap.Dimensions != size || bitmap.ColorMode != colorMode)
            {
                bitmap = new Bitmap(size, colorMode);
            }

            using (var renderer = new BitmapRenderer(imageProvider, bitmap, outputOption))
            {
                return(await renderer.RenderAsync().AsTask().ConfigureAwait(false));
            }
        }
        /// <summary>
        /// Renders the IImageProvider into a WriteableBitmap. If the passed WriteableBitmap is non-null, and it matches the passed size, it will be reused. Otherwise this method creates a new WriteableBitmap. Note that this method must be called on the UI thread.
        /// </summary>
        /// <param name="imageProvider">The image provider to render the image content of.</param>
        /// <param name="writeableBitmap">The WriteableBitmap to reuse, if possible. If null is passed, a new WriteableBitmap is created.</param>
        /// <param name="size">The desired size of the rendered image.</param>
        /// <param name="outputOption">Specifies how to fit the image into the rendered rectangle, if the aspect ratio differs.</param>
        /// <returns>A task resulting in either the reused WriteableBitmap, or a new one if necessary.</returns>
        public static Task <WriteableBitmap> GetBitmapAsync(this IImageProvider imageProvider, WriteableBitmap writeableBitmap, Size size, OutputOption outputOption)
        {
            if (writeableBitmap == null || writeableBitmap.PixelWidth != (int)size.Width || writeableBitmap.PixelHeight != (int)size.Height)
            {
                writeableBitmap = new WriteableBitmap((int)size.Width, (int)size.Height);
            }

            return(imageProvider.GetBitmapAsync(writeableBitmap, outputOption).AsTask());
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            try
            {
                EntityReference FirstAttachment  = FirstAttachmentId.Get(executionContext);
                EntityReference SecondAttachment = SecondAttachmentId.Get(executionContext);
                EntityReference Contact          = ContactId.Get(executionContext);
                string          Option           = OutputOption.Get(executionContext);
                Boolean         Logging          = EnableLogging.Get(executionContext);
                string          LicenseFilePath  = LicenseFile.Get(executionContext);

                if (Logging)
                {
                    Log("Workflow Executed");
                }

                // Create a CRM Service in Workflow.
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                if (Logging)
                {
                    Log("Executing Query to retrieve First Attachment");
                }

                Entity FirstNote = service.Retrieve("annotation", FirstAttachment.Id, new ColumnSet(new string[] { "subject", "documentbody" }));

                if (Logging)
                {
                    Log("First Attachment Retrieved Successfully");
                }
                if (Logging)
                {
                    Log("Executing Query to retrieve Second Attachment");
                }

                Entity SecondNote = service.Retrieve("annotation", SecondAttachment.Id, new ColumnSet(new string[] { "subject", "documentbody" }));

                if (Logging)
                {
                    Log("Second Attachment Retrieved Successfully");
                }

                MemoryStream fileStream1 = null, fileStream2 = null;
                string       FileName1 = "";
                string       FileName2 = "";
                if (FirstNote != null && FirstNote.Contains("documentbody"))
                {
                    byte[] DocumentBody = Convert.FromBase64String(FirstNote["documentbody"].ToString());
                    fileStream1 = new MemoryStream(DocumentBody);
                    if (FirstNote.Contains("filename"))
                    {
                        FileName1 = FirstNote["filename"].ToString();
                    }
                }
                if (SecondNote != null && SecondNote.Contains("documentbody"))
                {
                    byte[] DocumentBody = Convert.FromBase64String(SecondNote["documentbody"].ToString());
                    fileStream2 = new MemoryStream(DocumentBody);
                    if (SecondNote.Contains("filename"))
                    {
                        FileName2 = SecondNote["filename"].ToString();
                    }
                }
                try
                {
                    if (Logging)
                    {
                        Log("Enable Licensing");
                    }

                    if (LicenseFilePath != "" && File.Exists(LicenseFilePath))
                    {
                        Aspose.Words.License Lic = new License();
                        Lic.SetLicense(LicenseFilePath);
                        if (Logging)
                        {
                            Log("License Set");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log("Error while applying license: " + ex.Message);
                }

                if (Logging)
                {
                    Log("Merging Documents");
                }

                Document doc1 = new Document(fileStream1);
                Document doc2 = new Document(fileStream2);
                doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);

                if (Logging)
                {
                    Log("Merging Complete");
                }

                MemoryStream UpdateDoc = new MemoryStream();

                if (Logging)
                {
                    Log("Saving Document");
                }

                doc1.Save(UpdateDoc, SaveFormat.Docx);
                byte[] byteData = UpdateDoc.ToArray();

                // Encode the data using base64.
                string encodedData = System.Convert.ToBase64String(byteData);

                if (Logging)
                {
                    Log("Creating Attachment");
                }

                Entity NewNote = new Entity("annotation");

                // Add a note to the entity.
                NewNote.Attributes.Add("objectid", new EntityReference("contact", Contact.Id));

                // Set EncodedData to Document Body.
                NewNote.Attributes.Add("documentbody", encodedData);

                // Set the type of attachment.
                NewNote.Attributes.Add("mimetype", @"application\ms-word");
                NewNote.Attributes.Add("notetext", "Document Created using template");

                if (Option == "0")
                {
                    NewNote.Id = FirstNote.Id;
                    NewNote.Attributes.Add("subject", FileName1);
                    NewNote.Attributes.Add("filename", FileName1);
                    service.Update(NewNote);
                }
                else if (Option == "1")
                {
                    NewNote.Id = SecondNote.Id;
                    NewNote.Attributes.Add("subject", FileName2);
                    NewNote.Attributes.Add("filename", FileName2);
                    service.Update(NewNote);
                }
                else
                {
                    NewNote.Attributes.Add("subject", "Aspose .Net Document Merger");
                    NewNote.Attributes.Add("filename", "Aspose .Net Document Merger.docx");
                    service.Create(NewNote);
                }
                if (Logging)
                {
                    Log("Successfull");
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Benchmarks all celestial calculations.
 /// </summary>
 public static void Celestial_Calculations(OutputOption opt)
 {
     Benchmark(() => { Celestial cel = new Celestial(45, 45, DateTime.Now); }, 100, "Celestial Time Calculations", opt);
 }
Ejemplo n.º 34
0
 public IAsyncOperation <Bitmap> GetBitmapAsync(Bitmap bitmap, OutputOption outputOption)
 {
     return(m_imageProvider.GetBitmapAsync(bitmap, outputOption));
 }
Ejemplo n.º 35
0
 private static FunctionResult Execute(Transaction transaction, string storedProcedureName, DatabaseModel.ProcedureParameters parameters = null, object[] parameterValues = null, bool fetchResultSets = false, OutputOption outputOption = OutputOption.RowByRow)
 {
     return(Execute(ConnectionTypeSelection.UseTransaction, transaction, null, storedProcedureName, parameters, parameterValues, fetchResultSets ? FetchResultSets(transaction.GetConnectionType()) : null, null, outputOption));
 }
		public IAsyncOperation<Bitmap> GetBitmapAsync(Bitmap bitmap, OutputOption outputOption)
		{
			return m_imageProvider.GetBitmapAsync(bitmap, outputOption);
		}
Ejemplo n.º 37
0
 IAsyncOperation<Bitmap> IImageProvider.GetBitmapAsync(Bitmap bitmap, OutputOption outputOption)
 {
     throw new NotImplementedException();
 }