Exemplo n.º 1
0
        public static void BroadCastData(object target, Stream outgoingData)
        {
            Log.Configure("LINQBridgeVs", "DynamicCore");

            try
            {
                var targetType = GetInterfaceTypeIfIsIterator(target);
                var targetTypeFullName = TypeNameHelper.GetDisplayName(targetType, true);
                var targetTypeName = TypeNameHelper.GetDisplayName(targetType, false);
                //I'm lazy I know it...
                var pattern1 = new Regex("[<]");
                var pattern2 = new Regex("[>]");
                var pattern3 = new Regex("[,]");
                var pattern4 = new Regex("[`]");
                var pattern5 = new Regex("[ ]");

                var fileName = pattern1.Replace(targetTypeFullName, "(");
                fileName = pattern2.Replace(fileName, ")");

                var typeName = pattern1.Replace(targetTypeName, string.Empty);
                typeName = pattern2.Replace(typeName, string.Empty);
                typeName = pattern3.Replace(typeName, string.Empty);
                typeName = pattern4.Replace(typeName, string.Empty);
                typeName = pattern5.Replace(typeName, string.Empty);

                fileName = TypeNameHelper.RemoveSystemNamespaces(fileName);

                var message = new Message
                {
                    FileName = string.Format(FileNameFormat, fileName),
                    TypeName = typeName.Trim(),
                    TypeFullName = targetTypeFullName, 
                    //TypeLocation = GetAssemblyLocation(vsVersion, targetType.Name),
                    TypeNamespace = targetType.Namespace,
                    AssemblyQualifiedName = targetType.AssemblyQualifiedName
                };

                var binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(outgoingData, message);

                Log.Write("BroadCastData to LINQBridgeVsTruck");

                var truck = new Truck("LINQBridgeVsTruck");
                truck.LoadCargo(target);
                var res = truck.DeliverTo(typeName);
                Log.Write("Data Succesfully Shipped to Grapple");

            }
            catch (Exception e)
            {
                Log.Write(e, "Error in BroadCastData");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deploys the dynamically generated linqscript.
        /// </summary>
        /// <param name="message">The message.</param>
        internal void DeployLinqScript(Message message)
        {
            try
            {
                Log.Write("Entered in DeployLinqScript");
                // Log.Write("Message: {0}", message);

                var dstScriptPath = Path.Combine(MyDocuments, Resources.LINQPadQuery);
                Log.Write("dstScriptPath: {0}", dstScriptPath);

                if (!FileSystem.Directory.Exists(dstScriptPath))
                {
                    var sec = new DirectorySecurity();
                    // Using this instead of the "Everyone" string means we work on non-English systems.
                    var everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                    sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
                    FileSystem.Directory.CreateDirectory(dstScriptPath, sec);
                    Log.Write(string.Format("Directory Created: {0}", dstScriptPath));
                }

                var dst = Path.Combine(dstScriptPath, string.Format(message.FileName, message.TypeFullName));
                Log.Write("dst: {0}", dst);

                var refAssemblies = new List <string>();

                refAssemblies.AddRange(message.ReferencedAssemblies);

                var linqQuery     = new Inspection(refAssemblies, message.TypeFullName, message.TypeNamespace, message.TypeName);
                var linqQueryText = linqQuery.TransformText();

                Log.Write("LinqQuery file Transformed");


                using (var memoryStream = FileSystem.File.Open(dst, FileMode.Create))
                    using (var streamWriter = new StreamWriter(memoryStream))
                    {
                        streamWriter.Write(linqQueryText);
                        streamWriter.Flush();
                        memoryStream.Flush();
                    }
                Log.Write("LinqQuery file Generated");
            }
            catch (Exception e)
            {
                Log.Write(e, "DynamicDebuggerVisualizer.DeployLinqScript");
                throw;
            }
        }
        /// <summary>
        /// Deploys the dynamically generated linqscript.
        /// </summary>
        /// <param name="message">The message.</param>
        internal void DeployLinqScript(Message message)
        {
            try
            {
                Log.Write("Entered in DeployLinqScript");
                // Log.Write("Message: {0}", message);

                var dstScriptPath = Path.Combine(MyDocuments, Resources.LINQPadQuery);
                Log.Write("dstScriptPath: {0}", dstScriptPath);

                if (!FileSystem.Directory.Exists(dstScriptPath))
                {
                    var sec = new DirectorySecurity();
                    // Using this instead of the "Everyone" string means we work on non-English systems.
                    var everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                    sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
                    FileSystem.Directory.CreateDirectory(dstScriptPath, sec);
                    Log.Write(string.Format("Directory Created: {0}", dstScriptPath));
                }

                var dst = Path.Combine(dstScriptPath, string.Format(message.FileName, message.TypeFullName));
                Log.Write("dst: {0}", dst);

                var refAssemblies = new List<string>();

                refAssemblies.AddRange(message.ReferencedAssemblies);

                var linqQuery = new Inspection(refAssemblies, message.TypeFullName, message.TypeNamespace, message.TypeName);
                var linqQueryText = linqQuery.TransformText();

                Log.Write("LinqQuery file Transformed");


                using (var memoryStream = FileSystem.File.Open(dst, FileMode.Create))
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    streamWriter.Write(linqQueryText);
                    streamWriter.Flush();
                    memoryStream.Flush();
                }
                Log.Write("LinqQuery file Generated");

            }
            catch (Exception e)
            {
                Log.Write(e, "DynamicDebuggerVisualizer.DeployLinqScript");
                throw;
            }
        }