Ejemplo n.º 1
0
        public void BroadCastData(object target, Stream outgoingData)
        {
            //configure once the vs version
            string vsVersion = VisualStudioVersionHelper.FindCurrentVisualStudioVersion();

            RavenWrapper.VisualStudioVersion = vsVersion;
            Log.VisualStudioVersion          = vsVersion;

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

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

                string 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);

                Message message = new Message
                {
                    FileName              = string.Format(FileNameFormat, fileName),
                    TypeName              = typeName.Trim(),
                    TypeFullName          = targetTypeFullName,
                    TypeNamespace         = targetType.Namespace,
                    AssemblyQualifiedName = targetType.AssemblyQualifiedName,
                    AssemblyName          = targetType.Assembly.GetName().Name
                };

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

                Log.Write("BroadCastData to LINQBridgeVsTruck");
                SerializationOption serializationOption = CommonRegistryConfigurations.GetSerializationOption(vsVersion);
                Truck truck = new Truck("LINQBridgeVsTruck", serializationOption);
                truck.LoadCargo(target);
                bool res = truck.DeliverTo(typeName);
                Log.Write("Data Succesfully Shipped to Grapple");
            }
            catch (Exception exception)
            {
                Log.Write(exception, "Error in BroadCastData");
                RavenWrapper.Instance.Capture(exception, message: "Error broadcasting the data to linqpad");
                throw;
            }
        }